Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between glTexSubImage and glTexImage function in OpenGL

What is the difference between the two functions? Any performance difference?

Thanks..

like image 277
Edwin Avatar asked Mar 09 '10 00:03

Edwin


People also ask

What is glTexSubImage2D?

glTexSubImage2D redefines a contiguous subregion of an existing two-dimensional texture image. The texels referenced by data replace the portion of the existing texture array with x indices xoffset and xoffset + width - 1 , inclusive, and y indices yoffset and yoffset + height - 1 , inclusive.

What is glteximage2d?

glteximage2d is the function that actually moves the texture data across to the gpu. you will need to create the texture object first using glGenTextures() and then bind it using glBindTexture(). there is a good example of this process in the opengl redbook example. you can then use this texture with a VBO.

What is Gl_depth_component?

GL_DEPTH_COMPONENT is used for PixelFormat, and GL_DEPTH_COMPONENT16 is used for Framebuffer/Renderbuffer Object. glRenderbufferStorage can use GL_DEPTH_COMPONENT16.

What is texture buffer?

A Buffer Texture is a one-dimensional Texture whose storage comes from a Buffer Object. They are used to allow a shader to access a large table of memory that is managed by a buffer object.


1 Answers

You create a texture using glTexImage, and then update its contents with glTexSubImage. When you update the texture, you can update the entire texture, or just a sub-rectangle of it.

It is far more efficient to create the one texture and update it than to create it and delete it repeatedly, so in that sense if you have a texture you want to update, always use glTexSubImage (after the initial creation).

Other techniques may be applicable for texture updates. For example, see this article on texture streaming for further information.

(Originally, this post suggested using glMapBuffer for texture updates - see discussion below.)

like image 59
gavinb Avatar answered Sep 16 '22 18:09

gavinb