Files
ld58/code/draw/core.h
James Bulman eb3c81cd04 Added unproject
Broken and buggy font stuff
Fixed some typos
Fixed draw rect not using dim properly
2025-10-05 21:11:18 +01:00

125 lines
1.9 KiB
C

#if !defined(LD_DRAW_CORE_H_)
#define LD_DRAW_CORE_H_
#define D_MAX_RECTS (262144)
typedef struct D_Glyph D_Glyph;
struct D_Glyph {
F32 advance;
V2f offset;
R2f box;
};
typedef struct D_Font D_Font;
struct D_Font {
D_Font *next;
F32 px;
F32 line_advance;
F32 ascent;
F32 descent;
F32 *kerning;
D_Glyph *glyphs;
Vk_Image image;
};
typedef struct D_Image D_Image;
struct D_Image {
Str8 name;
Vk_Image image;
};
typedef struct D_Rect D_Rect;
struct D_Rect {
U32 texture;
U32 c[4]; // per-vertex colours
F32 uv[4];
F32 angle;
F32 x, y;
F32 w, h;
U32 p0, p1;
};
StaticAssert(sizeof(D_Rect) == 64);
struct G_Camera;
typedef struct D_Context D_Context;
struct D_Context {
Vk_Buffer *rbo;
Vk_Buffer staging;
M_Arena *arena;
U32 n_pipelines;
Vk_Pipeline *pipelines;
U32 n_images;
D_Image *images;
U32 n_fonts;
D_Font *fonts;
U32 max_rects;
U32 n_rects;
D_Rect *rects;
U32 window_width;
U32 window_height;
struct G_Camera *camera;
};
typedef U32 D_RectFlags;
enum D_RectFlags {
D_RECT_IGNORE_ASPECT = (1 << 0), // by default only width is used as a "dimension"
D_RECT_PER_VERTEX_COLOUR = (1 << 1), // split colours per vertex
};
typedef struct D_RectOpts D_RectOpts;
struct D_RectOpts {
D_RectFlags flags;
U32 texture;
R2f uv;
V2f p;
F32 angle;
union {
V2f dim;
struct {
F32 w, h;
};
struct {
F32 scale, _h;
};
};
union {
V4f c;
V4f vtxc[4];
};
};
function void D_Begin(D_Context *draw, Vk_Frame *frame, U32 max_rects);
function void D_End(D_Context *draw, Vk_Frame *frame);
function void D_Text(D_Context *draw, D_Font *font, Str8 text, F32 x, F32 y);
function void _D_Rect(D_Context *draw, D_RectOpts *opts);
#define D_Rect(draw, x, y, ...) _D_Rect(draw, &(D_RectOpts) { .p = V2F(x, y), .uv = R2F(V2F(0, 0), V2F(1, 1)), .scale = 1, .c = V4F(1, 1, 1, 1), ##__VA_ARGS__ })
function void D_FontLoad(D_Context *draw, Str8 path, F32 size);
#endif // LD_DRAW_CORE_H_