diff --git a/korge-core/src/korlibs/graphics/gl/AGOpengl.kt b/korge-core/src/korlibs/graphics/gl/AGOpengl.kt index cdc2ef052a..b32999269e 100644 --- a/korge-core/src/korlibs/graphics/gl/AGOpengl.kt +++ b/korge-core/src/korlibs/graphics/gl/AGOpengl.kt @@ -541,14 +541,24 @@ class AGOpengl(val gl: KmlGl, var context: KmlGlContext? = null) : AG() { //println("loc=$loc") if (loc >= 0) { gl.enableVertexAttribArray(loc) - gl.vertexAttribPointer( - loc, - elementCount, - glElementType, - att.normalized, - totalSize, - entry.baseOffset + off.toLong() - ) + if (att.type == VarType.SInt1) { + gl.vertexAttribIPointer( + loc, + elementCount, + glElementType, + totalSize, + entry.baseOffset + off.toLong() + ) + } else { + gl.vertexAttribPointer( + loc, + elementCount, + glElementType, + att.normalized, + totalSize, + entry.baseOffset + off.toLong() + ) + } if (att.divisor != 0) { gl.vertexAttribDivisor(loc, att.divisor) } diff --git a/korge-core/src/korlibs/graphics/gl/AGOpenglConvert.kt b/korge-core/src/korlibs/graphics/gl/AGOpenglConvert.kt index 5a9517e523..40eca47d30 100644 --- a/korge-core/src/korlibs/graphics/gl/AGOpenglConvert.kt +++ b/korge-core/src/korlibs/graphics/gl/AGOpenglConvert.kt @@ -126,7 +126,7 @@ fun VarType.toGl(): Int = when (this.kind) { VarKind.TUNSIGNED_BYTE -> KmlGl.UNSIGNED_BYTE VarKind.TSHORT -> KmlGl.SHORT VarKind.TUNSIGNED_SHORT -> KmlGl.UNSIGNED_SHORT - VarKind.TINT -> KmlGl.UNSIGNED_INT + VarKind.TINT -> KmlGl.INT VarKind.TFLOAT -> KmlGl.FLOAT } diff --git a/korge-core/src/korlibs/kgl/KmlGl.kt b/korge-core/src/korlibs/kgl/KmlGl.kt index 422bd07ea8..86640339eb 100644 --- a/korge-core/src/korlibs/kgl/KmlGl.kt +++ b/korge-core/src/korlibs/kgl/KmlGl.kt @@ -161,6 +161,7 @@ open class KmlGl : Extra by Extra.Mixin(), AGFeatures { open fun vertexAttrib4f(index: Int, x: Float, y: Float, z: Float, w: Float): Unit = TODO() open fun vertexAttrib4fv(index: Int, v: Buffer): Unit = TODO() open fun vertexAttribPointer(index: Int, size: Int, type: Int, normalized: Boolean, stride: Int, pointer: Long): Unit = TODO() + open fun vertexAttribIPointer(index: Int, size: Int, type: Int, stride: Int, pointer: Long): Unit = TODO() open fun viewport(x: Int, y: Int, width: Int, height: Int): Unit = TODO() fun enableDisable(cap: Int, enable: Boolean): Boolean { if (enable) enable(cap) else disable(cap) diff --git a/korge-core/src/korlibs/kgl/KmlGlProxy.kt b/korge-core/src/korlibs/kgl/KmlGlProxy.kt index 1288b06553..468160da30 100644 --- a/korge-core/src/korlibs/kgl/KmlGlProxy.kt +++ b/korge-core/src/korlibs/kgl/KmlGlProxy.kt @@ -1063,6 +1063,13 @@ open class KmlGlProxy(parent: KmlGl) : KmlGlFastProxy(parent) { after("vertexAttribPointer", sparams, res) return res } + override fun vertexAttribIPointer(index: Int, size: Int, type: Int, stride: Int, pointer: Long) { + val sparams = listOf(index, size, type, stride, pointer) + before("vertexAttribIPointer", sparams) + val res = parent.vertexAttribIPointer(index, size, type, stride, pointer) + after("vertexAttribIPointer", sparams, res) + return res + } override fun viewport(x: Int, y: Int, width: Int, height: Int) { val sparams = listOf(x, y, width, height) before("viewport", sparams) @@ -1607,6 +1614,7 @@ open class KmlGlFastProxy(var parent: KmlGl) : KmlGl() { } override fun vertexAttrib4fv(index: Int, v: Buffer) = parent.vertexAttrib4fv(index, v) override fun vertexAttribPointer(index: Int, size: Int, type: Int, normalized: Boolean, stride: Int, pointer: Long) = parent.vertexAttribPointer(index, size, type, normalized, stride, pointer) + override fun vertexAttribIPointer(index: Int, size: Int, type: Int, stride: Int, pointer: Long) = parent.vertexAttribIPointer(index, size, type, stride, pointer) override fun viewport(x: Int, y: Int, width: Int, height: Int) = parent.viewport(x, y, width, height) override fun bindBufferRange(target: Int, index: Int, buffer: Int, offset: Int, size: Int) = parent.bindBufferRange(target, index, buffer, offset, size) diff --git a/korge-core/src/korlibs/sdl/SDL.kt b/korge-core/src/korlibs/sdl/SDL.kt index 2a4c46a1a1..38033ce828 100644 --- a/korge-core/src/korlibs/sdl/SDL.kt +++ b/korge-core/src/korlibs/sdl/SDL.kt @@ -153,6 +153,7 @@ open class OpenGL : FFILib("/System/Library/Frameworks/OpenGL.framework/OpenGL") val glGetString by func<(GLenum) -> GLString>() val glGetStringi by func<(GLenum, GLuint) -> GLString>() val glVertexAttribPointer by func<(GLuint, GLint, GLenum, GLboolean, GLsizei, GLvoidPtr) -> Unit>() + val glVertexAttribIPointer by func<(GLuint, GLint, GLenum, GLsizei, GLvoidPtr) -> Unit>() val glVertexAttrib4fv by func<(GLuint, GLfloatPtr) -> Unit>() val glActiveTexture by func<(GLenum) -> Unit>() val glAttachShader by func<(GLuint, GLuint) -> Unit>() @@ -435,6 +436,8 @@ class KmlGlOpenGL(val gl: OpenGL = OpenGL()) : KmlGl() { override fun vertexAttrib4fv(index: Int, v: Buffer): Unit = gl.glVertexAttrib4fv(index, v.pointer) override fun vertexAttribPointer(index: Int, size: Int, type: Int, normalized: Boolean, stride: Int, pointer: Long): Unit = gl.glVertexAttribPointer(index, size, type, normalized.toInt(), stride, pointer.convert()) + override fun vertexAttribIPointer(index: Int, size: Int, type: Int, stride: Int, pointer: Long): Unit = + gl.glVertexAttribIPointer(index, size, type, stride, pointer.convert()) override fun viewport(x: Int, y: Int, width: Int, height: Int): Unit = gl.glViewport(x, y, width, height) override val isInstancedSupported: Boolean get() = true diff --git a/korge-core/src@darwin/korlibs/kgl/KmlGlNative.kt b/korge-core/src@darwin/korlibs/kgl/KmlGlNative.kt index 03e9d03e3e..101736ed5b 100644 --- a/korge-core/src@darwin/korlibs/kgl/KmlGlNative.kt +++ b/korge-core/src@darwin/korlibs/kgl/KmlGlNative.kt @@ -177,6 +177,7 @@ actual class KmlGlNative actual constructor() : NativeBaseKmlGl() { override fun vertexAttrib4f(index: Int, x: Float, y: Float, z: Float, w: Float): Unit = tempBufferAddress { glVertexAttrib4f(index.convert(), x, y, z, w) } override fun vertexAttrib4fv(index: Int, v: Buffer): Unit = tempBufferAddress { glVertexAttrib4fv(index.convert(), v.unsafeAddress().reinterpret()) } override fun vertexAttribPointer(index: Int, size: Int, type: Int, normalized: Boolean, stride: Int, pointer: Long): Unit = tempBufferAddress { glVertexAttribPointer(index.convert(), size.convert(), type.convert(), normalized.toInt().convert(), stride.convert(), pointer.toCPointer()) } + override fun vertexAttribIPointer(index: Int, size: Int, type: Int, stride: Int, pointer: Long): Unit = tempBufferAddress { glVertexAttribIPointer(index.convert(), size.convert(), type.convert(), stride.convert(), pointer.toCPointer()) } override fun viewport(x: Int, y: Int, width: Int, height: Int): Unit = tempBufferAddress { glViewport(x.convert(), y.convert(), width.convert(), height.convert()) } override val isInstancedSupported: Boolean get() = true diff --git a/korge-core/src@js/korlibs/kgl/KmlGlJsCanvas.kt b/korge-core/src@js/korlibs/kgl/KmlGlJsCanvas.kt index 0cba466440..748e313c67 100644 --- a/korge-core/src@js/korlibs/kgl/KmlGlJsCanvas.kt +++ b/korge-core/src@js/korlibs/kgl/KmlGlJsCanvas.kt @@ -4,10 +4,12 @@ package korlibs.kgl +import korlibs.audio.format.MP3Base.Parser.Companion.samples import korlibs.graphics.gl.* import korlibs.graphics.shader.gl.* import korlibs.image.bitmap.* import korlibs.image.format.* +import korlibs.logger.* import korlibs.math.* import korlibs.memory.* import korlibs.memory.Buffer @@ -237,6 +239,13 @@ class KmlGlJsCanvas(val canvas: HTMLCanvasElement, val glOpts: dynamic) : KmlGl( override fun vertexAttrib4f(index: Int, x: Float, y: Float, z: Float, w: Float): Unit = gl.vertexAttrib4f(index, x, y, z, w) override fun vertexAttrib4fv(index: Int, v: Buffer): Unit = gl.vertexAttrib4fv(index, v) override fun vertexAttribPointer(index: Int, size: Int, type: Int, normalized: Boolean, stride: Int, pointer: Long): Unit = gl.vertexAttribPointer(index, size, type, normalized, stride, pointer.toInt()) + override fun vertexAttribIPointer(index: Int, size: Int, type: Int, stride: Int, pointer: Long): Unit { + if (webglVersion >= 2) { + gl.asDynamic().vertexAttribIPointer(index, size, type, stride, pointer.toInt()) + } else { + TODO() + } + } override fun viewport(x: Int, y: Int, width: Int, height: Int): Unit = gl.viewport(x, y, width, height) private fun Float32Array.sliceIfRequired(count: Int): Float32Array = if (this.length == count) this else Float32Array(this.buffer, 0, count) diff --git a/korge-core/src@jvm/korlibs/render/platform/INativeGL.kt b/korge-core/src@jvm/korlibs/render/platform/INativeGL.kt index 933932968c..3e951bb04c 100644 --- a/korge-core/src@jvm/korlibs/render/platform/INativeGL.kt +++ b/korge-core/src@jvm/korlibs/render/platform/INativeGL.kt @@ -202,6 +202,7 @@ object DirectGL : INativeGL { external override fun glVertexAttrib4f(index: GLuint, x: GLfloat, y: GLfloat, z: GLfloat, w: GLfloat) external override fun glVertexAttrib4fv(index: GLuint, v: FloatPtr) external override fun glVertexAttribPointer(index: GLuint, size: GLint, type: GLenum, normalized: GLboolean, stride: GLsizei, pointer: IntSize) + external override fun glVertexAttribIPointer(index: GLuint, size: GLint, type: GLenum, stride: GLsizei, pointer: IntSize) external override fun glViewport(x: GLint, y: GLint, width: GLsizei, height: GLsizei) external override fun glDrawArraysInstanced(mode: GLenum, first: GLint, count: GLsizei, instancecount: GLsizei) external override fun glDrawElementsInstanced(mode: GLenum, count: GLsizei, type: GLenum, indices: IntSize, instancecount: GLsizei) @@ -449,6 +450,7 @@ interface INativeGL { fun glVertexAttrib4f(index: GLuint, x: GLfloat, y: GLfloat, z: GLfloat, w: GLfloat) fun glVertexAttrib4fv(index: GLuint, v: FloatPtr) fun glVertexAttribPointer(index: GLuint, size: GLint, type: GLenum, normalized: GLboolean, stride: GLsizei, pointer: IntSize) + fun glVertexAttribIPointer(index: GLuint, size: GLint, type: GLenum, stride: GLsizei, pointer: IntSize) fun glViewport(x: GLint, y: GLint, width: GLsizei, height: GLsizei) fun glDrawArraysInstanced(mode: GLenum, first: GLint, count: GLsizei, instancecount: GLsizei): Unit diff --git a/korge-core/src@jvm/korlibs/render/platform/NativeKgl.kt b/korge-core/src@jvm/korlibs/render/platform/NativeKgl.kt index 198c2de13a..38b7b1132d 100644 --- a/korge-core/src@jvm/korlibs/render/platform/NativeKgl.kt +++ b/korge-core/src@jvm/korlibs/render/platform/NativeKgl.kt @@ -160,6 +160,7 @@ open class NativeKgl constructor(private val gl: INativeGL) : KmlGl() { override fun vertexAttrib4f(index: Int, x: Float, y: Float, z: Float, w: Float): Unit = gl.glVertexAttrib4f(index, x, y, z, w) override fun vertexAttrib4fv(index: Int, v: Buffer): Unit = gl.glVertexAttrib4fv(index, v.directFloatBuffer) override fun vertexAttribPointer(index: Int, size: Int, type: Int, normalized: Boolean, stride: Int, pointer: Long): Unit = gl.glVertexAttribPointer(index, size, type, normalized.toByte(), stride, NativeLong(pointer)) + override fun vertexAttribIPointer(index: Int, size: Int, type: Int, stride: Int, pointer: Long): Unit = gl.glVertexAttribIPointer(index, size, type, stride, NativeLong(pointer)) override fun viewport(x: Int, y: Int, width: Int, height: Int): Unit = gl.glViewport(x, y, width, height) // GL_ARB_instanced_arrays diff --git a/korge-core/src@native/korlibs/kgl/KmlGlNativeExt.kt b/korge-core/src@native/korlibs/kgl/KmlGlNativeExt.kt index 9db39693f2..c9f8b405ff 100644 --- a/korge-core/src@native/korlibs/kgl/KmlGlNativeExt.kt +++ b/korge-core/src@native/korlibs/kgl/KmlGlNativeExt.kt @@ -182,6 +182,7 @@ abstract class NativeBaseKmlGl : KmlGl() { override fun vertexAttrib4fv(index: Int, v: Buffer): Unit = tempBufferAddress { glVertexAttrib4fvExt(index.convert(), v.unsafeAddress().reinterpret()) } override fun viewport(x: Int, y: Int, width: Int, height: Int): Unit = tempBufferAddress { glViewportExt(x.convert(), y.convert(), width.convert(), height.convert()) } override fun vertexAttribPointer(index: Int, size: Int, type: Int, normalized: Boolean, stride: Int, pointer: Long): Unit = tempBufferAddress { glVertexAttribPointerExt(index.convert(), size.convert(), type.convert(), normalized.toInt().convert(), stride.convert(), pointer.toCPointer()?.reinterpret()) } + override fun vertexAttribIPointer(index: Int, size: Int, type: Int, stride: Int, pointer: Long): Unit = tempBufferAddress { glVertexAttribIPointerExt(index.convert(), size.convert(), type.convert(), stride.convert(), pointer.toCPointer()?.reinterpret()) } override val isInstancedSupported: Boolean get() = true override fun drawArraysInstanced(mode: Int, first: Int, count: Int, instancecount: Int): Unit = glDrawArraysInstancedExt(mode.convert(), first.convert(), count.convert(), instancecount.convert()) @@ -282,6 +283,7 @@ abstract class NativeBaseKmlGl : KmlGl() { val glGetStringExt by GLFunc<(GLenum) -> GLString>() val glGetStringiExt by GLFunc<(GLenum, GLuint) -> GLString>() val glVertexAttribPointerExt by GLFunc<(GLuint, GLint, GLenum, GLboolean, GLsizei, GLvoidPtr) -> Unit>() + val glVertexAttribIPointerExt by GLFunc<(GLuint, GLint, GLenum, GLsizei, GLvoidPtr) -> Unit>() val glVertexAttrib4fvExt by GLFunc<(GLuint, GLfloatPtr) -> Unit>() val glActiveTextureExt by GLFunc<(GLenum) -> Unit>() val glAttachShaderExt by GLFunc<(GLuint, GLuint) -> Unit>() diff --git a/korge-core/src@wasmJs/korlibs/kgl/KmlGlWasmCanvas.kt b/korge-core/src@wasmJs/korlibs/kgl/KmlGlWasmCanvas.kt index c7ac3ef033..53b5210a55 100644 --- a/korge-core/src@wasmJs/korlibs/kgl/KmlGlWasmCanvas.kt +++ b/korge-core/src@wasmJs/korlibs/kgl/KmlGlWasmCanvas.kt @@ -32,6 +32,7 @@ public external interface WebGLRenderingContextBase2 : WebGLRenderingContextBase fun deleteVertexArray(free: WebGLVertexArrayObject?) fun bindVertexArray(get: WebGLVertexArrayObject?) fun renderbufferStorageMultisample(target: Int, samples: Int, internalformat: Int, width: Int, height: Int) + fun vertexAttribIPointer(index: Int, size: Int, type: Int, stride: Int, offset: Int) } @@ -274,6 +275,8 @@ class KmlGlWasmCanvas(val canvas: HTMLCanvasElement, val glOpts: JsAny) : KmlGl( override fun vertexAttrib4f(index: Int, x: Float, y: Float, z: Float, w: Float): Unit = gl.vertexAttrib4f(index, x, y, z, w) override fun vertexAttrib4fv(index: Int, v: Buffer): Unit = gl.vertexAttrib4fv(index, v.toF32()) override fun vertexAttribPointer(index: Int, size: Int, type: Int, normalized: Boolean, stride: Int, pointer: Long): Unit = gl.vertexAttribPointer(index, size, type, normalized, stride, pointer.toInt()) + override fun vertexAttribIPointer(index: Int, size: Int, type: Int, stride: Int, pointer: Long): Unit = + gl.vertexAttribIPointer(index, size, type, stride, pointer.toInt()) override fun viewport(x: Int, y: Int, width: Int, height: Int): Unit = gl.viewport(x, y, width, height) private fun Float32Array.sliceIfRequired(count: Int): Float32Array = if (this.length == count) this else Float32Array(this.buffer, 0, count)