How to make glTexImage2D faster?

Hi,

i met some problems at speed of glTexImage2D. By capturing every frame from bulit-in camera of Symbian phone, i want to convert it to texture image. So firstly i change its size to 256128 from 264198 and then convert bgr to rgb. After that, i use glGenTextures to generate a texture object and bind this frame image. The codes are following:

// Textures are initialized in OpenGL ES API by this function.
    glGenTextures( 1, iTexturesID );	
    

    //Bind the background texture to iTexturesID[0], set the texture environment. 
    glBindTexture( GL_TEXTURE_2D, iTexturesID[0] );
    
    aBitmap.LockHeap();
    TUint8* aCamFrameData=(TUint8*)aBitmap.DataAddress(); //aBitmap is a converted image 

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, aCamFrameData);  
    aBitmap.UnlockHeap();

    
    
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR  );   
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
   
   		    
    // Before drawing the background texture, we need to switch to ortho (2D) mode.  
    // Passing 1 instead of the implicit size of screen will make OpeGL use the full size of screen (1:1)
    OrthoMode(0, 1, 0, 1);	
    DrawBGPoly();
    PerspectiveMode();
		    
    glDeleteTextures(1, iTexturesID);

I call this function when one frame is obtained. The real time of performance is so slow. The frame per second is only 6fps (The frame per second is about 13fps under no texture mapping). how can i raise the speed of texute mapping?
Looking forward to fast replying.

Thank you. :?

Hi,

Here are some potential optimization opportunities:

[ul]
[li] The texture object does not need to be deleted if you only want to replace its contents. Just keep the same texture object around and use glTexImage2D to refresh the pixel data.[/:m:sd9ea59f][/li][li] On some devices with hardware graphics accelerators, such as the N95, it might be beneficial to create two different textures and alternate between them in successive frames. This helps to avoid stalling the graphics accelerator if it is still busy using the texture when a new video frame comes in.[/:m:sd9ea59f][/li][] Profile your code to see whether the texture upload operation (glTexImage2D) is the bottleneck or whether it might be some other operation in the pipeline. For instance, you mentioned you change the bitmap size from 264x198 to 256x128. It might be better to let OpenGL ES scale the texture for you, and instead of resizing the CFbsBitmap just copy it to the upper left corner of a 256x128 bitmap.[/:m:sd9ea59f][/ul]

[quote=“skyostil”]
Hi,

Here are some potential optimization opportunities:

[ul]
[li] The texture object does not need to be deleted if you only want to replace its contents. Just keep the same texture object around and use glTexImage2D to refresh the pixel data.[/:m:mjgw0lph][/li][li] On some devices with hardware graphics accelerators, such as the N95, it might be beneficial to create two different textures and alternate between them in successive frames. This helps to avoid stalling the graphics accelerator if it is still busy using the texture when a new video frame comes in.[/:m:mjgw0lph][/li][li] Profile your code to see whether the texture upload operation (glTexImage2D) is the bottleneck or whether it might be some other operation in the pipeline. For instance, you mentioned you change the bitmap size from 264x198 to 256x128. It might be better to let OpenGL ES scale the texture for you, and instead of resizing the CFbsBitmap just copy it to the upper left corner of a 256x128 bitmap.[/*:m:mjgw0lph][/ul][/li][/quote]

Hi,

i improved my codes as following:

  1. in initialization routine, i use generate and store the texture id using glGenTextures and then give NULL pointer to glTexImage2D.
  2. in loop routine, i use glTexSubImage2D to update texture with scaled frame image.

For avoiding background skewing, i use two textures, one is 256256 and another one is 64256. The screen size and frame size both are 320*240. The redundant texture could be clipped by orthography. I use Nokia N95 to test. The real time performance is so low, about 9fps which is much lower than 30fps. I don’t know how to deal with it. Could anyone help me?

Thanks a lots.

The quickest format for uploading textures on the N95 seems to be RGB 565. In my application I get YUV frames from the camera, convert to RGB 565 and then use that in the texSubimage2D call. Can just about hit 30fps with that if you’re not doing any other processing. I’ve also got a Samsung i8910 (600MHz and a newer ARM core) - on that one I’ve written some NEON code (new ARM SIMD instructions) to do the YUV -> RGB 565 conversion in around 1.5ms, but the upload to texture and rendering still seems pretty slow (about 20ms).

Simon

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.