diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/SkeletalFeature.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/SkeletalFeature.kt index 7de5fdab3..4b995d64a 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/SkeletalFeature.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/SkeletalFeature.kt @@ -19,6 +19,7 @@ import de.bixilon.kotlinglm.vec3.Vec3d import de.bixilon.minosoft.data.entities.EntityRotation import de.bixilon.minosoft.gui.rendering.entities.easteregg.EntityEasterEggs.isFlipped import de.bixilon.minosoft.gui.rendering.entities.renderer.EntityRenderer +import de.bixilon.minosoft.gui.rendering.entities.renderer.living.LivingEntityRenderer import de.bixilon.minosoft.gui.rendering.skeletal.baked.BakedSkeletalModel import de.bixilon.minosoft.gui.rendering.skeletal.instance.SkeletalInstance import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.EMPTY @@ -64,7 +65,10 @@ open class SkeletalFeature( } override fun draw() { - val tint = renderer.light.value.mix(renderer.damage.value) + var tint = renderer.light.value + if (renderer is LivingEntityRenderer<*>) { + tint = tint.mix(renderer.damage.value) + } instance.draw(tint) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/TextureManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/TextureManager.kt index 284d160c9..f851e5c9e 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/TextureManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/TextureManager.kt @@ -55,4 +55,8 @@ abstract class TextureManager { staticTextures.use(shader, name) dynamicTextures.use(shader, name) } + + fun reload() { + dynamicTextures.reload() + } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/dynamic/DynamicTextureArray.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/dynamic/DynamicTextureArray.kt index 4edd8b42c..a648ffd19 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/dynamic/DynamicTextureArray.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/dynamic/DynamicTextureArray.kt @@ -152,7 +152,7 @@ abstract class DynamicTextureArray( lock.unlock() } - private fun reload() { + fun reload() { unload() upload() this.reload = false diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/dynamic/OpenGLDynamicTextureArray.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/dynamic/OpenGLDynamicTextureArray.kt index 432dd908c..a661b6f50 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/dynamic/OpenGLDynamicTextureArray.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/dynamic/OpenGLDynamicTextureArray.kt @@ -36,6 +36,7 @@ class OpenGLDynamicTextureArray( initialSize: Int = 32, val resolution: Int, ) : DynamicTextureArray(context, initialSize) { + private val empty = IntArray(resolution * resolution) { 0x00 } private var handle = -1 override fun upload(index: Int, texture: DynamicTexture) { @@ -49,15 +50,17 @@ class OpenGLDynamicTextureArray( private fun unsafeUpload(index: Int, texture: DynamicTexture) { val data = texture.data ?: throw IllegalArgumentException("No texture data?") for ((level, buffer) in data.collect().withIndex()) { - // glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level, 0, 0, index, texture.size.x shr level, texture.size.y shr level, 1, GL_RGBA, GL_UNSIGNED_BYTE, mipmap) - glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level, 0, 0, index, resolution shr level, resolution shr level, 1, GL_RGBA, GL_UNSIGNED_BYTE, buffer) + if (data.size.x != resolution || data.size.y != resolution) { + // clear first + glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level, 0, 0, index, resolution shr level, resolution shr level, 1, GL_RGBA, GL_UNSIGNED_BYTE, empty) + } + glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level, 0, 0, index, data.size.x shr level, data.size.y shr level, 1, GL_RGBA, GL_UNSIGNED_BYTE, buffer) } } override fun upload() { if (handle >= 0) throw MemoryLeakException("Texture was not unloaded!") val textureId = OpenGLTextureUtil.createTextureArray() - for (level in 0 until OpenGLTextureUtil.MAX_MIPMAP_LEVELS) { glTexImage3D(GL_TEXTURE_2D_ARRAY, level, GL_RGBA, resolution shr level, resolution shr level, textures.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, null as ByteBuffer?) } @@ -67,6 +70,7 @@ class OpenGLDynamicTextureArray( if (texture.data == null) continue unsafeUpload(index, texture) } + this.handle = textureId for (shader in shaders) { unsafeUse(shader) @@ -74,7 +78,6 @@ class OpenGLDynamicTextureArray( context.textures.staticTextures.activate() // TODO: why? - this.handle = textureId } override fun activate() { diff --git a/src/main/java/de/bixilon/minosoft/terminal/commands/rendering/ReloadCommand.kt b/src/main/java/de/bixilon/minosoft/terminal/commands/rendering/ReloadCommand.kt index 29eb344e5..e011ffacc 100644 --- a/src/main/java/de/bixilon/minosoft/terminal/commands/rendering/ReloadCommand.kt +++ b/src/main/java/de/bixilon/minosoft/terminal/commands/rendering/ReloadCommand.kt @@ -18,7 +18,17 @@ import de.bixilon.minosoft.commands.nodes.LiteralNode object ReloadCommand : RenderingCommand { override var node = LiteralNode("reload", setOf("rl")) .addChild(LiteralNode("shaders", executor = { - it.connection.rendering?.context?.system?.reloadShaders() ?: throw IllegalStateException("Rendering is not loaded!") - it.connection.util.sendDebugMessage("Shaders reloaded!") + val context = it.connection.rendering?.context ?: throw IllegalStateException("Rendering is not loaded!") + context.queue += { + context.system.reloadShaders() + it.connection.util.sendDebugMessage("Shaders reloaded!") + } + })) + .addChild(LiteralNode("textures", executor = { + val context = it.connection.rendering?.context ?: throw IllegalStateException("Rendering is not loaded!") + context.queue += { + context.textures.reload() + it.connection.util.sendDebugMessage("Textures reloaded!") + } })) }