Would this result in a speed increase at all or is this a complete waste of time ? or is there a different/better way of doing this ?
cheers,
rich
Edit: code formattings a bit wonky, ah well
Edited by - burnseh on December 30, 2001 6:44:09 PM
Edited by - burnseh on December 30, 2001 6:44:55 PM

Would you mind elaborating on what you do, I am interested in building my own state manager.

Also, would a rendering manager by similar to a state manager? For example, to reduce state changes, I WOULD build a tree. Each node would be a state change and a linked list of data to render under that state. Then, rendering would traverse this tree of state nodes with data associated with each. Would this idea be the same as what is being discussed here??

It''s faster than just calling glEnable everytime, but that switch is a bottleneck, especially if you have a lot of cases. An easy way to avoid this is just writing some functions like mglEnableTexture2D and so on. Or define them as macros what''ll save you the function''s overhead. I use some trick of mine to optimize my code where I would need a switch, making the code as fast as seperate functions, but it needs special values for all cases and a lot of assembler, making it only usable if you may define all constants by yourself.

my opengl statemanager *handles sorting of states (for optimal performance).*it will also LOG out all current states (so i can see if something is enabled which shouldnt be)*a lot of error checking etc

There was an interesting discussion about redundant state changed on opengl.org''s forums and the thing that came out was that the redundant state changes should be avoided at any cost(well, almost at any cost). NVIDIA driver does not ignore them, while the driver _could_ check for redundant state changes they do not do it to favor well-written applications over badly-written(this was one of the points, search the advanced forum for more details).

While with many cases the state-manager could be a little slow, its still faster than a redundant state change in 99%. To speed up one could use macros, or, which I prefer, inline functions.

as lev saiz its a bad think if the driver checked. if it checked its gonna be slower so no drivers will do this for statechanges

shag - i havent been working much on gotterdammerung lately (been staying in a tent 5 days out of seven 4 the last couple of months whilst im away picking fruit thus no access to a computer) though the bright side is ive saved up enuf cash to buy me a geforce2mx if i can just make it to a decent sized town ill grab one (the nearest is 300km distance

I posted my idea of using a tree with state "nodes" where at each node has a linked list of data to render. At render time the tree is traversed, therby it should minimize state changes to what is needed....but no one really had any comments on whether this "sounds" good. Ive heard of this idea elsewhere. Sound good??

I think that the switch method is "too slow" because it costs a lot of "if" instructions.I had implement the state management through flag.

- to enable a state you wrote : Enable (CF_CULL_FACE); - CF_CULL_FACE is a flag define like below#define CF_CULL_FACE 0 //cull is the 0-th bit - a flag with the value of the state is declared: long states; - All render state are in an array :GLenum allGLstates[] = { GL_CULL_FACE, ... }; - and enable code is like this :void Enable (const ulong flag){ if ( GetFlagValue (states, (1< { glEnable ( *(allGLstates+flag) ); SetFlag (states, (1< }}I think that this method could be faster that the switch. But there are a lot of methods to do it.

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.

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 changedone 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

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.

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 FALSE