Exploring Textures

I’ve been exploring the Texture class and stumbled on these two methods:


I checked their API and doc methods, but there are still some things that aren’t quite clear to me, so I thought it best to ask…

In what format is the format is the image stored in RAM? Can the RAM image still be encoded (in png or tif for example?)? Or is it in some raw image format (RGBA? YUV?)?

I’m also confused as to how I’m supposed to use modifyRamImage’s return value, as well as what I’m supposed to pass to setRamImage. As far as I can tell, Python doesn’t have any pointers. How do I get these methods to work?

This is the raw RGBA data of the texture. The precise format is defined by the other properties of the Texture class: getNumComponents() will be 3 for an RGB texture, or 4 for an RGBA texture; getComponentType() will usually be TUnsignedByte (in which case getComponentWidth() will be 1) but it might be TUnsignedShort (in which case getComponentWidth() will be 2).

The texture won’t be PNG or JPEG encoded, but it might be DXT encoded. If so, getRamImageCompression() will return something other than CMOff. You’d have to go out of your way to get a compressed texture image in the RAM image for a texture object, though.

All of these ram image methods operate on an object of type PTAUchar, which is a class object Panda uses internally to pass data objects around. You can call setData() or getData() on a PTAUchar to retrieve or set its actual data as a Python string. What you do with it from there is up to you, of course. People have asked for (and used) this interface as a means to transfer image data from some other source–see this post, for instance.


“You can call setData() or getData() on a PTAUchar to retrieve or set its actual data as a Python string.”

I tried to use PTAUchar.setRamImage on a unicode string, but I got a range error. It seems to expect me to pass it an ASCII string of 7-bit characters… but if I do that, how am I suppose to express the complete range of possible values for RGBA pixels?


Ahh… have to encode the string in latin-1 first. Yeesh, python really needs a byte type.