summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@digia.com>2014-09-01 16:25:14 +0200
committerLaszlo Agocs <laszlo.agocs@digia.com>2014-09-04 14:06:42 +0200
commitf4ae4f41b06d61f32dbef3cac90e8e3b187ee378 (patch)
tree8a60f24e55ea02579dcecf6aae9e629045411381
parent105fa5b5d9e876bd0da962f2a91ccd83d8bea459 (diff)
hellowindow: Set all the state for each frame
Trying to be smart and minimizing the amount of GL calls per frame to provide a good example was a mistake (in a way): There are components, like the eglfs mouse cursor, that change the context state. To make sure the example work in these cases, set the state upon each frame. Change-Id: Ief1fd7bbb0fb1955a64dac97a071b7a3d9d506d4 Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
-rw-r--r--examples/opengl/hellowindow/hellowindow.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp
index da31fee920..57eb111edb 100644
--- a/examples/opengl/hellowindow/hellowindow.cpp
+++ b/examples/opengl/hellowindow/hellowindow.cpp
@@ -147,6 +147,21 @@ void Renderer::render()
f->glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio());
f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
+ f->glFrontFace(GL_CW);
+ f->glCullFace(GL_FRONT);
+ f->glEnable(GL_CULL_FACE);
+ f->glEnable(GL_DEPTH_TEST);
+
+ m_program->bind();
+ m_vbo.bind();
+
+ m_program->enableAttributeArray(vertexAttr);
+ m_program->enableAttributeArray(normalAttr);
+ m_program->setAttributeBuffer(vertexAttr, GL_FLOAT, 0, 3);
+ const int verticesSize = vertices.count() * 3 * sizeof(GLfloat);
+ m_program->setAttributeBuffer(normalAttr, GL_FLOAT, verticesSize, 3);
+
QMatrix4x4 modelview;
modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
@@ -212,18 +227,6 @@ void Renderer::initialize()
m_vbo.allocate(verticesSize * 2);
m_vbo.write(0, vertices.constData(), verticesSize);
m_vbo.write(verticesSize, normals.constData(), verticesSize);
-
- QOpenGLFunctions *f = m_context->functions();
- f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
- f->glFrontFace(GL_CW);
- f->glCullFace(GL_FRONT);
- f->glEnable(GL_CULL_FACE);
- f->glEnable(GL_DEPTH_TEST);
-
- m_program->enableAttributeArray(vertexAttr);
- m_program->enableAttributeArray(normalAttr);
- m_program->setAttributeBuffer(vertexAttr, GL_FLOAT, 0, 3);
- m_program->setAttributeBuffer(normalAttr, GL_FLOAT, verticesSize, 3);
}
void Renderer::createGeometry()