/
Doom3ShaderSystem.h
162 lines (114 loc) · 4.58 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
162
#pragma once
#include "ishaders.h"
#include "ifilesystem.h"
#include "imodule.h"
#include "iradiant.h"
#include "icommandsystem.h"
#include <functional>
#include "moduleobservers.h"
#include "ShaderLibrary.h"
#include "TableDefinition.h"
#include "textures/GLTextureManager.h"
#include "ThreadedDefLoader.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;
// The ShaderFileLoader will provide a new ShaderLibrary once complete
util::ThreadedDefLoader<ShaderLibraryPtr> _defLoader;
// 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;
// The observers that are attached to this system. These get
// notified upon realisation of this class.
ModuleObservers _observers;
// Signals for module subscribers
sigc::signal<void> _signalDefsLoaded;
sigc::signal<void> _signalDefsUnloaded;
// Used to provide feedback to the user during long operations
ILongRunningOperation* _currentOperation;
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 calls realise() on any
// attached moduleobservers
void realise() override;
// greebo: Unrealises the attached ModuleObservers 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;
// Return a shader by name
MaterialPtr getMaterialForName(const std::string& name) override;
bool materialExists(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 attach(ModuleObserver& observer) override;
void detach(ModuleObserver& observer) override;
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(ShaderLayer::Type t) override;
IShaderExpressionPtr createShaderExpressionFromString(const std::string& exprStr) override;
// Look up a table def, return NULL if not found
TableDefinitionPtr getTableForName(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 ApplicationContext& ctx) override;
void shutdownModule() override;
private:
// This attaches this class as ModuleObserver to the Filesystem
void construct();
void destroy();
// For methods accessing the ShaderLibrary the parser thread must be done
void ensureDefsLoaded();
// The "Flush & Reload Shaders" command target
void refreshShadersCmd(const cmd::ArgumentList& args);
// Unloads all the existing shaders and calls activeShadersChangedNotify()
void freeShaders();
/** Load the shader definitions from the MTR files
* (doesn't load any textures yet). */
ShaderLibraryPtr loadMaterialFiles();
void testShaderExpressionParsing();
}; // class Doom3ShaderSystem
typedef std::shared_ptr<Doom3ShaderSystem> Doom3ShaderSystemPtr;
Doom3ShaderSystemPtr GetShaderSystem();
GLTextureManager& GetTextureManager();
} // namespace shaders