Learning_GTK4_tree/gsk/vulkan/resources/clip.vert.glsl

64 lines
1.1 KiB
GLSL

#include "constants.glsl"
#include "rect.vert.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);
}
Rect
clip_rect (Rect r)
{
/* rounded corner clipping is done in fragment shader */
return rect_intersect (r, rect_round_larger (rect_from_gsk (push.clip_bounds)));
}
#elif defined(CLIP_RECT)
vec4
clip(vec4 rect)
{
return intersect(rect, push.clip_bounds);
}
Rect
clip_rect (Rect r)
{
return rect_intersect (r, rect_round_larger (rect_from_gsk (push.clip_bounds)));
}
#elif defined(CLIP_NONE)
vec4 clip(vec4 rect)
{
return rect;
}
Rect
clip_rect (Rect r)
{
return r;
}
#else
#error "No clipping define given. Need CLIP_NONE, CLIP_RECT or CLIP_ROUNDED_RECT"
#endif
#endif