summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-12-29 23:33:39 +1100
committerquou <quou@disroot.org>2024-12-29 23:33:39 +1100
commit131f0b370f52f70f3dc4a6341d543ef2329cc00e (patch)
treee1cbeb0ccd976d371d2d6dcdee2928ce9539014f
parente25b20717523e579bb6f1e0d17b635c71bad6fab (diff)
add a seperate update_cbuffers function to models to avoid doing it on every render
-rw-r--r--c2.cpp13
-rw-r--r--model.cpp17
-rw-r--r--model.hpp9
3 files changed, 25 insertions, 14 deletions
diff --git a/c2.cpp b/c2.cpp
index e88f12d..e36b1cd 100644
--- a/c2.cpp
+++ b/c2.cpp
@@ -215,22 +215,23 @@ extern "C" int entrypoint() {
raxis
));
monkey->update_transforms();
+ monkey->update_cbuffers(
+ dev,
+ transform,
+ projection
+ );
ctx.debug_push("depth prepass");
monkey->render(
dev,
&frame_arena,
- depth_prepass,
- transform,
- projection
+ depth_prepass
);
ctx.debug_pop();
ctx.debug_push("forward");
monkey->render(
dev,
&frame_arena,
- pass2,
- transform,
- projection
+ pass2
);
ctx.debug_pop();
diff --git a/model.cpp b/model.cpp
index dd14085..3b0e90f 100644
--- a/model.cpp
+++ b/model.cpp
@@ -156,16 +156,13 @@ void Model::update_transforms() {
meshes[i].get_world(*this);
}
-void Model::render(
+void Model::update_cbuffers(
Device* dev,
- Arena* a,
- Render_Pass& pass,
const m4f& transform,
const m4f& view_projection
) {
int i, c = mesh_count;
Mesh* meshes = get_meshes();
- Context& ctx = dev->get_ctx();
MVP_Cbuffer* cbuffers = (MVP_Cbuffer*)dev->map_buffer(
mvp,
0,
@@ -175,8 +172,18 @@ void Model::render(
cbuffers[i].view_projection = view_projection;
cbuffers[i].model = transform * meshes[i].world;
}
- bool depth_only = !pass.colour_count;
dev->unmap_buffer(mvp);
+}
+
+void Model::render(
+ Device* dev,
+ Arena* a,
+ Render_Pass& pass
+) {
+ int i, c = mesh_count;
+ Mesh* meshes = get_meshes();
+ Context& ctx = dev->get_ctx();
+ bool depth_only = !pass.colour_count;
for (i = 0; i < c; i++) {
Mesh& mesh = meshes[i];
Shader& shader = dev->get_shader(mesh.shader);
diff --git a/model.hpp b/model.hpp
index 7130024..03cdef4 100644
--- a/model.hpp
+++ b/model.hpp
@@ -27,13 +27,16 @@ struct Model : public Asset {
void destroy(Device* dev);
void update_transforms();
- void render(
+ void update_cbuffers(
Device* dev,
- Arena* a,
- Render_Pass& pass,
const m4f& transform,
const m4f& view_projection
);
+ void render(
+ Device* dev,
+ Arena* a,
+ Render_Pass& pass
+ );
};
struct Model_Loader : public Asset_Loader {