diff options
Diffstat (limited to 'src/quick/scenegraph/qsgdefaultrectanglenode.cpp')
-rw-r--r-- | src/quick/scenegraph/qsgdefaultrectanglenode.cpp | 66 |
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); |