power_play/src/gp/gp_core.h
2025-07-30 17:31:14 -05:00

165 lines
3.7 KiB
C

////////////////////////////////
//~ Opaque types
Struct(G_Resource);
Struct(G_RenderSig);
Struct(G_Swapchain);
////////////////////////////////
//~ Render
Struct(G_Indices)
{
u32 count;
u32 *indices;
};
typedef i32 G_RenderCmdKind; enum
{
GP_RENDER_CMD_KIND_NONE,
GP_RENDER_CMD_KIND_DRAW_MATERIAL,
GP_RENDER_CMD_KIND_DRAW_UI_RECT,
GP_RENDER_CMD_KIND_DRAW_UI_SHAPE,
GP_RENDER_CMD_KIND_PUSH_GRID,
NUM_GP_RENDER_CMD_KINDS
};
Struct(G_RenderCmdDesc)
{
G_RenderCmdKind kind;
union
{
struct
{
Xform xf;
G_Resource *texture;
ClipRect clip;
u32 tint;
b32 is_light;
Vec3 light_emittance;
u32 grid_cmd_id;
} material;
struct
{
Xform xf;
G_Resource *texture;
ClipRect clip;
u32 tint;
} ui_rect;
struct
{
Vec2Array vertices;
G_Indices indices;
u32 color;
} ui_shape;
struct
{
f32 line_thickness;
f32 line_spacing;
Vec2 offset;
u32 bg0_color;
u32 bg1_color;
u32 line_color;
u32 x_color;
u32 y_color;
} grid;
};
};
Struct(G_RenderParams)
{
Vec2I32 ui_size;
Vec2I32 render_size;
Xform world_to_render_xf;
Xform render_to_ui_xf;
b32 effects_disabled;
};
////////////////////////////////
//~ Texture
typedef i32 G_TextureFormat; enum
{
GP_TEXTURE_FORMAT_NONE,
GP_TEXTURE_FORMAT_R8_UNORM,
GP_TEXTURE_FORMAT_R8G8B8A8_UNORM,
GP_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB,
GP_TEXTURE_FORMAT_R16G16B16A16_FLOAT,
NUM_GP_TEXTURE_FORMATS
};
typedef i32 G_TextureFlag; enum
{
GP_TEXTURE_FLAG_NONE = (0),
GP_TEXTURE_FLAG_TARGETABLE = (1 << 0)
};
////////////////////////////////
//~ Memory info
Struct(G_MemoryInfo)
{
u64 local_used;
u64 local_budget;
u64 non_local_used;
u64 non_local_budget;
};
////////////////////////////////
//~ Startup
void gp_startup(void);
////////////////////////////////
//~ Resource operations
/* NOTE: Internally, the layer will make sure to not release any resources
* until after any in-flight GPU runs finish using them. However, it is up to
* the caller to make sure the released resources aren't then referenced in
* any runs
*/
void gp_resource_release(G_Resource *resource);
////////////////////////////////
//~ Texture operations
G_Resource *gp_texture_alloc(G_TextureFormat format, u32 flags, Vec2I32 size, void *initial_data);
Vec2I32 gp_texture_get_size(G_Resource *texture);
////////////////////////////////
//~ Render operations
G_RenderSig *gp_render_sig_alloc(void);
/* Returns a cmd id internal to the sig */
u32 gp_push_render_cmd(G_RenderSig *render_sig, G_RenderCmdDesc *desc);
G_Resource *gp_run_render(G_RenderSig *gp_render_sig, G_RenderParams render_params);
////////////////////////////////
//~ Memory query
G_MemoryInfo gp_query_memory_info(void);
////////////////////////////////
//~ Swapchain
G_Swapchain *gp_swapchain_alloc(P_Window *window, Vec2I32 resolution);
void gp_swapchain_release(G_Swapchain *gp_swapchain);
/* Waits until a new backbuffer is ready to be written to.
* This should be called before rendering for minimum latency. */
void gp_swapchain_wait(G_Swapchain *gp_swapchain);
////////////////////////////////
//~ Present
/* 1. Clears the backbuffer and ensures it's at size `backbuffer_resolution`
* 2. Blits `texture` to the backbuffer using `texture_xf`
* 3. Presents the backbuffer */
void gp_present(G_Swapchain *gp_swapchain, Vec2I32 backbuffer_resolution, G_Resource *texture, Xform texture_xf, i32 vsync);