diff --git a/CMakeLists.txt b/CMakeLists.txt index 5475fbf..b450e6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,20 @@ add_compile_definitions(WITH_VALIDATION_LAYERS) set(CMAKE_BUILD_TYPE Debug) FILE(GLOB_RECURSE CXX_SOURCES src/*.cpp) +FILE(GLOB_RECURSE GLSL_SOURCE_FILES shaders/**.frag shaders/**.vert) + +foreach(GLSL ${GLSL_SOURCE_FILES}) + get_filename_component(FILE_NAME "${GLSL}" NAME) + set(SPV_FILE "${PROJECT_BINARY_DIR}/shaders/${FILE_NAME}.spv") + add_custom_command(OUTPUT ${SPV_FILE} + COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/shaders/" + COMMAND glslc ${GLSL} -g -o ${SPV_FILE} + DEPENDS ${GLSL} + COMMENT "Rebuilding ${SPV_FILE}") + list(APPEND SPIRV_BINARY_KERNELS ${SPV_FILE}) +endforeach() +add_custom_target(shaders DEPENDS ${SPIRV_BINARY_KERNELS}) add_executable(VulkanTest ${CXX_SOURCES}) -target_link_libraries(VulkanTest glfw vulkan) \ No newline at end of file +add_dependencies(VulkanTest shaders) +target_link_libraries(VulkanTest glfw vulkan) diff --git a/src/HelloTriangleApplication.cpp b/src/HelloTriangleApplication.cpp index ff20abc..2bf59bb 100644 --- a/src/HelloTriangleApplication.cpp +++ b/src/HelloTriangleApplication.cpp @@ -9,7 +9,6 @@ #include #define GLFW_INCLUDE_VULKAN - #include #include "queues.h" @@ -154,8 +153,8 @@ void HelloTriangleApplication::createGraphicsPipeline() { std::vector vertShaderCode; std::vector fragShaderCode; - readFile("shaders/vert.spv", &vertShaderCode); - readFile("shaders/frag.spv", &fragShaderCode); + readFile("shaders/shader.vert.spv", &vertShaderCode); + readFile("shaders/shader.frag.spv", &fragShaderCode); VkShaderModule vertShaderModule = createShaderModule(vertShaderCode); VkShaderModule fragShaderModule = createShaderModule(fragShaderCode); diff --git a/src/HelloTriangleApplication.h b/src/HelloTriangleApplication.h index 31da1e3..71b3e23 100644 --- a/src/HelloTriangleApplication.h +++ b/src/HelloTriangleApplication.h @@ -62,7 +62,6 @@ private: void cleanup(); // utility functions - std::vector getRequiredExtensions(); VkShaderModule createShaderModule(const std::vector &code); }; diff --git a/src/util.cpp b/src/util.cpp index 28e904d..d314726 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -4,12 +4,9 @@ #include "util.h" #include -#include void readFile(const std::string& filename, std::vector* target) { - auto actualPath = std::filesystem::path("..") / filename; - - std::ifstream file(actualPath.string(), std::ios::ate | std::ios::binary); + std::ifstream file(filename, std::ios::ate | std::ios::binary); if (!file.is_open()) { throw std::runtime_error("failed to open file");