OpenGL constants are currently declared with the wrong types( ie: int) instead of GLenum, GLint, GLbitfield, etc...
Currently we have to manually covert/coerce to the correct type before calling opengl functions
proc glGenBuffers(n: GLsizei, buffers: ptr GLuint)
proc glGenTextures(n: GLsizei, textures: ptr GLuint)
proc glBindTexture(target: GLenum, texture: GLuint)
proc glTexBuffer(target: GLenum, internalformat: GLenum, buffer: GLuint)
# is called like so:
var texid: GLuint
var id: GLuint
glGenBuffers(1, addr(id))
glGenTextures(1, addr(texid))
glBindTexture(GL_TEXTURE_BUFFER.GLenum, texid)
glTexBuffer(GL_TEXTURE_BUFFER.GLenum, GL_RGB8.GLenum, id)
I propose to convert these constants to their proper types according to the C specification. ( I have already mostly done this on a private branch using regex search and replace)
Problem is, this might break some program depending on the old constant types, especially if we use distinct types (for GLenum and GLbitfield; GLint is supposed to be an alias to int32).
Also, we should probably figure out a way to automate this conversion from the C headers to avoid doing this manually each times the specs are updated. I suppose the original module was generated with c2nim, but using what cmdline arguments?
I generated the interface by reading the spec files (XML), and constants for example are only annotated with integer literals. Type information is omitted in other cases as well unfortunately.
Anyway, it doesn't seem necessary to perform conversions manually according to my tests (with the latest opengl version and a recent development version of nim).
Which versions have you tested this with?
Several. from nim 0.11 (october 2015) to current devel. But my main point was type safety. If constants are properly typed I cannot put a GLbitfield instead of an GLint and it should help with reversed arguments errors.
Most opengl constant are actually GLenum (s) which shouldn't have any operator defined.
A few are GLint: GL_REPEAT, GL_MIRRORED_CLAMP & co used with mostly with glTexParameteri GLint should be an alias to int/int32 since glTexParameteri might takes an integer literal in some cases.
GLbitfield should likely be distinct uint32 with binary OR and NOT defined.
otherwise any of the constants are interchangeable and errors are only discovered at runtime.
For GLbitfield it is actually fairly easy. the "_BIT" suffix is present in GLbitfield constants sometime followed by "_$VENDOR". something like: re"_BIT(b|d?[_]+)" should catch these (value for Glbitfield constants are power of 2)
for GLboolean: GL_TRUE and GL_FALSE
for GLint here is a list that should cover it. see: https://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexParameter.xml
for glTexParameteri(target, GL_TEXTURE_WRAP, wrap);
GL_REPEAT
GL_CLAMP
GL_CLAMP_TO_EDGE
GL_CLAMP_TO_EDGE_SGIS
GL_CLAMP_TO_BORDER
GL_CLAMP_TO_BORDER_ARB
GL_CLAMP_TO_BORDER_NV
GL_CLAMP_TO_BORDER_SGIS
GL_MIRROR_CLAMP_TO_BORDER_EXT
GL_MIRROR_CLAMP_EXT
GL_MIRROR_CLAMP_ATI
GL_MIRROR_CLAMP_TO_EDGE
GL_MIRROR_CLAMP_TO_EDGE_ATI
GL_MIRROR_CLAMP_TO_EDGE_EXT
GL_MIRRORED_REPEAT
GL_MIRRORED_REPEAT_ARB
GL_MIRRORED_REPEAT_IBM
GL_MIRRORED_REPEAT_OES
for glTexParameteri(target, GL_TEXTURE_MAG_FILTER, filter)
GL_NEAREST
GL_LINEAR
GL_LINEAR_MIPMAP_LINEAR
GL_LINEAR_MIPMAP_NEAREST
GL_NEAREST_MIPMAP_LINEAR
GL_NEAREST_MIPMAP_NEAREST
every thing else is a GLenum. (the vast majority) there might be one or two missing, but thats what bugfixes are for :)