summaryrefslogtreecommitdiff
path: root/c2.cpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-12-22 22:19:36 +1100
committerquou <quou@disroot.org>2024-12-22 22:19:36 +1100
commit58245585cbe77e6c03ebe13f29e10393ff3c45b4 (patch)
tree6c3dcd8e9adcbc699318d4062bb2cf594116702e /c2.cpp
parent82767020e84ec8c1af2e3817fc7efede5497c82d (diff)
cute asset loading system
Diffstat (limited to 'c2.cpp')
-rw-r--r--c2.cpp21
1 files changed, 15 insertions, 6 deletions
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 <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();
}