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?
1 Answers
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.

- 449,505
- 63
- 781
- 982
-
Since I have an array texture, I'm using this one: void QOpenGLTexture::setData(int mipLevel, int layer, PixelFormat sourceFormat, PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions * const options = Q_NULLPTR), so from what you say I need to call allocateStorage everytime that I want to transfer the pixels to the texture from PBO right? – user3178756 Mar 14 '18 at 09:13
-
@user3178756: No. Indeed, [the documentation](http://doc.qt.io/qt-5/qopengltexture.html#allocateStorage-1) makes it clear that you cannot call `allocateStorage` *twice* on the same texture. I was trying to say that it needed to have been called before `setData`, not that there should be a 1:1 mapping between `setData` and `allocateStorage`. – Nicol Bolas Mar 14 '18 at 13:52
-
Thanks! I have another related question: GLubyte* ptr = (GLubyte*)m_vPUBONNZ[m_iPBONextIndx]->map(QOpenGLBuffer::WriteOnly); My texture is QOpenGLTexture::UInt16 and if I use anything other than GLubyte I will get a segmentation fault during rendering, why I can't cast to anything else (like GLushort) during PBO mapping? How one specifies the type of data for PBO? – user3178756 Mar 14 '18 at 18:03
-
@user3178756: I can't tell; you didn't post all of your relevant code. But I've answered your current question; if you have another, you should ask that. – Nicol Bolas Mar 14 '18 at 18:06