merge ui & render
This commit is contained in:
parent
aa395bfd5a
commit
6de00915ea
@ -29,14 +29,13 @@ struct cs_input {
|
||||
DECLS(uint3, SV_DispatchThreadID);
|
||||
};
|
||||
|
||||
#define SAMPLES 4
|
||||
#define MARCHES 16
|
||||
|
||||
/* ========================== *
|
||||
* Lighting
|
||||
* ========================== */
|
||||
|
||||
#define AMBIENT float4(1, 1, 1, 1)
|
||||
#define SAMPLES 4
|
||||
#define MARCHES 16
|
||||
#define AMBIENT float4(0, 0, 0, 0)
|
||||
|
||||
INLINE float4 get_light_in_dir(uint2 ray_start, float2 ray_dir)
|
||||
{
|
||||
@ -70,7 +69,7 @@ INLINE float4 get_light_at_pos(uint2 pos)
|
||||
{
|
||||
float4 result = 0;
|
||||
for (int i = 0; i < SAMPLES; ++i) {
|
||||
float angle = TAU * (((float)i + rand_float_from_float2(pos + (float)i + sin(g_constants.time))) / ((float)SAMPLES - 1));
|
||||
float angle = TAU * (((float)i + rand_float_from_float2(pos + (float)i)) / ((float)SAMPLES - 1));
|
||||
float2 dir = float2(cos(angle), sin(angle));
|
||||
float4 light_in_dir = get_light_in_dir(pos, dir);
|
||||
result += light_in_dir;
|
||||
|
||||
60
src/draw.c
60
src/draw.c
@ -44,18 +44,18 @@ void draw_material(struct gp_render_sig *sig, struct draw_material_params params
|
||||
* Fill shapes
|
||||
* ========================== */
|
||||
|
||||
void draw_poly_ex(struct gp_ui_sig *sig, struct v2_array vertices, struct gp_indices indices, u32 color)
|
||||
void draw_poly_ex(struct gp_render_sig *sig, struct v2_array vertices, struct gp_indices indices, u32 color)
|
||||
{
|
||||
struct gp_ui_cmd_desc cmd = ZI;
|
||||
cmd.kind = GP_UI_CMD_KIND_DRAW_SHAPE;
|
||||
cmd.shape.vertices = vertices;
|
||||
cmd.shape.indices = indices;
|
||||
cmd.shape.color = color;
|
||||
gp_push_ui_cmd(sig, &cmd);
|
||||
struct gp_render_cmd_desc cmd = ZI;
|
||||
cmd.kind = GP_RENDER_CMD_KIND_DRAW_UI_SHAPE;
|
||||
cmd.ui_shape.vertices = vertices;
|
||||
cmd.ui_shape.indices = indices;
|
||||
cmd.ui_shape.color = color;
|
||||
gp_push_render_cmd(sig, &cmd);
|
||||
}
|
||||
|
||||
/* Draws a filled polygon using triangles in a fan pattern */
|
||||
void draw_poly(struct gp_ui_sig *sig, struct v2_array vertices, u32 color)
|
||||
void draw_poly(struct gp_render_sig *sig, struct v2_array vertices, u32 color)
|
||||
{
|
||||
if (vertices.count >= 3) {
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
@ -81,7 +81,7 @@ void draw_poly(struct gp_ui_sig *sig, struct v2_array vertices, u32 color)
|
||||
}
|
||||
}
|
||||
|
||||
void draw_circle(struct gp_ui_sig *sig, struct v2 pos, f32 radius, u32 color, u32 detail)
|
||||
void draw_circle(struct gp_render_sig *sig, struct v2 pos, f32 radius, u32 color, u32 detail)
|
||||
{
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
@ -104,7 +104,7 @@ void draw_circle(struct gp_ui_sig *sig, struct v2 pos, f32 radius, u32 color, u3
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
void draw_quad(struct gp_ui_sig *sig, struct quad quad, u32 color)
|
||||
void draw_quad(struct gp_render_sig *sig, struct quad quad, u32 color)
|
||||
{
|
||||
LOCAL_PERSIST u32 indices_array[6] = {
|
||||
0, 1, 2,
|
||||
@ -119,7 +119,7 @@ void draw_quad(struct gp_ui_sig *sig, struct quad quad, u32 color)
|
||||
* Line shapes
|
||||
* ========================== */
|
||||
|
||||
void draw_gradient_line(struct gp_ui_sig *sig, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color)
|
||||
void draw_gradient_line(struct gp_render_sig *sig, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color)
|
||||
{
|
||||
#if 0
|
||||
struct quad quad = quad_from_line(start, end, thickness);
|
||||
@ -132,19 +132,19 @@ void draw_gradient_line(struct gp_ui_sig *sig, struct v2 start, struct v2 end, f
|
||||
#endif
|
||||
}
|
||||
|
||||
void draw_line(struct gp_ui_sig *sig, struct v2 start, struct v2 end, f32 thickness, u32 color)
|
||||
void draw_line(struct gp_render_sig *sig, struct v2 start, struct v2 end, f32 thickness, u32 color)
|
||||
{
|
||||
struct quad quad = quad_from_line(start, end, thickness);
|
||||
draw_quad(sig, quad, color);
|
||||
}
|
||||
|
||||
void draw_ray(struct gp_ui_sig *sig, struct v2 pos, struct v2 rel, f32 thickness, u32 color)
|
||||
void draw_ray(struct gp_render_sig *sig, struct v2 pos, struct v2 rel, f32 thickness, u32 color)
|
||||
{
|
||||
struct quad quad = quad_from_ray(pos, rel, thickness);
|
||||
draw_quad(sig, quad, color);
|
||||
}
|
||||
|
||||
void draw_poly_line(struct gp_ui_sig *sig, struct v2_array points, b32 loop, f32 thickness, u32 color)
|
||||
void draw_poly_line(struct gp_render_sig *sig, struct v2_array points, b32 loop, f32 thickness, u32 color)
|
||||
{
|
||||
if (points.count >= 2) {
|
||||
for (u64 i = 1; i < points.count; ++i) {
|
||||
@ -162,7 +162,7 @@ void draw_poly_line(struct gp_ui_sig *sig, struct v2_array points, b32 loop, f32
|
||||
}
|
||||
}
|
||||
|
||||
void draw_circle_line(struct gp_ui_sig *sig, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail)
|
||||
void draw_circle_line(struct gp_render_sig *sig, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail)
|
||||
{
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
@ -185,14 +185,14 @@ void draw_circle_line(struct gp_ui_sig *sig, struct v2 pos, f32 radius, f32 thic
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
void draw_quad_line(struct gp_ui_sig *sig, struct quad quad, f32 thickness, u32 color)
|
||||
void draw_quad_line(struct gp_render_sig *sig, struct quad quad, f32 thickness, u32 color)
|
||||
{
|
||||
struct v2 points[] = { quad.p0, quad.p1, quad.p2, quad.p3 };
|
||||
struct v2_array a = { .points = points, .count = countof(points) };
|
||||
draw_poly_line(sig, a, 1, thickness, color);
|
||||
}
|
||||
|
||||
void draw_arrow_line(struct gp_ui_sig *sig, struct v2 start, struct v2 end, f32 thickness, f32 arrowhead_height, u32 color)
|
||||
void draw_arrow_line(struct gp_render_sig *sig, struct v2 start, struct v2 end, f32 thickness, f32 arrowhead_height, u32 color)
|
||||
{
|
||||
const f32 head_width_ratio = 0.5f; /* Width of arrowhead relative to its length */
|
||||
|
||||
@ -222,13 +222,13 @@ void draw_arrow_line(struct gp_ui_sig *sig, struct v2 start, struct v2 end, f32
|
||||
draw_quad(sig, line_quad, color);
|
||||
}
|
||||
|
||||
void draw_arrow_ray(struct gp_ui_sig *sig, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color)
|
||||
void draw_arrow_ray(struct gp_render_sig *sig, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color)
|
||||
{
|
||||
struct v2 end = v2_add(pos, rel);
|
||||
draw_arrow_line(sig, pos, end, thickness, arrowhead_height, color);
|
||||
}
|
||||
|
||||
void draw_collider_line(struct gp_ui_sig *sig, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail)
|
||||
void draw_collider_line(struct gp_render_sig *sig, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail)
|
||||
{
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct v2_array poly = ZI;
|
||||
@ -286,16 +286,16 @@ void draw_grid(struct gp_render_sig *sig, struct xform xf, u32 bg0_color, u32 bg
|
||||
* UI
|
||||
* ========================== */
|
||||
|
||||
void draw_ui(struct gp_ui_sig *sig, struct draw_ui_params params)
|
||||
void draw_ui_rect(struct gp_render_sig *sig, struct draw_ui_rect_params params)
|
||||
{
|
||||
struct gp_ui_cmd_desc cmd = ZI;
|
||||
cmd.kind = GP_UI_CMD_KIND_DRAW_RECT;
|
||||
cmd.rect.xf = params.xf;
|
||||
cmd.rect.sprite = params.sprite;
|
||||
cmd.rect.texture = params.texture;
|
||||
cmd.rect.clip = params.clip;
|
||||
cmd.rect.tint = params.tint;
|
||||
gp_push_ui_cmd(sig, &cmd);
|
||||
struct gp_render_cmd_desc cmd = ZI;
|
||||
cmd.kind = GP_RENDER_CMD_KIND_DRAW_UI_RECT;
|
||||
cmd.ui_rect.xf = params.xf;
|
||||
cmd.ui_rect.sprite = params.sprite;
|
||||
cmd.ui_rect.texture = params.texture;
|
||||
cmd.ui_rect.clip = params.clip;
|
||||
cmd.ui_rect.tint = params.tint;
|
||||
gp_push_render_cmd(sig, &cmd);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -303,7 +303,7 @@ void draw_ui(struct gp_ui_sig *sig, struct draw_ui_params params)
|
||||
* ========================== */
|
||||
|
||||
/* Returns the rect of the text area */
|
||||
struct rect draw_text(struct gp_ui_sig *sig, struct draw_text_params params)
|
||||
struct rect draw_text(struct gp_render_sig *sig, struct draw_text_params params)
|
||||
{
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
@ -471,7 +471,7 @@ struct rect draw_text(struct gp_ui_sig *sig, struct draw_text_params params)
|
||||
struct v2 pos = V2(draw_pos.x + tg->off_x, draw_pos.y + tg->off_y);
|
||||
struct v2 size = V2(tg->width, tg->height);
|
||||
struct xform xf = xform_from_rect(RECT_FROM_V2(pos, size));
|
||||
draw_ui(sig, DRAW_UI_PARAMS(.xf = xf, .texture = params.font->texture, .tint = params.color, .clip = tg->clip));
|
||||
draw_ui_rect(sig, DRAW_UI_RECT_PARAMS(.xf = xf, .texture = params.font->texture, .tint = params.color, .clip = tg->clip));
|
||||
draw_pos.x += tg->advance;
|
||||
|
||||
}
|
||||
|
||||
34
src/draw.h
34
src/draw.h
@ -35,35 +35,35 @@ void draw_material(struct gp_render_sig *sig, struct draw_material_params params
|
||||
* Fill shapes
|
||||
* ========================== */
|
||||
|
||||
void draw_poly_ex(struct gp_ui_sig *sig, struct v2_array vertices, struct gp_indices indices, u32 color);
|
||||
void draw_poly_ex(struct gp_render_sig *sig, struct v2_array vertices, struct gp_indices indices, u32 color);
|
||||
|
||||
void draw_poly(struct gp_ui_sig *sig, struct v2_array points, u32 color);
|
||||
void draw_poly(struct gp_render_sig *sig, struct v2_array points, u32 color);
|
||||
|
||||
void draw_circle(struct gp_ui_sig *sig, struct v2 pos, f32 radius, u32 color, u32 detail);
|
||||
void draw_circle(struct gp_render_sig *sig, struct v2 pos, f32 radius, u32 color, u32 detail);
|
||||
|
||||
void draw_quad(struct gp_ui_sig *sig, struct quad quad, u32 color);
|
||||
void draw_quad(struct gp_render_sig *sig, struct quad quad, u32 color);
|
||||
|
||||
/* ========================== *
|
||||
* Line shapes
|
||||
* ========================== */
|
||||
|
||||
void draw_gradient_line(struct gp_ui_sig *sig, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color);
|
||||
void draw_gradient_line(struct gp_render_sig *sig, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color);
|
||||
|
||||
void draw_line(struct gp_ui_sig *sig, struct v2 start, struct v2 end, f32 thickness, u32 color);
|
||||
void draw_line(struct gp_render_sig *sig, struct v2 start, struct v2 end, f32 thickness, u32 color);
|
||||
|
||||
void draw_ray(struct gp_ui_sig *sig, struct v2 pos, struct v2 rel, f32 thickness, u32 color);
|
||||
void draw_ray(struct gp_render_sig *sig, struct v2 pos, struct v2 rel, f32 thickness, u32 color);
|
||||
|
||||
void draw_poly_line(struct gp_ui_sig *sig, struct v2_array points, b32 loop, f32 thickness, u32 color);
|
||||
void draw_poly_line(struct gp_render_sig *sig, struct v2_array points, b32 loop, f32 thickness, u32 color);
|
||||
|
||||
void draw_circle_line(struct gp_ui_sig *sig, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail);
|
||||
void draw_circle_line(struct gp_render_sig *sig, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail);
|
||||
|
||||
void draw_quad_line(struct gp_ui_sig *sig, struct quad quad, f32 thickness, u32 color);
|
||||
void draw_quad_line(struct gp_render_sig *sig, struct quad quad, f32 thickness, u32 color);
|
||||
|
||||
void draw_arrow_line(struct gp_ui_sig *sig, struct v2 start, struct v2 end, f32 thickness, f32 arrowhead_height, u32 color);
|
||||
void draw_arrow_line(struct gp_render_sig *sig, struct v2 start, struct v2 end, f32 thickness, f32 arrowhead_height, u32 color);
|
||||
|
||||
void draw_arrow_ray(struct gp_ui_sig *sig, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color);
|
||||
void draw_arrow_ray(struct gp_render_sig *sig, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color);
|
||||
|
||||
void draw_collider_line(struct gp_ui_sig *sig, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail);
|
||||
void draw_collider_line(struct gp_render_sig *sig, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail);
|
||||
|
||||
/* ========================== *
|
||||
* Grid
|
||||
@ -75,13 +75,13 @@ void draw_grid(struct gp_render_sig *sig, struct xform xf, u32 bg0_color, u32 bg
|
||||
* UI
|
||||
* ========================== */
|
||||
|
||||
#define DRAW_UI_PARAMS(...) ((struct draw_ui_params) { \
|
||||
#define DRAW_UI_RECT_PARAMS(...) ((struct draw_ui_rect_params) { \
|
||||
.tint = COLOR_WHITE, \
|
||||
.clip = CLIP_ALL, \
|
||||
__VA_ARGS__ \
|
||||
})
|
||||
|
||||
struct draw_ui_params {
|
||||
struct draw_ui_rect_params {
|
||||
struct xform xf;
|
||||
struct gp_resource *texture; /* Overrides sprite if set */
|
||||
struct sprite_tag sprite;
|
||||
@ -89,7 +89,7 @@ struct draw_ui_params {
|
||||
u32 tint;
|
||||
};
|
||||
|
||||
void draw_ui(struct gp_ui_sig *sig, struct draw_ui_params params);
|
||||
void draw_ui_rect(struct gp_render_sig *sig, struct draw_ui_rect_params params);
|
||||
|
||||
/* ========================== *
|
||||
* Text
|
||||
@ -137,6 +137,6 @@ struct draw_text_params {
|
||||
struct string str;
|
||||
};
|
||||
|
||||
struct rect draw_text(struct gp_ui_sig *sig, struct draw_text_params params);
|
||||
struct rect draw_text(struct gp_render_sig *sig, struct draw_text_params params);
|
||||
|
||||
#endif
|
||||
|
||||
62
src/gp.h
62
src/gp.h
@ -57,6 +57,8 @@ struct v2i32 gp_texture_get_size(struct gp_resource *texture);
|
||||
enum gp_render_cmd_kind {
|
||||
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
|
||||
@ -75,6 +77,18 @@ struct gp_render_cmd_desc {
|
||||
struct v3 light_emittance;
|
||||
i32 grid_cmd_id;
|
||||
} material;
|
||||
struct {
|
||||
struct xform xf;
|
||||
struct sprite_tag sprite;
|
||||
struct gp_resource *texture;
|
||||
struct clip_rect clip;
|
||||
u32 tint;
|
||||
} ui_rect;
|
||||
struct {
|
||||
struct v2_array vertices;
|
||||
struct gp_indices indices;
|
||||
u32 color;
|
||||
} ui_shape;
|
||||
struct {
|
||||
f32 line_thickness;
|
||||
f32 line_spacing;
|
||||
@ -89,7 +103,7 @@ struct gp_render_cmd_desc {
|
||||
};
|
||||
|
||||
struct gp_render_params {
|
||||
struct gp_resource *draw_target;
|
||||
struct v2i32 draw_target_size;
|
||||
struct rect draw_target_viewport;
|
||||
struct xform draw_target_view;
|
||||
b32 clear_target;
|
||||
@ -100,51 +114,7 @@ struct gp_render_sig *gp_render_sig_alloc(void);
|
||||
/* Returns a cmd id internal to the sig */
|
||||
i32 gp_push_render_cmd(struct gp_render_sig *render_sig, struct gp_render_cmd_desc *desc);
|
||||
|
||||
void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params render_params);
|
||||
|
||||
/* ========================== *
|
||||
* UI
|
||||
* ========================== */
|
||||
|
||||
enum gp_ui_cmd_kind {
|
||||
GP_UI_CMD_KIND_NONE,
|
||||
GP_UI_CMD_KIND_DRAW_RECT,
|
||||
GP_UI_CMD_KIND_DRAW_SHAPE,
|
||||
|
||||
NUM_GP_UI_CMD_KINDS
|
||||
};
|
||||
|
||||
struct gp_ui_cmd_desc {
|
||||
enum gp_ui_cmd_kind kind;
|
||||
union {
|
||||
struct {
|
||||
struct xform xf;
|
||||
struct sprite_tag sprite;
|
||||
struct gp_resource *texture;
|
||||
struct clip_rect clip;
|
||||
u32 tint;
|
||||
} rect;
|
||||
struct {
|
||||
struct v2_array vertices;
|
||||
struct gp_indices indices;
|
||||
u32 color;
|
||||
} shape;
|
||||
};
|
||||
};
|
||||
|
||||
struct gp_ui_params {
|
||||
struct gp_resource *draw_target;
|
||||
struct rect draw_target_viewport;
|
||||
struct xform draw_target_view;
|
||||
b32 clear_target;
|
||||
};
|
||||
|
||||
struct gp_ui_sig *gp_ui_sig_alloc(void);
|
||||
|
||||
/* Returns a cmd id internal to the flow */
|
||||
i32 gp_push_ui_cmd(struct gp_ui_sig *ui_sig, struct gp_ui_cmd_desc *desc);
|
||||
|
||||
void gp_run_ui(struct gp_ui_sig *ui_sig, struct gp_ui_params ui_params);
|
||||
struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params render_params);
|
||||
|
||||
/* ========================== *
|
||||
* Memory info
|
||||
|
||||
353
src/gp_dx12.c
353
src/gp_dx12.c
@ -710,7 +710,7 @@ INTERNAL void dx12_init_pipelines(void)
|
||||
desc->ps.func = LIT("ps");
|
||||
desc->ia[0] = (D3D12_INPUT_ELEMENT_DESC) { "pos", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 };
|
||||
desc->ia[1] = (D3D12_INPUT_ELEMENT_DESC) { "color_srgb", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 };
|
||||
desc->rtvs[0].format = DXGI_FORMAT_R16G16B16A16_FLOAT;
|
||||
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
desc->rtvs[0].blending = 1;
|
||||
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
||||
}
|
||||
@ -722,7 +722,7 @@ INTERNAL void dx12_init_pipelines(void)
|
||||
desc->ps.file = LIT("sh/ui.hlsl");
|
||||
desc->vs.func = LIT("vs");
|
||||
desc->ps.func = LIT("ps");
|
||||
desc->rtvs[0].format = DXGI_FORMAT_R16G16B16A16_FLOAT;
|
||||
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
desc->rtvs[0].blending = 1;
|
||||
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
||||
}
|
||||
@ -2521,12 +2521,20 @@ struct render_sig {
|
||||
u32 num_material_instance_descs;
|
||||
struct arena *material_instance_descs_arena;
|
||||
|
||||
/* Ui instances */
|
||||
u32 num_ui_rect_instance_descs;
|
||||
struct arena *ui_rect_instance_descs_arena;
|
||||
|
||||
/* UI shapes */
|
||||
struct arena *ui_shape_verts_arena;
|
||||
struct arena *ui_shape_indices_arena;
|
||||
|
||||
/* Grids */
|
||||
u32 num_material_grid_descs;
|
||||
struct arena *material_grid_descs_arena;
|
||||
|
||||
/* Resources */
|
||||
struct v2i32 old_size;
|
||||
struct dx12_resource *final_target;
|
||||
struct dx12_resource *albedo;
|
||||
struct dx12_resource *emittance;
|
||||
struct dx12_resource *emittance_flood_a;
|
||||
@ -2544,6 +2552,14 @@ struct material_instance_desc {
|
||||
i32 grid_id;
|
||||
};
|
||||
|
||||
struct ui_rect_instance_desc {
|
||||
struct xform xf;
|
||||
struct sprite_tag sprite;
|
||||
struct dx12_resource *texture;
|
||||
struct clip_rect clip;
|
||||
u32 tint;
|
||||
};
|
||||
|
||||
struct material_grid_desc {
|
||||
f32 line_thickness;
|
||||
f32 line_spacing;
|
||||
@ -2567,6 +2583,9 @@ INTERNAL struct render_sig *render_sig_alloc(void)
|
||||
|
||||
sig->material_instance_descs_arena = arena_alloc(GIBI(1));
|
||||
sig->material_grid_descs_arena = arena_alloc(GIBI(1));
|
||||
sig->ui_rect_instance_descs_arena = arena_alloc(GIBI(1));
|
||||
sig->ui_shape_verts_arena = arena_alloc(GIBI(1));
|
||||
sig->ui_shape_indices_arena = arena_alloc(GIBI(1));
|
||||
|
||||
return sig;
|
||||
}
|
||||
@ -2579,6 +2598,14 @@ INTERNAL void render_sig_reset(struct render_sig *sig)
|
||||
sig->num_material_instance_descs = 0;
|
||||
arena_reset(sig->material_instance_descs_arena);
|
||||
|
||||
/* Reset UI rect instances */
|
||||
sig->num_ui_rect_instance_descs = 0;
|
||||
arena_reset(sig->ui_rect_instance_descs_arena);
|
||||
|
||||
/* Reset shapes */
|
||||
arena_reset(sig->ui_shape_verts_arena);
|
||||
arena_reset(sig->ui_shape_indices_arena);
|
||||
|
||||
/* Reset grids */
|
||||
sig->num_material_grid_descs = 0;
|
||||
arena_reset(sig->material_grid_descs_arena);
|
||||
@ -2613,6 +2640,33 @@ i32 gp_push_render_cmd(struct gp_render_sig *render_sig, struct gp_render_cmd_de
|
||||
ret = ++sig->num_material_instance_descs;
|
||||
} break;
|
||||
|
||||
case GP_RENDER_CMD_KIND_DRAW_UI_RECT:
|
||||
{
|
||||
struct ui_rect_instance_desc *instance_desc = arena_push(sig->ui_rect_instance_descs_arena, struct ui_rect_instance_desc);
|
||||
instance_desc->xf = cmd_desc->ui_rect.xf;
|
||||
instance_desc->sprite = cmd_desc->ui_rect.sprite;
|
||||
instance_desc->texture = (struct dx12_resource *)cmd_desc->ui_rect.texture;
|
||||
instance_desc->clip = cmd_desc->ui_rect.clip;
|
||||
instance_desc->tint = cmd_desc->ui_rect.tint;
|
||||
ret = ++sig->num_ui_rect_instance_descs;
|
||||
} break;
|
||||
|
||||
case GP_RENDER_CMD_KIND_DRAW_UI_SHAPE:
|
||||
{
|
||||
u32 color = cmd_desc->ui_shape.color;
|
||||
struct sh_shape_vert *verts = arena_push_array_no_zero(sig->ui_shape_verts_arena, struct sh_shape_vert, cmd_desc->ui_shape.vertices.count);
|
||||
u32 *indices = arena_push_array_no_zero(sig->ui_shape_indices_arena, u32, cmd_desc->ui_shape.indices.count);
|
||||
for (u32 i = 0; i < cmd_desc->ui_shape.vertices.count; ++i) {
|
||||
struct sh_shape_vert *v = &verts[i];
|
||||
v->pos = sh_float2_from_v2(cmd_desc->ui_shape.vertices.points[i]);
|
||||
v->color_srgb = sh_uint_from_u32(color);
|
||||
}
|
||||
u32 vert_offset = verts - (struct sh_shape_vert *)arena_base(sig->ui_shape_verts_arena);
|
||||
for (u32 i = 0; i < cmd_desc->ui_shape.indices.count; ++i) {
|
||||
indices[i] = cmd_desc->ui_shape.indices.indices[i] + vert_offset;
|
||||
}
|
||||
} break;
|
||||
|
||||
case GP_RENDER_CMD_KIND_PUSH_GRID:
|
||||
{
|
||||
struct material_grid_desc *grid_desc = arena_push(sig->material_grid_descs_arena, struct material_grid_desc);
|
||||
@ -2635,27 +2689,30 @@ i32 gp_push_render_cmd(struct gp_render_sig *render_sig, struct gp_render_cmd_de
|
||||
* Render
|
||||
* ========================== */
|
||||
|
||||
void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params params)
|
||||
struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params params)
|
||||
{
|
||||
__prof;
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct render_sig *sig = (struct render_sig *)render_sig;
|
||||
struct dx12_resource *final_target = (struct dx12_resource *)params.draw_target;
|
||||
struct v2i32 final_target_size = final_target->texture_size;
|
||||
struct v2i32 final_target_size = params.draw_target_size;
|
||||
final_target_size.x = max_i32(final_target_size.x, 1);
|
||||
final_target_size.y = max_i32(final_target_size.y, 1);
|
||||
|
||||
/* Allocate resources */
|
||||
if (!v2i32_eq(sig->old_size, final_target_size)) {
|
||||
__profn("Allocate buffers");
|
||||
/* Release sig resources if size changed */
|
||||
if (sig->final_target && !v2i32_eq(final_target_size, sig->final_target->texture_size)) {
|
||||
__profn("Release sig resources");
|
||||
fenced_release(sig->final_target, FENCED_RELEASE_KIND_RESOURCE);
|
||||
fenced_release(sig->albedo, FENCED_RELEASE_KIND_RESOURCE);
|
||||
fenced_release(sig->emittance, FENCED_RELEASE_KIND_RESOURCE);
|
||||
fenced_release(sig->emittance_flood_a, FENCED_RELEASE_KIND_RESOURCE);
|
||||
fenced_release(sig->emittance_flood_b, FENCED_RELEASE_KIND_RESOURCE);
|
||||
sig->final_target = 0;
|
||||
}
|
||||
|
||||
/* Release buffers */
|
||||
/* TODO: Batch release */
|
||||
if (sig->albedo) {
|
||||
fenced_release(sig->albedo, FENCED_RELEASE_KIND_RESOURCE);
|
||||
fenced_release(sig->emittance, FENCED_RELEASE_KIND_RESOURCE);
|
||||
fenced_release(sig->emittance_flood_a, FENCED_RELEASE_KIND_RESOURCE);
|
||||
fenced_release(sig->emittance_flood_b, FENCED_RELEASE_KIND_RESOURCE);
|
||||
}
|
||||
/* Alloc buffers */
|
||||
/* Allocate sig resources */
|
||||
if (!sig->final_target) {
|
||||
__profn("Allocate sig resources");
|
||||
sig->final_target = gbuff_alloc(DXGI_FORMAT_R8G8B8A8_UNORM, final_target_size, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
sig->albedo = gbuff_alloc(DXGI_FORMAT_R8G8B8A8_UNORM, final_target_size, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
sig->emittance = gbuff_alloc(DXGI_FORMAT_R16G16B16A16_FLOAT, final_target_size, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
sig->emittance_flood_a = gbuff_alloc(DXGI_FORMAT_R16G16_UINT, final_target_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
@ -2667,12 +2724,15 @@ void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params par
|
||||
struct pipeline *material_pipeline = pipeline_from_name(pipeline_scope, LIT("material"));
|
||||
struct pipeline *flood_pipeline = pipeline_from_name(pipeline_scope, LIT("flood"));
|
||||
struct pipeline *shade_pipeline = pipeline_from_name(pipeline_scope, LIT("shade"));
|
||||
struct pipeline *ui_pipeline = pipeline_from_name(pipeline_scope, LIT("ui"));
|
||||
struct pipeline *shape_pipeline = pipeline_from_name(pipeline_scope, LIT("shape"));
|
||||
struct command_queue *cq = G.command_queues[DX12_QUEUE_DIRECT];
|
||||
struct command_list *cl = command_list_open(cq->cl_pool);
|
||||
{
|
||||
__profn("Run render");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Run render", RGB32_F(0.5, 0.2, 0.2));
|
||||
struct mat4x4 vp_matrix = calculate_vp(params.draw_target_view, params.draw_target_viewport.width, params.draw_target_viewport.height);
|
||||
struct mat4x4 world_vp_matrix = calculate_vp(params.draw_target_view, params.draw_target_viewport.width, params.draw_target_viewport.height);
|
||||
struct mat4x4 ui_vp_matrix = calculate_vp(XFORM_IDENT, params.draw_target_viewport.width, params.draw_target_viewport.height);
|
||||
|
||||
/* Upload dummmy vert & index buffer */
|
||||
/* TODO: Make these static */
|
||||
@ -2683,6 +2743,7 @@ void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params par
|
||||
|
||||
/* Process sig data into uploadable data */
|
||||
struct sh_material_instance *material_instances = arena_push_array_no_zero(scratch.arena, struct sh_material_instance, sig->num_material_instance_descs);
|
||||
struct sh_ui_instance *ui_rect_instances = arena_push_array_no_zero(scratch.arena, struct sh_ui_instance, sig->num_ui_rect_instance_descs);
|
||||
struct sh_material_grid *grids = arena_push_array_no_zero(scratch.arena, struct sh_material_grid, sig->num_material_grid_descs);
|
||||
{
|
||||
__profn("Process sig data");
|
||||
@ -2714,6 +2775,30 @@ void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params par
|
||||
}
|
||||
}
|
||||
|
||||
/* Process ui rect instances */
|
||||
{
|
||||
__profn("Process ui rect instances");
|
||||
for (u32 i = 0; i < sig->num_ui_rect_instance_descs; ++i) {
|
||||
struct ui_rect_instance_desc *desc = &((struct ui_rect_instance_desc *)arena_base(sig->ui_rect_instance_descs_arena))[i];
|
||||
struct sh_ui_instance *instance = &ui_rect_instances[i];
|
||||
i32 texture_id = -1;
|
||||
if (desc->texture != 0) {
|
||||
texture_id = desc->texture->srv_descriptor->index;
|
||||
} else if (desc->sprite.hash != 0) {
|
||||
struct sprite_texture *st = sprite_texture_from_tag_async(sprite_scope, desc->sprite);
|
||||
struct dx12_resource *texture = (struct dx12_resource *)st->gp_texture;
|
||||
if (texture) {
|
||||
texture_id = texture->srv_descriptor->index;
|
||||
}
|
||||
}
|
||||
instance->tex_nurid = sh_int_from_i32(texture_id);
|
||||
instance->xf = sh_float2x3_from_xform(desc->xf);
|
||||
instance->uv0 = sh_float2_from_v2(desc->clip.p0);
|
||||
instance->uv1 = sh_float2_from_v2(desc->clip.p1);
|
||||
instance->tint_srgb = sh_uint_from_u32(desc->tint);
|
||||
}
|
||||
}
|
||||
|
||||
/* Process grids */
|
||||
{
|
||||
__profn("Process grids");
|
||||
@ -2734,6 +2819,9 @@ void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params par
|
||||
|
||||
/* Upload buffers */
|
||||
struct command_buffer *material_instance_buffer = command_list_push_buffer(cl, STRING(sizeof(*material_instances) * sig->num_material_instance_descs, (u8 *)material_instances));
|
||||
struct command_buffer *ui_rect_instance_buffer = command_list_push_buffer(cl, STRING(sizeof(*ui_rect_instances) * sig->num_ui_rect_instance_descs, (u8 *)ui_rect_instances));
|
||||
struct command_buffer *ui_shape_verts_buffer = command_list_push_buffer(cl, STRING_FROM_ARENA(sig->ui_shape_verts_arena));
|
||||
struct command_buffer *ui_shape_indices_buffer = command_list_push_buffer(cl, STRING_FROM_ARENA(sig->ui_shape_indices_arena));
|
||||
struct command_buffer *grid_buffer = command_list_push_buffer(cl, STRING(sizeof(*grids) * sig->num_material_grid_descs, (u8 *)grids));
|
||||
|
||||
/* Upload descriptor heap */
|
||||
@ -2781,7 +2869,7 @@ void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params par
|
||||
|
||||
/* Set constants */
|
||||
struct sh_material_constants constants = ZI;
|
||||
constants.projection = sh_float4x4_from_mat4x4(vp_matrix);
|
||||
constants.projection = sh_float4x4_from_mat4x4(world_vp_matrix);
|
||||
|
||||
/* Set parameters */
|
||||
command_list_set_graphics_root_constant(cl, &constants, sizeof(constants));
|
||||
@ -2877,7 +2965,7 @@ void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params par
|
||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->emittance, D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE },
|
||||
{ D3D12_RESOURCE_BARRIER_TYPE_UAV, emittance_flood_read, 0 },
|
||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, emittance_flood_read, D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE },
|
||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, final_target, D3D12_RESOURCE_STATE_UNORDERED_ACCESS }
|
||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->final_target, D3D12_RESOURCE_STATE_UNORDERED_ACCESS }
|
||||
};
|
||||
dx12_resource_barriers(cl->cl, countof(barriers), barriers);
|
||||
}
|
||||
@ -2887,7 +2975,7 @@ void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params par
|
||||
__profn("Clear target");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Clear target", RGB32_F(0.5, 0.2, 0.2));
|
||||
f32 clear_color[] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
ID3D12GraphicsCommandList_ClearUnorderedAccessViewFloat(cl->cl, gpu_handle_from_descriptor(final_target->uav_descriptor, descriptor_heap), final_target->uav_descriptor->handle, final_target->resource, clear_color, 0, 0);
|
||||
ID3D12GraphicsCommandList_ClearUnorderedAccessViewFloat(cl->cl, gpu_handle_from_descriptor(sig->final_target->uav_descriptor, descriptor_heap), sig->final_target->uav_descriptor->handle, sig->final_target->resource, clear_color, 0, 0);
|
||||
}
|
||||
|
||||
/* Shade pass */
|
||||
@ -2906,7 +2994,7 @@ void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params par
|
||||
constants.albedo_tex_urid = sh_uint_from_u32(sig->albedo->srv_descriptor->index);
|
||||
constants.emittance_tex_urid = sh_uint_from_u32(sig->emittance->srv_descriptor->index);
|
||||
constants.emittance_flood_tex_urid = sh_uint_from_u32(emittance_flood_read->srv_descriptor->index);
|
||||
constants.write_tex_urid = sh_uint_from_u32(final_target->uav_descriptor->index);
|
||||
constants.write_tex_urid = sh_uint_from_u32(sig->final_target->uav_descriptor->index);
|
||||
constants.tex_width = sh_uint_from_u32(final_target_size.x);
|
||||
constants.tex_height = sh_uint_from_u32(final_target_size.y);
|
||||
constants.exposure = sh_float_from_f32(1.0);
|
||||
@ -2921,200 +3009,15 @@ void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params par
|
||||
/* Dispatch */
|
||||
ID3D12GraphicsCommandList_Dispatch(cl->cl, (final_target_size.x + 7) / 8, (final_target_size.y + 7) / 8, 1);
|
||||
}
|
||||
}
|
||||
command_list_close(cl);
|
||||
pipeline_scope_end(pipeline_scope);
|
||||
sprite_scope_end(sprite_scope);
|
||||
|
||||
sig->old_size = final_target_size;
|
||||
render_sig_reset(sig);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* UI sig
|
||||
* ========================== */
|
||||
|
||||
struct ui_sig {
|
||||
struct arena *arena;
|
||||
|
||||
/* Rect instances */
|
||||
u32 num_rect_instance_descs;
|
||||
struct arena *rect_instance_descs_arena;
|
||||
|
||||
/* Shapes */
|
||||
struct arena *shape_verts_arena;
|
||||
struct arena *shape_indices_arena;
|
||||
};
|
||||
|
||||
struct ui_rect_instance_desc {
|
||||
struct xform xf;
|
||||
struct sprite_tag sprite;
|
||||
struct dx12_resource *texture;
|
||||
struct clip_rect clip;
|
||||
u32 tint;
|
||||
};
|
||||
|
||||
INTERNAL struct ui_sig *ui_sig_alloc(void)
|
||||
{
|
||||
__prof;
|
||||
struct ui_sig *sig = 0;
|
||||
{
|
||||
struct arena *arena = arena_alloc(MEBI(64));
|
||||
sig = arena_push(arena, struct ui_sig);
|
||||
sig->arena = arena;
|
||||
}
|
||||
|
||||
sig->rect_instance_descs_arena = arena_alloc(GIBI(1));
|
||||
sig->shape_verts_arena = arena_alloc(GIBI(1));
|
||||
sig->shape_indices_arena = arena_alloc(GIBI(1));
|
||||
|
||||
return sig;
|
||||
}
|
||||
|
||||
INTERNAL void ui_sig_reset(struct ui_sig *sig)
|
||||
{
|
||||
__prof;
|
||||
|
||||
/* Reset rect instances */
|
||||
sig->num_rect_instance_descs = 0;
|
||||
arena_reset(sig->rect_instance_descs_arena);
|
||||
|
||||
/* Reset shapes */
|
||||
arena_reset(sig->shape_verts_arena);
|
||||
arena_reset(sig->shape_indices_arena);
|
||||
}
|
||||
|
||||
struct gp_ui_sig *gp_ui_sig_alloc(void)
|
||||
{
|
||||
struct ui_sig *sig = ui_sig_alloc();
|
||||
return (struct gp_ui_sig *)sig;
|
||||
}
|
||||
|
||||
i32 gp_push_ui_cmd(struct gp_ui_sig *ui_sig, struct gp_ui_cmd_desc *cmd_desc)
|
||||
{
|
||||
i32 ret = 0;
|
||||
struct ui_sig *sig = (struct ui_sig *)ui_sig;
|
||||
if (sig) {
|
||||
switch (cmd_desc->kind) {
|
||||
default: break;
|
||||
|
||||
case GP_UI_CMD_KIND_DRAW_RECT:
|
||||
{
|
||||
struct ui_rect_instance_desc *instance_desc = arena_push(sig->rect_instance_descs_arena, struct ui_rect_instance_desc);
|
||||
instance_desc->xf = cmd_desc->rect.xf;
|
||||
instance_desc->sprite = cmd_desc->rect.sprite;
|
||||
instance_desc->texture = (struct dx12_resource *)cmd_desc->rect.texture;
|
||||
instance_desc->clip = cmd_desc->rect.clip;
|
||||
instance_desc->tint = cmd_desc->rect.tint;
|
||||
ret = ++sig->num_rect_instance_descs;
|
||||
} break;
|
||||
|
||||
case GP_UI_CMD_KIND_DRAW_SHAPE:
|
||||
{
|
||||
u32 color = cmd_desc->shape.color;
|
||||
struct sh_shape_vert *verts = arena_push_array_no_zero(sig->shape_verts_arena, struct sh_shape_vert, cmd_desc->shape.vertices.count);
|
||||
u32 *indices = arena_push_array_no_zero(sig->shape_indices_arena, u32, cmd_desc->shape.indices.count);
|
||||
for (u32 i = 0; i < cmd_desc->shape.vertices.count; ++i) {
|
||||
struct sh_shape_vert *v = &verts[i];
|
||||
v->pos = sh_float2_from_v2(cmd_desc->shape.vertices.points[i]);
|
||||
v->color_srgb = sh_uint_from_u32(color);
|
||||
}
|
||||
u32 vert_offset = verts - (struct sh_shape_vert *)arena_base(sig->shape_verts_arena);
|
||||
for (u32 i = 0; i < cmd_desc->shape.indices.count; ++i) {
|
||||
indices[i] = cmd_desc->shape.indices.indices[i] + vert_offset;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* UI
|
||||
* ========================== */
|
||||
|
||||
void gp_run_ui(struct gp_ui_sig *ui_sig, struct gp_ui_params params)
|
||||
{
|
||||
#if 1
|
||||
__prof;
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct ui_sig *sig = (struct ui_sig *)ui_sig;
|
||||
struct dx12_resource *final_target = (struct dx12_resource *)params.draw_target;
|
||||
|
||||
struct sprite_scope *sprite_scope = sprite_scope_begin();
|
||||
struct pipeline_scope *pipeline_scope = pipeline_scope_begin();
|
||||
struct pipeline *ui_pipeline = pipeline_from_name(pipeline_scope, LIT("ui"));
|
||||
struct pipeline *shape_pipeline = pipeline_from_name(pipeline_scope, LIT("shape"));
|
||||
struct command_queue *cq = G.command_queues[DX12_QUEUE_DIRECT];
|
||||
struct command_list *cl = command_list_open(cq->cl_pool);
|
||||
{
|
||||
__profn("Run ui");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Run ui", RGB32_F(0.5, 0.2, 0.2));
|
||||
struct mat4x4 vp_matrix = calculate_vp(params.draw_target_view, params.draw_target_viewport.width, params.draw_target_viewport.height);
|
||||
|
||||
/* Upload dummmy vert & index buffer */
|
||||
/* TODO: Make these static */
|
||||
/* Dummy vertex buffer */
|
||||
LOCAL_PERSIST u16 quad_indices[6] = { 0, 1, 2, 0, 2, 3 };
|
||||
struct command_buffer *dummy_vertex_buffer = command_list_push_buffer(cl, STRING(0, 0));
|
||||
struct command_buffer *quad_index_buffer = command_list_push_buffer(cl, STRING_FROM_ARRAY(quad_indices));
|
||||
|
||||
/* Process sig data into uploadable data */
|
||||
struct sh_ui_instance *ui_instances = arena_push_array_no_zero(scratch.arena, struct sh_ui_instance, sig->num_rect_instance_descs);
|
||||
{
|
||||
__profn("Process sig data");
|
||||
|
||||
/* Process rect instances */
|
||||
{
|
||||
__profn("Process ui instances");
|
||||
for (u32 i = 0; i < sig->num_rect_instance_descs; ++i) {
|
||||
struct ui_rect_instance_desc *desc = &((struct ui_rect_instance_desc *)arena_base(sig->rect_instance_descs_arena))[i];
|
||||
struct sh_ui_instance *instance = &ui_instances[i];
|
||||
i32 texture_id = -1;
|
||||
if (desc->texture != 0) {
|
||||
texture_id = desc->texture->srv_descriptor->index;
|
||||
} else if (desc->sprite.hash != 0) {
|
||||
struct sprite_texture *st = sprite_texture_from_tag_async(sprite_scope, desc->sprite);
|
||||
struct dx12_resource *texture = (struct dx12_resource *)st->gp_texture;
|
||||
if (texture) {
|
||||
texture_id = texture->srv_descriptor->index;
|
||||
}
|
||||
}
|
||||
instance->tex_nurid = sh_int_from_i32(texture_id);
|
||||
instance->xf = sh_float2x3_from_xform(desc->xf);
|
||||
instance->uv0 = sh_float2_from_v2(desc->clip.p0);
|
||||
instance->uv1 = sh_float2_from_v2(desc->clip.p1);
|
||||
instance->tint_srgb = sh_uint_from_u32(desc->tint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Upload buffers */
|
||||
struct command_buffer *ui_instance_buffer = command_list_push_buffer(cl, STRING(sizeof(*ui_instances) * sig->num_rect_instance_descs, (u8 *)ui_instances));
|
||||
struct command_buffer *shape_verts_buffer = command_list_push_buffer(cl, STRING_FROM_ARENA(sig->shape_verts_arena));
|
||||
struct command_buffer *shape_indices_buffer = command_list_push_buffer(cl, STRING_FROM_ARENA(sig->shape_indices_arena));
|
||||
|
||||
/* Upload descriptor heap */
|
||||
struct command_descriptor_heap *descriptor_heap = command_list_push_descriptor_heap(cl, G.cbv_srv_uav_heap);
|
||||
ID3D12DescriptorHeap *heaps[] = { descriptor_heap->heap };
|
||||
ID3D12GraphicsCommandList_SetDescriptorHeaps(cl->cl, countof(heaps), heaps);
|
||||
|
||||
/* Bind final target as RTV */
|
||||
{
|
||||
struct dx12_resource_barrier_desc barriers[] = {
|
||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, final_target, D3D12_RESOURCE_STATE_RENDER_TARGET },
|
||||
{ D3D12_RESOURCE_BARRIER_TYPE_UAV, sig->final_target, 0},
|
||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->final_target, D3D12_RESOURCE_STATE_RENDER_TARGET },
|
||||
};
|
||||
dx12_resource_barriers(cl->cl, countof(barriers), barriers);
|
||||
ID3D12GraphicsCommandList_OMSetRenderTargets(cl->cl, 1, &final_target->rtv_descriptor->handle, 0, 0);
|
||||
}
|
||||
|
||||
/* Clear final target */
|
||||
if (params.clear_target) {
|
||||
__profn("Clear target");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Clear target", RGB32_F(0.5, 0.2, 0.2));
|
||||
f32 clear_color[] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
ID3D12GraphicsCommandList_ClearRenderTargetView(cl->cl, final_target->rtv_descriptor->handle, clear_color, 0, 0);
|
||||
ID3D12GraphicsCommandList_OMSetRenderTargets(cl->cl, 1, &sig->final_target->rtv_descriptor->handle, 0, 0);
|
||||
}
|
||||
|
||||
/* UI rect pass */
|
||||
@ -3134,15 +3037,15 @@ void gp_run_ui(struct gp_ui_sig *ui_sig, struct gp_ui_params params)
|
||||
|
||||
/* Set constants */
|
||||
struct sh_ui_constants constants = ZI;
|
||||
constants.projection = sh_float4x4_from_mat4x4(vp_matrix);
|
||||
constants.projection = sh_float4x4_from_mat4x4(ui_vp_matrix);
|
||||
|
||||
/* Set parameters */
|
||||
command_list_set_graphics_root_constant(cl, &constants, sizeof(constants));
|
||||
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(cl->cl, 1, descriptor_heap->start_gpu_handle);
|
||||
ID3D12GraphicsCommandList_SetGraphicsRootShaderResourceView(cl->cl, 2, ui_instance_buffer->resource->gpu_address);
|
||||
ID3D12GraphicsCommandList_SetGraphicsRootShaderResourceView(cl->cl, 2, ui_rect_instance_buffer->resource->gpu_address);
|
||||
|
||||
/* Draw */
|
||||
u32 instance_count = ui_instance_buffer->size / sizeof(struct sh_ui_instance);
|
||||
u32 instance_count = ui_rect_instance_buffer->size / sizeof(struct sh_ui_instance);
|
||||
D3D12_VERTEX_BUFFER_VIEW vbv = vbv_from_command_buffer(dummy_vertex_buffer, 0);
|
||||
D3D12_INDEX_BUFFER_VIEW ibv = ibv_from_command_buffer(quad_index_buffer, DXGI_FORMAT_R16_UINT);
|
||||
ID3D12GraphicsCommandList_IASetPrimitiveTopology(cl->cl, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
@ -3151,10 +3054,10 @@ void gp_run_ui(struct gp_ui_sig *ui_sig, struct gp_ui_params params)
|
||||
ID3D12GraphicsCommandList_DrawIndexedInstanced(cl->cl, 6, instance_count, 0, 0, 0);
|
||||
}
|
||||
|
||||
/* Shape pass */
|
||||
/* UI shape pass */
|
||||
if (shape_pipeline->success) {
|
||||
__profn("Shape pass");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Shape pass", RGB32_F(0.5, 0.2, 0.2));
|
||||
__profn("UI shape pass");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "UI shape pass", RGB32_F(0.5, 0.2, 0.2));
|
||||
|
||||
/* Bind pipeline */
|
||||
ID3D12GraphicsCommandList_SetPipelineState(cl->cl, shape_pipeline->pso);
|
||||
@ -3168,15 +3071,15 @@ void gp_run_ui(struct gp_ui_sig *ui_sig, struct gp_ui_params params)
|
||||
|
||||
/* Set constants */
|
||||
struct sh_shape_constants constants = ZI;
|
||||
constants.projection = sh_float4x4_from_mat4x4(vp_matrix);
|
||||
constants.projection = sh_float4x4_from_mat4x4(ui_vp_matrix);
|
||||
|
||||
/* Set parameters */
|
||||
command_list_set_graphics_root_constant(cl, &constants, sizeof(constants));
|
||||
|
||||
/* Draw */
|
||||
u32 index_count = shape_indices_buffer->size / sizeof(u32);
|
||||
D3D12_VERTEX_BUFFER_VIEW vbv = vbv_from_command_buffer(shape_verts_buffer, sizeof(struct sh_shape_vert));
|
||||
D3D12_INDEX_BUFFER_VIEW ibv = ibv_from_command_buffer(shape_indices_buffer, DXGI_FORMAT_R32_UINT);
|
||||
u32 index_count = ui_shape_indices_buffer->size / sizeof(u32);
|
||||
D3D12_VERTEX_BUFFER_VIEW vbv = vbv_from_command_buffer(ui_shape_verts_buffer, sizeof(struct sh_shape_vert));
|
||||
D3D12_INDEX_BUFFER_VIEW ibv = ibv_from_command_buffer(ui_shape_indices_buffer, DXGI_FORMAT_R32_UINT);
|
||||
ID3D12GraphicsCommandList_IASetPrimitiveTopology(cl->cl, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
ID3D12GraphicsCommandList_IASetVertexBuffers(cl->cl, 0, 1, &vbv);
|
||||
ID3D12GraphicsCommandList_IASetIndexBuffer(cl->cl, &ibv);
|
||||
@ -3187,12 +3090,10 @@ void gp_run_ui(struct gp_ui_sig *ui_sig, struct gp_ui_params params)
|
||||
pipeline_scope_end(pipeline_scope);
|
||||
sprite_scope_end(sprite_scope);
|
||||
|
||||
ui_sig_reset(sig);
|
||||
render_sig_reset(sig);
|
||||
scratch_end(scratch);
|
||||
#else
|
||||
(UNUSED)ui_sig;
|
||||
(UNUSED)params;
|
||||
#endif
|
||||
|
||||
return (struct gp_resource *)sig->final_target;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
|
||||
147
src/user.c
147
src/user.c
@ -68,9 +68,7 @@ GLOBAL struct {
|
||||
struct second_stat net_bytes_sent;
|
||||
|
||||
/* Gpu resources */
|
||||
struct gp_resource *user_texture;
|
||||
struct gp_render_sig *world_render_sig;
|
||||
struct gp_ui_sig *ui_sig;
|
||||
struct gp_render_sig *render_sig;
|
||||
|
||||
struct xform world_to_user_xf;
|
||||
|
||||
@ -239,8 +237,7 @@ struct user_startup_receipt user_startup(struct font_startup_receipt *font_sr,
|
||||
|
||||
/* GPU handles */
|
||||
G.world_to_user_xf = XFORM_IDENT;
|
||||
G.world_render_sig = gp_render_sig_alloc();
|
||||
G.ui_sig = gp_ui_sig_alloc();
|
||||
G.render_sig = gp_render_sig_alloc();
|
||||
|
||||
G.console_logs_arena = arena_alloc(GIBI(64));
|
||||
//log_register_callback(debug_console_log_callback, LOG_LEVEL_SUCCESS);
|
||||
@ -286,13 +283,13 @@ INTERNAL void debug_draw_xform(struct xform xf, u32 color_x, u32 color_y)
|
||||
x_ray = v2_mul(x_ray, ray_scale);
|
||||
y_ray = v2_mul(y_ray, ray_scale);
|
||||
|
||||
draw_arrow_ray(G.ui_sig, pos, x_ray, thickness, arrowhead_len, color_x);
|
||||
draw_arrow_ray(G.ui_sig, pos, y_ray, thickness, arrowhead_len, color_y);
|
||||
draw_arrow_ray(G.render_sig, pos, x_ray, thickness, arrowhead_len, color_x);
|
||||
draw_arrow_ray(G.render_sig, pos, y_ray, thickness, arrowhead_len, color_y);
|
||||
|
||||
//u32 color_quad = RGBA32_F(0, 1, 1, 0.3);
|
||||
//struct quad quad = quad_from_rect(RECT(0, 0, 1, -1));
|
||||
//quad = xform_mul_quad(xf, quad_scale(quad, 0.075f));
|
||||
//draw_quad(G.ui_sig, quad, color);
|
||||
//draw_quad(G.render_sig, quad, color);
|
||||
}
|
||||
|
||||
INTERNAL void debug_draw_movement(struct sim_ent *ent)
|
||||
@ -309,7 +306,7 @@ INTERNAL void debug_draw_movement(struct sim_ent *ent)
|
||||
struct v2 vel_ray = xform_basis_mul_v2(G.world_to_user_xf, velocity);
|
||||
|
||||
if (v2_len(vel_ray) > 0.00001) {
|
||||
draw_arrow_ray(G.ui_sig, pos, vel_ray, thickness, arrow_len, color_vel);
|
||||
draw_arrow_ray(G.render_sig, pos, vel_ray, thickness, arrow_len, color_vel);
|
||||
}
|
||||
}
|
||||
|
||||
@ -481,7 +478,7 @@ INTERNAL void draw_debug_console(i32 level, b32 minimized)
|
||||
if (log->level <= level) {
|
||||
/* Draw background */
|
||||
u32 color = colors[log->level][log->color_index];
|
||||
draw_quad(G.ui_sig, quad_from_rect(log->bounds), ALPHA32_F(color, opacity));
|
||||
draw_quad(G.render_sig, quad_from_rect(log->bounds), ALPHA32_F(color, opacity));
|
||||
|
||||
/* Draw text */
|
||||
struct string text = log->msg;
|
||||
@ -498,7 +495,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 rect bounds = draw_text(G.ui_sig, params);
|
||||
struct rect bounds = draw_text(G.render_sig, params);
|
||||
|
||||
struct rect draw_bounds = bounds;
|
||||
draw_bounds.x -= bg_margin;
|
||||
@ -1002,7 +999,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
struct v2 size = xform_basis_invert_mul_v2(G.world_to_user_xf, G.user_size);
|
||||
u32 color0 = RGBA32_F(0.17f, 0.17f, 0.17f, 1.f);
|
||||
u32 color1 = RGBA32_F(0.15f, 0.15f, 0.15f, 1.f);
|
||||
draw_grid(G.world_render_sig, xform_from_rect(RECT_FROM_V2(pos, size)), color0, color1, RGBA32(0x3f, 0x3f, 0x3f, 0xFF), COLOR_RED, COLOR_GREEN, thickness, spacing, offset);
|
||||
draw_grid(G.render_sig, xform_from_rect(RECT_FROM_V2(pos, size)), color0, color1, RGBA32(0x3f, 0x3f, 0x3f, 0xFF), COLOR_RED, COLOR_GREEN, thickness, spacing, offset);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -1186,9 +1183,9 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
u32 color_end = RGBA32_F(1, 0.8, 0.4, opacity_b);
|
||||
|
||||
if (opacity_b > 0.99f) {
|
||||
draw_circle(G.world_render_sig, b, thickness / 2, color_end, 20);
|
||||
draw_circle(G.render_sig, b, thickness / 2, color_end, 20);
|
||||
}
|
||||
draw_gradient_line(G.world_render_sig, a, b, thickness, color_start, color_end);
|
||||
draw_gradient_line(G.render_sig, a, b, thickness, color_start, color_end);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1204,7 +1201,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
u32 tint = ent->sprite_tint;
|
||||
struct sprite_sheet_frame frame = sprite_sheet_get_frame(sheet, ent->animation_frame);
|
||||
struct draw_material_params params = DRAW_MATERIAL_PARAMS(.xf = sprite_xform, .sprite = sprite, .tint = tint, .clip = frame.clip, .is_light = is_light, .light_emittance = emittance);
|
||||
draw_material(G.world_render_sig, params);
|
||||
draw_material(G.render_sig, params);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1224,7 +1221,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
struct v2 pos = sim_pos_from_world_tile_index(world_tile_index);
|
||||
struct xform tile_xf = xform_from_rect(RECT_FROM_V2(pos, V2(tile_size, tile_size)));
|
||||
struct draw_material_params params = DRAW_MATERIAL_PARAMS(.xf = tile_xf, .sprite = tile_sprite, .is_light = 1, .light_emittance = V3(0, 0, 0));
|
||||
draw_material(G.world_render_sig, params);
|
||||
draw_material(G.render_sig, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1252,7 +1249,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
u32 color = RGBA32_F(1, 0, 1, 0.5);
|
||||
struct quad quad = quad_from_aabb(aabb);
|
||||
quad = xform_mul_quad(G.world_to_user_xf, quad);
|
||||
draw_quad_line(G.ui_sig, quad, thickness, color);
|
||||
draw_quad_line(G.render_sig, quad, thickness, color);
|
||||
}
|
||||
|
||||
/* Draw focus arrow */
|
||||
@ -1263,7 +1260,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
start = xform_mul_v2(G.world_to_user_xf, start);
|
||||
struct v2 end = v2_add(xf.og, ent->control.focus);
|
||||
end = xform_mul_v2(G.world_to_user_xf, end);
|
||||
draw_arrow_line(G.ui_sig, start, end, 3, 10, RGBA32_F(1, 1, 1, 0.5));
|
||||
draw_arrow_line(G.render_sig, start, end, 3, 10, RGBA32_F(1, 1, 1, 0.5));
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -1289,16 +1286,16 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
struct quad quad = quad_from_rect(slice.rect);
|
||||
quad = xform_mul_quad(sprite_xform, quad);
|
||||
quad = xform_mul_quad(G.world_to_user_xf, quad);
|
||||
draw_quad_line(G.ui_sig, quad, 2, quad_color);
|
||||
draw_quad_line(G.render_sig, quad, 2, quad_color);
|
||||
}
|
||||
|
||||
draw_circle(G.ui_sig, center, 3, point_color, 20);
|
||||
draw_circle(G.render_sig, center, 3, point_color, 20);
|
||||
|
||||
if (slice.has_ray) {
|
||||
struct v2 ray = xform_basis_mul_v2(sprite_xform, slice.dir);
|
||||
ray = xform_basis_mul_v2(G.world_to_user_xf, ray);
|
||||
ray = v2_with_len(ray, 25);
|
||||
draw_arrow_ray(G.ui_sig, center, ray, 2, 10, ray_color);
|
||||
draw_arrow_ray(G.render_sig, center, ray, 2, 10, ray_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1315,7 +1312,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
f32 radius = 3;
|
||||
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);
|
||||
draw_circle(G.ui_sig, point, radius, color, 10);
|
||||
draw_circle(G.render_sig, point, radius, color, 10);
|
||||
|
||||
DEBUGBREAKABLE;
|
||||
}
|
||||
@ -1330,8 +1327,8 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
struct v2 point_end = G.world_cursor;
|
||||
point_start = xform_mul_v2(G.world_to_user_xf, point_start);
|
||||
point_end = xform_mul_v2(G.world_to_user_xf, point_end);
|
||||
draw_arrow_line(G.ui_sig, point_start, point_end, 3, 10, color);
|
||||
draw_circle(G.ui_sig, point_start, 4, color, 10);
|
||||
draw_arrow_line(G.render_sig, point_start, point_end, 3, 10, color);
|
||||
draw_circle(G.render_sig, point_start, 4, color, 10);
|
||||
}
|
||||
|
||||
/* Draw collider */
|
||||
@ -1343,13 +1340,13 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
/* Draw collider using support points */
|
||||
u32 detail = 32;
|
||||
struct xform collider_draw_xf = xform_mul(G.world_to_user_xf, xf);
|
||||
draw_collider_line(G.ui_sig, collider, collider_draw_xf, thickness, color, detail);
|
||||
draw_collider_line(G.render_sig, collider, collider_draw_xf, thickness, color, detail);
|
||||
}
|
||||
{
|
||||
/* Draw collider shape points */
|
||||
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]);
|
||||
draw_circle(G.ui_sig, p, 3, COLOR_BLUE, 10);
|
||||
draw_circle(G.render_sig, p, 3, COLOR_BLUE, 10);
|
||||
}
|
||||
}
|
||||
if (collider.count == 1 && collider.radius > 0) {
|
||||
@ -1358,14 +1355,14 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
struct v2 end = collider_get_support_point(&collider, xf, v2_neg(xf.by)).p;
|
||||
start = xform_mul_v2(G.world_to_user_xf, start);
|
||||
end = xform_mul_v2(G.world_to_user_xf, end);
|
||||
draw_line(G.ui_sig, start, end, thickness, color);
|
||||
draw_line(G.render_sig, start, end, thickness, color);
|
||||
}
|
||||
#if 0
|
||||
/* Draw support point at focus dir */
|
||||
{
|
||||
struct v2 p = collider_support_point(&collider, xf, ent->control.focus);
|
||||
p = xform_mul_v2(G.world_to_user_xf, p);
|
||||
draw_circle(G.ui_sig, p, 3, COLOR_RED, 10);
|
||||
draw_circle(G.render_sig, p, 3, COLOR_RED, 10);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1389,7 +1386,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
|
||||
/* Draw point */
|
||||
{
|
||||
draw_circle(G.ui_sig, xform_mul_v2(G.world_to_user_xf, dbg_pt), radius, color, 10);
|
||||
draw_circle(G.render_sig, xform_mul_v2(G.world_to_user_xf, dbg_pt), radius, color, 10);
|
||||
}
|
||||
|
||||
/* Draw normal */
|
||||
@ -1399,7 +1396,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
f32 arrow_height = 5;
|
||||
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)));
|
||||
draw_arrow_line(G.ui_sig, start, end, arrow_thickness, arrow_height, color);
|
||||
draw_arrow_line(G.render_sig, start, end, arrow_thickness, arrow_height, color);
|
||||
}
|
||||
#if 0
|
||||
/* Draw contact info */
|
||||
@ -1429,7 +1426,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
FMT_UINT(data->num_points));
|
||||
|
||||
|
||||
draw_text(G.ui_sig, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, dbg_pt)), V2(0, offset_px)), text);
|
||||
draw_text(G.render_sig, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, dbg_pt)), V2(0, offset_px)), text);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1457,8 +1454,8 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
u32 color = RGBA32_F(1, 1, 0, 0.5);
|
||||
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);
|
||||
draw_circle(G.ui_sig, a, radius, color, 10);
|
||||
draw_circle(G.ui_sig, b, radius, color, 10);
|
||||
draw_circle(G.render_sig, a, radius, color, 10);
|
||||
draw_circle(G.render_sig, b, radius, color, 10);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1475,28 +1472,28 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
{
|
||||
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);
|
||||
draw_line(G.ui_sig, a, b, thickness, color_line);
|
||||
draw_circle(G.ui_sig, a, radius, color_a, 10);
|
||||
draw_circle(G.ui_sig, b, radius, color_b, 10);
|
||||
draw_line(G.render_sig, a, b, thickness, color_line);
|
||||
draw_circle(G.render_sig, a, radius, color_a, 10);
|
||||
draw_circle(G.render_sig, b, radius, color_b, 10);
|
||||
|
||||
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);
|
||||
draw_line(G.ui_sig, a_clipped, b_clipped, thickness, color_line_clipped);
|
||||
draw_circle(G.ui_sig, a_clipped, radius, color_a_clipped, 10);
|
||||
draw_circle(G.ui_sig, b_clipped, radius, color_b_clipped, 10);
|
||||
draw_line(G.render_sig, a_clipped, b_clipped, thickness, color_line_clipped);
|
||||
draw_circle(G.render_sig, a_clipped, radius, color_a_clipped, 10);
|
||||
draw_circle(G.render_sig, b_clipped, radius, color_b_clipped, 10);
|
||||
}
|
||||
{
|
||||
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);
|
||||
draw_line(G.ui_sig, a, b, thickness, color_line);
|
||||
draw_circle(G.ui_sig, a, radius, color_a, 10);
|
||||
draw_circle(G.ui_sig, b, radius, color_b, 10);
|
||||
draw_line(G.render_sig, a, b, thickness, color_line);
|
||||
draw_circle(G.render_sig, a, radius, color_a, 10);
|
||||
draw_circle(G.render_sig, b, radius, color_b, 10);
|
||||
|
||||
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);
|
||||
draw_line(G.ui_sig, a_clipped, b_clipped, thickness, color_line_clipped);
|
||||
draw_circle(G.ui_sig, a_clipped, radius, color_a_clipped, 10);
|
||||
draw_circle(G.ui_sig, b_clipped, radius, color_b_clipped, 10);
|
||||
draw_line(G.render_sig, a_clipped, b_clipped, thickness, color_line_clipped);
|
||||
draw_circle(G.render_sig, a_clipped, radius, color_a_clipped, 10);
|
||||
draw_circle(G.render_sig, b_clipped, radius, color_b_clipped, 10);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1537,7 +1534,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
FMT_FLOAT_P(xform_get_rotation(e1_xf), 24));
|
||||
|
||||
|
||||
draw_text(G.ui_sig, 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.render_sig, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, V2(0, 0))), V2(0, offset_px)), text);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1553,8 +1550,8 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
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]);
|
||||
draw_poly_line(G.ui_sig, m, 1, thickness, color);
|
||||
//draw_poly(G.ui_sig, m, color);
|
||||
draw_poly_line(G.render_sig, m, 1, thickness, color);
|
||||
//draw_poly(G.render_sig, m, color);
|
||||
}
|
||||
|
||||
/* Draw cloud */
|
||||
@ -1566,7 +1563,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
|
||||
for (u64 i = 0; i < m.count; ++i) {
|
||||
struct v2 p = xform_mul_v2(G.world_to_user_xf, m.points[i]);
|
||||
draw_circle(G.ui_sig, p, radius, color, 10);
|
||||
draw_circle(G.render_sig, p, radius, color, 10);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1580,8 +1577,8 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
.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]);
|
||||
draw_poly_line(G.ui_sig, m, 1, thickness, color);
|
||||
for (u64 i = 0; i < m.count; ++i) draw_circle(G.ui_sig, m.points[i], 10, color, 10);
|
||||
draw_poly_line(G.render_sig, m, 1, thickness, color);
|
||||
for (u64 i = 0; i < m.count; ++i) draw_circle(G.render_sig, m.points[i], 10, color, 10);
|
||||
}
|
||||
|
||||
/* Draw simplex */
|
||||
@ -1599,18 +1596,18 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
|
||||
if (simplex.len >= 1) {
|
||||
u32 color = simplex.len == 1 ? color_first : (simplex.len == 2 ? color_second : color_third);
|
||||
draw_circle(G.ui_sig, simplex_array.points[0], thickness * 3, color, 10);
|
||||
draw_circle(G.render_sig, simplex_array.points[0], thickness * 3, color, 10);
|
||||
}
|
||||
if (simplex.len >= 2) {
|
||||
u32 color = simplex.len == 2 ? color_first : color_second;
|
||||
draw_circle(G.ui_sig, simplex_array.points[1], thickness * 3, color, 10);
|
||||
draw_circle(G.render_sig, simplex_array.points[1], thickness * 3, color, 10);
|
||||
}
|
||||
if (simplex.len >= 3) {
|
||||
u32 color = color_first;
|
||||
draw_circle(G.ui_sig, simplex_array.points[2], thickness * 3, color, 10);
|
||||
draw_circle(G.render_sig, simplex_array.points[2], thickness * 3, color, 10);
|
||||
}
|
||||
if (simplex.len >= 2) {
|
||||
draw_poly_line(G.ui_sig, simplex_array, simplex.len > 2, thickness, line_color);
|
||||
draw_poly_line(G.render_sig, simplex_array, simplex.len > 2, thickness, line_color);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1622,7 +1619,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
f32 arrowhead_height = 10;
|
||||
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));
|
||||
draw_arrow_line(G.ui_sig, start, end, arrow_thickness, arrowhead_height, color);
|
||||
draw_arrow_line(G.render_sig, start, end, arrow_thickness, arrowhead_height, color);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1637,7 +1634,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
|
||||
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);
|
||||
draw_arrow_line(G.ui_sig, start, end, thickness, arrow_height, color);
|
||||
draw_arrow_line(G.render_sig, start, end, thickness, arrow_height, color);
|
||||
}
|
||||
|
||||
/* Draw camera rect */
|
||||
@ -1649,7 +1646,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
struct quad quad = xform_mul_quad(quad_xf, QUAD_UNIT_SQUARE_CENTERED);
|
||||
quad = xform_mul_quad(G.world_to_user_xf, quad);
|
||||
|
||||
draw_quad_line(G.ui_sig, quad, thickness, color);
|
||||
draw_quad_line(G.render_sig, quad, thickness, color);
|
||||
}
|
||||
|
||||
arena_temp_end(temp);
|
||||
@ -1665,7 +1662,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
struct sprite_texture *t = sprite_texture_from_tag_async(sprite_frame_scope, crosshair);
|
||||
struct v2 size = V2(t->width, t->height);
|
||||
struct xform xf = XFORM_TRS(.t = crosshair_pos, .s = size);
|
||||
draw_ui(G.ui_sig, DRAW_UI_PARAMS(.xf = xf, .sprite = crosshair));
|
||||
draw_ui_rect(G.render_sig, DRAW_UI_RECT_PARAMS(.xf = xf, .sprite = crosshair));
|
||||
}
|
||||
|
||||
/* FIXME: Enable this */
|
||||
@ -1877,7 +1874,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
struct string dbg_text = ZI;
|
||||
dbg_text.text = arena_push_dry(temp.arena, u8);
|
||||
dbg_text.len += get_ent_debug_text(temp.arena, ent).len;
|
||||
draw_text(G.ui_sig, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = dbg_text));
|
||||
draw_text(G.render_sig, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = dbg_text));
|
||||
|
||||
arena_temp_end(temp);
|
||||
}
|
||||
@ -1992,12 +1989,12 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
//text.len += string_copy(temp.arena, LIT("\n")).len;
|
||||
#endif
|
||||
|
||||
//draw_text(G.ui_sig, 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_sig, font, pos, text);
|
||||
//draw_text(G.render_sig, 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.render_sig, font, pos, text);
|
||||
|
||||
struct v2 pos = V2(10, G.user_size.y);
|
||||
enum draw_text_offset_y offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM;
|
||||
draw_text(G.ui_sig, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = COLOR_WHITE));
|
||||
draw_text(G.render_sig, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = COLOR_WHITE));
|
||||
arena_temp_end(temp);
|
||||
}
|
||||
}
|
||||
@ -2025,35 +2022,19 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
struct v2i32 user_resolution = v2_round_to_int(user_viewport.size);
|
||||
struct v2i32 backbuffer_resolution = v2_round_to_int(G.screen_size);
|
||||
|
||||
/* Allocate user texture */
|
||||
if (!G.user_texture || !v2i32_eq(gp_texture_get_size(G.user_texture), user_resolution)) {
|
||||
if (G.user_texture) {
|
||||
gp_resource_release(G.user_texture);
|
||||
}
|
||||
G.user_texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R16G16B16A16_FLOAT, GP_TEXTURE_FLAG_TARGETABLE, user_resolution, 0);
|
||||
}
|
||||
|
||||
/* Draw world to user texture */
|
||||
struct gp_resource *render_texture = 0;
|
||||
{
|
||||
struct gp_render_params params = ZI;
|
||||
params.draw_target = G.user_texture;
|
||||
params.draw_target_size = user_resolution;
|
||||
params.draw_target_viewport = user_viewport;
|
||||
params.draw_target_view = G.world_to_user_xf;
|
||||
params.clear_target = 1;
|
||||
gp_run_render(G.world_render_sig, params);
|
||||
}
|
||||
|
||||
/* Draw ui to user texture */
|
||||
{
|
||||
struct gp_ui_params params = ZI;
|
||||
params.draw_target = G.user_texture;
|
||||
params.draw_target_viewport = user_viewport;
|
||||
params.draw_target_view = XFORM_IDENT;
|
||||
gp_run_ui(G.ui_sig, params);
|
||||
render_texture = gp_run_render(G.render_sig, params);
|
||||
}
|
||||
|
||||
/* Present */
|
||||
gp_present(G.swapchain, backbuffer_resolution, G.user_texture, XFORM_TRS(.t = v2_mul(G.screen_size, 0.5), .s = G.user_size), VSYNC);
|
||||
gp_present(G.swapchain, backbuffer_resolution, render_texture, XFORM_TRS(.t = v2_mul(G.screen_size, 0.5), .s = G.user_size), VSYNC);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
|
||||
Loading…
Reference in New Issue
Block a user