Updating a texture in OpenGL with glTexImage2D
Asked Answered
B

1

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?

Blather answered 25/3, 2012 at 20:55 Comment(0)
P
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://mcmap.net/q/527830/-how-to-manipulate-texture-content-on-the-fly

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

Photocomposition answered 6/11, 2012 at 10:4 Comment(4)
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?Blather
Do you use desktop OpenGL or OpenGL ES?Photocomposition
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.Blather
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.Photocomposition

© 2022 - 2024 — McMap. All rights reserved.