set draw target xform per-dispatch

This commit is contained in:
jacob 2025-06-17 16:47:21 -05:00
parent 29ec298b48
commit 0c0cfdde08
5 changed files with 73 additions and 110 deletions

View File

@ -24,18 +24,6 @@ struct draw_startup_receipt draw_startup(struct gpu_startup_receipt *gpu_sr,
return (struct draw_startup_receipt) { 0 }; return (struct draw_startup_receipt) { 0 };
} }
/* ========================== *
* View
* ========================== */
void draw_set_view(struct gpu_handle plan, struct xform xf)
{
struct gpu_cmd_params cmd = ZI;
cmd.kind = GPU_CMD_KIND_DRAW_VIEW;
cmd.view.xf = xf;
gpu_push_cmd(plan, cmd);
}
/* ========================== * /* ========================== *
* Texture * Texture
* ========================== */ * ========================== */

View File

@ -10,12 +10,6 @@ struct draw_startup_receipt { i32 _; };
struct draw_startup_receipt draw_startup(struct gpu_startup_receipt *gpu_sr, struct draw_startup_receipt draw_startup(struct gpu_startup_receipt *gpu_sr,
struct font_startup_receipt *font_sr); struct font_startup_receipt *font_sr);
/* ========================== *
* View
* ========================== */
void draw_set_view(struct gpu_handle plan, struct xform xf);
/* ========================== * /* ========================== *
* Texture * Texture
* ========================== */ * ========================== */

View File

@ -68,7 +68,6 @@ struct gpu_indices {
enum gpu_cmd_kind { enum gpu_cmd_kind {
GPU_CMD_KIND_NONE, GPU_CMD_KIND_NONE,
GPU_CMD_KIND_DRAW_VIEW,
GPU_CMD_KIND_DRAW_MESH, GPU_CMD_KIND_DRAW_MESH,
GPU_CMD_KIND_DRAW_TEXTURE, GPU_CMD_KIND_DRAW_TEXTURE,
GPU_CMD_KIND_DRAW_GRID, GPU_CMD_KIND_DRAW_GRID,
@ -80,9 +79,6 @@ enum gpu_cmd_kind {
struct gpu_cmd_params { struct gpu_cmd_params {
enum gpu_cmd_kind kind; enum gpu_cmd_kind kind;
union { union {
struct {
struct xform xf;
} view;
struct { struct {
struct v2_array vertices; struct v2_array vertices;
struct gpu_indices indices; struct gpu_indices indices;
@ -127,6 +123,7 @@ struct gpu_dispatch_params {
struct gpu_handle plan; struct gpu_handle plan;
struct gpu_handle draw_target; struct gpu_handle draw_target;
struct rect draw_target_viewport; struct rect draw_target_viewport;
struct xform draw_target_view;
}; };
struct gpu_handle gpu_dispatch_state_alloc(void); struct gpu_handle gpu_dispatch_state_alloc(void);
@ -137,7 +134,7 @@ void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_para
* Backbuffer * Backbuffer
* ========================== */ * ========================== */
/* Returns a texture representing the internal backbuffer. Lifetime is managed by gpu layer. */ /* Returns a texture representing the internal backbuffer. Lifetime is managed by gpu layer. */
struct gpu_handle gpu_recreate_backbuffer(struct v2i32 size); struct gpu_handle gpu_recreate_backbuffer(struct v2i32 size);
/* Presents the backbuffer to the screen */ /* Presents the backbuffer to the screen */

View File

@ -1376,19 +1376,6 @@ void gpu_push_cmd(struct gpu_handle gpu_plan, struct gpu_cmd_params params)
ASSERT(false); ASSERT(false);
} break; } break;
case GPU_CMD_KIND_DRAW_VIEW:
{
struct dx11_cmd *cmd = arena_push(&plan->cpu_cmds_arena, struct dx11_cmd);
cmd->kind = params.kind;
cmd->view.xf = params.view.xf;
if (plan->cpu_last_cmd) {
plan->cpu_last_cmd->next = cmd;
} else {
plan->cpu_first_cmd = cmd;
}
plan->cpu_last_cmd = cmd;
} break;
case GPU_CMD_KIND_DRAW_MESH: case GPU_CMD_KIND_DRAW_MESH:
{ {
struct dx11_cmd *cmd = plan->cpu_last_cmd; struct dx11_cmd *cmd = plan->cpu_last_cmd;
@ -1699,7 +1686,7 @@ void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_para
} }
/* Regular pass */ /* Regular pass */
struct mat4x4 vp_matrix = calculate_vp(XFORM_IDENT, viewport.width, viewport.height); struct mat4x4 vp_matrix = calculate_vp(params.draw_target_view, viewport.width, viewport.height);
{ {
__profscope(Regular pass); __profscope(Regular pass);
__profscope_dx11(G.profiling_ctx, Regular pass, RGB32_F(0.2, 0.5, 0.5)); __profscope_dx11(G.profiling_ctx, Regular pass, RGB32_F(0.2, 0.5, 0.5));
@ -1713,12 +1700,6 @@ void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_para
ASSERT(false); ASSERT(false);
} break; } break;
case GPU_CMD_KIND_DRAW_VIEW:
{
__profscope(Set draw view);
vp_matrix = calculate_vp(cmd->view.xf, viewport.width, viewport.height);
} break;
case GPU_CMD_KIND_DRAW_MESH: case GPU_CMD_KIND_DRAW_MESH:
{ {
__profscope(Draw mesh); __profscope(Draw mesh);

View File

@ -75,7 +75,7 @@ GLOBAL struct {
struct gpu_handle backbuffer_texture; struct gpu_handle backbuffer_texture;
struct gpu_handle world_gpu_plan; struct gpu_handle world_gpu_plan;
struct gpu_handle user_gpu_plan; struct gpu_handle ui_gpu_plan;
struct gpu_handle backbuffer_gpu_plan; struct gpu_handle backbuffer_gpu_plan;
struct gpu_handle user_dispatch_state; struct gpu_handle user_dispatch_state;
@ -259,7 +259,7 @@ struct user_startup_receipt user_startup(struct work_startup_receipt *work_sr,
/* GPU handles */ /* GPU handles */
G.world_to_user_xf = XFORM_IDENT; G.world_to_user_xf = XFORM_IDENT;
G.world_gpu_plan = gpu_plan_alloc(); G.world_gpu_plan = gpu_plan_alloc();
G.user_gpu_plan = gpu_plan_alloc(); G.ui_gpu_plan = gpu_plan_alloc();
G.backbuffer_gpu_plan = gpu_plan_alloc(); G.backbuffer_gpu_plan = gpu_plan_alloc();
G.user_dispatch_state = gpu_dispatch_state_alloc(); G.user_dispatch_state = gpu_dispatch_state_alloc();
G.backbuffer_dispatch_state = gpu_dispatch_state_alloc(); G.backbuffer_dispatch_state = gpu_dispatch_state_alloc();
@ -349,13 +349,13 @@ INTERNAL void debug_draw_xform(struct xform xf, u32 color_x, u32 color_y)
x_ray = v2_mul(x_ray, ray_scale); x_ray = v2_mul(x_ray, ray_scale);
y_ray = v2_mul(y_ray, ray_scale); y_ray = v2_mul(y_ray, ray_scale);
draw_arrow_ray(G.user_gpu_plan, pos, x_ray, thickness, arrowhead_len, color_x); draw_arrow_ray(G.ui_gpu_plan, pos, x_ray, thickness, arrowhead_len, color_x);
draw_arrow_ray(G.user_gpu_plan, pos, y_ray, thickness, arrowhead_len, color_y); draw_arrow_ray(G.ui_gpu_plan, pos, y_ray, thickness, arrowhead_len, color_y);
//u32 color_quad = RGBA32_F(0, 1, 1, 0.3); //u32 color_quad = RGBA32_F(0, 1, 1, 0.3);
//struct quad quad = quad_from_rect(RECT(0, 0, 1, -1)); //struct quad quad = quad_from_rect(RECT(0, 0, 1, -1));
//quad = xform_mul_quad(xf, quad_scale(quad, 0.075f)); //quad = xform_mul_quad(xf, quad_scale(quad, 0.075f));
//draw_quad(G.user_gpu_plan, quad, color); //draw_quad(G.ui_gpu_plan, quad, color);
} }
INTERNAL void debug_draw_movement(struct sim_ent *ent) INTERNAL void debug_draw_movement(struct sim_ent *ent)
@ -372,7 +372,7 @@ INTERNAL void debug_draw_movement(struct sim_ent *ent)
struct v2 vel_ray = xform_basis_mul_v2(G.world_to_user_xf, velocity); struct v2 vel_ray = xform_basis_mul_v2(G.world_to_user_xf, velocity);
if (v2_len(vel_ray) > 0.00001) { if (v2_len(vel_ray) > 0.00001) {
draw_arrow_ray(G.user_gpu_plan, pos, vel_ray, thickness, arrow_len, color_vel); draw_arrow_ray(G.ui_gpu_plan, pos, vel_ray, thickness, arrow_len, color_vel);
} }
} }
@ -542,7 +542,7 @@ INTERNAL void draw_debug_console(i32 level, b32 minimized)
if (log->level <= level) { if (log->level <= level) {
/* Draw background */ /* Draw background */
u32 color = colors[log->level][log->color_index]; u32 color = colors[log->level][log->color_index];
draw_quad(G.user_gpu_plan, quad_from_rect(log->bounds), ALPHA32_F(color, opacity)); draw_quad(G.ui_gpu_plan, quad_from_rect(log->bounds), ALPHA32_F(color, opacity));
/* Draw text */ /* Draw text */
struct string text = log->msg; struct string text = log->msg;
@ -559,7 +559,7 @@ INTERNAL void draw_debug_console(i32 level, b32 minimized)
} }
struct draw_text_params params = DRAW_TEXT_PARAMS(.font = font, .pos = draw_pos, .offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM, .color = ALPHA32_F(COLOR_WHITE, opacity), .str = text); struct draw_text_params params = DRAW_TEXT_PARAMS(.font = font, .pos = draw_pos, .offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM, .color = ALPHA32_F(COLOR_WHITE, opacity), .str = text);
struct rect bounds = draw_text(G.user_gpu_plan, params); struct rect bounds = draw_text(G.ui_gpu_plan, params);
struct rect draw_bounds = bounds; struct rect draw_bounds = bounds;
draw_bounds.x -= bg_margin; draw_bounds.x -= bg_margin;
@ -1033,13 +1033,6 @@ INTERNAL void user_update(void)
} }
G.world_cursor = xform_invert_mul_v2(G.world_to_user_xf, G.user_cursor); G.world_cursor = xform_invert_mul_v2(G.world_to_user_xf, G.user_cursor);
/* ========================== *
* Set draw views
* ========================== */
draw_set_view(G.world_gpu_plan, G.world_to_user_xf);
draw_set_view(G.user_gpu_plan, XFORM_IDENT);
/* ========================== * /* ========================== *
* Update listener from view * Update listener from view
* ========================== */ * ========================== */
@ -1329,7 +1322,7 @@ INTERNAL void user_update(void)
u32 color = RGBA32_F(1, 0, 1, 0.5); u32 color = RGBA32_F(1, 0, 1, 0.5);
struct quad quad = quad_from_aabb(aabb); struct quad quad = quad_from_aabb(aabb);
quad = xform_mul_quad(G.world_to_user_xf, quad); quad = xform_mul_quad(G.world_to_user_xf, quad);
draw_quad_line(G.user_gpu_plan, quad, thickness, color); draw_quad_line(G.ui_gpu_plan, quad, thickness, color);
} }
/* Draw focus arrow */ /* Draw focus arrow */
@ -1340,7 +1333,7 @@ INTERNAL void user_update(void)
start = xform_mul_v2(G.world_to_user_xf, start); start = xform_mul_v2(G.world_to_user_xf, start);
struct v2 end = v2_add(xf.og, ent->control.focus); struct v2 end = v2_add(xf.og, ent->control.focus);
end = xform_mul_v2(G.world_to_user_xf, end); end = xform_mul_v2(G.world_to_user_xf, end);
draw_arrow_line(G.user_gpu_plan, start, end, 3, 10, RGBA32_F(1, 1, 1, 0.5)); draw_arrow_line(G.ui_gpu_plan, start, end, 3, 10, RGBA32_F(1, 1, 1, 0.5));
} }
#if 0 #if 0
@ -1366,16 +1359,16 @@ INTERNAL void user_update(void)
struct quad quad = quad_from_rect(slice.rect); struct quad quad = quad_from_rect(slice.rect);
quad = xform_mul_quad(sprite_xform, quad); quad = xform_mul_quad(sprite_xform, quad);
quad = xform_mul_quad(G.world_to_user_xf, quad); quad = xform_mul_quad(G.world_to_user_xf, quad);
draw_quad_line(G.user_gpu_plan, quad, 2, quad_color); draw_quad_line(G.ui_gpu_plan, quad, 2, quad_color);
} }
draw_circle(G.user_gpu_plan, center, 3, point_color, 20); draw_circle(G.ui_gpu_plan, center, 3, point_color, 20);
if (slice.has_ray) { if (slice.has_ray) {
struct v2 ray = xform_basis_mul_v2(sprite_xform, slice.dir); struct v2 ray = xform_basis_mul_v2(sprite_xform, slice.dir);
ray = xform_basis_mul_v2(G.world_to_user_xf, ray); ray = xform_basis_mul_v2(G.world_to_user_xf, ray);
ray = v2_with_len(ray, 25); ray = v2_with_len(ray, 25);
draw_arrow_ray(G.user_gpu_plan, center, ray, 2, 10, ray_color); draw_arrow_ray(G.ui_gpu_plan, center, ray, 2, 10, ray_color);
} }
} }
} }
@ -1392,7 +1385,7 @@ INTERNAL void user_update(void)
f32 radius = 3; f32 radius = 3;
struct v2 point = xform_mul_v2(e1_xf, ent->weld_joint_data.point_local_e1); struct v2 point = xform_mul_v2(e1_xf, ent->weld_joint_data.point_local_e1);
point = xform_mul_v2(G.world_to_user_xf, point); point = xform_mul_v2(G.world_to_user_xf, point);
draw_circle(G.user_gpu_plan, point, radius, color, 10); draw_circle(G.ui_gpu_plan, point, radius, color, 10);
DEBUGBREAKABLE; DEBUGBREAKABLE;
} }
@ -1407,8 +1400,8 @@ INTERNAL void user_update(void)
struct v2 point_end = G.world_cursor; struct v2 point_end = G.world_cursor;
point_start = xform_mul_v2(G.world_to_user_xf, point_start); point_start = xform_mul_v2(G.world_to_user_xf, point_start);
point_end = xform_mul_v2(G.world_to_user_xf, point_end); point_end = xform_mul_v2(G.world_to_user_xf, point_end);
draw_arrow_line(G.user_gpu_plan, point_start, point_end, 3, 10, color); draw_arrow_line(G.ui_gpu_plan, point_start, point_end, 3, 10, color);
draw_circle(G.user_gpu_plan, point_start, 4, color, 10); draw_circle(G.ui_gpu_plan, point_start, 4, color, 10);
} }
/* Draw collider */ /* Draw collider */
@ -1420,13 +1413,13 @@ INTERNAL void user_update(void)
/* Draw collider using support points */ /* Draw collider using support points */
u32 detail = 32; u32 detail = 32;
struct xform collider_draw_xf = xform_mul(G.world_to_user_xf, xf); struct xform collider_draw_xf = xform_mul(G.world_to_user_xf, xf);
draw_collider_line(G.user_gpu_plan, collider, collider_draw_xf, thickness, color, detail); draw_collider_line(G.ui_gpu_plan, collider, collider_draw_xf, thickness, color, detail);
} }
{ {
/* Draw collider shape points */ /* Draw collider shape points */
for (u32 i = 0; i < collider.count; ++i) { for (u32 i = 0; i < collider.count; ++i) {
struct v2 p = xform_mul_v2(xform_mul(G.world_to_user_xf, xf), collider.points[i]); struct v2 p = xform_mul_v2(xform_mul(G.world_to_user_xf, xf), collider.points[i]);
draw_circle(G.user_gpu_plan, p, 3, COLOR_BLUE, 10); draw_circle(G.ui_gpu_plan, p, 3, COLOR_BLUE, 10);
} }
} }
if (collider.count == 1 && collider.radius > 0) { if (collider.count == 1 && collider.radius > 0) {
@ -1435,14 +1428,14 @@ INTERNAL void user_update(void)
struct v2 end = collider_get_support_point(&collider, xf, v2_neg(xf.by)).p; struct v2 end = collider_get_support_point(&collider, xf, v2_neg(xf.by)).p;
start = xform_mul_v2(G.world_to_user_xf, start); start = xform_mul_v2(G.world_to_user_xf, start);
end = xform_mul_v2(G.world_to_user_xf, end); end = xform_mul_v2(G.world_to_user_xf, end);
draw_line(G.user_gpu_plan, start, end, thickness, color); draw_line(G.ui_gpu_plan, start, end, thickness, color);
} }
#if 0 #if 0
/* Draw support point at focus dir */ /* Draw support point at focus dir */
{ {
struct v2 p = collider_support_point(&collider, xf, ent->control.focus); struct v2 p = collider_support_point(&collider, xf, ent->control.focus);
p = xform_mul_v2(G.world_to_user_xf, p); p = xform_mul_v2(G.world_to_user_xf, p);
draw_circle(G.user_gpu_plan, p, 3, COLOR_RED, 10); draw_circle(G.ui_gpu_plan, p, 3, COLOR_RED, 10);
} }
#endif #endif
} }
@ -1466,7 +1459,7 @@ INTERNAL void user_update(void)
/* Draw point */ /* Draw point */
{ {
draw_circle(G.user_gpu_plan, xform_mul_v2(G.world_to_user_xf, dbg_pt), radius, color, 10); draw_circle(G.ui_gpu_plan, xform_mul_v2(G.world_to_user_xf, dbg_pt), radius, color, 10);
} }
/* Draw normal */ /* Draw normal */
@ -1476,7 +1469,7 @@ INTERNAL void user_update(void)
f32 arrow_height = 5; f32 arrow_height = 5;
struct v2 start = xform_mul_v2(G.world_to_user_xf, dbg_pt); struct v2 start = xform_mul_v2(G.world_to_user_xf, dbg_pt);
struct v2 end = xform_mul_v2(G.world_to_user_xf, v2_add(dbg_pt, v2_mul(v2_norm(data->normal), len))); struct v2 end = xform_mul_v2(G.world_to_user_xf, v2_add(dbg_pt, v2_mul(v2_norm(data->normal), len)));
draw_arrow_line(G.user_gpu_plan, start, end, arrow_thickness, arrow_height, color); draw_arrow_line(G.ui_gpu_plan, start, end, arrow_thickness, arrow_height, color);
} }
#if 0 #if 0
/* Draw contact info */ /* Draw contact info */
@ -1506,7 +1499,7 @@ INTERNAL void user_update(void)
FMT_UINT(data->num_points)); FMT_UINT(data->num_points));
draw_text(G.user_gpu_plan, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, dbg_pt)), V2(0, offset_px)), text); draw_text(G.ui_gpu_plan, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, dbg_pt)), V2(0, offset_px)), text);
} }
} }
#endif #endif
@ -1534,8 +1527,8 @@ INTERNAL void user_update(void)
u32 color = RGBA32_F(1, 1, 0, 0.5); u32 color = RGBA32_F(1, 1, 0, 0.5);
struct v2 a = xform_mul_v2(G.world_to_user_xf, data->closest0); struct v2 a = xform_mul_v2(G.world_to_user_xf, data->closest0);
struct v2 b = xform_mul_v2(G.world_to_user_xf, data->closest1); struct v2 b = xform_mul_v2(G.world_to_user_xf, data->closest1);
draw_circle(G.user_gpu_plan, a, radius, color, 10); draw_circle(G.ui_gpu_plan, a, radius, color, 10);
draw_circle(G.user_gpu_plan, b, radius, color, 10); draw_circle(G.ui_gpu_plan, b, radius, color, 10);
} }
#endif #endif
@ -1552,28 +1545,28 @@ INTERNAL void user_update(void)
{ {
struct v2 a = xform_mul_v2(G.world_to_user_xf, collider_res.a0); struct v2 a = xform_mul_v2(G.world_to_user_xf, collider_res.a0);
struct v2 b = xform_mul_v2(G.world_to_user_xf, collider_res.b0); struct v2 b = xform_mul_v2(G.world_to_user_xf, collider_res.b0);
draw_line(G.user_gpu_plan, a, b, thickness, color_line); draw_line(G.ui_gpu_plan, a, b, thickness, color_line);
draw_circle(G.user_gpu_plan, a, radius, color_a, 10); draw_circle(G.ui_gpu_plan, a, radius, color_a, 10);
draw_circle(G.user_gpu_plan, b, radius, color_b, 10); draw_circle(G.ui_gpu_plan, b, radius, color_b, 10);
struct v2 a_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.a0_clipped); struct v2 a_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.a0_clipped);
struct v2 b_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.b0_clipped); struct v2 b_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.b0_clipped);
draw_line(G.user_gpu_plan, a_clipped, b_clipped, thickness, color_line_clipped); draw_line(G.ui_gpu_plan, a_clipped, b_clipped, thickness, color_line_clipped);
draw_circle(G.user_gpu_plan, a_clipped, radius, color_a_clipped, 10); draw_circle(G.ui_gpu_plan, a_clipped, radius, color_a_clipped, 10);
draw_circle(G.user_gpu_plan, b_clipped, radius, color_b_clipped, 10); draw_circle(G.ui_gpu_plan, b_clipped, radius, color_b_clipped, 10);
} }
{ {
struct v2 a = xform_mul_v2(G.world_to_user_xf, collider_res.a1); struct v2 a = xform_mul_v2(G.world_to_user_xf, collider_res.a1);
struct v2 b = xform_mul_v2(G.world_to_user_xf, collider_res.b1); struct v2 b = xform_mul_v2(G.world_to_user_xf, collider_res.b1);
draw_line(G.user_gpu_plan, a, b, thickness, color_line); draw_line(G.ui_gpu_plan, a, b, thickness, color_line);
draw_circle(G.user_gpu_plan, a, radius, color_a, 10); draw_circle(G.ui_gpu_plan, a, radius, color_a, 10);
draw_circle(G.user_gpu_plan, b, radius, color_b, 10); draw_circle(G.ui_gpu_plan, b, radius, color_b, 10);
struct v2 a_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.a1_clipped); struct v2 a_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.a1_clipped);
struct v2 b_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.b1_clipped); struct v2 b_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.b1_clipped);
draw_line(G.user_gpu_plan, a_clipped, b_clipped, thickness, color_line_clipped); draw_line(G.ui_gpu_plan, a_clipped, b_clipped, thickness, color_line_clipped);
draw_circle(G.user_gpu_plan, a_clipped, radius, color_a_clipped, 10); draw_circle(G.ui_gpu_plan, a_clipped, radius, color_a_clipped, 10);
draw_circle(G.user_gpu_plan, b_clipped, radius, color_b_clipped, 10); draw_circle(G.ui_gpu_plan, b_clipped, radius, color_b_clipped, 10);
} }
} }
@ -1614,7 +1607,7 @@ INTERNAL void user_update(void)
FMT_FLOAT_P(xform_get_rotation(e1_xf), 24)); FMT_FLOAT_P(xform_get_rotation(e1_xf), 24));
draw_text(G.user_gpu_plan, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, V2(0, 0))), V2(0, offset_px)), text); draw_text(G.ui_gpu_plan, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, V2(0, 0))), V2(0, offset_px)), text);
} }
} }
#endif #endif
@ -1630,8 +1623,8 @@ INTERNAL void user_update(void)
struct v2_array m = menkowski(temp.arena, &e0_collider, &e1_collider, e0_xf, e1_xf, detail); struct v2_array m = menkowski(temp.arena, &e0_collider, &e1_collider, e0_xf, e1_xf, detail);
for (u64 i = 0; i < m.count; ++i) m.points[i] = xform_mul_v2(G.world_to_user_xf, m.points[i]); for (u64 i = 0; i < m.count; ++i) m.points[i] = xform_mul_v2(G.world_to_user_xf, m.points[i]);
draw_poly_line(G.user_gpu_plan, m, true, thickness, color); draw_poly_line(G.ui_gpu_plan, m, true, thickness, color);
//draw_poly(G.user_gpu_plan, m, color); //draw_poly(G.ui_gpu_plan, m, color);
} }
/* Draw cloud */ /* Draw cloud */
@ -1643,7 +1636,7 @@ INTERNAL void user_update(void)
for (u64 i = 0; i < m.count; ++i) { for (u64 i = 0; i < m.count; ++i) {
struct v2 p = xform_mul_v2(G.world_to_user_xf, m.points[i]); struct v2 p = xform_mul_v2(G.world_to_user_xf, m.points[i]);
draw_circle(G.user_gpu_plan, p, radius, color, 10); draw_circle(G.ui_gpu_plan, p, radius, color, 10);
} }
} }
@ -1657,8 +1650,8 @@ INTERNAL void user_update(void)
.count = collider_res.prototype.len .count = collider_res.prototype.len
}; };
for (u64 i = 0; i < m.count; ++i) m.points[i] = xform_mul_v2(G.world_to_user_xf, m.points[i]); for (u64 i = 0; i < m.count; ++i) m.points[i] = xform_mul_v2(G.world_to_user_xf, m.points[i]);
draw_poly_line(G.user_gpu_plan, m, true, thickness, color); draw_poly_line(G.ui_gpu_plan, m, true, thickness, color);
for (u64 i = 0; i < m.count; ++i) draw_circle(G.user_gpu_plan, m.points[i], 10, color, 10); for (u64 i = 0; i < m.count; ++i) draw_circle(G.ui_gpu_plan, m.points[i], 10, color, 10);
} }
/* Draw simplex */ /* Draw simplex */
@ -1676,18 +1669,18 @@ INTERNAL void user_update(void)
if (simplex.len >= 1) { if (simplex.len >= 1) {
u32 color = simplex.len == 1 ? color_first : (simplex.len == 2 ? color_second : color_third); u32 color = simplex.len == 1 ? color_first : (simplex.len == 2 ? color_second : color_third);
draw_circle(G.user_gpu_plan, simplex_array.points[0], thickness * 3, color, 10); draw_circle(G.ui_gpu_plan, simplex_array.points[0], thickness * 3, color, 10);
} }
if (simplex.len >= 2) { if (simplex.len >= 2) {
u32 color = simplex.len == 2 ? color_first : color_second; u32 color = simplex.len == 2 ? color_first : color_second;
draw_circle(G.user_gpu_plan, simplex_array.points[1], thickness * 3, color, 10); draw_circle(G.ui_gpu_plan, simplex_array.points[1], thickness * 3, color, 10);
} }
if (simplex.len >= 3) { if (simplex.len >= 3) {
u32 color = color_first; u32 color = color_first;
draw_circle(G.user_gpu_plan, simplex_array.points[2], thickness * 3, color, 10); draw_circle(G.ui_gpu_plan, simplex_array.points[2], thickness * 3, color, 10);
} }
if (simplex.len >= 2) { if (simplex.len >= 2) {
draw_poly_line(G.user_gpu_plan, simplex_array, simplex.len > 2, thickness, line_color); draw_poly_line(G.ui_gpu_plan, simplex_array, simplex.len > 2, thickness, line_color);
} }
} }
@ -1699,7 +1692,7 @@ INTERNAL void user_update(void)
f32 arrowhead_height = 10; f32 arrowhead_height = 10;
struct v2 start = xform_mul_v2(G.world_to_user_xf, V2(0, 0)); struct v2 start = xform_mul_v2(G.world_to_user_xf, V2(0, 0));
struct v2 end = xform_mul_v2(G.world_to_user_xf, v2_mul(v2_norm(collider_res.normal), len)); struct v2 end = xform_mul_v2(G.world_to_user_xf, v2_mul(v2_norm(collider_res.normal), len));
draw_arrow_line(G.user_gpu_plan, start, end, arrow_thickness, arrowhead_height, color); draw_arrow_line(G.ui_gpu_plan, start, end, arrow_thickness, arrowhead_height, color);
} }
} }
#endif #endif
@ -1714,7 +1707,7 @@ INTERNAL void user_update(void)
struct v2 start = xform_mul_v2(G.world_to_user_xf, xf.og); struct v2 start = xform_mul_v2(G.world_to_user_xf, xf.og);
struct v2 end = xform_mul_v2(G.world_to_user_xf, parent_xf.og); struct v2 end = xform_mul_v2(G.world_to_user_xf, parent_xf.og);
draw_arrow_line(G.user_gpu_plan, start, end, thickness, arrow_height, color); draw_arrow_line(G.ui_gpu_plan, start, end, thickness, arrow_height, color);
} }
/* Draw camera rect */ /* Draw camera rect */
@ -1726,7 +1719,7 @@ INTERNAL void user_update(void)
struct quad quad = xform_mul_quad(quad_xf, QUAD_UNIT_SQUARE_CENTERED); struct quad quad = xform_mul_quad(quad_xf, QUAD_UNIT_SQUARE_CENTERED);
quad = xform_mul_quad(G.world_to_user_xf, quad); quad = xform_mul_quad(G.world_to_user_xf, quad);
draw_quad_line(G.user_gpu_plan, quad, thickness, color); draw_quad_line(G.ui_gpu_plan, quad, thickness, color);
} }
arena_temp_end(temp); arena_temp_end(temp);
@ -1744,7 +1737,7 @@ INTERNAL void user_update(void)
struct v2 size = V2(t->width, t->height); struct v2 size = V2(t->width, t->height);
struct xform xf = XFORM_TRS(.t = crosshair_pos, .s = size); struct xform xf = XFORM_TRS(.t = crosshair_pos, .s = size);
draw_texture(G.user_gpu_plan, DRAW_TEXTURE_PARAMS(.xf = xf, .sprite = crosshair_tag)); draw_texture(G.ui_gpu_plan, DRAW_TEXTURE_PARAMS(.xf = xf, .sprite = crosshair_tag));
struct rect cursor_clip = RECT_FROM_V2(G.user_screen_offset, G.user_size); struct rect cursor_clip = RECT_FROM_V2(G.user_screen_offset, G.user_size);
cursor_clip.pos = v2_add(cursor_clip.pos, v2_mul(size, 0.5f)); cursor_clip.pos = v2_add(cursor_clip.pos, v2_mul(size, 0.5f));
@ -1942,7 +1935,7 @@ INTERNAL void user_update(void)
struct string dbg_text = ZI; struct string dbg_text = ZI;
dbg_text.text = arena_push_dry(temp.arena, u8); dbg_text.text = arena_push_dry(temp.arena, u8);
dbg_text.len += get_ent_debug_text(temp.arena, ent).len; dbg_text.len += get_ent_debug_text(temp.arena, ent).len;
draw_text(G.user_gpu_plan, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = dbg_text)); draw_text(G.ui_gpu_plan, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = dbg_text));
arena_temp_end(temp); arena_temp_end(temp);
} }
@ -2042,16 +2035,16 @@ INTERNAL void user_update(void)
//text.len += string_copy(temp.arena, LIT("\n")).len; //text.len += string_copy(temp.arena, LIT("\n")).len;
#if COLLIDER_DEBUG #if COLLIDER_DEBUG
draw_text(G.user_gpu_plan, font, pos, string_format(temp.arena, LIT("collider gjk steps: %F"), FMT_UINT(collider_debug_steps))); draw_text(G.ui_gpu_plan, font, pos, string_format(temp.arena, LIT("collider gjk steps: %F"), FMT_UINT(collider_debug_steps)));
pos.y += spacing; pos.y += spacing;
#endif #endif
//draw_text(G.user_gpu_plan, font, pos, string_format(temp.arena, LIT("blended world entities: %F/%F"), FMT_UINT(G.ss_blended->num_ents_allocated), FMT_UINT(G.ss_blended->num_ents_reserved))); //draw_text(G.ui_gpu_plan, font, pos, string_format(temp.arena, LIT("blended world entities: %F/%F"), FMT_UINT(G.ss_blended->num_ents_allocated), FMT_UINT(G.ss_blended->num_ents_reserved)));
//draw_text(G.user_gpu_plan, font, pos, text); //draw_text(G.ui_gpu_plan, font, pos, text);
struct v2 pos = V2(10, G.user_size.y); struct v2 pos = V2(10, G.user_size.y);
enum draw_text_offset_y offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM; enum draw_text_offset_y offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM;
draw_text(G.user_gpu_plan, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = COLOR_WHITE)); draw_text(G.ui_gpu_plan, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = COLOR_WHITE));
arena_temp_end(temp); arena_temp_end(temp);
} }
} }
@ -2106,32 +2099,42 @@ INTERNAL void user_update(void)
/* Send plans to GPU */ /* Send plans to GPU */
gpu_submit_plan(G.world_gpu_plan); gpu_submit_plan(G.world_gpu_plan);
gpu_submit_plan(G.user_gpu_plan); gpu_submit_plan(G.ui_gpu_plan);
gpu_submit_plan(G.backbuffer_gpu_plan); gpu_submit_plan(G.backbuffer_gpu_plan);
/* Clear textures */ /* Clear textures */
gpu_texture_clear(G.user_texture, 0); gpu_texture_clear(G.user_texture, 0);
gpu_texture_clear(G.backbuffer_texture, RGBA32_F(0, 0, 0, 1)); gpu_texture_clear(G.backbuffer_texture, RGBA32_F(0, 0, 0, 1));
/* Render to user texture */ /* Render world to user texture */
{ {
struct gpu_dispatch_params params = ZI; struct gpu_dispatch_params params = ZI;
params.plan = G.world_gpu_plan; params.plan = G.world_gpu_plan;
params.draw_target = G.user_texture; params.draw_target = G.user_texture;
params.draw_target_viewport = user_viewport; params.draw_target_viewport = user_viewport;
params.draw_target_view = G.world_to_user_xf;
gpu_dispatch(G.user_dispatch_state, params);
}
/* Render ui to user texture */
{
struct gpu_dispatch_params params = ZI;
params.plan = G.ui_gpu_plan;
params.draw_target = G.user_texture;
params.draw_target_viewport = user_viewport;
params.draw_target_view = XFORM_IDENT;
gpu_dispatch(G.user_dispatch_state, params); gpu_dispatch(G.user_dispatch_state, params);
} }
#if 0
/* Render to backbuffer texture */ /* Render to backbuffer texture */
{ {
struct gpu_dispatch_params params = ZI; struct gpu_dispatch_params params = ZI;
params.plan = G.backbuffer_gpu_plan; params.plan = G.backbuffer_gpu_plan;
params.draw_target = G.backbuffer_texture; params.draw_target = G.backbuffer_texture;
params.draw_target_viewport = backbuffer_viewport; params.draw_target_viewport = backbuffer_viewport;
params.draw_target_view = XFORM_IDENT;
gpu_dispatch(G.backbuffer_dispatch_state, params); gpu_dispatch(G.backbuffer_dispatch_state, params);
} }
#endif
/* Swap backbuffer */ /* Swap backbuffer */
gpu_swap_backbuffer(VSYNC_ENABLED); gpu_swap_backbuffer(VSYNC_ENABLED);