diff options
author | quou <quou@disroot.org> | 2024-12-22 22:19:36 +1100 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-12-22 22:19:36 +1100 |
commit | 58245585cbe77e6c03ebe13f29e10393ff3c45b4 (patch) | |
tree | 6c3dcd8e9adcbc699318d4062bb2cf594116702e /c2.cpp | |
parent | 82767020e84ec8c1af2e3817fc7efede5497c82d (diff) |
cute asset loading system
Diffstat (limited to 'c2.cpp')
-rw-r--r-- | c2.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -7,6 +7,7 @@ extern "C" { #include <string.h> #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>("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(); } |