Crude Hack To Enable OpenGL 3/4 Contexts

This is not a proposed patch to panda, as its a monster in disguise…its a proof of concept with the intent to write a patch capable of being included :stuck_out_tongue:

Currently, the hack/patch, enables using a QT window/surface as Panda’s main render window, and using QT OpenGL context as Panda’s context. Technically any apps context could be used, pyglet for example.

It works for me on arch linux(kde/gnome), mint/ubuntu and windows. Can’t check mac.
The example shows geom shaders and tessellation shaders, but I have also generated a texture with a compute shader to test that, although this is not so useful yet in panda.

Will explain the two patches later in post. My arch linux based patch is supplied.
I will do a file diff patch later for your convenience.

<<file uri:>>
<<file uri:>>
<<file uri:>>
<<file uri:>>

The butchered qt/c++ sean harmer demo, that I have rewritten in panda3d to test this is just here for a proof of concept. Not sure what the distribution rights are LGPL I think…but dont hold me to that please: ) Just use it to see it in action.


To avoid gotchya’s if you try the butchered SeanHarmer demo supplied you need qt5.1+ opengl version (not angle), pyqt or pyside in your panda python folder…just use pip or easy_install.

This example is just his code, rewritten in python/panda3d with his GL subroutines replaced by individual shaders as subroutines in shaders dont compile in panda at present. I should have done this by now, as I hacked the whole shader code to get compute shaders in lol

This will show Panda3d using tessellation shaders :slight_smile:

One very big gotchya is you have to use a GL backward compatibility profile, as new core opengl contexts dont have transforms and stuff. Don’t use core profiles!

You can see I use the 4.3 compatibility context for the butchered demo. Please note the QT debug contexts also work if you need precise timings :slight_smile: See timing queries in QT…

Obviously some things in Panda will break when sharing a more advanced context.
What i’ve found is if your panda geom auto-generates shaders, or you supply them, when its displayed they will work fine… where as if you use some of the old multipass?! stuff, they will crash to desktop.
To be honest all nodes should be using some sort of shader if you are planning to use new opengl from what I understand.

Why QT… no reason other than im lazy, it loads all OpenGL functions for use and all events work seamlessly between panda and QT. Pyglet will work too if you use my proposals.

###Patch Section One

New panda config var (cant be set when panda has already initialised obviously)

Nasty QT hook to hook in window/widget handle and context.

Initial makecurrent hack added to pandas render with the wait for contextready hook.

QT Swapbuffer hack at end of panda render. (this is needed or you dont see update in qt window)
Cleanup code for quit.

The above patches basically just implant the window and context.
I needed the context ready hook to avoid the occassionally nanosec delay in QT that would cause a CTD…dont ask me why the context can disapear in QT …but this solves it.

I propose this should really be encapsulated in a guardian type class, but my code is just a proof of concept hack sorry :slight_smile: For example SharedQTOpenGLGuardian blah blah

###Patch Section Two

New property in pandanode to indicate this node uses advanced Qt shaders, not pandas.

New advanced vert,frag,geom,tesscont,tesseval,compute pointers,buffer pointers.

Copy/Butcher of the current shader files. I basically copied them and put the hooks in if you using QT shaders to compile in QT after the panda shader properties have been built. Not proud of this, but as I say…see if it works…and it does.

Hook advanced shaders in drawcalls to QT if present.

Some example hooks ive used there, see the compute shader, tess shader hooks. You could literally put any advanced GL call in there.

Cleanup/release hack

To be honest, you could hook anything in this bit for example float textures from QT, the mipmap functions, the VBO,framebuffer object stuff. Which ever you add…you just override the normal panda node settings and have qt allocated it…and hook the relevant gl function in the draw call section. I used the buffer pointer for the compute shader to generate that crappy texture :stuck_out_tongue:

I propose this should all be encapsulated in a SharedQTPandaNode/Geom

Im posting this, as i’d like to come up with someway to have this added to panda as default.

I make no excuses for the crudity of my hack, but I just needed to see if it will work, im no gfx guru.

It seems to me, it would be very straight forward to add advanced guardians and an extended advanced geom node…then none of the above hacks would be needed :slight_smile:
Enabling silent OpenGL context creation from QT, pyglet, etc…

Let me know, with flames, what you think :slight_smile:

###Patch Section Two Update

<<file uri:>>

Quick update, and again no apologies for the gross hack :slight_smile:

Run this patch after

If you set the useAdvanced node property it now completely replaces pandas shaders.
Not fully checked this, maybe some problems.

As you can see, copied/renamed the panda src files and injected the QT bit, so original panda nodes with shaders are unaffected now.

I’ve checked transforms, auxiliaries and instance shader parameters seem to work fine.

You can see by the butchery done I just pass to the panda produced shader through a quick find/replace and have QT compile it :slight_smile:

This means you can now use all the new shader types unless im missing something.
However, to pass subroutine inputs and things like that you will need to use direct pyQT access to-:
from that you can access glGetSubroutineIndex,glUniformSubroutinesuiv etc.

Sorry about no error checking and all that, but hey I still didnt expect it to work :slight_smile:

One final test I am currently trying before clean up, is to add direct GL function access to the advanced pandanode/geom node.
Im thinking this will have a text file initial script, draw call script, and dispose script.

This would easily enable to use any open gl call from Panda from the node.
It initialises when you add the node, disposes on deletion and the draw call would inject its commands into pandas draw call when it is rendered.

Think you could fully use compute shaders then to access the buffers in panda through QT. At the moment they only work if the buffer stays in GPU memory, which it only does during the render pass currently so we dont get leaks…sorry

This will take more than a night to dust though.

I’m I the only one where the links dont show up as links?

1 Like

I will put a hosting link in little bit, cant say I’d noticed that sorry :stuck_out_tongue:

###Minor update###
Having spoken to rdb briefly yesterday this next hack may be irrelevant, but ive not had time to look at his suggestion.

I’ve added a few hook functions in panda texture file areas so you can silently use QTImage(opengl) formats. Ive always had issues modifying floating images in panda, but as i said im not really that clued up.
Note: you can use QTs painter functions to edit these images too! So Font rendering etc could be abuse too

As long as you dont use panda features on the hooked texture, it seems ok.

As adding QT as a dependency, or any other opengl framework (which is all im using it for basically), is a no go, I will propose and show a simple example, of a few updates to Panda that will remove the need to build linked to QT, or any other framework.

For example having OpenGL override/shared property in state guardian, and override pointer in nodes. With this, Panda would just delegate to the given attached subroutine when it encounters a node with advanced/external connection.

As i said, my current hacks were just to see if i could get it to work, and surprisingly it does.