vulkan: Add clip.vert.glsl

Implement clipping the same way as in the last commit for the
fragment shaders.
This commit is contained in:
Benjamin Otte 2017-01-17 05:50:52 +01:00
parent cf65443fb3
commit 3768c676c6
24 changed files with 74 additions and 102 deletions

View File

@ -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 = \

View File

@ -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);

View File

@ -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);

View File

@ -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];

View File

@ -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];

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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);

Binary file not shown.