[SOLVED]Reading the render texture buffer.

saladin

18-12-2007 06:02:21

Hi,

I'm trying to have my ogre program render to a video instead of a sequence of images using pymedia. I got stuck when I need to get the pixel data from my renderTexture object.

In the C++ version, pixel data can be extracted from a render texture through the mBuffer member variable. But I cannot see it in python-ogre.

Or if someone knows how to copy the RenderTexture to a Texture, that can help work around it too.

Any help will be appreciated.

Cheers.

andy

18-12-2007 14:19:42

There is the readData function on a HardwarePixelBuffer.. The following is something simular on the HardwareBufferManager...

storageclass = ctypes.c_float * (8*9) #or whatever size...
temp=storageclass(1.1)
temphwb = ogre.HardwareBufferManager.getSingleton()
temphwb.readData(0, 2, ctypes.addressof(temp))


Regards
Andy

saladin

19-12-2007 01:39:06

There is the readData function on a HardwarePixelBuffer.. The following is something simular on the HardwareBufferManager...

storageclass = ctypes.c_float * (8*9) #or whatever size...
temp=storageclass(1.1)
temphwb = ogre.HardwareBufferManager.getSingleton()
temphwb.readData(0, 2, ctypes.addressof(temp))


Regards
Andy


Hi, thanks for the fast reply. But I got this error when calling readData on my pixel buffer.
OgreUnimplementedException: OGRE EXCEPTION(9:): Reading a byte range is not implemented. Use blitToMemory. in HardwarePixelBuffer::readData at ..\src\OgreHardwarePixelBuffer.cpp (line 163) :cry: :cry: :cry:

andy

19-12-2007 02:04:17

If you have Python-Ogre checkout from the svn you can look in ./demos/ogre/tests/Test_WriteToTexture.py (it might also be in the binary release?)

It shows the use of blitToMemory with a PixelBox :
..........
fontTexture = ogre.TextureManager.getSingleton().getByName\
(font.getMaterial().getTechnique(0).getPass(0).getTextureUnitState(0).getTextureName())

fontBuffer = fontTexture.getBuffer()
destBuffer = destTexture.getBuffer()

destPb = destBuffer.lock(destRectangle,ogre.HardwareBuffer.HBL_NORMAL)

## The font texture buffer was created write only...so we cannot read it back :o).
## One solution is to copy the buffer instead of locking it.
## (Maybe there is a way to create a font texture which is not write_only ?)

## create a buffer
nBuffSize = fontBuffer.getSizeInBytes()
## Here we show the difference in C++ and Python
## uint8* buff = (uint8*)calloc(nBuffSize, sizeof(uint8))
storageclass = ctypes.c_uint8 * (nBuffSize) # allocate a buffer class
buff=storageclass()

## the PixelBox call needs a pointer to the buffer and here's how we do this in Python-Ogre
VoidPointer = ogre.CastVoidPtr(ctypes.addressof(buff))

## create pixel box using the copy of the buffer
fontPb = ogre.PixelBox(fontBuffer.getWidth(), fontBuffer.getHeight(),fontBuffer.getDepth(),
fontBuffer.getFormat(), VoidPointer)
fontBuffer.blitToMemory(fontPb)

fontData = buff

# we nede to know the size of the dest buffer so hopefully this is right
destSize = destPb.getConsecutiveSize()
destData = (ctypes.c_uint8 * (destSize)).from_address( ogre.CastInt(destPb.getData()) )

fontPixelSize = ogre.PixelUtil.getNumElemBytes(fontPb.format)
destPixelSize = ogre.PixelUtil.getNumElemBytes(destPb.format)
............

Andy

saladin

19-12-2007 03:31:55

AWESOME! That's exactly what I need.
It's all sorted now. :lol: :lol: :lol: :lol: