Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions korge-core/src/korlibs/graphics/gl/AGOpengl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion korge-core/src/korlibs/graphics/gl/AGOpenglConvert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions korge-core/src/korlibs/kgl/KmlGl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions korge-core/src/korlibs/kgl/KmlGlProxy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Any?>(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<Any?>(x, y, width, height)
before("viewport", sparams)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions korge-core/src/korlibs/sdl/SDL.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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>()
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions korge-core/src@darwin/korlibs/kgl/KmlGlNative.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<IntVar>()) }
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<IntVar>()) }
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
Expand Down
9 changes: 9 additions & 0 deletions korge-core/src@js/korlibs/kgl/KmlGlJsCanvas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no fallback on this case ?

Copy link
Copy Markdown
Member

@ygdrasil-io ygdrasil-io Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reosfire can you put an explicit message at least ?

}
}
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)
Expand Down
2 changes: 2 additions & 0 deletions korge-core/src@jvm/korlibs/render/platform/INativeGL.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions korge-core/src@jvm/korlibs/render/platform/NativeKgl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions korge-core/src@native/korlibs/kgl/KmlGlNativeExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<IntVar>()?.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<IntVar>()?.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())
Expand Down Expand Up @@ -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>()
Expand Down
3 changes: 3 additions & 0 deletions korge-core/src@wasmJs/korlibs/kgl/KmlGlWasmCanvas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}


Expand Down Expand Up @@ -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)
Expand Down
Loading