Hi,
I've tried to optimize the merge of seperate colors into a texture, but
it's
very much slower !!! : 4ms vs. 120ms for a 256*256 texture.
The idea is to copy r, g, b values into a frame buffer by using
glColorMask
and then copy to texture inside hardware
Does any body have a better idea ?
Clemens
void Frame::Way1()
{
int iLen = sizeof( r);
for( int i=0; i < iLen; ++i)
{
rgb[i][0] = r[i];
rgb[i][1] = g[i];
rgb[i][2] = b[i];
}
GLuint iTex = -1;
glGenTextures( 1, & iTex);
glBindTexture( GL_TEXTURE_2D, iTex);
glTexImage2D( GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE,
rgb);
glDeleteTextures( 1, & iTex);
}
void Frame::Way2()
{
glPushAttrib( GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT );
int iNumBuffer = -1;
glGetIntegerv( GL_DRAW_BUFFER, & iNumBuffer);
glDrawBuffer( GL_AUX0);
// Drawing onto buffer
glRasterPos2i( 0, 0);
glColorMask( 1, 0, 0, 1);
glDrawPixels( 256, 256, GL_RED, GL_UNSIGNED_BYTE, r);
glColorMask( 0, 1, 0, 0);
glDrawPixels( 256, 256, GL_GREEN, GL_UNSIGNED_BYTE, g);
glColorMask( 0, 0, 1, 1);
glDrawPixels( 256, 256, GL_BLUE, GL_UNSIGNED_BYTE, b);
glColorMask( 1, 1, 1, 1);
// retrieving into texture buffer
GLuint iTex = -1;
glGenTextures( 1, & iTex);
glBindTexture( GL_TEXTURE_2D, iTex);
glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, 256, 256);
glGetTexImage( GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, rgb_res);
glPopAttrib();
}


|