Search code examples
c++qtopenglqtopengl

glTexSubImage3D vs QOpenGLTexture setData


To my understanding QOpenGLTexture::setData is equivalent to glTexImage3D in case of texture array or 3D texture. Now if I want to use PBO to update the texture at runtime, I need to use glTexSubImage3D instead of glTexImage3D, what is the equivalent in Qt texture for that?


Solution

  • First, asynchronous uploads in no way require the use of glTexSubImage3D; they work for any pixel transfer function.

    Second, setData is the equivalent of the SubImage-class of OpenGL functions. Or at least, most overloads of setData are; the one that takes a MipMapGeneration flag will allocate storage for you (because Qt's OpenGL abstraction is the place where consistency goes to die). So you can use PBOs just fine with setData.

    Textures in OpenGL are rather like pointers. allocateStorage is like allocating memory and storing the allocated memory in a pointer (int *p = new int[20];). setData is like accessing the allocated object and copying data into it (p[0] = 5;). You have to have allocated memory before you can store stuff into it, but you don't need to allocate memory again after you've done so before.