From 3a4030ad898acbb458dd449d3c293fd3648868c1 Mon Sep 17 00:00:00 2001 From: Warwick Date: Tue, 14 Nov 2023 15:05:06 +0000 Subject: [PATCH] Going further into the vulkan tutorial. :( Wish I didn't need it --- compile_shaders.sh | 2 +- shaders/shader.vert.spv | Bin 424 -> 0 bytes src/application.cpp | 2 +- src/application.hpp | 2 ++ src/yave_graphics_pipeline.cpp | 34 +++++++++++++++++++++++++++++++++ src/yave_graphics_pipeline.hpp | 15 ++++++++++----- src/yave_window.hpp | 28 ++++++++++++++++----------- 7 files changed, 65 insertions(+), 18 deletions(-) delete mode 100644 shaders/shader.vert.spv create mode 100644 src/yave_graphics_pipeline.cpp diff --git a/compile_shaders.sh b/compile_shaders.sh index 3f675e2..9c266fd 100755 --- a/compile_shaders.sh +++ b/compile_shaders.sh @@ -1,3 +1,3 @@ #!/bin/bash glslc shaders/shader.vert -o shaders/shader.vert.spv -glslc shaders/shader.frag -o shaders/shader.vert.spv +glslc shaders/shader.frag -o shaders/shader.frag.spv diff --git a/shaders/shader.vert.spv b/shaders/shader.vert.spv deleted file mode 100644 index 47d2768453f81ddde416df6318329f014c5cd0f7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 424 zcmYjO%ZkE45bQNZ<8u{3Z;Rql5f3U03%iF!<`VGW2Mm(rFc1^bD0uVR{3W zbb6{%-Cbdv!mupzAysMMc}80bU_@$CvQ_zOe{#se$!tEQqA89QQu7H-5tX^!n1mlH z$QCr@FdQcb6Gg6QC}NZHwOXx|ztq8Qrw`dVj&y92NQY)01(`WT)Ok6bNrLzo<^?Vk z`JJw~c5iyj{?jrlKh$ diff --git a/src/application.cpp b/src/application.cpp index ba4b5e3..eea182d 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -4,7 +4,7 @@ namespace yave { void Application::run() { - yaveVulkanInstance VI = yaveVulkanInstance(); + YaveVulkanInstance VI = YaveVulkanInstance(); while (!yaveWindow.shouldClose()) { glfwPollEvents(); diff --git a/src/application.hpp b/src/application.hpp index 604b2c2..b09798d 100644 --- a/src/application.hpp +++ b/src/application.hpp @@ -1,6 +1,7 @@ #pragma once #include "yave_window.hpp" +#include "yave_graphics_pipeline.hpp" namespace yave { class Application { @@ -12,6 +13,7 @@ class Application { private: YaveWindow yaveWindow{WIDTH, HEIGHT, "Hello Vulkan!"}; + YaveGrPipeline yavePipeline{"shaders/shader.vert.spv","shaders/shader.frag.spv"}; }; } // namespace yave diff --git a/src/yave_graphics_pipeline.cpp b/src/yave_graphics_pipeline.cpp new file mode 100644 index 0000000..c65bc6d --- /dev/null +++ b/src/yave_graphics_pipeline.cpp @@ -0,0 +1,34 @@ +#include "yave_graphics_pipeline.hpp" +#include +#include +#include + +namespace yave { +YaveGrPipeline::YaveGrPipeline(const std::string &vertFilepath, + const std::string &fragFilepath) { + createGraphicsPipeline(vertFilepath, fragFilepath); +} + +std::vector YaveGrPipeline::readFile(const std::string &filepath) { + std::ifstream file{filepath, std::ios::ate | std::ios::binary}; + if (!file.is_open()) { + throw std::runtime_error("failed to open file: " + filepath); + } + + size_t fileSize = static_cast(file.tellg()); + std::vector buffer(fileSize); + + file.seekg(0); + file.read(buffer.data(), fileSize); + file.close(); + + return buffer; +} + +void YaveGrPipeline::createGraphicsPipeline(const std::string &vertFilepath, + const std::string &fragFilepath) { + auto vertCode = readFile(vertFilepath); + auto fragCode = readFile(fragFilepath); +} + +} // namespace yave diff --git a/src/yave_graphics_pipeline.hpp b/src/yave_graphics_pipeline.hpp index 39ed6be..9d1ccde 100644 --- a/src/yave_graphics_pipeline.hpp +++ b/src/yave_graphics_pipeline.hpp @@ -1,15 +1,20 @@ #pragma once -#include +#include +#include namespace yave { class YaveGrPipeline { - public: - YaveGrPipeline(const std::string& vertFilepath, const std::string& fragFilepath); +public: + YaveGrPipeline(const std::string &vertFilepath, + const std::string &fragFilepath); - private: - +private: + static std::vector readFile(const std::string &filepath); + + void createGraphicsPipeline(const std::string &vertFilepath, + const std::string &fragFilepath); }; } // namespace yave diff --git a/src/yave_window.hpp b/src/yave_window.hpp index 0d232f6..f9357b9 100644 --- a/src/yave_window.hpp +++ b/src/yave_window.hpp @@ -8,21 +8,27 @@ namespace yave { class YaveWindow { - private: - GLFWwindow *window; +private: + GLFWwindow *window; - void initWindow(); + void initWindow(); - const int width; - const int height; - std::string windowName; + const int width; + const int height; + std::string windowName; - public: - YaveWindow(int w, int h, std::string name); - ~YaveWindow(); +public: + // Delete Copy constructors + // This class should match one to one with glfw window instances + YaveWindow(const YaveWindow &) = delete; + YaveWindow &operator=(const YaveWindow &) = delete; - bool shouldClose() { return glfwWindowShouldClose(window); } + // Initialiser and destructor + YaveWindow(int w, int h, std::string name); + ~YaveWindow(); + // Tell apllicaton that the user has attempted to close the window + bool shouldClose() { return glfwWindowShouldClose(window); } }; -} +} // namespace yave