From 19f8a7a7a50e8f94ab216d32242a62500535f1e2 Mon Sep 17 00:00:00 2001 From: Waqas Tahir Date: Wed, 11 Oct 2023 17:11:18 +0500 Subject: [PATCH 1/9] introduce tex sub image 2d --- .../com/danielgergely/kgl/KglAndroid.kt | 16 ++++ .../kotlin/com/danielgergely/kgl/KglJogl.kt | 16 ++++ .../kotlin/com/danielgergely/kgl/KglLwjgl.kt | 78 +++++++++++++++++++ .../kotlin/com/danielgergely/kgl/Kgl.kt | 12 +++ .../kotlin/com/danielgergely/kgl/Kgl.kt | 24 ++++++ 5 files changed, 146 insertions(+) diff --git a/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt b/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt index 6795f56..0a77f83 100644 --- a/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt +++ b/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt @@ -184,6 +184,22 @@ object KglAndroid : Kgl { } } + override fun texSubImage2D( + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int, + buffer: Buffer + ) { + buffer.withJavaBuffer { javaBuffer -> + GL.glTexSubImage2D(target, level, xOffset, yOffset, width, height, format, type, javaBuffer) + } + } + override fun activeTexture(texture: Int) = GL.glActiveTexture(texture) override fun bindTexture(target: Int, texture: Texture?) = GL.glBindTexture(target, texture ?: 0) override fun generateMipmap(target: Int) = GL.glGenerateMipmap(target) diff --git a/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt b/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt index 8b654de..c566773 100644 --- a/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt +++ b/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt @@ -241,6 +241,22 @@ class KglJogl(private val gl: GL) : Kgl { } } + override fun texSubImage2D( + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int, + buffer: Buffer + ) { + buffer.withJavaBuffer { javaBuffer-> + gl.glTexSubImage2D(target, level, xOffset, yOffset, width, height, format, type, javaBuffer) + } + } + override fun activeTexture(texture: Int) = gl.glActiveTexture(texture) override fun bindTexture(target: Int, texture: Texture?) = gl.glBindTexture(target, texture ?: 0) diff --git a/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt b/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt index bde6eba..6844529 100644 --- a/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt +++ b/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt @@ -263,6 +263,84 @@ object KglLwjgl : Kgl { } } + override fun texSubImage2D( + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int, + buffer: Buffer + ) { + buffer.withJavaBuffer { javaBuffer -> + when (javaBuffer) { + is ByteBuffer -> GL.glTexSubImage2D( + target, + level, + xOffset, + yOffset, + width, + height, + format, + type, + javaBuffer + ) + + is ShortBuffer -> GL.glTexSubImage2D( + target, + level, + xOffset, + yOffset, + width, + height, + format, + type, + javaBuffer + ) + + is IntBuffer -> GL.glTexSubImage2D( + target, + level, + xOffset, + yOffset, + width, + height, + format, + type, + javaBuffer + ) + + is FloatBuffer -> GL.glTexSubImage2D( + target, + level, + xOffset, + yOffset, + width, + height, + format, + type, + javaBuffer + ) + + is DoubleBuffer -> GL.glTexSubImage2D( + target, + level, + xOffset, + yOffset, + width, + height, + format, + type, + javaBuffer + ) + + else -> throw IllegalArgumentException("unknown buffer type ${javaBuffer.javaClass}") + } + } + } + override fun texParameteri(target: Int, pname: Int, value: Int) { GL.glTexParameteri(target, pname, value) } diff --git a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Kgl.kt b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Kgl.kt index 56f71c7..1e212e6 100644 --- a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Kgl.kt +++ b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Kgl.kt @@ -85,6 +85,18 @@ public interface Kgl { buffer: Buffer ) + public fun texSubImage2D( + target: Int, + level: Int, + xOffset : Int, + yOffset : Int, + width: Int, + height: Int, + format: Int, + type: Int, + buffer: Buffer + ) + public fun activeTexture(texture: Int) public fun bindTexture(target: Int, texture: Texture?) public fun generateMipmap(target: Int) diff --git a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt index e8e590d..798ac78 100644 --- a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt +++ b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt @@ -170,6 +170,30 @@ public class KglJs(private val gl: WebGLRenderingContext) : Kgl { ) } + override fun texSubImage2D( + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int, + buffer: Buffer + ) { + gl.texSubImage2D( + target, + level, + xOffset, + yOffset, + width, + height, + format, + type, + buffer.getJsBufferWithOffset() + ) + } + public override fun activeTexture(texture: Int): Unit = gl.activeTexture(texture) public override fun bindTexture(target: Int, texture: Texture?): Unit = From 8a8a5c1f38a93920a6a1535887626f73d8c3bff8 Mon Sep 17 00:00:00 2001 From: Waqas Tahir Date: Wed, 11 Oct 2023 18:28:26 +0500 Subject: [PATCH 2/9] seperate desktop and android source sets, keep everything shared in androJvmMain --- kgl/build.gradle.kts | 16 +++++++++++++++- .../kotlin/com/danielgergely/kgl/Buffer.kt | 0 .../kotlin/com/danielgergely/kgl/Types.kt | 0 3 files changed, 15 insertions(+), 1 deletion(-) rename kgl/src/{jvmMain => androJvmMain}/kotlin/com/danielgergely/kgl/Buffer.kt (100%) rename kgl/src/{jvmMain => androJvmMain}/kotlin/com/danielgergely/kgl/Types.kt (100%) diff --git a/kgl/build.gradle.kts b/kgl/build.gradle.kts index ec786ac..85ef1f9 100644 --- a/kgl/build.gradle.kts +++ b/kgl/build.gradle.kts @@ -1,6 +1,7 @@ plugins { kotlin("multiplatform") id("maven-publish") + id("com.android.library") } repositories { @@ -12,6 +13,9 @@ version = currentVersion kotlin { jvm() + androidTarget { + publishLibraryVariants() + } js { browser { @@ -41,11 +45,21 @@ kotlin { implementation(kotlin("test-annotations-common")) } } - val jvmMain by getting { + // android and jvm shared + val androJvmMain by creating { + dependsOn(commonMain) dependencies { implementation(kotlin("stdlib-jdk8")) } } + // desktop jvm + val jvmMain by getting { + dependsOn(androJvmMain) + } + // android jvm + val androidMain by getting { + dependsOn(jvmMain) + } val jvmTest by getting { dependencies { implementation(kotlin("test")) diff --git a/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Buffer.kt b/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Buffer.kt similarity index 100% rename from kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Buffer.kt rename to kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Buffer.kt diff --git a/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt similarity index 100% rename from kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt rename to kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt From 59253e4cf182fdb137b05ff4c3cba9a1b02f2d7b Mon Sep 17 00:00:00 2001 From: Waqas Tahir Date: Wed, 11 Oct 2023 18:33:34 +0500 Subject: [PATCH 3/9] separated modules successfully keeping TextureResource intact --- .idea/inspectionProfiles/Project_Default.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ kgl/build.gradle.kts | 2 +- .../kotlin/com/danielgergely/kgl/Types.kt | 10 ---------- .../kotlin/com/danielgergely/kgl/Types.kt | 13 +++++++++++++ .../jvmMain/kotlin/com/danielgergely/kgl/Types.kt | 13 +++++++++++++ 6 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/modules.xml create mode 100644 kgl/src/androidMain/kotlin/com/danielgergely/kgl/Types.kt create mode 100644 kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..801f533 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8c22b3f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/kgl/build.gradle.kts b/kgl/build.gradle.kts index 85ef1f9..efbd75a 100644 --- a/kgl/build.gradle.kts +++ b/kgl/build.gradle.kts @@ -58,7 +58,7 @@ kotlin { } // android jvm val androidMain by getting { - dependsOn(jvmMain) + dependsOn(androJvmMain) } val jvmTest by getting { dependencies { diff --git a/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt index 8dab421..93e5690 100644 --- a/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt @@ -10,16 +10,6 @@ public actual typealias GlBuffer = Int public actual typealias Texture = Int -public actual class TextureResource( - public val width: Int, - public val height: Int, - public val format: Int, - public val type: Int, - public val data: Buffer, -) { - public actual fun dispose() {} -} - public actual typealias VertexArrayObject = Int public actual typealias Framebuffer = Int diff --git a/kgl/src/androidMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/androidMain/kotlin/com/danielgergely/kgl/Types.kt new file mode 100644 index 0000000..ff1a8e3 --- /dev/null +++ b/kgl/src/androidMain/kotlin/com/danielgergely/kgl/Types.kt @@ -0,0 +1,13 @@ +package com.danielgergely.kgl + +import java.nio.Buffer + +public actual class TextureResource( + public val width: Int, + public val height: Int, + public val format: Int, + public val type: Int, + public val data: Buffer, +) { + public actual fun dispose() {} +} \ No newline at end of file diff --git a/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt new file mode 100644 index 0000000..ff1a8e3 --- /dev/null +++ b/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt @@ -0,0 +1,13 @@ +package com.danielgergely.kgl + +import java.nio.Buffer + +public actual class TextureResource( + public val width: Int, + public val height: Int, + public val format: Int, + public val type: Int, + public val data: Buffer, +) { + public actual fun dispose() {} +} \ No newline at end of file From 7b6409344878ca9fc787e9e88047687bdb086c47 Mon Sep 17 00:00:00 2001 From: Waqas Tahir Date: Wed, 11 Oct 2023 21:04:03 +0500 Subject: [PATCH 4/9] introducing a bitmap texture asset --- .idea/compiler.xml | 2 +- .idea/modules.xml | 2 +- .../com/danielgergely/kgl/KglAndroid.kt | 20 ++++++ .../kotlin/com/danielgergely/kgl/KglJogl.kt | 22 ++++++ .../kotlin/com/danielgergely/kgl/KglLwjgl.kt | 22 ++++++ .../kotlin/com/danielgergely/kgl/Types.kt | 68 +++++++++++++++++++ .../kotlin/com/danielgergely/kgl/Types.kt | 62 ++++++++++++++--- .../kotlin/com/danielgergely/kgl/Kgl.kt | 15 ++++ .../kotlin/com/danielgergely/kgl/Types.kt | 4 +- .../kotlin/com/danielgergely/kgl/Types.kt | 8 ++- .../kotlin/com/danielgergely/kgl/Types.kt | 11 --- .../kotlin/com/danielgergely/kgl/Types.kt | 8 ++- 12 files changed, 216 insertions(+), 28 deletions(-) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fb7f4a8..b589d56 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 8c22b3f..ccd3a77 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt b/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt index 0a77f83..86ab1c3 100644 --- a/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt +++ b/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt @@ -1,7 +1,9 @@ package com.danielgergely.kgl +import android.graphics.Bitmap import android.opengl.GLES20 import android.opengl.GLES30 +import android.opengl.GLUtils typealias GL = GLES20 @@ -200,6 +202,24 @@ object KglAndroid : Kgl { } } + override fun texImage2D(target: Int, level: Int, internalFormat: Int, border: Int, resource: TextureAsset) { + TODO("Not yet implemented") + } + + override fun texSubImage2D( + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int, + resource: TextureAsset + ) { + TODO("Not yet implemented") + } + override fun activeTexture(texture: Int) = GL.glActiveTexture(texture) override fun bindTexture(target: Int, texture: Texture?) = GL.glBindTexture(target, texture ?: 0) override fun generateMipmap(target: Int) = GL.glGenerateMipmap(target) diff --git a/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt b/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt index c566773..19f2f4e 100644 --- a/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt +++ b/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt @@ -211,6 +211,28 @@ class KglJogl(private val gl: GL) : Kgl { override fun deleteTexture(texture: Texture) = gl.glDeleteTextures(1, intArrayOf(texture), 0) + override fun texImage2D(target: Int, level: Int, internalFormat: Int, border: Int, resource: TextureAsset) { + with(resource) { + texImage2D(target, level, internalFormat, border) + } + } + + override fun texSubImage2D( + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int, + resource: TextureAsset + ) { + with(resource){ + texSubImage2D(target, level, xOffset, yOffset, width, height, format, type) + } + } + override fun texImage2D(target: Int, level: Int, internalFormat: Int, border: Int, resource: TextureResource) { texImage2D( target = target, diff --git a/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt b/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt index 6844529..7f89579 100644 --- a/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt +++ b/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt @@ -185,6 +185,28 @@ object KglLwjgl : Kgl { ) } + override fun texImage2D(target: Int, level: Int, internalFormat: Int, border: Int, resource: TextureAsset) { + with(resource) { + texImage2D(target, level, internalFormat, border) + } + } + + override fun texSubImage2D( + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int, + resource: TextureAsset + ) { + with(resource){ + texSubImage2D(target, level, xOffset, yOffset, width, height, format, type) + } + } + override fun texImage2D( target: Int, level: Int, diff --git a/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt index 93e5690..f909060 100644 --- a/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt @@ -15,3 +15,71 @@ public actual typealias VertexArrayObject = Int public actual typealias Framebuffer = Int public actual typealias Renderbuffer = Int + +public actual interface TextureAsset { + + public actual fun dispose() + + public fun Kgl.texImage2D(target: Int, level: Int, internalFormat: Int, border: Int) + + public fun Kgl.texSubImage2D( + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int + ) + +} + +public actual class TextureResource( + public val width: Int, + public val height: Int, + public val format: Int, + public val type: Int, + public val data: Buffer, +) : TextureAsset { + + public override fun dispose() {} + + public override fun Kgl.texImage2D(target: Int, level: Int, internalFormat: Int, border: Int) { + texImage2D( + target = target, + level = level, + internalFormat = internalFormat, + width = width, + height = height, + border = border, + format = format, + type = type, + buffer = data + ) + } + + override fun Kgl.texSubImage2D( + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int + ) { + texSubImage2D( + target, + level, + xOffset, + yOffset, + width, + height, + format, + type, + data + ) + } + +} \ No newline at end of file diff --git a/kgl/src/androidMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/androidMain/kotlin/com/danielgergely/kgl/Types.kt index ff1a8e3..c24fab8 100644 --- a/kgl/src/androidMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/androidMain/kotlin/com/danielgergely/kgl/Types.kt @@ -1,13 +1,55 @@ package com.danielgergely.kgl -import java.nio.Buffer - -public actual class TextureResource( - public val width: Int, - public val height: Int, - public val format: Int, - public val type: Int, - public val data: Buffer, -) { - public actual fun dispose() {} +import android.graphics.Bitmap +import android.opengl.GLUtils + +public class BitmapTextureAsset( + public val bitmap: Bitmap, + public val type: Int = -1, +) : TextureAsset { + + public inline val width: Int get() = bitmap.width + public val height: Int get() = bitmap.height + + public override fun dispose() {} + + override fun Kgl.texImage2D(target: Int, level: Int, internalFormat: Int, border: Int) { + if (internalFormat == -1) { + GLUtils.texImage2D( + target, level, bitmap, border + ) + } else { + if (type == -1) { + GLUtils.texImage2D( + target, level, internalFormat, bitmap, border + ) + } else { + GLUtils.texImage2D( + target, level, internalFormat, bitmap, type, border + ) + } + } + } + + override fun Kgl.texSubImage2D( + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int + ) { + if(format != -1 && type != -1){ + GLUtils.texSubImage2D( + target, level, xOffset, yOffset, bitmap, format, type + ) + } else { + GLUtils.texSubImage2D( + target, level, xOffset, yOffset, bitmap + ) + } + } + } \ No newline at end of file diff --git a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Kgl.kt b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Kgl.kt index 1e212e6..b470578 100644 --- a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Kgl.kt +++ b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Kgl.kt @@ -73,6 +73,21 @@ public interface Kgl { public fun createTextures(n: Int): Array public fun deleteTexture(texture: Texture) public fun texImage2D(target: Int, level: Int, internalFormat: Int, border: Int, resource: TextureResource) + + public fun texImage2D(target: Int, level: Int, internalFormat: Int, border: Int, resource: TextureAsset) + + public fun texSubImage2D( + target: Int, + level: Int, + xOffset : Int, + yOffset : Int, + width: Int, + height: Int, + format: Int, + type: Int, + resource: TextureAsset + ) + public fun texImage2D( target: Int, level: Int, diff --git a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Types.kt index 8eb6473..d51f0ee 100644 --- a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Types.kt @@ -8,10 +8,12 @@ public expect class UniformLocation public expect class GlBuffer -public expect class TextureResource { +public expect interface TextureAsset { public fun dispose() } +public expect class TextureResource : TextureAsset + public expect class Texture public expect class VertexArrayObject diff --git a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt index a46d5d8..fdee3aa 100644 --- a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt @@ -17,8 +17,12 @@ public actual typealias Program = Any */ public actual typealias UniformLocation = Any -public actual open class TextureResource(public val image: TexImageSource) { - public actual open fun dispose() {} +public actual interface TextureAsset { + public actual fun dispose() +} + +public actual open class TextureResource(public val image: TexImageSource) : TextureAsset { + public override fun dispose() {} } /** diff --git a/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt index ff1a8e3..e6e5659 100644 --- a/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt @@ -1,13 +1,2 @@ package com.danielgergely.kgl -import java.nio.Buffer - -public actual class TextureResource( - public val width: Int, - public val height: Int, - public val format: Int, - public val type: Int, - public val data: Buffer, -) { - public actual fun dispose() {} -} \ No newline at end of file diff --git a/kgl/src/nativeMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/nativeMain/kotlin/com/danielgergely/kgl/Types.kt index b1fc133..5cf95ca 100644 --- a/kgl/src/nativeMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/nativeMain/kotlin/com/danielgergely/kgl/Types.kt @@ -11,14 +11,18 @@ public actual typealias GlBuffer = Int public actual typealias Texture = Int +public actual interface TextureAsset { + public actual fun dispose() +} + public actual class TextureResource( public val width: Int, public val height: Int, public val format: Int, public val type: Int, public val data: Buffer, -) { - public actual fun dispose() { +) : TextureAsset { + public override fun dispose() { data.dispose() } } From 59f4425c2b673eb9e4bcc89d53c04190e2a21210 Mon Sep 17 00:00:00 2001 From: Waqas Tahir Date: Wed, 11 Oct 2023 21:23:58 +0500 Subject: [PATCH 5/9] web implementation --- .../kotlin/com/danielgergely/kgl/Kgl.kt | 42 +++++++++++++++++++ .../kotlin/com/danielgergely/kgl/Types.kt | 36 ++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt index 798ac78..c586698 100644 --- a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt +++ b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt @@ -194,6 +194,48 @@ public class KglJs(private val gl: WebGLRenderingContext) : Kgl { ) } + public fun texSubImage2D( + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + format: Int, + type: Int, + resource: TextureResource + ): Unit { + gl.texSubImage2D( + target, + level, + xOffset, + yOffset, + format, + type, + resource.image + ) + } + + override fun texImage2D(target: Int, level: Int, internalFormat: Int, border: Int, resource: TextureAsset) { + with(resource){ + texImage2D(target, level, internalFormat, border) + } + } + + override fun texSubImage2D( + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int, + asset: TextureAsset + ) { + with(asset){ + texSubImage2D(target, level, xOffset, yOffset, width, height, format, type) + } + } + public override fun activeTexture(texture: Int): Unit = gl.activeTexture(texture) public override fun bindTexture(target: Int, texture: Texture?): Unit = diff --git a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt index fdee3aa..e76b4c8 100644 --- a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt @@ -18,11 +18,47 @@ public actual typealias Program = Any public actual typealias UniformLocation = Any public actual interface TextureAsset { + public actual fun dispose() + + public fun Kgl.texImage2D(target: Int, level: Int, internalFormat: Int, border: Int) + + public fun Kgl.texSubImage2D( + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int + ) + } public actual open class TextureResource(public val image: TexImageSource) : TextureAsset { + public override fun dispose() {} + + override fun Kgl.texImage2D(target: Int, level: Int, internalFormat: Int, border: Int) { + texImage2D(target, level, internalFormat, border, this@TextureResource) + } + + override fun Kgl.texSubImage2D( + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int + ) { + (this@texSubImage2D as KglJs).texSubImage2D( + target, level, xOffset, yOffset, format, type, resource = this@TextureResource + ) + } + } /** From 715c32431f892d54ec31ccfdb6f26cbb9d59b1b9 Mon Sep 17 00:00:00 2001 From: Waqas Tahir Date: Wed, 11 Oct 2023 21:45:20 +0500 Subject: [PATCH 6/9] fix not having Kgl as scope to avoid calling wrong functions, fix android implementation --- .../kotlin/com/danielgergely/kgl/KglAndroid.kt | 4 ++-- .../main/kotlin/com/danielgergely/kgl/KglJogl.kt | 8 ++------ .../main/kotlin/com/danielgergely/kgl/KglLwjgl.kt | 8 ++------ .../kotlin/com/danielgergely/kgl/Types.kt | 14 ++++++++------ .../kotlin/com/danielgergely/kgl/Types.kt | 5 +++-- kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt | 10 +++------- .../jsMain/kotlin/com/danielgergely/kgl/Types.kt | 14 ++++++++------ 7 files changed, 28 insertions(+), 35 deletions(-) diff --git a/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt b/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt index 86ab1c3..427dced 100644 --- a/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt +++ b/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt @@ -203,7 +203,7 @@ object KglAndroid : Kgl { } override fun texImage2D(target: Int, level: Int, internalFormat: Int, border: Int, resource: TextureAsset) { - TODO("Not yet implemented") + resource.texImage2D(kgl = this, target, level, internalFormat, border) } override fun texSubImage2D( @@ -217,7 +217,7 @@ object KglAndroid : Kgl { type: Int, resource: TextureAsset ) { - TODO("Not yet implemented") + resource.texSubImage2D(kgl = this, target, level, xOffset, yOffset, width, height, format, type) } override fun activeTexture(texture: Int) = GL.glActiveTexture(texture) diff --git a/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt b/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt index 19f2f4e..d1c1b6f 100644 --- a/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt +++ b/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt @@ -212,9 +212,7 @@ class KglJogl(private val gl: GL) : Kgl { override fun deleteTexture(texture: Texture) = gl.glDeleteTextures(1, intArrayOf(texture), 0) override fun texImage2D(target: Int, level: Int, internalFormat: Int, border: Int, resource: TextureAsset) { - with(resource) { - texImage2D(target, level, internalFormat, border) - } + resource.texImage2D(kgl = this, target, level, internalFormat, border) } override fun texSubImage2D( @@ -228,9 +226,7 @@ class KglJogl(private val gl: GL) : Kgl { type: Int, resource: TextureAsset ) { - with(resource){ - texSubImage2D(target, level, xOffset, yOffset, width, height, format, type) - } + resource.texSubImage2D(kgl = this, target, level, xOffset, yOffset, width, height, format, type) } override fun texImage2D(target: Int, level: Int, internalFormat: Int, border: Int, resource: TextureResource) { diff --git a/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt b/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt index 7f89579..7dfc2ed 100644 --- a/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt +++ b/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt @@ -186,9 +186,7 @@ object KglLwjgl : Kgl { } override fun texImage2D(target: Int, level: Int, internalFormat: Int, border: Int, resource: TextureAsset) { - with(resource) { - texImage2D(target, level, internalFormat, border) - } + resource.texImage2D(kgl = this, target, level, internalFormat, border) } override fun texSubImage2D( @@ -202,9 +200,7 @@ object KglLwjgl : Kgl { type: Int, resource: TextureAsset ) { - with(resource){ - texSubImage2D(target, level, xOffset, yOffset, width, height, format, type) - } + resource.texSubImage2D(kgl = this, target, level, xOffset, yOffset, width, height, format, type) } override fun texImage2D( diff --git a/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt index f909060..108b523 100644 --- a/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt @@ -20,9 +20,10 @@ public actual interface TextureAsset { public actual fun dispose() - public fun Kgl.texImage2D(target: Int, level: Int, internalFormat: Int, border: Int) + public fun texImage2D(kgl : Kgl, target: Int, level: Int, internalFormat: Int, border: Int) - public fun Kgl.texSubImage2D( + public fun texSubImage2D( + kgl : Kgl, target: Int, level: Int, xOffset: Int, @@ -45,8 +46,8 @@ public actual class TextureResource( public override fun dispose() {} - public override fun Kgl.texImage2D(target: Int, level: Int, internalFormat: Int, border: Int) { - texImage2D( + public override fun texImage2D(kgl : Kgl, target: Int, level: Int, internalFormat: Int, border: Int) { + kgl.texImage2D( target = target, level = level, internalFormat = internalFormat, @@ -59,7 +60,8 @@ public actual class TextureResource( ) } - override fun Kgl.texSubImage2D( + override fun texSubImage2D( + kgl : Kgl, target: Int, level: Int, xOffset: Int, @@ -69,7 +71,7 @@ public actual class TextureResource( format: Int, type: Int ) { - texSubImage2D( + kgl.texSubImage2D( target, level, xOffset, diff --git a/kgl/src/androidMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/androidMain/kotlin/com/danielgergely/kgl/Types.kt index c24fab8..e300d42 100644 --- a/kgl/src/androidMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/androidMain/kotlin/com/danielgergely/kgl/Types.kt @@ -13,7 +13,7 @@ public class BitmapTextureAsset( public override fun dispose() {} - override fun Kgl.texImage2D(target: Int, level: Int, internalFormat: Int, border: Int) { + override fun texImage2D(kgl : Kgl, target: Int, level: Int, internalFormat: Int, border: Int) { if (internalFormat == -1) { GLUtils.texImage2D( target, level, bitmap, border @@ -31,7 +31,8 @@ public class BitmapTextureAsset( } } - override fun Kgl.texSubImage2D( + override fun texSubImage2D( + kgl : Kgl, target: Int, level: Int, xOffset: Int, diff --git a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt index c586698..4aa5067 100644 --- a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt +++ b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt @@ -215,9 +215,7 @@ public class KglJs(private val gl: WebGLRenderingContext) : Kgl { } override fun texImage2D(target: Int, level: Int, internalFormat: Int, border: Int, resource: TextureAsset) { - with(resource){ - texImage2D(target, level, internalFormat, border) - } + resource.texImage2D(kgl = this, target, level, internalFormat, border) } override fun texSubImage2D( @@ -229,11 +227,9 @@ public class KglJs(private val gl: WebGLRenderingContext) : Kgl { height: Int, format: Int, type: Int, - asset: TextureAsset + resource: TextureAsset ) { - with(asset){ - texSubImage2D(target, level, xOffset, yOffset, width, height, format, type) - } + resource.texSubImage2D(kgl = this, target, level, xOffset, yOffset, width, height, format, type) } diff --git a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt index e76b4c8..235f5c7 100644 --- a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt @@ -21,9 +21,10 @@ public actual interface TextureAsset { public actual fun dispose() - public fun Kgl.texImage2D(target: Int, level: Int, internalFormat: Int, border: Int) + public fun texImage2D(kgl : Kgl, target: Int, level: Int, internalFormat: Int, border: Int) - public fun Kgl.texSubImage2D( + public fun texSubImage2D( + kgl : Kgl, target: Int, level: Int, xOffset: Int, @@ -40,11 +41,12 @@ public actual open class TextureResource(public val image: TexImageSource) : Tex public override fun dispose() {} - override fun Kgl.texImage2D(target: Int, level: Int, internalFormat: Int, border: Int) { - texImage2D(target, level, internalFormat, border, this@TextureResource) + override fun texImage2D(kgl: Kgl, target: Int, level: Int, internalFormat: Int, border: Int) { + kgl.texImage2D(target, level, internalFormat, border, this@TextureResource) } - override fun Kgl.texSubImage2D( + override fun texSubImage2D( + kgl: Kgl, target: Int, level: Int, xOffset: Int, @@ -54,7 +56,7 @@ public actual open class TextureResource(public val image: TexImageSource) : Tex format: Int, type: Int ) { - (this@texSubImage2D as KglJs).texSubImage2D( + (kgl as KglJs).texSubImage2D( target, level, xOffset, yOffset, format, type, resource = this@TextureResource ) } From a7569284c884b94697be58ab537378440808d22f Mon Sep 17 00:00:00 2001 From: Waqas Tahir Date: Thu, 12 Oct 2023 10:56:58 +0500 Subject: [PATCH 7/9] move types to android --- .../kotlin/com/danielgergely/kgl/Types.kt | 0 kgl/build.gradle.kts | 16 +--- .../kotlin/com/danielgergely/kgl/Types.kt | 87 ------------------- .../kotlin/com/danielgergely/kgl/Buffer.kt | 0 .../kotlin/com/danielgergely/kgl/Types.kt | 85 ++++++++++++++++++ 5 files changed, 86 insertions(+), 102 deletions(-) rename {kgl/src/androidMain => kgl-android/src/main}/kotlin/com/danielgergely/kgl/Types.kt (100%) delete mode 100644 kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt rename kgl/src/{androJvmMain => jvmMain}/kotlin/com/danielgergely/kgl/Buffer.kt (100%) diff --git a/kgl/src/androidMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl-android/src/main/kotlin/com/danielgergely/kgl/Types.kt similarity index 100% rename from kgl/src/androidMain/kotlin/com/danielgergely/kgl/Types.kt rename to kgl-android/src/main/kotlin/com/danielgergely/kgl/Types.kt diff --git a/kgl/build.gradle.kts b/kgl/build.gradle.kts index efbd75a..ec786ac 100644 --- a/kgl/build.gradle.kts +++ b/kgl/build.gradle.kts @@ -1,7 +1,6 @@ plugins { kotlin("multiplatform") id("maven-publish") - id("com.android.library") } repositories { @@ -13,9 +12,6 @@ version = currentVersion kotlin { jvm() - androidTarget { - publishLibraryVariants() - } js { browser { @@ -45,21 +41,11 @@ kotlin { implementation(kotlin("test-annotations-common")) } } - // android and jvm shared - val androJvmMain by creating { - dependsOn(commonMain) + val jvmMain by getting { dependencies { implementation(kotlin("stdlib-jdk8")) } } - // desktop jvm - val jvmMain by getting { - dependsOn(androJvmMain) - } - // android jvm - val androidMain by getting { - dependsOn(androJvmMain) - } val jvmTest by getting { dependencies { implementation(kotlin("test")) diff --git a/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt deleted file mode 100644 index 108b523..0000000 --- a/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Types.kt +++ /dev/null @@ -1,87 +0,0 @@ -package com.danielgergely.kgl - -public actual typealias Shader = Int - -public actual typealias Program = Int - -public actual typealias UniformLocation = Int - -public actual typealias GlBuffer = Int - -public actual typealias Texture = Int - -public actual typealias VertexArrayObject = Int - -public actual typealias Framebuffer = Int - -public actual typealias Renderbuffer = Int - -public actual interface TextureAsset { - - public actual fun dispose() - - public fun texImage2D(kgl : Kgl, target: Int, level: Int, internalFormat: Int, border: Int) - - public fun texSubImage2D( - kgl : Kgl, - target: Int, - level: Int, - xOffset: Int, - yOffset: Int, - width: Int, - height: Int, - format: Int, - type: Int - ) - -} - -public actual class TextureResource( - public val width: Int, - public val height: Int, - public val format: Int, - public val type: Int, - public val data: Buffer, -) : TextureAsset { - - public override fun dispose() {} - - public override fun texImage2D(kgl : Kgl, target: Int, level: Int, internalFormat: Int, border: Int) { - kgl.texImage2D( - target = target, - level = level, - internalFormat = internalFormat, - width = width, - height = height, - border = border, - format = format, - type = type, - buffer = data - ) - } - - override fun texSubImage2D( - kgl : Kgl, - target: Int, - level: Int, - xOffset: Int, - yOffset: Int, - width: Int, - height: Int, - format: Int, - type: Int - ) { - kgl.texSubImage2D( - target, - level, - xOffset, - yOffset, - width, - height, - format, - type, - data - ) - } - -} \ No newline at end of file diff --git a/kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Buffer.kt b/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Buffer.kt similarity index 100% rename from kgl/src/androJvmMain/kotlin/com/danielgergely/kgl/Buffer.kt rename to kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Buffer.kt diff --git a/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt index e6e5659..108b523 100644 --- a/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt @@ -1,2 +1,87 @@ package com.danielgergely.kgl +public actual typealias Shader = Int + +public actual typealias Program = Int + +public actual typealias UniformLocation = Int + +public actual typealias GlBuffer = Int + +public actual typealias Texture = Int + +public actual typealias VertexArrayObject = Int + +public actual typealias Framebuffer = Int + +public actual typealias Renderbuffer = Int + +public actual interface TextureAsset { + + public actual fun dispose() + + public fun texImage2D(kgl : Kgl, target: Int, level: Int, internalFormat: Int, border: Int) + + public fun texSubImage2D( + kgl : Kgl, + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int + ) + +} + +public actual class TextureResource( + public val width: Int, + public val height: Int, + public val format: Int, + public val type: Int, + public val data: Buffer, +) : TextureAsset { + + public override fun dispose() {} + + public override fun texImage2D(kgl : Kgl, target: Int, level: Int, internalFormat: Int, border: Int) { + kgl.texImage2D( + target = target, + level = level, + internalFormat = internalFormat, + width = width, + height = height, + border = border, + format = format, + type = type, + buffer = data + ) + } + + override fun texSubImage2D( + kgl : Kgl, + target: Int, + level: Int, + xOffset: Int, + yOffset: Int, + width: Int, + height: Int, + format: Int, + type: Int + ) { + kgl.texSubImage2D( + target, + level, + xOffset, + yOffset, + width, + height, + format, + type, + data + ) + } + +} \ No newline at end of file From 16ee7f4ffbc51f17d03a9ec710054384cfdda1f7 Mon Sep 17 00:00:00 2001 From: Waqas Tahir Date: Thu, 12 Oct 2023 12:00:27 +0500 Subject: [PATCH 8/9] add isValid to texture asset --- .idea/misc.xml | 2 +- .idea/modules.xml | 8 -------- .../src/main/kotlin/com/danielgergely/kgl/Types.kt | 4 ++++ kgl/src/commonMain/kotlin/com/danielgergely/kgl/Types.kt | 5 +++++ kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt | 2 ++ kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt | 3 +++ kgl/src/nativeMain/kotlin/com/danielgergely/kgl/Types.kt | 4 ++++ 7 files changed, 19 insertions(+), 9 deletions(-) delete mode 100644 .idea/modules.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index c3df9b0..10ceac1 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index ccd3a77..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/kgl-android/src/main/kotlin/com/danielgergely/kgl/Types.kt b/kgl-android/src/main/kotlin/com/danielgergely/kgl/Types.kt index e300d42..ffaba32 100644 --- a/kgl-android/src/main/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl-android/src/main/kotlin/com/danielgergely/kgl/Types.kt @@ -11,6 +11,10 @@ public class BitmapTextureAsset( public inline val width: Int get() = bitmap.width public val height: Int get() = bitmap.height + override fun isValid(): Boolean { + return !bitmap.isRecycled + } + public override fun dispose() {} override fun texImage2D(kgl : Kgl, target: Int, level: Int, internalFormat: Int, border: Int) { diff --git a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Types.kt index d51f0ee..0b5c461 100644 --- a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Types.kt @@ -9,7 +9,12 @@ public expect class UniformLocation public expect class GlBuffer public expect interface TextureAsset { + + /** if asset is valid, isRecycled == false on Android **/ + public fun isValid() : Boolean + public fun dispose() + } public expect class TextureResource : TextureAsset diff --git a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt index 235f5c7..5527a9d 100644 --- a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt @@ -19,6 +19,8 @@ public actual typealias UniformLocation = Any public actual interface TextureAsset { + public actual fun isValid() : Boolean = true + public actual fun dispose() public fun texImage2D(kgl : Kgl, target: Int, level: Int, internalFormat: Int, border: Int) diff --git a/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt index 108b523..8c2a254 100644 --- a/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt @@ -18,6 +18,9 @@ public actual typealias Renderbuffer = Int public actual interface TextureAsset { + /** calls isRecycled on bitmap **/ + public actual fun isValid() : Boolean = true + public actual fun dispose() public fun texImage2D(kgl : Kgl, target: Int, level: Int, internalFormat: Int, border: Int) diff --git a/kgl/src/nativeMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/nativeMain/kotlin/com/danielgergely/kgl/Types.kt index 5cf95ca..fecdc75 100644 --- a/kgl/src/nativeMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/nativeMain/kotlin/com/danielgergely/kgl/Types.kt @@ -12,7 +12,11 @@ public actual typealias GlBuffer = Int public actual typealias Texture = Int public actual interface TextureAsset { + + public actual fun isValid() : Boolean = true + public actual fun dispose() + } public actual class TextureResource( From 7b3ec2c64c1b4cffbb0e675407ee28008e0842ac Mon Sep 17 00:00:00 2001 From: Waqas Tahir Date: Thu, 12 Oct 2023 12:09:14 +0500 Subject: [PATCH 9/9] fix bitmap texture asset isValid() --- kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt | 6 +++++- kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt | 6 +++++- kgl/src/nativeMain/kotlin/com/danielgergely/kgl/Types.kt | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt index 5527a9d..e1f0d48 100644 --- a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Types.kt @@ -19,7 +19,7 @@ public actual typealias UniformLocation = Any public actual interface TextureAsset { - public actual fun isValid() : Boolean = true + public actual fun isValid() : Boolean public actual fun dispose() @@ -41,6 +41,10 @@ public actual interface TextureAsset { public actual open class TextureResource(public val image: TexImageSource) : TextureAsset { + override fun isValid(): Boolean { + return true + } + public override fun dispose() {} override fun texImage2D(kgl: Kgl, target: Int, level: Int, internalFormat: Int, border: Int) { diff --git a/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt index 8c2a254..910f789 100644 --- a/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/jvmMain/kotlin/com/danielgergely/kgl/Types.kt @@ -19,7 +19,7 @@ public actual typealias Renderbuffer = Int public actual interface TextureAsset { /** calls isRecycled on bitmap **/ - public actual fun isValid() : Boolean = true + public actual fun isValid() : Boolean public actual fun dispose() @@ -47,6 +47,10 @@ public actual class TextureResource( public val data: Buffer, ) : TextureAsset { + override fun isValid(): Boolean { + return true + } + public override fun dispose() {} public override fun texImage2D(kgl : Kgl, target: Int, level: Int, internalFormat: Int, border: Int) { diff --git a/kgl/src/nativeMain/kotlin/com/danielgergely/kgl/Types.kt b/kgl/src/nativeMain/kotlin/com/danielgergely/kgl/Types.kt index fecdc75..5e39fc3 100644 --- a/kgl/src/nativeMain/kotlin/com/danielgergely/kgl/Types.kt +++ b/kgl/src/nativeMain/kotlin/com/danielgergely/kgl/Types.kt @@ -13,7 +13,7 @@ public actual typealias Texture = Int public actual interface TextureAsset { - public actual fun isValid() : Boolean = true + public actual fun isValid() : Boolean public actual fun dispose() @@ -26,9 +26,15 @@ public actual class TextureResource( public val type: Int, public val data: Buffer, ) : TextureAsset { + + override fun isValid(): Boolean { + return true + } + public override fun dispose() { data.dispose() } + } public actual typealias VertexArrayObject = Int