Some questions about the basic procedure for drawing
I have successfully completed a OpenGL ES 1.1 app for Android and people seem to like it. Now I'm reading the book "Open GL ES 2.0 Programming Guide" and trying to learn about how to use shaders. I think I get most of it, but I'm confused on a few points.
In 1.1, it was pretty straightforward. I would send OpenGL my list of vertices, texture coords and normals, and then call glDrawElements() and my model would get drawn.
Now in 2.0, I can specify the Vertex Attributes, which include the vertices, texture coords and normals, and maybe more. Then I call glDrawElements() and specify the indices of the vertices of my triangles. This time, it is my vertex shader which understands which attribute is position, and then puts it in gl_position, which the frag shader will pick up and use.
What I'm confused about is whether I have to send the attributes every time I draw, or next frame (where perhaps the only thing different is the view matrix) do I only have to call glDrawElements() again with the indices? Do the Vertex Attributes persist?
Another question is, where do the primitives get clipped against the view frustum? Does my application have to be careful to only send primitives which are in the view for performance reasons, or would OpenGL clip them fairly early in the chain anyway, so I don't need to work very hard at not sending triangles which have no chance of being in the view?
Thanks very much for any insight.
Re: Some questions about the basic procedure for drawing
Ok, I re-read Chapter 1 and this one was answered on page 7:
Another question is, where do the primitives get clipped against the view frustum?
"In the primitive assembly stage, the shaded vertices are assembled into individual geometric primitives that can be drawn as a triangle, line or point-sprite. For each primitive, it must be determined whether the primitive lies within the view frustum (the region of 3D space that is visible on the screen). If the primitive is not completely inside the the view frustum, the primitive might need to be clipped to the view frustum. If the primitive is completely outside, it is discarded."
So, if I send indices of triangles which are outside the view, they will clipped during primitive assembly, which is after the vertex shaders run (but before the frag shaders). So it becomes a question of which is faster, to try to eliminated triangles before I send the indices, or send them all through the vertex shaders and let the GPU clip them against the view frustum.