When checking for errors, I get [EDIT:] 1282 (“invalid operation”). I take this to mean that the OpenGL is still using OpenGL 2 for glTexImage2D, and so the call is failing.
OpenGL errors are not that complex to understand. GL_INVALID_ENUM/VALUE
are thrown when you pass something an enum or value that is unexpected, unsupported, or out-of-range. If you pass “17” as the internal format to glTexImage2D
, you will get GL_INVALID_ENUM
, because 17 is not a valid enum number for an internal format. If you pass 103,422 as the width to glTexImage2D
, you will get GL_INVALID_VALUE
, because 103,422 is almost certainly larger than GL_MAX_TEXTURE_2D
‘s size.
GL_INVALID_OPERATION
is always used for combinations of state that go wrong. Either there is some context state previously set that doesn’t mesh with the function you’re calling, or two or more parameters combined are causing a problem. The latter is the case you have here.
If your implementation didn’t support integer textures at all, then you would get INVALID_ENUM
(because the internal format is not a valid format). Getting INVALID_OPERATION
means that something else is wrong.
Namely, this:
glTexImage2D(GL_TEXTURE_2D,0,get_type(1), TEXTURE_SIZE,TEXTURE_SIZE, 0,get_type(2),data_type,data);
Your get_type(2)
call returns GL_RGB
or GL_RGBA
in all cases. However, when using integral image formats, you must use a pixel transfer format with _INTEGER
at the end.
So your get_type(2)
needs to be this:
inline GLenum get_type(int which) { return (which==1)? GL_RGB16UI: GL_RGB_INTEGER; }
And similarly for other integral image formats.