kgl icon indicating copy to clipboard operation
kgl copied to clipboard

No conversion from cinterop types to Kotlin types done by code generator

Open nlbuescher opened this issue 5 years ago • 7 comments

Functions like glGetString are generated with a return type of CPointer<GLubyteVar> rather than String. This requires a conversion using a !!.reinterpret<ByteVar>().toKString(), which could be included in the generated code to make the kotlin-facing functions more kotlinic.

nlbuescher avatar Jan 20 '20 19:01 nlbuescher

Hi! Thanks for the interest in the project. Generating more Kotlin friendly functions is on the TODO list. The only issue is to decide what to do with the not so friendly low-level functions, or how to expose them rather. I'll probably just do it the LWJGL way with the n prefix.

Dominaezzz avatar Jan 20 '20 20:01 Dominaezzz

By not-so-firendly low-level function do you mean the version of glGetString that returns a CPointer<GLubyteVar>??

nlbuescher avatar Jan 20 '20 21:01 nlbuescher

Yes, glGetString that returns CPointer<GLubyteVar>? (or glIsEnabled that returns Int instead of Boolean).

Dominaezzz avatar Jan 20 '20 21:01 Dominaezzz

I started in the nice_gl branch. So far have done functions similar to:

  • fun glGetString(): String
  • fun glGetInteger(pname: GLenum): GLint instead of just fun glGetInteger(pname: GLenum, value: CPointer<GLintVar>): GLint.
  • fun glGenBuffer(): GLint in addition to fun glGenBuffers(count: GLsizei, idx: CPointer<GLuintVar>).
  • fun glGetUniformLocation(program: GLuint, name: String) in addition to fun glGetUniformLocation(program: GLuint, name: CValuesRef<GLcharVar>?): GLint
  • GLboolean to Boolean

Feel free to suggest any that could be added to the list.

EDIT: I won't be touching primitive arrays just yet.

Dominaezzz avatar Jan 22 '20 20:01 Dominaezzz

I created some convenience functions for my own GL bindings and what I've done for primitive arrays for functions like glCreateBuffers is the following:

fun glCreateBuffers(n: Int): UIntArray = UIntArray(n).apply {
    usePinned { copengl.glCreateBuffers(n, it.addressOf(0)) }
}

fun glCreateBuffer(): UInt = glCreateBuffers(1).first()

nlbuescher avatar Jan 27 '20 15:01 nlbuescher

Are there any plans to use the Enums generated from the GL registry in the gl functions?

nlbuescher avatar Jan 27 '20 17:01 nlbuescher

Ah.... those. The enums are generated from the official gl.xml registry. The problem is the registry isn't exhaustive about enums, so it doesn't work very well. I've been considering moving all the enums into a single enum but I'm not sure I like that idea very much.

Dominaezzz avatar Jan 27 '20 18:01 Dominaezzz