disallow binding of texture array if unloaded + fix

Its simply impossible. Shaders can not be loaded/used when its not loaded.

This fixes and INVALID_OPERATION opengl error
This commit is contained in:
Moritz Zwerger 2023-11-26 19:45:59 +01:00
parent b36e8f7f6a
commit 1f11a66fae
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
9 changed files with 21 additions and 22 deletions

View File

@ -66,10 +66,10 @@ internal object MinosoftSIT {
val worker = TaskWorker() val worker = TaskWorker()
MinosoftBoot.register(worker) MinosoftBoot.register(worker)
worker.minusAssign(BootTasks.PROFILES) worker -= BootTasks.PROFILES
worker.minusAssign(BootTasks.LAN_SERVERS) worker -= BootTasks.LAN_SERVERS
worker.minusAssign(BootTasks.MODS) worker -= BootTasks.MODS
worker.minusAssign(BootTasks.CLI) worker -= BootTasks.CLI
worker.work(MinosoftBoot.LATCH) worker.work(MinosoftBoot.LATCH)
MinosoftBoot.LATCH.dec() MinosoftBoot.LATCH.dec()
MinosoftBoot.LATCH.await() MinosoftBoot.LATCH.await()

View File

@ -57,13 +57,13 @@ class WorldBorderRenderer(
override fun init(latch: AbstractLatch) { override fun init(latch: AbstractLatch) {
shader.native.defines["MAX_DISTANCE"] = MAX_DISTANCE shader.native.defines["MAX_DISTANCE"] = MAX_DISTANCE
shader.load()
texture = context.textures.static.create(TEXTURE) texture = context.textures.static.create(TEXTURE)
context.camera.offset::offset.observe(this) { reload = true } context.camera.offset::offset.observe(this) { reload = true }
} }
override fun postInit(latch: AbstractLatch) { override fun postInit(latch: AbstractLatch) {
shader.load()
context.textures.static.use(shader) context.textures.static.use(shader)
shader.textureIndexLayer = texture.renderData.shaderTextureId shader.textureIndexLayer = texture.renderData.shaderTextureId
} }

View File

@ -31,6 +31,9 @@ class FramebufferManager(
fun init() { fun init() {
world.init() world.init()
gui.init() gui.init()
for (error in context.system.getErrors()) {
println()
}
context.connection.events.listen<ResizeWindowEvent> { context.connection.events.listen<ResizeWindowEvent> {
world.framebuffer.resize(it.size) world.framebuffer.resize(it.size)
@ -39,6 +42,9 @@ class FramebufferManager(
} }
fun postInit() { fun postInit() {
for (error in context.system.getErrors()) {
println()
}
world.postInit() world.postInit()
gui.postInit() gui.postInit()
} }

View File

@ -86,11 +86,8 @@ class WeatherOverlay(private val context: RenderContext) : Overlay {
mesh.load() mesh.load()
} }
override fun init() {
shader.load()
}
override fun postInit() { override fun postInit() {
shader.load()
shader.use() shader.use()
context.textures.static.use(shader) context.textures.static.use(shader)
} }

View File

@ -43,6 +43,8 @@ class OpenGLFontTextureArray(
override fun upload(latch: AbstractLatch?) { override fun upload(latch: AbstractLatch?) {
this.handle = OpenGLTextureUtil.createTextureArray(0) this.handle = OpenGLTextureUtil.createTextureArray(0)
// glTexParameteriv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_RGBA, intArrayOf(GL_LUMINANCE, GL_LUMINANCE, GL_LUMINANCE, GL_LUMINANCE)) // TODO: not working?
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_COMPRESSED_LUMINANCE_ALPHA, RESOLUTION, RESOLUTION, textures.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, null as ByteBuffer?) glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_COMPRESSED_LUMINANCE_ALPHA, RESOLUTION, RESOLUTION, textures.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, null as ByteBuffer?)
for (texture in textures) { for (texture in textures) {
@ -62,6 +64,7 @@ class OpenGLFontTextureArray(
} }
override fun use(shader: NativeShader, name: String) { override fun use(shader: NativeShader, name: String) {
if (state != TextureArrayStates.UPLOADED) throw IllegalStateException("Texture array is not uploaded yet! Are you trying to load a shader in the init phase?")
shader.use() shader.use()
activate() activate()

View File

@ -53,7 +53,7 @@ class OpenGLTextureArray(
private fun upload(resolution: Int, textures: List<Texture>): Int { private fun upload(resolution: Int, textures: List<Texture>): Int {
val textureId = OpenGLTextureUtil.createTextureArray(mipmaps) val handle = OpenGLTextureUtil.createTextureArray(mipmaps)
for (level in 0..mipmaps) { for (level in 0..mipmaps) {
glTexImage3D(GL_TEXTURE_2D_ARRAY, level, GL_RGBA8, resolution shr level, resolution shr level, textures.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, null as ByteBuffer?) glTexImage3D(GL_TEXTURE_2D_ARRAY, level, GL_RGBA8, resolution shr level, resolution shr level, textures.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, null as ByteBuffer?)
@ -70,7 +70,7 @@ class OpenGLTextureArray(
texture.data = TextureData.NULL texture.data = TextureData.NULL
} }
return textureId return handle
} }
@ -98,6 +98,7 @@ class OpenGLTextureArray(
} }
override fun use(shader: NativeShader, name: String) { override fun use(shader: NativeShader, name: String) {
if (state != TextureArrayStates.UPLOADED) throw IllegalStateException("Texture array is not uploaded yet! Are you trying to load a shader in the init phase?")
shader.use() shader.use()
activate() activate()

View File

@ -96,6 +96,7 @@ class OpenGLDynamicTextureArray(
} }
override fun unsafeUse(shader: NativeShader, name: String) { override fun unsafeUse(shader: NativeShader, name: String) {
if (handle <= 0) throw IllegalStateException("Texture array is not uploaded yet! Are you trying to load a shader in the init phase?")
shader.use() shader.use()
activate() activate()
shader.setTexture("$name[$index]", index) shader.setTexture("$name[$index]", index)

View File

@ -15,7 +15,6 @@ package de.bixilon.minosoft.protocol.packets.s2c.play.sign
import de.bixilon.kotlinglm.vec3.Vec3i import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.minosoft.data.entities.block.sign.SignBlockEntity import de.bixilon.minosoft.data.entities.block.sign.SignBlockEntity
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
@ -30,17 +29,9 @@ class SignTextS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
} else { } else {
buffer.readBlockPosition() buffer.readBlockPosition()
} }
val lines: Array<ChatComponent> val lines = Array(SignBlockEntity.LINES) { buffer.readChatComponent() }
init {
val lines: MutableList<ChatComponent> = mutableListOf()
for (i in 0 until SignBlockEntity.LINES) {
lines.add(buffer.readChatComponent())
}
this.lines = lines.toTypedArray()
}
override fun handle(connection: PlayConnection) { override fun handle(connection: PlayConnection) {
val entity = connection.world.getBlockEntity(position)?.unsafeCast<SignBlockEntity>() ?: SignBlockEntity(connection) val entity = connection.world.getBlockEntity(position)?.unsafeCast<SignBlockEntity>() ?: SignBlockEntity(connection)

View File

@ -359,7 +359,7 @@ object KUtil {
} }
@Deprecated("kutil 1.25") @Deprecated("kutil 1.25")
fun TaskWorker.minusAssign(identifier: Any) { operator fun TaskWorker.minusAssign(identifier: Any) {
this::class.java.getDeclaredField("tasks").apply { isAccessible = true }.get(this).unsafeCast<MutableMap<Any, WorkerTask>>().remove(identifier) this::class.java.getDeclaredField("tasks").apply { isAccessible = true }.get(this).unsafeCast<MutableMap<Any, WorkerTask>>().remove(identifier)
} }
} }