Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. OpenGL array textures in Qt
Forum Updated to NodeBB v4.3 + New Features

OpenGL array textures in Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 2 Posters 4.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    delt
    wrote on 5 Dec 2015, 10:25 last edited by delt 12 May 2015, 14:43
    #1

    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 =)

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 5 Dec 2015, 14:41 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        delt
        wrote on 5 Dec 2015, 14:46 last edited by
        #3

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

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on 5 Dec 2015, 14:47 last edited by
          #4

          Not at all. According to the docs I linked QOpenGLTexture is supported starting with Qt5.2, so you should be good to go.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            delt
            wrote on 5 Dec 2015, 21:56 last edited by
            #5

            Oh, right. Thanks again!

            1 Reply Last reply
            0
            • D Offline
              D Offline
              delt
              wrote on 5 Dec 2015, 22:05 last edited by
              #6

              ...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"

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on 5 Dec 2015, 22:23 last edited by
                #7

                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.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  delt
                  wrote on 6 Dec 2015, 14:41 last edited by
                  #8

                  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!

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on 6 Dec 2015, 15:19 last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      delt
                      wrote on 6 Dec 2015, 17:15 last edited by
                      #10

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

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        Chris Kawa
                        Lifetime Qt Champion
                        wrote on 6 Dec 2015, 17:21 last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          delt
                          wrote on 6 Dec 2015, 17:50 last edited by
                          #12

                          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?

                          1 Reply Last reply
                          0

                          1/12

                          5 Dec 2015, 10:25

                          • Login

                          • Login or register to search.
                          1 out of 12
                          • First post
                            1/12
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved