power_play/src/draw/draw.h
2025-12-09 14:31:25 -06:00

154 lines
4.2 KiB
C

////////////////////////////////////////////////////////////
//~ Material types
Struct(D_MaterialParams)
{
Xform xf;
GPU_Resource *texture;
ClipRect clip;
u32 tint;
b32 is_light;
Vec3 light_emittance;
};
#define D_MATERIALPARAMS(...) ((D_MaterialParams) { \
.tint = Color_White, \
.clip = AllClipped, \
__VA_ARGS__ \
})
////////////////////////////////////////////////////////////
//~ Ui types
Struct(D_UiRectParams)
{
Xform xf;
GPU_Resource *texture;
ClipRect clip;
u32 tint;
};
#define D_UIRECTPARAMS(...) ((D_UiRectParams) { \
.tint = Color_White, \
.clip = AllClipped, \
__VA_ARGS__ \
})
////////////////////////////////////////////////////////////
//~ Text types
/* How is text aligned within its area */
Enum(D_TextAlignment)
{
DRAW_TEXT_ALIGNMENT_LEFT, /* Default */
DRAW_TEXT_ALIGNMENT_CENTER,
DRAW_TEXT_ALIGNMENT_RIGHT
};
/* How does the specified text position relate to the text area.
* E.g. BOTTOM & RIGHT means the bottom-right of the text area will snap to
* the specified position. */
Enum(D_TextOffsetX)
{
DRAW_TEXT_OFFSET_X_LEFT, /* Default */
DRAW_TEXT_OFFSET_X_CENTER,
DRAW_TEXT_OFFSET_X_RIGHT
};
Enum(D_TextOffsetY)
{
DRAW_TEXT_OFFSET_Y_TOP, /* Default */
DRAW_TEXT_OFFSET_Y_CENTER,
DRAW_TEXT_OFFSET_Y_BOTTOM
};
Struct(D_TextGlyph)
{
f32 off_x;
f32 off_y;
f32 width;
f32 height;
f32 advance;
ClipRect clip;
};
Struct(D_TextLine)
{
f32 line_width;
u32 num_glyphs;
D_TextGlyph *glyphs;
D_TextLine *next;
};
Struct(D_TextParams)
{
F_Font *font;
Vec2 pos;
f32 scale;
u32 color;
D_TextAlignment alignment;
D_TextOffsetX offset_x;
D_TextOffsetY offset_y;
String str;
};
#define D_TEXTPARAMS(...) ((D_TextParams) { \
.scale = 1.0, \
.alignment = DRAW_TEXT_ALIGNMENT_LEFT, \
.offset_x = DRAW_TEXT_OFFSET_X_LEFT, \
.offset_y = DRAW_TEXT_OFFSET_Y_TOP, \
.color = Color_White, \
__VA_ARGS__ \
})
////////////////////////////////////////////////////////////
//~ State types
Struct(D_SharedState)
{
GPU_Resource *solid_white_texture;
} extern D_shared_state;
////////////////////////////////////////////////////////////
//~ Bootstrap
void D_Bootstrap(void);
////////////////////////////////////////////////////////////
//~ Material
void D_DrawMaterial(GPU_RenderSig *sig, D_MaterialParams params);
////////////////////////////////////////////////////////////
//~ Solid shape
void D_DrawPolyEx(GPU_RenderSig *sig, Vec2Array vertices, GPU_Indices indices, u32 color);
void D_DrawPoly(GPU_RenderSig *sig, Vec2Array points, u32 color);
void D_DrawCircle(GPU_RenderSig *sig, Vec2 pos, f32 radius, u32 color, u32 detail);
void D_DrawQuad(GPU_RenderSig *sig, Quad quad, u32 color);
////////////////////////////////////////////////////////////
//~ Line shape
void D_DrawLineGradient(GPU_RenderSig *sig, Vec2 start, Vec2 end, f32 thickness, u32 start_color, u32 end_color);
void D_DrawLine(GPU_RenderSig *sig, Vec2 start, Vec2 end, f32 thickness, u32 color);
void D_DrawRay(GPU_RenderSig *sig, Vec2 pos, Vec2 rel, f32 thickness, u32 color);
void D_DrawPolyLine(GPU_RenderSig *sig, Vec2Array points, b32 loop, f32 thickness, u32 color);
void D_DrawCircleLine(GPU_RenderSig *sig, Vec2 pos, f32 radius, f32 thickness, u32 color, u32 detail);
void D_DrawQuadLine(GPU_RenderSig *sig, Quad quad, f32 thickness, u32 color);
void D_DrawArrowLine(GPU_RenderSig *sig, Vec2 start, Vec2 end, f32 thickness, f32 arrowhead_height, u32 color);
void D_DrawArrowRay(GPU_RenderSig *sig, Vec2 pos, Vec2 rel, f32 thickness, f32 arrowhead_height, u32 color);
void D_DrawColliderLine(GPU_RenderSig *sig, CLD_Shape shape, Xform shape_xf, f32 thickness, u32 color, u32 detail);
////////////////////////////////////////////////////////////
//~ Grid
void D_DrawGrid(GPU_RenderSig *sig, Xform xf, u32 bg0_color, u32 bg1_color, u32 line_color, u32 x_color, u32 y_color, f32 thickness, f32 spacing, Vec2 offset);
////////////////////////////////////////////////////////////
//~ Ui
void D_DrawUiRect(GPU_RenderSig *sig, D_UiRectParams params);
////////////////////////////////////////////////////////////
//~ Text
Rect draw_text(GPU_RenderSig *sig, D_TextParams params);