layout(location = 0) in vec2 inPos;
layout(location = 1) in vec4 inColor;
-layout(location = 2) in vec4 inRect;
-layout(location = 3) in vec4 inCornerWidths;
-layout(location = 4) in vec4 inCornerHeights;
+layout(location = 2) in RoundedRect inRect;
layout(location = 5) in vec4 inBorderWidths;
layout(location = 0) out vec4 color;
void main()
{
- RoundedRect routside = RoundedRect (vec4(inRect.xy, inRect.xy + inRect.zw), inCornerWidths, inCornerHeights);
+ RoundedRect routside = inRect;
RoundedRect rinside = rounded_rect_shrink (routside, inBorderWidths);
float alpha = clamp (rounded_rect_coverage (routside, inPos) -
rounded_rect_coverage (rinside, inPos),
0.0, 1.0);
- color = clip (inPos, vec4(inColor.rgb * inColor.a, inColor.a) * alpha);
+ color = clip_scaled (inPos, vec4(inColor.rgb * inColor.a, inColor.a) * alpha);
}
#version 420 core
#include "clip.vert.glsl"
+#include "rounded-rect.glsl"
layout(location = 0) in vec4 inRect;
layout(location = 1) in vec4 inCornerWidths;
layout(location = 0) out vec2 outPos;
layout(location = 1) out flat vec4 outColor;
-layout(location = 2) out flat vec4 outRect;
-layout(location = 3) out flat vec4 outCornerWidths;
-layout(location = 4) out flat vec4 outCornerHeights;
+layout(location = 2) out flat RoundedRect outRect;
layout(location = 5) out flat vec4 outBorderWidths;
vec2 offsets[6] = { vec2(0.0, 0.0),
pos = mix (rect.bounds.xy, rect.bounds.zw, offsets[vert_index]);
else
pos = mix (rect.bounds.zy, rect.bounds.xw, offsets[vert_index]);
- gl_Position = push.mvp * vec4 (push.scale * pos, 0.0, 1.0);
+ gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
outColor = inBorderColors[((gl_VertexIndex / 3 + 15) / 4) % 4];
outPos = pos;
- outRect = inRect;
- outCornerWidths = inCornerWidths;
- outCornerHeights = inCornerHeights;
- outBorderWidths = inBorderWidths;
+ outRect = RoundedRect(inRect.xyxy + vec4(0,0,inRect.zw), inCornerWidths, inCornerHeights);
+ outRect = rounded_rect_scale (outRect, push.scale);
+ outBorderWidths = inBorderWidths * push.scale.yxyx;
}
#define _CLIP_
#ifdef CLIP_ROUNDED_RECT
-vec4 clip(vec2 pos, vec4 color)
+
+vec4
+clip_scaled (vec2 pos, vec4 color)
{
RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw), push.clip_widths, push.clip_heights);
+ r = rounded_rect_scale (r, push.scale);
+
return color * rounded_rect_coverage (r, pos);
}
+
#elif defined(CLIP_RECT)
-vec4 clip(vec2 pos, vec4 color)
+
+vec4
+clip_scaled (vec2 pos, vec4 color)
{
- /* clipped in vertex shader already */
return color;
}
+
#elif defined(CLIP_NONE)
-vec4 clip(vec2 pos, vec4 color)
+
+vec4
+clip_scaled (vec2 pos, vec4 color)
{
return color;
}
+
#else
#error "No clipping define given. Need CLIP_NONE, CLIP_RECT or CLIP_ROUNDED_RECT"
#endif
+vec4
+clip (vec2 pos, vec4 color)
+{
+ return clip_scaled (pos * push.scale, color);
+}
+
#endif
void main()
{
float alpha = inColor.a * rect_coverage (inRect, inPos);
- color = clip (inPos, vec4(inColor.rgb, 1) * alpha);
+ color = clip_scaled (inPos, vec4(inColor.rgb, 1) * alpha);
}
Rect rect = rect_round_larger (clip_rect (rect_from_gsk (inRect)));
vec2 pos = mix (rect.bounds.xy, rect.bounds.zw, offsets[gl_VertexIndex]);
- gl_Position = push.mvp * vec4 (push.scale * pos, 0.0, 1.0);
+ gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
outPos = pos;
outRect = rect_from_gsk (inRect);
outColor = inColor;
Rect
rect_from_gsk (vec4 xywh)
{
- return Rect(xywh.xyxy + vec4(0,0,xywh.zw));
+ return Rect((xywh.xyxy + vec4(0,0,xywh.zw)) * push.scale.xyxy);
}
float
return max (max2.x, max2.y);
}
+RoundedRect
+rounded_rect_scale (RoundedRect r, vec2 scale)
+{
+ r.bounds *= scale.xyxy;
+ r.corner_widths *= scale.xxxx;
+ r.corner_heights *= scale.yyyy;
+
+ return r;
+}
+
RoundedRect
rounded_rect_shrink (RoundedRect r, vec4 amount)
{