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
32 std::unordered_map<std::set<ShaderMacro>, std::shared_ptr<Shader>, ShaderMacroSetHash>
34 };
35
36 ShaderPack() = delete;
37 ShaderPack(const ShaderPack&) = delete;
38 ShaderPack& operator=(const ShaderPack&) = delete;
39
40 virtual ~ShaderPack() = default;
41
52 static std::variant<std::shared_ptr<ShaderPack>, std::string, Error>
53 compileShaderPack(Renderer* pRenderer, const ShaderDescription& shaderDescription);
54
67 static std::variant<std::shared_ptr<ShaderPack>, Error> createFromCache(
68 Renderer* pRenderer,
69 const ShaderDescription& shaderDescription,
70 std::optional<ShaderCacheInvalidationReason>& cacheInvalidationReason);
71
81
92 std::shared_ptr<Shader> getShader(const std::set<ShaderMacro>& shaderConfiguration);
93
99 std::string getShaderName() const;
100
106 ShaderType getShaderType();
107
113 std::pair<std::mutex, InternalResources>* getInternalResources();
114
115 private:
124 ShaderDescription& description,
125 const std::set<ShaderMacro>& shaderConfigurationMacros,
126 Renderer* pRenderer);
127
134 ShaderPack(const std::string& sShaderName, ShaderType shaderType);
135
137 std::pair<std::mutex, InternalResources> mtxInternalResources;
138
140 std::string sShaderName;
141
143 ShaderType shaderType;
144 };
145} // namespace ne
Definition: Error.h:27
Definition: Renderer.h:43
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:137
bool releaseShaderPackDataFromMemoryIfLoaded()
Definition: ShaderPack.cpp:154
std::string getShaderName() const
Definition: ShaderPack.cpp:186
ShaderType shaderType
Definition: ShaderPack.h:143
std::shared_ptr< Shader > getShader(const std::set< ShaderMacro > &shaderConfiguration)
Definition: ShaderPack.cpp:167
std::string sShaderName
Definition: ShaderPack.h:140
ShaderType getShaderType()
Definition: ShaderPack.cpp:188
std::pair< std::mutex, InternalResources > * getInternalResources()
Definition: ShaderPack.cpp:190
static void addEngineMacrosToShaderDescription(ShaderDescription &description, const std::set< ShaderMacro > &shaderConfigurationMacros, Renderer *pRenderer)
Definition: ShaderPack.cpp:194
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:198
Definition: ShaderPack.h:28
std::unordered_map< std::set< ShaderMacro >, std::shared_ptr< Shader >, ShaderMacroSetHash > shadersInPack
Definition: ShaderPack.h:33