132 lines
3.2 KiB
C
132 lines
3.2 KiB
C
#ifndef GP_H
|
|
#define GP_H
|
|
|
|
struct sys_window;
|
|
|
|
/* ========================== *
|
|
* Startup
|
|
* ========================== */
|
|
|
|
struct gp_startup_receipt { i32 _; };
|
|
struct gp_startup_receipt gp_startup(void);
|
|
|
|
/* ========================== *
|
|
* Resource
|
|
* ========================== */
|
|
|
|
struct gp_resource;
|
|
|
|
/* NOTE: Internally, the layer will make sure to not release any resources
|
|
* until after the GPU finishes using them. However, it is up to the caller
|
|
* to make sure the released resources aren't then referenced in any flow
|
|
* dispatches. */
|
|
void gp_resource_release(struct gp_resource *resource);
|
|
|
|
/* ========================== *
|
|
* Texture
|
|
* ========================== */
|
|
|
|
enum gp_texture_format {
|
|
GP_TEXTURE_FORMAT_NONE,
|
|
GP_TEXTURE_FORMAT_R8G8B8A8_UNORM,
|
|
GP_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB,
|
|
|
|
NUM_GP_TEXTURE_FORMATS
|
|
};
|
|
|
|
enum gp_texture_flag {
|
|
GP_TEXTURE_FLAG_NONE = (0),
|
|
GP_TEXTURE_FLAG_TARGETABLE = (1 << 0)
|
|
};
|
|
|
|
struct gp_resource *gp_texture_alloc(enum gp_texture_format format, u32 flags, struct v2i32 size, void *initial_data);
|
|
|
|
struct v2i32 gp_texture_get_size(struct gp_resource *texture);
|
|
|
|
/* ========================== *
|
|
* Flow
|
|
* ========================== */
|
|
|
|
enum gp_cmd_kind {
|
|
GP_CMD_KIND_NONE,
|
|
GP_CMD_KIND_DRAW_SHAPE,
|
|
GP_CMD_KIND_DRAW_MATERIAL,
|
|
GP_CMD_KIND_PUSH_GRID,
|
|
|
|
NUM_GP_CMD_KINDS
|
|
};
|
|
|
|
struct gp_indices {
|
|
u32 count;
|
|
u32 *indices;
|
|
};
|
|
|
|
struct gp_cmd_desc {
|
|
enum gp_cmd_kind kind;
|
|
union {
|
|
struct {
|
|
struct xform xf;
|
|
struct sprite_tag sprite;
|
|
struct gp_resource *texture;
|
|
struct clip_rect clip;
|
|
u32 tint;
|
|
f32 emittance;
|
|
i32 grid_cmd_id;
|
|
} material;
|
|
struct {
|
|
struct v2_array vertices;
|
|
struct gp_indices indices;
|
|
u32 color;
|
|
} shape;
|
|
struct {
|
|
f32 line_thickness;
|
|
f32 line_spacing;
|
|
struct v2 offset;
|
|
u32 bg0_color;
|
|
u32 bg1_color;
|
|
u32 line_color;
|
|
u32 x_color;
|
|
u32 y_color;
|
|
} grid;
|
|
};
|
|
};
|
|
|
|
struct gp_dispatch_params {
|
|
struct gp_flow *flow;
|
|
struct gp_resource *draw_target;
|
|
struct rect draw_target_viewport;
|
|
struct xform draw_target_view;
|
|
b32 clear_target;
|
|
};
|
|
|
|
struct gp_flow *gp_flow_alloc(void);
|
|
|
|
/* Returns a cmd id internal to the flow */
|
|
i32 gp_push_cmd(struct gp_flow *gp_flow, struct gp_cmd_desc *desc);
|
|
|
|
void gp_dispatch(struct gp_dispatch_params params);
|
|
|
|
/* ========================== *
|
|
* Memory info
|
|
* ========================== */
|
|
|
|
struct gp_memory_info {
|
|
u64 local_used;
|
|
u64 local_budget;
|
|
u64 non_local_used;
|
|
u64 non_local_budget;
|
|
};
|
|
|
|
struct gp_memory_info gp_query_memory_info(void);
|
|
|
|
/* ========================== *
|
|
* Present
|
|
* ========================== */
|
|
|
|
/* 1. Clears the backbuffer and ensures it's at size `backbuffer_resolution`
|
|
* 2. Blits `texture` to the backbuffer using `texture_xf` (applied to centered unit square)
|
|
* 3. Presents the backbuffer */
|
|
void gp_present(struct sys_window *window, struct v2i32 backbuffer_resolution, struct gp_resource *texture, struct xform texture_xf, i32 vsync);
|
|
|
|
#endif
|