Issues with blitToMemory Usage

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
whizkid667
Gnoblar
Posts: 13
Joined: Sat Feb 21, 2009 5:10 am

Issues with blitToMemory Usage

Post by whizkid667 » Wed Aug 19, 2009 1:10 pm

Hi,

I am trying to write the entire contents of a texture into a buffer. For this I am using the "Ogre::HardwarePixelBuffer::blitToMemory" interface. This works perfectly fine in DirectX but crashes in OpenGl when I use a Non-Power-Of_Two texture. To rectify this I made the size of the buffer being passed into the pixel box to the next power of 2. This resolved the crash but unfortunately am unable to make sense of the data that I get back in the buffer(again only for OpenGL). As a test case I have a completely Red texture(jpg image) of size 10x10 pixels. So here am creating a buffer of size 512(instead of 400) and passing it to create the PixelBox. I've checked that the pixel format being obtained is "PF_X8R8G8B8". After Bliting I've listed out the Buffer being obtained below. It seems that upto 256 bytes its working fine. But after that it doesn't write anything at all. How should I then proceed to get the contents of the texture into a buffer? The interesting thing is that the PixelBox gives RowPitch as 10 and slicePitch as 100, which is same as the Width & Height.

Code: Select all

Ogre::HardwarePixelBufferSharedPtr 	pPixelBuffer	= _pUserData->_pTexture->getBuffer() ;
const size_t nSizeToCopy 						= pPixelBuffer->getSizeInBytes() ; //Gives 400
const unsigned int nAdjustedSize 				= GetNextPowerOfTwo_Fast(nSizeToCopy) ; // Increasing the size to the next power of 2 '512'

unsigned char*		pPixelData 				= new unsigned char[nAdjustedSize] ;
			
Ogre::PixelBox PxboxTemp = Ogre::PixelBox(Ogre::Box(0, 0, _pUserData->_pTexture->getWidth(), _pUserData->_pTexture->getHeight()), pPixelBuffer->getFormat(), pPixelData) ;

//pPixelBuffer->readData(0, nSizeToCopy, (void*)pPixelData) ;
pPixelBuffer->blitToMemory(PxboxTemp) ;

Ogre::uint8* pPixelBoxBuffer	= static_cast<Ogre::uint8*>(PxboxTemp.data) ;

const int nRowPitch = static_cast<int>(PxboxTemp.rowPitch) ; //Am getting rowPitch as 10
const int nSlicePitch = static_cast<int>(PxboxTemp.slicePitch) ; //Am getting slicePitch as 100

const int nPixelBoxHeight = nSlicePitch / nRowPitch ; // Am getting as 10
This is the buffer that am obtaining

Code: Select all

0x09FE6C10  00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff  ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ  : 32 Bytes
0x09FE6C30  00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff  ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ  : 64 Bytes
0x09FE6C50  00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff  ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ  : 96 Bytes
0x09FE6C70  00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff  ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ  : 128 Bytes
0x09FE6C90  00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff  ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ  : 160 Bytes
0x09FE6CB0  00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff  ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ  : 192 Bytes
0x09FE6CD0  00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff  ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ  : 224 Bytes
0x09FE6CF0  00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff 00 00 fe ff  ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ..þÿ  : 256 Bytes
0x09FE6D10  cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd  ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ            : 288 Bytes
0x09FE6D30  cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd  ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ            : 320 Bytes
0x09FE6D50  cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd  ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ            : 352 Bytes
0x09FE6D70  cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd  ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ            : 384 Bytes
0x09FE6D90  cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd  ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ            : 416 Bytes
0x09FE6DB0  cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd  ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ            : 448 Bytes
0x09FE6DD0  cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd  ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ            : 480 Bytes
0x09FE6DF0  cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd  ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ            : 512 Bytes
0x09FE6E10  fd fd fd fd ab ab ab ab ab ab ab ab ee fe ee fe 00 00 00 00 00 00 00 00 fb 4d fb c1 13 5b 0d 00  ýýýý««««««««îþîþ........ûMûÁ.[..
0x09FE6E30  80 0a 0f 05 f0 cc a6 02 ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe  €...ð̦.îþîþîþîþîþîþîþîþîþîþîþîþ
0x09FE6E50  ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe  îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþ
0x09FE6E70  ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe  îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþ

P.S : Am using NVidia GeForce GTS 250 card. I guess it should have supported Non-Power-Of-Two textures. But can't figure out why its not working in GL.

Thanks in Advance
0 x

Post Reply