I have been trying to implement a dynamic texture that displays a series of images on a 2D plane. Images come in very quickly, so my implementation has to be as fast as possible.
What I decided to do is to directly modify the texture's buffer, taking inspiration from the dynamic texture tutorial and these code snippets shared from artoolkit.
This is how I defined my Dynamic texture:
Code: Select all
image_texture_ = texture_manager.createManual("DynamicImageTexture",
resource_group_name,
Ogre::TEX_TYPE_2D,
width_, height_, 0,
Ogre::PF_BYTE_RGB,
Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
And this is how I update it, by copying over the section of memory that contains the incoming image:
Code: Select all
{
Ogre::HardwarePixelBufferSharedPtr buffer = image_texture_->getBuffer(0,0);
buffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
const Ogre::PixelBox &pb = buffer->getCurrentLock();
uchar *data = static_cast<uchar*>(pb.data);
// Copy the data
memcpy(
(uchar*)pb.data,
(uchar*)&image->data[0],
image->data.size()
);
buffer->unlock();
}
However I have noticed that while Ogre asks you explicitly what kind of format the pixels should have, it completely disregards this information in favor of an internally defined "standard". Encoding detection won't matter if Ogre doesn't listen to me when I try to tell it how to read the data.
In my code I ask for an Ogre::PF_BYTE_RGB pixel format, but when I query the pixel buffer on its format it tells me it's Ogre::PF_A8R8G8B8, no matter what I specify. This behavior is confirmed here and here.
My questions are:
- How can I avoid the Pixel Format from being overridden and actually correctly interpreting the data I give?
- Can I do that without loosing much of the performance improvement given by the usage of dynamic textures?