separate ui into its own pipeline
This commit is contained in:
parent
a403c07e8a
commit
0c1047bc9c
@ -141,3 +141,21 @@ SH_STRUCT(sh_shape_vert {
|
||||
SH_DECLS(float2, pos);
|
||||
SH_DECLS(uint, color_srgb);
|
||||
});
|
||||
|
||||
/* ========================== *
|
||||
* UI shader structures
|
||||
* ========================== */
|
||||
|
||||
SH_STRUCT(sh_ui_constants {
|
||||
SH_DECL(float4x4, projection);
|
||||
});
|
||||
SH_ASSERT_32BIT(struct sh_ui_constants, 16); /* Expected 32bit root constant size in shader */
|
||||
|
||||
SH_STRUCT(sh_ui_instance {
|
||||
SH_DECL(int, tex_nurid);
|
||||
SH_DECL(int, grid_id);
|
||||
SH_DECL(float2x3, xf);
|
||||
SH_DECL(float2, uv0);
|
||||
SH_DECL(float2, uv1);
|
||||
SH_DECL(uint, tint_srgb);
|
||||
});
|
||||
|
||||
@ -44,7 +44,7 @@ INLINE float4 get_light_in_dir(uint2 pos, float2 dir)
|
||||
uint2 flood = g_emittance_flood_textures[g_constants.emittance_flood_tex_urid][at];
|
||||
int2 dist_vec = (int2)at - (int2)flood;
|
||||
float dist = length(dist_vec);
|
||||
if (dist < 2) {
|
||||
if (dist <= 1) {
|
||||
result = g_gbuff_textures[g_constants.emittance_tex_urid][flood];
|
||||
break;
|
||||
} else {
|
||||
@ -70,12 +70,6 @@ INLINE float4 get_light_at_pos(uint2 pos)
|
||||
result /= SAMPLES;
|
||||
|
||||
return result;
|
||||
|
||||
|
||||
// float4 emittance = g_gbuff_textures[g_constants.emittance_tex_urid][pos];
|
||||
// uint2 emittance_flood = g_emittance_flood_textures[g_constants.emittance_flood_tex_urid][pos];
|
||||
// emittance_flood *= (emittance_flood.x < 0xFFFF && emittance_flood.y < 0xFFFF);
|
||||
// return float4(float(emittance_flood.x) / float(g_constants.tex_width), float(emittance_flood.y) / float(g_constants.tex_height), 0, 1);
|
||||
}
|
||||
|
||||
[numthreads(8, 8, 1)]
|
||||
@ -85,11 +79,10 @@ SH_ENTRY(ROOTSIG) void cs(struct cs_input input)
|
||||
if (id.x >= g_constants.tex_width || id.y >= g_constants.tex_height) {
|
||||
return; /* Overflow */
|
||||
}
|
||||
float4 old_color = g_gbuff_textures[g_constants.write_tex_urid][id];
|
||||
float4 albedo = g_gbuff_textures[g_constants.albedo_tex_urid][id];
|
||||
float4 lighting = get_light_at_pos(id);
|
||||
|
||||
float4 final_color = old_color + albedo + lighting;
|
||||
float4 final_color = albedo * lighting;
|
||||
|
||||
g_write_textures[g_constants.write_tex_urid][id] = final_color;
|
||||
}
|
||||
|
||||
86
res/sh/ui.hlsl
Normal file
86
res/sh/ui.hlsl
Normal file
@ -0,0 +1,86 @@
|
||||
#include "sh/common.hlsl"
|
||||
|
||||
/* ========================== *
|
||||
* Root signature
|
||||
* ========================== */
|
||||
|
||||
#define ROOTSIG \
|
||||
"RootConstants(num32BitConstants = 16, b0), " \
|
||||
"DescriptorTable(SRV(t0, space = 0, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)), " \
|
||||
"SRV(t0, space = 1), " \
|
||||
\
|
||||
"StaticSampler(s0, " \
|
||||
"filter = FILTER_MIN_MAG_MIP_POINT, " \
|
||||
"addressU = TEXTURE_ADDRESS_CLAMP, " \
|
||||
"addressV = TEXTURE_ADDRESS_CLAMP, " \
|
||||
"addressW = TEXTURE_ADDRESS_CLAMP, " \
|
||||
"maxAnisotropy = 1)"
|
||||
|
||||
ConstantBuffer<struct sh_ui_constants> g_constants : register(b0);
|
||||
Texture2D g_textures[] : register(t0, space0);
|
||||
StructuredBuffer<struct sh_ui_instance> g_instances : register(t0, space1);
|
||||
|
||||
SamplerState g_sampler : register(s0);
|
||||
|
||||
/* ========================== *
|
||||
* Vertex shader
|
||||
* ========================== */
|
||||
|
||||
struct vs_input {
|
||||
DECLS(uint, SV_InstanceID);
|
||||
DECLS(uint, SV_VertexID);
|
||||
};
|
||||
|
||||
struct vs_output {
|
||||
nointerpolation DECLS(int, tex_nurid);
|
||||
DECLS(float2, uv);
|
||||
DECLS(float4, tint_lin);
|
||||
DECLS(float4, SV_Position);
|
||||
};
|
||||
|
||||
SH_ENTRY(ROOTSIG) struct vs_output vs(struct vs_input input)
|
||||
{
|
||||
static const float2 unit_quad_verts[4] = {
|
||||
float2(-0.5f, -0.5f),
|
||||
float2(0.5f, -0.5f),
|
||||
float2(0.5f, 0.5f),
|
||||
float2(-0.5f, 0.5f)
|
||||
};
|
||||
|
||||
struct sh_ui_instance instance = g_instances[input.SV_InstanceID];
|
||||
float2 vert = unit_quad_verts[input.SV_VertexID];
|
||||
float2 world_pos = mul(instance.xf, float3(vert, 1)).xy;
|
||||
|
||||
struct vs_output output;
|
||||
output.SV_Position = mul(g_constants.projection, float4(world_pos, 0, 1));
|
||||
output.tex_nurid = instance.tex_nurid;
|
||||
output.uv = instance.uv0 + ((vert + 0.5) * (instance.uv1 - instance.uv0));
|
||||
output.tint_lin = linear_from_srgb32(instance.tint_srgb);
|
||||
return output;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Pixel shader
|
||||
* ========================== */
|
||||
|
||||
struct ps_input {
|
||||
struct vs_output vs;
|
||||
};
|
||||
|
||||
struct ps_output {
|
||||
DECLS(float4, SV_Target0);
|
||||
};
|
||||
|
||||
SH_ENTRY(ROOTSIG) struct ps_output ps(struct ps_input input)
|
||||
{
|
||||
struct ps_output output;
|
||||
float4 color = input.vs.tint_lin;
|
||||
|
||||
/* Texture */
|
||||
if (input.vs.tex_nurid >= 0) {
|
||||
color *= g_textures[NURID(input.vs.tex_nurid)].Sample(g_sampler, input.vs.uv);
|
||||
}
|
||||
|
||||
output.SV_Target0 = color;
|
||||
return output;
|
||||
}
|
||||
@ -622,7 +622,7 @@ void br_read_bytes(struct bitbuff_reader *br, struct string out)
|
||||
}
|
||||
}
|
||||
|
||||
/* Will return NULL on bitbuff overflow. Result should be checked. */
|
||||
/* Will return 0 on bitbuff overflow. Result should be checked. */
|
||||
u8 *br_read_bytes_raw(struct bitbuff_reader *br, u64 num_bytes)
|
||||
{
|
||||
br_align(br);
|
||||
|
||||
106
src/draw.c
106
src/draw.c
@ -23,38 +23,38 @@ struct draw_startup_receipt draw_startup(struct font_startup_receipt *font_sr)
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Texture
|
||||
* Material
|
||||
* ========================== */
|
||||
|
||||
void draw_texture(struct gp_sig *flow, struct draw_texture_params params)
|
||||
void draw_material(struct gp_render_sig *sig, struct draw_material_params params)
|
||||
{
|
||||
struct gp_cmd_desc cmd = ZI;
|
||||
cmd.kind = GP_CMD_KIND_DRAW_MATERIAL;
|
||||
struct gp_render_cmd_desc cmd = ZI;
|
||||
cmd.kind = GP_RENDER_CMD_KIND_DRAW_MATERIAL;
|
||||
cmd.material.xf = params.xf;
|
||||
cmd.material.sprite = params.sprite;
|
||||
cmd.material.texture = params.texture;
|
||||
cmd.material.clip = params.clip;
|
||||
cmd.material.tint = params.tint;
|
||||
cmd.material.emittance = params.emittance;
|
||||
gp_push_cmd(flow, &cmd);
|
||||
gp_push_render_cmd(sig, &cmd);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Fill shapes
|
||||
* ========================== */
|
||||
|
||||
void draw_poly_ex(struct gp_sig *flow, struct v2_array vertices, struct gp_indices indices, u32 color)
|
||||
void draw_poly_ex(struct gp_ui_sig *sig, struct v2_array vertices, struct gp_indices indices, u32 color)
|
||||
{
|
||||
struct gp_cmd_desc cmd = ZI;
|
||||
cmd.kind = GP_CMD_KIND_DRAW_SHAPE;
|
||||
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_cmd(flow, &cmd);
|
||||
gp_push_ui_cmd(sig, &cmd);
|
||||
}
|
||||
|
||||
/* Draws a filled polygon using triangles in a fan pattern */
|
||||
void draw_poly(struct gp_sig *flow, struct v2_array vertices, u32 color)
|
||||
void draw_poly(struct gp_ui_sig *sig, struct v2_array vertices, u32 color)
|
||||
{
|
||||
if (vertices.count >= 3) {
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
@ -74,13 +74,13 @@ void draw_poly(struct gp_sig *flow, struct v2_array vertices, u32 color)
|
||||
indices.indices[tri_offset + 2] = (i + 2);
|
||||
}
|
||||
|
||||
draw_poly_ex(flow, vertices, indices, color);
|
||||
draw_poly_ex(sig, vertices, indices, color);
|
||||
|
||||
scratch_end(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
void draw_circle(struct gp_sig *flow, struct v2 pos, f32 radius, u32 color, u32 detail)
|
||||
void draw_circle(struct gp_ui_sig *sig, struct v2 pos, f32 radius, u32 color, u32 detail)
|
||||
{
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
@ -98,12 +98,12 @@ void draw_circle(struct gp_sig *flow, struct v2 pos, f32 radius, u32 color, u32
|
||||
.points = points,
|
||||
.count = detail
|
||||
};
|
||||
draw_poly(flow, vertices, color);
|
||||
draw_poly(sig, vertices, color);
|
||||
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
void draw_quad(struct gp_sig *flow, struct quad quad, u32 color)
|
||||
void draw_quad(struct gp_ui_sig *sig, struct quad quad, u32 color)
|
||||
{
|
||||
LOCAL_PERSIST u32 indices_array[6] = {
|
||||
0, 1, 2,
|
||||
@ -111,57 +111,57 @@ void draw_quad(struct gp_sig *flow, struct quad quad, u32 color)
|
||||
};
|
||||
struct v2_array vertices = { .count = 4, .points = quad.e };
|
||||
struct gp_indices indices = { .count = 6, .indices = indices_array };
|
||||
draw_poly_ex(flow, vertices, indices, color);
|
||||
draw_poly_ex(sig, vertices, indices, color);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Line shapes
|
||||
* ========================== */
|
||||
|
||||
void draw_gradient_line(struct gp_sig *flow, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color)
|
||||
void draw_gradient_line(struct gp_ui_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);
|
||||
draw_texture(flow, DRAW_TEXTURE_PARAMS(.texture = G.solid_white_texture, .tint0 = start_color, .tint1 = end_color, .quad = quad));
|
||||
draw_material(sig, DRAW_MATERIAL_PARAMS(.texture = G.solid_white_texture, .tint0 = start_color, .tint1 = end_color, .quad = quad));
|
||||
#else
|
||||
/* Placeholder */
|
||||
(UNUSED)end_color;
|
||||
struct quad quad = quad_from_line(start, end, thickness);
|
||||
draw_quad(flow, quad, start_color);
|
||||
draw_quad(sig, quad, start_color);
|
||||
#endif
|
||||
}
|
||||
|
||||
void draw_line(struct gp_sig *flow, struct v2 start, struct v2 end, f32 thickness, u32 color)
|
||||
void draw_line(struct gp_ui_sig *sig, struct v2 start, struct v2 end, f32 thickness, u32 color)
|
||||
{
|
||||
struct quad quad = quad_from_line(start, end, thickness);
|
||||
draw_quad(flow, quad, color);
|
||||
draw_quad(sig, quad, color);
|
||||
}
|
||||
|
||||
void draw_ray(struct gp_sig *flow, struct v2 pos, struct v2 rel, f32 thickness, u32 color)
|
||||
void draw_ray(struct gp_ui_sig *sig, struct v2 pos, struct v2 rel, f32 thickness, u32 color)
|
||||
{
|
||||
struct quad quad = quad_from_ray(pos, rel, thickness);
|
||||
draw_quad(flow, quad, color);
|
||||
draw_quad(sig, quad, color);
|
||||
}
|
||||
|
||||
void draw_poly_line(struct gp_sig *flow, struct v2_array points, b32 loop, f32 thickness, u32 color)
|
||||
void draw_poly_line(struct gp_ui_sig *sig, struct v2_array points, b32 loop, f32 thickness, u32 color)
|
||||
{
|
||||
if (points.count >= 2) {
|
||||
for (u64 i = 1; i < points.count; ++i) {
|
||||
struct v2 p1 = points.points[i - 1];
|
||||
struct v2 p2 = points.points[i];
|
||||
struct quad q = quad_from_line(p1, p2, thickness);
|
||||
draw_quad(flow, q, color);
|
||||
draw_quad(sig, q, color);
|
||||
}
|
||||
if (loop && points.count > 2) {
|
||||
struct v2 p1 = points.points[points.count - 1];
|
||||
struct v2 p2 = points.points[0];
|
||||
struct quad q = quad_from_line(p1, p2, thickness);
|
||||
draw_quad(flow, q, color);
|
||||
draw_quad(sig, q, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_circle_line(struct gp_sig *flow, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail)
|
||||
void draw_circle_line(struct gp_ui_sig *sig, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail)
|
||||
{
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
@ -179,19 +179,19 @@ void draw_circle_line(struct gp_sig *flow, struct v2 pos, f32 radius, f32 thickn
|
||||
.points = points,
|
||||
.count = detail
|
||||
};
|
||||
draw_poly_line(flow, a, 1, thickness, color);
|
||||
draw_poly_line(sig, a, 1, thickness, color);
|
||||
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
void draw_quad_line(struct gp_sig *flow, struct quad quad, f32 thickness, u32 color)
|
||||
void draw_quad_line(struct gp_ui_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(flow, a, 1, thickness, color);
|
||||
draw_poly_line(sig, a, 1, thickness, color);
|
||||
}
|
||||
|
||||
void draw_arrow_line(struct gp_sig *flow, struct v2 start, struct v2 end, f32 thickness, f32 arrowhead_height, u32 color)
|
||||
void draw_arrow_line(struct gp_ui_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 */
|
||||
|
||||
@ -215,19 +215,19 @@ void draw_arrow_line(struct gp_sig *flow, struct v2 start, struct v2 end, f32 th
|
||||
.points = head_points,
|
||||
.count = countof(head_points)
|
||||
};
|
||||
draw_poly(flow, head_points_v2_array, color);
|
||||
draw_poly(sig, head_points_v2_array, color);
|
||||
|
||||
struct quad line_quad = quad_from_line(start, head_start, thickness);
|
||||
draw_quad(flow, line_quad, color);
|
||||
draw_quad(sig, line_quad, color);
|
||||
}
|
||||
|
||||
void draw_arrow_ray(struct gp_sig *flow, struct v2 pos, struct v2 rel, 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)
|
||||
{
|
||||
struct v2 end = v2_add(pos, rel);
|
||||
draw_arrow_line(flow, pos, end, thickness, arrowhead_height, color);
|
||||
draw_arrow_line(sig, pos, end, thickness, arrowhead_height, color);
|
||||
}
|
||||
|
||||
void draw_collider_line(struct gp_sig *flow, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail)
|
||||
void draw_collider_line(struct gp_ui_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;
|
||||
@ -248,7 +248,7 @@ void draw_collider_line(struct gp_sig *flow, struct collider_shape shape, struct
|
||||
poly.points[i] = p;
|
||||
}
|
||||
}
|
||||
draw_poly_line(flow, poly, 1, thickness, color);
|
||||
draw_poly_line(sig, poly, 1, thickness, color);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
@ -256,12 +256,12 @@ void draw_collider_line(struct gp_sig *flow, struct collider_shape shape, struct
|
||||
* Grid
|
||||
* ========================== */
|
||||
|
||||
void draw_grid(struct gp_sig *flow, struct xform xf, u32 bg0_color, u32 bg1_color, u32 line_color, u32 x_color, u32 y_color, f32 thickness, f32 spacing, struct v2 offset)
|
||||
void draw_grid(struct gp_render_sig *sig, struct xform xf, u32 bg0_color, u32 bg1_color, u32 line_color, u32 x_color, u32 y_color, f32 thickness, f32 spacing, struct v2 offset)
|
||||
{
|
||||
i32 grid_id = 0;
|
||||
{
|
||||
struct gp_cmd_desc cmd = ZI;
|
||||
cmd.kind = GP_CMD_KIND_PUSH_GRID;
|
||||
struct gp_render_cmd_desc cmd = ZI;
|
||||
cmd.kind = GP_RENDER_CMD_KIND_PUSH_GRID;
|
||||
cmd.grid.bg0_color = bg0_color;
|
||||
cmd.grid.bg1_color = bg1_color;
|
||||
cmd.grid.line_color = line_color;
|
||||
@ -270,15 +270,31 @@ void draw_grid(struct gp_sig *flow, struct xform xf, u32 bg0_color, u32 bg1_colo
|
||||
cmd.grid.line_thickness = thickness;
|
||||
cmd.grid.line_spacing = spacing;
|
||||
cmd.grid.offset = offset;
|
||||
grid_id = gp_push_cmd(flow, &cmd);
|
||||
grid_id = gp_push_render_cmd(sig, &cmd);
|
||||
}
|
||||
|
||||
struct gp_cmd_desc cmd = ZI;
|
||||
cmd.kind = GP_CMD_KIND_DRAW_MATERIAL;
|
||||
struct gp_render_cmd_desc cmd = ZI;
|
||||
cmd.kind = GP_RENDER_CMD_KIND_DRAW_MATERIAL;
|
||||
cmd.material.xf = xf;
|
||||
cmd.material.tint = COLOR_WHITE;
|
||||
cmd.material.grid_cmd_id = grid_id;
|
||||
gp_push_cmd(flow, &cmd);
|
||||
gp_push_render_cmd(sig, &cmd);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* UI
|
||||
* ========================== */
|
||||
|
||||
void draw_ui(struct gp_ui_sig *sig, struct draw_ui_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);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
@ -286,7 +302,7 @@ void draw_grid(struct gp_sig *flow, struct xform xf, u32 bg0_color, u32 bg1_colo
|
||||
* ========================== */
|
||||
|
||||
/* Returns the rect of the text area */
|
||||
struct rect draw_text(struct gp_sig *flow, struct draw_text_params params)
|
||||
struct rect draw_text(struct gp_ui_sig *sig, struct draw_text_params params)
|
||||
{
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
@ -454,7 +470,7 @@ struct rect draw_text(struct gp_sig *flow, 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_texture(flow, DRAW_TEXTURE_PARAMS(.xf = xf, .texture = params.font->texture, .tint = params.color, .clip = tg->clip));
|
||||
draw_ui(sig, DRAW_UI_PARAMS(.xf = xf, .texture = params.font->texture, .tint = params.color, .clip = tg->clip));
|
||||
draw_pos.x += tg->advance;
|
||||
|
||||
}
|
||||
|
||||
58
src/draw.h
58
src/draw.h
@ -10,16 +10,16 @@ struct draw_startup_receipt { i32 _; };
|
||||
struct draw_startup_receipt draw_startup(struct font_startup_receipt *font_sr);
|
||||
|
||||
/* ========================== *
|
||||
* Texture
|
||||
* Material
|
||||
* ========================== */
|
||||
|
||||
#define DRAW_TEXTURE_PARAMS(...) ((struct draw_texture_params) { \
|
||||
#define DRAW_MATERIAL_PARAMS(...) ((struct draw_material_params) { \
|
||||
.tint = COLOR_WHITE, \
|
||||
.clip = CLIP_ALL, \
|
||||
__VA_ARGS__ \
|
||||
})
|
||||
|
||||
struct draw_texture_params {
|
||||
struct draw_material_params {
|
||||
struct xform xf;
|
||||
struct gp_resource *texture; /* Overrides sprite if set */
|
||||
struct sprite_tag sprite;
|
||||
@ -28,47 +28,67 @@ struct draw_texture_params {
|
||||
u32 emittance;
|
||||
};
|
||||
|
||||
void draw_texture(struct gp_sig *flow, struct draw_texture_params params);
|
||||
void draw_material(struct gp_render_sig *sig, struct draw_material_params params);
|
||||
|
||||
/* ========================== *
|
||||
* Fill shapes
|
||||
* ========================== */
|
||||
|
||||
void draw_poly_ex(struct gp_sig *flow, struct v2_array vertices, struct gp_indices indices, u32 color);
|
||||
void draw_poly_ex(struct gp_ui_sig *sig, struct v2_array vertices, struct gp_indices indices, u32 color);
|
||||
|
||||
void draw_poly(struct gp_sig *flow, struct v2_array points, u32 color);
|
||||
void draw_poly(struct gp_ui_sig *sig, struct v2_array points, u32 color);
|
||||
|
||||
void draw_circle(struct gp_sig *flow, struct v2 pos, f32 radius, u32 color, u32 detail);
|
||||
void draw_circle(struct gp_ui_sig *sig, struct v2 pos, f32 radius, u32 color, u32 detail);
|
||||
|
||||
void draw_quad(struct gp_sig *flow, struct quad quad, u32 color);
|
||||
void draw_quad(struct gp_ui_sig *sig, struct quad quad, u32 color);
|
||||
|
||||
/* ========================== *
|
||||
* Line shapes
|
||||
* ========================== */
|
||||
|
||||
void draw_gradient_line(struct gp_sig *flow, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color);
|
||||
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_line(struct gp_sig *flow, struct v2 start, struct v2 end, f32 thickness, u32 color);
|
||||
void draw_line(struct gp_ui_sig *sig, struct v2 start, struct v2 end, f32 thickness, u32 color);
|
||||
|
||||
void draw_ray(struct gp_sig *flow, struct v2 pos, struct v2 rel, f32 thickness, u32 color);
|
||||
void draw_ray(struct gp_ui_sig *sig, struct v2 pos, struct v2 rel, f32 thickness, u32 color);
|
||||
|
||||
void draw_poly_line(struct gp_sig *flow, struct v2_array points, b32 loop, 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_circle_line(struct gp_sig *flow, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail);
|
||||
void draw_circle_line(struct gp_ui_sig *sig, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail);
|
||||
|
||||
void draw_quad_line(struct gp_sig *flow, struct quad quad, f32 thickness, u32 color);
|
||||
void draw_quad_line(struct gp_ui_sig *sig, struct quad quad, f32 thickness, u32 color);
|
||||
|
||||
void draw_arrow_line(struct gp_sig *flow, struct v2 start, struct v2 end, f32 thickness, f32 arrowhead_height, 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_ray(struct gp_sig *flow, struct v2 pos, struct v2 rel, 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_collider_line(struct gp_sig *flow, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail);
|
||||
void draw_collider_line(struct gp_ui_sig *sig, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail);
|
||||
|
||||
/* ========================== *
|
||||
* Grid
|
||||
* ========================== */
|
||||
|
||||
void draw_grid(struct gp_sig *flow, struct xform xf, u32 bg0_color, u32 bg1_color, u32 line_color, u32 x_color, u32 y_color, f32 thickness, f32 spacing, struct v2 offset);
|
||||
void draw_grid(struct gp_render_sig *sig, struct xform xf, u32 bg0_color, u32 bg1_color, u32 line_color, u32 x_color, u32 y_color, f32 thickness, f32 spacing, struct v2 offset);
|
||||
|
||||
/* ========================== *
|
||||
* UI
|
||||
* ========================== */
|
||||
|
||||
#define DRAW_UI_PARAMS(...) ((struct draw_ui_params) { \
|
||||
.tint = COLOR_WHITE, \
|
||||
.clip = CLIP_ALL, \
|
||||
__VA_ARGS__ \
|
||||
})
|
||||
|
||||
struct draw_ui_params {
|
||||
struct xform xf;
|
||||
struct gp_resource *texture; /* Overrides sprite if set */
|
||||
struct sprite_tag sprite;
|
||||
struct clip_rect clip;
|
||||
u32 tint;
|
||||
};
|
||||
|
||||
void draw_ui(struct gp_ui_sig *sig, struct draw_ui_params params);
|
||||
|
||||
/* ========================== *
|
||||
* Text
|
||||
@ -116,6 +136,6 @@ struct draw_text_params {
|
||||
struct string str;
|
||||
};
|
||||
|
||||
struct rect draw_text(struct gp_sig *flow, struct draw_text_params params);
|
||||
struct rect draw_text(struct gp_ui_sig *sig, struct draw_text_params params);
|
||||
|
||||
#endif
|
||||
|
||||
85
src/gp.h
85
src/gp.h
@ -4,6 +4,11 @@
|
||||
struct sys_window;
|
||||
struct snc_counter;
|
||||
|
||||
struct gp_indices {
|
||||
u32 count;
|
||||
u32 *indices;
|
||||
};
|
||||
|
||||
/* ========================== *
|
||||
* Startup
|
||||
* ========================== */
|
||||
@ -45,25 +50,19 @@ struct gp_resource *gp_texture_alloc(enum gp_texture_format format, u32 flags, s
|
||||
struct v2i32 gp_texture_get_size(struct gp_resource *texture);
|
||||
|
||||
/* ========================== *
|
||||
* Flow
|
||||
* Render
|
||||
* ========================== */
|
||||
|
||||
enum gp_cmd_kind {
|
||||
GP_CMD_KIND_NONE,
|
||||
GP_CMD_KIND_DRAW_SHAPE,
|
||||
GP_CMD_KIND_DRAW_MATERIAL,
|
||||
GP_CMD_KIND_PUSH_GRID,
|
||||
enum gp_render_cmd_kind {
|
||||
GP_RENDER_CMD_KIND_NONE,
|
||||
GP_RENDER_CMD_KIND_DRAW_MATERIAL,
|
||||
GP_RENDER_CMD_KIND_PUSH_GRID,
|
||||
|
||||
NUM_GP_CMD_KINDS
|
||||
NUM_GP_RENDER_CMD_KINDS
|
||||
};
|
||||
|
||||
struct gp_indices {
|
||||
u32 count;
|
||||
u32 *indices;
|
||||
};
|
||||
|
||||
struct gp_cmd_desc {
|
||||
enum gp_cmd_kind kind;
|
||||
struct gp_render_cmd_desc {
|
||||
enum gp_render_cmd_kind kind;
|
||||
union {
|
||||
struct {
|
||||
struct xform xf;
|
||||
@ -74,11 +73,6 @@ struct gp_cmd_desc {
|
||||
u32 emittance;
|
||||
i32 grid_cmd_id;
|
||||
} material;
|
||||
struct {
|
||||
struct v2_array vertices;
|
||||
struct gp_indices indices;
|
||||
u32 color;
|
||||
} shape;
|
||||
struct {
|
||||
f32 line_thickness;
|
||||
f32 line_spacing;
|
||||
@ -92,20 +86,63 @@ struct gp_cmd_desc {
|
||||
};
|
||||
};
|
||||
|
||||
struct gp_run_params {
|
||||
struct gp_sig *sig;
|
||||
struct gp_render_params {
|
||||
struct gp_resource *draw_target;
|
||||
struct rect draw_target_viewport;
|
||||
struct xform draw_target_view;
|
||||
b32 clear_target;
|
||||
};
|
||||
|
||||
struct gp_sig *gp_sig_alloc(void);
|
||||
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_cmd(struct gp_sig *gp_sig, struct gp_cmd_desc *desc);
|
||||
i32 gp_push_ui_cmd(struct gp_ui_sig *ui_sig, struct gp_ui_cmd_desc *desc);
|
||||
|
||||
void gp_run(struct gp_run_params params);
|
||||
void gp_run_ui(struct gp_ui_sig *ui_sig, struct gp_ui_params ui_params);
|
||||
|
||||
/* ========================== *
|
||||
* Memory info
|
||||
|
||||
716
src/gp_dx12.c
716
src/gp_dx12.c
@ -714,6 +714,18 @@ INTERNAL void dx12_init_pipelines(void)
|
||||
desc->rtvs[0].blending = 1;
|
||||
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
||||
}
|
||||
/* Material pipeline */
|
||||
{
|
||||
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
||||
desc->name = LIT("ui");
|
||||
desc->vs.file = LIT("sh/ui.hlsl");
|
||||
desc->ps.file = LIT("sh/ui.hlsl");
|
||||
desc->vs.func = LIT("vs");
|
||||
desc->ps.func = LIT("ps");
|
||||
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);
|
||||
}
|
||||
/* Blit pipeilne */
|
||||
{
|
||||
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
||||
@ -1565,153 +1577,6 @@ INTERNAL void cpu_descriptor_heap_release(struct cpu_descriptor_heap *dh)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ========================== *
|
||||
* Sig
|
||||
* ========================== */
|
||||
|
||||
struct sig {
|
||||
struct arena *arena;
|
||||
|
||||
/* Material instances */
|
||||
u32 num_material_instance_descs;
|
||||
struct arena *material_instance_descs_arena;
|
||||
|
||||
/* Grids */
|
||||
u32 num_material_grid_descs;
|
||||
struct arena *material_grid_descs_arena;
|
||||
|
||||
/* Shapes */
|
||||
struct arena *shape_verts_arena;
|
||||
struct arena *shape_indices_arena;
|
||||
|
||||
/* Resources */
|
||||
struct v2i32 old_size;
|
||||
struct dx12_resource *albedo;
|
||||
struct dx12_resource *emittance;
|
||||
struct dx12_resource *emittance_flood_a;
|
||||
struct dx12_resource *emittance_flood_b;
|
||||
|
||||
struct sig *next_free;
|
||||
};
|
||||
|
||||
struct material_instance_desc {
|
||||
struct xform xf;
|
||||
struct sprite_tag sprite;
|
||||
struct dx12_resource *texture;
|
||||
struct clip_rect clip;
|
||||
u32 tint;
|
||||
u32 emittance;
|
||||
i32 grid_id;
|
||||
};
|
||||
|
||||
struct material_grid_desc {
|
||||
f32 line_thickness;
|
||||
f32 line_spacing;
|
||||
struct v2 offset;
|
||||
u32 bg0_color;
|
||||
u32 bg1_color;
|
||||
u32 line_color;
|
||||
u32 x_color;
|
||||
u32 y_color;
|
||||
};
|
||||
|
||||
INTERNAL struct sig *sig_alloc(void)
|
||||
{
|
||||
__prof;
|
||||
struct sig *sig = 0;
|
||||
{
|
||||
struct arena *arena = arena_alloc(MEBI(64));
|
||||
sig = arena_push(arena, struct sig);
|
||||
sig->arena = arena;
|
||||
}
|
||||
|
||||
sig->material_instance_descs_arena = arena_alloc(GIBI(1));
|
||||
sig->material_grid_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 sig_reset(struct sig *sig)
|
||||
{
|
||||
__prof;
|
||||
|
||||
/* Reset material instances */
|
||||
sig->num_material_instance_descs = 0;
|
||||
arena_reset(sig->material_instance_descs_arena);
|
||||
|
||||
/* Reset grids */
|
||||
sig->num_material_grid_descs = 0;
|
||||
arena_reset(sig->material_grid_descs_arena);
|
||||
|
||||
/* Reset shapes */
|
||||
arena_reset(sig->shape_verts_arena);
|
||||
arena_reset(sig->shape_indices_arena);
|
||||
}
|
||||
|
||||
struct gp_sig *gp_sig_alloc(void)
|
||||
{
|
||||
__prof;
|
||||
struct sig *sig = sig_alloc();
|
||||
return (struct gp_sig *)sig;
|
||||
}
|
||||
|
||||
i32 gp_push_cmd(struct gp_sig *gp_sig, struct gp_cmd_desc *cmd_desc)
|
||||
{
|
||||
i32 ret = 0;
|
||||
struct sig *sig = (struct sig *)gp_sig;
|
||||
if (sig) {
|
||||
switch (cmd_desc->kind) {
|
||||
default: break;
|
||||
|
||||
case GP_CMD_KIND_DRAW_MATERIAL:
|
||||
{
|
||||
struct material_instance_desc *instance_desc = arena_push(sig->material_instance_descs_arena, struct material_instance_desc);
|
||||
instance_desc->xf = cmd_desc->material.xf;
|
||||
instance_desc->sprite = cmd_desc->material.sprite;
|
||||
instance_desc->texture = (struct dx12_resource *)cmd_desc->material.texture;
|
||||
instance_desc->clip = cmd_desc->material.clip;
|
||||
instance_desc->tint = cmd_desc->material.tint;
|
||||
instance_desc->emittance = cmd_desc->material.emittance;
|
||||
instance_desc->grid_id = cmd_desc->material.grid_cmd_id - 1;
|
||||
ret = ++sig->num_material_instance_descs;
|
||||
} break;
|
||||
|
||||
case GP_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;
|
||||
|
||||
case GP_CMD_KIND_PUSH_GRID:
|
||||
{
|
||||
struct material_grid_desc *grid_desc = arena_push(sig->material_grid_descs_arena, struct material_grid_desc);
|
||||
grid_desc->line_thickness = cmd_desc->grid.line_thickness;
|
||||
grid_desc->line_spacing = cmd_desc->grid.line_spacing;
|
||||
grid_desc->offset = cmd_desc->grid.offset;
|
||||
grid_desc->bg0_color = cmd_desc->grid.bg0_color;
|
||||
grid_desc->bg1_color = cmd_desc->grid.bg1_color;
|
||||
grid_desc->line_color = cmd_desc->grid.line_color;
|
||||
grid_desc->x_color = cmd_desc->grid.x_color;
|
||||
grid_desc->y_color = cmd_desc->grid.y_color;
|
||||
ret = ++sig->num_material_grid_descs;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Fenced release
|
||||
* ========================== */
|
||||
@ -2349,82 +2214,6 @@ INTERNAL struct command_buffer *command_list_push_buffer(struct command_list *cl
|
||||
return cb;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Util
|
||||
* ========================== */
|
||||
|
||||
INTERNAL void command_list_set_graphics_root_constant(struct command_list *cl, void *src, u32 size)
|
||||
{
|
||||
__prof;
|
||||
if (size % 4 == 0) {
|
||||
u32 num32bit = size / 4;
|
||||
for (u32 i = 0; i < num32bit; ++i) {
|
||||
u32 val = 0;
|
||||
MEMCPY(&val, (((u32 *)src) + i), 4);
|
||||
ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstant(cl->cl, 0, val, i);
|
||||
}
|
||||
} else {
|
||||
/* Root constant structs must pad to 32 bits */
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
INTERNAL void command_list_set_compute_root_constant(struct command_list *cl, void *src, u32 size)
|
||||
{
|
||||
__prof;
|
||||
if (size % 4 == 0) {
|
||||
u32 num32bit = size / 4;
|
||||
for (u32 i = 0; i < num32bit; ++i) {
|
||||
u32 val = 0;
|
||||
MEMCPY(&val, (((u32 *)src) + i), 4);
|
||||
ID3D12GraphicsCommandList_SetComputeRoot32BitConstant(cl->cl, 0, val, i);
|
||||
}
|
||||
} else {
|
||||
/* Root constant structs must pad to 32 bits */
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
INTERNAL struct D3D12_VIEWPORT viewport_from_rect(struct rect r)
|
||||
{
|
||||
struct D3D12_VIEWPORT viewport = ZI;
|
||||
viewport.TopLeftX = r.x;
|
||||
viewport.TopLeftY = r.y;
|
||||
viewport.Width = r.width;
|
||||
viewport.Height = r.height;
|
||||
viewport.MinDepth = 0.0f;
|
||||
viewport.MaxDepth = 1.0f;
|
||||
return viewport;
|
||||
}
|
||||
|
||||
INTERNAL D3D12_RECT scissor_from_rect(struct rect r)
|
||||
{
|
||||
D3D12_RECT scissor = ZI;
|
||||
scissor.left = r.x;
|
||||
scissor.top = r.y;
|
||||
scissor.right = r.x + r.width;
|
||||
scissor.bottom = r.y + r.height;
|
||||
return scissor;
|
||||
}
|
||||
|
||||
INTERNAL D3D12_VERTEX_BUFFER_VIEW vbv_from_command_buffer(struct command_buffer *cb, u32 vertex_size)
|
||||
{
|
||||
D3D12_VERTEX_BUFFER_VIEW vbv = ZI;
|
||||
vbv.BufferLocation = cb->resource->gpu_address;
|
||||
vbv.SizeInBytes = cb->size;
|
||||
vbv.StrideInBytes = vertex_size;
|
||||
return vbv;
|
||||
}
|
||||
|
||||
INTERNAL D3D12_INDEX_BUFFER_VIEW ibv_from_command_buffer(struct command_buffer *cb, DXGI_FORMAT format)
|
||||
{
|
||||
D3D12_INDEX_BUFFER_VIEW ibv = ZI;
|
||||
ibv.BufferLocation = cb->resource->gpu_address;
|
||||
ibv.Format = format;
|
||||
ibv.SizeInBytes = cb->size;
|
||||
return ibv;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Wait job
|
||||
* ========================== */
|
||||
@ -2449,7 +2238,6 @@ INTERNAL SYS_JOB_DEF(dx12_wait_fence_job, job)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ========================== *
|
||||
* Texture
|
||||
* ========================== */
|
||||
@ -2604,9 +2392,81 @@ struct v2i32 gp_texture_get_size(struct gp_resource *resource)
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Run
|
||||
* Run utils
|
||||
* ========================== */
|
||||
|
||||
INTERNAL void command_list_set_graphics_root_constant(struct command_list *cl, void *src, u32 size)
|
||||
{
|
||||
__prof;
|
||||
if (size % 4 == 0) {
|
||||
u32 num32bit = size / 4;
|
||||
for (u32 i = 0; i < num32bit; ++i) {
|
||||
u32 val = 0;
|
||||
MEMCPY(&val, (((u32 *)src) + i), 4);
|
||||
ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstant(cl->cl, 0, val, i);
|
||||
}
|
||||
} else {
|
||||
/* Root constant structs must pad to 32 bits */
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
INTERNAL void command_list_set_compute_root_constant(struct command_list *cl, void *src, u32 size)
|
||||
{
|
||||
__prof;
|
||||
if (size % 4 == 0) {
|
||||
u32 num32bit = size / 4;
|
||||
for (u32 i = 0; i < num32bit; ++i) {
|
||||
u32 val = 0;
|
||||
MEMCPY(&val, (((u32 *)src) + i), 4);
|
||||
ID3D12GraphicsCommandList_SetComputeRoot32BitConstant(cl->cl, 0, val, i);
|
||||
}
|
||||
} else {
|
||||
/* Root constant structs must pad to 32 bits */
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
INTERNAL struct D3D12_VIEWPORT viewport_from_rect(struct rect r)
|
||||
{
|
||||
struct D3D12_VIEWPORT viewport = ZI;
|
||||
viewport.TopLeftX = r.x;
|
||||
viewport.TopLeftY = r.y;
|
||||
viewport.Width = r.width;
|
||||
viewport.Height = r.height;
|
||||
viewport.MinDepth = 0.0f;
|
||||
viewport.MaxDepth = 1.0f;
|
||||
return viewport;
|
||||
}
|
||||
|
||||
INTERNAL D3D12_RECT scissor_from_rect(struct rect r)
|
||||
{
|
||||
D3D12_RECT scissor = ZI;
|
||||
scissor.left = r.x;
|
||||
scissor.top = r.y;
|
||||
scissor.right = r.x + r.width;
|
||||
scissor.bottom = r.y + r.height;
|
||||
return scissor;
|
||||
}
|
||||
|
||||
INTERNAL D3D12_VERTEX_BUFFER_VIEW vbv_from_command_buffer(struct command_buffer *cb, u32 vertex_size)
|
||||
{
|
||||
D3D12_VERTEX_BUFFER_VIEW vbv = ZI;
|
||||
vbv.BufferLocation = cb->resource->gpu_address;
|
||||
vbv.SizeInBytes = cb->size;
|
||||
vbv.StrideInBytes = vertex_size;
|
||||
return vbv;
|
||||
}
|
||||
|
||||
INTERNAL D3D12_INDEX_BUFFER_VIEW ibv_from_command_buffer(struct command_buffer *cb, DXGI_FORMAT format)
|
||||
{
|
||||
D3D12_INDEX_BUFFER_VIEW ibv = ZI;
|
||||
ibv.BufferLocation = cb->resource->gpu_address;
|
||||
ibv.Format = format;
|
||||
ibv.SizeInBytes = cb->size;
|
||||
return ibv;
|
||||
}
|
||||
|
||||
INTERNAL struct dx12_resource *gbuff_alloc(DXGI_FORMAT format, struct v2i32 size, D3D12_RESOURCE_STATES initial_state)
|
||||
{
|
||||
__prof;
|
||||
@ -2649,11 +2509,134 @@ INTERNAL D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_from_descriptor(struct descripto
|
||||
return res;
|
||||
}
|
||||
|
||||
void gp_run(struct gp_run_params params)
|
||||
/* ========================== *
|
||||
* Render sig
|
||||
* ========================== */
|
||||
|
||||
struct render_sig {
|
||||
struct arena *arena;
|
||||
|
||||
/* Material instances */
|
||||
u32 num_material_instance_descs;
|
||||
struct arena *material_instance_descs_arena;
|
||||
|
||||
/* Grids */
|
||||
u32 num_material_grid_descs;
|
||||
struct arena *material_grid_descs_arena;
|
||||
|
||||
/* Resources */
|
||||
struct v2i32 old_size;
|
||||
struct dx12_resource *albedo;
|
||||
struct dx12_resource *emittance;
|
||||
struct dx12_resource *emittance_flood_a;
|
||||
struct dx12_resource *emittance_flood_b;
|
||||
};
|
||||
|
||||
struct material_instance_desc {
|
||||
struct xform xf;
|
||||
struct sprite_tag sprite;
|
||||
struct dx12_resource *texture;
|
||||
struct clip_rect clip;
|
||||
u32 tint;
|
||||
u32 emittance;
|
||||
i32 grid_id;
|
||||
};
|
||||
|
||||
struct material_grid_desc {
|
||||
f32 line_thickness;
|
||||
f32 line_spacing;
|
||||
struct v2 offset;
|
||||
u32 bg0_color;
|
||||
u32 bg1_color;
|
||||
u32 line_color;
|
||||
u32 x_color;
|
||||
u32 y_color;
|
||||
};
|
||||
|
||||
INTERNAL struct render_sig *render_sig_alloc(void)
|
||||
{
|
||||
__prof;
|
||||
struct render_sig *sig = 0;
|
||||
{
|
||||
struct arena *arena = arena_alloc(MEBI(64));
|
||||
sig = arena_push(arena, struct render_sig);
|
||||
sig->arena = arena;
|
||||
}
|
||||
|
||||
sig->material_instance_descs_arena = arena_alloc(GIBI(1));
|
||||
sig->material_grid_descs_arena = arena_alloc(GIBI(1));
|
||||
|
||||
return sig;
|
||||
}
|
||||
|
||||
INTERNAL void render_sig_reset(struct render_sig *sig)
|
||||
{
|
||||
__prof;
|
||||
|
||||
/* Reset material instances */
|
||||
sig->num_material_instance_descs = 0;
|
||||
arena_reset(sig->material_instance_descs_arena);
|
||||
|
||||
/* Reset grids */
|
||||
sig->num_material_grid_descs = 0;
|
||||
arena_reset(sig->material_grid_descs_arena);
|
||||
}
|
||||
|
||||
struct gp_render_sig *gp_render_sig_alloc(void)
|
||||
{
|
||||
__prof;
|
||||
struct render_sig *sig = render_sig_alloc();
|
||||
return (struct gp_render_sig *)sig;
|
||||
}
|
||||
|
||||
i32 gp_push_render_cmd(struct gp_render_sig *render_sig, struct gp_render_cmd_desc *cmd_desc)
|
||||
{
|
||||
i32 ret = 0;
|
||||
struct render_sig *sig = (struct render_sig *)render_sig;
|
||||
if (sig) {
|
||||
switch (cmd_desc->kind) {
|
||||
default: break;
|
||||
|
||||
case GP_RENDER_CMD_KIND_DRAW_MATERIAL:
|
||||
{
|
||||
struct material_instance_desc *instance_desc = arena_push(sig->material_instance_descs_arena, struct material_instance_desc);
|
||||
instance_desc->xf = cmd_desc->material.xf;
|
||||
instance_desc->sprite = cmd_desc->material.sprite;
|
||||
instance_desc->texture = (struct dx12_resource *)cmd_desc->material.texture;
|
||||
instance_desc->clip = cmd_desc->material.clip;
|
||||
instance_desc->tint = cmd_desc->material.tint;
|
||||
instance_desc->emittance = cmd_desc->material.emittance;
|
||||
instance_desc->grid_id = cmd_desc->material.grid_cmd_id - 1;
|
||||
ret = ++sig->num_material_instance_descs;
|
||||
} 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);
|
||||
grid_desc->line_thickness = cmd_desc->grid.line_thickness;
|
||||
grid_desc->line_spacing = cmd_desc->grid.line_spacing;
|
||||
grid_desc->offset = cmd_desc->grid.offset;
|
||||
grid_desc->bg0_color = cmd_desc->grid.bg0_color;
|
||||
grid_desc->bg1_color = cmd_desc->grid.bg1_color;
|
||||
grid_desc->line_color = cmd_desc->grid.line_color;
|
||||
grid_desc->x_color = cmd_desc->grid.x_color;
|
||||
grid_desc->y_color = cmd_desc->grid.y_color;
|
||||
ret = ++sig->num_material_grid_descs;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Render
|
||||
* ========================== */
|
||||
|
||||
void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params params)
|
||||
{
|
||||
__prof;
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct sig *sig = (struct sig *)params.sig;
|
||||
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;
|
||||
|
||||
@ -2681,7 +2664,6 @@ void gp_run(struct gp_run_params params)
|
||||
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 *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);
|
||||
{
|
||||
@ -2748,19 +2730,12 @@ void gp_run(struct gp_run_params params)
|
||||
/* 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 *grid_buffer = command_list_push_buffer(cl, STRING(sizeof(*grids) * sig->num_material_grid_descs, (u8 *)grids));
|
||||
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);
|
||||
|
||||
/* Material pass */
|
||||
{
|
||||
__profn("Material pass");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Material pass", RGB32_F(0.5, 0.2, 0.2));
|
||||
|
||||
/* Bind gbuffers */
|
||||
{
|
||||
struct dx12_resource_barrier_desc barriers[] = {
|
||||
@ -2784,8 +2759,12 @@ void gp_run(struct gp_run_params params)
|
||||
ID3D12GraphicsCommandList_ClearRenderTargetView(cl->cl, sig->emittance->rtv_descriptor->handle, clear_color, 0, 0);
|
||||
}
|
||||
|
||||
/* Dispatch */
|
||||
/* Material pass */
|
||||
if (material_pipeline->success) {
|
||||
__profn("Material pass");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Material pass", RGB32_F(0.5, 0.2, 0.2));
|
||||
|
||||
/* Dispatch */
|
||||
__profn("Material pass run");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Material pass run", RGB32_F(0.5, 0.2, 0.2));
|
||||
|
||||
@ -2818,17 +2797,10 @@ void gp_run(struct gp_run_params params)
|
||||
ID3D12GraphicsCommandList_IASetIndexBuffer(cl->cl, &ibv);
|
||||
ID3D12GraphicsCommandList_DrawIndexedInstanced(cl->cl, 6, instance_count, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Flood pass */
|
||||
struct dx12_resource *emittance_flood_read = sig->emittance_flood_a;
|
||||
struct dx12_resource *emittance_flood_write = sig->emittance_flood_a;
|
||||
{
|
||||
__profn("Flood pass");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Flood pass", RGB32_F(0.5, 0.2, 0.2));
|
||||
|
||||
/* Transition emittance & emittance flood */
|
||||
struct dx12_resource *emittance_flood_read = sig->emittance_flood_a;
|
||||
struct dx12_resource *emittance_flood_write = sig->emittance_flood_a;
|
||||
{
|
||||
struct dx12_resource_barrier_desc barriers[] = {
|
||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->emittance, D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE },
|
||||
@ -2838,8 +2810,11 @@ void gp_run(struct gp_run_params params)
|
||||
dx12_resource_barriers(cl->cl, countof(barriers), barriers);
|
||||
}
|
||||
|
||||
/* Dispatch */
|
||||
/* Flood pass */
|
||||
if (flood_pipeline->success) {
|
||||
__profn("Flood pass");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Flood pass", RGB32_F(0.5, 0.2, 0.2));
|
||||
|
||||
/* Bind pipeline */
|
||||
ID3D12GraphicsCommandList_SetPipelineState(cl->cl, flood_pipeline->pso);
|
||||
ID3D12GraphicsCommandList_SetComputeRootSignature(cl->cl, flood_pipeline->rootsig);
|
||||
@ -2893,12 +2868,6 @@ void gp_run(struct gp_run_params params)
|
||||
++step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Shade pass */
|
||||
{
|
||||
__profn("Shade pass");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Shade pass", RGB32_F(0.5, 0.2, 0.2));
|
||||
|
||||
/* Transition gbuffers & final target */
|
||||
{
|
||||
@ -2920,8 +2889,12 @@ void gp_run(struct gp_run_params params)
|
||||
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);
|
||||
}
|
||||
|
||||
/* Dispatch */
|
||||
/* Shade pass */
|
||||
if (shade_pipeline->success) {
|
||||
__profn("Shade pass");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Shade pass", RGB32_F(0.5, 0.2, 0.2));
|
||||
|
||||
/* Dispatch */
|
||||
__profn("Shade pass run");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Shade pass run", RGB32_F(0.5, 0.2, 0.2));
|
||||
|
||||
@ -2950,11 +2923,182 @@ void gp_run(struct gp_run_params params)
|
||||
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);
|
||||
|
||||
/* Shape pass */
|
||||
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;
|
||||
{
|
||||
__profn("Shape pass");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Shape pass", RGB32_F(0.5, 0.2, 0.2));
|
||||
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);
|
||||
{
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Run", 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 */
|
||||
{
|
||||
@ -2965,6 +3109,59 @@ void gp_run(struct gp_run_params params)
|
||||
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);
|
||||
}
|
||||
|
||||
/* UI rect pass */
|
||||
{
|
||||
__profn("UI rect");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "UI rect", RGB32_F(0.5, 0.2, 0.2));
|
||||
|
||||
/* Dispatch */
|
||||
if (ui_pipeline->success) {
|
||||
__profn("UI rect run");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "UI rect run", RGB32_F(0.5, 0.2, 0.2));
|
||||
|
||||
/* Bind pipeline */
|
||||
ID3D12GraphicsCommandList_SetPipelineState(cl->cl, ui_pipeline->pso);
|
||||
ID3D12GraphicsCommandList_SetGraphicsRootSignature(cl->cl, ui_pipeline->rootsig);
|
||||
|
||||
/* Set Rasterizer State */
|
||||
D3D12_VIEWPORT viewport = viewport_from_rect(params.draw_target_viewport);
|
||||
D3D12_RECT scissor = scissor_from_rect(params.draw_target_viewport);
|
||||
ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport);
|
||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||
|
||||
/* Set constants */
|
||||
struct sh_ui_constants constants = ZI;
|
||||
constants.projection = sh_float4x4_from_mat4x4(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);
|
||||
|
||||
/* Draw */
|
||||
u32 instance_count = ui_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);
|
||||
ID3D12GraphicsCommandList_IASetVertexBuffers(cl->cl, 0, 1, &vbv);
|
||||
ID3D12GraphicsCommandList_IASetIndexBuffer(cl->cl, &ibv);
|
||||
ID3D12GraphicsCommandList_DrawIndexedInstanced(cl->cl, 6, instance_count, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Shape pass */
|
||||
{
|
||||
__profn("Shape pass");
|
||||
__profnc_dx12(cl->cq->prof, cl->cl, "Shape pass", RGB32_F(0.5, 0.2, 0.2));
|
||||
|
||||
/* Dispatch */
|
||||
if (shape_pipeline->success) {
|
||||
__profn("Shape pass run");
|
||||
@ -3002,9 +3199,12 @@ void gp_run(struct gp_run_params params)
|
||||
pipeline_scope_end(pipeline_scope);
|
||||
sprite_scope_end(sprite_scope);
|
||||
|
||||
sig->old_size = final_target_size;
|
||||
sig_reset(sig);
|
||||
ui_sig_reset(sig);
|
||||
scratch_end(scratch);
|
||||
#else
|
||||
(UNUSED)ui_sig;
|
||||
(UNUSED)params;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
|
||||
146
src/user.c
146
src/user.c
@ -69,8 +69,8 @@ GLOBAL struct {
|
||||
|
||||
/* Gpu resources */
|
||||
struct gp_resource *user_texture;
|
||||
struct gp_sig *world_gp_sig;
|
||||
struct gp_sig *ui_gp_sig;
|
||||
struct gp_render_sig *world_render_sig;
|
||||
struct gp_ui_sig *ui_sig;
|
||||
|
||||
struct xform world_to_user_xf;
|
||||
|
||||
@ -239,8 +239,8 @@ struct user_startup_receipt user_startup(struct font_startup_receipt *font_sr,
|
||||
|
||||
/* GPU handles */
|
||||
G.world_to_user_xf = XFORM_IDENT;
|
||||
G.world_gp_sig = gp_sig_alloc();
|
||||
G.ui_gp_sig = gp_sig_alloc();
|
||||
G.world_render_sig = gp_render_sig_alloc();
|
||||
G.ui_sig = gp_ui_sig_alloc();
|
||||
|
||||
G.console_logs_arena = arena_alloc(GIBI(64));
|
||||
//log_register_callback(debug_console_log_callback, LOG_LEVEL_SUCCESS);
|
||||
@ -286,13 +286,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_gp_sig, pos, x_ray, thickness, arrowhead_len, color_x);
|
||||
draw_arrow_ray(G.ui_gp_sig, pos, y_ray, thickness, arrowhead_len, color_y);
|
||||
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);
|
||||
|
||||
//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_gp_sig, quad, color);
|
||||
//draw_quad(G.ui_sig, quad, color);
|
||||
}
|
||||
|
||||
INTERNAL void debug_draw_movement(struct sim_ent *ent)
|
||||
@ -309,7 +309,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_gp_sig, pos, vel_ray, thickness, arrow_len, color_vel);
|
||||
draw_arrow_ray(G.ui_sig, pos, vel_ray, thickness, arrow_len, color_vel);
|
||||
}
|
||||
}
|
||||
|
||||
@ -481,7 +481,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_gp_sig, quad_from_rect(log->bounds), ALPHA32_F(color, opacity));
|
||||
draw_quad(G.ui_sig, quad_from_rect(log->bounds), ALPHA32_F(color, opacity));
|
||||
|
||||
/* Draw text */
|
||||
struct string text = log->msg;
|
||||
@ -498,7 +498,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_gp_sig, params);
|
||||
struct rect bounds = draw_text(G.ui_sig, params);
|
||||
|
||||
struct rect draw_bounds = bounds;
|
||||
draw_bounds.x -= bg_margin;
|
||||
@ -1002,7 +1002,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_gp_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.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);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -1153,6 +1153,8 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
struct xform sprite_xform = xform_mul(xf, ent->sprite_local_xform);
|
||||
|
||||
/* Draw tracer */
|
||||
/* TODO: Enable this */
|
||||
#if 0
|
||||
if (sim_ent_has_prop(ent, SEPROP_TRACER)) {
|
||||
struct v2 velocity = ent->tracer_start_velocity;
|
||||
|
||||
@ -1184,11 +1186,11 @@ 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_gp_sig, b, thickness / 2, color_end, 20);
|
||||
draw_circle(G.world_render_sig, b, thickness / 2, color_end, 20);
|
||||
}
|
||||
draw_gradient_line(G.world_gp_sig, a, b, thickness, color_start, color_end);
|
||||
|
||||
draw_gradient_line(G.world_render_sig, a, b, thickness, color_start, color_end);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Draw sprite */
|
||||
if (!sprite_tag_is_nil(sprite)) {
|
||||
@ -1201,8 +1203,8 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
u32 emittance = is_light ? COLOR_WHITE : 0;
|
||||
u32 tint = ent->sprite_tint;
|
||||
struct sprite_sheet_frame frame = sprite_sheet_get_frame(sheet, ent->animation_frame);
|
||||
struct draw_texture_params params = DRAW_TEXTURE_PARAMS(.xf = sprite_xform, .sprite = sprite, .tint = tint, .clip = frame.clip, .emittance = emittance);
|
||||
draw_texture(G.world_gp_sig, params);
|
||||
struct draw_material_params params = DRAW_MATERIAL_PARAMS(.xf = sprite_xform, .sprite = sprite, .tint = tint, .clip = frame.clip, .emittance = emittance);
|
||||
draw_material(G.world_render_sig, params);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1221,8 +1223,8 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
struct v2i32 world_tile_index = sim_world_tile_index_from_local_tile_index(chunk_index, local_tile_index);
|
||||
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_texture_params params = DRAW_TEXTURE_PARAMS(.xf = tile_xf, .sprite = tile_sprite, .emittance = COLOR_BLACK);
|
||||
draw_texture(G.world_gp_sig, params);
|
||||
struct draw_material_params params = DRAW_MATERIAL_PARAMS(.xf = tile_xf, .sprite = tile_sprite, .emittance = COLOR_BLACK);
|
||||
draw_material(G.world_render_sig, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1250,7 +1252,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_gp_sig, quad, thickness, color);
|
||||
draw_quad_line(G.ui_sig, quad, thickness, color);
|
||||
}
|
||||
|
||||
/* Draw focus arrow */
|
||||
@ -1261,7 +1263,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_gp_sig, start, end, 3, 10, RGBA32_F(1, 1, 1, 0.5));
|
||||
draw_arrow_line(G.ui_sig, start, end, 3, 10, RGBA32_F(1, 1, 1, 0.5));
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -1287,16 +1289,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_gp_sig, quad, 2, quad_color);
|
||||
draw_quad_line(G.ui_sig, quad, 2, quad_color);
|
||||
}
|
||||
|
||||
draw_circle(G.ui_gp_sig, center, 3, point_color, 20);
|
||||
draw_circle(G.ui_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_gp_sig, center, ray, 2, 10, ray_color);
|
||||
draw_arrow_ray(G.ui_sig, center, ray, 2, 10, ray_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1313,7 +1315,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_gp_sig, point, radius, color, 10);
|
||||
draw_circle(G.ui_sig, point, radius, color, 10);
|
||||
|
||||
DEBUGBREAKABLE;
|
||||
}
|
||||
@ -1328,8 +1330,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_gp_sig, point_start, point_end, 3, 10, color);
|
||||
draw_circle(G.ui_gp_sig, point_start, 4, color, 10);
|
||||
draw_arrow_line(G.ui_sig, point_start, point_end, 3, 10, color);
|
||||
draw_circle(G.ui_sig, point_start, 4, color, 10);
|
||||
}
|
||||
|
||||
/* Draw collider */
|
||||
@ -1341,13 +1343,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_gp_sig, collider, collider_draw_xf, thickness, color, detail);
|
||||
draw_collider_line(G.ui_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_gp_sig, p, 3, COLOR_BLUE, 10);
|
||||
draw_circle(G.ui_sig, p, 3, COLOR_BLUE, 10);
|
||||
}
|
||||
}
|
||||
if (collider.count == 1 && collider.radius > 0) {
|
||||
@ -1356,14 +1358,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_gp_sig, start, end, thickness, color);
|
||||
draw_line(G.ui_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_gp_sig, p, 3, COLOR_RED, 10);
|
||||
draw_circle(G.ui_sig, p, 3, COLOR_RED, 10);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1387,7 +1389,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
|
||||
/* Draw point */
|
||||
{
|
||||
draw_circle(G.ui_gp_sig, xform_mul_v2(G.world_to_user_xf, dbg_pt), radius, color, 10);
|
||||
draw_circle(G.ui_sig, xform_mul_v2(G.world_to_user_xf, dbg_pt), radius, color, 10);
|
||||
}
|
||||
|
||||
/* Draw normal */
|
||||
@ -1397,7 +1399,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_gp_sig, start, end, arrow_thickness, arrow_height, color);
|
||||
draw_arrow_line(G.ui_sig, start, end, arrow_thickness, arrow_height, color);
|
||||
}
|
||||
#if 0
|
||||
/* Draw contact info */
|
||||
@ -1427,7 +1429,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
FMT_UINT(data->num_points));
|
||||
|
||||
|
||||
draw_text(G.ui_gp_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.ui_sig, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, dbg_pt)), V2(0, offset_px)), text);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1455,8 +1457,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_gp_sig, a, radius, color, 10);
|
||||
draw_circle(G.ui_gp_sig, b, radius, color, 10);
|
||||
draw_circle(G.ui_sig, a, radius, color, 10);
|
||||
draw_circle(G.ui_sig, b, radius, color, 10);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1473,28 +1475,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_gp_sig, a, b, thickness, color_line);
|
||||
draw_circle(G.ui_gp_sig, a, radius, color_a, 10);
|
||||
draw_circle(G.ui_gp_sig, b, radius, color_b, 10);
|
||||
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);
|
||||
|
||||
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_gp_sig, a_clipped, b_clipped, thickness, color_line_clipped);
|
||||
draw_circle(G.ui_gp_sig, a_clipped, radius, color_a_clipped, 10);
|
||||
draw_circle(G.ui_gp_sig, b_clipped, radius, color_b_clipped, 10);
|
||||
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);
|
||||
}
|
||||
{
|
||||
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_gp_sig, a, b, thickness, color_line);
|
||||
draw_circle(G.ui_gp_sig, a, radius, color_a, 10);
|
||||
draw_circle(G.ui_gp_sig, b, radius, color_b, 10);
|
||||
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);
|
||||
|
||||
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_gp_sig, a_clipped, b_clipped, thickness, color_line_clipped);
|
||||
draw_circle(G.ui_gp_sig, a_clipped, radius, color_a_clipped, 10);
|
||||
draw_circle(G.ui_gp_sig, b_clipped, radius, color_b_clipped, 10);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1535,7 +1537,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
FMT_FLOAT_P(xform_get_rotation(e1_xf), 24));
|
||||
|
||||
|
||||
draw_text(G.ui_gp_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.ui_sig, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, V2(0, 0))), V2(0, offset_px)), text);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1551,8 +1553,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_gp_sig, m, 1, thickness, color);
|
||||
//draw_poly(G.ui_gp_sig, m, color);
|
||||
draw_poly_line(G.ui_sig, m, 1, thickness, color);
|
||||
//draw_poly(G.ui_sig, m, color);
|
||||
}
|
||||
|
||||
/* Draw cloud */
|
||||
@ -1564,7 +1566,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_gp_sig, p, radius, color, 10);
|
||||
draw_circle(G.ui_sig, p, radius, color, 10);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1578,8 +1580,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_gp_sig, m, 1, thickness, color);
|
||||
for (u64 i = 0; i < m.count; ++i) draw_circle(G.ui_gp_sig, m.points[i], 10, color, 10);
|
||||
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 simplex */
|
||||
@ -1597,18 +1599,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_gp_sig, simplex_array.points[0], thickness * 3, color, 10);
|
||||
draw_circle(G.ui_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_gp_sig, simplex_array.points[1], thickness * 3, color, 10);
|
||||
draw_circle(G.ui_sig, simplex_array.points[1], thickness * 3, color, 10);
|
||||
}
|
||||
if (simplex.len >= 3) {
|
||||
u32 color = color_first;
|
||||
draw_circle(G.ui_gp_sig, simplex_array.points[2], thickness * 3, color, 10);
|
||||
draw_circle(G.ui_sig, simplex_array.points[2], thickness * 3, color, 10);
|
||||
}
|
||||
if (simplex.len >= 2) {
|
||||
draw_poly_line(G.ui_gp_sig, simplex_array, simplex.len > 2, thickness, line_color);
|
||||
draw_poly_line(G.ui_sig, simplex_array, simplex.len > 2, thickness, line_color);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1620,7 +1622,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_gp_sig, start, end, arrow_thickness, arrowhead_height, color);
|
||||
draw_arrow_line(G.ui_sig, start, end, arrow_thickness, arrowhead_height, color);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1635,7 +1637,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_gp_sig, start, end, thickness, arrow_height, color);
|
||||
draw_arrow_line(G.ui_sig, start, end, thickness, arrow_height, color);
|
||||
}
|
||||
|
||||
/* Draw camera rect */
|
||||
@ -1647,7 +1649,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_gp_sig, quad, thickness, color);
|
||||
draw_quad_line(G.ui_sig, quad, thickness, color);
|
||||
}
|
||||
|
||||
arena_temp_end(temp);
|
||||
@ -1663,7 +1665,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_texture(G.ui_gp_sig, DRAW_TEXTURE_PARAMS(.xf = xf, .sprite = crosshair));
|
||||
draw_ui(G.ui_sig, DRAW_UI_PARAMS(.xf = xf, .sprite = crosshair));
|
||||
}
|
||||
|
||||
/* FIXME: Enable this */
|
||||
@ -1875,7 +1877,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_gp_sig, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = dbg_text));
|
||||
draw_text(G.ui_sig, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = dbg_text));
|
||||
|
||||
arena_temp_end(temp);
|
||||
}
|
||||
@ -1990,12 +1992,12 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
//text.len += string_copy(temp.arena, LIT("\n")).len;
|
||||
#endif
|
||||
|
||||
//draw_text(G.ui_gp_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_gp_sig, font, pos, text);
|
||||
//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);
|
||||
|
||||
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_gp_sig, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = COLOR_WHITE));
|
||||
draw_text(G.ui_sig, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = COLOR_WHITE));
|
||||
arena_temp_end(temp);
|
||||
}
|
||||
}
|
||||
@ -2031,25 +2033,23 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
G.user_texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, GP_TEXTURE_FLAG_TARGETABLE, user_resolution, 0);
|
||||
}
|
||||
|
||||
/* Render world to user texture */
|
||||
/* Draw world to user texture */
|
||||
{
|
||||
struct gp_run_params params = ZI;
|
||||
params.sig = G.world_gp_sig;
|
||||
struct gp_render_params params = ZI;
|
||||
params.draw_target = G.user_texture;
|
||||
params.draw_target_viewport = user_viewport;
|
||||
params.draw_target_view = G.world_to_user_xf;
|
||||
params.clear_target = 1;
|
||||
gp_run(params);
|
||||
gp_run_render(G.world_render_sig, params);
|
||||
}
|
||||
|
||||
/* Render ui to user texture */
|
||||
/* Draw ui to user texture */
|
||||
{
|
||||
struct gp_run_params params = ZI;
|
||||
params.sig = G.ui_gp_sig;
|
||||
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(params);
|
||||
gp_run_ui(G.ui_sig, params);
|
||||
}
|
||||
|
||||
/* Present */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user