#ifndef GP_H #define GP_H struct sys_window; struct work_startup_receipt; /* ========================== * * Startup * ========================== */ struct gp_startup_receipt { i32 _; }; struct gp_startup_receipt gp_startup(struct work_startup_receipt *work_sr); /* ========================== * * Handle * ========================== */ struct gp_handle { union { /* dx11 style */ u64 v; /* dx12 style */ struct { u64 gen; u64 idx; }; }; }; struct gp_handle_array { u64 count; struct gp_handle **handles; }; /* 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 referenced in any flows before * dispatching. */ void gp_release(struct gp_handle handle); /* ========================== * * 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_handle gp_texture_alloc(enum gp_texture_format format, u32 flags, struct v2i32 size, void *initial_data); void gp_texture_clear(struct gp_handle target_texture, u32 clear_color); struct v2i32 gp_texture_get_size(struct gp_handle texture); /* ========================== * * Flow * ========================== */ struct gp_indices { u32 count; u32 *indices; }; enum gp_cmd_kind { GP_CMD_KIND_NONE, GP_CMD_KIND_DRAW_MESH, GP_CMD_KIND_DRAW_TEXTURE, GP_CMD_KIND_DRAW_GRID, GP_CMD_KIND_TEST, NUM_GP_CMD_KINDS }; struct gp_cmd_params { enum gp_cmd_kind kind; union { struct { struct v2_array vertices; struct gp_indices indices; u32 color; } mesh; struct { struct xform xf; struct sprite_tag sprite; struct gp_handle texture; struct clip_rect clip; u32 tint; f32 emittance; } texture; struct { struct xform xf; 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 { struct xform xf; } test; }; }; struct gp_dispatch_params { struct gp_handle flow; struct gp_handle draw_target; struct rect draw_target_viewport; struct xform draw_target_view; b32 clear_target; }; struct gp_handle gp_flow_alloc(void); void gp_push_cmd(struct gp_handle gp_flow, struct gp_cmd_params params); void gp_dispatch(struct gp_dispatch_params params); /* ========================== * * Present * ========================== */ /* 1. Clears the backbuffer and ensures its 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_handle texture, struct xform texture_xf, i32 vsync); #endif