22

Are glTexImage2D and glTexSubImage2D the only ways to pass a buffer of pixels to a texture?

At the moment I use in a setup function glTexImage2D passing null as the buffer, and then on the render loop I call glTexSubImage2D with the new buffer data on each iteration.

But knowing that the texture will not change any property such as the dimensions, is there any more efficient way to pass the actual pixel data to the rendering texture?

Sergey K.
  • 24,894
  • 13
  • 106
  • 174
PerracoLabs
  • 16,449
  • 15
  • 74
  • 127

1 Answers1

44

In modern OpenGL there are 4 different methods to update 2D textures:

  1. glTexImage2D - the slowest one, recreates internal data structures.

  2. glTexSubImage2D - a bit faster, but can't change the parameters (size, pixel format) of the image.

  3. Render-to-texture with FBO - update texture entirely on GPU, very fast. Refer to this answer for more details: https://stackoverflow.com/a/10702468/1065190

  4. Pixel Buffer Object PBO - for fast uploads from CPU to GPU, not supported (yet) on OpenGL ES.

zero298
  • 25,467
  • 10
  • 75
  • 100
Sergey K.
  • 24,894
  • 13
  • 106
  • 174
  • I see that FBO would be the best option, but, my textures need to use the GL_LUMINANCE parameter and I just found out that FBO do not support such. Is then the only option to use glTexSubImage2D? – PerracoLabs Nov 07 '12 at 10:27
  • Do you use desktop OpenGL or OpenGL ES? – Sergey K. Nov 07 '12 at 10:30
  • using OpenGL ES on Android. The reason to use GL_LUMINANCE is that I must pass YUV420sp data into a shader, there for I do 2 calls to glTexSubImage2D to pass 2 planes, one for Y and another for UV. and therefore I have to use GL_LUMINANCE. the option of converting YUV into RGB prior to pass the data to the shader is not an option for speed reasons. – PerracoLabs Nov 07 '12 at 13:42
  • You must compare the performance of rendering into RGB FBO vs TexSubImage2D/GL_LUMINANCE. If RGB FBO is faster - just use it. If it is not - use TexSubImage2D. – Sergey K. Nov 07 '12 at 13:52