From dc575601a9efa58599343609e78175ecbf68bab8 Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Tue, 28 Nov 2023 00:03:11 +0100 Subject: [PATCH] remove RenderSystem::nativeShaders Should not be exposed publicly as it does not matter. Checking system quality is faster then set contains --- .../minosoft/gui/rendering/system/dummy/DummyRenderSystem.kt | 1 - .../minosoft/gui/rendering/system/base/RenderSystem.kt | 1 - .../gui/rendering/system/opengl/OpenGLNativeShader.kt | 5 ++--- .../gui/rendering/system/opengl/OpenGLRenderSystem.kt | 3 +-- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/dummy/DummyRenderSystem.kt b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/dummy/DummyRenderSystem.kt index 53a92ab8a9..44c52e9751 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/dummy/DummyRenderSystem.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/dummy/DummyRenderSystem.kt @@ -41,7 +41,6 @@ import java.nio.FloatBuffer class DummyRenderSystem( private val context: RenderContext, ) : RenderSystem { - override val nativeShaders: MutableSet = mutableSetOf() override val shaders: MutableSet = mutableSetOf() override lateinit var vendor: GPUVendor override var shader: NativeShader? = null diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/RenderSystem.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/RenderSystem.kt index f1439cb929..85fe49acae 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/RenderSystem.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/RenderSystem.kt @@ -33,7 +33,6 @@ import de.bixilon.minosoft.util.collections.floats.DirectArrayFloatList import java.nio.FloatBuffer interface RenderSystem { - val nativeShaders: MutableSet val shaders: MutableSet val vendor: GPUVendor var shader: NativeShader? diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLNativeShader.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLNativeShader.kt index 573a35b785..d9b0abd2c7 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLNativeShader.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLNativeShader.kt @@ -17,6 +17,7 @@ import de.bixilon.kotlinglm.mat4x4.Mat4 import de.bixilon.kotlinglm.vec2.Vec2 import de.bixilon.kotlinglm.vec3.Vec3 import de.bixilon.kotlinglm.vec4.Vec4 +import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.minosoft.assets.util.InputStreamUtil.readAsString import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.data.text.formatting.color.RGBColor @@ -37,6 +38,7 @@ class OpenGLNativeShader( private val vertex: ResourceLocation, private val geometry: ResourceLocation?, private val fragment: ResourceLocation, + val system: OpenGLRenderSystem = context.system.unsafeCast(), ) : NativeShader { override var loaded: Boolean = false private set @@ -98,8 +100,6 @@ class OpenGLNativeShader( glDeleteShader(program) } loaded = true - - context.system.nativeShaders += this } override fun unload() { @@ -107,7 +107,6 @@ class OpenGLNativeShader( glDeleteProgram(this.handler) loaded = false this.handler = -1 - context.system.nativeShaders -= this } override fun reload() { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLRenderSystem.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLRenderSystem.kt index dc832bb6e8..63c1ed64be 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLRenderSystem.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLRenderSystem.kt @@ -50,7 +50,6 @@ class OpenGLRenderSystem( private val context: RenderContext, ) : RenderSystem { private var thread: Thread? = null - override val nativeShaders: MutableSet = mutableSetOf() override val shaders: MutableSet = mutableSetOf() private val capabilities: MutableSet = RenderingCapabilities.set() override lateinit var vendor: OpenGLVendor @@ -84,7 +83,7 @@ class OpenGLRenderSystem( check(value is OpenGLNativeShader) { "Can not use non OpenGL shader in OpenGL render system!" } check(value.loaded) { "Shader not loaded!" } - check(value in nativeShaders) { "Shader not part of this context!" } + check(this === value.system) { "Shader not part of this context!" } value.unsafeUse()