vengine  0.1.0
3D graphics engine made with Vulkan
Loading...
Searching...
No Matches
Shaders.hpp
Go to the documentation of this file.
1///
2/// @file Shaders.hpp
3/// @brief This file contains the Shader class
4/// @namespace ven
5///
6
7#pragma once
8
9#include <string>
10
11#include <vulkan/vulkan.h>
12#include <glm/glm.hpp>
13
14#include "VEngine/Device.hpp"
15#include "VEngine/Model.hpp"
16
17namespace ven {
18
20 PipelineConfigInfo() = default;
23
24 std::vector<VkVertexInputBindingDescription> bindingDescriptions;
25 std::vector<VkVertexInputAttributeDescription> attributeDescriptions;
26 VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo{};
27 VkPipelineRasterizationStateCreateInfo rasterizationInfo{};
28 VkPipelineMultisampleStateCreateInfo multisampleInfo{};
29 VkPipelineColorBlendAttachmentState colorBlendAttachment{};
30 VkPipelineColorBlendStateCreateInfo colorBlendInfo{};
31 VkPipelineDepthStencilStateCreateInfo depthStencilInfo{};
32 std::vector<VkDynamicState> dynamicStateEnables;
33 VkPipelineDynamicStateCreateInfo dynamicStateInfo{};
34 VkPipelineLayout pipelineLayout = nullptr;
35 VkRenderPass renderPass = nullptr;
36 uint32_t subpass = 0;
37 };
38
39 class Shaders {
40
41 public:
42
43 Shaders(Device &device, const std::string& vertFilepath, const std::string& fragFilepath, const PipelineConfigInfo& configInfo) : m_device{device} { createGraphicsPipeline(vertFilepath, fragFilepath, configInfo); };
44 ~Shaders();
45
46 Shaders(const Shaders&) = delete;
47 Shaders& operator=(const Shaders&) = delete;
48
49 static void defaultPipelineConfigInfo(PipelineConfigInfo& configInfo);
50 void bind(const VkCommandBuffer commandBuffer) const { vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_graphicsPipeline); }
51
52 private:
53
54 static std::vector<char> readFile(const std::string &filename);
55 void createGraphicsPipeline(const std::string& vertFilepath, const std::string& fragFilepath, const PipelineConfigInfo& configInfo);
56 void createShaderModule(const std::vector<char>& code, VkShaderModule* shaderModule) const;
57
59 VkPipeline m_graphicsPipeline{nullptr};
60 VkShaderModule m_vertShaderModule{nullptr};
61 VkShaderModule m_fragShaderModule{nullptr};
62
63 }; // class Shaders
64
65} // namespace ven
This file contains the Device class.
This file contains the Model class.
VkPipeline m_graphicsPipeline
Definition Shaders.hpp:59
void createGraphicsPipeline(const std::string &vertFilepath, const std::string &fragFilepath, const PipelineConfigInfo &configInfo)
Definition shaders.cpp:31
Device & m_device
Definition Shaders.hpp:58
Shaders(Device &device, const std::string &vertFilepath, const std::string &fragFilepath, const PipelineConfigInfo &configInfo)
Definition Shaders.hpp:43
static std::vector< char > readFile(const std::string &filename)
Definition shaders.cpp:13
void createShaderModule(const std::vector< char > &code, VkShaderModule *shaderModule) const
Definition shaders.cpp:100
static void defaultPipelineConfigInfo(PipelineConfigInfo &configInfo)
Definition shaders.cpp:112
Shaders(const Shaders &)=delete
Shaders & operator=(const Shaders &)=delete
void bind(const VkCommandBuffer commandBuffer) const
Definition Shaders.hpp:50
VkShaderModule m_vertShaderModule
Definition Shaders.hpp:60
VkShaderModule m_fragShaderModule
Definition Shaders.hpp:61
std::vector< VkDynamicState > dynamicStateEnables
Definition Shaders.hpp:32
PipelineConfigInfo(const PipelineConfigInfo &)=delete
std::vector< VkVertexInputBindingDescription > bindingDescriptions
Definition Shaders.hpp:24
VkPipelineDepthStencilStateCreateInfo depthStencilInfo
Definition Shaders.hpp:31
VkPipelineRasterizationStateCreateInfo rasterizationInfo
Definition Shaders.hpp:27
std::vector< VkVertexInputAttributeDescription > attributeDescriptions
Definition Shaders.hpp:25
VkPipelineColorBlendAttachmentState colorBlendAttachment
Definition Shaders.hpp:29
VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo
Definition Shaders.hpp:26
VkPipelineMultisampleStateCreateInfo multisampleInfo
Definition Shaders.hpp:28
VkPipelineColorBlendStateCreateInfo colorBlendInfo
Definition Shaders.hpp:30
PipelineConfigInfo & operator=(const PipelineConfigInfo &)=delete
VkPipelineDynamicStateCreateInfo dynamicStateInfo
Definition Shaders.hpp:33
VkRenderPass renderPass
Definition Shaders.hpp:35
VkPipelineLayout pipelineLayout
Definition Shaders.hpp:34