Why glGenLists return value directly while glGenTextures use reference parameter?
May be it's a little OCD but I fe开发者_运维问答el it's annoying that in OpenGL, glGenLists
return the ID of lists directly while glGenTextures
use reference parameter to feed back the ID.
GLuint glGenLists(GLsizei range);
void glGenTextures(GLsizei n, GLuint * textures);
Is there any good reason behind this inconsistence?
Christian Rau touches on the right theme.
The reason why the glGenLists guarantees ordering of the returned value is string drawing. The usage model wanted glListBase + glCallLists to allow a simple
// ascii model
// init
asciiBase = glGenLists(128);
// usage
glListBase(asciiBase);
glCallList(strlen(string), GL_UNSIGNED_BYTE, string);
For that usage model, you really required the range to be contiguous. There was no such model envisioned for textures, so the requirement to get contiguous names was removed, as it simplified the implementation of the GL.
As an additional tidbit, note that the glGen* calls are all optional. Nothing prevents you from doing:
glBindTexture(GL_TEXTURE_2D, 5);
// never called glGenTextures to get that 5!!!
I think glGenLists returning directly is more of a relict from the past. The reason for glGenTextures to use a pointer, is that you can get more than one texture name. But for glGenLists that is not neccessary, as the n list IDs generated by a single call to glGenLists(n) are guaranteed to have consecutive values, so that you can use glCallLists and glListBase effectively. So you only need to know the first value.
But texture IDs are not guaranteed to have this property, so you need all n values, and therefore the array. I suppose when introducing texture objects (which came after display lists) they realized, that this call is much more general, as now you do not have the implementation guarantee consecutive texture IDs (which also does not have any advantages).
精彩评论