Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

How does OpenGL use its enum values?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 lride   Members   

663
Like
0Likes
Like

Posted 31 October 2012 - 08:18 PM

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 ?
An invisible text.

#2 Hodgman   Moderators   

50631
Like
2Likes
Like

Posted 31 October 2012 - 08:31 PM

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, 31 October 2012 - 08:32 PM.


#3 Katie   Members   

2220
Like
1Likes
Like

Posted 01 November 2012 - 04:33 AM

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..."

#4 mhagain   Members   

13160
Like
0Likes
Like

Posted 04 November 2012 - 11:17 AM

It depends on the driver; OpenGL itself is just a specification and has nothing to say about this.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.