2017-01-10 13:59:20 +00:00
|
|
|
#version 420 core
|
|
|
|
|
2017-01-17 04:50:52 +00:00
|
|
|
#include "clip.vert.glsl"
|
2023-05-13 01:14:16 +00:00
|
|
|
#include "rounded-rect.glsl"
|
2017-01-17 01:20:08 +00:00
|
|
|
|
2017-01-10 13:59:20 +00:00
|
|
|
layout(location = 0) in vec4 inRect;
|
|
|
|
layout(location = 1) in vec4 inCornerWidths;
|
|
|
|
layout(location = 2) in vec4 inCornerHeights;
|
|
|
|
layout(location = 3) in vec4 inBorderWidths;
|
|
|
|
layout(location = 4) in mat4 inBorderColors;
|
|
|
|
|
|
|
|
layout(location = 0) out vec2 outPos;
|
|
|
|
layout(location = 1) out flat vec4 outColor;
|
2023-05-13 01:14:16 +00:00
|
|
|
layout(location = 2) out flat RoundedRect outRect;
|
2017-01-10 13:59:20 +00:00
|
|
|
layout(location = 5) out flat vec4 outBorderWidths;
|
|
|
|
|
|
|
|
vec2 offsets[6] = { vec2(0.0, 0.0),
|
|
|
|
vec2(1.0, 0.0),
|
|
|
|
vec2(0.0, 1.0),
|
|
|
|
vec2(1.0, 1.0),
|
|
|
|
vec2(0.0, 1.0),
|
|
|
|
vec2(1.0, 0.0) };
|
|
|
|
|
|
|
|
#define TOP 0
|
|
|
|
#define RIGHT 1
|
|
|
|
#define BOTTOM 2
|
|
|
|
#define LEFT 3
|
|
|
|
|
|
|
|
#define TOP_LEFT 0
|
|
|
|
#define TOP_RIGHT 1
|
|
|
|
#define BOTTOM_RIGHT 2
|
|
|
|
#define BOTTOM_LEFT 3
|
|
|
|
|
|
|
|
#define SLICE_TOP_LEFT 0
|
|
|
|
#define SLICE_TOP 1
|
|
|
|
#define SLICE_TOP_RIGHT 2
|
|
|
|
#define SLICE_RIGHT 3
|
|
|
|
#define SLICE_BOTTOM_RIGHT 4
|
|
|
|
#define SLICE_BOTTOM 5
|
|
|
|
#define SLICE_BOTTOM_LEFT 6
|
|
|
|
#define SLICE_LEFT 7
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
int slice_index = gl_VertexIndex / 6;
|
|
|
|
int vert_index = gl_VertexIndex % 6;
|
|
|
|
|
|
|
|
vec4 corner_widths = max (inCornerWidths, inBorderWidths.wyyw);
|
|
|
|
vec4 corner_heights = max (inCornerHeights, inBorderWidths.xxzz);
|
|
|
|
|
2023-05-07 01:41:38 +00:00
|
|
|
Rect rect;
|
2017-01-10 13:59:20 +00:00
|
|
|
|
|
|
|
switch (slice_index)
|
|
|
|
{
|
|
|
|
case SLICE_TOP_LEFT:
|
2023-05-07 01:41:38 +00:00
|
|
|
rect = rect_from_gsk (vec4(inRect.xy, corner_widths[TOP_LEFT], corner_heights[TOP_LEFT]));
|
|
|
|
rect = rect_round_larger (rect);
|
2017-01-10 13:59:20 +00:00
|
|
|
vert_index = (vert_index + 3) % 6;
|
|
|
|
break;
|
|
|
|
case SLICE_TOP:
|
2023-05-07 01:41:38 +00:00
|
|
|
rect = rect_from_gsk (vec4(inRect.x + corner_widths[TOP_LEFT], inRect.y, inRect.z - corner_widths[TOP_LEFT] - corner_widths[TOP_RIGHT], inBorderWidths[TOP]));
|
|
|
|
rect = rect_round_smaller_larger (rect);
|
2017-01-10 13:59:20 +00:00
|
|
|
outColor = inBorderColors[TOP];
|
|
|
|
break;
|
|
|
|
case SLICE_TOP_RIGHT:
|
2023-05-07 01:41:38 +00:00
|
|
|
rect = rect_from_gsk (vec4(inRect.x + inRect.z - corner_widths[TOP_RIGHT], inRect.y, corner_widths[TOP_RIGHT], corner_heights[TOP_RIGHT]));
|
|
|
|
rect = rect_round_larger (rect);
|
2017-01-10 13:59:20 +00:00
|
|
|
break;
|
|
|
|
case SLICE_RIGHT:
|
2023-05-07 01:41:38 +00:00
|
|
|
rect = rect_from_gsk (vec4(inRect.x + inRect.z - inBorderWidths[RIGHT], inRect.y + corner_heights[TOP_RIGHT], inBorderWidths[RIGHT], inRect.w - corner_heights[TOP_RIGHT] - corner_heights[BOTTOM_RIGHT]));
|
|
|
|
rect = rect_round_larger_smaller (rect);
|
2017-01-10 13:59:20 +00:00
|
|
|
outColor = inBorderColors[RIGHT];
|
|
|
|
break;
|
|
|
|
case SLICE_BOTTOM_RIGHT:
|
2023-05-07 01:41:38 +00:00
|
|
|
rect = rect_from_gsk (vec4(inRect.x + inRect.z - corner_widths[BOTTOM_RIGHT], inRect.y + inRect.w - corner_heights[BOTTOM_RIGHT], corner_widths[BOTTOM_RIGHT], corner_heights[BOTTOM_RIGHT]));
|
|
|
|
rect = rect_round_larger (rect);
|
2017-01-10 13:59:20 +00:00
|
|
|
break;
|
|
|
|
case SLICE_BOTTOM:
|
2023-05-07 01:41:38 +00:00
|
|
|
rect = rect_from_gsk (vec4(inRect.x + corner_widths[BOTTOM_LEFT], inRect.y + inRect.w - inBorderWidths[BOTTOM], inRect.z - corner_widths[BOTTOM_LEFT] - corner_widths[BOTTOM_RIGHT], inBorderWidths[BOTTOM]));
|
|
|
|
rect = rect_round_smaller_larger (rect);
|
2017-01-10 13:59:20 +00:00
|
|
|
break;
|
|
|
|
case SLICE_BOTTOM_LEFT:
|
2023-05-07 01:41:38 +00:00
|
|
|
rect = rect_from_gsk (vec4(inRect.x, inRect.y + inRect.w - corner_heights[BOTTOM_LEFT], corner_widths[BOTTOM_LEFT], corner_heights[BOTTOM_LEFT]));
|
2017-01-10 13:59:20 +00:00
|
|
|
vert_index = (vert_index + 3) % 6;
|
2023-05-07 01:41:38 +00:00
|
|
|
rect = rect_round_larger (rect);
|
2017-01-10 13:59:20 +00:00
|
|
|
break;
|
|
|
|
case SLICE_LEFT:
|
2023-05-07 01:41:38 +00:00
|
|
|
rect = rect_from_gsk (vec4(inRect.x, inRect.y + corner_heights[TOP_LEFT], inBorderWidths[LEFT], inRect.w - corner_heights[TOP_LEFT] - corner_heights[BOTTOM_LEFT]));
|
|
|
|
rect = rect_round_larger_smaller (rect);
|
2017-01-10 13:59:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-05-07 01:41:38 +00:00
|
|
|
rect = clip_rect (rect);
|
|
|
|
|
2017-01-10 13:59:20 +00:00
|
|
|
vec2 pos;
|
|
|
|
if ((slice_index % 4) != 0 || (vert_index % 3) != 2)
|
2023-05-07 01:41:38 +00:00
|
|
|
pos = mix (rect.bounds.xy, rect.bounds.zw, offsets[vert_index]);
|
2017-01-10 13:59:20 +00:00
|
|
|
else
|
2023-05-07 01:41:38 +00:00
|
|
|
pos = mix (rect.bounds.zy, rect.bounds.xw, offsets[vert_index]);
|
2023-05-13 01:14:16 +00:00
|
|
|
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
|
2017-01-10 13:59:20 +00:00
|
|
|
outColor = inBorderColors[((gl_VertexIndex / 3 + 15) / 4) % 4];
|
|
|
|
outPos = pos;
|
2023-05-13 01:14:16 +00:00
|
|
|
outRect = RoundedRect(inRect.xyxy + vec4(0,0,inRect.zw), inCornerWidths, inCornerHeights);
|
|
|
|
outRect = rounded_rect_scale (outRect, push.scale);
|
|
|
|
outBorderWidths = inBorderWidths * push.scale.yxyx;
|
2017-01-10 13:59:20 +00:00
|
|
|
}
|