vg-renderer
vg-renderer copied to clipboard
feat: implements support for specifying depth order of drawing commands
We use vg-renderer extensively in our project and have found the need to specify a depth order (which gets passed through to bgfx::submit as depth). This is used to, for example, render text on top of UI components or just layer different shapes in a specified ordering
This PR attempts to add a public API to vg-renderer to specify the depth ordering state of the renderer. I'm unsure about some things:
- Should the function be called
depthOrderorsetDepthOrder(I went with the former, opting for brevity) - Should it be a state of
DrawCommand, or is it sufficient to keep the depth order inState? Again, I went with the former - If depthOrder does live in
DrawCommand, then do we need tom_ForceNewDrawCommandwhenctxPopStateruns if the depth order is different? - If depthOrder should live exclusively in
State, then is it OK togetState(ctx)from theend(...)function in order to read the depthOrder forbgfx::submit?
I am happy to change anything (naming, etc) to match convention here
Thanks for the PR and sorry for the delayed reply.
Unfortunately I cannot merge this PR atm because I feel this should be a feature implemented in a different way. Regarding your questions:
- Between the two naming choices you mentioned I'd prefer setDepthOrder().
- Both. The current depth order should be kept in State (so it'll be affected by push/pop) and copied into the DrawCommand's struct. The user does not know (and should not care) when a new DrawCommand is created.
- Yes.
- I didn't understand the question.
In other words, I'd implement it similar to how the scissor rect is currently handled.
May I ask how depth order can help with the "text on top of UI widget" case? Is your whole UI a single layer (background + text)? If it has multiple layers (e.g. overlapping windows), do you plan to increase the depth order for every UI layer?
My approach to this would be a bit different (and a bit more complicated). IMO the API should be something like:
vg::beginLayer(1)
// Draw shapes to layer 1 here
vg::endLayer() // Automatically revert to layer 0
// Draw shapes to layer 0 here
vg::beginLayer(2)
// Draw shapes to layer 2 here
vg::endLayer()
AFAIR, I tried implementing something like that in the layers branch but I never finished it. Unfortunately I don't remember the details.
Having said all that, I don't currently use this version of the library in my own projects. I use a stripped down version based on c99 branch. AFAIK @bkaradzic plans on integrating vg-renderer into bgfx at some point so it might be better if you tried porting your changes to his branch once it's ready.