diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2013-11-06 13:07:58 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-13 23:42:13 +0100 |
commit | 3afffa47feabc80e1bc20ffd2143a722a1c360a2 (patch) | |
tree | 1e8d5e367aefae0d25c67a1c5e82eeeb357203a6 /src/quick/scenegraph/shaders | |
parent | 376844cc6f312d2ab8cf3191ec3e5535bfa850e0 (diff) |
Adapt Qt Quick 2 renderer to work with OpenGL Core Profile
The basic approach is to have the batched renderer create and bind a
vertex array object if it detects we are using an OpenGL Core profile
context. The VAO is bound for the duration of the QQ2 renderer's
work cycle and unbound at the end so as to not interfere with any
other VAO's a user may wish to use.
All shaders have been copied and ported to be compliant with the
GLSL 150 core specification which is the minimum for a Core profile
context (OpenGL 3.2 Core). We are not using any newer features as
yet so this will work anywhere we can get a Core profile context.
The QSGShaderSourceBuilder class has been extended to resolve any
requests for shaders to the same basefilename with "_core"
appended prior to any file extension. This could be extended in
the future to allow version, or GPU or platform specific shaders.
The QSGShaderSourceBuilder has also been extended to allow it to
insert #define definitions in the prologue of a shader. Any such
definition is inserted:
* After the last #extension directive (if any are found)
* Otherwise after the #version directive (if found)
* Otherwise at the start of the shader source
This is required by the custom particle shaders which make
extensive use of such #defines.
In addition the mechanism used by the distance field glyph cache to
extend the cache with new glyphs has been modified to work (and
work more efficiently) when using a Core profile context.
Rather than using a shader program and a buffer filling quad to
blit the old texture into the new cache texture, we instead use
the technique of framebuffer blitting. The existing fallback
implementation using glTexSubImage2D() is still available if
needed.
The DECLARATIVE_EXAMPLE_MAIN macro has been extended to allow easy
testing of any of the QtDeclarative examples with a core profile
context. Just run the example with
QT_QUICK_CORE_PROFILE=1 ./text
for e.g. The only ones that may not work out of the box are those
that provide GLSL shader source e.g. the customparticles or
shader effect examples. These work fine if the shader source is
adapted to GLSL 150 core.
In the future it may be a good idea to expose some context property
to QML that the user can use to determine what shader source
variation to provide to Qt Quick. Along these lines it would also
be very nice to allow the provision of shader source to
ShaderEffect or CustomParticle from a separate source file just as
we now do within Qt Quick.
Task-number: QTBUG-32050
Change-Id: Ia6e9f06dbb8508af9ae03c6b60fb418b4cc9e41f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/quick/scenegraph/shaders')
34 files changed, 602 insertions, 4 deletions
diff --git a/src/quick/scenegraph/shaders/24bittextmask.frag b/src/quick/scenegraph/shaders/24bittextmask.frag index ac62e7b642..5c21e202f9 100644 --- a/src/quick/scenegraph/shaders/24bittextmask.frag +++ b/src/quick/scenegraph/shaders/24bittextmask.frag @@ -1,10 +1,10 @@ varying highp vec2 sampleCoord; -uniform lowp sampler2D texture; +uniform lowp sampler2D _qt_texture; uniform lowp float color; // just the alpha, really... void main() { - lowp vec4 glyph = texture2D(texture, sampleCoord); + lowp vec4 glyph = texture2D(_qt_texture, sampleCoord); gl_FragColor = vec4(glyph.rgb * color, glyph.a); }
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/24bittextmask_core.frag b/src/quick/scenegraph/shaders/24bittextmask_core.frag new file mode 100644 index 0000000000..29d1f23017 --- /dev/null +++ b/src/quick/scenegraph/shaders/24bittextmask_core.frag @@ -0,0 +1,14 @@ +#version 150 core + +in vec2 sampleCoord; + +out vec4 fragColor; + +uniform sampler2D _qt_texture; +uniform float color; // just the alpha, really... + +void main() +{ + vec4 glyph = texture(_qt_texture, sampleCoord); + fragColor = vec4(glyph.rgb * color, glyph.a); +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/8bittextmask.frag b/src/quick/scenegraph/shaders/8bittextmask.frag index f2f06e8e07..44ffb279cb 100644 --- a/src/quick/scenegraph/shaders/8bittextmask.frag +++ b/src/quick/scenegraph/shaders/8bittextmask.frag @@ -1,9 +1,9 @@ varying highp vec2 sampleCoord; -uniform lowp sampler2D texture; +uniform lowp sampler2D _qt_texture; uniform lowp vec4 color; void main() { - gl_FragColor = color * texture2D(texture, sampleCoord).a; + gl_FragColor = color * texture2D(_qt_texture, sampleCoord).a; }
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/8bittextmask_core.frag b/src/quick/scenegraph/shaders/8bittextmask_core.frag new file mode 100644 index 0000000000..2d67a4676a --- /dev/null +++ b/src/quick/scenegraph/shaders/8bittextmask_core.frag @@ -0,0 +1,13 @@ +#version 150 core + +in vec2 sampleCoord; + +out vec4 fragColor; + +uniform sampler2D _qt_texture; +uniform vec4 color; + +void main() +{ + fragColor = color * texture(_qt_texture, sampleCoord).r; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldoutlinetext_core.frag b/src/quick/scenegraph/shaders/distancefieldoutlinetext_core.frag new file mode 100644 index 0000000000..80fa05ca3c --- /dev/null +++ b/src/quick/scenegraph/shaders/distancefieldoutlinetext_core.frag @@ -0,0 +1,20 @@ +#version 150 core + +in vec2 sampleCoord; + +out vec4 fragColor; + +uniform sampler2D _qt_texture; +uniform vec4 color; +uniform vec4 styleColor; +uniform float alphaMin; +uniform float alphaMax; +uniform float outlineAlphaMax0; +uniform float outlineAlphaMax1; + +void main() +{ + float d = texture(_qt_texture, sampleCoord).r; + fragColor = mix(styleColor, color, smoothstep(alphaMin, alphaMax, d)) + * smoothstep(outlineAlphaMax0, outlineAlphaMax1, d); +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldshiftedtext_core.frag b/src/quick/scenegraph/shaders/distancefieldshiftedtext_core.frag new file mode 100644 index 0000000000..3f66965e78 --- /dev/null +++ b/src/quick/scenegraph/shaders/distancefieldshiftedtext_core.frag @@ -0,0 +1,20 @@ +#version 150 core + +in vec2 sampleCoord; +in vec2 shiftedSampleCoord; + +out vec4 fragColor; + +uniform sampler2D _qt_texture; +uniform vec4 color; +uniform vec4 styleColor; +uniform float alphaMin; +uniform float alphaMax; + +void main() +{ + float a = smoothstep(alphaMin, alphaMax, texture(_qt_texture, sampleCoord).r); + vec4 shifted = styleColor * smoothstep(alphaMin, alphaMax, + texture(_qt_texture, shiftedSampleCoord).r); + fragColor = mix(shifted, color, a); +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldshiftedtext_core.vert b/src/quick/scenegraph/shaders/distancefieldshiftedtext_core.vert new file mode 100644 index 0000000000..b7a3ecc667 --- /dev/null +++ b/src/quick/scenegraph/shaders/distancefieldshiftedtext_core.vert @@ -0,0 +1,18 @@ +#version 150 core + +in vec4 vCoord; +in vec2 tCoord; + +out vec2 sampleCoord; +out vec2 shiftedSampleCoord; + +uniform mat4 matrix; +uniform vec2 textureScale; +uniform vec2 shift; + +void main() +{ + sampleCoord = tCoord * textureScale; + shiftedSampleCoord = (tCoord - shift) * textureScale; + gl_Position = matrix * vCoord; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldtext_core.frag b/src/quick/scenegraph/shaders/distancefieldtext_core.frag new file mode 100644 index 0000000000..9c64a60d3d --- /dev/null +++ b/src/quick/scenegraph/shaders/distancefieldtext_core.frag @@ -0,0 +1,16 @@ +#version 150 core + +in vec2 sampleCoord; + +out vec4 fragColor; + +uniform sampler2D _qt_texture; +uniform vec4 color; +uniform float alphaMin; +uniform float alphaMax; + +void main() +{ + fragColor = color * smoothstep(alphaMin, alphaMax, + texture(_qt_texture, sampleCoord).r); +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldtext_core.vert b/src/quick/scenegraph/shaders/distancefieldtext_core.vert new file mode 100644 index 0000000000..7fc693d139 --- /dev/null +++ b/src/quick/scenegraph/shaders/distancefieldtext_core.vert @@ -0,0 +1,15 @@ +#version 150 core + +in vec4 vCoord; +in vec2 tCoord; + +out vec2 sampleCoord; + +uniform mat4 matrix; +uniform vec2 textureScale; + +void main() +{ + sampleCoord = tCoord * textureScale; + gl_Position = matrix * vCoord; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/flatcolor_core.frag b/src/quick/scenegraph/shaders/flatcolor_core.frag new file mode 100644 index 0000000000..23a957ad7b --- /dev/null +++ b/src/quick/scenegraph/shaders/flatcolor_core.frag @@ -0,0 +1,10 @@ +#version 150 core + +out vec4 fragColor; + +uniform vec4 color; + +void main() +{ + fragColor = color; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/flatcolor_core.vert b/src/quick/scenegraph/shaders/flatcolor_core.vert new file mode 100644 index 0000000000..e33c591b95 --- /dev/null +++ b/src/quick/scenegraph/shaders/flatcolor_core.vert @@ -0,0 +1,10 @@ +#version 150 core + +in vec4 vCoord; + +uniform mat4 matrix; + +void main() +{ + gl_Position = matrix * vCoord; +} diff --git a/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext_core.frag b/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext_core.frag new file mode 100644 index 0000000000..cf6ba2b8d9 --- /dev/null +++ b/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext_core.frag @@ -0,0 +1,32 @@ +#version 150 core + +in vec2 sampleCoord; +in vec3 sampleFarLeft; +in vec3 sampleNearLeft; +in vec3 sampleNearRight; +in vec3 sampleFarRight; + +out vec4 fragColor; + +uniform sampler2D _qt_texture; +uniform vec4 color; +uniform float alphaMin; +uniform float alphaMax; + +void main() +{ + vec4 n; + n.x = textureProj(_qt_texture, sampleFarLeft).r; + n.y = textureProj(_qt_texture, sampleNearLeft).r; + float c = texture(_qt_texture, sampleCoord).r; + n.z = textureProj(_qt_texture, sampleNearRight).r; + n.w = textureProj(_qt_texture, sampleFarRight).r; + + vec2 d = min(abs(n.yw - n.xz) * 2., 0.67); + vec2 lo = mix(vec2(alphaMin), vec2(0.5), d); + vec2 hi = mix(vec2(alphaMax), vec2(0.5), d); + n = smoothstep(lo.xxyy, hi.xxyy, n); + c = smoothstep(lo.x + lo.y, hi.x + hi.y, 2. * c); + + fragColor = vec4(0.333 * (n.xyz + n.yzw + c), c) * color.w; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext_core.vert b/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext_core.vert new file mode 100644 index 0000000000..936f74725b --- /dev/null +++ b/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext_core.vert @@ -0,0 +1,36 @@ +#version 150 core + +in vec4 vCoord; +in vec2 tCoord; + +out vec2 sampleCoord; +out vec3 sampleFarLeft; +out vec3 sampleNearLeft; +out vec3 sampleNearRight; +out vec3 sampleFarRight; + +uniform mat4 matrix; +uniform vec2 textureScale; +uniform float fontScale; +uniform vec4 vecDelta; + +void main() +{ + sampleCoord = tCoord * textureScale; + gl_Position = matrix * vCoord; + + // Calculate neighbor pixel position in item space. + vec3 wDelta = gl_Position.w * vecDelta.xyw; + vec3 farLeft = vCoord.xyw - 0.667 * wDelta; + vec3 nearLeft = vCoord.xyw - 0.333 * wDelta; + vec3 nearRight = vCoord.xyw + 0.333 * wDelta; + vec3 farRight = vCoord.xyw + 0.667 * wDelta; + + // Calculate neighbor texture coordinate. + vec2 scale = textureScale / fontScale; + vec2 base = sampleCoord - scale * vCoord.xy; + sampleFarLeft = vec3(base * farLeft.z + scale * farLeft.xy, farLeft.z); + sampleNearLeft = vec3(base * nearLeft.z + scale * nearLeft.xy, nearLeft.z); + sampleNearRight = vec3(base * nearRight.z + scale * nearRight.xy, nearRight.z); + sampleFarRight = vec3(base * farRight.z + scale * farRight.xy, farRight.z); +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext_core.frag b/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext_core.frag new file mode 100644 index 0000000000..2dd588d307 --- /dev/null +++ b/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext_core.frag @@ -0,0 +1,21 @@ +#version 150 core + +in vec3 sampleNearLeft; +in vec3 sampleNearRight; + +out vec4 fragColor; + +uniform sampler2D _qt_texture; +uniform vec4 color; +uniform float alphaMin; +uniform float alphaMax; + +void main() +{ + vec2 n; + n.x = textureProj(_qt_texture, sampleNearLeft).r; + n.y = textureProj(_qt_texture, sampleNearRight).r; + n = smoothstep(alphaMin, alphaMax, n); + float c = 0.5 * (n.x + n.y); + fragColor = vec4(n.x, c, n.y, c) * color.w; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext_core.vert b/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext_core.vert new file mode 100644 index 0000000000..b887a70001 --- /dev/null +++ b/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext_core.vert @@ -0,0 +1,29 @@ +#version 150 core + +in vec4 vCoord; +in vec2 tCoord; + +out vec3 sampleNearLeft; +out vec3 sampleNearRight; + +uniform mat4 matrix; +uniform vec2 textureScale; +uniform float fontScale; +uniform vec4 vecDelta; + +void main() +{ + vec2 sampleCoord = tCoord * textureScale; + gl_Position = matrix * vCoord; + + // Calculate neighbor pixel position in item space. + vec3 wDelta = gl_Position.w * vecDelta.xyw; + vec3 nearLeft = vCoord.xyw - 0.25 * wDelta; + vec3 nearRight = vCoord.xyw + 0.25 * wDelta; + + // Calculate neighbor texture coordinate. + vec2 scale = textureScale / fontScale; + vec2 base = sampleCoord - scale * vCoord.xy; + sampleNearLeft = vec3(base * nearLeft.z + scale * nearLeft.xy, nearLeft.z); + sampleNearRight = vec3(base * nearRight.z + scale * nearRight.xy, nearRight.z); +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/opaquetexture_core.frag b/src/quick/scenegraph/shaders/opaquetexture_core.frag new file mode 100644 index 0000000000..5f30e68677 --- /dev/null +++ b/src/quick/scenegraph/shaders/opaquetexture_core.frag @@ -0,0 +1,12 @@ +#version 150 core + +in vec2 qt_TexCoord; + +out vec4 fragColor; + +uniform sampler2D qt_Texture; + +void main() +{ + fragColor = texture(qt_Texture, qt_TexCoord); +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/opaquetexture_core.vert b/src/quick/scenegraph/shaders/opaquetexture_core.vert new file mode 100644 index 0000000000..419b1a825c --- /dev/null +++ b/src/quick/scenegraph/shaders/opaquetexture_core.vert @@ -0,0 +1,14 @@ +#version 150 core + +uniform mat4 qt_Matrix; + +in vec4 qt_VertexPosition; +in vec2 qt_VertexTexCoord; + +out vec2 qt_TexCoord; + +void main() +{ + qt_TexCoord = qt_VertexTexCoord; + gl_Position = qt_Matrix * qt_VertexPosition; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/outlinedtext_core.frag b/src/quick/scenegraph/shaders/outlinedtext_core.frag new file mode 100644 index 0000000000..e19c8937f9 --- /dev/null +++ b/src/quick/scenegraph/shaders/outlinedtext_core.frag @@ -0,0 +1,25 @@ +#version 150 core + +in vec2 sampleCoord; +in vec2 sCoordUp; +in vec2 sCoordDown; +in vec2 sCoordLeft; +in vec2 sCoordRight; + +out vec4 fragColor; + +uniform sampler2D _qt_texture; +uniform vec4 color; +uniform vec4 styleColor; + +void main() +{ + float glyph = texture(_qt_texture, sampleCoord).r; + float outline = clamp(clamp(texture(_qt_texture, sCoordUp).r + + texture(_qt_texture, sCoordDown).r + + texture(_qt_texture, sCoordLeft).r + + texture(_qt_texture, sCoordRight).r, + 0.0, 1.0) - glyph, + 0.0, 1.0); + fragColor = outline * styleColor + glyph * color; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/outlinedtext_core.vert b/src/quick/scenegraph/shaders/outlinedtext_core.vert new file mode 100644 index 0000000000..4aa13101fd --- /dev/null +++ b/src/quick/scenegraph/shaders/outlinedtext_core.vert @@ -0,0 +1,24 @@ +#version 150 core + +in vec4 vCoord; +in vec2 tCoord; + +out vec2 sampleCoord; +out vec2 sCoordUp; +out vec2 sCoordDown; +out vec2 sCoordLeft; +out vec2 sCoordRight; + +uniform mat4 matrix; +uniform vec2 textureScale; +uniform vec2 shift; + +void main() +{ + sampleCoord = tCoord * textureScale; + sCoordUp = (tCoord - vec2(0.0, -1.0)) * textureScale; + sCoordDown = (tCoord - vec2(0.0, 1.0)) * textureScale; + sCoordLeft = (tCoord - vec2(-1.0, 0.0)) * textureScale; + sCoordRight = (tCoord - vec2(1.0, 0.0)) * textureScale; + gl_Position = matrix * vCoord; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/rendernode_core.frag b/src/quick/scenegraph/shaders/rendernode_core.frag new file mode 100644 index 0000000000..7c187265df --- /dev/null +++ b/src/quick/scenegraph/shaders/rendernode_core.frag @@ -0,0 +1,12 @@ +#version 150 core + +uniform sampler2D tex; + +in vec2 t; + +out vec4 color; + +void main() +{ + fragColor = texture(tex, t); +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/rendernode_core.vert b/src/quick/scenegraph/shaders/rendernode_core.vert new file mode 100644 index 0000000000..a76d519a5a --- /dev/null +++ b/src/quick/scenegraph/shaders/rendernode_core.vert @@ -0,0 +1,12 @@ +#version 150 core + +in vec4 av; +in vec2 at; + +out vec2 t; + +void main() +{ + gl_Position = av; + t = at; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/smoothcolor_core.frag b/src/quick/scenegraph/shaders/smoothcolor_core.frag new file mode 100644 index 0000000000..84533c2b40 --- /dev/null +++ b/src/quick/scenegraph/shaders/smoothcolor_core.frag @@ -0,0 +1,10 @@ +#version 150 core + +in vec4 color; + +out vec4 fragColor; + +void main() +{ + fragColor = color; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/smoothcolor_core.vert b/src/quick/scenegraph/shaders/smoothcolor_core.vert new file mode 100644 index 0000000000..1eed751ccd --- /dev/null +++ b/src/quick/scenegraph/shaders/smoothcolor_core.vert @@ -0,0 +1,47 @@ +#version 150 core + +in vec4 vertex; +in vec4 vertexColor; +in vec2 vertexOffset; + +out vec4 color; + +uniform vec2 pixelSize; +uniform mat4 matrix; +uniform float opacity; + +void main() +{ + vec4 pos = matrix * vertex; + gl_Position = pos; + + if (vertexOffset.x != 0.) { + vec4 delta = matrix[0] * vertexOffset.x; + vec2 dir = delta.xy * pos.w - pos.xy * delta.w; + vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize); + dir -= ndir * delta.w * pos.w; + float numerator = dot(dir, ndir * pos.w * pos.w); + float scale = 0.0; + if (numerator < 0.0) + scale = 1.0; + else + scale = min(1.0, numerator / dot(dir, dir)); + gl_Position += scale * delta; + } + + if (vertexOffset.y != 0.) { + vec4 delta = matrix[1] * vertexOffset.y; + vec2 dir = delta.xy * pos.w - pos.xy * delta.w; + vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize); + dir -= ndir * delta.w * pos.w; + float numerator = dot(dir, ndir * pos.w * pos.w); + float scale = 0.0; + if (numerator < 0.0) + scale = 1.0; + else + scale = min(1.0, numerator / dot(dir, dir)); + gl_Position += scale * delta; + } + + color = vertexColor * opacity; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/smoothtexture_core.frag b/src/quick/scenegraph/shaders/smoothtexture_core.frag new file mode 100644 index 0000000000..8a9aefd4c8 --- /dev/null +++ b/src/quick/scenegraph/shaders/smoothtexture_core.frag @@ -0,0 +1,13 @@ +#version 150 core + +in vec2 texCoord; +in float vertexOpacity; + +out vec4 fragColor; + +uniform sampler2D qt_Texture; + +void main() +{ + fragColor = texture(qt_Texture, texCoord) * vertexOpacity; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/smoothtexture_core.vert b/src/quick/scenegraph/shaders/smoothtexture_core.vert new file mode 100644 index 0000000000..a2489a39c5 --- /dev/null +++ b/src/quick/scenegraph/shaders/smoothtexture_core.vert @@ -0,0 +1,54 @@ +#version 150 core + +in vec4 vertex; +in vec2 multiTexCoord; +in vec2 vertexOffset; +in vec2 texCoordOffset; + +out vec2 texCoord; +out float vertexOpacity; + +uniform vec2 pixelSize; +uniform mat4 qt_Matrix; +uniform float opacity; + +void main() +{ + vec4 pos = qt_Matrix * vertex; + gl_Position = pos; + texCoord = multiTexCoord; + + if (vertexOffset.x != 0.) { + vec4 delta = qt_Matrix[0] * vertexOffset.x; + vec2 dir = delta.xy * pos.w - pos.xy * delta.w; + vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize); + dir -= ndir * delta.w * pos.w; + float numerator = dot(dir, ndir * pos.w * pos.w); + float scale = 0.0; + if (numerator < 0.0) + scale = 1.0; + else + scale = min(1.0, numerator / dot(dir, dir)); + gl_Position += scale * delta; + texCoord.x += scale * texCoordOffset.x; + } + + if (vertexOffset.y != 0.) { + vec4 delta = qt_Matrix[1] * vertexOffset.y; + vec2 dir = delta.xy * pos.w - pos.xy * delta.w; + vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize); + dir -= ndir * delta.w * pos.w; + float numerator = dot(dir, ndir * pos.w * pos.w); + float scale = 0.0; + if (numerator < 0.0) + scale = 1.0; + else + scale = min(1.0, numerator / dot(dir, dir)); + gl_Position += scale * delta; + texCoord.y += scale * texCoordOffset.y; + } + + bool onEdge = any(notEqual(vertexOffset, vec2(0.))); + bool outerEdge = all(equal(texCoordOffset, vec2(0.))); + vertexOpacity = onEdge && outerEdge ? 0. : opacity; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/stencilclip_core.frag b/src/quick/scenegraph/shaders/stencilclip_core.frag new file mode 100644 index 0000000000..4d05de4ca9 --- /dev/null +++ b/src/quick/scenegraph/shaders/stencilclip_core.frag @@ -0,0 +1,8 @@ +#version 150 core + +out vec4 fragColor; + +void main() +{ + fragColor = vec4(0.81, 0.83, 0.12, 1.0); // Trolltech green ftw! +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/stencilclip_core.vert b/src/quick/scenegraph/shaders/stencilclip_core.vert new file mode 100644 index 0000000000..37e240c735 --- /dev/null +++ b/src/quick/scenegraph/shaders/stencilclip_core.vert @@ -0,0 +1,10 @@ +#version 150 core + +in vec4 vCoord; + +uniform mat4 matrix; + +void main() +{ + gl_Position = matrix * vCoord; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/styledtext_core.frag b/src/quick/scenegraph/shaders/styledtext_core.frag new file mode 100644 index 0000000000..50f64c64a2 --- /dev/null +++ b/src/quick/scenegraph/shaders/styledtext_core.frag @@ -0,0 +1,18 @@ +#version 150 core + +in vec2 sampleCoord; +in vec2 shiftedSampleCoord; + +out vec4 color; + +uniform sampler2D _qt_texture; +uniform vec4 color; +uniform vec4 styleColor; + +void main() +{ + float glyph = texture(_qt_texture, sampleCoord).a; + float style = clamp(texture(_qt_texture, shiftedSampleCoord).r - glyph, + 0.0, 1.0); + fragColor = style * styleColor + glyph * color; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/styledtext_core.vert b/src/quick/scenegraph/shaders/styledtext_core.vert new file mode 100644 index 0000000000..b7a3ecc667 --- /dev/null +++ b/src/quick/scenegraph/shaders/styledtext_core.vert @@ -0,0 +1,18 @@ +#version 150 core + +in vec4 vCoord; +in vec2 tCoord; + +out vec2 sampleCoord; +out vec2 shiftedSampleCoord; + +uniform mat4 matrix; +uniform vec2 textureScale; +uniform vec2 shift; + +void main() +{ + sampleCoord = tCoord * textureScale; + shiftedSampleCoord = (tCoord - shift) * textureScale; + gl_Position = matrix * vCoord; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/textmask_core.frag b/src/quick/scenegraph/shaders/textmask_core.frag new file mode 100644 index 0000000000..17dda53c97 --- /dev/null +++ b/src/quick/scenegraph/shaders/textmask_core.frag @@ -0,0 +1,14 @@ +#version 150 core + +in vec2 sampleCoord; + +out vec4 fragColor; + +uniform sampler2D _qt_texture; +uniform vec4 color; + +void main() +{ + vec4 glyph = texture(_qt_texture, sampleCoord); + fragColor = vec4(glyph.rgb * color.a, glyph.a); +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/textmask_core.vert b/src/quick/scenegraph/shaders/textmask_core.vert new file mode 100644 index 0000000000..619248dccb --- /dev/null +++ b/src/quick/scenegraph/shaders/textmask_core.vert @@ -0,0 +1,15 @@ +#version 150 core + +in vec4 vCoord; +in vec2 tCoord; + +out vec2 sampleCoord; + +uniform mat4 matrix; +uniform vec2 textureScale; + +void main() +{ + sampleCoord = tCoord * textureScale; + gl_Position = matrix * vCoord; +} diff --git a/src/quick/scenegraph/shaders/texture_core.frag b/src/quick/scenegraph/shaders/texture_core.frag new file mode 100644 index 0000000000..d9bdf6a238 --- /dev/null +++ b/src/quick/scenegraph/shaders/texture_core.frag @@ -0,0 +1,13 @@ +#version 150 core + +in vec2 qt_TexCoord; + +out vec4 fragColor; + +uniform sampler2D qt_Texture; +uniform float opacity; + +void main() +{ + fragColor = texture(qt_Texture, qt_TexCoord) * opacity; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/vertexcolor_core.frag b/src/quick/scenegraph/shaders/vertexcolor_core.frag new file mode 100644 index 0000000000..84533c2b40 --- /dev/null +++ b/src/quick/scenegraph/shaders/vertexcolor_core.frag @@ -0,0 +1,10 @@ +#version 150 core + +in vec4 color; + +out vec4 fragColor; + +void main() +{ + fragColor = color; +}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/vertexcolor_core.vert b/src/quick/scenegraph/shaders/vertexcolor_core.vert new file mode 100644 index 0000000000..219b840913 --- /dev/null +++ b/src/quick/scenegraph/shaders/vertexcolor_core.vert @@ -0,0 +1,15 @@ +#version 150 core + +in vec4 vertexCoord; +in vec4 vertexColor; + +out vec4 color; + +uniform mat4 matrix; +uniform float opacity; + +void main() +{ + gl_Position = matrix * vertexCoord; + color = vertexColor * opacity; +}
\ No newline at end of file |