views:

420

answers:

1

glCallLists() is a convenient function for rendering a series of display lists, especially for things like text rendering. I'm curious -- is it actually more efficient to call glCallLists(), or is it merely a convenience function? For example, which of these two snippets is likely to be faster?

const char *str = "this is a test";
// suppose the display lists numbered [displayListBase..displayListBase+255] have
// been initialized with display lists to render each ASCII character

// snippet 1:
glListBase(displayListBase);
glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);

// snippet 2:
const char *s;
for(s = str; *s; s++)
    glCallList(displayListBase + (unsigned char)*s);

I'm not trying to prematurely optimize, I'm just merely curious as to whether glCallLists provides any significant advantages over the manual approach. If not, then why does it exist? OpenGL tends to be very minimalistic, in that there are very few convenience functions that aren't strictly necessary; the convenience functions that do exist are generally under the glu namespace (GL utilities), e.g. gluOrtho2D(), which provides a wrapper around glOrtho().

I haven't tried profiling the two snippets yet, although I would guess that profiling may be complicated by CPU-GPU interaction, especially over such a short timeframe. The runtime may also be significantly affected by the sizes of the display lists involved, and the number of display lists executed.

+4  A: 

Benchmarking is the only way to be sure, as OpenGL implemenations vary. Even then, that will answer the question for your system, not necessarily any other system.

If you have a hardware OpenGL implementation, then glCallLists might be able to just transfer a few tens of bytes to the hardware in one shot, versus the back-and-forth of many seperate glCallList. So it certainly is conceivable that it would be faster.

Implementations might implement glCallLists in software to do exactly what you just described, resulting in no net gain.

Chris Arguin