-
Notifications
You must be signed in to change notification settings - Fork 47
/
Doom3ShaderSystem.h
161 lines (115 loc) · 4.87 KB
/
Doom3ShaderSystem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#pragma once
#include "ishaders.h"
#include "ifilesystem.h"
#include "imodule.h"
#include "iradiant.h"
#include "icommandsystem.h"
#include <functional>
#include "ShaderLibrary.h"
#include "ShaderFileLoader.h"
#include "TableDefinition.h"
#include "textures/GLTextureManager.h"
namespace shaders
{
/**
* \brief
* Implementation of the MaterialManager for Doom 3 .
*/
class Doom3ShaderSystem :
public MaterialManager,
public vfs::VirtualFileSystem::Observer
{
// The shaderlibrary stores all the known shaderdefinitions
// as well as the active shaders
ShaderLibraryPtr _library;
#if 0
// The ShaderFileLoader will provide a new ShaderLibrary once complete
std::unique_ptr<ShaderFileLoader> _defLoader;
#endif
// The manager that handles the texture caching.
GLTextureManagerPtr _textureManager;
// Active shaders list changed signal
sigc::signal<void> _signalActiveShadersChanged;
// Flag to indicate whether the active shaders callback should be invoked
bool _enableActiveUpdates;
// TRUE if the material files have been parsed
bool _realised;
// Signals for module subscribers
sigc::signal<void> _signalDefsLoaded;
sigc::signal<void> _signalDefsUnloaded;
sigc::signal<void, const std::string&> _sigMaterialCreated;
sigc::signal<void, const std::string&, const std::string&> _sigMaterialRenamed;
sigc::signal<void, const std::string&> _sigMaterialRemoved;
public:
// Constructor, allocates the library
Doom3ShaderSystem();
// Gets called on initialise
void onFileSystemInitialise() override;
// Gets called on shutdown
void onFileSystemShutdown() override;
// greebo: This parses the material files and emits the defs loaded signal
void realise() override;
// greebo: Emits the defs unloaded signal and frees the shaders
void unrealise() override;
// Flushes the shaders from memory and reloads the material files
void refresh() override;
// Is the shader system realised
bool isRealised() override;
sigc::signal<void>& signal_DefsLoaded() override;
sigc::signal<void>& signal_DefsUnloaded() override;
sigc::signal<void, const std::string&>& signal_materialCreated() override;
sigc::signal<void, const std::string&, const std::string&>& signal_materialRenamed() override;
sigc::signal<void, const std::string&>& signal_materialRemoved() override;
// Return a shader by name
MaterialPtr getMaterial(const std::string& name) override;
bool materialExists(const std::string& name) override;
bool materialCanBeModified(const std::string& name) override;
void foreachShaderName(const ShaderNameCallback& callback) override;
void activeShadersChangedNotify();
// Enable or disable the active shaders callback
void setActiveShaderUpdates(bool v) override {
_enableActiveUpdates = v;
}
void setLightingEnabled(bool enabled) override;
const char* getTexturePrefix() const override;
/**
* greebo: Traverse all shaders using the given visitor class.
*/
void foreachMaterial(const std::function<void(const MaterialPtr&)>& func) override;
/* greebo: Loads an image from disk and creates a basic shader
* object out of it (i.e. only diffuse and editor image are non-empty).
*/
TexturePtr loadTextureFromFile(const std::string& filename) override;
GLTextureManager& getTextureManager();
// Get default textures for D,B,S layers
TexturePtr getDefaultInteractionTexture(IShaderLayer::Type t) override;
IShaderExpression::Ptr createShaderExpressionFromString(const std::string& exprStr) override;
MaterialPtr createEmptyMaterial(const std::string& name) override;
MaterialPtr copyMaterial(const std::string& nameOfOriginal, const std::string& nameOfCopy) override;
bool renameMaterial(const std::string& oldName, const std::string& newName) override;
void removeMaterial(const std::string& name) override;
void saveMaterial(const std::string& name) override;
// Look up a table def, return NULL if not found
ITableDefinition::Ptr getTable(const std::string& name);
public:
sigc::signal<void> signal_activeShadersChanged() const override;
// RegisterableModule implementation
const std::string& getName() const override;
const StringSet& getDependencies() const override;
void initialiseModule(const IApplicationContext& ctx) override;
void shutdownModule() override;
private:
// This attaches this class as Observer to the Filesystem
void construct();
void destroy();
// For methods accessing the ShaderLibrary the parser thread must be done
void ensureDefsLoaded();
// Unloads all the existing shaders and calls activeShadersChangedNotify()
void freeShaders();
void testShaderExpressionParsing();
std::string ensureNonConflictingName(const std::string& name);
};
typedef std::shared_ptr<Doom3ShaderSystem> Doom3ShaderSystemPtr;
Doom3ShaderSystemPtr GetShaderSystem();
GLTextureManager& GetTextureManager();
} // namespace shaders