Game Development Community

GBitmap copy from buffer

by Xavier "eXoDuS" Amado · in Torque Game Engine · 06/15/2008 (2:48 pm) · 2 replies

Hey there, been a while since I wrote on this forums :)

I'm having some trouble copying from a GBitmap to another one, please read through this code first so I can explain:

glReadBuffer( GL_BACK );
	glBindTexture( GL_TEXTURE_2D, mTempBuffer->getGLName());
	glCopyTexSubImage2D( GL_TEXTURE_2D, 0,       // 0 = no mipmaplevels
						 0, 0,                   // X and y offsets, see docs
						 0, 0,					 // point
						 mBounds.extent.x,		 // extent 
						 mBounds.extent.y				 
						);

	mTempBuffer->refresh();
	mTempBuffer->getBitmap()->extrudeMipLevels();
	
	U8 *dst = mFrameBufferTexture->getBitmap()->getWritableBits(0);
	const U8 *src = mTempBuffer->getBitmap()->getBits(0);
	dMemcpy(dst, src, mTempBuffer->getWidth() * mTempBuffer->getHeight() * mTempBuffer->getBitmap()->bytesPerPixel);

	mFrameBufferTexture->refresh();

I'm copying the contents from the framebuffer to mTempBuffer, which is a Gbitmap that's been initialized before. Just for testing then I'm trying to copy the pixels directly from one Bitmap to another one, but the src buffer is always white, all the pixels are white. The bitmap itself contains valid data, since rendering mTempBuffer to the screen shows the bitmap correctly, it only appears white when I try to access the pixel data using ->getBits(0).

I've been pulling my hair at these for a whole day, is there something I'm missing?

Thanks!

#1
06/15/2008 (7:32 pm)
An update..

My best guess is that glCopyTexSubImage2D writes to it's own copy of the GBitmap data(). Since GBitmap is initialized as empty, and it just creates a GL name, it never knows about the data copy...

So is there another way to copy data to an arbitrary buffer I can supply? (getWritableBits())
#2
06/15/2008 (11:47 pm)
Nevermind... glReadPixels, but it's super slow to download from the GPU =]