Skip to content

Commit 1c68158

Browse files
committed
map gl format to native format
1 parent 9350f06 commit 1c68158

File tree

1 file changed

+9
-2
lines changed
  • common/src/main/kotlin/com/lambda/graphics/texture

1 file changed

+9
-2
lines changed

common/src/main/kotlin/com/lambda/graphics/texture/Texture.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.lambda.graphics.texture.TextureUtils.readImage
2323
import com.lambda.graphics.texture.TextureUtils.setupTexture
2424
import com.lambda.util.math.Rect.Companion.basedOn
2525
import com.lambda.util.math.Vec2d
26+
import net.minecraft.client.texture.NativeImage
2627
import org.lwjgl.opengl.GL45C.*
2728
import java.awt.image.BufferedImage
2829
import 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

Comments
 (0)