mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
gui: replace meshes Vec2t<*> with Vec2 or Vec2i
This reduces memory allocation rate
This commit is contained in:
parent
f526d99441
commit
5fd52fb192
@ -15,7 +15,6 @@ package de.bixilon.minosoft.gui.rendering.font
|
||||
|
||||
import de.bixilon.kotlinglm.vec2.Vec2
|
||||
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||
import de.bixilon.kotlinglm.vec2.Vec2t
|
||||
import de.bixilon.kutil.math.simple.FloatMath.ceil
|
||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.RenderContext
|
||||
@ -47,12 +46,12 @@ class CharData(
|
||||
_render(position, color, false, italic, bold, strikethrough, underlined, consumer, options, scale)
|
||||
}
|
||||
|
||||
private fun GUIVertexConsumer.addQuad(start: Vec2t<*>, end: Vec2t<*>, texture: AbstractTexture, uvStart: Vec2, uvEnd: Vec2, italic: Boolean, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
val italicOffset = if (italic) (end.y.toFloat() - start.y.toFloat()) / Font.CHAR_HEIGHT.toFloat() * ITALIC_OFFSET else 0.0f
|
||||
private fun GUIVertexConsumer.addQuad(start: Vec2, end: Vec2, texture: AbstractTexture, uvStart: Vec2, uvEnd: Vec2, italic: Boolean, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
val italicOffset = if (italic) (end.y - start.y) / Font.CHAR_HEIGHT.toFloat() * ITALIC_OFFSET else 0.0f
|
||||
|
||||
val positions = arrayOf(
|
||||
Vec2(start.x.toFloat() + italicOffset, start.y),
|
||||
Vec2(end.x.toFloat() + italicOffset, start.y),
|
||||
Vec2(start.x + italicOffset, start.y),
|
||||
Vec2(end.x + italicOffset, start.y),
|
||||
end,
|
||||
Vec2(start.x, end.y),
|
||||
)
|
||||
@ -107,7 +106,7 @@ class CharData(
|
||||
}
|
||||
|
||||
if (underlined) {
|
||||
vertexConsumer.addQuad(startPosition + Vec2i(-horizontalSpacing, charHeight), Vec2i(endPosition.x + boldOffset + horizontalSpacing, startPosition.y + charHeight + verticalSpacing / 2.0f), whiteTexture.texture, whiteTexture.uvStart, whiteTexture.uvEnd, italic, color, options)
|
||||
vertexConsumer.addQuad(startPosition + Vec2(-horizontalSpacing, charHeight), Vec2(endPosition.x + boldOffset + horizontalSpacing, startPosition.y + charHeight + verticalSpacing / 2.0f), whiteTexture.texture, whiteTexture.uvStart, whiteTexture.uvEnd, italic, color, options)
|
||||
}
|
||||
|
||||
// ToDo: Obfuscated
|
||||
|
@ -15,7 +15,6 @@ package de.bixilon.minosoft.gui.rendering.font
|
||||
|
||||
import de.bixilon.kotlinglm.mat4x4.Mat4
|
||||
import de.bixilon.kotlinglm.vec2.Vec2
|
||||
import de.bixilon.kotlinglm.vec2.Vec2t
|
||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.font.renderer.ChatComponentRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMeshCache
|
||||
@ -29,8 +28,8 @@ import de.bixilon.minosoft.gui.rendering.world.mesh.SingleWorldMesh
|
||||
class WorldGUIConsumer(val mesh: SingleWorldMesh, val transform: Mat4, val light: Int) : GUIVertexConsumer {
|
||||
override val order: Array<Pair<Int, Int>> get() = mesh.order
|
||||
|
||||
override fun addVertex(position: Vec2t<*>, texture: ShaderIdentifiable, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
val transformed = transform.fastTimes(position.x.toFloat() / ChatComponentRenderer.TEXT_BLOCK_RESOLUTION, -position.y.toFloat() / ChatComponentRenderer.TEXT_BLOCK_RESOLUTION)
|
||||
override fun addVertex(position: Vec2, texture: ShaderIdentifiable, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
val transformed = transform.fastTimes(position.x / ChatComponentRenderer.TEXT_BLOCK_RESOLUTION, -position.y / ChatComponentRenderer.TEXT_BLOCK_RESOLUTION)
|
||||
mesh.addVertex(transformed, uv, texture as AbstractTexture, tint.rgb, light)
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
package de.bixilon.minosoft.gui.rendering.gui.mesh
|
||||
|
||||
import de.bixilon.kotlinglm.vec2.Vec2
|
||||
import de.bixilon.kotlinglm.vec2.Vec2t
|
||||
import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList
|
||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.RenderContext
|
||||
@ -29,7 +28,7 @@ class GUIMesh(
|
||||
data: AbstractFloatList,
|
||||
) : Mesh(context, GUIMeshStruct, initialCacheSize = 40000, clearOnLoad = false, data = data), GUIVertexConsumer {
|
||||
|
||||
override fun addVertex(position: Vec2t<*>, texture: ShaderIdentifiable, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
override fun addVertex(position: Vec2, texture: ShaderIdentifiable, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
addVertex(data, halfSize, position, texture, uv, tint, options)
|
||||
}
|
||||
|
||||
@ -49,12 +48,15 @@ class GUIMesh(
|
||||
companion object {
|
||||
|
||||
fun transformPosition(position: Vec2, halfSize: Vec2): Vec2 {
|
||||
val pixel = position / halfSize
|
||||
return Vec2(pixel.x - 1.0f, 1.0f - pixel.y)
|
||||
val res = Vec2(position)
|
||||
res /= halfSize
|
||||
res.x -= 1.0f
|
||||
res.y = 1.0f - res.y
|
||||
return res
|
||||
}
|
||||
|
||||
fun addVertex(data: AbstractFloatList, halfSize: Vec2, position: Vec2t<*>, texture: ShaderIdentifiable, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
val outPosition = transformPosition(Vec2(position), halfSize)
|
||||
fun addVertex(data: AbstractFloatList, halfSize: Vec2, position: Vec2, texture: ShaderIdentifiable, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
val outPosition = transformPosition(position, halfSize)
|
||||
var color = tint.rgba
|
||||
|
||||
if (options != null) {
|
||||
|
@ -15,7 +15,6 @@ package de.bixilon.minosoft.gui.rendering.gui.mesh
|
||||
|
||||
import de.bixilon.kotlinglm.vec2.Vec2
|
||||
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||
import de.bixilon.kotlinglm.vec2.Vec2t
|
||||
import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList
|
||||
import de.bixilon.kutil.collections.primitive.floats.HeapArrayFloatList
|
||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||
@ -40,7 +39,7 @@ class GUIMeshCache(
|
||||
}
|
||||
}
|
||||
|
||||
override fun addVertex(position: Vec2t<*>, texture: ShaderIdentifiable, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
override fun addVertex(position: Vec2, texture: ShaderIdentifiable, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
GUIMesh.addVertex(data, halfSize, position, texture, uv, tint, options)
|
||||
revision++
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
package de.bixilon.minosoft.gui.rendering.gui.mesh
|
||||
|
||||
import de.bixilon.kotlinglm.vec2.Vec2
|
||||
import de.bixilon.kotlinglm.vec2.Vec2t
|
||||
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.gui.atlas.TextureLike
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.ShaderIdentifiable
|
||||
@ -22,9 +22,12 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.ShaderIdentifiable
|
||||
interface GUIVertexConsumer {
|
||||
val order: Array<Pair<Int, Int>>
|
||||
|
||||
fun addVertex(position: Vec2t<*>, texture: ShaderIdentifiable, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?)
|
||||
fun addVertex(position: Vec2, texture: ShaderIdentifiable, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?)
|
||||
fun addVertex(position: Vec2i, texture: ShaderIdentifiable, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
addVertex(Vec2(position), texture, uv, tint, options)
|
||||
}
|
||||
|
||||
fun addQuad(start: Vec2t<*>, end: Vec2t<*>, texture: ShaderIdentifiable, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), tint: RGBColor, options: GUIVertexOptions?) {
|
||||
fun addQuad(start: Vec2, end: Vec2, texture: ShaderIdentifiable, uvStart: Vec2 = UV_START, uvEnd: Vec2 = UV_END, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
val positions = arrayOf(
|
||||
start,
|
||||
Vec2(end.x, start.y),
|
||||
@ -43,11 +46,39 @@ interface GUIVertexConsumer {
|
||||
}
|
||||
}
|
||||
|
||||
fun addQuad(start: Vec2t<*>, end: Vec2t<*>, texture: TextureLike, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
fun addQuad(start: Vec2i, end: Vec2i, texture: ShaderIdentifiable, uvStart: Vec2 = UV_START, uvEnd: Vec2 = UV_END, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
val positions = arrayOf(
|
||||
Vec2(start),
|
||||
Vec2(end.x, start.y),
|
||||
Vec2(end),
|
||||
Vec2(start.x, end.y),
|
||||
)
|
||||
val texturePositions = arrayOf(
|
||||
Vec2(uvEnd.x, uvStart.y),
|
||||
uvStart,
|
||||
Vec2(uvStart.x, uvEnd.y),
|
||||
uvEnd,
|
||||
)
|
||||
|
||||
for ((vertexIndex, textureIndex) in order) {
|
||||
addVertex(positions[vertexIndex], texture, texturePositions[textureIndex], tint, options)
|
||||
}
|
||||
}
|
||||
|
||||
fun addQuad(start: Vec2, end: Vec2, texture: TextureLike, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
addQuad(start, end, texture.texture, texture.uvStart, texture.uvEnd, tint, options)
|
||||
}
|
||||
|
||||
fun addQuad(start: Vec2i, end: Vec2i, texture: TextureLike, tint: RGBColor, options: GUIVertexOptions?) {
|
||||
addQuad(start, end, texture.texture, texture.uvStart, texture.uvEnd, tint, options)
|
||||
}
|
||||
|
||||
fun addCache(cache: GUIMeshCache)
|
||||
|
||||
fun ensureSize(size: Int)
|
||||
|
||||
companion object {
|
||||
val UV_START = Vec2(0.0f, 0.0f)
|
||||
val UV_END = Vec2(1.0f, 1.0f)
|
||||
}
|
||||
}
|
||||
|
@ -27,9 +27,7 @@ class SingleWorldMesh(context: RenderContext, initialCacheSize: Int, onDemand: B
|
||||
fun addVertex(position: FloatArray, uv: Vec2, texture: AbstractTexture, tintColor: Int, light: Int) {
|
||||
data.ensureSize(WorldMeshStruct.FLOATS_PER_VERTEX)
|
||||
val transformedUV = texture.renderData.transformUV(uv).array
|
||||
data.add(position[0])
|
||||
data.add(position[1])
|
||||
data.add(position[2])
|
||||
data.add(position)
|
||||
data.add(transformedUV)
|
||||
data.add(texture.renderData.shaderTextureId.buffer())
|
||||
data.add((tintColor or (light shl 24)).buffer())
|
||||
|
Loading…
x
Reference in New Issue
Block a user