summaryrefslogtreecommitdiffstats
path: root/examples/opengl/qopenglwindow/background_renderer.cpp
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@theqtcompany.com>2015-01-06 14:55:30 +0100
committerJørgen Lind <jorgen.lind@theqtcompany.com>2015-01-10 19:40:31 +0100
commitcd7532ad7b8cf496bf138651ab38f07c3059df1d (patch)
tree22917ffaf4f0f7086a2c22cadbf15f1abd5de227 /examples/opengl/qopenglwindow/background_renderer.cpp
parentc2b86ade9e1aca5b729676ec8f3fe8fc783690ba (diff)
Fix a couple of bugs in the QOpenGLWindow example
Also make the fragment shader a bit simpler Change-Id: Ie50940da0a4f896504c9f5962cdb6c455983302f Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Diffstat (limited to 'examples/opengl/qopenglwindow/background_renderer.cpp')
-rw-r--r--examples/opengl/qopenglwindow/background_renderer.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/examples/opengl/qopenglwindow/background_renderer.cpp b/examples/opengl/qopenglwindow/background_renderer.cpp
index 2c830ac13c..9308e9d258 100644
--- a/examples/opengl/qopenglwindow/background_renderer.cpp
+++ b/examples/opengl/qopenglwindow/background_renderer.cpp
@@ -75,8 +75,8 @@ FragmentToy::FragmentToy(const QString &fragmentSource, QObject *parent)
m_fragment_file_last_modified = info.lastModified();
m_fragment_file = fragmentSource;
#ifndef QT_NO_FILESYSTEMWATCHER
- m_watcher.addPath(info.canonicalFilePath());
- QObject::connect(&m_watcher, &QFileSystemWatcher::fileChanged, this, &FragmentToy::fileChanged);
+ m_watcher.addPath(info.canonicalPath());
+ QObject::connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FragmentToy::fileChanged);
#endif
}
}
@@ -94,7 +94,7 @@ void FragmentToy::draw(const QSize &windowSize)
if (!m_vao.isCreated())
m_vao.create();
- m_vao.bind();
+ QOpenGLVertexArrayObject::Binder binder(&m_vao);
if (!m_vertex_buffer.isCreated()) {
m_vertex_buffer.create();
@@ -115,7 +115,7 @@ void FragmentToy::draw(const QSize &windowSize)
}
}
- if (!m_fragment_shader) {
+ if (!m_fragment_shader && m_recompile_shaders) {
QByteArray data;
if (m_fragment_file.size()) {
QFile file(m_fragment_file);
@@ -160,6 +160,9 @@ void FragmentToy::draw(const QSize &windowSize)
}
+ if (!m_program->isLinked())
+ return;
+
m_program->bind();
m_vertex_buffer.bind();
@@ -167,15 +170,13 @@ void FragmentToy::draw(const QSize &windowSize)
m_program->enableAttributeArray("vertexCoord");
m_vertex_buffer.release();
- float radiens = (QTime::currentTime().msecsSinceStartOfDay() / 60) / (2 * M_PI);
+ uint time = QDateTime::currentDateTime().toMSecsSinceEpoch();
m_program->setUniformValue("currentTime", (uint) QDateTime::currentDateTime().toMSecsSinceEpoch());
- m_program->setUniformValue("radiens", radiens);
m_program->setUniformValue("windowSize", windowSize);
QOpenGLContext::currentContext()->functions()->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
m_program->release();
- m_vao.release();
}
void FragmentToy::fileChanged(const QString &path)