@@ -45,6 +45,9 @@ open class Texture(
4545 var initialized: Boolean = false ; private set
4646 val id = glGenTextures()
4747
48+ var width = - 1 ; protected set
49+ var height = - 1 ; protected set
50+
4851 /* *
4952 * Binds the texture to a specific slot in the graphics pipeline.
5053 */
@@ -64,8 +67,9 @@ open class Texture(
6467 // mipmaps from them
6568 setupLOD(levels = levels)
6669
67- val width = image.width
68- val height = image.height
70+ width = image.width
71+ height = image.height
72+ initialized = true
6973
7074 // Set this mipmap to `offset` to define the original texture
7175 setupTexture(GL_LINEAR_MIPMAP_LINEAR , GL_LINEAR )
@@ -74,11 +78,16 @@ open class Texture(
7478 }
7579
7680 open fun update (image : BufferedImage , offset : Int = 0) {
77- if (forceConsistency && initialized)
78- throw IllegalStateException (" Client tried to update a texture, but the enforce consistency flag was present" )
81+ if (! initialized) return upload(image, offset)
7982
80- val width = image.width
81- val height = image.height
83+ check(forceConsistency && initialized) {
84+ " Client tried to update a texture, but the enforce consistency flag was present"
85+ }
86+
87+ check(image.width + image.height > this .width + this .height && initialized) {
88+ " Client tried to update a texture with more data than allowed" +
89+ " Expected ${this .width + this .height} bytes but got ${image.width + image.height} "
90+ }
8291
8392 // Can we rebuild LOD ?
8493 glTexSubImage2D(GL_TEXTURE_2D , offset, 0 , 0 , width, height, GL_RGBA , GL_UNSIGNED_BYTE , readImage(image))
@@ -100,8 +109,6 @@ open class Texture(
100109 image?.let {
101110 bind()
102111 upload(it)
103-
104- initialized = true
105112 }
106113 }
107114}
0 commit comments