Sign in to follow this  

Multiple Passes and Multiple Shaders with Vertex Arrays

This topic is 3572 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

There's a few concepts I'm not really understanding clearly with regards to Multiple Pass Rendering, Shaders, and Vertex Arrays. Let's say that I was rendering triangles using Vertex Arrays, and I'm trying to render 2 cubes. I want to texture the two cubes with two different textures and shade the cubes with two different shaders. It may sound silly but I feel confused as to how I could render these 2 cubes in just one call of glDrawArrays: I think I would have to make two calls to glDrawArrays because wouldn't you have to bind textures two times and call UseProgram two times(one time for each texture)? And even then, I think that glDrawArrays would immediately draw the array to the screen, therefore limiting me to one texture and one program per call to glDrawArrays.........is that a correct assumption? Would I possibly need multiple passes to render these two cubes?

Share this post


Link to post
Share on other sites
Correct, you are limited to one Shader program and one set of textures per drawing operation, because as you rightly point out you can't bind another set of textures during rendering.

I say set of textures because using 2 or more textures at once has been possible for many years now [smile]

Share this post


Link to post
Share on other sites
Ah yes, I did forget about that >_<.

So would I simply need to

1) Bind texture (or set of textures) and use the first program.
2) Call glDrawArrays to render the part of the array containing the first cube?
3) Bind another texture and use the second program
4) Call glDrawArrays again to render the other cube?

To render one single frame?

Share this post


Link to post
Share on other sites
Yep; although a point to keep in mind for future usage is to keep state changes down.

So if you have a bunch of object which need the same shader but different textures you'd bind the shader once and only change textures before rendering.

Share this post


Link to post
Share on other sites
Quote:
Original post by XenoPhyre
Thanks =D. So those two DrawArrays calls would render to the same frame? How would you start fresh and do a new frame?


glClear() begins a frame by clearing your back-buffer, and whatever SwapBuffers() function is provided by your API ends the frame by swapping the back-buffer onto the screen.

Share this post


Link to post
Share on other sites

This topic is 3572 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this