Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions chapter-0/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_RUNTIME_DLLS:chapter_0> $<TARGET_FILE_DIR:chapter_0>
COMMAND_EXPAND_LISTS
)
if (WIN32)
add_custom_command(TARGET chapter_0 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:chapter_0> $<TARGET_FILE_DIR:chapter_0>
COMMAND_EXPAND_LISTS
)
endif()
10 changes: 6 additions & 4 deletions chapter-1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_RUNTIME_DLLS:chapter_1> $<TARGET_FILE_DIR:chapter_1>
COMMAND_EXPAND_LISTS
)
if (WIN32)
add_custom_command(TARGET chapter_1 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:chapter_1> $<TARGET_FILE_DIR:chapter_1>
COMMAND_EXPAND_LISTS
)
endif()
10 changes: 6 additions & 4 deletions chapter-2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_RUNTIME_DLLS:chapter_2> $<TARGET_FILE_DIR:chapter_2>
COMMAND_EXPAND_LISTS
)
if (WIN32)
add_custom_command(TARGET chapter_2 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:chapter_2> $<TARGET_FILE_DIR:chapter_2>
COMMAND_EXPAND_LISTS
)
endif()
10 changes: 6 additions & 4 deletions chapter-3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_RUNTIME_DLLS:chapter_3> $<TARGET_FILE_DIR:chapter_3>
COMMAND_EXPAND_LISTS
)
if (WIN32)
add_custom_command(TARGET chapter_3 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:chapter_3> $<TARGET_FILE_DIR:chapter_3>
COMMAND_EXPAND_LISTS
)
endif()
1 change: 1 addition & 0 deletions chapter-3/vk_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <array>
#include <iostream>
#include <fstream>
#include <thread>

#include "imgui.h"
#include "imgui_impl_sdl2.h"
Expand Down
7 changes: 4 additions & 3 deletions chapter-3/vk_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ std::optional<std::vector<std::shared_ptr<MeshAsset>>> 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 {};
Expand All @@ -29,7 +30,7 @@ std::optional<std::vector<std::shared_ptr<MeshAsset>>> 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
Expand All @@ -40,7 +41,7 @@ std::optional<std::vector<std::shared_ptr<MeshAsset>>> loadGltfMeshes(VulkanEngi
// often
std::vector<uint32_t> indices;
std::vector<Vertex> vertices;
for (fastgltf::Mesh& mesh : gltf.meshes) {
for (const fastgltf::Mesh& mesh : gltf.meshes) {
MeshAsset newmesh;

newmesh.name = mesh.name;
Expand Down
10 changes: 6 additions & 4 deletions chapter-4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_RUNTIME_DLLS:chapter_4> $<TARGET_FILE_DIR:chapter_4>
COMMAND_EXPAND_LISTS
)
if (WIN32)
add_custom_command(TARGET chapter_4 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:chapter_4> $<TARGET_FILE_DIR:chapter_4>
COMMAND_EXPAND_LISTS
)
endif()
7 changes: 4 additions & 3 deletions chapter-4/vk_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ std::optional<std::vector<std::shared_ptr<MeshAsset>>> 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 {};
Expand All @@ -29,7 +30,7 @@ std::optional<std::vector<std::shared_ptr<MeshAsset>>> 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
Expand All @@ -40,7 +41,7 @@ std::optional<std::vector<std::shared_ptr<MeshAsset>>> loadGltfMeshes(VulkanEngi
// often
std::vector<uint32_t> indices;
std::vector<Vertex> vertices;
for (fastgltf::Mesh& mesh : gltf.meshes) {
for (const fastgltf::Mesh& mesh : gltf.meshes) {
MeshAsset newmesh;

newmesh.name = mesh.name;
Expand Down
10 changes: 6 additions & 4 deletions chapter-5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_RUNTIME_DLLS:chapter_5> $<TARGET_FILE_DIR:chapter_5>
COMMAND_EXPAND_LISTS
)
if (WIN32)
add_custom_command(TARGET chapter_5 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:chapter_5> $<TARGET_FILE_DIR:chapter_5>
COMMAND_EXPAND_LISTS
)
endif()
64 changes: 32 additions & 32 deletions chapter-5/vk_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "vk_initializers.h"
#include "vk_types.h"
#include <glm/gtx/quaternion.hpp>
#include <glm/gtc/type_ptr.hpp>

#include <fastgltf/glm_element_traits.hpp>
#include <fastgltf/parser.hpp>
Expand All @@ -25,9 +26,7 @@ std::optional<AllocatedImage> 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;
Expand Down Expand Up @@ -137,7 +136,11 @@ std::optional<std::shared_ptr<LoadedGLTF>> 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;
Expand All @@ -153,15 +156,15 @@ std::optional<std::shared_ptr<LoadedGLTF>> 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) {
auto load = parser.loadBinaryGLTF(&data, path.parent_path(), gltfOptions);
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 {
Expand All @@ -180,7 +183,7 @@ std::optional<std::shared_ptr<LoadedGLTF>> 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;
Expand Down Expand Up @@ -229,16 +232,13 @@ std::optional<std::shared_ptr<LoadedGLTF>> 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<GLTFMaterial> newMat = std::make_shared<GLTFMaterial>();
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;
Expand Down Expand Up @@ -280,7 +280,7 @@ std::optional<std::shared_ptr<LoadedGLTF>> loadGltf(VulkanEngine* engine, std::s
std::vector<uint32_t> indices;
std::vector<Vertex> vertices;

for (fastgltf::Mesh& mesh : gltf.meshes) {
for (const fastgltf::Mesh& mesh : gltf.meshes) {
std::shared_ptr<MeshAsset> newmesh = std::make_shared<MeshAsset>();
meshes.push_back(newmesh);
file.meshes[mesh.name.c_str()] = newmesh;
Expand All @@ -290,7 +290,7 @@ std::optional<std::shared_ptr<LoadedGLTF>> 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;
Expand Down Expand Up @@ -364,7 +364,7 @@ std::optional<std::shared_ptr<LoadedGLTF>> 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);
}
Expand Down Expand Up @@ -393,23 +393,23 @@ std::optional<std::shared_ptr<LoadedGLTF>> 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
Expand Down
10 changes: 6 additions & 4 deletions meshbaker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_RUNTIME_DLLS:meshbaker> $<TARGET_FILE_DIR:meshbaker>
COMMAND_EXPAND_LISTS
)
if (WIN32)
add_custom_command(TARGET meshbaker POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:meshbaker> $<TARGET_FILE_DIR:meshbaker>
COMMAND_EXPAND_LISTS
)
endif()
4 changes: 2 additions & 2 deletions meshbaker/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down