https://kotlinlang.org logo
Title
n

norman784

05/28/2018, 11:51 AM
I’m so confused by the bindings generated by konan, don’t understand how to call this function, it is supposed to be just like this:
val vertexShaderSource: String = "...."
val vertexShader = glCreateShader(GL_VERTEX_SHADER)
glShaderSource(vertexShader, 1, vertexShaderSource, null)
Tried different thinks like
.toCValues()
,
.cValuesOf()
,
.cstr.getPointer(this /* memscoped reference */)
, I find so complicated some of the bindings, don’t know if theres a better way to detect that the variable is a char array and do automatically the convertion between string a char array (and vice versa) This is how the
glShaderSource
looks like in kotlin
public fun glShaderSource(shader: platform.OpenGLCommon.GLuint /* = <http://kotlin.Int|kotlin.Int> */, count: platform.OpenGLCommon.GLsizei /* = <http://kotlin.Int|kotlin.Int> */, string: kotlinx.cinterop.CValuesRef<kotlinx.cinterop.CPointerVar<platform.OpenGLCommon.GLcharVar /* = kotlinx.cinterop.ByteVarOf<platform.OpenGLCommon.GLchar /* = kotlin.Byte */> */> /* = kotlinx.cinterop.CPointerVarOf<kotlinx.cinterop.CPointer<kotlinx.cinterop.ByteVarOf<platform.OpenGLCommon.GLchar /* = kotlin.Byte */>>> */>?, length: kotlinx.cinterop.CValuesRef<platform.OpenGLCommon.GLintVar /* = kotlinx.cinterop.IntVarOf<platform.OpenGLCommon.GLint /* = kotlin.Int */> */>?): kotlin.Unit { /* compiled code */ }
And this is the c function
void glShaderSource(	GLuint shader,
 	GLsizei count,
 	const GLchar **string,
 	const GLint *length);
s

svyatoslav.scherbina

05/28/2018, 12:01 PM
This should work:
memScoped {
    glShaderSource(vertexShader, 1, cValuesOf(vertexShaderSource.cstr.getPointer(memScope)), null)
}
Have you seen our OpenGL-based demo app? https://github.com/JetBrains/kotlinconf-spinner/blob/f37a6ea758b04915d619fcf68273e4a21ae4d9fc/kotlin-native/samples/fullstack/clients/shared/src/main/kotlin/gl.kt#L103
don’t know if theres a better way to detect that the variable is a char array and do automatically the convertion between string a char array (and vice versa)
The thing is that
const GLchar **string
is not a char array, it is a pointer to char array. Or, to be more precise: a pointer to pointer to char.
n

norman784

05/28/2018, 12:24 PM
Thanks, forgot to check there, but the weird thing is that I searched on google like this
kotlin native glShaderSource
and that repo didn’t appear. Ok, I get, so maybe the official bindings maybe will be cool if theres some hand made changes to be much easier to interact with the API.