diff --git a/doc/rendering/world_renderer.md b/doc/rendering/world_renderer.md index 04f72da5a..b3785a04f 100644 --- a/doc/rendering/world_renderer.md +++ b/doc/rendering/world_renderer.md @@ -48,4 +48,3 @@ - Reduce memory usage - Unload on minimize - Biomes: Check if chunk is single biome - - Texture rotation in hopper diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDRenderer.kt index db948e27c..f7c3e92af 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDRenderer.kt @@ -49,6 +49,7 @@ import de.bixilon.minosoft.util.KUtil.synchronizedMapOf import de.bixilon.minosoft.util.KUtil.toResourceLocation import de.bixilon.minosoft.util.KUtil.toSynchronizedMap import de.bixilon.minosoft.util.KUtil.unsafeCast +import de.bixilon.minosoft.util.collections.DirectArrayFloatList import glm_.glm import glm_.mat4x4.Mat4 import glm_.vec2.Vec2 @@ -153,11 +154,15 @@ class HUDRenderer( } override fun drawOther() { - if (this::mesh.isInitialized) { + val data = if (this::mesh.isInitialized) { mesh.unload() + mesh.data.buffer.clear() + mesh.data + } else { + DirectArrayFloatList() } - mesh = GUIMesh(renderWindow, matrix) + mesh = GUIMesh(renderWindow, matrix, data) val hudElements = hudElements.toSynchronizedMap().values val time = System.currentTimeMillis() diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt index 2e765e94e..2a188ba30 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt @@ -25,6 +25,7 @@ import de.bixilon.minosoft.gui.rendering.input.camera.hit.BlockRaycastHit import de.bixilon.minosoft.gui.rendering.input.camera.hit.EntityRaycastHit import de.bixilon.minosoft.gui.rendering.system.base.BlendingFunctions import de.bixilon.minosoft.util.KUtil.toResourceLocation +import de.bixilon.minosoft.util.collections.DirectArrayFloatList class CrosshairHUDElement(hudRenderer: HUDRenderer) : CustomHUDElement(hudRenderer) { private lateinit var crosshairAtlasElement: HUDAtlasElement @@ -62,7 +63,7 @@ class CrosshairHUDElement(hudRenderer: HUDRenderer) : CustomHUDElement(hudRender val config = Minosoft.config.config.game.hud.crosshair - val mesh = GUIMesh(renderWindow, hudRenderer.matrix) + val mesh = GUIMesh(renderWindow, hudRenderer.matrix, DirectArrayFloatList(42)) // Custom draw to make the crosshair inverted if (renderWindow.connection.player.gamemode == Gamemodes.SPECTATOR) { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt index c880b05b6..0b71bceb0 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt @@ -19,6 +19,7 @@ import de.bixilon.minosoft.gui.rendering.RenderWindow import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct +import de.bixilon.minosoft.util.collections.DirectArrayFloatList import glm_.mat4x4.Mat4 import glm_.vec2.Vec2 import glm_.vec2.Vec2t @@ -28,7 +29,8 @@ import glm_.vec4.Vec4 class GUIMesh( renderWindow: RenderWindow, val matrix: Mat4, -) : Mesh(renderWindow, GUIMeshStruct, initialCacheSize = 40000), GUIVertexConsumer { + data: DirectArrayFloatList, +) : Mesh(renderWindow, GUIMeshStruct, initialCacheSize = 40000, clearOnLoad = false, data = data), GUIVertexConsumer { override fun addVertex(position: Vec2t<*>, z: Int, texture: AbstractTexture, uv: Vec2, tint: RGBColor, options: GUIVertexOptions?) { data.addAll(createVertex(matrix, position, z, texture, uv, tint, options)) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt index 10e42befe..8fdc8cd5f 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt @@ -25,9 +25,11 @@ abstract class Mesh( private val struct: MeshStruct, private val primitiveType: PrimitiveTypes = renderWindow.renderSystem.preferredPrimitiveType, initialCacheSize: Int = 10000, + val clearOnLoad: Boolean = true, + data: DirectArrayFloatList? = null, ) { val order = renderWindow.renderSystem.primitiveMeshOrder - private var _data: DirectArrayFloatList? = DirectArrayFloatList(initialCacheSize) + private var _data: DirectArrayFloatList? = data ?: DirectArrayFloatList(initialCacheSize) var data: DirectArrayFloatList get() = _data!! set(value) { @@ -46,8 +48,10 @@ abstract class Mesh( fun load() { buffer = renderWindow.renderSystem.createVertexBuffer(struct, data.buffer, primitiveType) buffer.init() - data.unload() - _data = null + if (clearOnLoad) { + data.unload() + _data = null + } vertices = buffer.vertices }