I don't think you can do this, but you really should be able to

Started by
6 comments, last by Thunder_Hawk 19 years, 1 month ago
Let's say I'm drawing multiple objects using vertex arrays and they're all different such that some are textured, some use a color values, some use color indices, and some have surface normals, but they don't all have all of them. I have to do the following, don't I:

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);

//draw object 1

glDisableClientState(GL_COLOR_ARRAY);
glDisableCleintState(GL_NORMAL_ARRAY);

glEnableClientState(GL_TEXTURE_ARRAY);

//draw object 2

glDisableClientState(GL_TEXTURE_ARRAY);

glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_INDEX_ARRAY);

//draw object 3

glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_INDEX_ARRAY);

You'd think you could just OR those GLenums together into a single enable/disable call, but you can't, right? Wouldn't this be much nicer:

glEnableClientState(GL_VERTEX_ARRAY | GL_NORMAL_ARRAY | GL_COLOR_ARRAY);

//draw object 1

glDisableClientState(GL_COLOR_ARRAY | GL_NORMAL_ARRAY);

glEnableClientState(GL_TEXTURE_ARRAY);

//draw object 2

glDisableClientState(GL_TEXTURE_ARRAY);

glEnableClientState(GL_NORMAL_ARRAY | GL_INDEX_ARRAY);

//draw object 3

glDisableClientState(GL_NORMAL_ARRAY | GL_VERTEX_ARRAY | GL_INDEX_ARRAY);

Can that be done? I don't think it can (I can't really test it right now). I'm not really complaining that if it can't be done, but am rather curious why it's not done that way?
Without order nothing can exist - without chaos nothing can evolve.
Advertisement
I'm fairly certain that you can do that, if you're so inclined.
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
Quote:Original post by Thunder_Hawk
I'm fairly certain that you can do that, if you're so inclined.


I am quite inclined and shall try it at my next convenience. Thank you.

It just seems to me like it would not only cut back on the lines of code without sacrificing too much readability, and is more efficient. I mean, I'm replacing 2 function calls with 2 OR operators. That's got to be quicker, right?
Without order nothing can exist - without chaos nothing can evolve.
I don't think you can or them together.

To look at your first example (GL_VERTEX_ARRAY | GL_NORMAL_ARRAY | GL_COLOR_ARRAY):
Vertex_Array = 0x8074
Normal_Array = 0x8075
Color_Array = 0x8076

These values are not made to be OR-ed together (if you do, you get 0x8077, which happens to be GL_INDEX_ARRAY).
The value you pass to glEn/DisableCLientState, aswell as glEn/Disable, is a numeric value indicating which state to en/disable. Numeric values can't be OR'ed in the same way as bitmasks (as accepted by glClear and glPushAttrib for example). So no, you can't OR several states together.

Since glEn/DisableClientState is the equivalent to glEn/Disable but for the client side of OpenGL, it would also make sense to be able to do the same with glEn/Disable. Different behaviour for (essentially) the same functions doesn't make sense. But think about it for a second; there are quite a lot of states that can be en/disabled (in OpenGL 2.0 and all extensions, we're talking several hudreds of states), and new extensions introduces more and more states to en/disable. The value passed to glEn/Disable must be able to hold one bit for each state, and that means a datatype with several hundreds of bits.

So I don't think OR'ing states is a good idea.
You can't OR them together; They are not designer to be ORed together!
The values that are designed to be ORed together have _BIT attached to their name:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

That's what I thought. Bummer. Thanks guys!
Without order nothing can exist - without chaos nothing can evolve.
Whoops, sorry about that. Bad memory
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________

This topic is closed to new replies.

Advertisement