Skip to content

Commit a5333d7

Browse files
committed
internal format texture api
1 parent bbee3b9 commit a5333d7

File tree

1 file changed

+8
-3
lines changed
  • common/src/main/kotlin/com/lambda/graphics/texture

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import java.nio.ByteBuffer
3333
* Represents a texture that can be uploaded and bound to the graphics pipeline
3434
* Supports mipmap generation and LOD (Level of Detail) configuration
3535
*/
36-
open class Texture{
36+
open class Texture {
37+
val internalFormat: Int
3738
val format: Int
3839
private val levels: Int
3940
private val forceConsistency: Boolean
@@ -46,10 +47,12 @@ open class Texture{
4647
* the texture after initialization will throw an exception
4748
*/
4849
constructor(image: BufferedImage?,
50+
internalFormat: Int = GL_RGBA,
4951
format: Int = GL_RGBA,
5052
levels: Int = 4,
5153
forceConsistency: Boolean = false)
5254
{
55+
this.internalFormat = internalFormat
5356
this.format = format
5457
this.levels = levels
5558
this.forceConsistency = forceConsistency
@@ -69,10 +72,12 @@ open class Texture{
6972
constructor(buffer: ByteBuffer,
7073
width: Int,
7174
height: Int,
75+
internalFormat: Int = GL_RGBA,
7276
format: Int = GL_RGBA,
7377
levels: Int = 4,
7478
forceConsistency: Boolean = false)
7579
{
80+
this.internalFormat = internalFormat
7681
this.format = format
7782
this.levels = levels
7883
this.forceConsistency = forceConsistency
@@ -124,7 +129,7 @@ open class Texture{
124129

125130
// Set this mipmap to `offset` to define the original texture
126131
setupTexture(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR)
127-
glTexImage2D(GL_TEXTURE_2D, offset, GL_RGBA, width, height, 0, format, GL_UNSIGNED_BYTE, readImage(image, getNativeFormat(format)))
132+
glTexImage2D(GL_TEXTURE_2D, offset, internalFormat, width, height, 0, format, GL_UNSIGNED_BYTE, readImage(image, getNativeFormat(format)))
128133
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
129134
}
130135

@@ -150,7 +155,7 @@ open class Texture{
150155

151156
// Set this mipmap to `offset` to define the original texture
152157
setupTexture(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR)
153-
glTexImage2D(GL_TEXTURE_2D, offset, GL_RGBA, width, height, 0, format, GL_UNSIGNED_BYTE, buffer)
158+
glTexImage2D(GL_TEXTURE_2D, offset, internalFormat, width, height, 0, format, GL_UNSIGNED_BYTE, buffer)
154159
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
155160
}
156161

0 commit comments

Comments
 (0)