stuartw
03-08-2006 01:54:41
Greetings people.
I have what is hopefully a simple question, I have spent some time looking for the answer, however it is currently eluding me.
I need to support a good form of RTT (Render To Texture)+Readback to python, basically to get the RGBA buffer back in a form I can use for non-screen things (such as input to the Python Imaging Library, lets say).
The RTT side of things is not difficult, however I seem to be beating my head up against a wall with organising the readback - a normal Texture seems to allow it, however a RenderTexture does not, and I am obviously missing somthing between the two.
Any hints? I would greatly appreciate any help here.
Regards,
Stuart.
Game_Ender
03-08-2006 17:41:48
I have code that does this in C++, not pyOgre, but hopefully it still works:
Creating the RenderTexture:
TexturePtr mTexture = TextureManager::getSingleton().createManual("RenderedImage",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D,
512 , 512, 0, PF_R8G8B8, TU_RENDERTARGET);
Creating a local copy of the hardware buffer
// Grab the hardward buffer and lock it
HardwarePixelBufferSharedPtr pBuffer = mTexture->getBuffer();
pBuffer->lock(HardwareBuffer::HBL_READ_ONLY);
// Get the current locked area of the texture (the whole thing)
PixelBox pixBox = pBuffer->getCurrentLock();
// Copy the image to system memory from the hardware buffer. The PixelBox
// is just a lightweight class that hold meta data about the buffer, it
// is needed for Pixel Conversion call.
PixelBox dest(512 , 512 , 1 , PF_R8G8B8);
// This will just do a straight copy if the pixel formats are the same
PixelUtil::bulkPixelConversion(pixBox, dest);
// Unlock the hardware buffer
pBuffer->unlock();
// Get an unsigned char pointer to our local copy of the render texture
uchar* finalBuffer = static_cast<char*>(dest.data);
finalBuffer is a pointer to the raw pixel data now stored in system memory and not the graphics card. This work fine and dandy in the my C++ program, but I have no idea what PixelBox::data returns in pyOgre.
stuartw
04-08-2006 00:59:02
I have code that does this in C++, not pyOgre, but hopefully it still works:
....
finalBuffer is a pointer to the raw pixel data now stored in system memory and not the graphics card. This work fine and dandy in the my C++ program, but I have no idea what PixelBox::data returns in pyOgre.
That is pretty much exactly what I want to do, unfortunately the needed functions dont seem to be wrapped in PyOgre yet, either ni 1.0.6 or 1.2, Does anyone know of a method that works in either? (The cannot eb THAT unusual a need, I suspect I am just missing something obvious).
Regards,
Stuart.
viblo2
05-08-2006 16:13:26
Depending on what you need it for, maybe you could use writeContentsToFile()?
Game_Ender
06-08-2006 21:24:56
The cannot eb THAT unusual a need, I suspect I am just missing something obvious.
Actually it is kind of an unusual request. I think most RTT results are just passed around inside of the GPU to generate various effects, this is sort of like using GPU like POVRay.