what do think of this ? (opengl states)

Started by
18 comments, last by burnseh 22 years, 3 months ago
Shag, even if certain drivers did actually ignore redundancy, there''s no guarantee of such a thing in the OpenGL specification. Therefore, if you were to make that assumption, your app might break somewhere. Never make assumptions.
Advertisement
To Galaxy Quest , i ''ve heard too this kind of tree for opengl state switching but i think it has to deal with a lot of precomputing, in fact before rnedering you should check which of you actual calls to the opengl api are more expensive than other and thus put in the tree, then render it, i think its a good idea coupling with a sort of list of the slowest state change
done during initialization , but after some struggle i preferred to write an opengl state manager with inlined function and the speed gain is neat at the cost of some if , moreover i don''t think that some driver does a redundant check, at least at my actual knowledge

If you actually inline the mglEnable and mglDisable functions, the compiler should optimise away the entire switch/case block, provided you use only constants as parameters.
Kippesoep
I should know by now never to post when pissed!!! I was bound to get it the wrong way round!

*quietly deleting above post*

Sorry for the misinformation!

Edited by - Shag on January 3, 2002 11:38:37 AM
The faster way is to take the shader description from a file (Quake3 uses text plain files). While interpreting the shader, make an OpenGL Display List. To activate the shader you must call the glCallList function. I thought that''s the faster way.



"If you''''re gonna die, die with your boots on"
"If you''re gonna die, die with your boots on"
Im sorta new to 3d, so I am unfamiliar with this term "SHADER" thrown around??

I also notice it referenced to quake(3). Did carmack coin this or is it specific to quake? I dont understand how this "shader" refers to states....
Shaders allow to define a lot of triangles properties such as if the depth test is enble, the culling, textures stage (envmode, gentex...), rgb color ...

So all of that use states in OpenGL so to set up a shader system, you must have a good states switching manager.

For the glList it is a excellent methods to improve the speed !

Vko
Vko
I haven't read any of the above replies yet so this may have already been said, but you can enumerate the names or place them in an array of some sort

instead of calls like

glEnable(GL_TEXTURE_2D);
bState_Texture2D = true;

use stuff something like

Sorry, had to edit this. the source call doesn't understand the define statement or the // comments very well, or breaks either.
// following line not really necessary but makes it neat#define Statements_Number 3// texturing on by default#define Statements_Default_1 TRUE// depthtest on by default#define Statements_Default_2 TRUE// blend off by default#define Statements_Default_3 FALSEtypedef struct __mglState{ long int enable; char flag;}_mglState;_mglState mglState[Statements_Number]={ {  GL_TEXTURE_2D,Statements_Default_1 }, {  GL_DEPTH_TEST,Statements_Default_2 }, {  GL_BLEND,Statements_Default_3 }};#define mglEnable(x)\{\ if(mglState[x].flag==FALSE)\ {\  glEnable(mglState[x].enable);\  mglState[x].flag=TRUE;\ }\}#define mglDisable(x)\{\ if(mglState[x].flag==TRUE)\ {\  glDisable(mglState[x].enable);\  mglState[x].flag=FALSE;\ }\}



Beer - the love catalyst
good ol' homepage



PS - check if it is long int or what for glEnable/glDisable. I forgot. Make sure it is the same (pososibly glint) as it will save on converting the number format.

Edited by - Dredge-Master on January 5, 2002 11:59:44 AM
Beer - the love catalystgood ol' homepage
Guys... I have a question.

What is the benefit to doing all of that work instead of calling glIsEnabled( stateToCheck );

Is that function slow or something?
quote:Original post by smitty1276
Is that function slow or something?


Yes, very slow in some cases.

-Lev

This topic is closed to new replies.

Advertisement