[gtk+] vulkan: Add clip.vert.glsl
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] vulkan: Add clip.vert.glsl
- Date: Tue, 17 Jan 2017 05:20:11 +0000 (UTC)
commit 3768c676c6e90daebaf208a0fdbffa78d210fc56
Author: Benjamin Otte <otte redhat com>
Date: Tue Jan 17 05:50:52 2017 +0100
vulkan: Add clip.vert.glsl
Implement clipping the same way as in the last commit for the
fragment shaders.
gsk/Makefile.am | 1 +
gsk/resources/vulkan/blend-clip-rounded.vert.glsl | 15 ++------
gsk/resources/vulkan/blend-clip-rounded.vert.spv | Bin 4684 -> 4868 bytes
gsk/resources/vulkan/blend-clip.vert.glsl | 15 ++------
gsk/resources/vulkan/blend-clip.vert.spv | Bin 4604 -> 4788 bytes
gsk/resources/vulkan/border-clip-rounded.vert.glsl | 15 ++------
gsk/resources/vulkan/border-clip-rounded.vert.spv | Bin 8952 -> 9136 bytes
gsk/resources/vulkan/border-clip.vert.glsl | 15 ++------
gsk/resources/vulkan/border-clip.vert.spv | Bin 8952 -> 9136 bytes
gsk/resources/vulkan/clip.vert.glsl | 36 ++++++++++++++++++++
gsk/resources/vulkan/color-clip-rounded.vert.glsl | 7 +++-
gsk/resources/vulkan/color-clip-rounded.vert.spv | Bin 1888 -> 3880 bytes
gsk/resources/vulkan/color-clip.vert.glsl | 15 ++------
gsk/resources/vulkan/color-clip.vert.spv | Bin 3588 -> 3772 bytes
.../vulkan/color-matrix-clip-rounded.vert.glsl | 15 ++------
.../vulkan/color-matrix-clip-rounded.vert.spv | Bin 5036 -> 5220 bytes
gsk/resources/vulkan/color-matrix-clip.vert.glsl | 15 ++------
gsk/resources/vulkan/color-matrix-clip.vert.spv | Bin 4956 -> 5140 bytes
gsk/resources/vulkan/linear-clip-rounded.vert.glsl | 6 ++-
gsk/resources/vulkan/linear-clip-rounded.vert.spv | Bin 5952 -> 7928 bytes
gsk/resources/vulkan/linear-clip.vert.glsl | 6 ++-
gsk/resources/vulkan/linear-clip.vert.spv | Bin 5856 -> 7832 bytes
gsk/resources/vulkan/linear.vert.glsl | 15 ++------
gsk/resources/vulkan/linear.vert.spv | Bin 7648 -> 6116 bytes
24 files changed, 74 insertions(+), 102 deletions(-)
---
diff --git a/gsk/Makefile.am b/gsk/Makefile.am
index dd480bf..06ed18e 100644
--- a/gsk/Makefile.am
+++ b/gsk/Makefile.am
@@ -59,6 +59,7 @@ gsk_private_vulkan_source_c = \
gskvulkanshader.c
gsk_private_vulkan_include_shaders = \
resources/vulkan/clip.frag.glsl \
+ resources/vulkan/clip.vert.glsl \
resources/vulkan/constants.glsl \
resources/vulkan/rounded-rect.glsl
gsk_private_vulkan_shaders = \
diff --git a/gsk/resources/vulkan/blend-clip-rounded.vert.glsl
b/gsk/resources/vulkan/blend-clip-rounded.vert.glsl
index 0a5f31d..fadf4b9 100644
--- a/gsk/resources/vulkan/blend-clip-rounded.vert.glsl
+++ b/gsk/resources/vulkan/blend-clip-rounded.vert.glsl
@@ -1,6 +1,7 @@
#version 420 core
-#include "constants.glsl"
+#define CLIP_ROUNDED_RECT
+#include "clip.vert.glsl"
layout(location = 0) in vec4 inRect;
layout(location = 1) in vec4 inTexRect;
@@ -19,18 +20,8 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
vec2(1.0, 0.0),
vec2(1.0, 1.0) };
-vec4 intersect(vec4 a, vec4 b)
-{
- a = vec4(a.xy, a.xy + a.zw);
- b = vec4(b.xy, b.xy + b.zw);
- vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
- if (any (greaterThanEqual (result.xy, result.zw)))
- return vec4(0.0,0.0,0.0,0.0);
- return vec4(result.xy, result.zw - result.xy);
-}
-
void main() {
- vec4 rect = intersect(inRect, push.clip_bounds);
+ vec4 rect = clip (inRect);
vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
diff --git a/gsk/resources/vulkan/blend-clip-rounded.vert.spv
b/gsk/resources/vulkan/blend-clip-rounded.vert.spv
index bc82237..cb6a9da 100644
Binary files a/gsk/resources/vulkan/blend-clip-rounded.vert.spv and
b/gsk/resources/vulkan/blend-clip-rounded.vert.spv differ
diff --git a/gsk/resources/vulkan/blend-clip.vert.glsl b/gsk/resources/vulkan/blend-clip.vert.glsl
index b1c622b..88ad7c7 100644
--- a/gsk/resources/vulkan/blend-clip.vert.glsl
+++ b/gsk/resources/vulkan/blend-clip.vert.glsl
@@ -1,6 +1,7 @@
#version 420 core
-#include "constants.glsl"
+#define CLIP_RECT
+#include "clip.vert.glsl"
layout(location = 0) in vec4 inRect;
layout(location = 1) in vec4 inTexRect;
@@ -18,18 +19,8 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
vec2(1.0, 0.0),
vec2(1.0, 1.0) };
-vec4 intersect(vec4 a, vec4 b)
-{
- a = vec4(a.xy, a.xy + a.zw);
- b = vec4(b.xy, b.xy + b.zw);
- vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
- if (any (greaterThanEqual (result.xy, result.zw)))
- return vec4(0.0,0.0,0.0,0.0);
- return vec4(result.xy, result.zw - result.xy);
-}
-
void main() {
- vec4 rect = intersect(inRect, push.clip_bounds);
+ vec4 rect = clip (inRect);
vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
diff --git a/gsk/resources/vulkan/blend-clip.vert.spv b/gsk/resources/vulkan/blend-clip.vert.spv
index 494f916..c8840cd 100644
Binary files a/gsk/resources/vulkan/blend-clip.vert.spv and b/gsk/resources/vulkan/blend-clip.vert.spv differ
diff --git a/gsk/resources/vulkan/border-clip-rounded.vert.glsl
b/gsk/resources/vulkan/border-clip-rounded.vert.glsl
index 8db91a5..ed11255 100644
--- a/gsk/resources/vulkan/border-clip-rounded.vert.glsl
+++ b/gsk/resources/vulkan/border-clip-rounded.vert.glsl
@@ -1,6 +1,7 @@
#version 420 core
-#include "constants.glsl"
+#define CLIP_ROUNDED_RECT
+#include "clip.vert.glsl"
layout(location = 0) in vec4 inRect;
layout(location = 1) in vec4 inCornerWidths;
@@ -45,16 +46,6 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
#define SLICE_BOTTOM_LEFT 6
#define SLICE_LEFT 7
-vec4 intersect(vec4 a, vec4 b)
-{
- a = vec4(a.xy, a.xy + a.zw);
- b = vec4(b.xy, b.xy + b.zw);
- vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
- if (any (greaterThanEqual (result.xy, result.zw)))
- return vec4(0.0,0.0,0.0,0.0);
- return vec4(result.xy, result.zw - result.xy);
-}
-
void main() {
int slice_index = gl_VertexIndex / 6;
int vert_index = gl_VertexIndex % 6;
@@ -96,7 +87,7 @@ void main() {
break;
}
- rect = intersect (rect, push.clip_bounds);
+ rect = clip (rect);
vec2 pos;
if ((slice_index % 4) != 0 || (vert_index % 3) != 2)
pos = rect.xy + rect.zw * offsets[vert_index];
diff --git a/gsk/resources/vulkan/border-clip-rounded.vert.spv
b/gsk/resources/vulkan/border-clip-rounded.vert.spv
index ce5e85e..50ce2a2 100644
Binary files a/gsk/resources/vulkan/border-clip-rounded.vert.spv and
b/gsk/resources/vulkan/border-clip-rounded.vert.spv differ
diff --git a/gsk/resources/vulkan/border-clip.vert.glsl b/gsk/resources/vulkan/border-clip.vert.glsl
index 8db91a5..8e0fc83 100644
--- a/gsk/resources/vulkan/border-clip.vert.glsl
+++ b/gsk/resources/vulkan/border-clip.vert.glsl
@@ -1,6 +1,7 @@
#version 420 core
-#include "constants.glsl"
+#define CLIP_RECT
+#include "clip.vert.glsl"
layout(location = 0) in vec4 inRect;
layout(location = 1) in vec4 inCornerWidths;
@@ -45,16 +46,6 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
#define SLICE_BOTTOM_LEFT 6
#define SLICE_LEFT 7
-vec4 intersect(vec4 a, vec4 b)
-{
- a = vec4(a.xy, a.xy + a.zw);
- b = vec4(b.xy, b.xy + b.zw);
- vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
- if (any (greaterThanEqual (result.xy, result.zw)))
- return vec4(0.0,0.0,0.0,0.0);
- return vec4(result.xy, result.zw - result.xy);
-}
-
void main() {
int slice_index = gl_VertexIndex / 6;
int vert_index = gl_VertexIndex % 6;
@@ -96,7 +87,7 @@ void main() {
break;
}
- rect = intersect (rect, push.clip_bounds);
+ rect = clip (rect);
vec2 pos;
if ((slice_index % 4) != 0 || (vert_index % 3) != 2)
pos = rect.xy + rect.zw * offsets[vert_index];
diff --git a/gsk/resources/vulkan/border-clip.vert.spv b/gsk/resources/vulkan/border-clip.vert.spv
index ce5e85e..50ce2a2 100644
Binary files a/gsk/resources/vulkan/border-clip.vert.spv and b/gsk/resources/vulkan/border-clip.vert.spv
differ
diff --git a/gsk/resources/vulkan/clip.vert.glsl b/gsk/resources/vulkan/clip.vert.glsl
new file mode 100644
index 0000000..0dce1a0
--- /dev/null
+++ b/gsk/resources/vulkan/clip.vert.glsl
@@ -0,0 +1,36 @@
+#include "constants.glsl"
+
+#ifndef _CLIP_
+#define _CLIP_
+
+vec4 intersect(vec4 a, vec4 b)
+{
+ a = vec4(a.xy, a.xy + a.zw);
+ b = vec4(b.xy, b.xy + b.zw);
+ vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
+ if (any (greaterThanEqual (result.xy, result.zw)))
+ return vec4(0.0,0.0,0.0,0.0);
+ return vec4(result.xy, result.zw - result.xy);
+}
+
+#ifdef CLIP_ROUNDED_RECT
+vec4 clip(vec4 rect)
+{
+ /* rounded corner clipping is done in fragment shader */
+ return intersect(rect, push.clip_bounds);
+}
+#elif defined(CLIP_RECT)
+vec4 clip(vec4 rect)
+{
+ return intersect(rect, push.clip_bounds);
+}
+#elif defined(CLIP_NONE)
+vec4 clip(vec4 rect)
+{
+ return rect;
+}
+#else
+#error "No clipping define given. Need CLIP_NONE, CLIP_RECT or CLIP_ROUNDED_RECT"
+#endif
+
+#endif
diff --git a/gsk/resources/vulkan/color-clip-rounded.vert.glsl
b/gsk/resources/vulkan/color-clip-rounded.vert.glsl
index 985a174..7f7a1e9 100644
--- a/gsk/resources/vulkan/color-clip-rounded.vert.glsl
+++ b/gsk/resources/vulkan/color-clip-rounded.vert.glsl
@@ -1,6 +1,7 @@
#version 420 core
-#include "constants.glsl"
+#define CLIP_ROUNDED_RECT
+#include "clip.vert.glsl"
layout(location = 0) in vec4 inRect;
layout(location = 1) in vec4 inColor;
@@ -20,7 +21,9 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
vec2(1.0, 1.0) };
void main() {
- vec2 pos = inRect.xy + inRect.zw * offsets[gl_VertexIndex];
+ vec4 rect = clip (inRect);
+
+ vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
outPos = pos;
outColor = inColor;
diff --git a/gsk/resources/vulkan/color-clip-rounded.vert.spv
b/gsk/resources/vulkan/color-clip-rounded.vert.spv
index 941189c..daaf33a 100644
Binary files a/gsk/resources/vulkan/color-clip-rounded.vert.spv and
b/gsk/resources/vulkan/color-clip-rounded.vert.spv differ
diff --git a/gsk/resources/vulkan/color-clip.vert.glsl b/gsk/resources/vulkan/color-clip.vert.glsl
index 724cee1..a869b8a 100644
--- a/gsk/resources/vulkan/color-clip.vert.glsl
+++ b/gsk/resources/vulkan/color-clip.vert.glsl
@@ -1,6 +1,7 @@
#version 420 core
-#include "constants.glsl"
+#define CLIP_RECT
+#include "clip.vert.glsl"
layout(location = 0) in vec4 inRect;
layout(location = 1) in vec4 inColor;
@@ -18,18 +19,8 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
vec2(1.0, 0.0),
vec2(1.0, 1.0) };
-vec4 intersect(vec4 a, vec4 b)
-{
- a = vec4(a.xy, a.xy + a.zw);
- b = vec4(b.xy, b.xy + b.zw);
- vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
- if (any (greaterThanEqual (result.xy, result.zw)))
- return vec4(0.0,0.0,0.0,0.0);
- return vec4(result.xy, result.zw - result.xy);
-}
-
void main() {
- vec4 rect = intersect(inRect, push.clip_bounds);
+ vec4 rect = clip (inRect);
vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
diff --git a/gsk/resources/vulkan/color-clip.vert.spv b/gsk/resources/vulkan/color-clip.vert.spv
index c07e45f..0b2711b 100644
Binary files a/gsk/resources/vulkan/color-clip.vert.spv and b/gsk/resources/vulkan/color-clip.vert.spv differ
diff --git a/gsk/resources/vulkan/color-matrix-clip-rounded.vert.glsl
b/gsk/resources/vulkan/color-matrix-clip-rounded.vert.glsl
index 1c7f0a4..3888b7e 100644
--- a/gsk/resources/vulkan/color-matrix-clip-rounded.vert.glsl
+++ b/gsk/resources/vulkan/color-matrix-clip-rounded.vert.glsl
@@ -1,6 +1,7 @@
#version 420 core
-#include "constants.glsl"
+#define CLIP_ROUNDED_RECT
+#include "clip.vert.glsl"
layout(location = 0) in vec4 inRect;
layout(location = 1) in vec4 inTexRect;
@@ -23,18 +24,8 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
vec2(1.0, 0.0),
vec2(1.0, 1.0) };
-vec4 intersect(vec4 a, vec4 b)
-{
- a = vec4(a.xy, a.xy + a.zw);
- b = vec4(b.xy, b.xy + b.zw);
- vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
- if (any (greaterThanEqual (result.xy, result.zw)))
- return vec4(0.0,0.0,0.0,0.0);
- return vec4(result.xy, result.zw - result.xy);
-}
-
void main() {
- vec4 rect = intersect(inRect, push.clip_bounds);
+ vec4 rect = clip (inRect);
vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
diff --git a/gsk/resources/vulkan/color-matrix-clip-rounded.vert.spv
b/gsk/resources/vulkan/color-matrix-clip-rounded.vert.spv
index 14b85f5..f4951f6 100644
Binary files a/gsk/resources/vulkan/color-matrix-clip-rounded.vert.spv and
b/gsk/resources/vulkan/color-matrix-clip-rounded.vert.spv differ
diff --git a/gsk/resources/vulkan/color-matrix-clip.vert.glsl
b/gsk/resources/vulkan/color-matrix-clip.vert.glsl
index 7f9b778..6ae0817 100644
--- a/gsk/resources/vulkan/color-matrix-clip.vert.glsl
+++ b/gsk/resources/vulkan/color-matrix-clip.vert.glsl
@@ -1,6 +1,7 @@
#version 420 core
-#include "constants.glsl"
+#define CLIP_RECT
+#include "clip.vert.glsl"
layout(location = 0) in vec4 inRect;
layout(location = 1) in vec4 inTexRect;
@@ -22,18 +23,8 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
vec2(1.0, 0.0),
vec2(1.0, 1.0) };
-vec4 intersect(vec4 a, vec4 b)
-{
- a = vec4(a.xy, a.xy + a.zw);
- b = vec4(b.xy, b.xy + b.zw);
- vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
- if (any (greaterThanEqual (result.xy, result.zw)))
- return vec4(0.0,0.0,0.0,0.0);
- return vec4(result.xy, result.zw - result.xy);
-}
-
void main() {
- vec4 rect = intersect(inRect, push.clip_bounds);
+ vec4 rect = clip (inRect);
vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
diff --git a/gsk/resources/vulkan/color-matrix-clip.vert.spv b/gsk/resources/vulkan/color-matrix-clip.vert.spv
index 84c3846..20b615e 100644
Binary files a/gsk/resources/vulkan/color-matrix-clip.vert.spv and
b/gsk/resources/vulkan/color-matrix-clip.vert.spv differ
diff --git a/gsk/resources/vulkan/linear-clip-rounded.vert.glsl
b/gsk/resources/vulkan/linear-clip-rounded.vert.glsl
index fd50e26..b574def 100644
--- a/gsk/resources/vulkan/linear-clip-rounded.vert.glsl
+++ b/gsk/resources/vulkan/linear-clip-rounded.vert.glsl
@@ -1,6 +1,7 @@
#version 420 core
-#include "constants.glsl"
+#define CLIP_ROUNDED_RECT
+#include "clip.vert.glsl"
struct ColorStop {
float offset;
@@ -50,7 +51,8 @@ get_gradient_pos (vec2 pos)
}
void main() {
- vec2 pos = inRect.xy + inRect.zw * offsets[gl_VertexIndex];
+ vec4 rect = clip (inRect);
+ vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
outPos = pos;
outGradientPos = get_gradient_pos (pos);
diff --git a/gsk/resources/vulkan/linear-clip-rounded.vert.spv
b/gsk/resources/vulkan/linear-clip-rounded.vert.spv
index 421516f..9124ffb 100644
Binary files a/gsk/resources/vulkan/linear-clip-rounded.vert.spv and
b/gsk/resources/vulkan/linear-clip-rounded.vert.spv differ
diff --git a/gsk/resources/vulkan/linear-clip.vert.glsl b/gsk/resources/vulkan/linear-clip.vert.glsl
index 4ec7f2e..1176420 100644
--- a/gsk/resources/vulkan/linear-clip.vert.glsl
+++ b/gsk/resources/vulkan/linear-clip.vert.glsl
@@ -1,6 +1,7 @@
#version 420 core
-#include "constants.glsl"
+#define CLIP_RECT
+#include "clip.vert.glsl"
struct ColorStop {
float offset;
@@ -49,7 +50,8 @@ get_gradient_pos (vec2 pos)
}
void main() {
- vec2 pos = inRect.xy + inRect.zw * offsets[gl_VertexIndex];
+ vec4 rect = clip (inRect);
+ vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
outGradientPos = get_gradient_pos (pos);
outRepeating = inRepeating;
diff --git a/gsk/resources/vulkan/linear-clip.vert.spv b/gsk/resources/vulkan/linear-clip.vert.spv
index e7d4cf6..74b8230 100644
Binary files a/gsk/resources/vulkan/linear-clip.vert.spv and b/gsk/resources/vulkan/linear-clip.vert.spv
differ
diff --git a/gsk/resources/vulkan/linear.vert.glsl b/gsk/resources/vulkan/linear.vert.glsl
index 7a55c61..5a7874c 100644
--- a/gsk/resources/vulkan/linear.vert.glsl
+++ b/gsk/resources/vulkan/linear.vert.glsl
@@ -1,6 +1,7 @@
#version 420 core
-#include "constants.glsl"
+#define CLIP_NONE
+#include "clip.vert.glsl"
struct ColorStop {
float offset;
@@ -39,16 +40,6 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
vec2(1.0, 0.0),
vec2(1.0, 1.0) };
-vec4 intersect(vec4 a, vec4 b)
-{
- a = vec4(a.xy, a.xy + a.zw);
- b = vec4(b.xy, b.xy + b.zw);
- vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
- if (any (greaterThanEqual (result.xy, result.zw)))
- return vec4(0.0,0.0,0.0,0.0);
- return vec4(result.xy, result.zw - result.xy);
-}
-
float
get_gradient_pos (vec2 pos)
{
@@ -59,7 +50,7 @@ get_gradient_pos (vec2 pos)
}
void main() {
- vec4 rect = intersect(inRect, push.clip_bounds);
+ vec4 rect = clip (inRect);
vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
outGradientPos = get_gradient_pos (pos);
diff --git a/gsk/resources/vulkan/linear.vert.spv b/gsk/resources/vulkan/linear.vert.spv
index f2b120f..8a40b6d 100644
Binary files a/gsk/resources/vulkan/linear.vert.spv and b/gsk/resources/vulkan/linear.vert.spv differ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]