From 58245585cbe77e6c03ebe13f29e10393ff3c45b4 Mon Sep 17 00:00:00 2001 From: quou Date: Sun, 22 Dec 2024 22:19:36 +1100 Subject: cute asset loading system --- c2.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'c2.cpp') diff --git a/c2.cpp b/c2.cpp index 92cff0b..9510c6a 100644 --- a/c2.cpp +++ b/c2.cpp @@ -7,6 +7,7 @@ extern "C" { #include #define video_arena_size (1024 * 1024 * 16) +#define asset_arena_size (1024 * 1024 * 4) #define per_frame_memory_size (1024 * 1024) static float verts[] = { @@ -24,8 +25,10 @@ struct C2 : public App { int main() { Arena video_arena; + Arena asset_arena; + Asset_Arena assets; Device* dev; - Shader_Id shader; + Shader* shader; Buffer_Id vbo; C2* app = App::create("c2"); void* per_frame; @@ -35,9 +38,15 @@ int main() { arena_alloc(app->arena, video_arena_size), video_arena_size ); + init_arena( + &asset_arena, + arena_alloc(app->arena, asset_arena_size), + asset_arena_size + ); + assets.init(&asset_arena, "pack"); dev = Device::create(&video_arena, app); app->dev = dev; - shader = dev->load_shader("data/triangle.csh"); + shader = (Shader*)assets.load("triangle.csh"); per_frame = heap_alloc( dev->heap, per_frame_memory_size @@ -68,14 +77,14 @@ int main() { Render_Pass& pass = pb.build_rp(); pb.begin(); - pb.shader(shader); - pb.vertex_format(dev->get_shader(shader).vf); + pb.shader(shader->id); + pb.vertex_format(shader->vf); Pipeline& pip = pb.build(); Vertex_Buffer_Binding binding[] = {{ .id = vbo, .offset = 0, - .target = dev->get_shader(shader).binding_index("verts") + .target = shader->binding_index("verts") }, {}}; Draw draw{}; @@ -90,8 +99,8 @@ int main() { dev->present(); app->end(); } + assets.destroy(); dev->destroy_buffer(vbo); - dev->destroy_shader(shader); dev->destroy(); app->destroy(); } -- cgit v1.2.3-54-g00ecf