aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bvh.cpp8
-rw-r--r--src/mesh.cpp14
-rw-r--r--src/scene.cpp17
3 files changed, 21 insertions, 18 deletions
diff --git a/src/bvh.cpp b/src/bvh.cpp
index 9d0b4b8..a22cd5e 100644
--- a/src/bvh.cpp
+++ b/src/bvh.cpp
@@ -150,15 +150,15 @@ aabb bvh::compute_bounds(uint32_t begin, uint32_t end) {
}
void bvh::subdivide(uint32_t parent_id, uint32_t begin, uint32_t end) {
- size_t count = end - begin;
+ const size_t count = end - begin;
if (count == 1) {
temp_nodes[parent_id] = std::move(leafs[begin]);
return;
}
- auto left_id = ++next_node_id;
- auto right_id = ++next_node_id;
+ const auto left_id = ++next_node_id;
+ const auto right_id = ++next_node_id;
temp_nodes[parent_id].left_id = (int32_t)left_id;
@@ -168,7 +168,7 @@ void bvh::subdivide(uint32_t parent_id, uint32_t begin, uint32_t end) {
return;
}
- auto parent_bb = temp_nodes[parent_id].bounding_box;
+ const auto& parent_bb = temp_nodes[parent_id].bounding_box;
int32_t split_axis = parent_bb.maximum_axis();
if (count <= 4) {
diff --git a/src/mesh.cpp b/src/mesh.cpp
index 3cebc52..bfc5caf 100644
--- a/src/mesh.cpp
+++ b/src/mesh.cpp
@@ -4,12 +4,14 @@ static std::vector<Mesh> meshes {};
void Mesh::add_submesh(const submesh& submesh) {
auto position_components = attribute_components(ATTRIBUTE_TYPE::POSITION);
- submeshes.emplace_back(submesh_info {
- (uint32_t)attributes[ATTRIBUTE_TYPE::POSITION].size() / position_components,
- (uint32_t)indices.size(),
- submesh.index_count / 3,
- 0
- });
+ submeshes.emplace_back(
+ submesh_info {
+ (uint32_t)attributes[ATTRIBUTE_TYPE::POSITION].size() / position_components,
+ (uint32_t)indices.size(),
+ submesh.index_count / 3,
+ 0
+ }
+ );
{
auto indices_off = indices.size();
diff --git a/src/scene.cpp b/src/scene.cpp
index 4093ff7..2f4aa97 100644
--- a/src/scene.cpp
+++ b/src/scene.cpp
@@ -89,32 +89,34 @@ scene::scene(const camera& cam, uint32_t width, uint32_t height)
const auto& mesh_positions = mesh->get_attribute(ATTRIBUTE_TYPE::POSITION);
const auto& mesh_indices = mesh->get_indices();
- indices.resize(indices.size() + (size_t)mesh->triangle_count() * 3);
- positions.resize(vertices_offset + (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::POSITION));
+ indices.resize(indices.size() + mesh_indices.size());
+ positions.resize(vertices_offset + mesh_positions.size());
normals.resize(vertices_offset + (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::NORMAL));
uvs.resize(vertices_offset + (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::UV_0));
std::memcpy(
positions.data() + vertices_offset * Mesh::attribute_components(ATTRIBUTE_TYPE::POSITION),
- positions.data(),
- (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::POSITION)
+ mesh_positions.data(),
+ mesh_positions.size() * sizeof(float)
);
std::memcpy(
normals.data() + vertices_offset * Mesh::attribute_components(ATTRIBUTE_TYPE::NORMAL),
mesh->get_attribute(ATTRIBUTE_TYPE::NORMAL).data(),
- (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::NORMAL)
+ (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::NORMAL) * sizeof(float)
);
std::memcpy(
uvs.data() + vertices_offset * Mesh::attribute_components(ATTRIBUTE_TYPE::UV_0),
mesh->get_attribute(ATTRIBUTE_TYPE::UV_0).data(),
- (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::UV_0)
+ (size_t)mesh->vertices_count() * Mesh::attribute_components(ATTRIBUTE_TYPE::UV_0) * sizeof(float)
);
// Add offset to indices in order to have absolute indices
for (const auto& submesh: mesh->get_submeshes()) {
- for (size_t element_index = 0; element_index < submesh.element_count; element_index++) {
+ auto vertex_offset = vertices_offset + submesh.vertex_offset;
+
+ for (size_t element_index { 0U }; element_index < submesh.element_count; element_index++) {
auto global_index = submesh.index_offset + element_index * 3;
size_t i1 = mesh_indices[global_index];
size_t i2 = mesh_indices[global_index + 1];
@@ -127,7 +129,6 @@ scene::scene(const camera& cam, uint32_t width, uint32_t height)
);
auto triangle_offset = triangles_offset * 3 + global_index;
- auto vertex_offset = vertices_offset + submesh.vertex_offset;
indices[triangle_offset] = (i1 + vertex_offset); // | (0xff000000 & (materials.size() << 8));
indices[triangle_offset + 1] = (i2 + vertex_offset); // | (0xff000000 & (materials.size() << 16));