Got text rendering bindless
parent
dc7f8ed750
commit
7720d696bc
@ -1,95 +1,121 @@
|
||||
#version 450
|
||||
#extension GL_EXT_buffer_reference : require
|
||||
|
||||
layout(buffer_reference, std430) buffer Symbol {
|
||||
int top;
|
||||
uint left;
|
||||
uint width;
|
||||
uint height;
|
||||
uint advance;
|
||||
struct String {
|
||||
vec2 pos;
|
||||
vec4 color;
|
||||
float size;
|
||||
uint offset;
|
||||
uint len;
|
||||
};
|
||||
|
||||
layout(std430, buffer_reference) readonly buffer StringList {
|
||||
String s[];
|
||||
};
|
||||
|
||||
layout(buffer_reference, std430) buffer Character {
|
||||
vec3 pos;
|
||||
struct Glyph {
|
||||
vec2 pos;
|
||||
vec4 color;
|
||||
float size;
|
||||
uint code;
|
||||
};
|
||||
|
||||
layout(buffer_reference, std430) buffer String {
|
||||
vec3 pos;
|
||||
layout(std430, buffer_reference) readonly buffer GlyphList {
|
||||
Glyph g[];
|
||||
};
|
||||
|
||||
struct Rect {
|
||||
vec2 pos;
|
||||
vec2 size;
|
||||
vec4 color;
|
||||
float size;
|
||||
uint offset;
|
||||
uint len;
|
||||
};
|
||||
|
||||
layout(buffer_reference, std430) readonly buffer SymbolList{
|
||||
Symbol symbols[];
|
||||
layout(std430, buffer_reference) readonly buffer RectList {
|
||||
Rect r[];
|
||||
};
|
||||
|
||||
layout(buffer_reference, std430) writeonly buffer CharacterList{
|
||||
Character characters[];
|
||||
layout(std430, buffer_reference) readonly buffer CodeList {
|
||||
uint c[];
|
||||
};
|
||||
|
||||
layout(buffer_reference, std430) readonly buffer Characters{
|
||||
uint codes[];
|
||||
struct DrawCommand {
|
||||
uint vertex_count;
|
||||
uint instance_count;
|
||||
uint fist_vertex;
|
||||
uint first_instance;
|
||||
};
|
||||
|
||||
layout(buffer_reference, std430) readonly buffer Strings{
|
||||
String strings[];
|
||||
struct DispatchCommand {
|
||||
uint x;
|
||||
uint y;
|
||||
uint z;
|
||||
};
|
||||
|
||||
layout(buffer_reference, std430) readonly buffer Font {
|
||||
uint num_symbols;
|
||||
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;
|
||||
SymbolList symbol_list;
|
||||
uint advance;
|
||||
};
|
||||
|
||||
layout(buffer_reference, std430) buffer DrawCommand {
|
||||
uint vertex_count;
|
||||
uint instance_count;
|
||||
uint first_vertx;
|
||||
uint first_instance;
|
||||
layout(std430, buffer_reference) buffer SymbolList {
|
||||
Symbol s[];
|
||||
};
|
||||
|
||||
layout(buffer_reference, std430) readonly buffer Pointers {
|
||||
Strings strings;
|
||||
Characters codes;
|
||||
CharacterList characters;
|
||||
DrawCommand draw;
|
||||
|
||||
struct Font {
|
||||
SymbolList symbols;
|
||||
uint num_symbols;
|
||||
uint width;
|
||||
uint height;
|
||||
};
|
||||
|
||||
layout(buffer_reference, std430) readonly buffer FontList {
|
||||
Font fonts[];
|
||||
|
||||
layout(std430, buffer_reference) buffer FontList {
|
||||
Font f[];
|
||||
};
|
||||
|
||||
layout(buffer_reference, std430) readonly buffer UIContext {
|
||||
mat4 screen;
|
||||
layout(std430, buffer_reference) buffer UIContext {
|
||||
FontList fonts;
|
||||
mat4 screen;
|
||||
};
|
||||
|
||||
layout(std430, push_constant) uniform Push {
|
||||
UIContext ui;
|
||||
Pointers pointers;
|
||||
} push;
|
||||
layout(std430, push_constant) uniform PushConstant {
|
||||
UIContext context;
|
||||
UILayer layer;
|
||||
} pc;
|
||||
|
||||
layout(local_size_x = 1) in;
|
||||
|
||||
void main() {
|
||||
uint gID = gl_GlobalInvocationID.x;
|
||||
String string = push.pointers.strings.strings[gID];
|
||||
Font font = push.ui.fonts.fonts[0];
|
||||
String string = pc.layer.strings.s[gID];
|
||||
Font font = pc.context.fonts.f[pc.layer.font_index];
|
||||
|
||||
uint buffer_pos = atomicAdd(push.pointers.draw.instance_count, string.len);
|
||||
uint buffer_pos = atomicAdd(pc.layer.draw_glyphs.instance_count, string.len);
|
||||
float x = 0;
|
||||
for(uint i = 0; i < string.len; i++) {
|
||||
Symbol symbol = font.symbol_list.symbols[push.pointers.codes.codes[string.offset + i]];
|
||||
push.pointers.characters.characters[buffer_pos + i].pos = string.pos + vec3(x, 0, 0);
|
||||
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);
|
||||
x += string.size*symbol.advance/font.width;
|
||||
push.pointers.characters.characters[buffer_pos + i].size = string.size;
|
||||
push.pointers.characters.characters[buffer_pos + i].color = string.color;
|
||||
push.pointers.characters.characters[buffer_pos + i].code = push.pointers.codes.codes[string.offset + i];
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue