Reputation: 2757
I am trying to figure out how to implement batching in my OpenGL/DirectX based applications. I know that when depth test / depth write is enabled, I can put a bunch of objects that render with a common material in the same coordinate space and draw using a single draw call. But in my particular application, I have several objects that test against the depth buffer, but do not write to the depth buffer, and rely on draw order get the correct appearance. These are typically 2D geometry (e.g. a panel with dynamic information) in a 3D world.
Is there a general solution I can use to be able to batch items that normally need a specific draw order? Or do I need to tweak my scene and enable depth writing on everything to take advantage of batching?
Upvotes: 2
Views: 2178
Reputation: 91
GPUs will render in geometry order, even within a single draw call. In other words, the first triangle will draw before the second triangle, and so forth --- even though the shading calculations may occur in parallel.
So you shouldn't need to do anything special here. As long as your instances are arranged in draw order within the batch, the results will be the same as if you used multiple draw calls.
Upvotes: 4
Reputation: 950
You could partition your normalized Z space in N (number of 2D objects) then trace each object using a different normalized Z value corresponding to your draw order and let the depth test do the "sorting" for you.
Upvotes: 0