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