roleplay/client/shader_src/ui_text.comp

122 lines
2.2 KiB
Plaintext

#version 450
#extension GL_EXT_buffer_reference : require
2024-10-18 18:34:31 -06:00
struct String {
vec2 pos;
vec4 color;
float size;
uint offset;
uint len;
};
layout(std430, buffer_reference) readonly buffer StringList {
String s[];
};
2024-10-18 18:34:31 -06:00
struct Glyph {
vec2 pos;
vec4 color;
float size;
uint code;
};
2024-10-18 18:34:31 -06:00
layout(std430, buffer_reference) readonly buffer GlyphList {
Glyph g[];
};
struct Rect {
vec2 pos;
vec2 size;
vec4 color;
};
2024-10-18 18:34:31 -06:00
layout(std430, buffer_reference) readonly buffer RectList {
Rect r[];
};
2024-10-18 18:34:31 -06:00
layout(std430, buffer_reference) readonly buffer CodeList {
uint c[];
};
2024-10-18 18:34:31 -06:00
struct DrawCommand {
uint vertex_count;
uint instance_count;
uint fist_vertex;
uint first_instance;
};
2024-10-18 18:34:31 -06:00
struct DispatchCommand {
uint x;
uint y;
uint z;
};
2024-10-18 18:34:31 -06:00
layout(std430, buffer_reference) buffer UILayer {
StringList strings;
CodeList codes;
RectList rects;
GlyphList glyphs;
DrawCommand draw_glyphs;
DrawCommand draw_rects;
DispatchCommand dispatch_strings;
uint font_index;
};
struct Symbol {
int top;
uint left;
uint width;
uint height;
2024-10-18 18:34:31 -06:00
uint advance;
};
2024-10-18 18:34:31 -06:00
layout(std430, buffer_reference) buffer SymbolList {
Symbol s[];
2024-10-15 11:44:59 -06:00
};
2024-10-18 18:34:31 -06:00
struct Font {
SymbolList symbols;
uint num_symbols;
uint width;
uint height;
};
2024-10-18 18:34:31 -06:00
layout(std430, buffer_reference) buffer FontList {
Font f[];
};
2024-10-18 18:34:31 -06:00
layout(std430, buffer_reference) buffer UIContext {
FontList fonts;
2024-10-18 18:34:31 -06:00
mat4 screen;
};
2024-10-18 18:34:31 -06:00
layout(std430, push_constant) uniform PushConstant {
UIContext context;
UILayer layer;
} pc;
2024-10-15 11:44:59 -06:00
layout(local_size_x = 1) in;
void main() {
2024-10-15 11:44:59 -06:00
uint gID = gl_GlobalInvocationID.x;
2024-10-18 18:34:31 -06:00
String string = pc.layer.strings.s[gID];
Font font = pc.context.fonts.f[pc.layer.font_index];
2024-10-15 11:44:59 -06:00
2024-10-18 18:34:31 -06:00
uint buffer_pos = atomicAdd(pc.layer.draw_glyphs.instance_count, string.len);
2024-10-15 16:37:20 -06:00
float x = 0;
for(uint i = 0; i < string.len; i++) {
2024-10-18 18:34:31 -06:00
Symbol symbol = font.symbols.s[pc.layer.codes.c[string.offset + i]];
pc.layer.glyphs.g[buffer_pos + i].pos = string.pos + vec2(x, 0);
2024-10-16 20:29:19 -06:00
x += string.size*symbol.advance/font.width;
2024-10-18 18:34:31 -06:00
pc.layer.glyphs.g[buffer_pos + i].size = string.size;
pc.layer.glyphs.g[buffer_pos + i].color = string.color;
pc.layer.glyphs.g[buffer_pos + i].code = pc.layer.codes.c[string.offset + i];
}
}