vengine  0.0.1
3D graphics engine
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
10
11namespace ven {
12
13 static constexpr std::string_view SHADERS_BIN_PATH = "build/shaders/";
14
16 PipelineConfigInfo() = default;
19
20 std::vector<VkVertexInputBindingDescription> bindingDescriptions;
21 std::vector<VkVertexInputAttributeDescription> attributeDescriptions;
22 VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo{};
23 VkPipelineRasterizationStateCreateInfo rasterizationInfo{};
24 VkPipelineMultisampleStateCreateInfo multisampleInfo{};
25 VkPipelineColorBlendAttachmentState colorBlendAttachment{};
26 VkPipelineColorBlendStateCreateInfo colorBlendInfo{};
27 VkPipelineDepthStencilStateCreateInfo depthStencilInfo{};
28 std::vector<VkDynamicState> dynamicStateEnables;
29 VkPipelineDynamicStateCreateInfo dynamicStateInfo{};
30 VkPipelineLayout pipelineLayout = nullptr;
31 VkRenderPass renderPass = nullptr;
32 uint32_t subpass = 0;
33 };
34
35 ///
36 /// @class Shaders
37 /// @brief Class for shaders
38 /// @namespace ven
39 ///
40 class Shaders {
41
42 public:
43
44 Shaders(Device &device, const std::string& vertFilepath, const std::string& fragFilepath, const PipelineConfigInfo& configInfo) : m_device{device} { createGraphicsPipeline(vertFilepath, fragFilepath, configInfo); };
45 ~Shaders();
46
47 Shaders(const Shaders&) = delete;
48 Shaders& operator=(const Shaders&) = delete;
49 Shaders(Shaders&&) = delete;
51
52 static void defaultPipelineConfigInfo(PipelineConfigInfo& configInfo);
53 void bind(const VkCommandBuffer commandBuffer) const { vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_graphicsPipeline); }
54
55 private:
56
57 static std::vector<char> readFile(const std::string &filename);
58 void createGraphicsPipeline(const std::string& vertFilepath, const std::string& fragFilepath, const PipelineConfigInfo& configInfo);
59 void createShaderModule(const std::vector<char>& code, VkShaderModule* shaderModule) const;
60
62 VkPipeline m_graphicsPipeline{nullptr};
63 VkShaderModule m_vertShaderModule{nullptr};
64 VkShaderModule m_fragShaderModule{nullptr};
65
66 }; // class Shaders
67
68} // namespace ven
This file contains the Device class.
Class for device.
Definition Device.hpp:35
Class for shaders.
Definition Shaders.hpp:40
Shaders & operator=(Shaders &&)=delete
VkPipeline m_graphicsPipeline
Definition Shaders.hpp:62
void createGraphicsPipeline(const std::string &vertFilepath, const std::string &fragFilepath, const PipelineConfigInfo &configInfo)
Definition shaders.cpp:27
Device & m_device
Definition Shaders.hpp:61
Shaders(Device &device, const std::string &vertFilepath, const std::string &fragFilepath, const PipelineConfigInfo &configInfo)
Definition Shaders.hpp:44
static std::vector< char > readFile(const std::string &filename)
Definition shaders.cpp:14
void createShaderModule(const std::vector< char > &code, VkShaderModule *shaderModule) const
Definition shaders.cpp:96
static void defaultPipelineConfigInfo(PipelineConfigInfo &configInfo)
Definition shaders.cpp:108
Shaders(const Shaders &)=delete
Shaders & operator=(const Shaders &)=delete
void bind(const VkCommandBuffer commandBuffer) const
Definition Shaders.hpp:53
VkShaderModule m_vertShaderModule
Definition Shaders.hpp:63
Shaders(Shaders &&)=delete
VkShaderModule m_fragShaderModule
Definition Shaders.hpp:64
static constexpr std::string_view SHADERS_BIN_PATH
Definition Shaders.hpp:13
std::vector< VkDynamicState > dynamicStateEnables
Definition Shaders.hpp:28
PipelineConfigInfo(const PipelineConfigInfo &)=delete
std::vector< VkVertexInputBindingDescription > bindingDescriptions
Definition Shaders.hpp:20
VkPipelineDepthStencilStateCreateInfo depthStencilInfo
Definition Shaders.hpp:27
VkPipelineRasterizationStateCreateInfo rasterizationInfo
Definition Shaders.hpp:23
std::vector< VkVertexInputAttributeDescription > attributeDescriptions
Definition Shaders.hpp:21
VkPipelineColorBlendAttachmentState colorBlendAttachment
Definition Shaders.hpp:25
VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo
Definition Shaders.hpp:22
VkPipelineMultisampleStateCreateInfo multisampleInfo
Definition Shaders.hpp:24
VkPipelineColorBlendStateCreateInfo colorBlendInfo
Definition Shaders.hpp:26
PipelineConfigInfo & operator=(const PipelineConfigInfo &)=delete
VkPipelineDynamicStateCreateInfo dynamicStateInfo
Definition Shaders.hpp:29
VkRenderPass renderPass
Definition Shaders.hpp:31
VkPipelineLayout pipelineLayout
Definition Shaders.hpp:30