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 47d2768..0000000 Binary files a/shaders/shader.vert.spv and /dev/null differ 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