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

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

## Recommended Posts

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?

##### Share on other sites
I'm fairly certain that you can do that, if you're so inclined.

##### Share on other sites
Quote:
 Original post by Thunder_HawkI'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?

##### Share on other sites
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).

##### Share on other sites
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.

##### Share on other sites
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);

##### Share on other sites
That's what I thought. Bummer. Thanks guys!

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 77
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632968
• Total Posts
3009586
• ### Who's Online (See full list)

There are no registered users currently online

×