feat: added shader compilation to cmakelist
This commit is contained in:
@@ -10,6 +10,20 @@ add_compile_definitions(WITH_VALIDATION_LAYERS)
|
|||||||
set(CMAKE_BUILD_TYPE Debug)
|
set(CMAKE_BUILD_TYPE Debug)
|
||||||
|
|
||||||
FILE(GLOB_RECURSE CXX_SOURCES src/*.cpp)
|
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})
|
add_executable(VulkanTest ${CXX_SOURCES})
|
||||||
target_link_libraries(VulkanTest glfw vulkan)
|
add_dependencies(VulkanTest shaders)
|
||||||
|
target_link_libraries(VulkanTest glfw vulkan)
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define GLFW_INCLUDE_VULKAN
|
#define GLFW_INCLUDE_VULKAN
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#include "queues.h"
|
#include "queues.h"
|
||||||
@@ -154,8 +153,8 @@ void HelloTriangleApplication::createGraphicsPipeline() {
|
|||||||
std::vector<char> vertShaderCode;
|
std::vector<char> vertShaderCode;
|
||||||
std::vector<char> fragShaderCode;
|
std::vector<char> fragShaderCode;
|
||||||
|
|
||||||
readFile("shaders/vert.spv", &vertShaderCode);
|
readFile("shaders/shader.vert.spv", &vertShaderCode);
|
||||||
readFile("shaders/frag.spv", &fragShaderCode);
|
readFile("shaders/shader.frag.spv", &fragShaderCode);
|
||||||
|
|
||||||
VkShaderModule vertShaderModule = createShaderModule(vertShaderCode);
|
VkShaderModule vertShaderModule = createShaderModule(vertShaderCode);
|
||||||
VkShaderModule fragShaderModule = createShaderModule(fragShaderCode);
|
VkShaderModule fragShaderModule = createShaderModule(fragShaderCode);
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ private:
|
|||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
// utility functions
|
// utility functions
|
||||||
std::vector<const char*> getRequiredExtensions();
|
|
||||||
VkShaderModule createShaderModule(const std::vector<char> &code);
|
VkShaderModule createShaderModule(const std::vector<char> &code);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,12 +4,9 @@
|
|||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
void readFile(const std::string& filename, std::vector<char>* target) {
|
void readFile(const std::string& filename, std::vector<char>* target) {
|
||||||
auto actualPath = std::filesystem::path("..") / filename;
|
std::ifstream file(filename, std::ios::ate | std::ios::binary);
|
||||||
|
|
||||||
std::ifstream file(actualPath.string(), std::ios::ate | std::ios::binary);
|
|
||||||
|
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
throw std::runtime_error("failed to open file");
|
throw std::runtime_error("failed to open file");
|
||||||
|
|||||||
Reference in New Issue
Block a user