Multiple Passes and Multiple Shaders with Vertex Arrays

Started by
5 comments, last by XenoPhyre 16 years, 1 month ago
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?
Advertisement
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]
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?
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.
Thanks =D. So those two DrawArrays calls would render to the same frame? How would you start fresh and do a new frame?
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.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Now I understand everything! Thanks a lot! :) I guess I forgot there was something called a back-buffer..

This topic is closed to new replies.

Advertisement