summaryrefslogtreecommitdiff
path: root/c2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c2.cpp')
-rw-r--r--c2.cpp42
1 files changed, 30 insertions, 12 deletions
diff --git a/c2.cpp b/c2.cpp
index 9510c6a..af912e5 100644
--- a/c2.cpp
+++ b/c2.cpp
@@ -23,12 +23,39 @@ struct C2 : public App {
}
};
+static Buffer_Id upload_verts(Device* dev) {
+ Buffer_Id stage = dev->create_buffer(
+ sizeof verts,
+ Buffer_Flags::copy_src |
+ Buffer_Flags::cpu_readwrite
+ );
+ Buffer_Id vbo = dev->create_buffer(
+ sizeof verts,
+ Buffer_Flags::vertex_buffer |
+ Buffer_Flags::copy_dst
+ );
+ {
+ void* mem;
+ mem = dev->map_buffer(stage, 0, sizeof verts);
+ memcpy(mem, verts, sizeof verts);
+ dev->unmap_buffer(stage);
+ }
+ {
+ Context& ctx = dev->acquire();
+ ctx.copy(vbo, stage);
+ dev->submit(ctx);
+ }
+ dev->destroy_buffer(stage);
+ return vbo;
+}
+
int main() {
Arena video_arena;
Arena asset_arena;
Asset_Arena assets;
Device* dev;
Shader* shader;
+ Texture* texture;
Buffer_Id vbo;
C2* app = App::create<C2>("c2");
void* per_frame;
@@ -47,23 +74,14 @@ int main() {
dev = Device::create(&video_arena, app);
app->dev = dev;
shader = (Shader*)assets.load("triangle.csh");
+ texture = (Texture*)assets.load("22.tex");
per_frame = heap_alloc(
dev->heap,
per_frame_memory_size
);
assert(per_frame != 0);
uint8_t r = 0;
- vbo = dev->create_buffer(
- sizeof verts,
- Buffer_Flags::vertex_buffer |
- Buffer_Flags::cpu_readwrite
- );
- {
- void* mem;
- mem = dev->map_buffer(vbo, 0, sizeof verts);
- memcpy(mem, verts, sizeof verts);
- dev->unmap_buffer(vbo);
- }
+ vbo = upload_verts(dev);
while (app->running) {
Arena frame_arena;
init_arena(&frame_arena, per_frame, per_frame_memory_size);
@@ -92,7 +110,7 @@ int main() {
draw.vertex_count = 3;
draw.instance_count = 1;
- dev->get_ctx().submit(*dev, draw, pip, pass);
+ dev->get_ctx().submit(draw, pip, pass);
/* dev->get_ctx().submit(*dev, pass);*/
r += 10;