Going further into the vulkan tutorial. :( Wish I didn't need it

This commit is contained in:
Warwick 2023-11-14 15:05:06 +00:00
parent 191aa7350d
commit 3a4030ad89
7 changed files with 65 additions and 18 deletions

View file

@ -1,3 +1,3 @@
#!/bin/bash #!/bin/bash
glslc shaders/shader.vert -o shaders/shader.vert.spv 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

Binary file not shown.

View file

@ -4,7 +4,7 @@
namespace yave { namespace yave {
void Application::run() { void Application::run() {
yaveVulkanInstance VI = yaveVulkanInstance(); YaveVulkanInstance VI = YaveVulkanInstance();
while (!yaveWindow.shouldClose()) { while (!yaveWindow.shouldClose()) {
glfwPollEvents(); glfwPollEvents();

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "yave_window.hpp" #include "yave_window.hpp"
#include "yave_graphics_pipeline.hpp"
namespace yave { namespace yave {
class Application { class Application {
@ -12,6 +13,7 @@ class Application {
private: private:
YaveWindow yaveWindow{WIDTH, HEIGHT, "Hello Vulkan!"}; YaveWindow yaveWindow{WIDTH, HEIGHT, "Hello Vulkan!"};
YaveGrPipeline yavePipeline{"shaders/shader.vert.spv","shaders/shader.frag.spv"};
}; };
} // namespace yave } // namespace yave

View file

@ -0,0 +1,34 @@
#include "yave_graphics_pipeline.hpp"
#include <cstddef>
#include <fstream>
#include <vector>
namespace yave {
YaveGrPipeline::YaveGrPipeline(const std::string &vertFilepath,
const std::string &fragFilepath) {
createGraphicsPipeline(vertFilepath, fragFilepath);
}
std::vector<char> 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<size_t>(file.tellg());
std::vector<char> 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

View file

@ -1,15 +1,20 @@
#pragma once #pragma once
#include<string> #include <string>
#include <vector>
namespace yave { namespace yave {
class YaveGrPipeline { class YaveGrPipeline {
public: public:
YaveGrPipeline(const std::string& vertFilepath, const std::string& fragFilepath); YaveGrPipeline(const std::string &vertFilepath,
const std::string &fragFilepath);
private: private:
static std::vector<char> readFile(const std::string &filepath);
void createGraphicsPipeline(const std::string &vertFilepath,
const std::string &fragFilepath);
}; };
} // namespace yave } // namespace yave

View file

@ -8,7 +8,7 @@
namespace yave { namespace yave {
class YaveWindow { class YaveWindow {
private: private:
GLFWwindow *window; GLFWwindow *window;
void initWindow(); void initWindow();
@ -17,12 +17,18 @@ class YaveWindow {
const int height; const int height;
std::string windowName; std::string windowName;
public: public:
// Delete Copy constructors
// This class should match one to one with glfw window instances
YaveWindow(const YaveWindow &) = delete;
YaveWindow &operator=(const YaveWindow &) = delete;
// Initialiser and destructor
YaveWindow(int w, int h, std::string name); YaveWindow(int w, int h, std::string name);
~YaveWindow(); ~YaveWindow();
// Tell apllicaton that the user has attempted to close the window
bool shouldClose() { return glfwWindowShouldClose(window); } bool shouldClose() { return glfwWindowShouldClose(window); }
}; };
} } // namespace yave