aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/qsgdefaultrectanglenode.cpp
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2013-10-26 18:48:56 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-31 12:54:28 +0100
commit426f6aa672b94d8324321bc6c6d4f1a358eebedc (patch)
tree8af3e5b0aa2fdcdb7655672669f5ae277151cc3d /src/quick/scenegraph/qsgdefaultrectanglenode.cpp
parent34c85bb56c92316a6ce1c79d25f9653fec14791c (diff)
Refactor shaders into seprate GLSL source files
The default implementation of QSGShaderMaterial::vertexShader() and fragmentShader() now loads the GLSL source from a list of source files that can be specified via the setShaderSourceFile() or setShaderSourceFiles() functions. Multiple shader source files for each shader stage are supported. Each source file will be read in the order specified and concatenated together before being compiled. The other places where Qt Quick 2 loads shader source code have been adapted to use the new QSGShaderSourceBuilder, which is also used internally by QSGMaterial. This puts Qt Quick 2 into a better state ready to support OpenGL core profile and to load different shaders based upon OpenGL version, profile, GPU vendor, platform, etc. Change-Id: I1a66213c2ce788413168eb48c7bc5317e61988a2 Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'src/quick/scenegraph/qsgdefaultrectanglenode.cpp')
-rw-r--r--src/quick/scenegraph/qsgdefaultrectanglenode.cpp66
1 files changed, 9 insertions, 57 deletions
diff --git a/src/quick/scenegraph/qsgdefaultrectanglenode.cpp b/src/quick/scenegraph/qsgdefaultrectanglenode.cpp
index 14c61bae79..fb989fd6fb 100644
--- a/src/quick/scenegraph/qsgdefaultrectanglenode.cpp
+++ b/src/quick/scenegraph/qsgdefaultrectanglenode.cpp
@@ -110,19 +110,26 @@ namespace
class SmoothColorMaterialShader : public QSGMaterialShader
{
public:
+ SmoothColorMaterialShader();
+
virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect);
virtual char const *const *attributeNames() const;
private:
virtual void initialize();
- virtual const char *vertexShader() const;
- virtual const char *fragmentShader() const;
int m_matrixLoc;
int m_opacityLoc;
int m_pixelSizeLoc;
};
+SmoothColorMaterialShader::SmoothColorMaterialShader()
+ : QSGMaterialShader()
+{
+ setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/scenegraph/shaders/smoothcolor.vert"));
+ setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/scenegraph/shaders/smoothcolor.frag"));
+}
+
void SmoothColorMaterialShader::updateState(const RenderState &state, QSGMaterial *, QSGMaterial *oldEffect)
{
if (state.isOpacityDirty())
@@ -156,61 +163,6 @@ void SmoothColorMaterialShader::initialize()
m_pixelSizeLoc = program()->uniformLocation("pixelSize");
}
-const char *SmoothColorMaterialShader::vertexShader() const
-{
- return
- "uniform highp vec2 pixelSize; \n"
- "uniform highp mat4 matrix; \n"
- "uniform lowp float opacity; \n"
- "attribute highp vec4 vertex; \n"
- "attribute lowp vec4 vertexColor; \n"
- "attribute highp vec2 vertexOffset; \n"
- "varying lowp vec4 color; \n"
- "void main() { \n"
- " highp vec4 pos = matrix * vertex; \n"
- " gl_Position = pos; \n"
-
- " if (vertexOffset.x != 0.) { \n"
- " highp vec4 delta = matrix[0] * vertexOffset.x; \n"
- " highp vec2 dir = delta.xy * pos.w - pos.xy * delta.w; \n"
- " highp vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize); \n"
- " dir -= ndir * delta.w * pos.w; \n"
- " highp float numerator = dot(dir, ndir * pos.w * pos.w); \n"
- " highp float scale = 0.0; \n"
- " if (numerator < 0.0) \n"
- " scale = 1.0; \n"
- " else \n"
- " scale = min(1.0, numerator / dot(dir, dir)); \n"
- " gl_Position += scale * delta; \n"
- " } \n"
-
- " if (vertexOffset.y != 0.) { \n"
- " highp vec4 delta = matrix[1] * vertexOffset.y; \n"
- " highp vec2 dir = delta.xy * pos.w - pos.xy * delta.w; \n"
- " highp vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize); \n"
- " dir -= ndir * delta.w * pos.w; \n"
- " highp float numerator = dot(dir, ndir * pos.w * pos.w); \n"
- " highp float scale = 0.0; \n"
- " if (numerator < 0.0) \n"
- " scale = 1.0; \n"
- " else \n"
- " scale = min(1.0, numerator / dot(dir, dir)); \n"
- " gl_Position += scale * delta; \n"
- " } \n"
-
- " color = vertexColor * opacity; \n"
- "}";
-}
-
-const char *SmoothColorMaterialShader::fragmentShader() const
-{
- return
- "varying lowp vec4 color; \n"
- "void main() { \n"
- " gl_FragColor = color; \n"
- "}";
-}
-
QSGSmoothColorMaterial::QSGSmoothColorMaterial()
{
setFlag(RequiresFullMatrixExceptTranslate, true);