skin fixes, reload textures command

This commit is contained in:
Moritz Zwerger 2023-11-05 22:57:36 +01:00
parent 2735b824b8
commit f105977d4b
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 29 additions and 8 deletions

View File

@ -19,6 +19,7 @@ import de.bixilon.kotlinglm.vec3.Vec3d
import de.bixilon.minosoft.data.entities.EntityRotation import de.bixilon.minosoft.data.entities.EntityRotation
import de.bixilon.minosoft.gui.rendering.entities.easteregg.EntityEasterEggs.isFlipped 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.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.baked.BakedSkeletalModel
import de.bixilon.minosoft.gui.rendering.skeletal.instance.SkeletalInstance import de.bixilon.minosoft.gui.rendering.skeletal.instance.SkeletalInstance
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.EMPTY import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.EMPTY
@ -64,7 +65,10 @@ open class SkeletalFeature(
} }
override fun draw() { 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) instance.draw(tint)
} }

View File

@ -55,4 +55,8 @@ abstract class TextureManager {
staticTextures.use(shader, name) staticTextures.use(shader, name)
dynamicTextures.use(shader, name) dynamicTextures.use(shader, name)
} }
fun reload() {
dynamicTextures.reload()
}
} }

View File

@ -152,7 +152,7 @@ abstract class DynamicTextureArray(
lock.unlock() lock.unlock()
} }
private fun reload() { fun reload() {
unload() unload()
upload() upload()
this.reload = false this.reload = false

View File

@ -36,6 +36,7 @@ class OpenGLDynamicTextureArray(
initialSize: Int = 32, initialSize: Int = 32,
val resolution: Int, val resolution: Int,
) : DynamicTextureArray(context, initialSize) { ) : DynamicTextureArray(context, initialSize) {
private val empty = IntArray(resolution * resolution) { 0x00 }
private var handle = -1 private var handle = -1
override fun upload(index: Int, texture: DynamicTexture) { override fun upload(index: Int, texture: DynamicTexture) {
@ -49,15 +50,17 @@ class OpenGLDynamicTextureArray(
private fun unsafeUpload(index: Int, texture: DynamicTexture) { private fun unsafeUpload(index: Int, texture: DynamicTexture) {
val data = texture.data ?: throw IllegalArgumentException("No texture data?") val data = texture.data ?: throw IllegalArgumentException("No texture data?")
for ((level, buffer) in data.collect().withIndex()) { 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) if (data.size.x != resolution || data.size.y != resolution) {
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level, 0, 0, index, resolution shr level, resolution shr level, 1, GL_RGBA, GL_UNSIGNED_BYTE, buffer) // 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() { override fun upload() {
if (handle >= 0) throw MemoryLeakException("Texture was not unloaded!") if (handle >= 0) throw MemoryLeakException("Texture was not unloaded!")
val textureId = OpenGLTextureUtil.createTextureArray() val textureId = OpenGLTextureUtil.createTextureArray()
for (level in 0 until OpenGLTextureUtil.MAX_MIPMAP_LEVELS) { 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?) 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 if (texture.data == null) continue
unsafeUpload(index, texture) unsafeUpload(index, texture)
} }
this.handle = textureId
for (shader in shaders) { for (shader in shaders) {
unsafeUse(shader) unsafeUse(shader)
@ -74,7 +78,6 @@ class OpenGLDynamicTextureArray(
context.textures.staticTextures.activate() // TODO: why? context.textures.staticTextures.activate() // TODO: why?
this.handle = textureId
} }
override fun activate() { override fun activate() {

View File

@ -18,7 +18,17 @@ import de.bixilon.minosoft.commands.nodes.LiteralNode
object ReloadCommand : RenderingCommand { object ReloadCommand : RenderingCommand {
override var node = LiteralNode("reload", setOf("rl")) override var node = LiteralNode("reload", setOf("rl"))
.addChild(LiteralNode("shaders", executor = { .addChild(LiteralNode("shaders", executor = {
it.connection.rendering?.context?.system?.reloadShaders() ?: throw IllegalStateException("Rendering is not loaded!") val context = it.connection.rendering?.context ?: throw IllegalStateException("Rendering is not loaded!")
context.queue += {
context.system.reloadShaders()
it.connection.util.sendDebugMessage("Shaders reloaded!") 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!")
}
})) }))
} }