Fix reading of shader sources in scene graph example
authorhjk <hjk121@nokiamail.com>
Tue, 25 Mar 2014 13:17:26 +0000 (14:17 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 27 Mar 2014 15:54:15 +0000 (16:54 +0100)
Task-number: QTBUG-33080
Change-Id: I9219233ab7c7fbe89c0a9f1453d7c6aeeca498a1
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
examples/quick/scenegraph/graph/linenode.cpp
examples/quick/scenegraph/graph/noisynode.cpp
examples/quick/scenegraph/graph/noisynode.h

index 015aa4f0ee3d3f54370cffe989c637d59320e921..0c63129ea8dfed2c230c8d3b062161c62f928d63 100644 (file)
@@ -40,8 +40,6 @@
 
 #include "linenode.h"
 
-#include <QtCore/QResource>
-
 #include <QtGui/QColor>
 
 #include <QtQuick/QSGSimpleMaterial>
@@ -58,14 +56,10 @@ class LineShader : public QSGSimpleMaterialShader<LineMaterial>
     QSG_DECLARE_SIMPLE_SHADER(LineShader, LineMaterial)
 
 public:
-    LineShader()
-       : vsh(readResource(":/scenegraph/graph/shaders/line.vsh")),
-         fsh(readResource(":/scenegraph/graph/shaders/line.fsh"))
-    {}
-
-    const char *vertexShader() const { return vsh.constData(); }
-
-    const char *fragmentShader() const { return fsh.constData(); }
+    LineShader() {
+        setShaderSourceFile(QOpenGLShader::Vertex, ":/scenegraph/graph/shaders/line.vsh");
+        setShaderSourceFile(QOpenGLShader::Fragment, ":/scenegraph/graph/shaders/line.fsh");
+    }
 
     QList<QByteArray> attributes() const {  return QList<QByteArray>() << "pos" << "t"; }
 
@@ -81,15 +75,7 @@ public:
         id_color = program()->uniformLocation("color");
     }
 
-    static QByteArray readResource(const char *path) {
-        QResource r(path);
-        Q_ASSERT(r.isValid());
-        return QByteArray((const char *)r.data(), r.size());
-    }
-
 private:
-    QByteArray vsh;
-    QByteArray fsh;
     int id_color;
     int id_spread;
     int id_size;
index 1fc87a2b971a3a37162146d1c85c53bcf3fcbe7b..7b2a843409ee959881801c8d78667e9e1fbf8ac2 100644 (file)
@@ -40,8 +40,6 @@
 
 #include "noisynode.h"
 
-#include <QtCore/QResource>
-
 #include <QtQuick/QSGSimpleMaterialShader>
 #include <QtQuick/QSGTexture>
 #include <QtQuick/QQuickWindow>
@@ -63,16 +61,9 @@ class NoisyShader : public QSGSimpleMaterialShader<NoisyMaterial>
     QSG_DECLARE_SIMPLE_SHADER(NoisyShader, NoisyMaterial)
 
 public:
-    const char *vertexShader() const {
-        QResource r(":/scenegraph/graph/shaders/noisy.vsh");
-        Q_ASSERT(r.isValid());
-        return (const char *) r.data();
-    }
-
-    const char *fragmentShader() const {
-        QResource r(":/scenegraph/graph/shaders/noisy.fsh");
-        Q_ASSERT(r.isValid());
-        return (const char *) r.data();
+    NoisyShader() {
+        setShaderSourceFile(QOpenGLShader::Vertex, ":/scenegraph/graph/shaders/noisy.vsh");
+        setShaderSourceFile(QOpenGLShader::Fragment, ":/scenegraph/graph/shaders/noisy.fsh");
     }
 
     QList<QByteArray> attributes() const {  return QList<QByteArray>() << "aVertex" << "aTexCoord"; }
index b5a291330f1343e7d48894b455fbd6fbdf5fd932..348efc66d20317431aacb5bad7bf8ed9ed36e94f 100644 (file)
@@ -42,8 +42,7 @@
 #define NOISYNODE_H
 
 #include <QSGGeometryNode>
-
-class QQuickWindow;
+#include <QQuickWindow>
 
 class NoisyNode : public QSGGeometryNode
 {