With the introduction of Panda3D 1.7.0, there is now a very powerful but also very dangerous feature that is now available to the public. This feature has been used internally at Walt Disney Imagineering for some time now, but it is now available to everyone. We call these Pointer Textures. It allows a user within python to give a long int to Panda3D, and Panda will cast this to a pointer and without question, upload the data at this pointer to the graphics card!
You can see why this is dangerous. This bypasses any checks or copies within Panda and is a direct gate to the graphics card. This means that if you do something wrong, your application will crash. No asserts, no error messages, it will just flat out crash. That should be about the extent of it, but I’d be lying if I said I didn’t cause a few BSODs here and there with this technique. Now that we have this little disclaimer out of the way, what is it good for?
For starters, it’s really fast. The current MovieTexture implementation actually does three copies of the same data within memory. Once from the decoder to system memory, once to Panda safe memory, and then another to the graphics card. This certainly works and the performance is quite reasonable. Where this fails is when you have large amounts of video data like 1080p content. That’s a lot of data to be unnecessarily moving around. For these applications, we use Pointer Textures.
We have an external python module that decodes movies using DirectShow and through pointer textures, we can display it in Panda as a texture. This has side benefits as well. Since DirectShow is multithreaded and a python module is not locked to the main python thread, DirectShow can decode the movies using different cores. This makes it a truly multi-threaded application. On a machine with 4 cores, I’ve managed to squeeze two simultaneous 720p videos through without problems.
Since pointer textures allow you direct access to graphics card memory, it also means that you can load anything as long as you have the pointer to the data and the correct format. Using this we’ve implemented Image Based Lighting via HDR textures.
Another added benefit to using pointer textures is that you don’t have to have to modify Panda to get special features. For instance, if you wanted to load an image format that is not currently supported by the texture loader, you would have to setup a Panda build environment, get the third party libs, and then modify the texture loader. Now you don’t have to. Just compile a python module via Swig or via the C Python API and make a function that returns the pointer as a long integer.
This goes far beyond static images or movies as well. Since it’s just data at a pointer, this method also works with special devices. Using this, we have connected Panda to specialized cameras, webcams, TV Tuner cards and even capture cards. The possibilities are endless.
If you want to start using this, here is a quick example that just loads a HDR pfm texture and displays it. It only works on Windows with Panda3D 1.7.0. I’ve included the source code for the python module as well if you are feeling like you want to compile that too. Simply run PfmTexture.py and you’ll should see the demo.