summaryrefslogtreecommitdiffstats
path: root/examples/opengl/threadedqopenglwidget
diff options
context:
space:
mode:
Diffstat (limited to 'examples/opengl/threadedqopenglwidget')
-rw-r--r--examples/opengl/threadedqopenglwidget/glwidget.cpp22
-rw-r--r--examples/opengl/threadedqopenglwidget/glwidget.h2
-rw-r--r--examples/opengl/threadedqopenglwidget/main.cpp5
3 files changed, 22 insertions, 7 deletions
diff --git a/examples/opengl/threadedqopenglwidget/glwidget.cpp b/examples/opengl/threadedqopenglwidget/glwidget.cpp
index 34d97bf1bf9..d447f0c7166 100644
--- a/examples/opengl/threadedqopenglwidget/glwidget.cpp
+++ b/examples/opengl/threadedqopenglwidget/glwidget.cpp
@@ -47,10 +47,6 @@ const int bubbleNum = 8;
GLWidget::GLWidget(QWidget *parent)
: QOpenGLWidget(parent)
{
- QSurfaceFormat format;
- format.setDepthBufferSize(16);
- setFormat(format);
-
setMinimumSize(300, 250);
connect(this, &QOpenGLWidget::aboutToCompose, this, &GLWidget::onAboutToCompose);
@@ -120,11 +116,16 @@ Renderer::Renderer(GLWidget *w)
void Renderer::paintQtLogo()
{
- program.enableAttributeArray(normalAttr);
+ vbo.bind();
+ program.setAttributeBuffer(vertexAttr, GL_FLOAT, 0, 3);
+ program.setAttributeBuffer(normalAttr, GL_FLOAT, vertices.count() * 3 * sizeof(GLfloat), 3);
+ vbo.release();
+
program.enableAttributeArray(vertexAttr);
- program.setAttributeArray(vertexAttr, vertices.constData());
- program.setAttributeArray(normalAttr, normals.constData());
+ program.enableAttributeArray(normalAttr);
+
glDrawArrays(GL_TRIANGLES, 0, vertices.size());
+
program.disableAttributeArray(normalAttr);
program.disableAttributeArray(vertexAttr);
}
@@ -201,6 +202,13 @@ void Renderer::render()
m_fScale = 1;
createGeometry();
+ vbo.create();
+ vbo.bind();
+ const int verticesSize = vertices.count() * 3 * sizeof(GLfloat);
+ vbo.allocate(verticesSize * 2);
+ vbo.write(0, vertices.constData(), verticesSize);
+ vbo.write(verticesSize, normals.constData(), verticesSize);
+
m_elapsed.start();
}
diff --git a/examples/opengl/threadedqopenglwidget/glwidget.h b/examples/opengl/threadedqopenglwidget/glwidget.h
index 9d746e681b2..8319faf322b 100644
--- a/examples/opengl/threadedqopenglwidget/glwidget.h
+++ b/examples/opengl/threadedqopenglwidget/glwidget.h
@@ -44,6 +44,7 @@
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
+#include <QOpenGLBuffer>
#include <QVector3D>
#include <QMatrix4x4>
#include <QThread>
@@ -83,6 +84,7 @@ private:
QVector<QVector3D> vertices;
QVector<QVector3D> normals;
QOpenGLShaderProgram program;
+ QOpenGLBuffer vbo;
int vertexAttr;
int normalAttr;
int matrixUniform;
diff --git a/examples/opengl/threadedqopenglwidget/main.cpp b/examples/opengl/threadedqopenglwidget/main.cpp
index 046a24d5766..75b7f5e46f6 100644
--- a/examples/opengl/threadedqopenglwidget/main.cpp
+++ b/examples/opengl/threadedqopenglwidget/main.cpp
@@ -40,6 +40,7 @@
#include <QApplication>
#include <QMainWindow>
+#include <QSurfaceFormat>
#include "mainwindow.h"
#include "glwidget.h"
@@ -47,6 +48,10 @@ int main( int argc, char ** argv )
{
QApplication a( argc, argv );
+ QSurfaceFormat format;
+ format.setDepthBufferSize(16);
+ QSurfaceFormat::setDefaultFormat(format);
+
// Two top-level windows with two QOpenGLWidget children in each.
// The rendering for the four QOpenGLWidgets happens on four separate threads.
MainWindow mw1;