I'm writing my own GUI lib using D3D11 ( but that's irrelevant ). I understand there are existing libraries out there for this, but I'm doing it for fun.
Anyway, each renderable quad has position, size, texture uv's, and colour (rgba) properties.
Each quad is stored within a quadbuffer that can hold 256 quads. And each source image holds a list of these quad buffers.
The typical render path is:
- Set shaders/data etc
- For each source image:
- Set source image
- Render each quad buffer
This seems to be very efficient, or at least efficient enough. Unfortunately, when designing the system I completely forgot about depth sorting.
Currently depth checks are disable for the GUI, and quads are literally rendered on top of each other as they come. As quads can have transparency,
ideally I'd like to render them from back to front to accumulate colour, but how would I go about sorting the quads and still render them efficiently?
I've considered giving each quadbuffer a depth layer, and then sorting the quadbuffers for rendering. This would still enable me to batch the quads, instead of rendering each quad individually.
But then I'd require more quadbuffers - and so more quads, than is necessary.
I guess this is the common battle between depth sorting and batching. Any thoughts?
Thanks
Edit: I should point out that the rendering of the GUI elements is separated from the implementation of the functionality. e.g A button doesn't have a render method, but instead holds renderable quads/sprites which will be rendered by the GUI system.