rename layer 'gpu' -> 'gp'
This commit is contained in:
parent
40e7abcc4e
commit
4313b1c768
6
build.c
6
build.c
@ -867,15 +867,15 @@ void OnBuild(StringList cli_args)
|
|||||||
if (is_c || is_cpp) {
|
if (is_c || is_cpp) {
|
||||||
if (StringBeginsWith(name, Lit("sys_")) ||
|
if (StringBeginsWith(name, Lit("sys_")) ||
|
||||||
StringBeginsWith(name, Lit("sock_")) ||
|
StringBeginsWith(name, Lit("sock_")) ||
|
||||||
StringBeginsWith(name, Lit("gpu_")) ||
|
StringBeginsWith(name, Lit("gp_")) ||
|
||||||
StringBeginsWith(name, Lit("playback_")) ||
|
StringBeginsWith(name, Lit("playback_")) ||
|
||||||
StringBeginsWith(name, Lit("mp3_")) ||
|
StringBeginsWith(name, Lit("mp3_")) ||
|
||||||
StringBeginsWith(name, Lit("ttf_"))) {
|
StringBeginsWith(name, Lit("ttf_"))) {
|
||||||
if (PlatformWindows) {
|
if (PlatformWindows) {
|
||||||
ignore = !(StringEqual(name, Lit("sys_win32.c")) ||
|
ignore = !(StringEqual(name, Lit("sys_win32.c")) ||
|
||||||
StringEqual(name, Lit("sock_win32.c")) ||
|
StringEqual(name, Lit("sock_win32.c")) ||
|
||||||
StringEqual(name, Lit("gpu_dx11.c")) ||
|
StringEqual(name, Lit("gp_dx11.c")) ||
|
||||||
StringEqual(name, Lit("gpu_dx12.c")) ||
|
StringEqual(name, Lit("gp_dx12.c")) ||
|
||||||
StringEqual(name, Lit("playback_wasapi.c")) ||
|
StringEqual(name, Lit("playback_wasapi.c")) ||
|
||||||
StringEqual(name, Lit("mp3_mmf.c")) ||
|
StringEqual(name, Lit("mp3_mmf.c")) ||
|
||||||
StringEqual(name, Lit("ttf_dwrite.cpp")));
|
StringEqual(name, Lit("ttf_dwrite.cpp")));
|
||||||
|
|||||||
12
src/app.c
12
src/app.c
@ -20,7 +20,7 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
#include "gpu.h"
|
#include "gp.h"
|
||||||
#include "phys.h"
|
#include "phys.h"
|
||||||
#include "sock.h"
|
#include "sock.h"
|
||||||
#include "host.h"
|
#include "host.h"
|
||||||
@ -323,16 +323,16 @@ void app_entry_point(struct string args_str)
|
|||||||
struct host_startup_receipt host_sr = host_startup(&sock_sr);
|
struct host_startup_receipt host_sr = host_startup(&sock_sr);
|
||||||
struct resource_startup_receipt resource_sr = resource_startup();
|
struct resource_startup_receipt resource_sr = resource_startup();
|
||||||
struct work_startup_receipt work_sr = work_startup(worker_count);
|
struct work_startup_receipt work_sr = work_startup(worker_count);
|
||||||
struct gpu_startup_receipt gpu_sr = gpu_startup(&work_sr, window);
|
struct gp_startup_receipt gp_sr = gp_startup(&work_sr, window);
|
||||||
struct asset_cache_startup_receipt asset_cache_sr = asset_cache_startup(&work_sr);
|
struct asset_cache_startup_receipt asset_cache_sr = asset_cache_startup(&work_sr);
|
||||||
struct ttf_startup_receipt ttf_sr = ttf_startup();
|
struct ttf_startup_receipt ttf_sr = ttf_startup();
|
||||||
struct font_startup_receipt font_sr = font_startup(&work_sr, &gpu_sr, &asset_cache_sr, &ttf_sr, &resource_sr);
|
struct font_startup_receipt font_sr = font_startup(&work_sr, &gp_sr, &asset_cache_sr, &ttf_sr, &resource_sr);
|
||||||
struct sprite_startup_receipt sprite_sr = sprite_startup(&gpu_sr, &resource_sr);
|
struct sprite_startup_receipt sprite_sr = sprite_startup(&gp_sr, &resource_sr);
|
||||||
struct mixer_startup_receipt mixer_sr = mixer_startup();
|
struct mixer_startup_receipt mixer_sr = mixer_startup();
|
||||||
struct sound_startup_receipt sound_sr = sound_startup(&work_sr, &asset_cache_sr, &resource_sr);
|
struct sound_startup_receipt sound_sr = sound_startup(&work_sr, &asset_cache_sr, &resource_sr);
|
||||||
struct draw_startup_receipt draw_sr = draw_startup(&gpu_sr, &font_sr);
|
struct draw_startup_receipt draw_sr = draw_startup(&gp_sr, &font_sr);
|
||||||
struct sim_startup_receipt sim_sr = sim_startup();
|
struct sim_startup_receipt sim_sr = sim_startup();
|
||||||
struct user_startup_receipt user_sr = user_startup(&work_sr, &gpu_sr, &font_sr, &sprite_sr, &draw_sr, &asset_cache_sr, &sound_sr, &mixer_sr, &host_sr, &sim_sr, connect_address, window);
|
struct user_startup_receipt user_sr = user_startup(&work_sr, &gp_sr, &font_sr, &sprite_sr, &draw_sr, &asset_cache_sr, &sound_sr, &mixer_sr, &host_sr, &sim_sr, connect_address, window);
|
||||||
struct playback_startup_receipt playback_sr = playback_startup(&mixer_sr);
|
struct playback_startup_receipt playback_sr = playback_startup(&mixer_sr);
|
||||||
|
|
||||||
(UNUSED)user_sr;
|
(UNUSED)user_sr;
|
||||||
|
|||||||
64
src/draw.c
64
src/draw.c
@ -1,5 +1,5 @@
|
|||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "gpu.h"
|
#include "gp.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
#include "scratch.h"
|
#include "scratch.h"
|
||||||
@ -7,20 +7,20 @@
|
|||||||
#include "collider.h"
|
#include "collider.h"
|
||||||
|
|
||||||
GLOBAL struct {
|
GLOBAL struct {
|
||||||
struct gpu_handle solid_white_texture;
|
struct gp_handle solid_white_texture;
|
||||||
} G = ZI, DEBUG_ALIAS(G, G_draw);
|
} G = ZI, DEBUG_ALIAS(G, G_draw);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Startup
|
* Startup
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct draw_startup_receipt draw_startup(struct gpu_startup_receipt *gpu_sr,
|
struct draw_startup_receipt draw_startup(struct gp_startup_receipt *gp_sr,
|
||||||
struct font_startup_receipt *font_sr)
|
struct font_startup_receipt *font_sr)
|
||||||
{
|
{
|
||||||
(UNUSED)gpu_sr;
|
(UNUSED)gp_sr;
|
||||||
(UNUSED)font_sr;
|
(UNUSED)font_sr;
|
||||||
u32 pixel_white = 0xFFFFFFFF;
|
u32 pixel_white = 0xFFFFFFFF;
|
||||||
G.solid_white_texture = gpu_texture_alloc(GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, V2I32(1, 1), &pixel_white);
|
G.solid_white_texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, V2I32(1, 1), &pixel_white);
|
||||||
return (struct draw_startup_receipt) { 0 };
|
return (struct draw_startup_receipt) { 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,35 +28,35 @@ struct draw_startup_receipt draw_startup(struct gpu_startup_receipt *gpu_sr,
|
|||||||
* Texture
|
* Texture
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
void draw_texture(struct gpu_handle plan, struct draw_texture_params params)
|
void draw_texture(struct gp_handle plan, struct draw_texture_params params)
|
||||||
{
|
{
|
||||||
struct gpu_cmd_params cmd = ZI;
|
struct gp_cmd_params cmd = ZI;
|
||||||
cmd.kind = GPU_CMD_KIND_DRAW_TEXTURE;
|
cmd.kind = GP_CMD_KIND_DRAW_TEXTURE;
|
||||||
cmd.texture.xf = params.xf;
|
cmd.texture.xf = params.xf;
|
||||||
cmd.texture.sprite = params.sprite;
|
cmd.texture.sprite = params.sprite;
|
||||||
cmd.texture.texture = params.texture;
|
cmd.texture.texture = params.texture;
|
||||||
cmd.texture.clip = params.clip;
|
cmd.texture.clip = params.clip;
|
||||||
cmd.texture.tint = params.tint;
|
cmd.texture.tint = params.tint;
|
||||||
cmd.texture.emittance = params.emittance;
|
cmd.texture.emittance = params.emittance;
|
||||||
gpu_push_cmd(plan, cmd);
|
gp_push_cmd(plan, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Fill shapes
|
* Fill shapes
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
void draw_poly_ex(struct gpu_handle plan, struct v2_array vertices, struct gpu_indices indices, u32 color)
|
void draw_poly_ex(struct gp_handle plan, struct v2_array vertices, struct gp_indices indices, u32 color)
|
||||||
{
|
{
|
||||||
struct gpu_cmd_params cmd = ZI;
|
struct gp_cmd_params cmd = ZI;
|
||||||
cmd.kind = GPU_CMD_KIND_DRAW_MESH;
|
cmd.kind = GP_CMD_KIND_DRAW_MESH;
|
||||||
cmd.mesh.vertices = vertices;
|
cmd.mesh.vertices = vertices;
|
||||||
cmd.mesh.indices = indices;
|
cmd.mesh.indices = indices;
|
||||||
cmd.mesh.color = color;
|
cmd.mesh.color = color;
|
||||||
gpu_push_cmd(plan, cmd);
|
gp_push_cmd(plan, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draws a filled polygon using triangles in a fan pattern */
|
/* Draws a filled polygon using triangles in a fan pattern */
|
||||||
void draw_poly(struct gpu_handle plan, struct v2_array vertices, u32 color)
|
void draw_poly(struct gp_handle plan, struct v2_array vertices, u32 color)
|
||||||
{
|
{
|
||||||
if (vertices.count >= 3) {
|
if (vertices.count >= 3) {
|
||||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||||
@ -65,7 +65,7 @@ void draw_poly(struct gpu_handle plan, struct v2_array vertices, u32 color)
|
|||||||
u32 num_indices = num_tris * 3;
|
u32 num_indices = num_tris * 3;
|
||||||
|
|
||||||
/* Generate indices in a fan pattern */
|
/* Generate indices in a fan pattern */
|
||||||
struct gpu_indices indices = {
|
struct gp_indices indices = {
|
||||||
.count = num_indices,
|
.count = num_indices,
|
||||||
.indices = arena_push_array_no_zero(scratch.arena, u32, num_indices)
|
.indices = arena_push_array_no_zero(scratch.arena, u32, num_indices)
|
||||||
};
|
};
|
||||||
@ -82,7 +82,7 @@ void draw_poly(struct gpu_handle plan, struct v2_array vertices, u32 color)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_circle(struct gpu_handle plan, struct v2 pos, f32 radius, u32 color, u32 detail)
|
void draw_circle(struct gp_handle plan, struct v2 pos, f32 radius, u32 color, u32 detail)
|
||||||
{
|
{
|
||||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||||
|
|
||||||
@ -105,14 +105,14 @@ void draw_circle(struct gpu_handle plan, struct v2 pos, f32 radius, u32 color, u
|
|||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_quad(struct gpu_handle plan, struct quad quad, u32 color)
|
void draw_quad(struct gp_handle plan, struct quad quad, u32 color)
|
||||||
{
|
{
|
||||||
LOCAL_PERSIST u32 indices_array[6] = {
|
LOCAL_PERSIST u32 indices_array[6] = {
|
||||||
0, 1, 2,
|
0, 1, 2,
|
||||||
0, 2, 3
|
0, 2, 3
|
||||||
};
|
};
|
||||||
struct v2_array vertices = { .count = 4, .points = quad.e };
|
struct v2_array vertices = { .count = 4, .points = quad.e };
|
||||||
struct gpu_indices indices = { .count = 6, .indices = indices_array };
|
struct gp_indices indices = { .count = 6, .indices = indices_array };
|
||||||
draw_poly_ex(plan, vertices, indices, color);
|
draw_poly_ex(plan, vertices, indices, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ void draw_quad(struct gpu_handle plan, struct quad quad, u32 color)
|
|||||||
* Line shapes
|
* Line shapes
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
void draw_gradient_line(struct gpu_handle plan, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color)
|
void draw_gradient_line(struct gp_handle plan, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
struct quad quad = quad_from_line(start, end, thickness);
|
struct quad quad = quad_from_line(start, end, thickness);
|
||||||
@ -133,19 +133,19 @@ void draw_gradient_line(struct gpu_handle plan, struct v2 start, struct v2 end,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_line(struct gpu_handle plan, struct v2 start, struct v2 end, f32 thickness, u32 color)
|
void draw_line(struct gp_handle plan, struct v2 start, struct v2 end, f32 thickness, u32 color)
|
||||||
{
|
{
|
||||||
struct quad quad = quad_from_line(start, end, thickness);
|
struct quad quad = quad_from_line(start, end, thickness);
|
||||||
draw_quad(plan, quad, color);
|
draw_quad(plan, quad, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_ray(struct gpu_handle plan, struct v2 pos, struct v2 rel, f32 thickness, u32 color)
|
void draw_ray(struct gp_handle plan, struct v2 pos, struct v2 rel, f32 thickness, u32 color)
|
||||||
{
|
{
|
||||||
struct quad quad = quad_from_ray(pos, rel, thickness);
|
struct quad quad = quad_from_ray(pos, rel, thickness);
|
||||||
draw_quad(plan, quad, color);
|
draw_quad(plan, quad, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_poly_line(struct gpu_handle plan, struct v2_array points, b32 loop, f32 thickness, u32 color)
|
void draw_poly_line(struct gp_handle plan, struct v2_array points, b32 loop, f32 thickness, u32 color)
|
||||||
{
|
{
|
||||||
if (points.count >= 2) {
|
if (points.count >= 2) {
|
||||||
for (u64 i = 1; i < points.count; ++i) {
|
for (u64 i = 1; i < points.count; ++i) {
|
||||||
@ -163,7 +163,7 @@ void draw_poly_line(struct gpu_handle plan, struct v2_array points, b32 loop, f3
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_circle_line(struct gpu_handle plan, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail)
|
void draw_circle_line(struct gp_handle plan, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail)
|
||||||
{
|
{
|
||||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||||
|
|
||||||
@ -186,14 +186,14 @@ void draw_circle_line(struct gpu_handle plan, struct v2 pos, f32 radius, f32 thi
|
|||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_quad_line(struct gpu_handle plan, struct quad quad, f32 thickness, u32 color)
|
void draw_quad_line(struct gp_handle plan, struct quad quad, f32 thickness, u32 color)
|
||||||
{
|
{
|
||||||
struct v2 points[] = { quad.p0, quad.p1, quad.p2, quad.p3 };
|
struct v2 points[] = { quad.p0, quad.p1, quad.p2, quad.p3 };
|
||||||
struct v2_array a = { .points = points, .count = ARRAY_COUNT(points) };
|
struct v2_array a = { .points = points, .count = ARRAY_COUNT(points) };
|
||||||
draw_poly_line(plan, a, true, thickness, color);
|
draw_poly_line(plan, a, true, thickness, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_arrow_line(struct gpu_handle plan, struct v2 start, struct v2 end, f32 thickness, f32 arrowhead_height, u32 color)
|
void draw_arrow_line(struct gp_handle plan, 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 */
|
const f32 head_width_ratio = 0.5f; /* Width of arrowhead relative to its length */
|
||||||
|
|
||||||
@ -223,13 +223,13 @@ void draw_arrow_line(struct gpu_handle plan, struct v2 start, struct v2 end, f32
|
|||||||
draw_quad(plan, line_quad, color);
|
draw_quad(plan, line_quad, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_arrow_ray(struct gpu_handle plan, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color)
|
void draw_arrow_ray(struct gp_handle plan, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color)
|
||||||
{
|
{
|
||||||
struct v2 end = v2_add(pos, rel);
|
struct v2 end = v2_add(pos, rel);
|
||||||
draw_arrow_line(plan, pos, end, thickness, arrowhead_height, color);
|
draw_arrow_line(plan, pos, end, thickness, arrowhead_height, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_collider_line(struct gpu_handle plan, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail)
|
void draw_collider_line(struct gp_handle plan, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail)
|
||||||
{
|
{
|
||||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||||
struct v2_array poly = ZI;
|
struct v2_array poly = ZI;
|
||||||
@ -258,10 +258,10 @@ void draw_collider_line(struct gpu_handle plan, struct collider_shape shape, str
|
|||||||
* Grid
|
* Grid
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
void draw_grid(struct gpu_handle plan, 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_handle plan, 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)
|
||||||
{
|
{
|
||||||
struct gpu_cmd_params cmd = ZI;
|
struct gp_cmd_params cmd = ZI;
|
||||||
cmd.kind = GPU_CMD_KIND_DRAW_GRID;
|
cmd.kind = GP_CMD_KIND_DRAW_GRID;
|
||||||
cmd.grid.xf = xf;
|
cmd.grid.xf = xf;
|
||||||
cmd.grid.bg0_color = bg0_color;
|
cmd.grid.bg0_color = bg0_color;
|
||||||
cmd.grid.bg1_color = bg1_color;
|
cmd.grid.bg1_color = bg1_color;
|
||||||
@ -271,7 +271,7 @@ void draw_grid(struct gpu_handle plan, struct xform xf, u32 bg0_color, u32 bg1_c
|
|||||||
cmd.grid.line_thickness = thickness;
|
cmd.grid.line_thickness = thickness;
|
||||||
cmd.grid.line_spacing = spacing;
|
cmd.grid.line_spacing = spacing;
|
||||||
cmd.grid.offset = offset;
|
cmd.grid.offset = offset;
|
||||||
gpu_push_cmd(plan, cmd);
|
gp_push_cmd(plan, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
@ -279,7 +279,7 @@ void draw_grid(struct gpu_handle plan, struct xform xf, u32 bg0_color, u32 bg1_c
|
|||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
/* Returns the rect of the text area */
|
/* Returns the rect of the text area */
|
||||||
struct rect draw_text(struct gpu_handle plan, struct draw_text_params params)
|
struct rect draw_text(struct gp_handle plan, struct draw_text_params params)
|
||||||
{
|
{
|
||||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||||
|
|
||||||
|
|||||||
38
src/draw.h
38
src/draw.h
@ -1,13 +1,13 @@
|
|||||||
#ifndef DRAW_H
|
#ifndef DRAW_H
|
||||||
#define DRAW_H
|
#define DRAW_H
|
||||||
|
|
||||||
#include "gpu.h"
|
#include "gp.h"
|
||||||
|
|
||||||
struct font;
|
struct font;
|
||||||
struct font_startup_receipt;
|
struct font_startup_receipt;
|
||||||
|
|
||||||
struct draw_startup_receipt { i32 _; };
|
struct draw_startup_receipt { i32 _; };
|
||||||
struct draw_startup_receipt draw_startup(struct gpu_startup_receipt *gpu_sr,
|
struct draw_startup_receipt draw_startup(struct gp_startup_receipt *gp_sr,
|
||||||
struct font_startup_receipt *font_sr);
|
struct font_startup_receipt *font_sr);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
@ -22,54 +22,54 @@ struct draw_startup_receipt draw_startup(struct gpu_startup_receipt *gpu_sr,
|
|||||||
|
|
||||||
struct draw_texture_params {
|
struct draw_texture_params {
|
||||||
struct xform xf;
|
struct xform xf;
|
||||||
struct gpu_handle texture; /* Overrides sprite if set */
|
struct gp_handle texture; /* Overrides sprite if set */
|
||||||
struct sprite_tag sprite;
|
struct sprite_tag sprite;
|
||||||
struct clip_rect clip;
|
struct clip_rect clip;
|
||||||
u32 tint;
|
u32 tint;
|
||||||
f32 emittance;
|
f32 emittance;
|
||||||
};
|
};
|
||||||
|
|
||||||
void draw_texture(struct gpu_handle plan, struct draw_texture_params params);
|
void draw_texture(struct gp_handle plan, struct draw_texture_params params);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Fill shapes
|
* Fill shapes
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
void draw_poly_ex(struct gpu_handle plan, struct v2_array vertices, struct gpu_indices indices, u32 color);
|
void draw_poly_ex(struct gp_handle plan, struct v2_array vertices, struct gp_indices indices, u32 color);
|
||||||
|
|
||||||
void draw_poly(struct gpu_handle plan, struct v2_array points, u32 color);
|
void draw_poly(struct gp_handle plan, struct v2_array points, u32 color);
|
||||||
|
|
||||||
void draw_circle(struct gpu_handle plan, struct v2 pos, f32 radius, u32 color, u32 detail);
|
void draw_circle(struct gp_handle plan, struct v2 pos, f32 radius, u32 color, u32 detail);
|
||||||
|
|
||||||
void draw_quad(struct gpu_handle plan, struct quad quad, u32 color);
|
void draw_quad(struct gp_handle plan, struct quad quad, u32 color);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Line shapes
|
* Line shapes
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
void draw_gradient_line(struct gpu_handle plan, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color);
|
void draw_gradient_line(struct gp_handle plan, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color);
|
||||||
|
|
||||||
void draw_line(struct gpu_handle plan, struct v2 start, struct v2 end, f32 thickness, u32 color);
|
void draw_line(struct gp_handle plan, struct v2 start, struct v2 end, f32 thickness, u32 color);
|
||||||
|
|
||||||
void draw_ray(struct gpu_handle plan, struct v2 pos, struct v2 rel, f32 thickness, u32 color);
|
void draw_ray(struct gp_handle plan, struct v2 pos, struct v2 rel, f32 thickness, u32 color);
|
||||||
|
|
||||||
void draw_poly_line(struct gpu_handle plan, struct v2_array points, b32 loop, f32 thickness, u32 color);
|
void draw_poly_line(struct gp_handle plan, struct v2_array points, b32 loop, f32 thickness, u32 color);
|
||||||
|
|
||||||
void draw_circle_line(struct gpu_handle plan, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail);
|
void draw_circle_line(struct gp_handle plan, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail);
|
||||||
|
|
||||||
void draw_quad_line(struct gpu_handle plan, struct quad quad, f32 thickness, u32 color);
|
void draw_quad_line(struct gp_handle plan, struct quad quad, f32 thickness, u32 color);
|
||||||
|
|
||||||
void draw_arrow_line(struct gpu_handle plan, struct v2 start, struct v2 end, f32 thickness, f32 arrowhead_height, u32 color);
|
void draw_arrow_line(struct gp_handle plan, struct v2 start, struct v2 end, f32 thickness, f32 arrowhead_height, u32 color);
|
||||||
|
|
||||||
void draw_arrow_ray(struct gpu_handle plan, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color);
|
void draw_arrow_ray(struct gp_handle plan, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color);
|
||||||
|
|
||||||
void draw_collider_line(struct gpu_handle plan, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail);
|
void draw_collider_line(struct gp_handle plan, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Grid
|
* Grid
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
void draw_grid(struct gpu_handle plan, 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_handle plan, 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);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Text
|
* Text
|
||||||
@ -117,6 +117,6 @@ struct draw_text_params {
|
|||||||
struct string str;
|
struct string str;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct rect draw_text(struct gpu_handle plan, struct draw_text_params params);
|
struct rect draw_text(struct gp_handle plan, struct draw_text_params params);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "gpu.h"
|
#include "gp.h"
|
||||||
|
|
||||||
#define LOOKUP_TABLE_SIZE (256)
|
#define LOOKUP_TABLE_SIZE (256)
|
||||||
GLOBAL u32 g_font_codes[] = {
|
GLOBAL u32 g_font_codes[] = {
|
||||||
@ -42,13 +42,13 @@ GLOBAL struct {
|
|||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct font_startup_receipt font_startup(struct work_startup_receipt *work_sr,
|
struct font_startup_receipt font_startup(struct work_startup_receipt *work_sr,
|
||||||
struct gpu_startup_receipt *gpu_sr,
|
struct gp_startup_receipt *gp_sr,
|
||||||
struct asset_cache_startup_receipt *asset_cache_sr,
|
struct asset_cache_startup_receipt *asset_cache_sr,
|
||||||
struct ttf_startup_receipt *ttf_sr,
|
struct ttf_startup_receipt *ttf_sr,
|
||||||
struct resource_startup_receipt *resource_sr)
|
struct resource_startup_receipt *resource_sr)
|
||||||
{
|
{
|
||||||
(UNUSED)work_sr;
|
(UNUSED)work_sr;
|
||||||
(UNUSED)gpu_sr;
|
(UNUSED)gp_sr;
|
||||||
(UNUSED)asset_cache_sr;
|
(UNUSED)asset_cache_sr;
|
||||||
(UNUSED)ttf_sr;
|
(UNUSED)ttf_sr;
|
||||||
(UNUSED)resource_sr;
|
(UNUSED)resource_sr;
|
||||||
@ -119,7 +119,7 @@ INTERNAL WORK_TASK_FUNC_DEF(font_load_asset_task, vparams)
|
|||||||
resource_close(&res);
|
resource_close(&res);
|
||||||
|
|
||||||
/* Send texture to GPU */
|
/* Send texture to GPU */
|
||||||
struct gpu_handle texture = gpu_texture_alloc(GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, V2I32(result.image_data.width, result.image_data.height), result.image_data.pixels);
|
struct gp_handle texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, V2I32(result.image_data.width, result.image_data.height), result.image_data.pixels);
|
||||||
|
|
||||||
/* Allocate store memory */
|
/* Allocate store memory */
|
||||||
struct font *font = NULL;
|
struct font *font = NULL;
|
||||||
|
|||||||
@ -2,11 +2,11 @@
|
|||||||
#define FONT_H
|
#define FONT_H
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "gpu.h"
|
#include "gp.h"
|
||||||
|
|
||||||
struct asset;
|
struct asset;
|
||||||
struct work_startup_receipt;
|
struct work_startup_receipt;
|
||||||
struct gpu_startup_receipt;
|
struct gp_startup_receipt;
|
||||||
struct asset_cache_startup_receipt;
|
struct asset_cache_startup_receipt;
|
||||||
struct ttf_startup_receipt;
|
struct ttf_startup_receipt;
|
||||||
struct resource_startup_receipt;
|
struct resource_startup_receipt;
|
||||||
@ -21,7 +21,7 @@ struct font_glyph {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct font {
|
struct font {
|
||||||
struct gpu_handle texture;
|
struct gp_handle texture;
|
||||||
u32 image_width;
|
u32 image_width;
|
||||||
u32 image_height;
|
u32 image_height;
|
||||||
f32 point_size;
|
f32 point_size;
|
||||||
@ -32,7 +32,7 @@ struct font {
|
|||||||
|
|
||||||
struct font_startup_receipt { i32 _; };
|
struct font_startup_receipt { i32 _; };
|
||||||
struct font_startup_receipt font_startup(struct work_startup_receipt *work_sr,
|
struct font_startup_receipt font_startup(struct work_startup_receipt *work_sr,
|
||||||
struct gpu_startup_receipt *gpu_sr,
|
struct gp_startup_receipt *gp_sr,
|
||||||
struct asset_cache_startup_receipt *asset_cache_sr,
|
struct asset_cache_startup_receipt *asset_cache_sr,
|
||||||
struct ttf_startup_receipt *ttf_sr,
|
struct ttf_startup_receipt *ttf_sr,
|
||||||
struct resource_startup_receipt *resource_sr);
|
struct resource_startup_receipt *resource_sr);
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef GPU_H
|
#ifndef GP_H
|
||||||
#define GPU_H
|
#define GP_H
|
||||||
|
|
||||||
struct sys_window;
|
struct sys_window;
|
||||||
struct work_startup_receipt;
|
struct work_startup_receipt;
|
||||||
@ -8,14 +8,14 @@ struct work_startup_receipt;
|
|||||||
* Startup
|
* Startup
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct gpu_startup_receipt { i32 _; };
|
struct gp_startup_receipt { i32 _; };
|
||||||
struct gpu_startup_receipt gpu_startup(struct work_startup_receipt *work_sr, struct sys_window *window);
|
struct gp_startup_receipt gp_startup(struct work_startup_receipt *work_sr, struct sys_window *window);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Handle
|
* Handle
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct gpu_handle {
|
struct gp_handle {
|
||||||
union {
|
union {
|
||||||
/* dx11 style */
|
/* dx11 style */
|
||||||
u64 v;
|
u64 v;
|
||||||
@ -27,67 +27,67 @@ struct gpu_handle {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gpu_handle_array {
|
struct gp_handle_array {
|
||||||
u64 count;
|
u64 count;
|
||||||
struct gpu_handle **handles;
|
struct gp_handle **handles;
|
||||||
};
|
};
|
||||||
|
|
||||||
void gpu_release(struct gpu_handle handle);
|
void gp_release(struct gp_handle handle);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Texture
|
* Texture
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
enum gpu_texture_format {
|
enum gp_texture_format {
|
||||||
GPU_TEXTURE_FORMAT_NONE,
|
GP_TEXTURE_FORMAT_NONE,
|
||||||
GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM,
|
GP_TEXTURE_FORMAT_R8G8B8A8_UNORM,
|
||||||
GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB,
|
GP_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB,
|
||||||
|
|
||||||
NUM_GPU_TEXTURE_FORMATS
|
NUM_GP_TEXTURE_FORMATS
|
||||||
};
|
};
|
||||||
|
|
||||||
enum gpu_texture_flag {
|
enum gp_texture_flag {
|
||||||
GPU_TEXTURE_FLAG_NONE = (0),
|
GP_TEXTURE_FLAG_NONE = (0),
|
||||||
GPU_TEXTURE_FLAG_TARGETABLE = (1 << 0)
|
GP_TEXTURE_FLAG_TARGETABLE = (1 << 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gpu_handle gpu_texture_alloc(enum gpu_texture_format format, u32 flags, struct v2i32 size, void *initial_data);
|
struct gp_handle gp_texture_alloc(enum gp_texture_format format, u32 flags, struct v2i32 size, void *initial_data);
|
||||||
|
|
||||||
void gpu_texture_clear(struct gpu_handle target_texture, u32 clear_color);
|
void gp_texture_clear(struct gp_handle target_texture, u32 clear_color);
|
||||||
|
|
||||||
struct v2i32 gpu_texture_get_size(struct gpu_handle texture);
|
struct v2i32 gp_texture_get_size(struct gp_handle texture);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Cmd buffer
|
* Cmd buffer
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct gpu_indices {
|
struct gp_indices {
|
||||||
u32 count;
|
u32 count;
|
||||||
u32 *indices;
|
u32 *indices;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum gpu_cmd_kind {
|
enum gp_cmd_kind {
|
||||||
GPU_CMD_KIND_NONE,
|
GP_CMD_KIND_NONE,
|
||||||
GPU_CMD_KIND_DRAW_MESH,
|
GP_CMD_KIND_DRAW_MESH,
|
||||||
GPU_CMD_KIND_DRAW_TEXTURE,
|
GP_CMD_KIND_DRAW_TEXTURE,
|
||||||
GPU_CMD_KIND_DRAW_GRID,
|
GP_CMD_KIND_DRAW_GRID,
|
||||||
GPU_CMD_KIND_TEST,
|
GP_CMD_KIND_TEST,
|
||||||
|
|
||||||
NUM_GPU_CMD_KINDS
|
NUM_GP_CMD_KINDS
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gpu_cmd_params {
|
struct gp_cmd_params {
|
||||||
enum gpu_cmd_kind kind;
|
enum gp_cmd_kind kind;
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
struct v2_array vertices;
|
struct v2_array vertices;
|
||||||
struct gpu_indices indices;
|
struct gp_indices indices;
|
||||||
u32 color;
|
u32 color;
|
||||||
} mesh;
|
} mesh;
|
||||||
struct {
|
struct {
|
||||||
struct xform xf;
|
struct xform xf;
|
||||||
struct sprite_tag sprite;
|
struct sprite_tag sprite;
|
||||||
struct gpu_handle texture;
|
struct gp_handle texture;
|
||||||
struct clip_rect clip;
|
struct clip_rect clip;
|
||||||
u32 tint;
|
u32 tint;
|
||||||
f32 emittance;
|
f32 emittance;
|
||||||
@ -109,22 +109,22 @@ struct gpu_cmd_params {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gpu_handle gpu_plan_alloc(void);
|
struct gp_handle gp_plan_alloc(void);
|
||||||
|
|
||||||
void gpu_push_cmd(struct gpu_handle gpu_plan, struct gpu_cmd_params params);
|
void gp_push_cmd(struct gp_handle gp_plan, struct gp_cmd_params params);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Dispatch
|
* Dispatch
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct gpu_dispatch_params {
|
struct gp_dispatch_params {
|
||||||
struct gpu_handle plan;
|
struct gp_handle plan;
|
||||||
struct gpu_handle draw_target;
|
struct gp_handle draw_target;
|
||||||
struct rect draw_target_viewport;
|
struct rect draw_target_viewport;
|
||||||
struct xform draw_target_view;
|
struct xform draw_target_view;
|
||||||
};
|
};
|
||||||
|
|
||||||
void gpu_dispatch(struct gpu_dispatch_params params);
|
void gp_dispatch(struct gp_dispatch_params params);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Present
|
* Present
|
||||||
@ -133,6 +133,6 @@ void gpu_dispatch(struct gpu_dispatch_params params);
|
|||||||
/* 1. Ensures the backbuffer is at size `backbuffer_resolution`
|
/* 1. Ensures the backbuffer is at size `backbuffer_resolution`
|
||||||
* 2. Blits `texture` to the backbuffer using `texture_xf` (applied to centered unit square)
|
* 2. Blits `texture` to the backbuffer using `texture_xf` (applied to centered unit square)
|
||||||
* 3. Presents the backbuffer */
|
* 3. Presents the backbuffer */
|
||||||
void gpu_present(struct v2i32 backbuffer_resolution, struct gpu_handle texture, struct xform texture_xf, i32 vsync);
|
void gp_present(struct v2i32 backbuffer_resolution, struct gp_handle texture, struct xform texture_xf, i32 vsync);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -1,6 +1,6 @@
|
|||||||
#if !DX12_TEST
|
#if !DX12_TEST
|
||||||
|
|
||||||
#include "gpu.h"
|
#include "gp.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
@ -127,7 +127,7 @@ struct dx11_cmd_buffers {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct dx11_cmd {
|
struct dx11_cmd {
|
||||||
enum gpu_cmd_kind kind;
|
enum gp_cmd_kind kind;
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
struct xform xf;
|
struct xform xf;
|
||||||
@ -139,7 +139,7 @@ struct dx11_cmd {
|
|||||||
u32 index_count;
|
u32 index_count;
|
||||||
} mesh;
|
} mesh;
|
||||||
struct {
|
struct {
|
||||||
struct gpu_handle texture; /* Overrides sprite if set */
|
struct gp_handle texture; /* Overrides sprite if set */
|
||||||
struct sprite_tag sprite;
|
struct sprite_tag sprite;
|
||||||
u32 instance_offset;
|
u32 instance_offset;
|
||||||
u32 instance_count;
|
u32 instance_count;
|
||||||
@ -166,7 +166,7 @@ struct dx11_plan {
|
|||||||
struct dx11_cmd *cpu_last_cmd;
|
struct dx11_cmd *cpu_last_cmd;
|
||||||
|
|
||||||
/* Commands w/ buffer data submitted to video memory */
|
/* Commands w/ buffer data submitted to video memory */
|
||||||
struct arena *gpu_cmds_arena;
|
struct arena *gp_cmds_arena;
|
||||||
struct dx11_cmd *gpu_first_cmd;
|
struct dx11_cmd *gpu_first_cmd;
|
||||||
struct dx11_cmd *gpu_last_cmd;
|
struct dx11_cmd *gpu_last_cmd;
|
||||||
|
|
||||||
@ -269,9 +269,9 @@ GLOBAL struct {
|
|||||||
struct dx11_buffer *quad_index_buffer;
|
struct dx11_buffer *quad_index_buffer;
|
||||||
|
|
||||||
/* Blit plan */
|
/* Blit plan */
|
||||||
struct gpu_handle present_blit_plan;
|
struct gp_handle present_blit_plan;
|
||||||
|
|
||||||
} G = ZI, DEBUG_ALIAS(G, G_gpu_dx11);
|
} G = ZI, DEBUG_ALIAS(G, G_gp_dx11);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Startup
|
* Startup
|
||||||
@ -285,7 +285,7 @@ INTERNAL struct dx11_buffer *dx11_buffer_alloc(struct D3D11_BUFFER_DESC desc, D3
|
|||||||
INTERNAL RESOURCE_WATCH_CALLBACK_FUNC_DEF(shader_resource_watch_callback, name);
|
INTERNAL RESOURCE_WATCH_CALLBACK_FUNC_DEF(shader_resource_watch_callback, name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct gpu_startup_receipt gpu_startup(struct work_startup_receipt *work_sr, struct sys_window *window)
|
struct gp_startup_receipt gp_startup(struct work_startup_receipt *work_sr, struct sys_window *window)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
(UNUSED)work_sr;
|
(UNUSED)work_sr;
|
||||||
@ -539,9 +539,9 @@ struct gpu_startup_receipt gpu_startup(struct work_startup_receipt *work_sr, str
|
|||||||
resource_register_watch_callback(shader_resource_watch_callback);
|
resource_register_watch_callback(shader_resource_watch_callback);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
G.present_blit_plan = gpu_plan_alloc();
|
G.present_blit_plan = gp_plan_alloc();
|
||||||
|
|
||||||
return (struct gpu_startup_receipt) { 0 };
|
return (struct gp_startup_receipt) { 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
@ -562,7 +562,7 @@ INLINE struct mat4x4 calculate_vp(struct xform view, f32 viewport_width, f32 vie
|
|||||||
|
|
||||||
INTERNAL void dx11_texture_release(struct dx11_texture *t);
|
INTERNAL void dx11_texture_release(struct dx11_texture *t);
|
||||||
|
|
||||||
void gpu_release(struct gpu_handle handle)
|
void gp_release(struct gp_handle handle)
|
||||||
{
|
{
|
||||||
struct dx11_handle_header *header = (struct dx11_handle_header *)handle.v;
|
struct dx11_handle_header *header = (struct dx11_handle_header *)handle.v;
|
||||||
switch (header->kind) {
|
switch (header->kind) {
|
||||||
@ -1009,15 +1009,15 @@ INTERNAL RESOURCE_WATCH_CALLBACK_FUNC_DEF(shader_resource_watch_callback, name)
|
|||||||
* Texture
|
* Texture
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
INTERNAL enum DXGI_FORMAT dx11_format_from_gpu_format(enum gpu_texture_format gpu_format)
|
INTERNAL enum DXGI_FORMAT dx11_format_from_gp_format(enum gp_texture_format gp_format)
|
||||||
{
|
{
|
||||||
LOCAL_PERSIST const enum DXGI_FORMAT dx11_formats[NUM_GPU_TEXTURE_FORMATS] = {
|
LOCAL_PERSIST const enum DXGI_FORMAT dx11_formats[NUM_GP_TEXTURE_FORMATS] = {
|
||||||
[GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM] = DXGI_FORMAT_R8G8B8A8_UNORM,
|
[GP_TEXTURE_FORMAT_R8G8B8A8_UNORM] = DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||||
[GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB] = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
|
[GP_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB] = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
|
||||||
};
|
};
|
||||||
enum DXGI_FORMAT res = DXGI_FORMAT_UNKNOWN;
|
enum DXGI_FORMAT res = DXGI_FORMAT_UNKNOWN;
|
||||||
if ((u32)gpu_format < ARRAY_COUNT(dx11_formats)) {
|
if ((u32)gp_format < ARRAY_COUNT(dx11_formats)) {
|
||||||
res = dx11_formats[gpu_format];
|
res = dx11_formats[gp_format];
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -1111,13 +1111,13 @@ INTERNAL void dx11_texture_release(struct dx11_texture *t)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct gpu_handle gpu_texture_alloc(enum gpu_texture_format format, u32 flags, struct v2i32 size, void *initial_data)
|
struct gp_handle gp_texture_alloc(enum gp_texture_format format, u32 flags, struct v2i32 size, void *initial_data)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
struct gpu_handle res = ZI;
|
struct gp_handle res = ZI;
|
||||||
|
|
||||||
/* Convert format to dx11 format */
|
/* Convert format to dx11 format */
|
||||||
enum DXGI_FORMAT dx11_format = dx11_format_from_gpu_format(format);
|
enum DXGI_FORMAT dx11_format = dx11_format_from_gp_format(format);
|
||||||
if (dx11_format == DXGI_FORMAT_UNKNOWN) {
|
if (dx11_format == DXGI_FORMAT_UNKNOWN) {
|
||||||
/* Unknown format */
|
/* Unknown format */
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
@ -1126,7 +1126,7 @@ struct gpu_handle gpu_texture_alloc(enum gpu_texture_format format, u32 flags, s
|
|||||||
|
|
||||||
/* Convert flags to dx11 flags */
|
/* Convert flags to dx11 flags */
|
||||||
u32 dx11_flags = D3D11_BIND_SHADER_RESOURCE;
|
u32 dx11_flags = D3D11_BIND_SHADER_RESOURCE;
|
||||||
if (flags & GPU_TEXTURE_FLAG_TARGETABLE) {
|
if (flags & GP_TEXTURE_FLAG_TARGETABLE) {
|
||||||
dx11_flags |= D3D11_BIND_RENDER_TARGET;
|
dx11_flags |= D3D11_BIND_RENDER_TARGET;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1135,7 +1135,7 @@ struct gpu_handle gpu_texture_alloc(enum gpu_texture_format format, u32 flags, s
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpu_texture_clear(struct gpu_handle target_texture, u32 clear_color)
|
void gp_texture_clear(struct gp_handle target_texture, u32 clear_color)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
struct dx11_texture *t = (struct dx11_texture *)target_texture.v;
|
struct dx11_texture *t = (struct dx11_texture *)target_texture.v;
|
||||||
@ -1150,7 +1150,7 @@ void gpu_texture_clear(struct gpu_handle target_texture, u32 clear_color)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct v2i32 gpu_texture_get_size(struct gpu_handle texture)
|
struct v2i32 gp_texture_get_size(struct gp_handle texture)
|
||||||
{
|
{
|
||||||
return ((struct dx11_texture *)texture.v)->size;
|
return ((struct dx11_texture *)texture.v)->size;
|
||||||
}
|
}
|
||||||
@ -1283,20 +1283,20 @@ INTERNAL void dx11_buffer_submit(struct dx11_buffer *buffer)
|
|||||||
* Plan
|
* Plan
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct gpu_handle gpu_plan_alloc(void)
|
struct gp_handle gp_plan_alloc(void)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
struct dx11_plan *plan = NULL;
|
struct dx11_plan *plan = NULL;
|
||||||
{
|
{
|
||||||
struct arena *cpu_cmds_arena = NULL;
|
struct arena *cpu_cmds_arena = NULL;
|
||||||
struct arena *gpu_cmds_arena = NULL;
|
struct arena *gp_cmds_arena = NULL;
|
||||||
{
|
{
|
||||||
struct sys_lock lock = sys_mutex_lock_e(G.plans_mutex);
|
struct sys_lock lock = sys_mutex_lock_e(G.plans_mutex);
|
||||||
if (G.first_free_plan) {
|
if (G.first_free_plan) {
|
||||||
plan = G.first_free_plan;
|
plan = G.first_free_plan;
|
||||||
G.first_free_plan = plan->next_free;
|
G.first_free_plan = plan->next_free;
|
||||||
cpu_cmds_arena = plan->cpu_cmds_arena;
|
cpu_cmds_arena = plan->cpu_cmds_arena;
|
||||||
gpu_cmds_arena = plan->gpu_cmds_arena;
|
gp_cmds_arena = plan->gp_cmds_arena;
|
||||||
} else {
|
} else {
|
||||||
plan = arena_push_no_zero(G.plans_arena, struct dx11_plan);
|
plan = arena_push_no_zero(G.plans_arena, struct dx11_plan);
|
||||||
}
|
}
|
||||||
@ -1306,13 +1306,13 @@ struct gpu_handle gpu_plan_alloc(void)
|
|||||||
if (!cpu_cmds_arena) {
|
if (!cpu_cmds_arena) {
|
||||||
cpu_cmds_arena = arena_alloc(GIGABYTE(64));
|
cpu_cmds_arena = arena_alloc(GIGABYTE(64));
|
||||||
}
|
}
|
||||||
if (!gpu_cmds_arena) {
|
if (!gp_cmds_arena) {
|
||||||
gpu_cmds_arena = arena_alloc(GIGABYTE(64));
|
gp_cmds_arena = arena_alloc(GIGABYTE(64));
|
||||||
}
|
}
|
||||||
plan->cpu_cmds_arena = cpu_cmds_arena;
|
plan->cpu_cmds_arena = cpu_cmds_arena;
|
||||||
plan->gpu_cmds_arena = gpu_cmds_arena;
|
plan->gp_cmds_arena = gp_cmds_arena;
|
||||||
arena_reset(plan->cpu_cmds_arena);
|
arena_reset(plan->cpu_cmds_arena);
|
||||||
arena_reset(plan->gpu_cmds_arena);
|
arena_reset(plan->gp_cmds_arena);
|
||||||
}
|
}
|
||||||
plan->header.kind = DX11_HANDLE_KIND_PLAN;
|
plan->header.kind = DX11_HANDLE_KIND_PLAN;
|
||||||
|
|
||||||
@ -1365,15 +1365,15 @@ struct gpu_handle gpu_plan_alloc(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct gpu_handle res = ZI;
|
struct gp_handle res = ZI;
|
||||||
res.v = (u64)plan;
|
res.v = (u64)plan;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpu_push_cmd(struct gpu_handle gpu_plan, struct gpu_cmd_params params)
|
void gp_push_cmd(struct gp_handle gp_plan, struct gp_cmd_params params)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
struct dx11_plan *plan = (struct dx11_plan *)gpu_plan.v;
|
struct dx11_plan *plan = (struct dx11_plan *)gp_plan.v;
|
||||||
|
|
||||||
switch (params.kind) {
|
switch (params.kind) {
|
||||||
default:
|
default:
|
||||||
@ -1382,7 +1382,7 @@ void gpu_push_cmd(struct gpu_handle gpu_plan, struct gpu_cmd_params params)
|
|||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case GPU_CMD_KIND_DRAW_MESH:
|
case GP_CMD_KIND_DRAW_MESH:
|
||||||
{
|
{
|
||||||
struct dx11_cmd *cmd = plan->cpu_last_cmd;
|
struct dx11_cmd *cmd = plan->cpu_last_cmd;
|
||||||
if (cmd && cmd->kind != params.kind) {
|
if (cmd && cmd->kind != params.kind) {
|
||||||
@ -1425,7 +1425,7 @@ void gpu_push_cmd(struct gpu_handle gpu_plan, struct gpu_cmd_params params)
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case GPU_CMD_KIND_DRAW_TEXTURE:
|
case GP_CMD_KIND_DRAW_TEXTURE:
|
||||||
{
|
{
|
||||||
struct dx11_cmd *cmd = plan->cpu_last_cmd;
|
struct dx11_cmd *cmd = plan->cpu_last_cmd;
|
||||||
if (cmd &&
|
if (cmd &&
|
||||||
@ -1462,7 +1462,7 @@ void gpu_push_cmd(struct gpu_handle gpu_plan, struct gpu_cmd_params params)
|
|||||||
instance->emittance = params.texture.emittance;
|
instance->emittance = params.texture.emittance;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case GPU_CMD_KIND_DRAW_GRID:
|
case GP_CMD_KIND_DRAW_GRID:
|
||||||
{
|
{
|
||||||
struct dx11_cmd *cmd = plan->cpu_last_cmd;
|
struct dx11_cmd *cmd = plan->cpu_last_cmd;
|
||||||
if (cmd && cmd->kind != params.kind) {
|
if (cmd && cmd->kind != params.kind) {
|
||||||
@ -1498,7 +1498,7 @@ void gpu_push_cmd(struct gpu_handle gpu_plan, struct gpu_cmd_params params)
|
|||||||
instance->y_srgb = params.grid.y_color;
|
instance->y_srgb = params.grid.y_color;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case GPU_CMD_KIND_TEST:
|
case GP_CMD_KIND_TEST:
|
||||||
{
|
{
|
||||||
struct dx11_cmd *cmd = arena_push(plan->cpu_cmds_arena, struct dx11_cmd);
|
struct dx11_cmd *cmd = arena_push(plan->cpu_cmds_arena, struct dx11_cmd);
|
||||||
cmd->kind = params.kind;
|
cmd->kind = params.kind;
|
||||||
@ -1589,15 +1589,15 @@ INTERNAL void dx11_unbind(u32 flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Lock resources during dispatch */
|
/* TODO: Lock resources during dispatch */
|
||||||
void gpu_dispatch(struct gpu_dispatch_params params)
|
void gp_dispatch(struct gp_dispatch_params params)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
__profscope_dx11(G.profiling_ctx, Dispatch, RGB32_F(0.5, 0.2, 0.2));
|
__profscope_dx11(G.profiling_ctx, Dispatch, RGB32_F(0.5, 0.2, 0.2));
|
||||||
struct dx11_plan *plan = (struct dx11_plan *)params.plan.v;
|
struct dx11_plan *plan = (struct dx11_plan *)params.plan.v;
|
||||||
|
|
||||||
/* Swap cmd lists */
|
/* Swap cmd lists */
|
||||||
struct arena *swp_arena = plan->gpu_cmds_arena;
|
struct arena *swp_arena = plan->gp_cmds_arena;
|
||||||
plan->gpu_cmds_arena = plan->cpu_cmds_arena;
|
plan->gp_cmds_arena = plan->cpu_cmds_arena;
|
||||||
plan->gpu_first_cmd = plan->cpu_first_cmd;
|
plan->gpu_first_cmd = plan->cpu_first_cmd;
|
||||||
plan->gpu_last_cmd = plan->cpu_last_cmd;
|
plan->gpu_last_cmd = plan->cpu_last_cmd;
|
||||||
|
|
||||||
@ -1659,7 +1659,7 @@ void gpu_dispatch(struct gpu_dispatch_params params)
|
|||||||
__profscope(Regular pass);
|
__profscope(Regular pass);
|
||||||
__profscope_dx11(G.profiling_ctx, Regular pass, RGB32_F(0.2, 0.5, 0.5));
|
__profscope_dx11(G.profiling_ctx, Regular pass, RGB32_F(0.2, 0.5, 0.5));
|
||||||
for (struct dx11_cmd *cmd = plan->gpu_first_cmd; cmd; cmd = cmd->next) {
|
for (struct dx11_cmd *cmd = plan->gpu_first_cmd; cmd; cmd = cmd->next) {
|
||||||
enum gpu_cmd_kind cmd_kind = cmd->kind;
|
enum gp_cmd_kind cmd_kind = cmd->kind;
|
||||||
|
|
||||||
switch (cmd_kind) {
|
switch (cmd_kind) {
|
||||||
default:
|
default:
|
||||||
@ -1668,7 +1668,7 @@ void gpu_dispatch(struct gpu_dispatch_params params)
|
|||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case GPU_CMD_KIND_DRAW_MESH:
|
case GP_CMD_KIND_DRAW_MESH:
|
||||||
{
|
{
|
||||||
__profscope(Draw mesh);
|
__profscope(Draw mesh);
|
||||||
__profscope_dx11(G.profiling_ctx, Draw mesh, RGB32_F(0.5, 0.2, 0.2));
|
__profscope_dx11(G.profiling_ctx, Draw mesh, RGB32_F(0.5, 0.2, 0.2));
|
||||||
@ -1714,7 +1714,7 @@ void gpu_dispatch(struct gpu_dispatch_params params)
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case GPU_CMD_KIND_DRAW_TEXTURE:
|
case GP_CMD_KIND_DRAW_TEXTURE:
|
||||||
{
|
{
|
||||||
__profscope(Draw texture);
|
__profscope(Draw texture);
|
||||||
__profscope_dx11(G.profiling_ctx, Draw texture, RGB32_F(0.2, 0.5, 0.2));
|
__profscope_dx11(G.profiling_ctx, Draw texture, RGB32_F(0.2, 0.5, 0.2));
|
||||||
@ -1775,7 +1775,7 @@ void gpu_dispatch(struct gpu_dispatch_params params)
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case GPU_CMD_KIND_DRAW_GRID:
|
case GP_CMD_KIND_DRAW_GRID:
|
||||||
{
|
{
|
||||||
__profscope(Draw grid);
|
__profscope(Draw grid);
|
||||||
__profscope_dx11(G.profiling_ctx, Draw grid, RGB32_F(0.2, 0.2, 0.5));
|
__profscope_dx11(G.profiling_ctx, Draw grid, RGB32_F(0.2, 0.2, 0.5));
|
||||||
@ -1822,7 +1822,7 @@ void gpu_dispatch(struct gpu_dispatch_params params)
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case GPU_CMD_KIND_TEST:
|
case GP_CMD_KIND_TEST:
|
||||||
{
|
{
|
||||||
__profscope(Test);
|
__profscope(Test);
|
||||||
__profscope_dx11(G.profiling_ctx, Test, RGB32_F(1, 0.2, 1));
|
__profscope_dx11(G.profiling_ctx, Test, RGB32_F(1, 0.2, 1));
|
||||||
@ -1879,7 +1879,7 @@ void gpu_dispatch(struct gpu_dispatch_params params)
|
|||||||
* Backbuffer
|
* Backbuffer
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
INTERNAL void gpu_capture_image_for_profiler(void);
|
INTERNAL void capture_image_for_profiler(void);
|
||||||
|
|
||||||
#if GSTAT_ENABLED || PROFILING
|
#if GSTAT_ENABLED || PROFILING
|
||||||
INTERNAL struct DXGI_QUERY_VIDEO_MEMORY_INFO get_memory_info(void)
|
INTERNAL struct DXGI_QUERY_VIDEO_MEMORY_INFO get_memory_info(void)
|
||||||
@ -1956,8 +1956,8 @@ INTERNAL void present_blit(struct dx11_texture *dst, struct dx11_texture *src, s
|
|||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
__profscope_dx11(G.profiling_ctx, Blit, RGB32_F(0.3, 0.1, 0.1));
|
__profscope_dx11(G.profiling_ctx, Blit, RGB32_F(0.3, 0.1, 0.1));
|
||||||
struct gpu_handle src_texture_handle = { .v = (u64)src };
|
struct gp_handle src_texture_handle = { .v = (u64)src };
|
||||||
struct gpu_handle dst_texture_handle = { .v = (u64)dst };
|
struct gp_handle dst_texture_handle = { .v = (u64)dst };
|
||||||
|
|
||||||
/* Draw texture to backbuffer texture */
|
/* Draw texture to backbuffer texture */
|
||||||
/* TODO: Specialized blit shader */
|
/* TODO: Specialized blit shader */
|
||||||
@ -1967,20 +1967,20 @@ INTERNAL void present_blit(struct dx11_texture *dst, struct dx11_texture *src, s
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Clear textures */
|
/* Clear textures */
|
||||||
gpu_texture_clear(dst_texture_handle, RGBA32_F(0, 0, 0, 1));
|
gp_texture_clear(dst_texture_handle, RGBA32_F(0, 0, 0, 1));
|
||||||
|
|
||||||
/* Render to backbuffer texture */
|
/* Render to backbuffer texture */
|
||||||
{
|
{
|
||||||
struct gpu_dispatch_params params = ZI;
|
struct gp_dispatch_params params = ZI;
|
||||||
params.plan = G.present_blit_plan;
|
params.plan = G.present_blit_plan;
|
||||||
params.draw_target = dst_texture_handle;
|
params.draw_target = dst_texture_handle;
|
||||||
params.draw_target_viewport = RECT_FROM_V2(V2(0, 0), V2(dst->size.x, dst->size.y));
|
params.draw_target_viewport = RECT_FROM_V2(V2(0, 0), V2(dst->size.x, dst->size.y));
|
||||||
params.draw_target_view = XFORM_IDENT;
|
params.draw_target_view = XFORM_IDENT;
|
||||||
gpu_dispatch(params);
|
gp_dispatch(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpu_present(struct v2i32 backbuffer_resolution, struct gpu_handle texture, struct xform texture_xf, i32 vsync)
|
void gp_present(struct v2i32 backbuffer_resolution, struct gp_handle texture, struct xform texture_xf, i32 vsync)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
|
|
||||||
@ -2047,7 +2047,7 @@ void gpu_present(struct v2i32 backbuffer_resolution, struct gpu_handle texture,
|
|||||||
present_blit(&G.backbuffer_texture, (struct dx11_texture *)texture.v, texture_xf);
|
present_blit(&G.backbuffer_texture, (struct dx11_texture *)texture.v, texture_xf);
|
||||||
|
|
||||||
/* Present */
|
/* Present */
|
||||||
gpu_capture_image_for_profiler();
|
capture_image_for_profiler();
|
||||||
{
|
{
|
||||||
__profscope(Present);
|
__profscope(Present);
|
||||||
IDXGISwapChain2_Present(G.swapchain, vsync, flags);
|
IDXGISwapChain2_Present(G.swapchain, vsync, flags);
|
||||||
@ -2071,7 +2071,7 @@ struct prof_cap {
|
|||||||
struct v2 size;
|
struct v2 size;
|
||||||
};
|
};
|
||||||
|
|
||||||
INTERNAL void gpu_capture_image_for_profiler(void)
|
INTERNAL void capture_image_for_profiler(void)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
|
|
||||||
@ -2148,7 +2148,7 @@ INTERNAL void gpu_capture_image_for_profiler(void)
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
INTERNAL void gpu_capture_image_for_profiler(void)
|
INTERNAL void capture_image_for_profiler(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
#if DX12_TEST
|
#if DX12_TEST
|
||||||
|
|
||||||
#include "gpu.h"
|
#include "gp.h"
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
#include "arena.h"
|
#include "arena.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
@ -115,7 +115,7 @@ struct command_descriptor_heap {
|
|||||||
D3D12_DESCRIPTOR_HEAP_TYPE type;
|
D3D12_DESCRIPTOR_HEAP_TYPE type;
|
||||||
ID3D12DescriptorHeap *heap;
|
ID3D12DescriptorHeap *heap;
|
||||||
D3D12_CPU_DESCRIPTOR_HANDLE cpu_handle;
|
D3D12_CPU_DESCRIPTOR_HANDLE cpu_handle;
|
||||||
D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle;
|
D3D12_GPU_DESCRIPTOR_HANDLE gp_handle;
|
||||||
|
|
||||||
struct command_descriptor_heap *next_in_command_list;
|
struct command_descriptor_heap *next_in_command_list;
|
||||||
|
|
||||||
@ -280,13 +280,13 @@ GLOBAL struct {
|
|||||||
struct dx12_resource *dummy_index_buffer;
|
struct dx12_resource *dummy_index_buffer;
|
||||||
D3D12_VERTEX_BUFFER_VIEW dummy_vertex_buffer_view;
|
D3D12_VERTEX_BUFFER_VIEW dummy_vertex_buffer_view;
|
||||||
D3D12_INDEX_BUFFER_VIEW quad_index_buffer_view;
|
D3D12_INDEX_BUFFER_VIEW quad_index_buffer_view;
|
||||||
} G = ZI, DEBUG_ALIAS(G, G_gpu_dx12);
|
} G = ZI, DEBUG_ALIAS(G, G_gp_dx12);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Startup
|
* Startup
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(gpu_shutdown);
|
INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(gp_shutdown);
|
||||||
INTERNAL void dx12_init_device(void);
|
INTERNAL void dx12_init_device(void);
|
||||||
INTERNAL void dx12_init_objects(void);
|
INTERNAL void dx12_init_objects(void);
|
||||||
INTERNAL void dx12_init_swapchain(struct sys_window *window);
|
INTERNAL void dx12_init_swapchain(struct sys_window *window);
|
||||||
@ -297,7 +297,7 @@ INTERNAL void command_queue_release(struct command_queue *cq);
|
|||||||
INTERNAL struct dx12_resource *dx12_resource_alloc_from_swapchain_buffer(ID3D12Resource *buff);
|
INTERNAL struct dx12_resource *dx12_resource_alloc_from_swapchain_buffer(ID3D12Resource *buff);
|
||||||
INTERNAL void dx12_resource_release(struct dx12_resource *resource);
|
INTERNAL void dx12_resource_release(struct dx12_resource *resource);
|
||||||
|
|
||||||
struct gpu_startup_receipt gpu_startup(struct work_startup_receipt *work_sr, struct sys_window *window)
|
struct gp_startup_receipt gp_startup(struct work_startup_receipt *work_sr, struct sys_window *window)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
(UNUSED)work_sr;
|
(UNUSED)work_sr;
|
||||||
@ -328,8 +328,8 @@ struct gpu_startup_receipt gpu_startup(struct work_startup_receipt *work_sr, str
|
|||||||
#if 0
|
#if 0
|
||||||
{
|
{
|
||||||
LOCAL_PERSIST const DXGI_FORMAT formats[] = {
|
LOCAL_PERSIST const DXGI_FORMAT formats[] = {
|
||||||
[GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM] = DXGI_FORMAT_R8G8B8A8_UNORM,
|
[GP_TEXTURE_FORMAT_R8G8B8A8_UNORM] = DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||||
[GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB] = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
|
[GP_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB] = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
|
||||||
};
|
};
|
||||||
|
|
||||||
enum dx12_resource_view_flags view_flags = DX12_RESOURCE_VIEW_FLAG_SRV;
|
enum dx12_resource_view_flags view_flags = DX12_RESOURCE_VIEW_FLAG_SRV;
|
||||||
@ -349,7 +349,7 @@ struct gpu_startup_receipt gpu_startup(struct work_startup_receipt *work_sr, str
|
|||||||
desc.MipLevels = 1;
|
desc.MipLevels = 1;
|
||||||
desc.SampleDesc.Count = 1;
|
desc.SampleDesc.Count = 1;
|
||||||
desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||||
if (flags & GPU_TEXTURE_FLAG_TARGETABLE) {
|
if (flags & GP_TEXTURE_FLAG_TARGETABLE) {
|
||||||
desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
|
desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
|
||||||
view_flags |= DX12_RESOURCE_VIEW_FLAG_RTV;
|
view_flags |= DX12_RESOURCE_VIEW_FLAG_RTV;
|
||||||
}
|
}
|
||||||
@ -388,13 +388,13 @@ struct gpu_startup_receipt gpu_startup(struct work_startup_receipt *work_sr, str
|
|||||||
|
|
||||||
|
|
||||||
/* Register callbacks */
|
/* Register callbacks */
|
||||||
app_register_exit_callback(gpu_shutdown);
|
app_register_exit_callback(gp_shutdown);
|
||||||
|
|
||||||
struct gpu_startup_receipt res = ZI;
|
struct gp_startup_receipt res = ZI;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(gpu_shutdown)
|
INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(gp_shutdown)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
#if DX12_DEBUG
|
#if DX12_DEBUG
|
||||||
@ -417,7 +417,7 @@ INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(gpu_shutdown)
|
|||||||
|
|
||||||
INTERNAL void dx12_resource_release(struct dx12_resource *t);
|
INTERNAL void dx12_resource_release(struct dx12_resource *t);
|
||||||
|
|
||||||
INTERNAL struct gpu_handle handle_alloc(enum handle_kind kind, void *data)
|
INTERNAL struct gp_handle handle_alloc(enum handle_kind kind, void *data)
|
||||||
{
|
{
|
||||||
u64 old_gen = 0;
|
u64 old_gen = 0;
|
||||||
u64 idx = 0;
|
u64 idx = 0;
|
||||||
@ -441,13 +441,13 @@ INTERNAL struct gpu_handle handle_alloc(enum handle_kind kind, void *data)
|
|||||||
entry->idx = idx;
|
entry->idx = idx;
|
||||||
entry->data = data;
|
entry->data = data;
|
||||||
|
|
||||||
struct gpu_handle res = ZI;
|
struct gp_handle res = ZI;
|
||||||
res.gen = entry->gen;
|
res.gen = entry->gen;
|
||||||
res.idx = entry->idx;
|
res.idx = entry->idx;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL struct handle_entry *handle_get_entry(struct gpu_handle handle, struct sys_lock *lock)
|
INTERNAL struct handle_entry *handle_get_entry(struct gp_handle handle, struct sys_lock *lock)
|
||||||
{
|
{
|
||||||
sys_assert_locked_e_or_s(lock, G.handle_entries_mutex);
|
sys_assert_locked_e_or_s(lock, G.handle_entries_mutex);
|
||||||
struct handle_entry *res = NULL;
|
struct handle_entry *res = NULL;
|
||||||
@ -460,7 +460,7 @@ INTERNAL struct handle_entry *handle_get_entry(struct gpu_handle handle, struct
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void *handle_get_data(struct gpu_handle handle, enum handle_kind kind)
|
INTERNAL void *handle_get_data(struct gp_handle handle, enum handle_kind kind)
|
||||||
{
|
{
|
||||||
void *data = NULL;
|
void *data = NULL;
|
||||||
struct sys_lock lock = sys_mutex_lock_s(G.handle_entries_mutex);
|
struct sys_lock lock = sys_mutex_lock_s(G.handle_entries_mutex);
|
||||||
@ -479,7 +479,7 @@ INTERNAL void *handle_get_data(struct gpu_handle handle, enum handle_kind kind)
|
|||||||
/* TODO: The GPU api should ensure that resources freed by the caller will not cause issues on the GPU (via fencing),
|
/* TODO: The GPU api should ensure that resources freed by the caller will not cause issues on the GPU (via fencing),
|
||||||
* however the caller is responsible for managing resource lifetimes on the CPU side (e.g. using sprites w/ sprite scopes
|
* however the caller is responsible for managing resource lifetimes on the CPU side (e.g. using sprites w/ sprite scopes
|
||||||
* to ensure freed textures aren't being used in pending command lists. */
|
* to ensure freed textures aren't being used in pending command lists. */
|
||||||
void gpu_release(struct gpu_handle handle)
|
void gp_release(struct gp_handle handle)
|
||||||
{
|
{
|
||||||
enum handle_kind kind = 0;
|
enum handle_kind kind = 0;
|
||||||
void *data = NULL;
|
void *data = NULL;
|
||||||
@ -1322,15 +1322,15 @@ INTERNAL struct plan *plan_alloc(void)
|
|||||||
return plan;
|
return plan;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct gpu_handle gpu_plan_alloc(void)
|
struct gp_handle gp_plan_alloc(void)
|
||||||
{
|
{
|
||||||
struct plan *plan = plan_alloc();
|
struct plan *plan = plan_alloc();
|
||||||
return handle_alloc(DX12_HANDLE_KIND_PLAN, plan);
|
return handle_alloc(DX12_HANDLE_KIND_PLAN, plan);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpu_push_cmd(struct gpu_handle gpu_plan, struct gpu_cmd_params params)
|
void gp_push_cmd(struct gp_handle gp_plan, struct gp_cmd_params params)
|
||||||
{
|
{
|
||||||
(UNUSED)gpu_plan;
|
(UNUSED)gp_plan;
|
||||||
(UNUSED)params;
|
(UNUSED)params;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1450,11 +1450,11 @@ INTERNAL enum D3D12_RESOURCE_STATES dx12_resource_barrier(ID3D12GraphicsCommandL
|
|||||||
return old_state;
|
return old_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct gpu_handle gpu_texture_alloc(enum gpu_texture_format format, u32 flags, struct v2i32 size, void *initial_data)
|
struct gp_handle gp_texture_alloc(enum gp_texture_format format, u32 flags, struct v2i32 size, void *initial_data)
|
||||||
{
|
{
|
||||||
LOCAL_PERSIST const DXGI_FORMAT formats[] = {
|
LOCAL_PERSIST const DXGI_FORMAT formats[] = {
|
||||||
[GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM] = DXGI_FORMAT_R8G8B8A8_UNORM,
|
[GP_TEXTURE_FORMAT_R8G8B8A8_UNORM] = DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||||
[GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB] = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
|
[GP_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB] = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
|
||||||
};
|
};
|
||||||
|
|
||||||
DXGI_FORMAT dxgi_format = 0;
|
DXGI_FORMAT dxgi_format = 0;
|
||||||
@ -1483,7 +1483,7 @@ struct gpu_handle gpu_texture_alloc(enum gpu_texture_format format, u32 flags, s
|
|||||||
desc.Format = dxgi_format;
|
desc.Format = dxgi_format;
|
||||||
desc.SampleDesc.Count = 1;
|
desc.SampleDesc.Count = 1;
|
||||||
desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||||
if (flags & GPU_TEXTURE_FLAG_TARGETABLE) {
|
if (flags & GP_TEXTURE_FLAG_TARGETABLE) {
|
||||||
desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
|
desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
|
||||||
view_flags |= DX12_RESOURCE_VIEW_FLAG_RTV;
|
view_flags |= DX12_RESOURCE_VIEW_FLAG_RTV;
|
||||||
}
|
}
|
||||||
@ -1498,13 +1498,13 @@ struct gpu_handle gpu_texture_alloc(enum gpu_texture_format format, u32 flags, s
|
|||||||
return handle_alloc(DX12_HANDLE_KIND_RESOURCE, r);
|
return handle_alloc(DX12_HANDLE_KIND_RESOURCE, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpu_texture_clear(struct gpu_handle target_resource, u32 clear_color)
|
void gp_texture_clear(struct gp_handle target_resource, u32 clear_color)
|
||||||
{
|
{
|
||||||
(UNUSED)target_resource;
|
(UNUSED)target_resource;
|
||||||
(UNUSED)clear_color;
|
(UNUSED)clear_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct v2i32 gpu_texture_get_size(struct gpu_handle resource)
|
struct v2i32 gp_texture_get_size(struct gp_handle resource)
|
||||||
{
|
{
|
||||||
struct v2i32 res = ZI;
|
struct v2i32 res = ZI;
|
||||||
struct dx12_resource *dx12_resource = handle_get_data(resource, DX12_HANDLE_KIND_RESOURCE);
|
struct dx12_resource *dx12_resource = handle_get_data(resource, DX12_HANDLE_KIND_RESOURCE);
|
||||||
@ -1725,7 +1725,7 @@ INTERNAL struct command_descriptor_heap *command_list_push_descriptor_heap(struc
|
|||||||
/* Remove from submitted list */
|
/* Remove from submitted list */
|
||||||
old_heap = cdh->heap;
|
old_heap = cdh->heap;
|
||||||
old_cpu_handle = cdh->cpu_handle;
|
old_cpu_handle = cdh->cpu_handle;
|
||||||
old_gpu_handle = cdh->gpu_handle;
|
old_gpu_handle = cdh->gp_handle;
|
||||||
struct command_descriptor_heap *prev = cdh->prev_submitted;
|
struct command_descriptor_heap *prev = cdh->prev_submitted;
|
||||||
struct command_descriptor_heap *next = cdh->next_submitted;
|
struct command_descriptor_heap *next = cdh->next_submitted;
|
||||||
if (prev) {
|
if (prev) {
|
||||||
@ -1749,7 +1749,7 @@ INTERNAL struct command_descriptor_heap *command_list_push_descriptor_heap(struc
|
|||||||
if (old_heap) {
|
if (old_heap) {
|
||||||
cdh->heap = old_heap;
|
cdh->heap = old_heap;
|
||||||
cdh->cpu_handle = old_cpu_handle;
|
cdh->cpu_handle = old_cpu_handle;
|
||||||
cdh->gpu_handle = old_gpu_handle;
|
cdh->gp_handle = old_gpu_handle;
|
||||||
} else {
|
} else {
|
||||||
D3D12_DESCRIPTOR_HEAP_DESC desc = ZI;
|
D3D12_DESCRIPTOR_HEAP_DESC desc = ZI;
|
||||||
desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||||
@ -1760,7 +1760,7 @@ INTERNAL struct command_descriptor_heap *command_list_push_descriptor_heap(struc
|
|||||||
sys_panic(LIT("Failed to create GPU descriptor heap"));
|
sys_panic(LIT("Failed to create GPU descriptor heap"));
|
||||||
}
|
}
|
||||||
ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(cdh->heap, &cdh->cpu_handle);
|
ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(cdh->heap, &cdh->cpu_handle);
|
||||||
ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(cdh->heap, &cdh->gpu_handle);
|
ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(cdh->heap, &cdh->gp_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy CPU heap */
|
/* Copy CPU heap */
|
||||||
@ -1868,8 +1868,8 @@ INTERNAL struct command_buffer *command_list_push_buffer(struct command_list *cl
|
|||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
LOCAL_PERSIST const DXGI_FORMAT formats[] = {
|
LOCAL_PERSIST const DXGI_FORMAT formats[] = {
|
||||||
[GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM] = DXGI_FORMAT_R8G8B8A8_UNORM,
|
[GP_TEXTURE_FORMAT_R8G8B8A8_UNORM] = DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||||
[GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB] = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
|
[GP_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB] = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
|
||||||
};
|
};
|
||||||
|
|
||||||
DXGI_FORMAT dxgi_format = 0;
|
DXGI_FORMAT dxgi_format = 0;
|
||||||
@ -1924,7 +1924,7 @@ INTERNAL struct command_buffer *command_list_push_buffer(struct command_list *cl
|
|||||||
* Dispatch
|
* Dispatch
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
void gpu_dispatch(struct gpu_dispatch_params params)
|
void gp_dispatch(struct gp_dispatch_params params)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
|
|
||||||
@ -1976,12 +1976,12 @@ void gpu_dispatch(struct gpu_dispatch_params params)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Bind instance buffer */
|
/* Bind instance buffer */
|
||||||
//ID3D12GraphicsCommandList_SetGraphicsRootShaderResourceView(cl->cl, 1, instance_buffer->gpu_handle);
|
//ID3D12GraphicsCommandList_SetGraphicsRootShaderResourceView(cl->cl, 1, instance_buffer->gp_handle);
|
||||||
|
|
||||||
/* Bind descriptor heap */
|
/* Bind descriptor heap */
|
||||||
ID3D12DescriptorHeap *heaps[] = { descriptor_heap->heap };
|
ID3D12DescriptorHeap *heaps[] = { descriptor_heap->heap };
|
||||||
ID3D12GraphicsCommandList_SetDescriptorHeaps(cl->cl, ARRAY_COUNT(heaps), heaps);
|
ID3D12GraphicsCommandList_SetDescriptorHeaps(cl->cl, ARRAY_COUNT(heaps), heaps);
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(cl->cl, 2, descriptor_heap->gpu_handle);
|
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(cl->cl, 2, descriptor_heap->gp_handle);
|
||||||
|
|
||||||
/* Setup Rasterizer State */
|
/* Setup Rasterizer State */
|
||||||
ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &d3d12_viewport);
|
ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &d3d12_viewport);
|
||||||
@ -2011,7 +2011,7 @@ void gpu_dispatch(struct gpu_dispatch_params params)
|
|||||||
* Present
|
* Present
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
void gpu_present(struct v2i32 backbuffer_resolution, struct gpu_handle texture, struct xform texture_xf, i32 vsync)
|
void gp_present(struct v2i32 backbuffer_resolution, struct gp_handle texture, struct xform texture_xf, i32 vsync)
|
||||||
{
|
{
|
||||||
(UNUSED)backbuffer_resolution;
|
(UNUSED)backbuffer_resolution;
|
||||||
(UNUSED)texture;
|
(UNUSED)texture;
|
||||||
12
src/sprite.c
12
src/sprite.c
@ -9,7 +9,7 @@
|
|||||||
#include "work.h"
|
#include "work.h"
|
||||||
#include "atomic.h"
|
#include "atomic.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "gpu.h"
|
#include "gp.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
#include "rand.h"
|
#include "rand.h"
|
||||||
|
|
||||||
@ -210,10 +210,10 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(sprite_evictor_thread_entry_point, arg)
|
|||||||
INTERNAL RESOURCE_WATCH_CALLBACK_FUNC_DEF(sprite_resource_watch_callback, info);
|
INTERNAL RESOURCE_WATCH_CALLBACK_FUNC_DEF(sprite_resource_watch_callback, info);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct sprite_startup_receipt sprite_startup(struct gpu_startup_receipt *gpu_sr,
|
struct sprite_startup_receipt sprite_startup(struct gp_startup_receipt *gp_sr,
|
||||||
struct resource_startup_receipt *resource_sr)
|
struct resource_startup_receipt *resource_sr)
|
||||||
{
|
{
|
||||||
(UNUSED)gpu_sr;
|
(UNUSED)gp_sr;
|
||||||
(UNUSED)resource_sr;
|
(UNUSED)resource_sr;
|
||||||
|
|
||||||
G.perm_arena = arena_alloc(MEGABYTE(1));
|
G.perm_arena = arena_alloc(MEGABYTE(1));
|
||||||
@ -227,7 +227,7 @@ struct sprite_startup_receipt sprite_startup(struct gpu_startup_receipt *gpu_sr,
|
|||||||
{
|
{
|
||||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||||
struct image_rgba purple_black_image = generate_purple_black_image(scratch.arena, 64, 64);
|
struct image_rgba purple_black_image = generate_purple_black_image(scratch.arena, 64, 64);
|
||||||
G.nil_texture->texture = gpu_texture_alloc(GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, V2I32(purple_black_image.width, purple_black_image.height), purple_black_image.pixels);
|
G.nil_texture->texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, V2I32(purple_black_image.width, purple_black_image.height), purple_black_image.pixels);
|
||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,7 +379,7 @@ INTERNAL void cache_entry_load_texture(struct cache_ref ref, struct sprite_tag t
|
|||||||
e->texture = arena_push(e->arena, struct sprite_texture);
|
e->texture = arena_push(e->arena, struct sprite_texture);
|
||||||
e->texture->width = decoded.image.width;
|
e->texture->width = decoded.image.width;
|
||||||
e->texture->height = decoded.image.height;
|
e->texture->height = decoded.image.height;
|
||||||
e->texture->texture = gpu_texture_alloc(GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB, 0, V2I32(decoded.image.width, decoded.image.height), decoded.image.pixels);
|
e->texture->texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB, 0, V2I32(decoded.image.width, decoded.image.height), decoded.image.pixels);
|
||||||
e->texture->valid = true;
|
e->texture->valid = true;
|
||||||
e->texture->loaded = true;
|
e->texture->loaded = true;
|
||||||
/* TODO: Query gpu for more accurate texture size in VRAM */
|
/* TODO: Query gpu for more accurate texture size in VRAM */
|
||||||
@ -1358,7 +1358,7 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(sprite_evictor_thread_entry_point, arg)
|
|||||||
for (struct evict_node *en = first_evicted; en; en = en->next_evicted) {
|
for (struct evict_node *en = first_evicted; en; en = en->next_evicted) {
|
||||||
struct cache_entry *n = en->cache_entry;
|
struct cache_entry *n = en->cache_entry;
|
||||||
if (n->kind == CACHE_ENTRY_KIND_TEXTURE && n->texture->valid) {
|
if (n->kind == CACHE_ENTRY_KIND_TEXTURE && n->texture->valid) {
|
||||||
gpu_release(n->texture->texture);
|
gp_release(n->texture->texture);
|
||||||
}
|
}
|
||||||
arena_release(n->arena);
|
arena_release(n->arena);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
#ifndef SPRITE_H
|
#ifndef SPRITE_H
|
||||||
#define SPRITE_H
|
#define SPRITE_H
|
||||||
|
|
||||||
#include "gpu.h"
|
#include "gp.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
struct gpu_startup_receipt;
|
struct gp_startup_receipt;
|
||||||
struct resource_startup_receipt;
|
struct resource_startup_receipt;
|
||||||
struct sprite_sheet_span;
|
struct sprite_sheet_span;
|
||||||
struct sprite_sheet_slice_group;
|
struct sprite_sheet_slice_group;
|
||||||
@ -14,7 +14,7 @@ struct sprite_sheet_slice_group;
|
|||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct sprite_startup_receipt { i32 _; };
|
struct sprite_startup_receipt { i32 _; };
|
||||||
struct sprite_startup_receipt sprite_startup(struct gpu_startup_receipt *gpu_sr,
|
struct sprite_startup_receipt sprite_startup(struct gp_startup_receipt *gp_sr,
|
||||||
struct resource_startup_receipt *resource_sr);
|
struct resource_startup_receipt *resource_sr);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
@ -48,7 +48,7 @@ void sprite_scope_end(struct sprite_scope *scope);
|
|||||||
struct sprite_texture {
|
struct sprite_texture {
|
||||||
b32 loaded;
|
b32 loaded;
|
||||||
b32 valid;
|
b32 valid;
|
||||||
struct gpu_handle texture;
|
struct gp_handle texture;
|
||||||
u32 width;
|
u32 width;
|
||||||
u32 height;
|
u32 height;
|
||||||
};
|
};
|
||||||
|
|||||||
162
src/user.c
162
src/user.c
@ -2,7 +2,7 @@
|
|||||||
#include "sim.h"
|
#include "sim.h"
|
||||||
#include "sim_ent.h"
|
#include "sim_ent.h"
|
||||||
#include "sim_step.h"
|
#include "sim_step.h"
|
||||||
#include "gpu.h"
|
#include "gp.h"
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
@ -71,10 +71,10 @@ GLOBAL struct {
|
|||||||
struct second_stat net_bytes_sent;
|
struct second_stat net_bytes_sent;
|
||||||
|
|
||||||
/* Gpu handles */
|
/* Gpu handles */
|
||||||
struct gpu_handle user_texture;
|
struct gp_handle user_texture;
|
||||||
|
|
||||||
struct gpu_handle world_gpu_plan;
|
struct gp_handle world_gp_plan;
|
||||||
struct gpu_handle ui_gpu_plan;
|
struct gp_handle ui_gp_plan;
|
||||||
|
|
||||||
struct xform world_to_user_xf;
|
struct xform world_to_user_xf;
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(user_local_sim_thread_entry_point, arg)
|
|||||||
INTERNAL SYS_WINDOW_EVENT_CALLBACK_FUNC_DEF(window_event_callback, event);
|
INTERNAL SYS_WINDOW_EVENT_CALLBACK_FUNC_DEF(window_event_callback, event);
|
||||||
|
|
||||||
struct user_startup_receipt user_startup(struct work_startup_receipt *work_sr,
|
struct user_startup_receipt user_startup(struct work_startup_receipt *work_sr,
|
||||||
struct gpu_startup_receipt *gpu_sr,
|
struct gp_startup_receipt *gp_sr,
|
||||||
struct font_startup_receipt *font_sr,
|
struct font_startup_receipt *font_sr,
|
||||||
struct sprite_startup_receipt *sprite_sr,
|
struct sprite_startup_receipt *sprite_sr,
|
||||||
struct draw_startup_receipt *draw_sr,
|
struct draw_startup_receipt *draw_sr,
|
||||||
@ -214,7 +214,7 @@ struct user_startup_receipt user_startup(struct work_startup_receipt *work_sr,
|
|||||||
struct sys_window *window)
|
struct sys_window *window)
|
||||||
{
|
{
|
||||||
(UNUSED)work_sr;
|
(UNUSED)work_sr;
|
||||||
(UNUSED)gpu_sr;
|
(UNUSED)gp_sr;
|
||||||
(UNUSED)font_sr;
|
(UNUSED)font_sr;
|
||||||
(UNUSED)sprite_sr;
|
(UNUSED)sprite_sr;
|
||||||
(UNUSED)draw_sr;
|
(UNUSED)draw_sr;
|
||||||
@ -253,8 +253,8 @@ struct user_startup_receipt user_startup(struct work_startup_receipt *work_sr,
|
|||||||
|
|
||||||
/* GPU handles */
|
/* GPU handles */
|
||||||
G.world_to_user_xf = XFORM_IDENT;
|
G.world_to_user_xf = XFORM_IDENT;
|
||||||
G.world_gpu_plan = gpu_plan_alloc();
|
G.world_gp_plan = gp_plan_alloc();
|
||||||
G.ui_gpu_plan = gpu_plan_alloc();
|
G.ui_gp_plan = gp_plan_alloc();
|
||||||
|
|
||||||
G.console_logs_mutex = sys_mutex_alloc();
|
G.console_logs_mutex = sys_mutex_alloc();
|
||||||
G.console_logs_arena = arena_alloc(GIGABYTE(64));
|
G.console_logs_arena = arena_alloc(GIGABYTE(64));
|
||||||
@ -341,13 +341,13 @@ INTERNAL void debug_draw_xform(struct xform xf, u32 color_x, u32 color_y)
|
|||||||
x_ray = v2_mul(x_ray, ray_scale);
|
x_ray = v2_mul(x_ray, ray_scale);
|
||||||
y_ray = v2_mul(y_ray, ray_scale);
|
y_ray = v2_mul(y_ray, ray_scale);
|
||||||
|
|
||||||
draw_arrow_ray(G.ui_gpu_plan, pos, x_ray, thickness, arrowhead_len, color_x);
|
draw_arrow_ray(G.ui_gp_plan, pos, x_ray, thickness, arrowhead_len, color_x);
|
||||||
draw_arrow_ray(G.ui_gpu_plan, pos, y_ray, thickness, arrowhead_len, color_y);
|
draw_arrow_ray(G.ui_gp_plan, pos, y_ray, thickness, arrowhead_len, color_y);
|
||||||
|
|
||||||
//u32 color_quad = RGBA32_F(0, 1, 1, 0.3);
|
//u32 color_quad = RGBA32_F(0, 1, 1, 0.3);
|
||||||
//struct quad quad = quad_from_rect(RECT(0, 0, 1, -1));
|
//struct quad quad = quad_from_rect(RECT(0, 0, 1, -1));
|
||||||
//quad = xform_mul_quad(xf, quad_scale(quad, 0.075f));
|
//quad = xform_mul_quad(xf, quad_scale(quad, 0.075f));
|
||||||
//draw_quad(G.ui_gpu_plan, quad, color);
|
//draw_quad(G.ui_gp_plan, quad, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void debug_draw_movement(struct sim_ent *ent)
|
INTERNAL void debug_draw_movement(struct sim_ent *ent)
|
||||||
@ -364,7 +364,7 @@ INTERNAL void debug_draw_movement(struct sim_ent *ent)
|
|||||||
struct v2 vel_ray = xform_basis_mul_v2(G.world_to_user_xf, velocity);
|
struct v2 vel_ray = xform_basis_mul_v2(G.world_to_user_xf, velocity);
|
||||||
|
|
||||||
if (v2_len(vel_ray) > 0.00001) {
|
if (v2_len(vel_ray) > 0.00001) {
|
||||||
draw_arrow_ray(G.ui_gpu_plan, pos, vel_ray, thickness, arrow_len, color_vel);
|
draw_arrow_ray(G.ui_gp_plan, pos, vel_ray, thickness, arrow_len, color_vel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,7 +534,7 @@ INTERNAL void draw_debug_console(i32 level, b32 minimized)
|
|||||||
if (log->level <= level) {
|
if (log->level <= level) {
|
||||||
/* Draw background */
|
/* Draw background */
|
||||||
u32 color = colors[log->level][log->color_index];
|
u32 color = colors[log->level][log->color_index];
|
||||||
draw_quad(G.ui_gpu_plan, quad_from_rect(log->bounds), ALPHA32_F(color, opacity));
|
draw_quad(G.ui_gp_plan, quad_from_rect(log->bounds), ALPHA32_F(color, opacity));
|
||||||
|
|
||||||
/* Draw text */
|
/* Draw text */
|
||||||
struct string text = log->msg;
|
struct string text = log->msg;
|
||||||
@ -551,7 +551,7 @@ INTERNAL void draw_debug_console(i32 level, b32 minimized)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct draw_text_params params = DRAW_TEXT_PARAMS(.font = font, .pos = draw_pos, .offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM, .color = ALPHA32_F(COLOR_WHITE, opacity), .str = text);
|
struct draw_text_params params = DRAW_TEXT_PARAMS(.font = font, .pos = draw_pos, .offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM, .color = ALPHA32_F(COLOR_WHITE, opacity), .str = text);
|
||||||
struct rect bounds = draw_text(G.ui_gpu_plan, params);
|
struct rect bounds = draw_text(G.ui_gp_plan, params);
|
||||||
|
|
||||||
struct rect draw_bounds = bounds;
|
struct rect draw_bounds = bounds;
|
||||||
draw_bounds.x -= bg_margin;
|
draw_bounds.x -= bg_margin;
|
||||||
@ -1050,7 +1050,7 @@ INTERNAL void user_update(void)
|
|||||||
struct v2 size = xform_basis_invert_mul_v2(G.world_to_user_xf, G.user_size);
|
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 color0 = RGBA32_F(0.17f, 0.17f, 0.17f, 1.f);
|
||||||
u32 color1 = RGBA32_F(0.15f, 0.15f, 0.15f, 1.f);
|
u32 color1 = RGBA32_F(0.15f, 0.15f, 0.15f, 1.f);
|
||||||
draw_grid(G.world_gpu_plan, 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_gp_plan, xform_from_rect(RECT_FROM_V2(pos, size)), color0, color1, RGBA32(0x3f, 0x3f, 0x3f, 0xFF), COLOR_RED, COLOR_GREEN, thickness, spacing, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
@ -1060,10 +1060,10 @@ INTERNAL void user_update(void)
|
|||||||
{
|
{
|
||||||
struct v2 pos = xform_invert_mul_v2(G.world_to_user_xf, V2(0, 0));
|
struct v2 pos = xform_invert_mul_v2(G.world_to_user_xf, V2(0, 0));
|
||||||
struct v2 size = xform_basis_invert_mul_v2(G.world_to_user_xf, G.user_size);
|
struct v2 size = xform_basis_invert_mul_v2(G.world_to_user_xf, G.user_size);
|
||||||
struct gpu_cmd_params cmd = ZI;
|
struct gp_cmd_params cmd = ZI;
|
||||||
cmd.kind = GPU_CMD_KIND_TEST;
|
cmd.kind = GP_CMD_KIND_TEST;
|
||||||
cmd.test.xf = xform_from_rect(RECT_FROM_V2(pos, size));
|
cmd.test.xf = xform_from_rect(RECT_FROM_V2(pos, size));
|
||||||
gpu_push_cmd(G.world_gpu_plan, cmd);
|
gp_push_cmd(G.world_gp_plan, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -1245,9 +1245,9 @@ INTERNAL void user_update(void)
|
|||||||
u32 color_end = RGBA32_F(1, 0.8, 0.4, opacity_b);
|
u32 color_end = RGBA32_F(1, 0.8, 0.4, opacity_b);
|
||||||
|
|
||||||
if (opacity_b > 0.99f) {
|
if (opacity_b > 0.99f) {
|
||||||
draw_circle(G.world_gpu_plan, b, thickness / 2, color_end, 20);
|
draw_circle(G.world_gp_plan, b, thickness / 2, color_end, 20);
|
||||||
}
|
}
|
||||||
draw_gradient_line(G.world_gpu_plan, a, b, thickness, color_start, color_end);
|
draw_gradient_line(G.world_gp_plan, a, b, thickness, color_start, color_end);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1263,7 +1263,7 @@ INTERNAL void user_update(void)
|
|||||||
u32 tint = ent->sprite_tint;
|
u32 tint = ent->sprite_tint;
|
||||||
struct sprite_sheet_frame frame = sprite_sheet_get_frame(sheet, ent->animation_frame);
|
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);
|
struct draw_texture_params params = DRAW_TEXTURE_PARAMS(.xf = sprite_xform, .sprite = sprite, .tint = tint, .clip = frame.clip, .emittance = emittance);
|
||||||
draw_texture(G.world_gpu_plan, params);
|
draw_texture(G.world_gp_plan, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1283,7 +1283,7 @@ INTERNAL void user_update(void)
|
|||||||
struct v2 pos = sim_pos_from_world_tile_index(world_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 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);
|
struct draw_texture_params params = DRAW_TEXTURE_PARAMS(.xf = tile_xf, .sprite = tile_sprite);
|
||||||
draw_texture(G.world_gpu_plan, params);
|
draw_texture(G.world_gp_plan, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1311,7 +1311,7 @@ INTERNAL void user_update(void)
|
|||||||
u32 color = RGBA32_F(1, 0, 1, 0.5);
|
u32 color = RGBA32_F(1, 0, 1, 0.5);
|
||||||
struct quad quad = quad_from_aabb(aabb);
|
struct quad quad = quad_from_aabb(aabb);
|
||||||
quad = xform_mul_quad(G.world_to_user_xf, quad);
|
quad = xform_mul_quad(G.world_to_user_xf, quad);
|
||||||
draw_quad_line(G.ui_gpu_plan, quad, thickness, color);
|
draw_quad_line(G.ui_gp_plan, quad, thickness, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw focus arrow */
|
/* Draw focus arrow */
|
||||||
@ -1322,7 +1322,7 @@ INTERNAL void user_update(void)
|
|||||||
start = xform_mul_v2(G.world_to_user_xf, start);
|
start = xform_mul_v2(G.world_to_user_xf, start);
|
||||||
struct v2 end = v2_add(xf.og, ent->control.focus);
|
struct v2 end = v2_add(xf.og, ent->control.focus);
|
||||||
end = xform_mul_v2(G.world_to_user_xf, end);
|
end = xform_mul_v2(G.world_to_user_xf, end);
|
||||||
draw_arrow_line(G.ui_gpu_plan, start, end, 3, 10, RGBA32_F(1, 1, 1, 0.5));
|
draw_arrow_line(G.ui_gp_plan, start, end, 3, 10, RGBA32_F(1, 1, 1, 0.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -1348,16 +1348,16 @@ INTERNAL void user_update(void)
|
|||||||
struct quad quad = quad_from_rect(slice.rect);
|
struct quad quad = quad_from_rect(slice.rect);
|
||||||
quad = xform_mul_quad(sprite_xform, quad);
|
quad = xform_mul_quad(sprite_xform, quad);
|
||||||
quad = xform_mul_quad(G.world_to_user_xf, quad);
|
quad = xform_mul_quad(G.world_to_user_xf, quad);
|
||||||
draw_quad_line(G.ui_gpu_plan, quad, 2, quad_color);
|
draw_quad_line(G.ui_gp_plan, quad, 2, quad_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_circle(G.ui_gpu_plan, center, 3, point_color, 20);
|
draw_circle(G.ui_gp_plan, center, 3, point_color, 20);
|
||||||
|
|
||||||
if (slice.has_ray) {
|
if (slice.has_ray) {
|
||||||
struct v2 ray = xform_basis_mul_v2(sprite_xform, slice.dir);
|
struct v2 ray = xform_basis_mul_v2(sprite_xform, slice.dir);
|
||||||
ray = xform_basis_mul_v2(G.world_to_user_xf, ray);
|
ray = xform_basis_mul_v2(G.world_to_user_xf, ray);
|
||||||
ray = v2_with_len(ray, 25);
|
ray = v2_with_len(ray, 25);
|
||||||
draw_arrow_ray(G.ui_gpu_plan, center, ray, 2, 10, ray_color);
|
draw_arrow_ray(G.ui_gp_plan, center, ray, 2, 10, ray_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1374,7 +1374,7 @@ INTERNAL void user_update(void)
|
|||||||
f32 radius = 3;
|
f32 radius = 3;
|
||||||
struct v2 point = xform_mul_v2(e1_xf, ent->weld_joint_data.point_local_e1);
|
struct v2 point = xform_mul_v2(e1_xf, ent->weld_joint_data.point_local_e1);
|
||||||
point = xform_mul_v2(G.world_to_user_xf, point);
|
point = xform_mul_v2(G.world_to_user_xf, point);
|
||||||
draw_circle(G.ui_gpu_plan, point, radius, color, 10);
|
draw_circle(G.ui_gp_plan, point, radius, color, 10);
|
||||||
|
|
||||||
DEBUGBREAKABLE;
|
DEBUGBREAKABLE;
|
||||||
}
|
}
|
||||||
@ -1389,8 +1389,8 @@ INTERNAL void user_update(void)
|
|||||||
struct v2 point_end = G.world_cursor;
|
struct v2 point_end = G.world_cursor;
|
||||||
point_start = xform_mul_v2(G.world_to_user_xf, point_start);
|
point_start = xform_mul_v2(G.world_to_user_xf, point_start);
|
||||||
point_end = xform_mul_v2(G.world_to_user_xf, point_end);
|
point_end = xform_mul_v2(G.world_to_user_xf, point_end);
|
||||||
draw_arrow_line(G.ui_gpu_plan, point_start, point_end, 3, 10, color);
|
draw_arrow_line(G.ui_gp_plan, point_start, point_end, 3, 10, color);
|
||||||
draw_circle(G.ui_gpu_plan, point_start, 4, color, 10);
|
draw_circle(G.ui_gp_plan, point_start, 4, color, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw collider */
|
/* Draw collider */
|
||||||
@ -1402,13 +1402,13 @@ INTERNAL void user_update(void)
|
|||||||
/* Draw collider using support points */
|
/* Draw collider using support points */
|
||||||
u32 detail = 32;
|
u32 detail = 32;
|
||||||
struct xform collider_draw_xf = xform_mul(G.world_to_user_xf, xf);
|
struct xform collider_draw_xf = xform_mul(G.world_to_user_xf, xf);
|
||||||
draw_collider_line(G.ui_gpu_plan, collider, collider_draw_xf, thickness, color, detail);
|
draw_collider_line(G.ui_gp_plan, collider, collider_draw_xf, thickness, color, detail);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
/* Draw collider shape points */
|
/* Draw collider shape points */
|
||||||
for (u32 i = 0; i < collider.count; ++i) {
|
for (u32 i = 0; i < collider.count; ++i) {
|
||||||
struct v2 p = xform_mul_v2(xform_mul(G.world_to_user_xf, xf), collider.points[i]);
|
struct v2 p = xform_mul_v2(xform_mul(G.world_to_user_xf, xf), collider.points[i]);
|
||||||
draw_circle(G.ui_gpu_plan, p, 3, COLOR_BLUE, 10);
|
draw_circle(G.ui_gp_plan, p, 3, COLOR_BLUE, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (collider.count == 1 && collider.radius > 0) {
|
if (collider.count == 1 && collider.radius > 0) {
|
||||||
@ -1417,14 +1417,14 @@ INTERNAL void user_update(void)
|
|||||||
struct v2 end = collider_get_support_point(&collider, xf, v2_neg(xf.by)).p;
|
struct v2 end = collider_get_support_point(&collider, xf, v2_neg(xf.by)).p;
|
||||||
start = xform_mul_v2(G.world_to_user_xf, start);
|
start = xform_mul_v2(G.world_to_user_xf, start);
|
||||||
end = xform_mul_v2(G.world_to_user_xf, end);
|
end = xform_mul_v2(G.world_to_user_xf, end);
|
||||||
draw_line(G.ui_gpu_plan, start, end, thickness, color);
|
draw_line(G.ui_gp_plan, start, end, thickness, color);
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
/* Draw support point at focus dir */
|
/* Draw support point at focus dir */
|
||||||
{
|
{
|
||||||
struct v2 p = collider_support_point(&collider, xf, ent->control.focus);
|
struct v2 p = collider_support_point(&collider, xf, ent->control.focus);
|
||||||
p = xform_mul_v2(G.world_to_user_xf, p);
|
p = xform_mul_v2(G.world_to_user_xf, p);
|
||||||
draw_circle(G.ui_gpu_plan, p, 3, COLOR_RED, 10);
|
draw_circle(G.ui_gp_plan, p, 3, COLOR_RED, 10);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -1448,7 +1448,7 @@ INTERNAL void user_update(void)
|
|||||||
|
|
||||||
/* Draw point */
|
/* Draw point */
|
||||||
{
|
{
|
||||||
draw_circle(G.ui_gpu_plan, xform_mul_v2(G.world_to_user_xf, dbg_pt), radius, color, 10);
|
draw_circle(G.ui_gp_plan, xform_mul_v2(G.world_to_user_xf, dbg_pt), radius, color, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw normal */
|
/* Draw normal */
|
||||||
@ -1458,7 +1458,7 @@ INTERNAL void user_update(void)
|
|||||||
f32 arrow_height = 5;
|
f32 arrow_height = 5;
|
||||||
struct v2 start = xform_mul_v2(G.world_to_user_xf, dbg_pt);
|
struct v2 start = xform_mul_v2(G.world_to_user_xf, dbg_pt);
|
||||||
struct v2 end = xform_mul_v2(G.world_to_user_xf, v2_add(dbg_pt, v2_mul(v2_norm(data->normal), len)));
|
struct v2 end = xform_mul_v2(G.world_to_user_xf, v2_add(dbg_pt, v2_mul(v2_norm(data->normal), len)));
|
||||||
draw_arrow_line(G.ui_gpu_plan, start, end, arrow_thickness, arrow_height, color);
|
draw_arrow_line(G.ui_gp_plan, start, end, arrow_thickness, arrow_height, color);
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
/* Draw contact info */
|
/* Draw contact info */
|
||||||
@ -1488,7 +1488,7 @@ INTERNAL void user_update(void)
|
|||||||
FMT_UINT(data->num_points));
|
FMT_UINT(data->num_points));
|
||||||
|
|
||||||
|
|
||||||
draw_text(G.ui_gpu_plan, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, dbg_pt)), V2(0, offset_px)), text);
|
draw_text(G.ui_gp_plan, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, dbg_pt)), V2(0, offset_px)), text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1516,8 +1516,8 @@ INTERNAL void user_update(void)
|
|||||||
u32 color = RGBA32_F(1, 1, 0, 0.5);
|
u32 color = RGBA32_F(1, 1, 0, 0.5);
|
||||||
struct v2 a = xform_mul_v2(G.world_to_user_xf, data->closest0);
|
struct v2 a = xform_mul_v2(G.world_to_user_xf, data->closest0);
|
||||||
struct v2 b = xform_mul_v2(G.world_to_user_xf, data->closest1);
|
struct v2 b = xform_mul_v2(G.world_to_user_xf, data->closest1);
|
||||||
draw_circle(G.ui_gpu_plan, a, radius, color, 10);
|
draw_circle(G.ui_gp_plan, a, radius, color, 10);
|
||||||
draw_circle(G.ui_gpu_plan, b, radius, color, 10);
|
draw_circle(G.ui_gp_plan, b, radius, color, 10);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1534,28 +1534,28 @@ INTERNAL void user_update(void)
|
|||||||
{
|
{
|
||||||
struct v2 a = xform_mul_v2(G.world_to_user_xf, collider_res.a0);
|
struct v2 a = xform_mul_v2(G.world_to_user_xf, collider_res.a0);
|
||||||
struct v2 b = xform_mul_v2(G.world_to_user_xf, collider_res.b0);
|
struct v2 b = xform_mul_v2(G.world_to_user_xf, collider_res.b0);
|
||||||
draw_line(G.ui_gpu_plan, a, b, thickness, color_line);
|
draw_line(G.ui_gp_plan, a, b, thickness, color_line);
|
||||||
draw_circle(G.ui_gpu_plan, a, radius, color_a, 10);
|
draw_circle(G.ui_gp_plan, a, radius, color_a, 10);
|
||||||
draw_circle(G.ui_gpu_plan, b, radius, color_b, 10);
|
draw_circle(G.ui_gp_plan, b, radius, color_b, 10);
|
||||||
|
|
||||||
struct v2 a_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.a0_clipped);
|
struct v2 a_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.a0_clipped);
|
||||||
struct v2 b_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.b0_clipped);
|
struct v2 b_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.b0_clipped);
|
||||||
draw_line(G.ui_gpu_plan, a_clipped, b_clipped, thickness, color_line_clipped);
|
draw_line(G.ui_gp_plan, a_clipped, b_clipped, thickness, color_line_clipped);
|
||||||
draw_circle(G.ui_gpu_plan, a_clipped, radius, color_a_clipped, 10);
|
draw_circle(G.ui_gp_plan, a_clipped, radius, color_a_clipped, 10);
|
||||||
draw_circle(G.ui_gpu_plan, b_clipped, radius, color_b_clipped, 10);
|
draw_circle(G.ui_gp_plan, b_clipped, radius, color_b_clipped, 10);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
struct v2 a = xform_mul_v2(G.world_to_user_xf, collider_res.a1);
|
struct v2 a = xform_mul_v2(G.world_to_user_xf, collider_res.a1);
|
||||||
struct v2 b = xform_mul_v2(G.world_to_user_xf, collider_res.b1);
|
struct v2 b = xform_mul_v2(G.world_to_user_xf, collider_res.b1);
|
||||||
draw_line(G.ui_gpu_plan, a, b, thickness, color_line);
|
draw_line(G.ui_gp_plan, a, b, thickness, color_line);
|
||||||
draw_circle(G.ui_gpu_plan, a, radius, color_a, 10);
|
draw_circle(G.ui_gp_plan, a, radius, color_a, 10);
|
||||||
draw_circle(G.ui_gpu_plan, b, radius, color_b, 10);
|
draw_circle(G.ui_gp_plan, b, radius, color_b, 10);
|
||||||
|
|
||||||
struct v2 a_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.a1_clipped);
|
struct v2 a_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.a1_clipped);
|
||||||
struct v2 b_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.b1_clipped);
|
struct v2 b_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.b1_clipped);
|
||||||
draw_line(G.ui_gpu_plan, a_clipped, b_clipped, thickness, color_line_clipped);
|
draw_line(G.ui_gp_plan, a_clipped, b_clipped, thickness, color_line_clipped);
|
||||||
draw_circle(G.ui_gpu_plan, a_clipped, radius, color_a_clipped, 10);
|
draw_circle(G.ui_gp_plan, a_clipped, radius, color_a_clipped, 10);
|
||||||
draw_circle(G.ui_gpu_plan, b_clipped, radius, color_b_clipped, 10);
|
draw_circle(G.ui_gp_plan, b_clipped, radius, color_b_clipped, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1596,7 +1596,7 @@ INTERNAL void user_update(void)
|
|||||||
FMT_FLOAT_P(xform_get_rotation(e1_xf), 24));
|
FMT_FLOAT_P(xform_get_rotation(e1_xf), 24));
|
||||||
|
|
||||||
|
|
||||||
draw_text(G.ui_gpu_plan, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, V2(0, 0))), V2(0, offset_px)), text);
|
draw_text(G.ui_gp_plan, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, V2(0, 0))), V2(0, offset_px)), text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1612,8 +1612,8 @@ INTERNAL void user_update(void)
|
|||||||
struct v2_array m = menkowski(temp.arena, &e0_collider, &e1_collider, e0_xf, e1_xf, detail);
|
struct v2_array m = menkowski(temp.arena, &e0_collider, &e1_collider, e0_xf, e1_xf, detail);
|
||||||
|
|
||||||
for (u64 i = 0; i < m.count; ++i) m.points[i] = xform_mul_v2(G.world_to_user_xf, m.points[i]);
|
for (u64 i = 0; i < m.count; ++i) m.points[i] = xform_mul_v2(G.world_to_user_xf, m.points[i]);
|
||||||
draw_poly_line(G.ui_gpu_plan, m, true, thickness, color);
|
draw_poly_line(G.ui_gp_plan, m, true, thickness, color);
|
||||||
//draw_poly(G.ui_gpu_plan, m, color);
|
//draw_poly(G.ui_gp_plan, m, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw cloud */
|
/* Draw cloud */
|
||||||
@ -1625,7 +1625,7 @@ INTERNAL void user_update(void)
|
|||||||
|
|
||||||
for (u64 i = 0; i < m.count; ++i) {
|
for (u64 i = 0; i < m.count; ++i) {
|
||||||
struct v2 p = xform_mul_v2(G.world_to_user_xf, m.points[i]);
|
struct v2 p = xform_mul_v2(G.world_to_user_xf, m.points[i]);
|
||||||
draw_circle(G.ui_gpu_plan, p, radius, color, 10);
|
draw_circle(G.ui_gp_plan, p, radius, color, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1639,8 +1639,8 @@ INTERNAL void user_update(void)
|
|||||||
.count = collider_res.prototype.len
|
.count = collider_res.prototype.len
|
||||||
};
|
};
|
||||||
for (u64 i = 0; i < m.count; ++i) m.points[i] = xform_mul_v2(G.world_to_user_xf, m.points[i]);
|
for (u64 i = 0; i < m.count; ++i) m.points[i] = xform_mul_v2(G.world_to_user_xf, m.points[i]);
|
||||||
draw_poly_line(G.ui_gpu_plan, m, true, thickness, color);
|
draw_poly_line(G.ui_gp_plan, m, true, thickness, color);
|
||||||
for (u64 i = 0; i < m.count; ++i) draw_circle(G.ui_gpu_plan, m.points[i], 10, color, 10);
|
for (u64 i = 0; i < m.count; ++i) draw_circle(G.ui_gp_plan, m.points[i], 10, color, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw simplex */
|
/* Draw simplex */
|
||||||
@ -1658,18 +1658,18 @@ INTERNAL void user_update(void)
|
|||||||
|
|
||||||
if (simplex.len >= 1) {
|
if (simplex.len >= 1) {
|
||||||
u32 color = simplex.len == 1 ? color_first : (simplex.len == 2 ? color_second : color_third);
|
u32 color = simplex.len == 1 ? color_first : (simplex.len == 2 ? color_second : color_third);
|
||||||
draw_circle(G.ui_gpu_plan, simplex_array.points[0], thickness * 3, color, 10);
|
draw_circle(G.ui_gp_plan, simplex_array.points[0], thickness * 3, color, 10);
|
||||||
}
|
}
|
||||||
if (simplex.len >= 2) {
|
if (simplex.len >= 2) {
|
||||||
u32 color = simplex.len == 2 ? color_first : color_second;
|
u32 color = simplex.len == 2 ? color_first : color_second;
|
||||||
draw_circle(G.ui_gpu_plan, simplex_array.points[1], thickness * 3, color, 10);
|
draw_circle(G.ui_gp_plan, simplex_array.points[1], thickness * 3, color, 10);
|
||||||
}
|
}
|
||||||
if (simplex.len >= 3) {
|
if (simplex.len >= 3) {
|
||||||
u32 color = color_first;
|
u32 color = color_first;
|
||||||
draw_circle(G.ui_gpu_plan, simplex_array.points[2], thickness * 3, color, 10);
|
draw_circle(G.ui_gp_plan, simplex_array.points[2], thickness * 3, color, 10);
|
||||||
}
|
}
|
||||||
if (simplex.len >= 2) {
|
if (simplex.len >= 2) {
|
||||||
draw_poly_line(G.ui_gpu_plan, simplex_array, simplex.len > 2, thickness, line_color);
|
draw_poly_line(G.ui_gp_plan, simplex_array, simplex.len > 2, thickness, line_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1681,7 +1681,7 @@ INTERNAL void user_update(void)
|
|||||||
f32 arrowhead_height = 10;
|
f32 arrowhead_height = 10;
|
||||||
struct v2 start = xform_mul_v2(G.world_to_user_xf, V2(0, 0));
|
struct v2 start = xform_mul_v2(G.world_to_user_xf, V2(0, 0));
|
||||||
struct v2 end = xform_mul_v2(G.world_to_user_xf, v2_mul(v2_norm(collider_res.normal), len));
|
struct v2 end = xform_mul_v2(G.world_to_user_xf, v2_mul(v2_norm(collider_res.normal), len));
|
||||||
draw_arrow_line(G.ui_gpu_plan, start, end, arrow_thickness, arrowhead_height, color);
|
draw_arrow_line(G.ui_gp_plan, start, end, arrow_thickness, arrowhead_height, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1696,7 +1696,7 @@ INTERNAL void user_update(void)
|
|||||||
|
|
||||||
struct v2 start = xform_mul_v2(G.world_to_user_xf, xf.og);
|
struct v2 start = xform_mul_v2(G.world_to_user_xf, xf.og);
|
||||||
struct v2 end = xform_mul_v2(G.world_to_user_xf, parent_xf.og);
|
struct v2 end = xform_mul_v2(G.world_to_user_xf, parent_xf.og);
|
||||||
draw_arrow_line(G.ui_gpu_plan, start, end, thickness, arrow_height, color);
|
draw_arrow_line(G.ui_gp_plan, start, end, thickness, arrow_height, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw camera rect */
|
/* Draw camera rect */
|
||||||
@ -1708,7 +1708,7 @@ INTERNAL void user_update(void)
|
|||||||
struct quad quad = xform_mul_quad(quad_xf, QUAD_UNIT_SQUARE_CENTERED);
|
struct quad quad = xform_mul_quad(quad_xf, QUAD_UNIT_SQUARE_CENTERED);
|
||||||
quad = xform_mul_quad(G.world_to_user_xf, quad);
|
quad = xform_mul_quad(G.world_to_user_xf, quad);
|
||||||
|
|
||||||
draw_quad_line(G.ui_gpu_plan, quad, thickness, color);
|
draw_quad_line(G.ui_gp_plan, quad, thickness, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
arena_temp_end(temp);
|
arena_temp_end(temp);
|
||||||
@ -1726,7 +1726,7 @@ INTERNAL void user_update(void)
|
|||||||
|
|
||||||
struct v2 size = V2(t->width, t->height);
|
struct v2 size = V2(t->width, t->height);
|
||||||
struct xform xf = XFORM_TRS(.t = crosshair_pos, .s = size);
|
struct xform xf = XFORM_TRS(.t = crosshair_pos, .s = size);
|
||||||
draw_texture(G.ui_gpu_plan, DRAW_TEXTURE_PARAMS(.xf = xf, .sprite = crosshair_tag));
|
draw_texture(G.ui_gp_plan, DRAW_TEXTURE_PARAMS(.xf = xf, .sprite = crosshair_tag));
|
||||||
|
|
||||||
struct rect cursor_clip = RECT_FROM_V2(G.user_screen_offset, G.user_size);
|
struct rect cursor_clip = RECT_FROM_V2(G.user_screen_offset, G.user_size);
|
||||||
cursor_clip.pos = v2_add(cursor_clip.pos, v2_mul(size, 0.5f));
|
cursor_clip.pos = v2_add(cursor_clip.pos, v2_mul(size, 0.5f));
|
||||||
@ -1924,7 +1924,7 @@ INTERNAL void user_update(void)
|
|||||||
struct string dbg_text = ZI;
|
struct string dbg_text = ZI;
|
||||||
dbg_text.text = arena_push_dry(temp.arena, u8);
|
dbg_text.text = arena_push_dry(temp.arena, u8);
|
||||||
dbg_text.len += get_ent_debug_text(temp.arena, ent).len;
|
dbg_text.len += get_ent_debug_text(temp.arena, ent).len;
|
||||||
draw_text(G.ui_gpu_plan, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = dbg_text));
|
draw_text(G.ui_gp_plan, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = dbg_text));
|
||||||
|
|
||||||
arena_temp_end(temp);
|
arena_temp_end(temp);
|
||||||
}
|
}
|
||||||
@ -2024,16 +2024,16 @@ INTERNAL void user_update(void)
|
|||||||
//text.len += string_copy(temp.arena, LIT("\n")).len;
|
//text.len += string_copy(temp.arena, LIT("\n")).len;
|
||||||
|
|
||||||
#if COLLIDER_DEBUG
|
#if COLLIDER_DEBUG
|
||||||
draw_text(G.ui_gpu_plan, font, pos, string_format(temp.arena, LIT("collider gjk steps: %F"), FMT_UINT(collider_debug_steps)));
|
draw_text(G.ui_gp_plan, font, pos, string_format(temp.arena, LIT("collider gjk steps: %F"), FMT_UINT(collider_debug_steps)));
|
||||||
pos.y += spacing;
|
pos.y += spacing;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//draw_text(G.ui_gpu_plan, font, pos, string_format(temp.arena, LIT("blended world entities: %F/%F"), FMT_UINT(G.ss_blended->num_ents_allocated), FMT_UINT(G.ss_blended->num_ents_reserved)));
|
//draw_text(G.ui_gp_plan, font, pos, string_format(temp.arena, LIT("blended world entities: %F/%F"), FMT_UINT(G.ss_blended->num_ents_allocated), FMT_UINT(G.ss_blended->num_ents_reserved)));
|
||||||
//draw_text(G.ui_gpu_plan, font, pos, text);
|
//draw_text(G.ui_gp_plan, font, pos, text);
|
||||||
|
|
||||||
struct v2 pos = V2(10, G.user_size.y);
|
struct v2 pos = V2(10, G.user_size.y);
|
||||||
enum draw_text_offset_y offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM;
|
enum draw_text_offset_y offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM;
|
||||||
draw_text(G.ui_gpu_plan, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = COLOR_WHITE));
|
draw_text(G.ui_gp_plan, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = COLOR_WHITE));
|
||||||
arena_temp_end(temp);
|
arena_temp_end(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2062,38 +2062,38 @@ INTERNAL void user_update(void)
|
|||||||
struct v2i32 backbuffer_resolution = v2_round_to_int(G.screen_size);
|
struct v2i32 backbuffer_resolution = v2_round_to_int(G.screen_size);
|
||||||
|
|
||||||
/* Allocate user texture */
|
/* Allocate user texture */
|
||||||
if (!G.user_texture.v || !v2i32_eq(gpu_texture_get_size(G.user_texture), user_resolution)) {
|
if (!G.user_texture.v || !v2i32_eq(gp_texture_get_size(G.user_texture), user_resolution)) {
|
||||||
if (G.user_texture.v) {
|
if (G.user_texture.v) {
|
||||||
gpu_release(G.user_texture);
|
gp_release(G.user_texture);
|
||||||
}
|
}
|
||||||
G.user_texture = gpu_texture_alloc(GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM, GPU_TEXTURE_FLAG_TARGETABLE, user_resolution, NULL);
|
G.user_texture = gp_texture_alloc(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, GP_TEXTURE_FLAG_TARGETABLE, user_resolution, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear textures */
|
/* Clear textures */
|
||||||
gpu_texture_clear(G.user_texture, 0);
|
gp_texture_clear(G.user_texture, 0);
|
||||||
|
|
||||||
/* Render world to user texture */
|
/* Render world to user texture */
|
||||||
{
|
{
|
||||||
struct gpu_dispatch_params params = ZI;
|
struct gp_dispatch_params params = ZI;
|
||||||
params.plan = G.world_gpu_plan;
|
params.plan = G.world_gp_plan;
|
||||||
params.draw_target = G.user_texture;
|
params.draw_target = G.user_texture;
|
||||||
params.draw_target_viewport = user_viewport;
|
params.draw_target_viewport = user_viewport;
|
||||||
params.draw_target_view = G.world_to_user_xf;
|
params.draw_target_view = G.world_to_user_xf;
|
||||||
gpu_dispatch(params);
|
gp_dispatch(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Render ui to user texture */
|
/* Render ui to user texture */
|
||||||
{
|
{
|
||||||
struct gpu_dispatch_params params = ZI;
|
struct gp_dispatch_params params = ZI;
|
||||||
params.plan = G.ui_gpu_plan;
|
params.plan = G.ui_gp_plan;
|
||||||
params.draw_target = G.user_texture;
|
params.draw_target = G.user_texture;
|
||||||
params.draw_target_viewport = user_viewport;
|
params.draw_target_viewport = user_viewport;
|
||||||
params.draw_target_view = XFORM_IDENT;
|
params.draw_target_view = XFORM_IDENT;
|
||||||
gpu_dispatch(params);
|
gp_dispatch(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Present user texture */
|
/* Present user texture */
|
||||||
gpu_present(backbuffer_resolution, G.user_texture, XFORM_TRS(.t = v2_mul(G.screen_size, 0.5), .s = G.user_size), VSYNC_ENABLED);
|
gp_present(backbuffer_resolution, G.user_texture, XFORM_TRS(.t = v2_mul(G.screen_size, 0.5), .s = G.user_size), VSYNC_ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
struct sys_window;
|
struct sys_window;
|
||||||
struct work_startup_receipt;
|
struct work_startup_receipt;
|
||||||
struct gpu_startup_receipt;
|
struct gp_startup_receipt;
|
||||||
struct font_startup_receipt;
|
struct font_startup_receipt;
|
||||||
struct sprite_startup_receipt;
|
struct sprite_startup_receipt;
|
||||||
struct draw_startup_receipt;
|
struct draw_startup_receipt;
|
||||||
@ -62,7 +62,7 @@ enum user_bind_kind {
|
|||||||
|
|
||||||
struct user_startup_receipt { i32 _; };
|
struct user_startup_receipt { i32 _; };
|
||||||
struct user_startup_receipt user_startup(struct work_startup_receipt *work_sr,
|
struct user_startup_receipt user_startup(struct work_startup_receipt *work_sr,
|
||||||
struct gpu_startup_receipt *gpu_sr,
|
struct gp_startup_receipt *gp_sr,
|
||||||
struct font_startup_receipt *font_sr,
|
struct font_startup_receipt *font_sr,
|
||||||
struct sprite_startup_receipt *sprite_sr,
|
struct sprite_startup_receipt *sprite_sr,
|
||||||
struct draw_startup_receipt *draw_sr,
|
struct draw_startup_receipt *draw_sr,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user