• Advertisement
Sign in to follow this  

How does OpenGL use its enum values?

This topic is 1906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Lots of OpenGL command takes enums. For example glEnable() can take GL_BLEND, GL_LINE_SMOOTH, GL_POLYGON_SMOOT, and many more.
But how does OpenGL process all this enum values?
A massive switch statement that checks for every possible values? or maybe more organized data structure like a map ?

Share this post


Link to post
Share on other sites
Advertisement
Yeah a switch is one way to do it, another is to manually construct your own jump table (which the compiler may do for you with a switch), e.g.
void a( int arg ) {}//called if enumValue == 0
void b( int arg ) {}//called if enumValue == 1
void c( int arg ) {}//called if enumValue == 2
typedef void(Fn)(int);
Fn* table[3] = { &a, &b, &c };
void CallByEnum( int enumValue, int arg )
{
assert( enumValue >= 0 && enumValue < 3 );
table[enumValue]( arg );
}
Edited by Hodgman

Share this post


Link to post
Share on other sites
Inside the driver, the code paths tend to be convoluted and so there really are a lot of "if (X) { callASetupFunction(); }" type structures. And, yes, that does mean there's a lot of testing needed to exercise all the sections -- and a lot of bugfixing about edge cases; "When I select X Y and Z, W doesn't work..."

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement