Lugdunum  0.1.0
Pipeline.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cstdint>
4 #include <functional>
5 #include <string>
6 #include <vector>
7 
13 
14 namespace lug {
15 namespace Graphics {
16 
17 namespace Vulkan {
18 
19 class Renderer;
20 
21 namespace Render {
22 
27 public:
33  struct Id {
37  struct PrimitivePart {
38  union {
39  struct {
40  uint32_t positionVertexData : 1;
41  uint32_t normalVertexData : 1;
42  uint32_t tangentVertexData : 1;
43  uint32_t countTexCoord : 2;
44  uint32_t countColor : 2;
45  uint32_t primitiveMode : 3;
46  };
47 
48  uint32_t value;
49  };
50 
51  explicit operator uint32_t() {
52  return value;
53  }
54  };
55 
61  struct MaterialPart {
62  union {
63  struct {
64  uint32_t baseColorInfo : 2;
65  uint32_t metallicRoughnessInfo : 2;
66  uint32_t normalInfo : 2;
67  uint32_t occlusionInfo : 2;
68  uint32_t emissiveInfo : 2;
69  };
70 
71  uint32_t value;
72  };
73 
74  explicit operator uint32_t() {
75  return value;
76  }
77  };
78 
79  struct ExtraPart {
80  union {
81  struct {
82  uint32_t displayMode : 3;
83  uint32_t irradianceMapInfo : 1;
84  uint32_t prefilteredMapInfo : 1;
85  };
86 
87  uint32_t value;
88  };
89 
90  explicit operator uint32_t() {
91  return value;
92  }
93  };
94 
95  union {
96  struct {
97  uint32_t primitivePart : 10;
98  uint32_t materialPart : 10;
99  uint32_t extraPart : 5;
100  };
101 
102  uint32_t value;
103  };
104 
105  Id(uint32_t id = 0): value(id) {}
106 
107  explicit operator uint32_t() const {
108  return value;
109  }
110 
111  explicit operator bool() const {
112  return value != 0;
113  }
114 
115  bool operator==(const Id& other) const {
116  return value == other.value;
117  }
118 
119  bool operator!=(const Id& other) const {
120  return value != other.value;
121  }
122 
123  bool operator<(const Id& other) const {
124  return value < other.value;
125  }
126 
128  PrimitivePart tmp;
129  tmp.value = primitivePart;
130  return tmp;
131  }
132 
134  MaterialPart tmp;
135  tmp.value = materialPart;
136  return tmp;
137  }
138 
140  ExtraPart tmp;
141  tmp.value = extraPart;
142  return tmp;
143  }
144 
154  static Id create(PrimitivePart primitivePart, MaterialPart materialPart, ExtraPart extraPart) {
155  Id id;
156 
157  id.primitivePart = static_cast<uint32_t>(primitivePart);
158  id.materialPart = static_cast<uint32_t>(materialPart);
159  id.extraPart = static_cast<uint32_t>(extraPart);
160 
161  return id;
162  };
163  };
164 
165 public:
167  public:
168  enum class Type : uint8_t {
169  Vertex,
170  Fragment
171  };
172 
173  public:
174  ShaderBuilder() = delete;
175 
176  ShaderBuilder(const ShaderBuilder&) = delete;
177  ShaderBuilder(ShaderBuilder&&) = delete;
178 
179  ShaderBuilder& operator=(const ShaderBuilder&) = delete;
180  ShaderBuilder& operator=(ShaderBuilder&&) = delete;
181 
182  ~ShaderBuilder() = delete;
183 
184  public:
185  static std::vector<uint32_t> buildShader(std::string shaderRoot, ::lug::Graphics::Render::Technique::Type technique, Type type, Pipeline::Id id);
186  static std::vector<uint32_t> buildShaderFromFile(std::string filename, Type type, Pipeline::Id id);
187  static std::vector<uint32_t> buildShaderFromString(std::string filename, std::string content, Type type, Pipeline::Id id);
188  };
189 
190 public:
191  Pipeline(Renderer& renderer, Id id);
192 
193  Pipeline(const Pipeline&) = delete;
194  Pipeline(Pipeline&&) = delete;
195 
196  Pipeline& operator=(const Pipeline&) = delete;
197  Pipeline& operator=(Pipeline&&) = delete;
198 
199  ~Pipeline() = default;
200 
206  Id getId() const;
207  static inline Id getBaseId();
208 
209  const API::GraphicsPipeline& getPipelineAPI();
210 
211  static Resource::SharedPtr<Pipeline> create(Renderer& renderer, Id id);
212 
213 private:
214  bool init();
215 
216 private:
219 
221 };
222 
224 
225 } // Render
226 } // Vulkan
227 } // Graphics
228 } // lug
229 
230 // Make Pipeline Id hashable like a uint32_t
231 namespace std {
232  template<> struct hash<lug::Graphics::Vulkan::Render::Pipeline::Id> {
234  return hash<uint32_t>()(id.value);
235  }
236  };
237 }
Id of the Pipeline. It&#39;s a concatenation of three parts: PrimitivePart, MaterialPart and PipelinePart...
Definition: Pipeline.hpp:33
Describes the material. How is the material composed, with textures, no textures, etc...
Definition: Pipeline.hpp:61
uint32_t occlusionInfo
0b00 texture with UV0, 0b01 texture with UV1, 0b10 texture with UV2, 0b11 no texture.
Definition: Pipeline.hpp:67
uint32_t countColor
The number of colors (maximum 3).
Definition: Pipeline.hpp:44
uint32_t baseColorInfo
0b00 texture with UV0, 0b01 texture with UV1, 0b10 texture with UV2, 0b11 no texture.
Definition: Pipeline.hpp:64
size_t operator()(const lug::Graphics::Vulkan::Render::Pipeline::Id &id) const
Definition: Pipeline.hpp:233
uint32_t positionVertexData
0 if no attribute position.
Definition: Pipeline.hpp:40
#define LUG_GRAPHICS_API
Definition: Export.hpp:11
Dummy class for a shared pointer.
Definition: Resource.hpp:66
bool operator==(const Id &other) const
Definition: Pipeline.hpp:115
static Id create(PrimitivePart primitivePart, MaterialPart materialPart, ExtraPart extraPart)
Create a pipeline id.
Definition: Pipeline.hpp:154
Class for resource.
Definition: Resource.hpp:17
uint32_t irradianceMapInfo
1 texture, 0 no texture.
Definition: Pipeline.hpp:83
uint32_t displayMode
Corresponding to the value in Renderer::DisplayMode.
Definition: Pipeline.hpp:82
uint32_t emissiveInfo
0b00 texture with UV0, 0b01 texture with UV1, 0b10 texture with UV2, 0b11 no texture.
Definition: Pipeline.hpp:68
bool operator!=(const Id &other) const
Definition: Pipeline.hpp:119
uint32_t normalVertexData
0 if no attribute normal.
Definition: Pipeline.hpp:41
uint32_t metallicRoughnessInfo
0b00 texture with UV0, 0b01 texture with UV1, 0b10 texture with UV2, 0b11 no texture.
Definition: Pipeline.hpp:65
uint32_t prefilteredMapInfo
1 texture, 0 no texture
Definition: Pipeline.hpp:84
uint32_t normalInfo
0b00 texture with UV0, 0b01 texture with UV1, 0b10 texture with UV2, 0b11 no texture.
Definition: Pipeline.hpp:66
uint32_t tangentVertexData
0 if no attribute tangeant.
Definition: Pipeline.hpp:42
bool operator<(const Id &other) const
Definition: Pipeline.hpp:123
Class for the Vulkan pipeline, Render side.
Definition: Pipeline.hpp:26
uint32_t countTexCoord
The number of texcoord (maximum 3).
Definition: Pipeline.hpp:43