From d26100734623f37063206b9b144c2a29fd71d414 Mon Sep 17 00:00:00 2001 From: quou Date: Wed, 1 Jan 2025 18:43:31 +1100 Subject: material system --- c2.cpp | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'c2.cpp') diff --git a/c2.cpp b/c2.cpp index fd02e50..73bbbb6 100644 --- a/c2.cpp +++ b/c2.cpp @@ -58,6 +58,30 @@ static Buffer_Id upload_verts(Device* dev) { return vbo; } +Texture_Id make_default_texture(Device* dev) { + unsigned* mem; + Texture_Id tex; + Buffer_Id buf = dev->create_buffer( + "default texture stage", + 4, + Buffer_Flags::copy_src | + Buffer_Flags::cpu_readwrite + ); + mem = (unsigned*)dev->map_buffer(buf, 0, 4); + mem[0] = 0xffffffff; + dev->unmap_buffer(buf); + tex = dev->create_texture( + "default PBR texture", + texture_format_rgba8i, + Texture_Flags::sampleable | Texture_Flags::copy_dst, + 1, + 1, + buf + ); + dev->destroy_bufferi(buf); + return tex; +} + static Sampler_Id create_clamped_linear(Device* dev) { Sampler_State s{}; s.min = Filter_Mode::linear; @@ -79,11 +103,13 @@ struct Config_Buffer2 { extern "C" int entrypoint() { Arena video_arena, asset_arena, ui_arena; Model_Loader model_loader; + Material_Loader mat_loader; Asset_Arena assets; Device* dev; Shader* shader, * ui_shader; Texture* texture; Texture* texture2; + Texture_Id default_texture; Model* monkey; Buffer_Id vbo, cbuf; Sampler_Id clamped_linear; @@ -109,8 +135,11 @@ extern "C" int entrypoint() { ); assets.init(&asset_arena, "pack", 128); dev = Device::create(&video_arena, app); + default_texture = make_default_texture(dev); model_loader.init(dev, &assets); + mat_loader.init(&assets, default_texture); register_asset_loader("MODL", &model_loader); + register_asset_loader("MTRL", &mat_loader); monkey = (Model*)assets.load("monkey.mdl"); app->dev = dev; shader = (Shader*)assets.load("triangle.csh"); @@ -234,14 +263,16 @@ extern "C" int entrypoint() { monkey->render( dev, &frame_arena, - depth_prepass + depth_prepass, + clamped_linear ); ctx.debug_pop(); ctx.debug_push("forward"); monkey->render( dev, &frame_arena, - pass2 + pass2, + clamped_linear ); ctx.debug_pop(); @@ -257,6 +288,7 @@ extern "C" int entrypoint() { } ui->destroy(); assets.destroy(); + dev->destroy_texture(default_texture); dev->destroy_sampler(clamped_linear); dev->destroy_buffer(vbo); dev->destroy_buffer(cbuf); -- cgit v1.2.3-54-g00ecf