aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.clang-format69
-rw-r--r--src/gltf.cpp54
2 files changed, 64 insertions, 59 deletions
diff --git a/.clang-format b/.clang-format
index 6cc25cd..b5daee6 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,38 +1,43 @@
-AccessModifierOffset: 0
-AlignAfterOpenBracket: DontAlign
-AlignConsecutiveAssignments: false
-AlignConsecutiveDeclarations: true
-AlignEscapedNewlines: Left
-AlignOperands: true
-AlignTrailingComments: false
-AllowAllParametersOfDeclarationOnNextLine: false
-AllowShortBlocksOnASingleLine: true
-AllowShortCaseLabelsOnASingleLine: false
-AllowShortFunctionsOnASingleLine: All
-AllowShortIfStatementsOnASingleLine: true
-AllowShortLoopsOnASingleLine: true
-BraceWrapping:
- AfterClass: true
- AfterControlStatement: false
- AfterEnum: false
- AfterFunction: true
- AfterNamespace: false
- AfterObjCDeclaration: false
- AfterStruct: true
- AfterUnion: false
- BeforeCatch: false
- BeforeElse: false
- IndentBraces: false
- SplitEmptyFunction: false
- SplitEmptyNamespace: true
- SplitEmptyRecord: true
-ColumnLimit: 120
-ConstructorInitializerIndentWidth: 4
-ContinuationIndentWidth: 4
+AlignEscapedNewlines: Right
+AlignTrailingComments: true
+ColumnLimit: 0
+ConstructorInitializerIndentWidth: 8
+Cpp11BracedListStyle: false
+DeriveLineEnding: false
+DerivePointerAlignment: false
+EmptyLineBeforeAccessModifier: Always
IndentWidth: 4
+KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: 2
+PointerAlignment: Left
+ReferenceAlignment: Left
+SeparateDefinitionBlocks: Always
SortIncludes: true
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: false
+SpaceAroundPointerQualifiers: Default
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCaseColon: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: false
+SpaceBeforeParens: Custom
+SpaceBeforeParensOptions:
+ AfterControlStatements: true
+ AfterFunctionDefinitionName: false
+ AfterFunctionDeclarationName: false
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceBeforeSquareBrackets: false
+SpaceInEmptyBlock: false
+SpaceInEmptyParentheses: false
+SpacesInConditionalStatement: false
+SpacesInContainerLiterals: false
+SpacesInLineCommentPrefix:
+ Minimum: 1
+ Maximum: 1
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
Standard: c++20
-TabWidth: 4
+UseCRLF: false
UseTab: Never
diff --git a/src/gltf.cpp b/src/gltf.cpp
index ed7a85d..0e611da 100644
--- a/src/gltf.cpp
+++ b/src/gltf.cpp
@@ -1,28 +1,28 @@
#include "gltf.hpp"
-#include <fstream>
-#include <filesystem>
#include <algorithm>
#include <execution>
+#include <filesystem>
+#include <fstream>
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
-#include "vk-renderer.hpp"
#include "utils.hpp"
+#include "vk-renderer.hpp"
-gltf::gltf(const std::filesystem::path &filepath) {
+gltf::gltf(const std::filesystem::path& filepath) {
auto parent_path = filepath.parent_path();
- std::fstream f { filepath };
+ std::fstream f{ filepath };
f >> gltf_json;
auto& scene = gltf_json["scenes"][0];
- auto &gltf_buffers = gltf_json["buffers"];
+ auto& gltf_buffers = gltf_json["buffers"];
auto buffer_count = gltf_buffers.size();
buffers.resize(gltf_buffers.size());
- for (auto buffer_index { 0U }; buffer_index < buffer_count; buffer_index++) {
+ for (auto buffer_index{ 0U }; buffer_index < buffer_count; buffer_index++) {
auto buffer_path = parent_path / gltf_buffers[buffer_index]["uri"].get<std::string>();
buffers[buffer_index] = read_file(buffer_path.string().c_str());
}
@@ -43,11 +43,11 @@ gltf::gltf(const std::filesystem::path &filepath) {
f.close();
}
-void gltf::load_node(uint32_t index, node &parent) {
- const auto &gltf_node = gltf_json["nodes"][index];
+void gltf::load_node(uint32_t index, node& parent) {
+ const auto& gltf_node = gltf_json["nodes"][index];
if (gltf_node.contains("children")) {
- const auto &children = gltf_node["children"];
+ const auto& children = gltf_node["children"];
uint32_t children_count = gltf_node["children"];
parent.children.resize(children_count);
@@ -62,15 +62,15 @@ void gltf::load_node(uint32_t index, node &parent) {
}
void gltf::load_meshes() {
- const auto &gltf_meshes = gltf_json["meshes"];
+ const auto& gltf_meshes = gltf_json["meshes"];
auto meshes_count = gltf_meshes.size();
meshes.resize(meshes_count);
for (size_t mesh_index = 0; mesh_index < meshes_count; mesh_index++) {
auto& mesh = meshes[mesh_index];
- const auto &primitives = gltf_meshes[mesh_index]["primitives"];
+ const auto& primitives = gltf_meshes[mesh_index]["primitives"];
- for (const auto &primitive : primitives) {
+ for (const auto& primitive : primitives) {
auto& material = materials[primitive["material"].get<uint32_t>()];
mesh.add_submesh(load_primitive(primitive), material);
}
@@ -79,7 +79,7 @@ void gltf::load_meshes() {
}
}
-Mesh::submesh gltf::load_primitive(const json &primitive) {
+Mesh::submesh gltf::load_primitive(const json& primitive) {
Mesh::submesh submesh;
submesh.indices = load_attribute(primitive["indices"]);
@@ -101,9 +101,9 @@ Mesh::submesh gltf::load_primitive(const json &primitive) {
Mesh::attribute gltf::load_attribute(uint32_t accessor_index) {
auto view_index = gltf_json["accessors"][accessor_index]["bufferView"].get<uint32_t>();
- const auto &view = gltf_json["bufferViews"][view_index];
+ const auto& view = gltf_json["bufferViews"][view_index];
auto offset = view["byteOffset"].get<off_t>();
- auto &buffer = buffers[view["buffer"].get<uint32_t>()];
+ auto& buffer = buffers[view["buffer"].get<uint32_t>()];
return {
&buffer[offset],
@@ -111,16 +111,16 @@ Mesh::attribute gltf::load_attribute(uint32_t accessor_index) {
};
}
-void gltf::load_textures(const std::filesystem::path &path) {
- const auto &gltf_images = gltf_json["images"];
+void gltf::load_textures(const std::filesystem::path& path) {
+ const auto& gltf_images = gltf_json["images"];
auto images_count = gltf_images.size();
- std::vector<raw_image> images{images_count};
+ std::vector<raw_image> images{ images_count };
std::vector<size_t> v(images_count);
std::iota(v.begin(), v.end(), 0);
std::for_each(std::execution::par, v.begin(), v.end(), [&](const size_t image_index) {
- const auto &gltf_image = gltf_images[image_index];
+ const auto& gltf_image = gltf_images[image_index];
auto filepath = (path / gltf_image["uri"].get<std::string>()).string();
auto& image = images[image_index];
image.data = stbi_load(filepath.c_str(), &image.width, &image.height, &image.channels, 4);
@@ -135,7 +135,7 @@ void gltf::load_textures(const std::filesystem::path &path) {
// samplers[sampler_index] = vkrenderer::create_sampler(VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_REPEAT);
// }
- const auto &gltf_textures = gltf_json["textures"];
+ const auto& gltf_textures = gltf_json["textures"];
auto textures_count = gltf_textures.size();
textures.resize(textures_count);
@@ -148,7 +148,7 @@ void gltf::load_textures(const std::filesystem::path &path) {
// sampler = samplers[sampler_index];
// }
- auto *texture = vkrenderer::create_2d_texture(static_cast<uint32_t>(image.width), static_cast<uint32_t>(image.height), VK_FORMAT_R8G8B8A8_UNORM, sampler);
+ auto* texture = vkrenderer::create_2d_texture(static_cast<uint32_t>(image.width), static_cast<uint32_t>(image.height), VK_FORMAT_R8G8B8A8_UNORM, sampler);
texture->update(image.data);
@@ -157,19 +157,19 @@ void gltf::load_textures(const std::filesystem::path &path) {
}
void gltf::load_materials() {
- const auto &gltf_materials = gltf_json["materials"];
+ const auto& gltf_materials = gltf_json["materials"];
auto materials_count = gltf_materials.size();
materials.resize(materials_count);
for (size_t material_index = 0; material_index < materials_count; material_index++) {
- const auto &gltf_material = gltf_materials[material_index];
- auto &material = materials[material_index];
+ const auto& gltf_material = gltf_materials[material_index];
+ auto& material = materials[material_index];
if (gltf_material.contains("pbrMetallicRoughness")) {
- const auto &pbr_params = gltf_material["pbrMetallicRoughness"];
+ const auto& pbr_params = gltf_material["pbrMetallicRoughness"];
if (pbr_params.contains("baseColorFactor")) {
- const auto &base_color = pbr_params["baseColorFactor"];
+ const auto& base_color = pbr_params["baseColorFactor"];
material.base_color.v[0] = base_color[0].get<float>();
material.base_color.v[1] = base_color[1].get<float>();
material.base_color.v[2] = base_color[2].get<float>();