55 lines
1.4 KiB
GLSL
55 lines
1.4 KiB
GLSL
#version 450
|
|
#extension GL_EXT_buffer_reference : require
|
|
|
|
#include "ui_common.glsl"
|
|
|
|
layout(std430, push_constant) uniform PushConstant {
|
|
Context context;
|
|
Layer layer;
|
|
} pc;
|
|
|
|
layout(location = 0) out vec4 fragColor;
|
|
layout(location = 1) out vec2 fragUV;
|
|
layout(location = 2) out uint code;
|
|
layout(location = 3) out uint index;
|
|
layout(location = 4) out uint type;
|
|
|
|
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),
|
|
};
|
|
|
|
void main() {
|
|
vec2 scale = pc.context.scale / pc.context.screen;
|
|
Drawable drawable = pc.layer.drawables.d[gl_InstanceIndex];
|
|
vec2 pos = square[gl_VertexIndex];
|
|
|
|
if(drawable.type == 0) {
|
|
// Rect
|
|
} else if(drawable.type == 1){
|
|
// Glyph
|
|
Font font = pc.context.fonts.f[pc.layer.font_index];
|
|
Symbol symbol = font.symbols.s[drawable.code];
|
|
|
|
float scalex = float(symbol.width)/float(font.width);
|
|
float scaley = float(symbol.height)/float(font.height);
|
|
float offx = float(symbol.left)/float(font.width);
|
|
float offy = float(symbol.top)/float(font.height);
|
|
|
|
fragUV = pos * vec2(scalex, scaley);
|
|
pos = pos * vec2(scalex, scaley) + vec2(offx, -offy);
|
|
}
|
|
|
|
gl_Position = vec4((pos * drawable.size + drawable.pos + pc.layer.container.pos) * scale, 0.0, 1.0) - vec4(1.0, 1.0, 0.0, 0.0);
|
|
|
|
fragColor = drawable.color;
|
|
code = drawable.code;
|
|
type = drawable.type;
|
|
index = pc.layer.font_index;
|
|
}
|
|
|