Skip to content

Commit 27510b1

Browse files
committed
Added texture construtor
1 parent aa3377c commit 27510b1

File tree

1 file changed

+17
-0
lines changed
  • common/src/main/kotlin/com/lambda/graphics/texture

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ package com.lambda.graphics.texture
2020
import com.lambda.graphics.texture.TextureUtils.bindTexture
2121
import com.lambda.graphics.texture.TextureUtils.readImage
2222
import com.lambda.graphics.texture.TextureUtils.setupTexture
23+
import com.lambda.util.LambdaResource
24+
import com.lambda.util.readImage
2325
import net.minecraft.client.texture.NativeImage
2426
import org.lwjgl.opengl.GL45C.*
2527
import java.awt.image.BufferedImage
@@ -36,6 +38,21 @@ open class Texture {
3638
private val levels: Int
3739
private val nativeFormat: NativeImage.Format // For mojang native images
3840

41+
/**
42+
* @param path Lambda resource path
43+
* @param format The format of the image passed in
44+
* @param levels Number of mipmap levels to generate for the texture
45+
*/
46+
constructor(path: LambdaResource, format: Int = GL_RGBA, levels: Int = 4) {
47+
val image = path.readImage()
48+
this.format = bufferedMapping[image.type] ?: format
49+
this.levels = levels
50+
this.nativeFormat = nativeMapping.getOrDefault(format, NativeImage.Format.RGBA)
51+
52+
bindTexture(id)
53+
upload(image)
54+
}
55+
3956
/**
4057
* @param image Optional initial image to upload to the texture
4158
* @param format The format of the image passed in, if the [image] is null, then you must pass the appropriate format

0 commit comments

Comments
 (0)