Unsolved OpenGL array textures in Qt
-
Hello,
I'm wondering if and how it's possible to use array textures in Qt. The QGLWidget class doesn't seem to have a bindTexture () function for this.
Which functions from which Qt classes should i use? Or should i use the OpenGL functions directly? I'm looking to target Qt 5.2.1 cross-platform, and OpenGL core 3.3.
/* edit */ oh forgot to add, i'm using a subclass of QGraphisScene with a QGLWidget and some standard widgets (a few buttons, a text line edit, etc) overlaid via proxy widgets.
Thanks very much for any advice =)
-
For new code you should definitely switch from QGL* to QOpenGL* classes.
As part of them there's QOpenGLTexture that has support for texture arrays.Btw. Why 5.2.1? There's 5.5.1 already and 5.6. on its way.
-
Thanks for the info.
...yeah, the problem is that most linux distributions aren't shipping versions 5.5 yet. Ubuntu and derivatives are still on 5.2.1 for their LTS version which currently is 14.04.
So, it looks like i'll have to write my own functions to do some pixel managing...?
-
Not at all. According to the docs I linked QOpenGLTexture is supported starting with Qt5.2, so you should be good to go.
-
Oh, right. Thanks again!
-
...however, there seems to be a typo or some kind of mismatch in the QOpenGLTexture docs.
From https://www.opengl.org/wiki/Array_Texture --
"2D array textures are created similarly; bind a newly-created texture object to GL_TEXTURE_2D_ARRAY, then use the "3D" image functions to allocate storage. The depth​ parameter sets the number of layers in the array.
Each 2D row/column sequence of pixel data in the "3D" array of pixels is considered a separate 2D layer. "
From http://doc.qt.io/qt-5/qopengltexture.html --
"QOpenGLTexture::Target2DArray 0x8C1A An array of 1-dimensional textures. Equivalent to GL_TEXTURE_2D_ARRAY"
-
Yeah, looks like a copy/paste error in the description. The value seems to be correct though, so the functionality should work fine.
You can report a documentation defect on https://bugreports.qt.io. -
You're right, a rough test with single textures seems to work perfectly, yay! :D
...Could you paste a quick example of how i would load an array texture of multiple texture layers into a QOpenGLTexture object? (just the Qt specific stuff) ...thanks!
-
Hm, it seems that all the setData() overloads usefull for 2D arrays have been introduced in Qt 5.3. The only one in 5.2 is the one taking QImage, but it can't produce a texture array.
Ok, then in 5.2 you can use QOpenGLTexture to create and manage the lifetime, binding etc, but you'll have to upload the data using vanilla OpenGL i.e. using glTexImage3D and glTexSubImage3D or, if you have EXT_direct_state_access glTextureImage3DEXT and glTextureSubImage3DEXT. -
...so, i could simply not use QOpenGLTexture and instead use OpenGL directly for 2d texture arrays, by writing simple function(s) that take pixel data from a QImage and arrange this data in a way that OpenGL functions can accept... sounds like a good approach?
-
You could, but if you use Qt anyway it's convenient to use QOpenGLTexture, as it plays nice with other Qt OpenGL classes like shaders or FBOs. You could just make a function that uses vanilla GL to upload the data.
Your choice I guess. -
Thanks again for your valuable help.
Can you post a quick example/pseudocode of how i'd create a QOpenGLTexture object and add an array texture to it?