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
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 {
void Application::run() {
yaveVulkanInstance VI = yaveVulkanInstance();
YaveVulkanInstance VI = YaveVulkanInstance();
while (!yaveWindow.shouldClose()) {
glfwPollEvents();

View file

@ -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

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
#include<string>
#include <string>
#include <vector>
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<char> readFile(const std::string &filepath);
void createGraphicsPipeline(const std::string &vertFilepath,
const std::string &fragFilepath);
};
} // namespace yave

View file

@ -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