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. Rescaled values in QOpenGLBuffer objects when bound to shader program?
Forum Update on Monday, May 27th 2025

Rescaled values in QOpenGLBuffer objects when bound to shader program?

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 2.9k Views
  • 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
    drhalftone
    wrote on last edited by
    #1

    In traditional OpenGL, I can specify if I want the values stored in my vertex buffer to be rescaledn (normalized) prior to sending to my vertex shader using the command:

    @void glVertexAttribPointer( GLuint index,
    GLint size,
    GLenum type,
    GLboolean normalized,
    GLsizei stride,
    const GLvoid * pointer);@

    In my case, my vertex buffer contains 2D vectors of type unsigned short. There doesn't seem to by any hooks into the new QOpenGLBuffer object for me to control this behavior when I bind the buffer to my vertex shader. So all my values get rescaled to the range between 0.0 and 1.0.

    Is there a way to control this behavior through the QOpenGLBuffer class?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      agocs
      wrote on last edited by
      #2

      The corresponding wrappers are in QOpenGLShaderProgram (setAttributeBuffer), not QOpenGLBuffer. And no, unfortunately it hardcodes GL_TRUE for normalized always.

      The workaround is simple though: call the gl function directly: context->functions()->glVertexAttribPointer(...). The wrappers do not add any useful functionality in this case.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        drhalftone
        wrote on last edited by
        #3

        Thanks. I just needed confirmation that it wasn't available in any of the QOpenGLXXX classes. And as you suggested, I modified the code to read:
        @ glVertexAttribPointer(programB.attributeLocation("qt_vertex"), 2, GL_UNSIGNED_SHORT, GL_FALSE, 2*sizeof(unsigned short), 0);
        programB.enableAttributeArray("qt_vertex");
        @

        1 Reply Last reply
        0
        • A Offline
          A Offline
          agocs
          wrote on last edited by
          #4

          Ok. You might want to use QOpenGLFunctions if you are using desktop OpenGL on Windows for example (since GL2 functions like glVertexAttribPointer are not available as regular functions there).

          Anyway, this behavior in the wrappers is really bizarre. I have created https://bugreports.qt-project.org/browse/QTBUG-37103 to investigate this further.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            drhalftone
            wrote on last edited by
            #5

            So you're saying, I should use:
            @ QOpenGLFunctions::glVertexAttribPointer(programB.attributeLocation("qt_vertex"), 2, GL_UNSIGNED_SHORT, GL_FALSE, 2*sizeof(unsigned short), 0);
            @

            1 Reply Last reply
            0
            • A Offline
              A Offline
              agocs
              wrote on last edited by
              #6

              No, you need a QOpenGLFunctions instance. Either fetch it from the QOpenGLContext (like, say, QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions()) or derive from the class as shown in http://qt-project.org/doc/qt-5.0/qtgui/qopenglfunctions.html

              1 Reply Last reply
              0
              • D Offline
                D Offline
                drhalftone
                wrote on last edited by
                #7

                You mean to declare my QGLWidget class as:
                @class LAURealTimeSLIGLWidget : public QGLWidget, protected QOpenGLFunctions@

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  agocs
                  wrote on last edited by
                  #8

                  Yes, and call initializeOpenGLFunctions() in initializeGL()

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    drhalftone
                    wrote on last edited by
                    #9

                    Okay. No problem. As a matter of fact, this whole thing started with a Qt example that includes that already. I just evolved that example to what I have now. Thanks for keeping me straight!

                    1 Reply Last reply
                    0
                    • Z Offline
                      Z Offline
                      ZapB
                      wrote on last edited by
                      #10

                      This is one of the many broken things in QOpenGLBuffer that I hope to address for Qt 5.4. The vertex specification really should not be on QOpenGLShaderProgram at all but rather on the buffer object / vertex array object. Unfortunately the QOpenGLBuffer API makes some assumptions that are incorrect and as a result is broken beyond repair. Fixing it will require a new class.

                      For now, as Laszlo says, just call glVertexAttribPointer directly or via one of the OpenGL function wrappers in Qt.

                      Nokia Certified Qt Specialist
                      Interested in hearing about Qt related work

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        StridaHD
                        wrote on last edited by
                        #11

                        Stumbling over the same problem with no choice of normalization, I totally agree that this issue should be adressed in the next version of Qt!

                        Thanks for the info provided in this thread.

                        1 Reply Last reply
                        0

                        • Login

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