Added rect draw api

Added some new maths types
Updated shaders to use new D_Rect structure
Added rect buffers to frames
Misc cleanup
This commit is contained in:
2025-10-05 14:27:05 +01:00
parent 3b8c50a361
commit 1757fc4b96
14 changed files with 432 additions and 121 deletions

View File

@@ -4,12 +4,12 @@
layout(location = 0) in vec2 frag_uv;
layout(location = 1) in vec4 frag_c;
layout(location = 2) in flat uint idx;
layout(location = 2) in flat uint texid;
layout(location = 0) out vec4 framebuffer;
layout(binding = 1) uniform sampler2D u_image[];
layout(binding = 1) uniform sampler2D u_images[];
void main() {
framebuffer = frag_c * texture(u_image[idx], frag_uv);
framebuffer = frag_c * texture(u_images[texid], frag_uv);
}

View File

@@ -2,6 +2,28 @@
#extension GL_EXT_scalar_block_layout : enable
uint indices[6] = { 0, 1, 3, 0, 3, 2 };
vec2 verticies[4] = vec2[](
vec2(-0.5, -0.5),
vec2( 0.5, -0.5),
vec2(-0.5, 0.5),
vec2( 0.5, 0.5)
);
struct G_Rect {
uint id;
uint c[4];
float uv[4];
float angle;
float x, y;
float w, h;
float _pad0, _pad1;
};
struct Vertex {
vec4 p;
vec2 uv;
@@ -15,22 +37,28 @@ uniform Global {
};
layout(binding = 0, scalar)
readonly buffer Vertices {
Vertex vtx[];
readonly buffer Rect {
G_Rect rects[];
};
layout(location = 0) out vec2 frag_uv;
layout(location = 1) out vec4 frag_c;
layout(location = 2) out flat uint idx;
layout(location = 2) out flat uint texid;
vec4 unorm_colour(uint c) {
vec4 result = vec4((c >> 0) & 0xFF, (c >> 8) & 0xFF, (c >> 16) & 0xFF, (c >> 24) & 0xFF) / 255.0f;
return result;
}
void main() {
Vertex v = vtx[gl_VertexIndex];
G_Rect rect = rects[gl_InstanceIndex];
uint idx = indices[gl_VertexIndex];
gl_Position = proj * v.p;
vec2 p = (verticies[idx] * vec2(rect.w, rect.h)) + vec2(rect.x, rect.y);
frag_uv = v.uv;
frag_c = vec4((v.c >> 24) & 0xFF, (v.c >> 16) & 0xFF, (v.c >> 8) & 0xFF, (v.c >> 0) & 0xFF) / 255.0f;
frag_c = frag_c.abgr;
gl_Position = proj * vec4(p, 1.0f, 1.0f);
idx = v.pad;
frag_uv = vec2(rect.uv[(idx & 1) << 1], rect.uv[1 + (uint(idx / 2) << 1)]);
frag_c = unorm_colour(rect.c[idx]);
texid = rect.id;
}