glTexImage2D vs glTexStorage2D

Hello as far as I understand only diffrence is that glTexStorage2D can not be changed (constant amount of allocated memory) and thanks to this faster and glTexImage2D can lead to change of amount of memory allocated for texture but is slower.

I need to occasionally change the texture size (infrequently byt big changes in size) and I wanted to migrate from glTexStorage2D to glTexImage2D, but my texture stop functioning

I initialized earlier my texture like

glTexStorage2D(GL_TEXTURE_2D, 1, GL_RType, width, height);

and update

  glTexSubImage2D(GL_TEXTURE_2D,0,0,0, widthh, heightt, GL_RED_INTEGER, textSpec.OpGlType, data)

and it worked

now I changed to no immidiately assigning dataa by

glTexImage2D(GL_TEXTURE_2D,0,0,0, widthh, heightt, GL_RED_INTEGER, textSpec.OpGlType, data)

and it no longer work - what am I doing wrong?

You shouldn’t do that. Just create a new texture and delete the old one.

You can’t even use glTexImage2D with direct state access APIs, so if you ever want to switch to them, you’ll need to make your peace with glTexStorage.

You didn’t specify an internal format for the image. Well, you specified 0, but that’s not a valid internal format. I don’t see GL_RType anywhere.

Also, you specified 0 for the width, widthh for the height, and heightt for the border size. glTexImage2D doesn’t take the same parameters as glTexSubImage2D.

1 Like

Texture completeness

https://www.khronos.org/opengl/wiki/Texture#Texture_completeness

This is essential reading.

A texture specified by glTexStorage cannot be incomplete as it specifies the full texture in a single GL call. All miplevels, array slices, cube map faces, etc are guaranteed to be there, and the specification of each such level/face/slice/etc is guaranteed to match the others.

Using glTexImage there is no such guarantee, and other texture object state (glTexParameter) or even global state (glSamplerParameter) can affect whether or not the texture is complete. The driver must wait until you try to use the texture, then validate it against this other state. Because this other state can change any time, the texture must be revalidated each time.

Using glTexStorage your program will just be more robust.

1 Like