Bind Buffer best practice?

If your drawing an array every frame, should you add this after every draw?

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0);

Or is this something you do only at program exit?

Strictly speaking, neither is necessary.

Cheapest approach is to just update these bind points lazily as needed. That is, for example, never reset them to “0” as you are doing above until right before you need to draw a batch with client arrays.

…and if you never need to draw a batch with client arrays, you’ll never do this at all.

Cool… ok similar question but with textures.

For each draw and for each texture I go through something like this…

enable texture
bind texture
disable texture

enable texture 2
bind texture 2
disable texture 2

So, is there any reason I need to enable and disable these textures in every draw. Can’t I just enable them all at program startup and then just bind as needed? Wouldn’t that be more efficient? I have about 10 textures.

Jeffg it really depend on what you are doing and if you are using fixed or programmable pipeline.
With shaders you can use all available texture slot in a round robin style (you don’t have to enable texture, just to bind and tell the shader witch slot to use).
With fixed pipeline you don’t have to disable texture if the next draw call still use texture.
Leaving texture unit active can give some problem in big program, for example you draw something with a texture, then you want to draw a grid of lines. If you don’t disable the texture unit your lines will be textured (even is you don’t specify the UV).
One solution can be to write a render layer to manage those low level stuff.

What I do is state tracking. I know what vbo is bound and what texture is bound to which unit and what client array is enabled.

With shaders you can use all available texture slot in a round robin style (you don’t have to enable texture, just to bind and tell the shader witch slot to use).

I would advise something else. Just have global rules about what kinds of textures use which texture unit indices. All the diffuse textures go to texture unit 0, all detail maps go to texture unit 1, etc. Things like that. That way, you never have to change the program’s state. You set the texture units into the program once, and never again.

Thanks for all the great tips!