Files
ld58/code/draw/core.h
James Bulman 1757fc4b96 Added rect draw api
Added some new maths types
Updated shaders to use new D_Rect structure
Added rect buffers to frames
Misc cleanup
2025-10-05 14:27:05 +01:00

86 lines
1.4 KiB
C

#if !defined(LD_DRAW_CORE_H_)
#define LD_DRAW_CORE_H_
#define D_MAX_RECTS 1024
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;
U32 n_pipelines;
Vk_Pipeline *pipelines;
U32 n_images;
D_Image *images;
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 {
F32 w, h;
F32 scale, _h;
V2f dim;
};
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_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__ })
#endif // LD_DRAW_CORE_H_