Skip to content

Commit

Permalink
Fixes mipmaps where TEXTURE_BASE/MAX_LEVEL are supported (#1568)
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed May 3, 2023
1 parent 2936f60 commit 420bc49
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,23 @@ class KorgeScreenshotTest {
assertScreenshot()
//println("[5]")
}

@Test
fun testMipmaps() = korgeScreenshotTest(
Size(32, 32),
bgcolor = Colors.BLUE
) {
val bmp = Bitmap32(128, 128).context2d(antialiased = false) {
stroke(Colors.RED, lineWidth = 24f) {
circle(Point(64, 64), 45f)
}
}
val bmp1 = bmp.clone()
val bmp2 = bmp.clone().mipmaps(enable = true)

image(bmp1).scale(0.125).xy(0, 0)
image(bmp2).scale(0.125).xy(16, 0)

assertScreenshot(posterize = 4)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 4 additions & 9 deletions korgw/src/commonMain/kotlin/korlibs/graphics/gl/AGOpengl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -878,11 +878,6 @@ class AGOpengl(val gl: KmlGl, var context: KmlGlContext? = null) : AG() {
gl.pixelStorei(KmlGl.UNPACK_SWAP_BYTES, KmlGl.GTRUE)
}

if (gl.variant.supportTextureLevel) {
gl.texParameteri(texTarget, KmlGl.TEXTURE_BASE_LEVEL, 0)
gl.texParameteri(texTarget, KmlGl.TEXTURE_MAX_LEVEL, 0)
}

when (bmp) {
null -> gl.texImage2D(target.toGl(), 0, type, tex.width, tex.height, 0, type, KmlGl.UNSIGNED_BYTE, null)
is NativeImage -> if (bmp.area != 0) {
Expand All @@ -903,11 +898,11 @@ class AGOpengl(val gl: KmlGl, var context: KmlGlContext? = null) : AG() {

totalSize += tex.width * tex.height * 4

if (gl.variant.supportTextureLevel) {
gl.texParameteri(KmlGl.TEXTURE_2D, KmlGl.TEXTURE_BASE_LEVEL, if (tex.mipmaps) tex.baseMipmapLevel ?: 0 else 0)
gl.texParameteri(KmlGl.TEXTURE_2D, KmlGl.TEXTURE_MAX_LEVEL, if (tex.mipmaps) tex.maxMipmapLevel ?: 1000 else 0)
}
if (tex.mipmaps) {
if (gl.variant.supportTextureLevel) {
tex.baseMipmapLevel?.let { gl.texParameteri(KmlGl.TEXTURE_2D, KmlGl.TEXTURE_BASE_LEVEL, it) }
tex.maxMipmapLevel?.let { gl.texParameteri(KmlGl.TEXTURE_2D, KmlGl.TEXTURE_MAX_LEVEL, it) }
}
gl.generateMipmap(texTarget)
}
}
Expand Down

0 comments on commit 420bc49

Please sign in to comment.