@@ -23,6 +23,7 @@ import com.lambda.graphics.texture.TextureUtils.readImage
2323import com.lambda.graphics.texture.TextureUtils.setupTexture
2424import com.lambda.util.math.Rect.Companion.basedOn
2525import com.lambda.util.math.Vec2d
26+ import net.minecraft.client.texture.NativeImage
2627import org.lwjgl.opengl.GL45C.*
2728import java.awt.image.BufferedImage
2829import java.lang.IllegalStateException
@@ -123,7 +124,7 @@ open class Texture{
123124
124125 // Set this mipmap to `offset` to define the original texture
125126 setupTexture(GL_LINEAR_MIPMAP_LINEAR , GL_LINEAR )
126- glTexImage2D(GL_TEXTURE_2D , offset, GL_RGBA , width, height, 0 , format, GL_UNSIGNED_BYTE , readImage(image))
127+ glTexImage2D(GL_TEXTURE_2D , offset, GL_RGBA , width, height, 0 , format, GL_UNSIGNED_BYTE , readImage(image, getNativeFormat(format) ))
127128 if (levels > 1 ) glGenerateMipmap(GL_TEXTURE_2D ) // This take the derived values GL_TEXTURE_BASE_LEVEL and GL_TEXTURE_MAX_LEVEL to generate the stack
128129 }
129130
@@ -171,7 +172,7 @@ open class Texture{
171172 " Expected ${this .width + this .height} bytes but got ${image.width + image.height} "
172173 }
173174
174- glTexSubImage2D(GL_TEXTURE_2D , offset, 0 , 0 , width, height, format, GL_UNSIGNED_BYTE , readImage(image))
175+ glTexSubImage2D(GL_TEXTURE_2D , offset, 0 , 0 , width, height, format, GL_UNSIGNED_BYTE , readImage(image, getNativeFormat(format) ))
175176 }
176177
177178 /* *
@@ -218,4 +219,10 @@ open class Texture{
218219 glTexParameteri(GL_TEXTURE_2D , GL_TEXTURE_BASE_LEVEL , 0 )
219220 glTexParameteri(GL_TEXTURE_2D , GL_TEXTURE_MAX_LEVEL , levels)
220221 }
222+
223+ private fun getNativeFormat (gl : Int ) =
224+ when (gl) {
225+ GL_RGB -> NativeImage .Format .RGB
226+ else -> NativeImage .Format .RGBA
227+ }
221228}
0 commit comments