Skip to content

Commit

Permalink
remove RenderSystem::nativeShaders
Browse files Browse the repository at this point in the history
Should not be exposed publicly as it does not matter. Checking system quality is faster then set contains
  • Loading branch information
Bixilon committed Nov 27, 2023
1 parent c18515f commit dc57560
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import java.nio.FloatBuffer
class DummyRenderSystem(
private val context: RenderContext,
) : RenderSystem {
override val nativeShaders: MutableSet<NativeShader> = mutableSetOf()
override val shaders: MutableSet<Shader> = mutableSetOf()
override lateinit var vendor: GPUVendor
override var shader: NativeShader? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import de.bixilon.minosoft.util.collections.floats.DirectArrayFloatList
import java.nio.FloatBuffer

interface RenderSystem {
val nativeShaders: MutableSet<NativeShader>
val shaders: MutableSet<Shader>
val vendor: GPUVendor
var shader: NativeShader?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -98,16 +100,13 @@ class OpenGLNativeShader(
glDeleteShader(program)
}
loaded = true

context.system.nativeShaders += this
}

override fun unload() {
check(loaded) { "Not loaded!" }
glDeleteProgram(this.handler)
loaded = false
this.handler = -1
context.system.nativeShaders -= this
}

override fun reload() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class OpenGLRenderSystem(
private val context: RenderContext,
) : RenderSystem {
private var thread: Thread? = null
override val nativeShaders: MutableSet<NativeShader> = mutableSetOf()
override val shaders: MutableSet<Shader> = mutableSetOf()
private val capabilities: MutableSet<RenderingCapabilities> = RenderingCapabilities.set()
override lateinit var vendor: OpenGLVendor
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit dc57560

Please sign in to comment.