Texture update using glTexSubImage2D

Hi.





I’m recently trying to display a video or an image sequence on OpenGL ES window.





What I did is making texture with the size of 512x512 and replace the texture data partially by using glTexSubImage2D in every frame. It works, but the problem is that calling glTexSubImage2D reduces rendering performance drastically.





The video or image size I used is 320x240 and it is not a high resolution. I’m sure that it must be in real-time without loosing much performance.





Anybody knows how I can improve the performance ?





The platform I’m working on is iPod Touch with firmware 2.0








The texture is created as:





glGenTextures(1, &bg_texture) ;


glBindTexture(GL_TEXTURE_2D, bg_texture) ;


glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,


    tex_size, tex_size,


    0, GL_RGBA, GL_UNSIGNED_BYTE,


    nil);


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);








and updated in renderScene() function :





glBindTexture(GL_TEXTURE_2D, 0) ;


glBindTexture(GL_TEXTURE_2D, bg_texture) ;


glTexSubImage2D(GL_TEXTURE_2D, 0,0,0,


    320, 240,


    GL_BGRA, GL_UNSIGNED_BYTE,


    pixelData);





Hello,


 


For questions related to performance or drivers you should go to the platform provider. We do not have visibility of our customers’ drivers so we cannot answer these questions in a proper manner.


In general, and this is true for all MBX platforms, to use glTexImage2D() mid scene is a bad idea. Texture formats are encoded in a special order to allow optimal utilisation of cache memory (this is a common practice on all 3D acceleration) and this encoding has to be applied to the whole texture every time the texture is updated (it does not matter whether you are updating just a small region of it). Using the texture in the same frame will also cause synchronisations issues forcing the previous render to finish, losing all parallelism between the GPU and the CPU.


 


The only recommendation I can think of is to use a 512x256 texture. Also double buffering the texture upload (so the one in use is not the one currently being updated) might help with performance.


 


Regards.


 


Carlos.