开发者

Passing parameters to OpenGL display lists

I was wondering if there is any way (standard or a clever trick) to pass parameters to an OpenGL display list. Let me show an example to clarify what I mean.

Suppose we have the following code:

GLuint l = glGenLists(1);
glNewList(l, GL_COMPILE);
  // ...some OpenGL function calls
  glBindTexture(GL_TEXTURE_2D, some_texture); // <-- here, I want `some_texture' to be a parameter that I can set when calling the display list
  //...some more stuff...
glEndList();

Is开发者_JS百科 there a way to accomplish what I want?


Well, yes, the bound texture is global state and if you bind a texture and then call a display list, the texture should still be bound when the list executed.

But it's better to stop using display lists and use VAs/VBOs, i recommend them!


That won't work. Be sure to read both the specification and the FAQ carefully, in particular:

The GL may be instructed to process a particular display list (possibly repeatedly) by providing a number that uniquely specifies it. Doing so causes the commands within the list to be executed just as if they were given normally. The only exception pertains to commands that rely upon client state. When such a command is accumulated into the display list (that is, when issued, not when executed), the client state in effect at that time applies to the command.

16.010 Why does a display list take up so much memory? An OpenGL display list must make a copy of all data it requires to recreate the call sequence that created it.

In other words, if you plan to change the texture's data store later, it will make no difference, because OpenGL keeps its own copy to ensure that it can exactly reproduce whatever was the current state.

The only way to get some kind of variability into display lists is via the nested display trick, but as Matias Valdenegro already suggested, you should not use display lists at all if you can help it. Other functionality (e.g. VBO) is more flexible and has the same or better performance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜