Add RenderConfig#initialBuilderCapacity

This commit is contained in:
DBotThePony 2023-09-06 19:06:12 +07:00
parent 386d71b92f
commit 0f4b7ace07
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 7 additions and 1 deletions

View File

@ -54,6 +54,8 @@ class VertexBuilder(
val defaultMode: GeometryType? = null,
initialCapacity: Int = 64
) {
constructor(attributes: GLAttributeList, initialCapacity: Int) : this(attributes, null, initialCapacity)
init {
require(initialCapacity > 0) { "Invalid capacity: $initialCapacity" }
}

View File

@ -16,7 +16,7 @@ class MultiMeshBuilder {
fun get(config: RenderConfig<*>, layer: Int): VertexBuilder {
return meshes.computeIfAbsent(config, Reference2ObjectFunction {
Int2ObjectOpenHashMap()
}).computeIfAbsent(layer, Int2ObjectFunction { Entry(config, VertexBuilder(config.program.attributes), layer) }).builder
}).computeIfAbsent(layer, Int2ObjectFunction { Entry(config, VertexBuilder(config.program.attributes, config.initialBuilderCapacity), layer) }).builder
}
fun clear() = meshes.clear()

View File

@ -5,6 +5,7 @@ import ru.dbotthepony.kvector.arrays.Matrix4f
abstract class RenderConfig<out T : GLShaderProgram>(val program: T) {
val state get() = program.state
open val initialBuilderCapacity: Int get() = 64
open fun setup(transform: Matrix4f = state.matrixStack.last()) {
program.use()

View File

@ -44,6 +44,9 @@ class TileRenderers(val client: StarboundClient) {
}
private inner class Config(private val texture: GLTexture2D, private val color: RGBAColor) : RenderConfig<GLTileProgram>(state.programs.tile) {
override val initialBuilderCapacity: Int
get() = 1024
override fun setup(transform: Matrix4f) {
super.setup(transform)
state.activeTexture = 0