Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

QML UI over OpenGL

$
0
0
After some research, I considered 2 ways to achieve the result I want: rendering the OpenGL scene to an FBO, and displaying that below the QML UI Following this video by Sean Hammer I followed the 2nd option, and got it working. Now of course, my UI view “steals” all the mouse/touch events, which I’ll have to propagate to my OpenGL scene. The only issue remaining is a warning I get when rendering my OpenGL scene: W/Qt      ( 3975): kernel\qobject.cpp:777 (bool check_parent_thread(QObject*, QThreadData*, QThreadData*)): QObject: Cannot create children for a parent that is in a different thread. W/Qt      ( 3975): (Parent is RubiksGL(0x6003b3a8), parent's thread is QThread(0x5cb65e48), current thread is QSGRenderThread(0x5cb39758) I made sure that I added Qt::DirectionConnection to my connection between the beforeRendering() signal and the rendering slot, so I’m not sure where the threads are different. The only thing I know is it happens inside my OpenGL rendering function, which looks like this: void RubiksGL::render() {     m_funcs->glViewport(0, 0, width(), height());     m_funcs->glDepthMask(true);     m_funcs->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);       m_program->bind();     moveCamera();     computeViewProjectionMatrices();     drawObjects();     m_program->release(); } drawObjects does the following: Object *object;     QMatrix4x4 matrix;     QOpenGLVertexArrayObject *vao;         for (int i=0; i<m_objectsList.size(); i++)         {             object = m_objectsList.at(i);             matrix = m_VPMatrix * object->transform();             m_program->setUniformValue(m_matrixUniform, matrix);               vao = new QOpenGLVertexArrayObject(this);             vao->create();             vao->bind();             std::vector<QVector3D> vertices = object->vertices();             std::vector<QVector3D> colors = object->colors();               m_verticesVBO.bind();             m_verticesVBO.allocate(&vertices[0], vertices.size() * sizeof(QVector3D));             m_colorsVBO.bind();             m_colorsVBO.allocate(&colors[0], colors.size() * sizeof(QVector3D));               m_funcs->glEnableVertexAttribArray(0);             m_verticesVBO.bind();             m_funcs->glVertexAttribPointer(m_posAttr, 3, GL_FLOAT, GL_FALSE, 0, NULL);             m_funcs->glEnableVertexAttribArray(1);             m_colorsVBO.bind();             m_funcs->glVertexAttribPointer(m_colAttr, 3, GL_FLOAT, GL_FALSE, 0, NULL);             m_funcs->glDrawArrays(GL_TRIANGLES, 0, vertices.size());               m_funcs->glDisableVertexAttribArray(1);             m_funcs->glDisableVertexAttribArray(0);             m_verticesVBO.release();             m_colorsVBO.release();             vao->release();             delete vao;         } I know my usage of VAOs and VBOs is not correct (I should move them to my initialize() function), that is something I’ll fix later. The warning above is issued for each glDrawArrays call. Is there something I missed regarding threads, either between the QQuickView and OpenGL, or directly within my rendering function?

Viewing all articles
Browse latest Browse all 4972

Trending Articles