Skip to content

Commit c790fbe

Browse files
committed
[*] Small fixes
1 parent 15379f9 commit c790fbe

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

include/inexor/vulkan-renderer/gltf2/gltf2_model.hpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,11 @@ struct ModelPrimitive {
3535
struct ModelScene {
3636
std::vector<ModelVertex> vertices;
3737
std::vector<uint32_t> indices;
38-
39-
[[nodiscard]] auto get_vertices() const noexcept {
40-
return vertices;
41-
}
42-
43-
[[nodiscard]] auto get_indices() const noexcept {
44-
return indices;
45-
}
4638
};
4739

4840
/// @brief A struct for glTF2 model nodes.
4941
struct ModelNode {
50-
ModelNode *parent = nullptr;
42+
ModelNode *parent{nullptr};
5143
std::vector<ModelNode> children;
5244
std::vector<ModelPrimitive> mesh;
5345
glm::mat4 matrix{};
@@ -60,7 +52,6 @@ class Model {
6052
private:
6153
const tinygltf::Model &m_model;
6254
const wrapper::Device &m_device;
63-
const std::string m_file_name;
6455

6556
std::vector<wrapper::GpuTexture> m_textures;
6657
std::vector<std::uint32_t> m_texture_indices;
@@ -84,6 +75,7 @@ class Model {
8475
// TODO: load animation skins
8576
// TODO: load pbr (physically based rendering) settings
8677
// TODO: load multiple texture coordinate sets
78+
// TODO: try to .reserve() memory for vectors and use emplace_back()
8779

8880
public:
8981
/// @brief Extract the model data from a model file.

src/vulkan-renderer/gltf2/gltf2_model.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ void Model::load_textures() {
3737
// The pointer to the rgb data we read from.
3838
unsigned char *mem_source_rgb = &texture.image[0];
3939

40-
for (size_t i = 0; i < texture.width * texture.height; ++i) {
40+
for (std::size_t i = 0; i < texture.width * texture.height; ++i) {
4141
std::memcpy(mem_target_rgba, mem_source_rgb, sizeof(unsigned char) * 3);
42+
// TODO: Remove pointer arithmetic or add NOLINT
4243
mem_target_rgba += 4;
44+
// TODO: Remove pointer arithmetic or add NOLINT
4345
mem_source_rgb += 3;
4446
}
4547

@@ -49,7 +51,7 @@ void Model::load_textures() {
4951
m_textures.emplace_back(m_device, &texture.image[0], texture_size, texture.width, texture.height,
5052
texture.component, 1, "glTF2 model texture");
5153
} else {
52-
spdlog::error("Can't load texture from model file {}", m_file_name);
54+
spdlog::error("Can't load texture with {} channels!", texture.component);
5355

5456
// Generate an error texture (checkboard pattern of pink and black squares).
5557
m_textures.emplace_back(m_device, wrapper::CpuTexture());
@@ -157,10 +159,13 @@ void Model::load_node(const tinygltf::Node &start_node, ModelNode *parent, std::
157159
}
158160

159161
// Append data to model's vertex buffer
160-
for (size_t vertex_number = 0; vertex_number < vertex_count; vertex_number++) {
162+
for (std::size_t vertex_number = 0; vertex_number < vertex_count; vertex_number++) {
161163
ModelVertex new_vertex{};
164+
// TODO: Remove pointer arithmetic or add NOLINT
162165
new_vertex.pos = glm::vec4(glm::make_vec3(&position_buffer[vertex_number * 3]), 1.0f);
166+
// TODO: Remove pointer arithmetic or add NOLINT
163167
new_vertex.normal = glm::normalize(glm::vec3(
168+
// TODO: Remove pointer arithmetic or add NOLINT
164169
normals_buffer != nullptr ? glm::make_vec3(&normals_buffer[vertex_number * 3]) : glm::vec3(0.0f)));
165170
new_vertex.uv = texture_coordinate_buffer != nullptr
166171
? glm::make_vec2(&texture_coordinate_buffer[vertex_number * 2])
@@ -215,8 +220,8 @@ void Model::load_node(const tinygltf::Node &start_node, ModelNode *parent, std::
215220
break;
216221
}
217222
default:
218-
spdlog::error("Index component type {} not supported!", accessor.componentType);
219-
return;
223+
// TODO: Is this worth an exception or not?
224+
spdlog::error("Index component type {} is not supported!", accessor.componentType);
220225
}
221226

222227
ModelPrimitive new_primitive{};
@@ -244,11 +249,8 @@ void Model::load_nodes() {
244249

245250
for (const auto &scene : m_model.scenes) {
246251
for (const auto &node : scene.nodes) {
247-
auto vertices = m_scenes[scene_index].get_vertices();
248-
auto indices = m_scenes[scene_index].get_indices();
249-
load_node(m_model.nodes[node], nullptr, vertices, indices);
252+
load_node(m_model.nodes[node], nullptr, m_scenes[scene_index].vertices, m_scenes[scene_index].indices);
250253
}
251-
252254
scene_index++;
253255
}
254256
}

0 commit comments

Comments
 (0)