I wonder if calling updateGL() in fixed timer intervals may slow down the rendering process. So, I want to try making the render real time. I do not the function to make it execute automatically. Anyone knows that?
I wonder if calling updateGL() in fixed timer intervals may slow down the rendering process. So, I want to try making the render real time. I do not the function to make it execute automatically. Anyone knows that?
i added
in the constructor andQt Code:
this->format().setSwapInterval(1);To copy to clipboard, switch view to plain text mode
at the end of paintGL() function. but it had no effect. how to make it render 60fps?swapbuffers()
why would render consume this much CPU ? I thought it was only handled by GPU.
is there any way to optimize it?
well, I monitor CPU usage with htop in linux. render rate and CPU usage have a direct relation.
if I render less, it drops. but I don't want to do that. it's a display program, imagine a circle, each degree containing 1000 or 2000 pixels (small rectangles), total 360 * 1000 pixels on the screen.
Then how could I monitor a reliable one?
Qt Code:
void GlWidget::paintGL() { glClearColor(0, 0, 0, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); QMatrix4x4 vMatrix; float sg = pow(2, camera.zoom); float sx = 256.0 / width(); float sy = 256.0 / height(); vMatrix.setToIdentity(); vMatrix.scale(sx * sg, sy * sg, 1); vMatrix.translate(-2 * camera.panX + 1, 2 * camera.panY - 1, 0); shaderProgramPixels.bind(); shaderProgramPixels.setUniformValue("mvpMatrix", vMatrix); ppi->render(&shaderProgramPixels); shaderProgramPixels.disableAttributeArray("vertex"); shaderProgramPixels.disableAttributeArray("color" ); shaderProgramPixels.release(); shaderProgram.bind(); shaderProgram.setUniformValue("mvpMatrix", vMatrix); ppi->RenderRange(&shaderProgram); RenderLines(); shaderProgram.disableAttributeArray("vertex"); shaderProgram.disableAttributeArray("color" ); shaderProgram.release(); }To copy to clipboard, switch view to plain text mode
Vertices are created at initialization once and then only used. All render functions inside paint do the following:
Qt Code:
void PlanPositionIndicator::render(QGLShaderProgram* shaderProgram) { // qDebug() << vertices.size(); shaderProgram->setAttributeArray("vertex", vertices.constData()); shaderProgram->enableAttributeArray("vertex"); shaderProgram->setAttributeArray("color", GL_FLOAT,colors,1); // shaderProgram->setAttributeArray("color", GL_FLOAT,colors.data(),1); shaderProgram->enableAttributeArray("color"); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDrawArrays(GL_TRIANGLES, 0, vertices.size()); }To copy to clipboard, switch view to plain text mode
That's a very good question. Probably using some dedicated instrumentation tool.
What is "vertices"? Is it a vertex buffer? Did you tell OpenGL that these values are static?Vertices are created at initialization once and then only used. All render functions inside paint do the following:
Qt Code:
void PlanPositionIndicator::render(QGLShaderProgram* shaderProgram) { // qDebug() << vertices.size(); shaderProgram->setAttributeArray("vertex", vertices.constData()); shaderProgram->enableAttributeArray("vertex"); shaderProgram->setAttributeArray("color", GL_FLOAT,colors,1); // shaderProgram->setAttributeArray("color", GL_FLOAT,colors.data(),1); shaderProgram->enableAttributeArray("color"); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDrawArrays(GL_TRIANGLES, 0, vertices.size()); }To copy to clipboard, switch view to plain text mode
Yes, it is a vertex buffer.QVector<QVector3D> vertices;If by this you mean VBO, in which we allocate these vertices and colors inside GPU, No, I haven't yet done it with VBO.Did you tell OpenGL that these values are static?
But, I want to try it now, I hope it reduces CPU usage.
by the way, I know how to use VBO with standard C++ opengl and not Qt, do you have any samples in Qt for this?
Seems more like a QVector.
This implies that you copy the vertices again and again to the GPU upon rendering every frame. If the list of vertices is fixed, that's a pure waste of CPU power.If by this you mean VBO, in which we allocate these vertices and colors inside GPU, No, I haven't yet done it with VBO.
There are examples in the docs. The usage is similar, only that the API is wrapped into Qt calls.by the way, I know how to use VBO with standard C++ opengl and not Qt, do you have any samples in Qt for this?
by the way do you know
how to bind two vertex buffers into different slots (slot0 and slot1),
I want something like this in OpenGL(QT):
Qt Code:
QGLBuffer VB0, VB1; VB0.bind(0); VB1.bind(1);To copy to clipboard, switch view to plain text mode
If I understand you correctly then you need to bind the first buffer, then use a call similar to QOpenGLShaderProgram::setAttributeBuffer() and then repeat for the other buffer (bind and assign).
Does etAttributeBuffer accept the QGLBuffer parameter?!
Bookmarks