diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-03-07 17:51:42 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-03-07 20:30:45 -0500 |
commit | 46d1fc1c24da4b77ba0b466c0ad45a206d479732 (patch) | |
tree | 4eafceb32cd266d67cf42dade71c62f6f6b3ee05 | |
parent | 2c05b758c7904ae178cc5f78698713914daa9cea (diff) | |
download | gtk+-46d1fc1c24da4b77ba0b466c0ad45a206d479732.tar.gz |
gsk: Use clip defines in shaders
Use the NO_CLIP and RECT_CLIP defines to make
simpler shaders for these cases.
Note: This does not work yet.
-rw-r--r-- | gsk/resources/glsl/preamble.fs.glsl | 29 | ||||
-rw-r--r-- | gsk/resources/glsl/preamble.glsl | 6 |
2 files changed, 29 insertions, 6 deletions
diff --git a/gsk/resources/glsl/preamble.fs.glsl b/gsk/resources/glsl/preamble.fs.glsl index c2cd1cdc29..cd0af69958 100644 --- a/gsk/resources/glsl/preamble.fs.glsl +++ b/gsk/resources/glsl/preamble.fs.glsl @@ -75,6 +75,16 @@ gsk_rounded_rect_coverage (GskRoundedRect r, vec2 p) return 1.0 - dot(vec4(is_out), corner_coverages); } +float +gsk_rect_coverage (vec4 r, vec2 p) +{ + if (p.x < r.x || p.y < r.y || + p.x >= r.z || p.y >= r.w) + return 0.0; + + return 1.0; +} + vec4 GskTexture(sampler2D sampler, vec2 texCoords) { #if defined(GSK_GLES) || defined(GSK_LEGACY) return texture2D(sampler, texCoords); @@ -101,14 +111,21 @@ vec2 gsk_get_frag_coord() { } void gskSetOutputColor(vec4 color) { - vec2 f = gsk_get_frag_coord(); + vec4 result; + +#if defined(NO_CLIP) + result = color; +#elif defined(RECT_CLIP) + result = color * gsk_rect_coverage(gsk_get_bounds(u_clip_rect), + gsk_get_frag_coord()); +#else + result = color * gsk_rounded_rect_coverage(gsk_create_rect(u_clip_rect), + gsk_get_frag_coord()); +#endif - // We do *NOT* transform the clip rect here since we already - // need to do that on the CPU. #if defined(GSK_GLES) || defined(GSK_LEGACY) - gl_FragColor = color * gsk_rounded_rect_coverage(gsk_create_rect(u_clip_rect), f); + gl_FragColor = result; #else - outputColor = color * gsk_rounded_rect_coverage(gsk_create_rect(u_clip_rect), f); + outputColor = result; #endif - /*outputColor = color;*/ } diff --git a/gsk/resources/glsl/preamble.glsl b/gsk/resources/glsl/preamble.glsl index 8ca6469f6d..8bc007ba67 100644 --- a/gsk/resources/glsl/preamble.glsl +++ b/gsk/resources/glsl/preamble.glsl @@ -38,6 +38,12 @@ gsk_create_rect(vec4[3] data) return GskRoundedRect(bounds, corner_points1, corner_points2); } +vec4 +gsk_get_bounds(vec4[3] data) +{ + return vec4(data[0].xy, data[0].xy + data[0].zw); +} + vec4 gsk_premultiply(vec4 c) { return vec4(c.rgb * c.a, c.a); } |