decouple gp from sprite layer
This commit is contained in:
parent
d544a55f0e
commit
4821bd1e85
@ -1,6 +1,26 @@
|
||||
#ifndef BASE_H
|
||||
#define BASE_H
|
||||
|
||||
/* Intrinsic header info:
|
||||
* <mmintrin.h" MMX
|
||||
* <xmmintrin.h" SSE
|
||||
* <emmintrin.h" SSE2
|
||||
* <pmmintrin.h" SSE3
|
||||
* <tmmintrin.h" SSSE3
|
||||
* <smmintrin.h" SSE4.1
|
||||
* <nmmintrin.h" SSE4.2
|
||||
* <ammintrin.h" SSE4A
|
||||
* <wmmintrin.h" AES
|
||||
* <immintrin.h" AVX, AVX2, FMA
|
||||
*/
|
||||
#include "stddef.h"
|
||||
#include "stdint.h"
|
||||
#include "stdarg.h"
|
||||
#include "intrin.h"
|
||||
#include "nmmintrin.h" /* SSE4.2 */
|
||||
|
||||
#include "../config.h"
|
||||
|
||||
#include "../prof/prof.h"
|
||||
|
||||
#include "base_core.h"
|
||||
|
||||
@ -8,29 +8,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ========================== *
|
||||
* Compiler headers
|
||||
* ========================== */
|
||||
|
||||
/* Intrinsic header info:
|
||||
* <mmintrin.h" MMX
|
||||
* <xmmintrin.h" SSE
|
||||
* <emmintrin.h" SSE2
|
||||
* <pmmintrin.h" SSE3
|
||||
* <tmmintrin.h" SSSE3
|
||||
* <smmintrin.h" SSE4.1
|
||||
* <nmmintrin.h" SSE4.2
|
||||
* <ammintrin.h" SSE4A
|
||||
* <wmmintrin.h" AES
|
||||
* <immintrin.h" AVX, AVX2, FMA
|
||||
*/
|
||||
|
||||
#include "stddef.h"
|
||||
#include "stdint.h"
|
||||
#include "stdarg.h"
|
||||
#include "intrin.h"
|
||||
#include "nmmintrin.h" /* SSE4.2 */
|
||||
|
||||
/* ========================== *
|
||||
* Flag defaults
|
||||
* ========================== */
|
||||
@ -674,12 +651,6 @@ INLINE i64 clamp_i64(i64 v, i64 min, i64 max) { return v < min ? min : v > max ?
|
||||
INLINE f32 clamp_f32(f32 v, f32 min, f32 max) { return v < min ? min : v > max ? max : v; }
|
||||
INLINE f64 clamp_f64(f64 v, f64 min, f64 max) { return v < min ? min : v > max ? max : v; }
|
||||
|
||||
/* ========================== *
|
||||
* Configurable constants
|
||||
* ========================== */
|
||||
|
||||
#include "../config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -24,7 +24,6 @@ void draw_material(struct gp_render_sig *sig, struct draw_material_params params
|
||||
struct gp_render_cmd_desc cmd = ZI;
|
||||
cmd.kind = GP_RENDER_CMD_KIND_DRAW_MATERIAL;
|
||||
cmd.material.xf = params.xf;
|
||||
cmd.material.sprite = params.sprite;
|
||||
cmd.material.texture = params.texture;
|
||||
cmd.material.clip = params.clip;
|
||||
cmd.material.tint = params.tint;
|
||||
@ -284,7 +283,6 @@ void draw_ui_rect(struct gp_render_sig *sig, struct draw_ui_rect_params params)
|
||||
struct gp_render_cmd_desc cmd = ZI;
|
||||
cmd.kind = GP_RENDER_CMD_KIND_DRAW_UI_RECT;
|
||||
cmd.ui_rect.xf = params.xf;
|
||||
cmd.ui_rect.sprite = params.sprite;
|
||||
cmd.ui_rect.texture = params.texture;
|
||||
cmd.ui_rect.clip = params.clip;
|
||||
cmd.ui_rect.tint = params.tint;
|
||||
|
||||
@ -16,8 +16,7 @@ struct draw_startup_receipt draw_startup(struct font_startup_receipt *font_sr);
|
||||
|
||||
struct draw_material_params {
|
||||
struct xform xf;
|
||||
struct gp_resource *texture; /* Overrides sprite if set */
|
||||
struct sprite_tag sprite;
|
||||
struct gp_resource *texture;
|
||||
struct clip_rect clip;
|
||||
u32 tint;
|
||||
b32 is_light;
|
||||
@ -78,8 +77,7 @@ void draw_grid(struct gp_render_sig *sig, struct xform xf, u32 bg0_color, u32 bg
|
||||
|
||||
struct draw_ui_rect_params {
|
||||
struct xform xf;
|
||||
struct gp_resource *texture; /* Overrides sprite if set */
|
||||
struct sprite_tag sprite;
|
||||
struct gp_resource *texture;
|
||||
struct clip_rect clip;
|
||||
u32 tint;
|
||||
};
|
||||
|
||||
@ -1,10 +1,5 @@
|
||||
#if !RESOURCE_RELOADING
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "dxc.h"
|
||||
}
|
||||
|
||||
struct dxc_compile_result dxc_compile(struct arena *arena, struct string shader_source, i32 num_args, struct string *args)
|
||||
{
|
||||
(UNUSED)arena;
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
#include "gp.h"
|
||||
|
||||
#include "../kernel/kernel.h"
|
||||
|
||||
#if PLATFORM_WINDOWS
|
||||
# include "gp_core_dx12.c"
|
||||
#else
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
#include "../inc/inc.h"
|
||||
#include "../resource/resource.h"
|
||||
#include "../watch/watch.h"
|
||||
#include "../kernel/kernel.h"
|
||||
|
||||
#include "gp_core.h"
|
||||
|
||||
|
||||
@ -67,7 +67,6 @@ struct gp_render_cmd_desc {
|
||||
union {
|
||||
struct {
|
||||
struct xform xf;
|
||||
struct sprite_tag sprite;
|
||||
struct gp_resource *texture;
|
||||
struct clip_rect clip;
|
||||
u32 tint;
|
||||
@ -77,7 +76,6 @@ struct gp_render_cmd_desc {
|
||||
} material;
|
||||
struct {
|
||||
struct xform xf;
|
||||
struct sprite_tag sprite;
|
||||
struct gp_resource *texture;
|
||||
struct clip_rect clip;
|
||||
u32 tint;
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
/* TODO: Remove this */
|
||||
#include "../sprite/sprite.h"
|
||||
|
||||
#pragma warning(push, 0)
|
||||
# define UNICODE
|
||||
# define COBJMACROS
|
||||
@ -2547,8 +2544,7 @@ struct render_sig {
|
||||
|
||||
struct material_instance_desc {
|
||||
struct xform xf;
|
||||
struct sprite_tag sprite;
|
||||
struct dx12_resource *texture;
|
||||
u32 texture_id;
|
||||
struct clip_rect clip;
|
||||
u32 tint;
|
||||
b32 is_light;
|
||||
@ -2558,8 +2554,7 @@ struct material_instance_desc {
|
||||
|
||||
struct ui_rect_instance_desc {
|
||||
struct xform xf;
|
||||
struct sprite_tag sprite;
|
||||
struct dx12_resource *texture;
|
||||
u32 texture_id;
|
||||
struct clip_rect clip;
|
||||
u32 tint;
|
||||
};
|
||||
@ -2632,10 +2627,10 @@ u32 gp_push_render_cmd(struct gp_render_sig *render_sig, struct gp_render_cmd_de
|
||||
|
||||
case GP_RENDER_CMD_KIND_DRAW_MATERIAL:
|
||||
{
|
||||
struct dx12_resource *texture = (struct dx12_resource *)cmd_desc->material.texture;
|
||||
struct material_instance_desc *instance_desc = arena_push(sig->material_instance_descs_arena, struct material_instance_desc);
|
||||
instance_desc->xf = cmd_desc->material.xf;
|
||||
instance_desc->sprite = cmd_desc->material.sprite;
|
||||
instance_desc->texture = (struct dx12_resource *)cmd_desc->material.texture;
|
||||
instance_desc->texture_id = texture ? texture->srv_descriptor->index : 0xFFFFFFFF;
|
||||
instance_desc->clip = cmd_desc->material.clip;
|
||||
instance_desc->tint = cmd_desc->material.tint;
|
||||
instance_desc->is_light = cmd_desc->material.is_light;
|
||||
@ -2646,10 +2641,10 @@ u32 gp_push_render_cmd(struct gp_render_sig *render_sig, struct gp_render_cmd_de
|
||||
|
||||
case GP_RENDER_CMD_KIND_DRAW_UI_RECT:
|
||||
{
|
||||
struct dx12_resource *texture = (struct dx12_resource *)cmd_desc->ui_rect.texture;
|
||||
struct ui_rect_instance_desc *instance_desc = arena_push(sig->ui_rect_instance_descs_arena, struct ui_rect_instance_desc);
|
||||
instance_desc->xf = cmd_desc->ui_rect.xf;
|
||||
instance_desc->sprite = cmd_desc->ui_rect.sprite;
|
||||
instance_desc->texture = (struct dx12_resource *)cmd_desc->ui_rect.texture;
|
||||
instance_desc->texture_id = texture ? texture->srv_descriptor->index : 0xFFFFFFFF;
|
||||
instance_desc->clip = cmd_desc->ui_rect.clip;
|
||||
instance_desc->tint = cmd_desc->ui_rect.tint;
|
||||
ret = ++sig->num_ui_rect_instance_descs;
|
||||
@ -2739,7 +2734,6 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
||||
rsig->ui_target = gbuff_alloc(DXGI_FORMAT_R8G8B8A8_UNORM, ui_size, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
}
|
||||
|
||||
struct sprite_scope *sprite_scope = sprite_scope_begin();
|
||||
struct pipeline_scope *pipeline_scope = pipeline_scope_begin();
|
||||
struct pipeline *material_pipeline = pipeline_from_name(pipeline_scope, LIT("kernel_material"));
|
||||
struct pipeline *flood_pipeline = pipeline_from_name(pipeline_scope, LIT("kernel_flood"));
|
||||
@ -2782,17 +2776,7 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
||||
for (u32 i = 0; i < rsig->num_material_instance_descs; ++i) {
|
||||
struct material_instance_desc *desc = &((struct material_instance_desc *)arena_base(rsig->material_instance_descs_arena))[i];
|
||||
struct k_material_instance *instance = &material_instances[i];
|
||||
u32 texture_id = 0xFFFFFFFF;
|
||||
if (desc->texture != 0) {
|
||||
texture_id = desc->texture->srv_descriptor->index;
|
||||
} else if (desc->sprite.hash != 0) {
|
||||
struct sprite_texture *st = sprite_texture_from_tag_async(sprite_scope, desc->sprite);
|
||||
struct dx12_resource *texture = (struct dx12_resource *)st->gp_texture;
|
||||
if (texture) {
|
||||
texture_id = texture->srv_descriptor->index;
|
||||
}
|
||||
}
|
||||
instance->tex_nurid = k_uint_from_u32(texture_id);
|
||||
instance->tex_nurid = k_uint_from_u32(desc->texture_id);
|
||||
instance->grid_id = k_uint_from_u32(desc->grid_id);
|
||||
instance->xf = k_float2x3_from_xform(desc->xf);
|
||||
instance->uv0 = k_float2_from_v2(desc->clip.p0);
|
||||
@ -2809,17 +2793,7 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
||||
for (u32 i = 0; i < rsig->num_ui_rect_instance_descs; ++i) {
|
||||
struct ui_rect_instance_desc *desc = &((struct ui_rect_instance_desc *)arena_base(rsig->ui_rect_instance_descs_arena))[i];
|
||||
struct k_ui_instance *instance = &ui_rect_instances[i];
|
||||
u32 texture_id = 0xFFFFFFFF;
|
||||
if (desc->texture != 0) {
|
||||
texture_id = desc->texture->srv_descriptor->index;
|
||||
} else if (desc->sprite.hash != 0) {
|
||||
struct sprite_texture *st = sprite_texture_from_tag_async(sprite_scope, desc->sprite);
|
||||
struct dx12_resource *texture = (struct dx12_resource *)st->gp_texture;
|
||||
if (texture) {
|
||||
texture_id = texture->srv_descriptor->index;
|
||||
}
|
||||
}
|
||||
instance->tex_nurid = k_uint_from_u32(texture_id);
|
||||
instance->tex_nurid = k_uint_from_u32(desc->texture_id);
|
||||
instance->xf = k_float2x3_from_xform(desc->xf);
|
||||
instance->uv0 = k_float2_from_v2(desc->clip.p0);
|
||||
instance->uv1 = k_float2_from_v2(desc->clip.p1);
|
||||
@ -3166,7 +3140,6 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
||||
}
|
||||
command_list_close(cl);
|
||||
pipeline_scope_end(pipeline_scope);
|
||||
sprite_scope_end(sprite_scope);
|
||||
|
||||
render_sig_reset(rsig);
|
||||
scratch_end(scratch);
|
||||
|
||||
@ -1224,15 +1224,15 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
/* Draw sprite */
|
||||
if (!sprite_tag_is_nil(sprite)) {
|
||||
struct sprite_sheet *sheet = sprite_sheet_from_tag_async(sprite_frame_scope, sprite);
|
||||
sprite_texture_from_tag_prefetch(sprite_frame_scope, sprite);
|
||||
struct sprite_texture *texture = sprite_texture_from_tag_async(sprite_frame_scope, sprite);
|
||||
|
||||
/* TODO: Fade in placeholder if texture isn't loaded */
|
||||
if (sheet->loaded) {
|
||||
if (sheet->loaded && texture->loaded) {
|
||||
b32 is_light = sim_ent_has_prop(ent, SEPROP_LIGHT_TEST);
|
||||
struct v3 emittance = ent->sprite_emittance;
|
||||
u32 tint = ent->sprite_tint;
|
||||
struct sprite_sheet_frame frame = sprite_sheet_get_frame(sheet, ent->animation_frame);
|
||||
struct draw_material_params params = DRAW_MATERIAL_PARAMS(.xf = sprite_xform, .sprite = sprite, .tint = tint, .clip = frame.clip, .is_light = is_light, .light_emittance = emittance);
|
||||
struct draw_material_params params = DRAW_MATERIAL_PARAMS(.xf = sprite_xform, .texture = texture->gp_texture, .tint = tint, .clip = frame.clip, .is_light = is_light, .light_emittance = emittance);
|
||||
draw_material(G.render_sig, params);
|
||||
}
|
||||
}
|
||||
@ -1242,18 +1242,21 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
if (sim_ent_has_prop(ent, SEPROP_TILE_CHUNK)) {
|
||||
struct v2i32 chunk_index = ent->tile_chunk_index;
|
||||
struct sprite_tag tile_sprite = sprite_tag_from_path(LIT("sprite/tile.ase"));
|
||||
f32 tile_size = 1.f / SIM_TILES_PER_UNIT_SQRT;
|
||||
for (i32 tile_y = 0; tile_y < SIM_TILES_PER_CHUNK_SQRT; ++tile_y) {
|
||||
for (i32 tile_x = 0; tile_x < SIM_TILES_PER_CHUNK_SQRT; ++tile_x) {
|
||||
struct v2i32 local_tile_index = V2I32(tile_x, tile_y);
|
||||
enum sim_tile_kind tile = ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)];
|
||||
//if (tile > -1) {
|
||||
if (tile == SIM_TILE_KIND_WALL) {
|
||||
struct v2i32 world_tile_index = sim_world_tile_index_from_local_tile_index(chunk_index, local_tile_index);
|
||||
struct v2 pos = sim_pos_from_world_tile_index(world_tile_index);
|
||||
struct xform tile_xf = xform_from_rect(RECT_FROM_V2(pos, V2(tile_size, tile_size)));
|
||||
struct draw_material_params params = DRAW_MATERIAL_PARAMS(.xf = tile_xf, .sprite = tile_sprite, .is_light = 1, .light_emittance = V3(0, 0, 0));
|
||||
draw_material(G.render_sig, params);
|
||||
struct sprite_texture *tile_texture = sprite_texture_from_tag_async(sprite_frame_scope, tile_sprite);
|
||||
if (tile_texture->loaded) {
|
||||
f32 tile_size = 1.f / SIM_TILES_PER_UNIT_SQRT;
|
||||
for (i32 tile_y = 0; tile_y < SIM_TILES_PER_CHUNK_SQRT; ++tile_y) {
|
||||
for (i32 tile_x = 0; tile_x < SIM_TILES_PER_CHUNK_SQRT; ++tile_x) {
|
||||
struct v2i32 local_tile_index = V2I32(tile_x, tile_y);
|
||||
enum sim_tile_kind tile = ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)];
|
||||
//if (tile > -1) {
|
||||
if (tile == SIM_TILE_KIND_WALL) {
|
||||
struct v2i32 world_tile_index = sim_world_tile_index_from_local_tile_index(chunk_index, local_tile_index);
|
||||
struct v2 pos = sim_pos_from_world_tile_index(world_tile_index);
|
||||
struct xform tile_xf = xform_from_rect(RECT_FROM_V2(pos, V2(tile_size, tile_size)));
|
||||
struct draw_material_params params = DRAW_MATERIAL_PARAMS(.xf = tile_xf, .texture = tile_texture->gp_texture, .is_light = 1, .light_emittance = V3(0, 0, 0));
|
||||
draw_material(G.render_sig, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1694,7 +1697,7 @@ INTERNAL void user_update(struct sys_window *window)
|
||||
struct sprite_texture *t = sprite_texture_from_tag_async(sprite_frame_scope, crosshair);
|
||||
struct v2 size = V2(t->width, t->height);
|
||||
struct xform xf = XFORM_TRS(.t = crosshair_pos, .s = size);
|
||||
draw_ui_rect(G.render_sig, DRAW_UI_RECT_PARAMS(.xf = xf, .sprite = crosshair));
|
||||
draw_ui_rect(G.render_sig, DRAW_UI_RECT_PARAMS(.xf = xf, .texture = t->gp_texture));
|
||||
}
|
||||
|
||||
/* FIXME: Enable this */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user