wren
Vulkan-based game engine
Toggle main menu visibility
Loading...
Searching...
No Matches
shader.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <filesystem>
4
#include <map>
5
#include <memory>
6
#include <string>
7
#include <vulkan/vulkan.hpp>
8
#include <vulkan/vulkan_enums.hpp>
9
#include <vulkan/vulkan_handles.hpp>
10
#include <vulkan/vulkan_structs.hpp>
11
#include <
wren/math/vector.hpp
>
12
#include <
wren/utils/result.hpp
>
13
14
namespace
spv_reflect
{
15
class
ShaderModule;
16
}
17
18
namespace
wren::reflect
{
19
using
spirv_t
= std::vector<uint32_t>;
20
}
21
22
namespace
wren::vk
{
23
24
BOOST_DEFINE_ENUM
(ShaderType,
Vertex
, Fragment);
25
26
class
ShaderModule
{
27
public
:
28
ShaderModule
() =
default
;
29
ShaderModule
(
reflect::spirv_t
spirv, const ::vk::ShaderModule&
module
);
30
31
[[nodiscard]]
auto
module
() const -> ::
vk
::
ShaderModule
{
return
module_
; }
32
33
[[nodiscard]]
auto
get_vertex_input_bindings
() const
34
-> std::vector<::
vk
::VertexInputBindingDescription>;
35
36
[[nodiscard]] auto
get_vertex_input_attributes
() const
37
-> std::vector<::
vk
::VertexInputAttributeDescription>;
38
39
[[nodiscard]] auto
get_descriptor_set_layout_bindings
() const
40
-> std::vector<::
vk
::DescriptorSetLayoutBinding>;
41
42
private:
43
reflect
::spirv_t
spirv_
;
44
::
vk
::
ShaderModule
module_
;
45
std::shared_ptr<
spv_reflect
::
ShaderModule
>
reflection_
;
46
};
47
48
class
Shader
{
49
public
:
50
using
Ptr
= std::shared_ptr<Shader>;
51
52
static
auto
create
(const ::vk::Device& device,
53
const
std::string&
vertex_shader
,
54
const
std::string&
fragment_shader
) ->
expected<Ptr>
;
55
56
static
auto
create
(const ::vk::Device& device,
57
const
std::filesystem::path& shader_path) ->
expected<Ptr>
;
58
59
[[nodiscard]]
auto
get_pipeline
()
const
{
return
pipeline_
; }
60
[[nodiscard]]
auto
pipeline_layout
()
const
{
return
pipeline_layout_
; }
61
[[nodiscard]]
auto
descriptor_layout
()
const
{
return
descriptor_layout_
; }
62
63
void
fragment_shader
(
const
ShaderModule
& fragment) {
64
fragment_shader_module_
= fragment;
65
}
66
67
void
vertex_shader
(
const
ShaderModule
& vertex) {
68
vertex_shader_module_
= vertex;
69
}
70
71
auto
create_graphics_pipeline
(const ::vk::Device& device,
72
const ::vk::RenderPass& render_pass,
73
const
math::Vec2f
& size,
bool
depth)
74
->
expected<void>
;
75
76
private
:
77
static
auto
read_wren_shader_file
(
const
std::filesystem::path& path)
78
->
expected<std::map<ShaderType, std::string>
>;
79
80
::vk::DescriptorSetLayout
descriptor_layout_
;
81
::vk::PipelineLayout
pipeline_layout_
;
82
::vk::Pipeline
pipeline_
;
83
84
ShaderModule
vertex_shader_module_
;
85
ShaderModule
fragment_shader_module_
;
86
};
87
88
}
// namespace wren::vk
wren::vk::ShaderModule
Definition
shader.hpp:26
wren::vk::ShaderModule::ShaderModule
ShaderModule()=default
wren::vk::ShaderModule::reflection_
std::shared_ptr< spv_reflect::ShaderModule > reflection_
Definition
shader.hpp:45
wren::vk::ShaderModule::module_
::vk::ShaderModule module_
Definition
shader.hpp:44
wren::vk::ShaderModule::module
auto module() const -> ::vk::ShaderModule
Definition
shader.hpp:31
wren::vk::ShaderModule::ShaderModule
ShaderModule(reflect::spirv_t spirv, const ::vk::ShaderModule &module)
wren::vk::ShaderModule::get_vertex_input_bindings
auto get_vertex_input_bindings() const -> std::vector<::vk::VertexInputBindingDescription >
wren::vk::ShaderModule::get_vertex_input_attributes
auto get_vertex_input_attributes() const -> std::vector<::vk::VertexInputAttributeDescription >
wren::vk::ShaderModule::spirv_
reflect::spirv_t spirv_
Definition
shader.hpp:43
wren::vk::ShaderModule::get_descriptor_set_layout_bindings
auto get_descriptor_set_layout_bindings() const -> std::vector<::vk::DescriptorSetLayoutBinding >
wren::vk::Shader
Definition
shader.hpp:48
wren::vk::Shader::create
static auto create(const ::vk::Device &device, const std::filesystem::path &shader_path) -> expected< Ptr >
wren::vk::Shader::descriptor_layout_
::vk::DescriptorSetLayout descriptor_layout_
Definition
shader.hpp:80
wren::vk::Shader::pipeline_layout_
::vk::PipelineLayout pipeline_layout_
Definition
shader.hpp:81
wren::vk::Shader::get_pipeline
auto get_pipeline() const
Definition
shader.hpp:59
wren::vk::Shader::fragment_shader
void fragment_shader(const ShaderModule &fragment)
Definition
shader.hpp:63
wren::vk::Shader::vertex_shader_module_
ShaderModule vertex_shader_module_
Definition
shader.hpp:84
wren::vk::Shader::fragment_shader_module_
ShaderModule fragment_shader_module_
Definition
shader.hpp:85
wren::vk::Shader::pipeline_layout
auto pipeline_layout() const
Definition
shader.hpp:60
wren::vk::Shader::create
static auto create(const ::vk::Device &device, const std::string &vertex_shader, const std::string &fragment_shader) -> expected< Ptr >
wren::vk::Shader::descriptor_layout
auto descriptor_layout() const
Definition
shader.hpp:61
wren::vk::Shader::Ptr
std::shared_ptr< Shader > Ptr
Definition
shader.hpp:50
wren::vk::Shader::read_wren_shader_file
static auto read_wren_shader_file(const std::filesystem::path &path) -> expected< std::map< ShaderType, std::string > >
wren::vk::Shader::pipeline_
::vk::Pipeline pipeline_
Definition
shader.hpp:82
wren::vk::Shader::create_graphics_pipeline
auto create_graphics_pipeline(const ::vk::Device &device, const ::vk::RenderPass &render_pass, const math::Vec2f &size, bool depth) -> expected< void >
wren::vk::Shader::vertex_shader
void vertex_shader(const ShaderModule &vertex)
Definition
shader.hpp:67
spv_reflect
Definition
shader.hpp:14
vk
Definition
ui.hpp:5
wren::reflect
Definition
reflect.hpp:25
wren::reflect::spirv_t
std::vector< uint32_t > spirv_t
Definition
shader.hpp:19
wren::vk
Definition
render_pass.hpp:19
wren::vk::BOOST_DEFINE_ENUM
BOOST_DEFINE_ENUM(ShaderType, Vertex, Fragment)
wren::expected
std::expected< T, Err > expected
Definition
result.hpp:43
wren::Vertex
Definition
mesh.hpp:20
wren::math::Vec2f
Definition
vector.hpp:161
vector.hpp
result.hpp
wren_vk
include
wren
vk
shader.hpp
Generated by
1.17.0