Hey good people,

I'm working on implementing a nice little render manager for my WebGL framework (will write a similar implementation for my Android framework later on) and right now I'm a bit at loss on optimizing the code and give the pipeline a good flow. What I understand is that I need to cramp in as many operations as possible in each draw call to make best use of the shader based pipeline, but most tutorials on the subject concentrate on simple draw calls off single elements just to give us a hint on how to render stuff.

Right now I have some questions on how to sort the draw calls, there are a couple of things that divide them, among these the Texture, shader and depth.
The first question is, if I want to draw a 2d scene, is it worth to enable Depth testing and giving the different sprites a z value, or is it better to pay the extra draw calls to get objects in the right z index? Say you have one texture for background and then another one for objects, but after that you need to use the first texture again for some reason, is it better to do the extra draw call or would I cram out better performance on enabling the Depth test?

It would be really nice to hear about how other people are solving the rendering loop for a shader based pipeline as I've always been working with the fixed pipeline before, its somewhat of a step to take to get used to the new way of sorting and optimizing really.

I think I should leave the question there right now, see if I get some answers to the depth thing that continue to pick on the topic as I develop my implementation.

Anyway, I look forward to hear your thoughts on the subject and see how others tackle this.

Cheers!