How does DisplayRegion::set_sort work?


We are a group of people having problems with the DisplayRegion render order. The objective was to set a specific order in which various orthographic views were rendered together with perspective views.

The documentation is straight forward, so it the source code comments, but the reality is that the sorting does not work as advertised. In the examples we had something like this:


According to the documentation (and common sense/logic) this would render in the following order: bgcam1, bgcam2, and finally fgcam. That does not occur in reality.
You can follow the thread in for more detailed examples.

I tried auditing the source code to understand why the render order defies both the documentation and logic. It seems like TotalDisplayRegions is like any ordinary vector, but I’m not a compentent C++ programmer and I have not found the code that actualy sorts that vector.

We currently need someone who is skilled with C++ to provide us with an explanation how the render order REALLY works -or- can confirm that we have indeed found a bug.

I’m posting here in hope that someone who knows Panda3D on a lower level will reply.
Thanks in advance!

The DisplayRegions in the _active_display_regions vector are sorted into order in GraphicsOutput::do_determine_display_regions().

I’m not aware of any bugs with this. When I set the sort on my DisplayRegions, it appears to work correctly. Note that, as I indicated in another thread, there may be other circumstances that make it difficult to determine visually what order the DisplayRegions are actually rendering in.


OK, I downloaded your sandwich.tgz. It is as I suspected: the fact that the depth buffer is not cleared by default when a 3-d DisplayRegion is created is causing confusion.

If you look carefully at the action in, you can see that even though the yellow ring appears to be obscuring the 3-d tetrahexahedron, you can see the textured background plane through the semitransparent parts of the ring, even where the 3-d solid is supposedly in front of the ring.

What’s actually happening is that your DisplayRegions are indeed being drawn in the order you are asking them to be drawn, but the depth buffer is making some things appear behind other things that were drawn before them.

This problem is solved by adding clearDepth = 1 to the base.makeCamera() call. It’s not necessary on the base.makeCamera2d() call, because Panda automatically sets 2-d scenes to clear the depth buffer by default.

Incidentally, setting sort = 11 can (appear) to solve the problem too, because the default render2d DisplayRegion is created with sort = 10, and that DisplayRegion also clears the depth buffer. So sorting the 3-d window after render2d will inadvertently get a mostly clear depth buffer, especially if you’re not really using render2d for much.

Anyway. We don’t clear the depth buffer by default on the 3-d scene, because normally there is only one 3-d scene which is typically rendered first, and it is faster to clear the depth buffer on the overall window (which happens by default) rather than to clear it on the individual DisplayRegion. So it’s not necessary to clear the depth buffer on the very first 3-D scene rendered.

We used to not clear the depth buffer by default on the 2-d scene, for a similar reason–there’s a cost associated with doing this, and we thought it would be good to make people enable the depth buffer if they really wanted it. But we had too many problems with people failing to enable this when they did need it, and getting confused by what they saw as a result, so we finally just decided to enable it.

You’re the first outside the VR Studio to try to stack up 3-d DisplayRegions on top of 2-d DisplayRegions, so you’re the lucky first one to be confused by the same thing in the 3-d case. :slight_smile:

By the way, my apologies for the long delay in my response. Normally, I do try to respond in a timely manner to questions like this on the forum, but I’ve been out for about six weeks, recovering from a recent (and unexpected) surgery, after I fell off my bicycle and landed on my elbow. Funny, that–a little bump, and boom, suddenly you’re facing the prospect of being known as Lefty for the rest of your life. Thankfully, I’m once again (finally) able to type with both hands. :slight_smile:


Hey drwr,

I’ve never seen anyone in any community forum (Irrlich, Ogre, etc…) that answer so fast to so many types of question that can sometimes be , let’s say , very nasty !!

My two cents