Skip to content

Commit 071d238

Browse files
committed
fixed the checks
1 parent 60907be commit 071d238

File tree

1 file changed

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

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,29 @@ import com.lambda.module.modules.client.RenderSettings
2424
import org.lwjgl.opengl.GL11C
2525
import org.lwjgl.opengl.GL45C.*
2626
import java.awt.image.BufferedImage
27+
import java.lang.IllegalStateException
28+
import java.nio.ByteBuffer
2729

2830
/**
29-
* Represents a texture that can be uploaded and bound to the graphics pipeline.
31+
* Represents a texture that can be uploaded and bound to the graphics pipeline
3032
* Supports mipmap generation and LOD (Level of Detail) configuration
3133
*
3234
* @param image Optional initial image to upload to the texture
35+
* @param format The format of the image passed in
3336
* @param levels Number of mipmap levels to generate for the texture
3437
* @param forceConsistency Flag to enforce consistency when updating the texture. If true, attempts to update
3538
* the texture after initialization will throw an exception
3639
*/
3740
open class Texture(
3841
image: BufferedImage?,
42+
val format: Int = GL_RGBA,
3943
private val levels: Int = 4,
4044
private val forceConsistency: Boolean = false,
4145
) {
4246
/**
4347
* Indicates whether there is an initial texture or not
4448
*/
45-
var initialized: Boolean = false; private set
49+
var initialized: Boolean = false; protected set
4650
val id = glGenTextures()
4751

4852
var width = -1; protected set
@@ -63,6 +67,8 @@ open class Texture(
6367
* @param offset The mipmap level to upload the image to
6468
*/
6569
open fun upload(image: BufferedImage, offset: Int = 0) {
70+
if (forceConsistency && initialized) throw IllegalStateException("Client tried to update a texture, but the enforce consistency flag was present")
71+
6672
// Store level_base +1 through `level` images and generate
6773
// mipmaps from them
6874
setupLOD(levels = levels)
@@ -79,10 +85,7 @@ open class Texture(
7985

8086
open fun update(image: BufferedImage, offset: Int = 0) {
8187
if (!initialized) return upload(image, offset)
82-
83-
check(forceConsistency && initialized) {
84-
"Client tried to update a texture, but the enforce consistency flag was present"
85-
}
88+
if (forceConsistency && initialized) throw IllegalStateException("Client tried to update a texture, but the enforce consistency flag was present")
8689

8790
check(image.width + image.height > this.width + this.height && initialized) {
8891
"Client tried to update a texture with more data than allowed" +

0 commit comments

Comments
 (0)