Occlusion not working with QPanda3D

NOTE: the following issue is related to the QPanda3D module and I already posted it as an issue on the corresponding github repo:

However, I feel there must be something very basic related Panda3D that I am doing wrong. Thus I thought it might be of interest to the main Panda3D discourse as well.

The issue is this:

I want to use PyQt5 for the GUI instead of DirectGUI. I found that most threads on the topic are rather outdated. The most thoroughly discussed and most recent thread I found was the following:

However, no conclusion was found to have the Panda3D window not appear in addition to Qt’s GL window which panda renders into. Thus I looked further and found the aforementioned QPanda3D module on github and pypy.

Unfortunately, when integrating QPanda3D into my game, I found that some objects were not appearing at all in the scene, or that they would not occlude each other as expected, i.e. an object that should be in front of another object gets rendered as if it were behind it.

I wrote an MWE that showcases the behaviour in both settings:

  • Panda3D + PyQt5 (wrong occlusion)
  • Panda3D + DirectGUI (correct occlusion)

You can find the MWE here: https://github.com/ParisNeo/QPanda3D/issues/4

I’d really appreciate any pointers as to what might be going wrong in the PyQt5 setting that causes this strange rendering behaviour.

Does the Qt GL window have a depth buffer?

After digging a bit deeper, I found that the QPanda3D module is based on the regular QWidget example from the thread I linked above. It grabs the rendered image from panda directly and paints it on itself in the paintEvent:

def paintEvent(self,  event):
        if self.panda3DWorld.screenTexture.mightHaveRamImage():
            self.panda3DWorld.screenTexture.setFormat(Texture.FRgba32)
            data = self.panda3DWorld.screenTexture.getRamImage().getData()
            ...

where panda3DWorld is an instance of Panda3DWorld which inherits ShowBase. The code for Panda3DWorld is located here: https://github.com/ParisNeo/QPanda3D/blob/master/QPanda3D/Panda3DWorld.py

I found the following calls:

        props = FrameBufferProperties()
        props.set_rgb_color(True)
        props.set_rgba_bits(8, 8, 8, 8)
        props.set_depth_bits(0)

        self.buff = self.graphicsEngine.make_output(
            self.pipe, name, sort,
            props, winprops,
            GraphicsPipe.BF_resizeable,
            self.win.get_gsg(), self.win)

and sure enough, changing the line

set_depth_bits(0)

to

set_depth_bits(8)

resolved the issue, i.e. the MWE is working as expected with both Qt and the plain Panda3D + DirectGUI setting. I’ll mark this as resolved and update the issue on QPanda3D 's GitHub.
Thank’s for pointing me in the right direction with your question, rdb!

I still have the following questions:

I wonder whether there might be any reason the author set it to zero.
Is 8 bits a reasonable precision for the depth buffer? The default seems to be 0 , since when I completely leave the line props.set_depth_bits(X) out, it reverts to the old “broken” behaviour.

Secondly, do you see any issues (e.g. performance) with going forward with the plain QWidget and screenTexture.getRamImage().getData() approach?

Since the development on QPanda3D seems to be stale (Mouse support missing since June) I am thinking about forking the repo and adding the features I need for my game, meanwhile contacting the author to see if he wants to revise and merge additions. I just don’t want to put in the effort if this is not a good setting from the start from the perspective of Panda3D.