From d453b38415adcaef814ec54c3419673d2dbf4ce7 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 25 Mar 2014 14:17:26 +0100 Subject: Fix reading of shader sources in scene graph example Task-number: QTBUG-33080 Change-Id: I9219233ab7c7fbe89c0a9f1453d7c6aeeca498a1 Reviewed-by: Gunnar Sletta --- examples/quick/scenegraph/graph/linenode.cpp | 22 ++++------------------ examples/quick/scenegraph/graph/noisynode.cpp | 15 +++------------ examples/quick/scenegraph/graph/noisynode.h | 3 +-- 3 files changed, 8 insertions(+), 32 deletions(-) (limited to 'examples/quick/scenegraph/graph') diff --git a/examples/quick/scenegraph/graph/linenode.cpp b/examples/quick/scenegraph/graph/linenode.cpp index 015aa4f0ee..0c63129ea8 100644 --- a/examples/quick/scenegraph/graph/linenode.cpp +++ b/examples/quick/scenegraph/graph/linenode.cpp @@ -40,8 +40,6 @@ #include "linenode.h" -#include - #include #include @@ -58,14 +56,10 @@ class LineShader : public QSGSimpleMaterialShader 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 attributes() const { return QList() << "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; diff --git a/examples/quick/scenegraph/graph/noisynode.cpp b/examples/quick/scenegraph/graph/noisynode.cpp index 1fc87a2b97..7b2a843409 100644 --- a/examples/quick/scenegraph/graph/noisynode.cpp +++ b/examples/quick/scenegraph/graph/noisynode.cpp @@ -40,8 +40,6 @@ #include "noisynode.h" -#include - #include #include #include @@ -63,16 +61,9 @@ class NoisyShader : public QSGSimpleMaterialShader 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 attributes() const { return QList() << "aVertex" << "aTexCoord"; } diff --git a/examples/quick/scenegraph/graph/noisynode.h b/examples/quick/scenegraph/graph/noisynode.h index b5a291330f..348efc66d2 100644 --- a/examples/quick/scenegraph/graph/noisynode.h +++ b/examples/quick/scenegraph/graph/noisynode.h @@ -42,8 +42,7 @@ #define NOISYNODE_H #include - -class QQuickWindow; +#include class NoisyNode : public QSGGeometryNode { -- cgit v1.2.3