diff --git a/chapter-0/CMakeLists.txt b/chapter-0/CMakeLists.txt index 7adbd7661..5a8a621a2 100644 --- a/chapter-0/CMakeLists.txt +++ b/chapter-0/CMakeLists.txt @@ -13,7 +13,9 @@ target_include_directories(chapter_0 PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(chapter_0 vkguide_shared vkbootstrap) -add_custom_command(TARGET chapter_0 POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND_EXPAND_LISTS - ) +if (WIN32) + add_custom_command(TARGET chapter_0 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND_EXPAND_LISTS + ) +endif() diff --git a/chapter-1/CMakeLists.txt b/chapter-1/CMakeLists.txt index 310cf2c95..8193030fe 100644 --- a/chapter-1/CMakeLists.txt +++ b/chapter-1/CMakeLists.txt @@ -13,7 +13,9 @@ target_include_directories(chapter_1 PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(chapter_1 vkguide_shared vkbootstrap) -add_custom_command(TARGET chapter_1 POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND_EXPAND_LISTS - ) +if (WIN32) + add_custom_command(TARGET chapter_1 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND_EXPAND_LISTS + ) +endif() diff --git a/chapter-2/CMakeLists.txt b/chapter-2/CMakeLists.txt index d9ab2cda6..c2757723a 100644 --- a/chapter-2/CMakeLists.txt +++ b/chapter-2/CMakeLists.txt @@ -14,7 +14,9 @@ target_include_directories(chapter_2 PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(chapter_2 vkguide_shared vkbootstrap imgui) -add_custom_command(TARGET chapter_2 POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND_EXPAND_LISTS - ) +if (WIN32) + add_custom_command(TARGET chapter_2 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND_EXPAND_LISTS + ) +endif() diff --git a/chapter-3/CMakeLists.txt b/chapter-3/CMakeLists.txt index 4ef4ba6bd..e2d8de281 100644 --- a/chapter-3/CMakeLists.txt +++ b/chapter-3/CMakeLists.txt @@ -15,7 +15,9 @@ target_include_directories(chapter_3 PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(chapter_3 vkguide_shared vkbootstrap imgui fastgltf::fastgltf) -add_custom_command(TARGET chapter_3 POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND_EXPAND_LISTS - ) +if (WIN32) + add_custom_command(TARGET chapter_3 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND_EXPAND_LISTS + ) +endif() diff --git a/chapter-3/vk_engine.cpp b/chapter-3/vk_engine.cpp index fa6bc0a46..0f4005ad9 100644 --- a/chapter-3/vk_engine.cpp +++ b/chapter-3/vk_engine.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "imgui.h" #include "imgui_impl_sdl2.h" diff --git a/chapter-3/vk_loader.cpp b/chapter-3/vk_loader.cpp index 690c00f68..dedfc5498 100644 --- a/chapter-3/vk_loader.cpp +++ b/chapter-3/vk_loader.cpp @@ -20,7 +20,8 @@ std::optional>> loadGltfMeshes(VulkanEngi data.loadFromFile(filePath); constexpr auto gltfOptions = fastgltf::Options::LoadGLBBuffers - | fastgltf::Options::LoadExternalBuffers; + | fastgltf::Options::LoadExternalBuffers + | fastgltf::Options::GenerateMeshIndices; fastgltf::Asset gltf; fastgltf::Parser parser {}; @@ -29,7 +30,7 @@ std::optional>> loadGltfMeshes(VulkanEngi if (load) { gltf = std::move(load.get()); } else { - fmt::print("Failed to load glTF: {} \n", fastgltf::to_underlying(load.error())); + fmt::print("Failed to load glTF: {} \n", fastgltf::getErrorMessage(load.error())); return {}; } //< openmesh @@ -40,7 +41,7 @@ std::optional>> loadGltfMeshes(VulkanEngi // often std::vector indices; std::vector vertices; - for (fastgltf::Mesh& mesh : gltf.meshes) { + for (const fastgltf::Mesh& mesh : gltf.meshes) { MeshAsset newmesh; newmesh.name = mesh.name; diff --git a/chapter-4/CMakeLists.txt b/chapter-4/CMakeLists.txt index 13b540847..dd58decbe 100644 --- a/chapter-4/CMakeLists.txt +++ b/chapter-4/CMakeLists.txt @@ -15,7 +15,9 @@ target_include_directories(chapter_4 PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(chapter_4 vkguide_shared vkbootstrap imgui fastgltf::fastgltf) -add_custom_command(TARGET chapter_4 POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND_EXPAND_LISTS - ) +if (WIN32) + add_custom_command(TARGET chapter_4 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND_EXPAND_LISTS + ) +endif() diff --git a/chapter-4/vk_loader.cpp b/chapter-4/vk_loader.cpp index 690c00f68..dedfc5498 100644 --- a/chapter-4/vk_loader.cpp +++ b/chapter-4/vk_loader.cpp @@ -20,7 +20,8 @@ std::optional>> loadGltfMeshes(VulkanEngi data.loadFromFile(filePath); constexpr auto gltfOptions = fastgltf::Options::LoadGLBBuffers - | fastgltf::Options::LoadExternalBuffers; + | fastgltf::Options::LoadExternalBuffers + | fastgltf::Options::GenerateMeshIndices; fastgltf::Asset gltf; fastgltf::Parser parser {}; @@ -29,7 +30,7 @@ std::optional>> loadGltfMeshes(VulkanEngi if (load) { gltf = std::move(load.get()); } else { - fmt::print("Failed to load glTF: {} \n", fastgltf::to_underlying(load.error())); + fmt::print("Failed to load glTF: {} \n", fastgltf::getErrorMessage(load.error())); return {}; } //< openmesh @@ -40,7 +41,7 @@ std::optional>> loadGltfMeshes(VulkanEngi // often std::vector indices; std::vector vertices; - for (fastgltf::Mesh& mesh : gltf.meshes) { + for (const fastgltf::Mesh& mesh : gltf.meshes) { MeshAsset newmesh; newmesh.name = mesh.name; diff --git a/chapter-5/CMakeLists.txt b/chapter-5/CMakeLists.txt index ca920d8d2..fe0b3e263 100644 --- a/chapter-5/CMakeLists.txt +++ b/chapter-5/CMakeLists.txt @@ -17,7 +17,9 @@ target_include_directories(chapter_5 PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(chapter_5 vkguide_shared vkbootstrap imgui fastgltf::fastgltf) -add_custom_command(TARGET chapter_5 POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND_EXPAND_LISTS - ) \ No newline at end of file +if (WIN32) + add_custom_command(TARGET chapter_5 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND_EXPAND_LISTS + ) +endif() diff --git a/chapter-5/vk_loader.cpp b/chapter-5/vk_loader.cpp index 2cc29d45d..cf3f05f51 100644 --- a/chapter-5/vk_loader.cpp +++ b/chapter-5/vk_loader.cpp @@ -6,6 +6,7 @@ #include "vk_initializers.h" #include "vk_types.h" #include +#include #include #include @@ -25,9 +26,7 @@ std::optional load_image(VulkanEngine* engine, fastgltf::Asset& assert(filePath.fileByteOffset == 0); // We don't support offsets with stbi. assert(filePath.uri.isLocalPath()); // We're only capable of loading // local files. - - const std::string path(filePath.uri.path().begin(), - filePath.uri.path().end()); // Thanks C++. + const std::string path(filePath.uri.path()); unsigned char* data = stbi_load(path.c_str(), &width, &height, &nrChannels, 4); if (data) { VkExtent3D imagesize; @@ -137,7 +136,11 @@ std::optional> loadGltf(VulkanEngine* engine, std::s fastgltf::Parser parser {}; - constexpr auto gltfOptions = fastgltf::Options::DontRequireValidAssetMember | fastgltf::Options::AllowDouble | fastgltf::Options::LoadGLBBuffers | fastgltf::Options::LoadExternalBuffers; + constexpr auto gltfOptions = fastgltf::Options::DontRequireValidAssetMember + | fastgltf::Options::AllowDouble + | fastgltf::Options::LoadGLBBuffers + | fastgltf::Options::LoadExternalBuffers + | fastgltf::Options::GenerateMeshIndices; // fastgltf::Options::LoadExternalImages; fastgltf::GltfDataBuffer data; @@ -153,7 +156,7 @@ std::optional> loadGltf(VulkanEngine* engine, std::s if (load) { gltf = std::move(load.get()); } else { - std::cerr << "Failed to load glTF: " << fastgltf::to_underlying(load.error()) << std::endl; + fmt::print("Failed to load glTF: {}", fastgltf::getErrorMessage(load.error())); return {}; } } else if (type == fastgltf::GltfType::GLB) { @@ -161,7 +164,7 @@ std::optional> loadGltf(VulkanEngine* engine, std::s if (load) { gltf = std::move(load.get()); } else { - std::cerr << "Failed to load glTF: " << fastgltf::to_underlying(load.error()) << std::endl; + fmt::print("Failed to load glTF: {}", fastgltf::getErrorMessage(load.error())); return {}; } } else { @@ -180,7 +183,7 @@ std::optional> loadGltf(VulkanEngine* engine, std::s //> load_samplers // load samplers - for (fastgltf::Sampler& sampler : gltf.samplers) { + for (const fastgltf::Sampler& sampler : gltf.samplers) { VkSamplerCreateInfo sampl = { .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .pNext = nullptr}; sampl.maxLod = VK_LOD_CLAMP_NONE; @@ -229,16 +232,13 @@ std::optional> loadGltf(VulkanEngine* engine, std::s //< load_buffer // //> load_material - for (fastgltf::Material& mat : gltf.materials) { + for (const fastgltf::Material& mat : gltf.materials) { std::shared_ptr newMat = std::make_shared(); materials.push_back(newMat); file.materials[mat.name.c_str()] = newMat; GLTFMetallic_Roughness::MaterialConstants constants; - constants.colorFactors.x = mat.pbrData.baseColorFactor[0]; - constants.colorFactors.y = mat.pbrData.baseColorFactor[1]; - constants.colorFactors.z = mat.pbrData.baseColorFactor[2]; - constants.colorFactors.w = mat.pbrData.baseColorFactor[3]; + constants.colorFactors = glm::make_vec4(mat.pbrData.baseColorFactor.data()); constants.metal_rough_factors.x = mat.pbrData.metallicFactor; constants.metal_rough_factors.y = mat.pbrData.roughnessFactor; @@ -280,7 +280,7 @@ std::optional> loadGltf(VulkanEngine* engine, std::s std::vector indices; std::vector vertices; - for (fastgltf::Mesh& mesh : gltf.meshes) { + for (const fastgltf::Mesh& mesh : gltf.meshes) { std::shared_ptr newmesh = std::make_shared(); meshes.push_back(newmesh); file.meshes[mesh.name.c_str()] = newmesh; @@ -290,7 +290,7 @@ std::optional> loadGltf(VulkanEngine* engine, std::s indices.clear(); vertices.clear(); - for (auto&& p : mesh.primitives) { + for (const fastgltf::Primitive& p : mesh.primitives) { GeoSurface newSurface; newSurface.startIndex = (uint32_t)indices.size(); newSurface.count = (uint32_t)gltf.accessors[p.indicesAccessor.value()].count; @@ -364,7 +364,7 @@ std::optional> loadGltf(VulkanEngine* engine, std::s glm::vec3 minpos = vertices[initial_vtx].position; glm::vec3 maxpos = vertices[initial_vtx].position; - for (int i = initial_vtx; i < vertices.size(); i++) { + for (size_t i = initial_vtx; i < vertices.size(); i++) { minpos = glm::min(minpos, vertices[i].position); maxpos = glm::max(maxpos, vertices[i].position); } @@ -393,23 +393,23 @@ std::optional> loadGltf(VulkanEngine* engine, std::s nodes.push_back(newNode); file.nodes[node.name.c_str()]; - std::visit(fastgltf::visitor { [&](fastgltf::Node::TransformMatrix matrix) { - memcpy(&newNode->localTransform, matrix.data(), sizeof(matrix)); - }, - [&](fastgltf::Node::TRS transform) { - glm::vec3 tl(transform.translation[0], transform.translation[1], - transform.translation[2]); - glm::quat rot(transform.rotation[3], transform.rotation[0], transform.rotation[1], - transform.rotation[2]); - glm::vec3 sc(transform.scale[0], transform.scale[1], transform.scale[2]); - - glm::mat4 tm = glm::translate(glm::mat4(1.f), tl); - glm::mat4 rm = glm::toMat4(rot); - glm::mat4 sm = glm::scale(glm::mat4(1.f), sc); - - newNode->localTransform = tm * rm * sm; - } }, - node.transform); + std::visit(fastgltf::visitor { + [&](fastgltf::Node::TransformMatrix matrix) { + std::memcpy(&newNode->localTransform, matrix.data(), sizeof(matrix)); + }, + [&](fastgltf::Node::TRS transform) { + glm::vec3 tl = glm::make_vec3(transform.translation.data()); + glm::quat rot(transform.rotation[3], transform.rotation[0], transform.rotation[1], + transform.rotation[2]); + glm::vec3 sc = glm::make_vec3(transform.scale.data()); + + glm::mat4 tm = glm::translate(glm::mat4(1.f), tl); + glm::mat4 rm = glm::toMat4(rot); + glm::mat4 sm = glm::scale(glm::mat4(1.f), sc); + + newNode->localTransform = tm * rm * sm; + } + }, node.transform); } //< load_nodes //> load_graph diff --git a/meshbaker/CMakeLists.txt b/meshbaker/CMakeLists.txt index fd0007c0d..033c540bc 100644 --- a/meshbaker/CMakeLists.txt +++ b/meshbaker/CMakeLists.txt @@ -13,7 +13,9 @@ target_include_directories(meshbaker PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(meshbaker vkguide_shared vkbootstrap imgui fastgltf::fastgltf) -add_custom_command(TARGET meshbaker POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND_EXPAND_LISTS - ) \ No newline at end of file +if (WIN32) + add_custom_command(TARGET meshbaker POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND_EXPAND_LISTS + ) +endif() \ No newline at end of file diff --git a/meshbaker/main.cpp b/meshbaker/main.cpp index 8d137d3ba..89fedb867 100644 --- a/meshbaker/main.cpp +++ b/meshbaker/main.cpp @@ -67,7 +67,7 @@ void output_meshes(std::filesystem::path target_file, std::filesystem::path sour gltf = std::move(load.get()); } else { - std::cerr << "Failed to load glTF: " << fastgltf::to_underlying(load.error()) << std::endl; + std::cerr << "Failed to load glTF: " << fastgltf::getErrorMessage(load.error()) << std::endl; } } else if (type == fastgltf::GltfType::GLB) { @@ -76,7 +76,7 @@ void output_meshes(std::filesystem::path target_file, std::filesystem::path sour gltf = std::move(load.get()); } else { - std::cerr << "Failed to load glTF: " << fastgltf::to_underlying(load.error()) << std::endl; + std::cerr << "Failed to load glTF: " << fastgltf::getErrorMessage(load.error()) << std::endl; } } else { diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index a9aae0490..aad62cc08 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -35,6 +35,7 @@ add_library(imgui STATIC) target_include_directories(imgui PUBLIC imgui) +target_compile_features(imgui PRIVATE cxx_std_17) target_sources(imgui PRIVATE imgui/imgui.h imgui/imgui.cpp