Results 1 to 4 of 4

Thread: how to make glTexImage2D faster?

  1. #1
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    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 256*128 from 264*198 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:
    Code :
    // 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.

  2. #2
    Junior Member
    Join Date
    Aug 2009
    Posts
    2

    Re: how to make glTexImage2D faster?

    Hi,

    Here are some potential optimization opportunities:

    • 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]
    • 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]
    • 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]

  3. #3
    Junior Member
    Join Date
    Mar 2008
    Posts
    17

    Re: how to make glTexImage2D faster?

    Quote Originally Posted by skyostil
    Hi,

    Here are some potential optimization opportunities:

    • 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]
    • 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]
    • 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]
    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 256*256 and another one is 64*256. 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.

  4. #4
    Junior Member
    Join Date
    Sep 2009
    Posts
    2

    Re: how to make glTexImage2D faster?

    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

Similar Threads

  1. Faster on CPU than on the GPU
    By vijaykiran in forum OpenCL
    Replies: 1
    Last Post: 08-12-2010, 10:44 PM
  2. about glTexImage2D
    By freesui1984 in forum OpenGL ES general technical discussions
    Replies: 7
    Last Post: 07-21-2008, 07:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •