2024-10-13 22:18:37 -06:00
|
|
|
#version 450
|
2024-10-14 14:16:59 -06:00
|
|
|
#extension GL_EXT_buffer_reference : require
|
|
|
|
|
2024-10-20 21:59:28 -06:00
|
|
|
#include "ui_common.glsl"
|
2024-10-15 00:06:46 -06:00
|
|
|
|
2024-10-13 22:18:37 -06:00
|
|
|
layout(location = 0) out vec4 fragColor;
|
|
|
|
layout(location = 1) out vec2 fragUV;
|
2024-11-12 11:56:57 -07:00
|
|
|
layout(location = 2) out flat uint glyph;
|
|
|
|
layout(location = 3) out flat uint index;
|
2024-10-20 22:39:54 -06:00
|
|
|
layout(location = 4) out flat uint type;
|
2024-10-22 17:48:37 -06:00
|
|
|
layout(location = 5) out flat vec2 container_offset;
|
2024-10-13 22:18:37 -06:00
|
|
|
|
2024-11-12 11:56:57 -07:00
|
|
|
const uint color_index[6] = {
|
|
|
|
0, 1, 2, 1, 3, 2
|
|
|
|
};
|
|
|
|
|
2024-10-17 15:56:35 -06:00
|
|
|
const vec2 square[6] = {
|
|
|
|
vec2(0.0, 0.0),
|
|
|
|
vec2(1.0, 0.0),
|
|
|
|
vec2(0.0, 1.0),
|
|
|
|
vec2(1.0, 0.0),
|
|
|
|
vec2(1.0, 1.0),
|
|
|
|
vec2(0.0, 1.0),
|
|
|
|
};
|
|
|
|
|
2024-10-13 22:18:37 -06:00
|
|
|
void main() {
|
2024-10-18 22:53:06 -06:00
|
|
|
Drawable drawable = pc.layer.drawables.d[gl_InstanceIndex];
|
2024-10-20 21:59:28 -06:00
|
|
|
vec2 pos = square[gl_VertexIndex];
|
2024-10-22 17:48:37 -06:00
|
|
|
|
|
|
|
// Top Left
|
|
|
|
if(pc.layer.container.anchor == 0) {
|
|
|
|
container_offset = pc.layer.container.offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Top Right
|
|
|
|
if(pc.layer.container.anchor == 1) {
|
2024-10-24 20:49:59 -06:00
|
|
|
container_offset = pc.layer.container.offset + vec2(pc.layer.container.context.extent.x - pc.layer.container.size.x, 0);
|
2024-10-22 17:48:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bottom Left
|
|
|
|
if(pc.layer.container.anchor == 2) {
|
2024-10-24 20:49:59 -06:00
|
|
|
container_offset = pc.layer.container.offset + vec2(0, pc.layer.container.context.extent.y - pc.layer.container.size.y);
|
2024-10-22 17:48:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bottom Right
|
|
|
|
if(pc.layer.container.anchor == 3) {
|
2024-10-24 20:49:59 -06:00
|
|
|
container_offset = pc.layer.container.offset + vec2(pc.layer.container.context.extent.x - pc.layer.container.size.x, pc.layer.container.context.extent.y - pc.layer.container.size.y);
|
2024-10-22 17:48:37 -06:00
|
|
|
}
|
2024-10-18 22:53:06 -06:00
|
|
|
|
2024-11-12 11:56:57 -07:00
|
|
|
if(drawable.type == 1) {
|
|
|
|
index = (drawable.var >> 16) & 0xFFFF;
|
|
|
|
glyph = drawable.var & 0xFFFF;
|
|
|
|
Font font = pc.layer.container.context.fonts.f[index];
|
|
|
|
Symbol symbol = font.symbols.s[glyph];
|
2024-10-18 22:53:06 -06:00
|
|
|
|
2024-10-20 22:39:12 -06:00
|
|
|
fragUV = pos * vec2(symbol.width, symbol.height);
|
|
|
|
pos = pos * vec2(symbol.width, symbol.height) + vec2(symbol.left, -symbol.top);
|
2024-11-12 11:56:57 -07:00
|
|
|
} else if(drawable.type == 2) {
|
2024-10-21 10:09:52 -06:00
|
|
|
fragUV = pos;
|
2024-11-12 11:56:57 -07:00
|
|
|
index = drawable.var;
|
2024-10-18 22:53:06 -06:00
|
|
|
}
|
|
|
|
|
2024-11-12 11:56:57 -07:00
|
|
|
|
2024-10-24 20:49:59 -06:00
|
|
|
gl_Position = vec4((pos * drawable.size + drawable.pos + container_offset) * pc.layer.container.context.screen * 2, 0.0, 1.0) - vec4(1.0, 1.0, 0.0, 0.0);
|
2024-10-20 21:59:28 -06:00
|
|
|
|
2024-11-12 11:56:57 -07:00
|
|
|
fragColor = drawable.color[color_index[gl_VertexIndex]];
|
2024-10-18 22:53:06 -06:00
|
|
|
type = drawable.type;
|
2024-10-13 22:18:37 -06:00
|
|
|
}
|
|
|
|
|