Jump to content
  • Advertisement
Sign in to follow this  

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!