mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 20:05:02 -04:00
fix some bugs with abstract meshes
This commit is contained in:
parent
8e3b799b40
commit
f5e09b27bb
@ -38,7 +38,7 @@ class ChunkBorderRenderer(
|
||||
if (chunkPosition == lastChunkPosition && lastMesh != null) {
|
||||
return
|
||||
}
|
||||
lastMesh?.unload(false)
|
||||
lastMesh?.unload(true)
|
||||
val mesh = LineMesh(renderWindow)
|
||||
|
||||
val dimension = renderWindow.connection.world.dimension ?: return
|
||||
|
@ -87,7 +87,7 @@ class EntityHitBoxRenderer(
|
||||
val mesh = this.meshes.getAndRemove(it.entity) ?: return@of
|
||||
|
||||
renderWindow.queue += {
|
||||
mesh.unload(false)
|
||||
mesh.unload(true)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -179,7 +179,7 @@ class HUDRenderer(val connection: PlayConnection, val renderWindow: RenderWindow
|
||||
hudElement.layout.checkCache(elementStart, realScaleFactor, orthographicMatrix, 0)
|
||||
tempMesh.addCacheMesh(hudElement.layout.cache)
|
||||
}
|
||||
currentHUDMesh.unload(false)
|
||||
currentHUDMesh.unload(true)
|
||||
tempMesh.load()
|
||||
currentHUDMesh = tempMesh
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.bixilon.minosoft.gui.rendering.system.base.buffer
|
||||
|
||||
interface RenderBuffer {
|
||||
val state: RenderBufferStates
|
||||
val type: RenderBufferTypes
|
||||
|
||||
fun init()
|
||||
@ -9,5 +10,5 @@ interface RenderBuffer {
|
||||
fun bind()
|
||||
fun unbind()
|
||||
|
||||
fun unload()
|
||||
fun unload(ignoreUnloaded: Boolean)
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.system.base.buffer
|
||||
|
||||
enum class RenderBufferStates {
|
||||
PREPARING,
|
||||
UPLOADED,
|
||||
UNLOADED,
|
||||
;
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex
|
||||
|
||||
enum class PrimitiveTypes {
|
||||
POINT,
|
||||
LINE,
|
||||
TRIANGLE,
|
||||
QUADS,
|
||||
enum class PrimitiveTypes(val vertices: Int) {
|
||||
POINT(1),
|
||||
LINE(2),
|
||||
TRIANGLE(4),
|
||||
QUAD(4),
|
||||
;
|
||||
}
|
@ -2,6 +2,7 @@ package de.bixilon.minosoft.gui.rendering.system.opengl.buffer
|
||||
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.FloatBuffer
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.RenderBufferDrawTypes
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.RenderBufferStates
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.RenderBufferTypes
|
||||
import org.lwjgl.opengl.GL15.glBufferData
|
||||
import org.lwjgl.opengl.GL15.glBufferSubData
|
||||
@ -18,6 +19,7 @@ open class FloatOpenGLBuffer(protected var _data: FloatArray?) : OpenGLRenderBuf
|
||||
bind()
|
||||
glBufferData(type.gl, data, drawTypes.gl)
|
||||
unbind()
|
||||
state = RenderBufferStates.UPLOADED
|
||||
}
|
||||
|
||||
override fun upload() {
|
||||
|
@ -2,11 +2,13 @@ package de.bixilon.minosoft.gui.rendering.system.opengl.buffer
|
||||
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.RenderBuffer
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.RenderBufferDrawTypes
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.RenderBufferStates
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.RenderBufferTypes
|
||||
import org.lwjgl.opengl.GL15.*
|
||||
import org.lwjgl.opengl.GL31.GL_UNIFORM_BUFFER
|
||||
|
||||
abstract class OpenGLRenderBuffer(override val type: RenderBufferTypes) : RenderBuffer {
|
||||
override var state: RenderBufferStates = RenderBufferStates.PREPARING
|
||||
abstract val drawTypes: RenderBufferDrawTypes
|
||||
|
||||
protected var id: Int = -1
|
||||
@ -24,9 +26,15 @@ abstract class OpenGLRenderBuffer(override val type: RenderBufferTypes) : Render
|
||||
glBindBuffer(type.gl, 0)
|
||||
}
|
||||
|
||||
override fun unload() {
|
||||
override fun unload(ignoreUnloaded: Boolean) {
|
||||
if (state != RenderBufferStates.UPLOADED && !ignoreUnloaded) {
|
||||
error("")
|
||||
}
|
||||
if (state != RenderBufferStates.UPLOADED) {
|
||||
state = RenderBufferStates.UNLOADED
|
||||
glDeleteBuffers(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected companion object {
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.system.opengl.buffer.uniform
|
||||
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.RenderBufferStates
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.uniform.FloatUniformBuffer
|
||||
import org.lwjgl.opengl.GL15.glBufferData
|
||||
import org.lwjgl.opengl.GL15.glBufferSubData
|
||||
@ -25,6 +26,7 @@ class FloatOpenGLUniformBuffer(bindingIndex: Int = 0, override var data: FloatAr
|
||||
bind()
|
||||
glBufferData(type.gl, data, drawTypes.gl)
|
||||
unbind()
|
||||
state = RenderBufferStates.UPLOADED
|
||||
}
|
||||
|
||||
override fun upload() {
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.system.opengl.buffer.uniform
|
||||
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.RenderBufferStates
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.uniform.IntUniformBuffer
|
||||
import org.lwjgl.opengl.GL15.glBufferData
|
||||
import org.lwjgl.opengl.GL15.glBufferSubData
|
||||
@ -25,6 +26,7 @@ class IntOpenGLUniformBuffer(bindingIndex: Int = 0, override var data: IntArray
|
||||
bind()
|
||||
glBufferData(type.gl, data, drawTypes.gl)
|
||||
unbind()
|
||||
state = RenderBufferStates.UPLOADED
|
||||
}
|
||||
|
||||
override fun upload() {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.bixilon.minosoft.gui.rendering.system.opengl.buffer.vertex
|
||||
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.RenderBufferStates
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.FloatVertexBuffer
|
||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveTypes
|
||||
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.FloatOpenGLBuffer
|
||||
@ -10,6 +11,7 @@ import de.bixilon.minosoft.util.Util
|
||||
import org.lwjgl.opengl.ARBVertexArrayObject.glBindVertexArray
|
||||
import org.lwjgl.opengl.ARBVertexArrayObject.glGenVertexArrays
|
||||
import org.lwjgl.opengl.GL11.*
|
||||
import org.lwjgl.opengl.GL15.glBufferData
|
||||
import org.lwjgl.opengl.GL20.glEnableVertexAttribArray
|
||||
import org.lwjgl.opengl.GL20.glVertexAttribPointer
|
||||
import kotlin.reflect.KClass
|
||||
@ -22,8 +24,6 @@ class FloatOpenGLVertexBuffer(override val structure: KClass<*>, data: FloatArra
|
||||
private var vao = -1
|
||||
|
||||
override fun init() {
|
||||
super.init()
|
||||
|
||||
Util.forceClassInit(structure.java)
|
||||
|
||||
val bytesPerVertex = structure.companionObjectInstance!!.unsafeCast<MeshStruct>().BYTES_PER_VERTEX
|
||||
@ -32,9 +32,12 @@ class FloatOpenGLVertexBuffer(override val structure: KClass<*>, data: FloatArra
|
||||
|
||||
vertices = data.size / floatsPerVertex
|
||||
vao = glGenVertexArrays()
|
||||
glBindVertexArray(vao)
|
||||
super.init()
|
||||
super.initialUpload()
|
||||
glBindVertexArray(vao)
|
||||
|
||||
bind()
|
||||
glBufferData(type.gl, data, drawTypes.gl)
|
||||
state = RenderBufferStates.UPLOADED
|
||||
|
||||
_data = null
|
||||
|
||||
@ -61,9 +64,9 @@ class FloatOpenGLVertexBuffer(override val structure: KClass<*>, data: FloatArra
|
||||
get() {
|
||||
return when (this) {
|
||||
PrimitiveTypes.POINT -> GL_POINTS
|
||||
PrimitiveTypes.LINE -> GL_LINE
|
||||
PrimitiveTypes.LINE -> GL_LINES
|
||||
PrimitiveTypes.TRIANGLE -> GL_TRIANGLES
|
||||
PrimitiveTypes.QUADS -> GL_QUADS
|
||||
PrimitiveTypes.QUAD -> GL_QUADS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,8 +53,13 @@ abstract class Mesh(
|
||||
buffer.draw()
|
||||
}
|
||||
|
||||
fun unload(todo: Boolean = false) {
|
||||
buffer.unload()
|
||||
fun unload(ignoreUnloaded: Boolean = false) {
|
||||
if (!this::buffer.isInitialized && !ignoreUnloaded) {
|
||||
error("")
|
||||
}
|
||||
if (this::buffer.isInitialized) {
|
||||
buffer.unload(ignoreUnloaded)
|
||||
}
|
||||
}
|
||||
|
||||
fun addQuad(start: Vec3, end: Vec3, textureStart: Vec2 = Vec2(0.0f, 0.0f), textureEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, textureCoordinate: Vec2) -> Unit) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user