Nameless Engine
Loading...
Searching...
No Matches
ShaderPack.h
1#pragma once
2
3// Standard.
4#include <mutex>
5#include <unordered_map>
6#include <memory>
7#include <optional>
8#include <string>
9
10// Custom.
11#include "shader/ShaderDescription.h"
12#include "shader/general/ShaderMacro.h"
13
14namespace ne {
15 class Renderer;
16 class Shader;
17
22 class ShaderPack {
23 // Shader manager can change shader pack configuration (to tell what shader should be currently used).
24 friend class ShaderManager;
25
26 public:
29 InternalResources() = default;
30
33
35 std::set<ShaderMacro> renderConfiguration;
36
38 std::unordered_map<std::set<ShaderMacro>, std::shared_ptr<Shader>, ShaderMacroSetHash>
40 };
41
42 ShaderPack() = delete;
43 ShaderPack(const ShaderPack&) = delete;
44 ShaderPack& operator=(const ShaderPack&) = delete;
45
46 virtual ~ShaderPack() = default;
47
58 static std::variant<std::shared_ptr<ShaderPack>, std::string, Error>
59 compileShaderPack(Renderer* pRenderer, const ShaderDescription& shaderDescription);
60
73 static std::variant<std::shared_ptr<ShaderPack>, Error> createFromCache(
74 Renderer* pRenderer,
75 const ShaderDescription& shaderDescription,
76 std::optional<ShaderCacheInvalidationReason>& cacheInvalidationReason);
77
87
113 std::shared_ptr<Shader> getShader(
114 const std::set<ShaderMacro>& additionalConfiguration,
115 std::set<ShaderMacro>& fullShaderConfiguration);
116
122 std::string getShaderName() const;
123
129 ShaderType getShaderType();
130
136 std::pair<std::mutex, InternalResources>* getInternalResources();
137
138 private:
147 ShaderDescription& description,
148 const std::set<ShaderMacro>& shaderConfigurationMacros,
149 Renderer* pRenderer);
150
157 ShaderPack(const std::string& sShaderName, ShaderType shaderType);
158
169 void setRendererConfiguration(const std::set<ShaderMacro>& renderConfiguration);
170
172 std::pair<std::mutex, InternalResources> mtxInternalResources;
173
175 std::string sShaderName;
176
178 ShaderType shaderType;
179 };
180} // namespace ne
Definition: Error.h:27
Definition: Renderer.h:39
Definition: ShaderManager.h:25
Definition: ShaderPack.h:22
static std::variant< std::shared_ptr< ShaderPack >, std::string, Error > compileShaderPack(Renderer *pRenderer, const ShaderDescription &shaderDescription)
Definition: ShaderPack.cpp:96
std::pair< std::mutex, InternalResources > mtxInternalResources
Definition: ShaderPack.h:172
bool releaseShaderPackDataFromMemoryIfLoaded()
Definition: ShaderPack.cpp:171
std::string getShaderName() const
Definition: ShaderPack.cpp:242
ShaderType shaderType
Definition: ShaderPack.h:178
void setRendererConfiguration(const std::set< ShaderMacro > &renderConfiguration)
Definition: ShaderPack.cpp:154
std::string sShaderName
Definition: ShaderPack.h:175
ShaderType getShaderType()
Definition: ShaderPack.cpp:244
std::shared_ptr< Shader > getShader(const std::set< ShaderMacro > &additionalConfiguration, std::set< ShaderMacro > &fullShaderConfiguration)
Definition: ShaderPack.cpp:184
std::pair< std::mutex, InternalResources > * getInternalResources()
Definition: ShaderPack.cpp:246
static void addEngineMacrosToShaderDescription(ShaderDescription &description, const std::set< ShaderMacro > &shaderConfigurationMacros, Renderer *pRenderer)
Definition: ShaderPack.cpp:250
static std::variant< std::shared_ptr< ShaderPack >, Error > createFromCache(Renderer *pRenderer, const ShaderDescription &shaderDescription, std::optional< ShaderCacheInvalidationReason > &cacheInvalidationReason)
Definition: ShaderPack.cpp:15
Definition: ShaderDescription.h:74
Definition: ShaderMacro.h:196
Definition: ShaderPack.h:28
std::set< ShaderMacro > renderConfiguration
Definition: ShaderPack.h:35
std::unordered_map< std::set< ShaderMacro >, std::shared_ptr< Shader >, ShaderMacroSetHash > shadersInPack
Definition: ShaderPack.h:39
bool bIsRenderConfigurationSet
Definition: ShaderPack.h:32