From af4b13ef6deb74d49c8ba13948796c5eb7e0a71c Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Mon, 24 Jul 2023 13:13:56 -0700 Subject: [PATCH 1/5] Add uniform[1234][fi]v() for uniform arrays. --- .../com/danielgergely/kgl/KglAndroid.kt | 8 +++ .../kotlin/com.danielgergely.kgl/KglIos.kt | 28 +++++++++++ .../kotlin/com/danielgergely/kgl/KglJogl.kt | 20 ++++++-- .../kotlin/com/danielgergely/kgl/KglLwjgl.kt | 28 +++++++++++ .../kotlin/com/danielgergely/kgl/DebugKgl.kt | 49 +++++++++++++++++++ .../kotlin/com/danielgergely/kgl/Kgl.kt | 7 +++ .../kotlin/com/danielgergely/kgl/Kgl.kt | 21 ++++++++ 7 files changed, 158 insertions(+), 3 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 46e85b7..636a0dc 100644 --- a/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt +++ b/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt @@ -91,21 +91,29 @@ object KglAndroid : Kgl { override fun disable(cap: Int) = GL.glDisable(cap) override fun uniform1f(location: UniformLocation, f: Float) = GL.glUniform1f(location, f) + override fun uniform1fv(location: UniformLocation, value: FloatArray) = GL.glUniform1fv(location, 1, value, 0) override fun uniform1i(location: UniformLocation, i: Int) = GL.glUniform1i(location, i) + override fun uniform1iv(location: UniformLocation, value: IntArray) = GL.glUniform1iv(location, 1, value, 0) override fun uniform2f(location: UniformLocation, x: Float, y: Float) = GL.glUniform2f(location, x, y) + override fun uniform2fv(location: UniformLocation, value: FloatArray) = GL.glUniform2fv(location, 1, value, 0) override fun uniform2i(location: UniformLocation, x: Int, y: Int) = GL.glUniform2i(location, x, y) + override fun uniform2iv(location: UniformLocation, value: IntArray) = GL.glUniform2iv(location, 1, value, 0) override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) = GL.glUniform3f(location, x, y, z) override fun uniform3fv(location: UniformLocation, value: FloatArray) = GL.glUniform3fv(location, 1, value, 0) override fun uniform3i(location: UniformLocation, x: Int, y: Int, z: Int) = GL.glUniform3i(location, x, y, z) + override fun uniform3iv(location: UniformLocation, value: IntArray) = GL.glUniform3iv(location, 1, value, 0) override fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float) = GL.glUniform4f(location, x, y, z, w) + override fun uniform4fv(location: UniformLocation, value: FloatArray) = GL.glUniform4fv(location, 1, value, 0) override fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int) = GL.glUniform4i(location, x, y, z, w) + override fun uniform4iv(location: UniformLocation, value: IntArray) = GL.glUniform4iv(location, 1, value, 0) + override fun uniformMatrix3fv(location: Int, transpose: Boolean, value: FloatArray) = GL.glUniformMatrix3fv(location, 1, transpose, value, 0) diff --git a/kgl-ios/src/nativeMain/kotlin/com.danielgergely.kgl/KglIos.kt b/kgl-ios/src/nativeMain/kotlin/com.danielgergely.kgl/KglIos.kt index 5eae076..f3fb5ee 100644 --- a/kgl-ios/src/nativeMain/kotlin/com.danielgergely.kgl/KglIos.kt +++ b/kgl-ios/src/nativeMain/kotlin/com.danielgergely.kgl/KglIos.kt @@ -199,18 +199,34 @@ object KglIos : Kgl { glUniform1f(location, f) } + override fun uniform1fv(location: UniformLocation, value: FloatArray) { + glUniform1fv(location, 1, value.refTo(0)) + } + override fun uniform1i(location: UniformLocation, i: Int) { glUniform1i(location, i) } + override fun uniform1iv(location: UniformLocation, value: IntArray) { + glUniform1iv(location, 1, value.refTo(0)) + } + override fun uniform2f(location: UniformLocation, x: Float, y: Float) { glUniform2f(location, x, y) } + override fun uniform2fv(location: UniformLocation, value: FloatArray) { + glUniform2fv(location, 1, value.refTo(0)) + } + override fun uniform2i(location: UniformLocation, x: Int, y: Int) { glUniform2i(location, x, y) } + override fun uniform2iv(location: UniformLocation, value: IntArray) { + glUniform2iv(location, 1, value.refTo(0)) + } + override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) { glUniform3f(location, x, y, z) } @@ -223,14 +239,26 @@ object KglIos : Kgl { glUniform3i(location, x, y, z) } + override fun uniform3iv(location: UniformLocation, value: IntArray) { + glUniform3iv(location, 1, value.refTo(0)) + } + override fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float) { glUniform4f(location, x, y, z, w) } + override fun uniform4fv(location: UniformLocation, value: FloatArray) { + glUniform4fv(location, 1, value.refTo(0)) + } + override fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int) { glUniform4i(location, x, y, z, w) } + override fun uniform4iv(location: UniformLocation, value: IntArray) { + glUniform4iv(location, 1, value.refTo(0)) + } + override fun uniformMatrix3fv(location: UniformLocation, transpose: Boolean, value: FloatArray) { glUniformMatrix3fv(location, 1, transpose.toGl(), value.refTo(0)) } 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 d4f00e2..11c63ed 100644 --- a/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt +++ b/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt @@ -144,29 +144,43 @@ class KglJogl(private val gl: GL) : Kgl { override fun uniform1f(location: UniformLocation, f: Float) = gl.glUniform1f(location, f) + override fun uniform1fv(location: UniformLocation, value: FloatArray) = gl.glUniform1fv(location, value.size, value, 0) + override fun uniform1i(location: UniformLocation, i: Int) = gl.glUniform1i(location, i) + override fun uniform1iv(location: UniformLocation, value: IntArray) = gl.glUniform1iv(location, value.size, value, 0) + override fun uniform2f(location: UniformLocation, x: Float, y: Float) = gl.glUniform2f(location, x, y) + override fun uniform2fv(location: UniformLocation, value: FloatArray) = gl.glUniform2fv(location, value.size, value, 0) + override fun uniform2i(location: UniformLocation, x: Int, y: Int) = gl.glUniform2i(location, x, y) + override fun uniform2iv(location: UniformLocation, value: IntArray) = gl.glUniform2iv(location, value.size, value, 0) + override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) = gl.glUniform3f(location, x, y, z) - override fun uniform3fv(location: UniformLocation, value: FloatArray) = gl.glUniform3fv(location, 1, value, 0) + override fun uniform3fv(location: UniformLocation, value: FloatArray) = gl.glUniform3fv(location, value.size, value, 0) override fun uniform3i(location: UniformLocation, x: Int, y: Int, z: Int) = gl.glUniform3i(location, x, y, z) + override fun uniform3iv(location: UniformLocation, value: IntArray) = gl.glUniform3iv(location, value.size, value, 0) + override fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float) = gl.glUniform4f(location, x, y, z, w) + override fun uniform4fv(location: UniformLocation, value: FloatArray) = gl.glUniform4fv(location, value.size, value, 0) + override fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int) = gl.glUniform4i(location, x, y, z, w) + override fun uniform4iv(location: UniformLocation, value: IntArray) = gl.glUniform4iv(location, value.size, value, 0) + override fun uniformMatrix3fv(location: UniformLocation, transpose: Boolean, value: FloatArray) = - gl.glUniformMatrix3fv(location, 1, transpose, value, 0) + gl.glUniformMatrix3fv(location, value.size, transpose, value, 0) override fun uniformMatrix4fv(location: UniformLocation, transpose: Boolean, value: FloatArray) = - gl.glUniformMatrix4fv(location, 1, transpose, value, 0) + gl.glUniformMatrix4fv(location, value.size, transpose, value, 0) override fun blendFunc(sFactor: Int, dFactor: Int) = gl.glBlendFunc(sFactor, dFactor) 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 8d743ec..fce47d4 100644 --- a/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt +++ b/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt @@ -271,18 +271,34 @@ object KglLwjgl : Kgl { GL.glUniform1f(location, f) } + override fun uniform1fv(location: UniformLocation, value: FloatArray) { + GL.glUniform1fv(location, value) + } + override fun uniform1i(location: UniformLocation, i: Int) { GL.glUniform1i(location, i) } + override fun uniform1iv(location: UniformLocation, value: IntArray) { + GL.glUniform1iv(location, value) + } + override fun uniform2f(location: UniformLocation, x: Float, y: Float) { GL.glUniform2f(location, x, y) } + override fun uniform2fv(location: UniformLocation, value: FloatArray) { + GL.glUniform2fv(location, value) + } + override fun uniform2i(location: UniformLocation, x: Int, y: Int) { GL.glUniform2i(location, x, y) } + override fun uniform2iv(location: UniformLocation, value: IntArray) { + GL.glUniform2iv(location, value) + } + override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) { GL.glUniform3f(location, x, y, z) } @@ -295,14 +311,26 @@ object KglLwjgl : Kgl { GL.glUniform3i(location, x, y, z) } + override fun uniform3iv(location: UniformLocation, value: IntArray) { + GL.glUniform3iv(location, value) + } + override fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float) { GL.glUniform4f(location, x, y, z, w) } + override fun uniform4fv(location: UniformLocation, value: FloatArray) { + GL.glUniform4fv(location, value) + } + override fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int) { GL.glUniform4i(location, x, y, z, w) } + override fun uniform4iv(location: UniformLocation, value: IntArray) { + GL.glUniform4iv(location, value) + } + override fun uniformMatrix3fv(location: UniformLocation, transpose: Boolean, value: FloatArray) { GL.glUniformMatrix3fv(location, transpose, value) } diff --git a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/DebugKgl.kt b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/DebugKgl.kt index d6644ac..acb96dc 100644 --- a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/DebugKgl.kt +++ b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/DebugKgl.kt @@ -209,6 +209,13 @@ public class DebugKgl( return ret } + override fun uniform1fv(location: UniformLocation, value: FloatArray) { + runBefore("uniform1fv") + val ret = kgl.uniform1fv(location, value) + runAfter("uniform1fv") + return ret + } + override fun uniform1i(location: UniformLocation, i: Int) { runBefore("uniform1i") val ret = kgl.uniform1i(location, i) @@ -216,6 +223,13 @@ public class DebugKgl( return ret } + override fun uniform1iv(location: UniformLocation, value: IntArray) { + runBefore("uniform1iv") + val ret = kgl.uniform1iv(location, value) + runAfter("uniform1iv") + return ret + } + override fun uniform2f(location: UniformLocation, x: Float, y: Float) { runBefore("uniform2f") val ret = kgl.uniform2f(location, x, y) @@ -223,6 +237,13 @@ public class DebugKgl( return ret } + override fun uniform2fv(location: UniformLocation, value: FloatArray) { + runBefore("uniform2fv") + val ret = kgl.uniform2fv(location, value) + runAfter("uniform2fv") + return ret + } + override fun uniform2i(location: UniformLocation, x: Int, y: Int) { runBefore("uniform2i") val ret = kgl.uniform2i(location, x, y) @@ -230,6 +251,13 @@ public class DebugKgl( return ret } + override fun uniform2iv(location: UniformLocation, value: IntArray) { + runBefore("uniform2iv") + val ret = kgl.uniform2iv(location, value) + runAfter("uniform2iv") + return ret + } + override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) { runBefore("uniform3f") val ret = kgl.uniform3f(location, x, y, z) @@ -251,6 +279,13 @@ public class DebugKgl( return ret } + override fun uniform3iv(location: UniformLocation, value: IntArray) { + runBefore("uniform3iv") + val ret = kgl.uniform3iv(location, value) + runAfter("uniform3iv") + return ret + } + override fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float) { runBefore("uniform4f") val ret = kgl.uniform4f(location, x, y, z, w) @@ -258,6 +293,13 @@ public class DebugKgl( return ret } + override fun uniform4fv(location: UniformLocation, value: FloatArray) { + runBefore("uniform4fv") + val ret = kgl.uniform4fv(location, value) + runAfter("uniform4fv") + return ret + } + override fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int) { runBefore("uniform4i") val ret = kgl.uniform4i(location, x, y, z, w) @@ -265,6 +307,13 @@ public class DebugKgl( return ret } + override fun uniform4iv(location: UniformLocation, value: IntArray) { + runBefore("uniform4iv") + val ret = kgl.uniform4iv(location, value) + runAfter("uniform4iv") + return ret + } + override fun uniformMatrix3fv(location: UniformLocation, transpose: Boolean, value: FloatArray) { runBefore("uniformMatrix3fv") val ret = kgl.uniformMatrix3fv(location, transpose, value) diff --git a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Kgl.kt b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Kgl.kt index c2a335e..56f71c7 100644 --- a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Kgl.kt +++ b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Kgl.kt @@ -39,17 +39,24 @@ public interface Kgl { public fun vertexAttribPointer(location: Int, size: Int, type: Int, normalized: Boolean, stride: Int, offset: Int) public fun uniform1f(location: UniformLocation, f: Float) + public fun uniform1fv(location: UniformLocation, value: FloatArray) public fun uniform1i(location: UniformLocation, i: Int) + public fun uniform1iv(location: UniformLocation, value: IntArray) public fun uniform2f(location: UniformLocation, x: Float, y: Float) + public fun uniform2fv(location: UniformLocation, value: FloatArray) public fun uniform2i(location: UniformLocation, x: Int, y: Int) + public fun uniform2iv(location: UniformLocation, value: IntArray) public fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) public fun uniform3fv(location: UniformLocation, value: FloatArray) public fun uniform3i(location: UniformLocation, x: Int, y: Int, z: Int) + public fun uniform3iv(location: UniformLocation, value: IntArray) public fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float) + public fun uniform4fv(location: UniformLocation, value: FloatArray) public fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int) + public fun uniform4iv(location: UniformLocation, value: IntArray) public fun uniformMatrix3fv(location: UniformLocation, transpose: Boolean, value: FloatArray) public fun uniformMatrix4fv(location: UniformLocation, transpose: Boolean, value: FloatArray) diff --git a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt index 28881a3..8a9bd27 100644 --- a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt +++ b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt @@ -88,15 +88,27 @@ public class KglJs(private val gl: WebGLRenderingContext) : Kgl { public override fun uniform1f(location: UniformLocation, f: Float): Unit = gl.uniform1f(location.unsafeCast(), f) + public override fun uniform1fv(location: UniformLocation, value: FloatArray): Unit = + gl.uniform1fv(location.unsafeCast(), value.unsafeCast()) + public override fun uniform1i(location: UniformLocation, i: Int): Unit = gl.uniform1i(location.unsafeCast(), i) + public override fun uniform1iv(location: UniformLocation, value: IntArray): Unit = + gl.uniform1iv(location.unsafeCast(), value.unsafeCast()) + public override fun uniform2f(location: UniformLocation, x: Float, y: Float): Unit = gl.uniform2f(location.unsafeCast(), x, y) + public override fun uniform2fv(location: UniformLocation, value: FloatArray): Unit = + gl.uniform2fv(location.unsafeCast(), value.unsafeCast()) + public override fun uniform2i(location: UniformLocation, x: Int, y: Int): Unit = gl.uniform2i(location.unsafeCast(), x, y) + public override fun uniform2iv(location: UniformLocation, value: IntArray): Unit = + gl.uniform2iv(location.unsafeCast(), value.unsafeCast()) + public override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float): Unit = gl.uniform3f(location.unsafeCast(), x, y, z) @@ -106,12 +118,21 @@ public class KglJs(private val gl: WebGLRenderingContext) : Kgl { public override fun uniform3i(location: UniformLocation, x: Int, y: Int, z: Int): Unit = gl.uniform3i(location.unsafeCast(), x, y, z) + public override fun uniform3iv(location: UniformLocation, value: IntArray): Unit = + gl.uniform3iv(location.unsafeCast(), value.unsafeCast()) + public override fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float): Unit = gl.uniform4f(location.unsafeCast(), x, y, z, w) + public override fun uniform4fv(location: UniformLocation, value: FloatArray): Unit = + gl.uniform4fv(location.unsafeCast(), value.unsafeCast()) + public override fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int): Unit = gl.uniform4i(location.unsafeCast(), x, y, z, w) + public override fun uniform4iv(location: UniformLocation, value: IntArray): Unit = + gl.uniform4iv(location.unsafeCast(), value.unsafeCast()) + public override fun uniformMatrix3fv(location: UniformLocation, transpose: Boolean, value: dynamic) { gl.uniformMatrix3fv(location.unsafeCast(), transpose, value.unsafeCast()) } From 87c6beea2facd4f8e5090a71236dcf41b4e13da0 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Mon, 31 Jul 2023 21:51:24 -0700 Subject: [PATCH 2/5] Fix JOGL implementation of uniform*v. --- .../src/main/kotlin/com/danielgergely/kgl/KglJogl.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 11c63ed..c6b32f9 100644 --- a/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt +++ b/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt @@ -152,29 +152,29 @@ class KglJogl(private val gl: GL) : Kgl { override fun uniform2f(location: UniformLocation, x: Float, y: Float) = gl.glUniform2f(location, x, y) - override fun uniform2fv(location: UniformLocation, value: FloatArray) = gl.glUniform2fv(location, value.size, value, 0) + override fun uniform2fv(location: UniformLocation, value: FloatArray) = gl.glUniform2fv(location, value.size / 2, value, 0) override fun uniform2i(location: UniformLocation, x: Int, y: Int) = gl.glUniform2i(location, x, y) - override fun uniform2iv(location: UniformLocation, value: IntArray) = gl.glUniform2iv(location, value.size, value, 0) + override fun uniform2iv(location: UniformLocation, value: IntArray) = gl.glUniform2iv(location, value.size / 2, value, 0) override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) = gl.glUniform3f(location, x, y, z) - override fun uniform3fv(location: UniformLocation, value: FloatArray) = gl.glUniform3fv(location, value.size, value, 0) + override fun uniform3fv(location: UniformLocation, value: FloatArray) = gl.glUniform3fv(location, value.size / 3, value, 0) override fun uniform3i(location: UniformLocation, x: Int, y: Int, z: Int) = gl.glUniform3i(location, x, y, z) - override fun uniform3iv(location: UniformLocation, value: IntArray) = gl.glUniform3iv(location, value.size, value, 0) + override fun uniform3iv(location: UniformLocation, value: IntArray) = gl.glUniform3iv(location, value.size / 3, value, 0) override fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float) = gl.glUniform4f(location, x, y, z, w) - override fun uniform4fv(location: UniformLocation, value: FloatArray) = gl.glUniform4fv(location, value.size, value, 0) + override fun uniform4fv(location: UniformLocation, value: FloatArray) = gl.glUniform4fv(location, value.size / 4, value, 0) override fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int) = gl.glUniform4i(location, x, y, z, w) - override fun uniform4iv(location: UniformLocation, value: IntArray) = gl.glUniform4iv(location, value.size, value, 0) + override fun uniform4iv(location: UniformLocation, value: IntArray) = gl.glUniform4iv(location, value.size / 4, value, 0) override fun uniformMatrix3fv(location: UniformLocation, transpose: Boolean, value: FloatArray) = gl.glUniformMatrix3fv(location, value.size, transpose, value, 0) From 400177d665cabd26161f8bf66985fa366c4f3984 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Tue, 1 Aug 2023 09:46:25 -0700 Subject: [PATCH 3/5] Fix calculation of uniform*v count on JOGL, Android, and iOS. --- .../com/danielgergely/kgl/KglAndroid.kt | 53 +++++++----- .../kotlin/com.danielgergely.kgl/KglIos.kt | 86 ++++++------------- .../kotlin/com/danielgergely/kgl/KglJogl.kt | 63 +++++++------- .../kotlin/com/danielgergely/kgl/Util.kt | 13 +++ 4 files changed, 105 insertions(+), 110 deletions(-) create mode 100644 kgl/src/commonMain/kotlin/com/danielgergely/kgl/Util.kt 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 636a0dc..94a34f0 100644 --- a/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt +++ b/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt @@ -90,35 +90,46 @@ object KglAndroid : Kgl { override fun enable(cap: Int) = GL.glEnable(cap) override fun disable(cap: Int) = GL.glDisable(cap) - override fun uniform1f(location: UniformLocation, f: Float) = GL.glUniform1f(location, f) - override fun uniform1fv(location: UniformLocation, value: FloatArray) = GL.glUniform1fv(location, 1, value, 0) - override fun uniform1i(location: UniformLocation, i: Int) = GL.glUniform1i(location, i) - override fun uniform1iv(location: UniformLocation, value: IntArray) = GL.glUniform1iv(location, 1, value, 0) - - override fun uniform2f(location: UniformLocation, x: Float, y: Float) = GL.glUniform2f(location, x, y) - override fun uniform2fv(location: UniformLocation, value: FloatArray) = GL.glUniform2fv(location, 1, value, 0) - override fun uniform2i(location: UniformLocation, x: Int, y: Int) = GL.glUniform2i(location, x, y) - override fun uniform2iv(location: UniformLocation, value: IntArray) = GL.glUniform2iv(location, 1, value, 0) - - override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) = GL.glUniform3f(location, x, y, z) - override fun uniform3fv(location: UniformLocation, value: FloatArray) = GL.glUniform3fv(location, 1, value, 0) - override fun uniform3i(location: UniformLocation, x: Int, y: Int, z: Int) = GL.glUniform3i(location, x, y, z) - override fun uniform3iv(location: UniformLocation, value: IntArray) = GL.glUniform3iv(location, 1, value, 0) + override fun uniform1f(location: UniformLocation, f: Float) = + GL.glUniform1f(location, f) + override fun uniform1fv(location: UniformLocation, value: FloatArray) = + GL.glUniform1fv(location, value.vSize(1), value, 0) + override fun uniform1i(location: UniformLocation, i: Int) = + GL.glUniform1i(location, i) + override fun uniform1iv(location: UniformLocation, value: IntArray) = + GL.glUniform1iv(location, value.vSize(1), value, 0) + + override fun uniform2f(location: UniformLocation, x: Float, y: Float) = + GL.glUniform2f(location, x, y) + override fun uniform2fv(location: UniformLocation, value: FloatArray) = + GL.glUniform2fv(location, value.vSize(2), value, 0) + override fun uniform2i(location: UniformLocation, x: Int, y: Int) = + GL.glUniform2i(location, x, y) + override fun uniform2iv(location: UniformLocation, value: IntArray) = + GL.glUniform2iv(location, value.vSize(2), value, 0) + + override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) = + GL.glUniform3f(location, x, y, z) + override fun uniform3fv(location: UniformLocation, value: FloatArray) = + GL.glUniform3fv(location, value.vSize(3), value, 0) + override fun uniform3i(location: UniformLocation, x: Int, y: Int, z: Int) = + GL.glUniform3i(location, x, y, z) + override fun uniform3iv(location: UniformLocation, value: IntArray) = + GL.glUniform3iv(location, value.vSize(3), value, 0) override fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float) = GL.glUniform4f(location, x, y, z, w) - - override fun uniform4fv(location: UniformLocation, value: FloatArray) = GL.glUniform4fv(location, 1, value, 0) + override fun uniform4fv(location: UniformLocation, value: FloatArray) = + GL.glUniform4fv(location, value.vSize(4), value, 0) override fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int) = GL.glUniform4i(location, x, y, z, w) - - override fun uniform4iv(location: UniformLocation, value: IntArray) = GL.glUniform4iv(location, 1, value, 0) + override fun uniform4iv(location: UniformLocation, value: IntArray) = + GL.glUniform4iv(location, value.vSize(4), value, 0) override fun uniformMatrix3fv(location: Int, transpose: Boolean, value: FloatArray) = - GL.glUniformMatrix3fv(location, 1, transpose, value, 0) - + GL.glUniformMatrix3fv(location, value.vSize(3*3), transpose, value, 0) override fun uniformMatrix4fv(location: Int, transpose: Boolean, value: FloatArray) = - GL.glUniformMatrix4fv(location, 1, transpose, value, 0) + GL.glUniformMatrix4fv(location, value.vSize(4*4), transpose, value, 0) override fun blendFunc(sFactor: Int, dFactor: Int) = GL.glBlendFunc(sFactor, dFactor) diff --git a/kgl-ios/src/nativeMain/kotlin/com.danielgergely.kgl/KglIos.kt b/kgl-ios/src/nativeMain/kotlin/com.danielgergely.kgl/KglIos.kt index f3fb5ee..69dadc8 100644 --- a/kgl-ios/src/nativeMain/kotlin/com.danielgergely.kgl/KglIos.kt +++ b/kgl-ios/src/nativeMain/kotlin/com.danielgergely.kgl/KglIos.kt @@ -195,77 +195,47 @@ object KglIos : Kgl { ) } - override fun uniform1f(location: UniformLocation, f: Float) { + override fun uniform1f(location: UniformLocation, f: Float) = glUniform1f(location, f) - } - - override fun uniform1fv(location: UniformLocation, value: FloatArray) { - glUniform1fv(location, 1, value.refTo(0)) - } - - override fun uniform1i(location: UniformLocation, i: Int) { + override fun uniform1fv(location: UniformLocation, value: FloatArray) = + glUniform1fv(location, value.vSize(1), value.refTo(0)) + override fun uniform1i(location: UniformLocation, i: Int) = glUniform1i(location, i) - } - - override fun uniform1iv(location: UniformLocation, value: IntArray) { - glUniform1iv(location, 1, value.refTo(0)) - } + override fun uniform1iv(location: UniformLocation, value: IntArray) = + glUniform1iv(location, value.vSize(1), value.refTo(0)) - override fun uniform2f(location: UniformLocation, x: Float, y: Float) { + override fun uniform2f(location: UniformLocation, x: Float, y: Float) = glUniform2f(location, x, y) - } - - override fun uniform2fv(location: UniformLocation, value: FloatArray) { - glUniform2fv(location, 1, value.refTo(0)) - } - - override fun uniform2i(location: UniformLocation, x: Int, y: Int) { + override fun uniform2fv(location: UniformLocation, value: FloatArray) = + glUniform2fv(location, value.vSize(2), value.refTo(0)) + override fun uniform2i(location: UniformLocation, x: Int, y: Int) = glUniform2i(location, x, y) - } + override fun uniform2iv(location: UniformLocation, value: IntArray) = + glUniform2iv(location, value.vSize(2), value.refTo(0)) - override fun uniform2iv(location: UniformLocation, value: IntArray) { - glUniform2iv(location, 1, value.refTo(0)) - } - - override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) { + override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) = glUniform3f(location, x, y, z) - } - - override fun uniform3fv(location: UniformLocation, value: FloatArray) { - glUniform3fv(location, 1, value.refTo(0)) - } - - override fun uniform3i(location: UniformLocation, x: Int, y: Int, z: Int) { + override fun uniform3fv(location: UniformLocation, value: FloatArray) = + glUniform3fv(location, value.vSize(3), value.refTo(0)) + override fun uniform3i(location: UniformLocation, x: Int, y: Int, z: Int) = glUniform3i(location, x, y, z) - } + override fun uniform3iv(location: UniformLocation, value: IntArray) = + glUniform3iv(location, value.vSize(3), value.refTo(0)) - override fun uniform3iv(location: UniformLocation, value: IntArray) { - glUniform3iv(location, 1, value.refTo(0)) - } - - override fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float) { + override fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float) = glUniform4f(location, x, y, z, w) - } - - override fun uniform4fv(location: UniformLocation, value: FloatArray) { - glUniform4fv(location, 1, value.refTo(0)) - } - - override fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int) { + override fun uniform4fv(location: UniformLocation, value: FloatArray) = + glUniform4fv(location, value.vSize(4), value.refTo(0)) + override fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int) = glUniform4i(location, x, y, z, w) - } + override fun uniform4iv(location: UniformLocation, value: IntArray) = + glUniform4iv(location, value.vSize(4), value.refTo(0)) - override fun uniform4iv(location: UniformLocation, value: IntArray) { - glUniform4iv(location, 1, value.refTo(0)) - } + override fun uniformMatrix3fv(location: UniformLocation, transpose: Boolean, value: FloatArray) = + glUniformMatrix3fv(location, value.vSize(3*3), transpose.toGl(), value.refTo(0)) - override fun uniformMatrix3fv(location: UniformLocation, transpose: Boolean, value: FloatArray) { - glUniformMatrix3fv(location, 1, transpose.toGl(), value.refTo(0)) - } - - override fun uniformMatrix4fv(location: UniformLocation, transpose: Boolean, value: FloatArray) { - glUniformMatrix4fv(location, 1, transpose.toGl(), value.refTo(0)) - } + override fun uniformMatrix4fv(location: UniformLocation, transpose: Boolean, value: FloatArray) = + glUniformMatrix4fv(location, value.vSize(4*4), transpose.toGl(), value.refTo(0)) override fun blendFunc(sFactor: Int, dFactor: Int) { glBlendFunc(sFactor.toUInt(), dFactor.toUInt()) 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 c6b32f9..2cca52d 100644 --- a/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt +++ b/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt @@ -142,45 +142,46 @@ class KglJogl(private val gl: GL) : Kgl { return gl.glVertexAttribPointer(location, size, type, normalized, stride, offset.toLong()) } - override fun uniform1f(location: UniformLocation, f: Float) = gl.glUniform1f(location, f) - - override fun uniform1fv(location: UniformLocation, value: FloatArray) = gl.glUniform1fv(location, value.size, value, 0) - - override fun uniform1i(location: UniformLocation, i: Int) = gl.glUniform1i(location, i) - - override fun uniform1iv(location: UniformLocation, value: IntArray) = gl.glUniform1iv(location, value.size, value, 0) - - override fun uniform2f(location: UniformLocation, x: Float, y: Float) = gl.glUniform2f(location, x, y) - - override fun uniform2fv(location: UniformLocation, value: FloatArray) = gl.glUniform2fv(location, value.size / 2, value, 0) - - override fun uniform2i(location: UniformLocation, x: Int, y: Int) = gl.glUniform2i(location, x, y) - - override fun uniform2iv(location: UniformLocation, value: IntArray) = gl.glUniform2iv(location, value.size / 2, value, 0) - - override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) = gl.glUniform3f(location, x, y, z) - - override fun uniform3fv(location: UniformLocation, value: FloatArray) = gl.glUniform3fv(location, value.size / 3, value, 0) - - override fun uniform3i(location: UniformLocation, x: Int, y: Int, z: Int) = gl.glUniform3i(location, x, y, z) - - override fun uniform3iv(location: UniformLocation, value: IntArray) = gl.glUniform3iv(location, value.size / 3, value, 0) + override fun uniform1f(location: UniformLocation, f: Float) = + gl.glUniform1f(location, f) + override fun uniform1fv(location: UniformLocation, value: FloatArray) = + gl.glUniform1fv(location, value.vSize(1), value, 0) + override fun uniform1i(location: UniformLocation, i: Int) = + gl.glUniform1i(location, i) + override fun uniform1iv(location: UniformLocation, value: IntArray) = + gl.glUniform1iv(location, value.vSize(1), value, 0) + + override fun uniform2f(location: UniformLocation, x: Float, y: Float) = + gl.glUniform2f(location, x, y) + override fun uniform2fv(location: UniformLocation, value: FloatArray) = + gl.glUniform2fv(location, value.vSize(2), value, 0) + override fun uniform2i(location: UniformLocation, x: Int, y: Int) = + gl.glUniform2i(location, x, y) + override fun uniform2iv(location: UniformLocation, value: IntArray) = + gl.glUniform2iv(location, value.vSize(2), value, 0) + + override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) = + gl.glUniform3f(location, x, y, z) + override fun uniform3fv(location: UniformLocation, value: FloatArray) = + gl.glUniform3fv(location, value.vSize(3), value, 0) + override fun uniform3i(location: UniformLocation, x: Int, y: Int, z: Int) = + gl.glUniform3i(location, x, y, z) + override fun uniform3iv(location: UniformLocation, value: IntArray) = + gl.glUniform3iv(location, value.vSize(3), value, 0) override fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float) = gl.glUniform4f(location, x, y, z, w) - - override fun uniform4fv(location: UniformLocation, value: FloatArray) = gl.glUniform4fv(location, value.size / 4, value, 0) - + override fun uniform4fv(location: UniformLocation, value: FloatArray) = + gl.glUniform4fv(location, value.vSize(4), value, 0) override fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int) = gl.glUniform4i(location, x, y, z, w) - - override fun uniform4iv(location: UniformLocation, value: IntArray) = gl.glUniform4iv(location, value.size / 4, value, 0) + override fun uniform4iv(location: UniformLocation, value: IntArray) = + gl.glUniform4iv(location, value.vSize(4), value, 0) override fun uniformMatrix3fv(location: UniformLocation, transpose: Boolean, value: FloatArray) = - gl.glUniformMatrix3fv(location, value.size, transpose, value, 0) - + gl.glUniformMatrix3fv(location, value.vSize(3*3), transpose, value, 0) override fun uniformMatrix4fv(location: UniformLocation, transpose: Boolean, value: FloatArray) = - gl.glUniformMatrix4fv(location, value.size, transpose, value, 0) + gl.glUniformMatrix4fv(location, value.vSize(4*4), transpose, value, 0) override fun blendFunc(sFactor: Int, dFactor: Int) = gl.glBlendFunc(sFactor, dFactor) diff --git a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Util.kt b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Util.kt new file mode 100644 index 0000000..8104da4 --- /dev/null +++ b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Util.kt @@ -0,0 +1,13 @@ +package com.danielgergely.kgl + +public fun FloatArray.vSize(vecSize: Int): Int { + if (size % vecSize != 0) + throw IllegalArgumentException("Array size must be a multiple of $vecSize.") + return size / vecSize +} + +public fun IntArray.vSize(vecSize: Int): Int { + if (size % vecSize != 0) + throw IllegalArgumentException("Array size must be a multiple of $vecSize.") + return size / vecSize +} \ No newline at end of file From dca11a78ad8341459525a758a9c8c54a95413e2c Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Tue, 1 Aug 2023 09:53:36 -0700 Subject: [PATCH 4/5] Reformat for consistency. --- .../kotlin/com/danielgergely/kgl/KglLwjgl.kt | 67 +++++-------------- .../kotlin/com/danielgergely/kgl/Kgl.kt | 13 ---- 2 files changed, 18 insertions(+), 62 deletions(-) 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 fce47d4..bde6eba 100644 --- a/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt +++ b/kgl-lwjgl/src/main/kotlin/com/danielgergely/kgl/KglLwjgl.kt @@ -267,77 +267,46 @@ object KglLwjgl : Kgl { GL.glTexParameteri(target, pname, value) } - override fun uniform1f(location: UniformLocation, f: Float) { + override fun uniform1f(location: UniformLocation, f: Float) = GL.glUniform1f(location, f) - } - - override fun uniform1fv(location: UniformLocation, value: FloatArray) { + override fun uniform1fv(location: UniformLocation, value: FloatArray) = GL.glUniform1fv(location, value) - } - - override fun uniform1i(location: UniformLocation, i: Int) { + override fun uniform1i(location: UniformLocation, i: Int) = GL.glUniform1i(location, i) - } - - override fun uniform1iv(location: UniformLocation, value: IntArray) { + override fun uniform1iv(location: UniformLocation, value: IntArray) = GL.glUniform1iv(location, value) - } - override fun uniform2f(location: UniformLocation, x: Float, y: Float) { + override fun uniform2f(location: UniformLocation, x: Float, y: Float) = GL.glUniform2f(location, x, y) - } - - override fun uniform2fv(location: UniformLocation, value: FloatArray) { + override fun uniform2fv(location: UniformLocation, value: FloatArray) = GL.glUniform2fv(location, value) - } - - override fun uniform2i(location: UniformLocation, x: Int, y: Int) { + override fun uniform2i(location: UniformLocation, x: Int, y: Int) = GL.glUniform2i(location, x, y) - } - - override fun uniform2iv(location: UniformLocation, value: IntArray) { + override fun uniform2iv(location: UniformLocation, value: IntArray) = GL.glUniform2iv(location, value) - } - override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) { + override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float) = GL.glUniform3f(location, x, y, z) - } - - override fun uniform3fv(location: UniformLocation, value: FloatArray) { + override fun uniform3fv(location: UniformLocation, value: FloatArray) = GL.glUniform3fv(location, value) - } - - override fun uniform3i(location: UniformLocation, x: Int, y: Int, z: Int) { + override fun uniform3i(location: UniformLocation, x: Int, y: Int, z: Int) = GL.glUniform3i(location, x, y, z) - } - - override fun uniform3iv(location: UniformLocation, value: IntArray) { + override fun uniform3iv(location: UniformLocation, value: IntArray) = GL.glUniform3iv(location, value) - } - override fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float) { + override fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float) = GL.glUniform4f(location, x, y, z, w) - } - - override fun uniform4fv(location: UniformLocation, value: FloatArray) { + override fun uniform4fv(location: UniformLocation, value: FloatArray) = GL.glUniform4fv(location, value) - } - - override fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int) { + override fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int) = GL.glUniform4i(location, x, y, z, w) - } - - override fun uniform4iv(location: UniformLocation, value: IntArray) { + override fun uniform4iv(location: UniformLocation, value: IntArray) = GL.glUniform4iv(location, value) - } - override fun uniformMatrix3fv(location: UniformLocation, transpose: Boolean, value: FloatArray) { + override fun uniformMatrix3fv(location: UniformLocation, transpose: Boolean, value: FloatArray) = GL.glUniformMatrix3fv(location, transpose, value) - } - - override fun uniformMatrix4fv(location: UniformLocation, transpose: Boolean, value: FloatArray) { + override fun uniformMatrix4fv(location: UniformLocation, transpose: Boolean, value: FloatArray) = GL.glUniformMatrix4fv(location, transpose, value) - } override fun useProgram(programId: Program) { GL.glUseProgram(programId) diff --git a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt index 8a9bd27..e8e590d 100644 --- a/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt +++ b/kgl/src/jsMain/kotlin/com/danielgergely/kgl/Kgl.kt @@ -87,56 +87,43 @@ public class KglJs(private val gl: WebGLRenderingContext) : Kgl { public override fun uniform1f(location: UniformLocation, f: Float): Unit = gl.uniform1f(location.unsafeCast(), f) - public override fun uniform1fv(location: UniformLocation, value: FloatArray): Unit = gl.uniform1fv(location.unsafeCast(), value.unsafeCast()) - public override fun uniform1i(location: UniformLocation, i: Int): Unit = gl.uniform1i(location.unsafeCast(), i) - public override fun uniform1iv(location: UniformLocation, value: IntArray): Unit = gl.uniform1iv(location.unsafeCast(), value.unsafeCast()) public override fun uniform2f(location: UniformLocation, x: Float, y: Float): Unit = gl.uniform2f(location.unsafeCast(), x, y) - public override fun uniform2fv(location: UniformLocation, value: FloatArray): Unit = gl.uniform2fv(location.unsafeCast(), value.unsafeCast()) - public override fun uniform2i(location: UniformLocation, x: Int, y: Int): Unit = gl.uniform2i(location.unsafeCast(), x, y) - public override fun uniform2iv(location: UniformLocation, value: IntArray): Unit = gl.uniform2iv(location.unsafeCast(), value.unsafeCast()) public override fun uniform3f(location: UniformLocation, x: Float, y: Float, z: Float): Unit = gl.uniform3f(location.unsafeCast(), x, y, z) - public override fun uniform3fv(location: UniformLocation, value: FloatArray): Unit = gl.uniform3fv(location.unsafeCast(), value.unsafeCast()) - public override fun uniform3i(location: UniformLocation, x: Int, y: Int, z: Int): Unit = gl.uniform3i(location.unsafeCast(), x, y, z) - public override fun uniform3iv(location: UniformLocation, value: IntArray): Unit = gl.uniform3iv(location.unsafeCast(), value.unsafeCast()) public override fun uniform4f(location: UniformLocation, x: Float, y: Float, z: Float, w: Float): Unit = gl.uniform4f(location.unsafeCast(), x, y, z, w) - public override fun uniform4fv(location: UniformLocation, value: FloatArray): Unit = gl.uniform4fv(location.unsafeCast(), value.unsafeCast()) - public override fun uniform4i(location: UniformLocation, x: Int, y: Int, z: Int, w: Int): Unit = gl.uniform4i(location.unsafeCast(), x, y, z, w) - public override fun uniform4iv(location: UniformLocation, value: IntArray): Unit = gl.uniform4iv(location.unsafeCast(), value.unsafeCast()) public override fun uniformMatrix3fv(location: UniformLocation, transpose: Boolean, value: dynamic) { gl.uniformMatrix3fv(location.unsafeCast(), transpose, value.unsafeCast()) } - public override fun uniformMatrix4fv(location: UniformLocation, transpose: Boolean, value: dynamic) { gl.uniformMatrix4fv(location.unsafeCast(), transpose, value.unsafeCast()) } From 5d71d033d2b8c93d026aa3a6a785e2123f88c335 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Tue, 15 Aug 2023 16:35:18 -0700 Subject: [PATCH 5/5] Move vSize to iOS, Android, and JOGL modules so they can be private. --- .../main/kotlin/com/danielgergely/kgl/KglAndroid.kt | 12 ++++++++++++ .../kotlin/com.danielgergely.kgl/KglIos.kt | 12 ++++++++++++ .../main/kotlin/com/danielgergely/kgl/KglJogl.kt | 12 ++++++++++++ .../commonMain/kotlin/com/danielgergely/kgl/Util.kt | 13 ------------- 4 files changed, 36 insertions(+), 13 deletions(-) delete mode 100644 kgl/src/commonMain/kotlin/com/danielgergely/kgl/Util.kt 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 94a34f0..6795f56 100644 --- a/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt +++ b/kgl-android/src/main/kotlin/com/danielgergely/kgl/KglAndroid.kt @@ -259,3 +259,15 @@ object KglAndroid : Kgl { } } } + +private fun FloatArray.vSize(vecSize: Int): Int { + if (size % vecSize != 0) + throw IllegalArgumentException("Array size must be a multiple of $vecSize.") + return size / vecSize +} + +private fun IntArray.vSize(vecSize: Int): Int { + if (size % vecSize != 0) + throw IllegalArgumentException("Array size must be a multiple of $vecSize.") + return size / vecSize +} diff --git a/kgl-ios/src/nativeMain/kotlin/com.danielgergely.kgl/KglIos.kt b/kgl-ios/src/nativeMain/kotlin/com.danielgergely.kgl/KglIos.kt index 69dadc8..6b86c8f 100644 --- a/kgl-ios/src/nativeMain/kotlin/com.danielgergely.kgl/KglIos.kt +++ b/kgl-ios/src/nativeMain/kotlin/com.danielgergely.kgl/KglIos.kt @@ -466,3 +466,15 @@ object KglIos : Kgl { private fun Boolean.toGl(): GLboolean = if (this) 1u else 0u private fun UByte.toBoolean() = this != platform.gles3.GL_FALSE.toUByte() + +private fun FloatArray.vSize(vecSize: Int): Int { + if (size % vecSize != 0) + throw IllegalArgumentException("Array size must be a multiple of $vecSize.") + return size / vecSize +} + +private fun IntArray.vSize(vecSize: Int): Int { + if (size % vecSize != 0) + throw IllegalArgumentException("Array size must be a multiple of $vecSize.") + return size / vecSize +} \ No newline at end of file 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 2cca52d..8b654de 100644 --- a/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt +++ b/kgl-jogl/src/main/kotlin/com/danielgergely/kgl/KglJogl.kt @@ -333,3 +333,15 @@ fun imageToByteBuffer(image: BufferedImage): ByteBuffer { return buffer } + +private fun FloatArray.vSize(vecSize: Int): Int { + if (size % vecSize != 0) + throw IllegalArgumentException("Array size must be a multiple of $vecSize.") + return size / vecSize +} + +private fun IntArray.vSize(vecSize: Int): Int { + if (size % vecSize != 0) + throw IllegalArgumentException("Array size must be a multiple of $vecSize.") + return size / vecSize +} \ No newline at end of file diff --git a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Util.kt b/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Util.kt deleted file mode 100644 index 8104da4..0000000 --- a/kgl/src/commonMain/kotlin/com/danielgergely/kgl/Util.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.danielgergely.kgl - -public fun FloatArray.vSize(vecSize: Int): Int { - if (size % vecSize != 0) - throw IllegalArgumentException("Array size must be a multiple of $vecSize.") - return size / vecSize -} - -public fun IntArray.vSize(vecSize: Int): Int { - if (size % vecSize != 0) - throw IllegalArgumentException("Array size must be a multiple of $vecSize.") - return size / vecSize -} \ No newline at end of file