Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: glEnableVertexAttribArray() and glUseProgram()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: glEnableVertexAttribArray() and glUseProgram()



Right - vertex array state, shader state, and texture image unit binding are all separate...same with blend state, and probably more state that I'm not thinking of.

This means...

- You can mix & match shaders with vertex feed-in pretty easily. (Useful if you want to visualize the same data in different ways.)

- You have to bind up a lot of crud each time you want to draw.

Furthermore, the GPU is doing a bunch of work on your behalf and it's really hard to prevent it from doing this work. Each time you go to use a new set of vertex array bindings with a new shader (or even change just the shader or just the bindings) the GPU may go:

"Oh, you want array attribute 7 fed into this attribute of your shader. Let me carefully inspect that and make sure that's a valid thing to do."

IANADW* and in theory a very aggressive driver could try to cache these combinations and/or try to optimize them out, but in my experience, revalidation does happen and it burns CPU time. So if there's a moral of the story it's that pretty much _any_ change in state hurts, including changing only one aspect of the state vector (only the shader or only the vertex bindings), because one aspect may have to be validated against the other.

cheers
Ben

* I am not a driver writer.

Keith Bauer wrote:
You will have both 7 & 2 enabled.

In general, state in OpenGL is independent of other state.  You won't
find things being reset just because you called some unrelated
function.

-Keith

On Tue, Jun 15, 2010 at 9:18 AM, Patrick M. Rutkowski
<email@hidden> wrote:
I'm a bit confused about how glEnableVertexAttribArray() is supposed
to work with respect to what happens after you call glUseProgram().

Say I do something like:

glUseProgram(ShaderA);
glEnableVertexAttribArray(7)
RenderA();

glUseProgram(ShaderB);
glEnableVertexAttribArray(2)
RenderB();

Would this be considered a bug? I mean, would the RenderB() function
have both attrib arrays 7 & 2 active during it's execution? Because my
intention is definitely that only 2 be active.

Do I have to scrupulously call glDisableVertexAttribArray() on each
identifier after the rendering for a particular shader program is
done?

Before I really thought about this issue, I was sort of under the
assumption that glEnableVertexAttribArray() enabled the array only for
the active program, the one you had most recently called
glUseProgram() on. But I'm not sure that's the case anymore.

Any comments or ideas here anybody?
-Patrick
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


-- Scenery Home Page: http://scenery.x-plane.com/ Scenery blog: http://xplanescenery.blogspot.com/ Plugin SDK: http://www.xsquawkbox.net/xpsdk/ X-Plane Wiki: http://wiki.x-plane.com/ Scenery mailing list: email@hidden Developer mailing list: email@hidden _______________________________________________ Do not post admin requests to the list. They will be ignored. Mac-opengl mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >glEnableVertexAttribArray() and glUseProgram() (From: "Patrick M. Rutkowski" <email@hidden>)
 >Re: glEnableVertexAttribArray() and glUseProgram() (From: Keith Bauer <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.