Rescaled values in QOpenGLBuffer objects when bound to shader program?
-
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?
-
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.
-
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");
@ -
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.
-
So you're saying, I should use:
@ QOpenGLFunctions::glVertexAttribPointer(programB.attributeLocation("qt_vertex"), 2, GL_UNSIGNED_SHORT, GL_FALSE, 2*sizeof(unsigned short), 0);
@ -
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
-
You mean to declare my QGLWidget class as:
@class LAURealTimeSLIGLWidget : public QGLWidget, protected QOpenGLFunctions@ -
Yes, and call initializeOpenGLFunctions() in initializeGL()
-
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!
-
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.
-
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.