TDME2  1.9.200
LightingShader.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <unordered_map>
5 #include <vector>
6 
7 #include <tdme/tdme.h>
8 #include <tdme/engine/fwd-tdme.h>
11 
12 using std::string;
13 using std::unordered_map;
14 using std::vector;
15 
19 
20 /**
21  * Interface to lighting shader program
22  * @author Andreas Drewke
23  */
25 {
26 private:
29  };
30  unordered_map<string, LightingShaderImplementation*> shaders;
31  Renderer* renderer { nullptr };
32  Engine* engine { nullptr };
33  bool running { false };
34  vector<LightingShaderContext> contexts;
35 
36 public:
37  // forbid class copy
39 
40  /**
41  * Public constructor
42  * @param renderer renderer
43  */
45 
46  /**
47  * Destructor
48  */
50 
51  /**
52  * @return initialized and ready to be used
53  */
54  bool isInitialized();
55 
56  /**
57  * Initialize
58  */
59  void initialize();
60 
61  /**
62  * Dispose
63  */
64  void dispose();
65 
66  /**
67  * Use lighting program
68  * @param engine engine
69  */
70  void useProgram(Engine* engine);
71 
72  /**
73  * Unuse lighting program
74  */
75  void unUseProgram();
76 
77  /**
78  * Update effect to program
79  * @param contextIdx context index
80  */
81  void updateEffect(int contextIdx);
82 
83  /**
84  * Update material to program
85  * @param contextIdx context index
86  */
87  void updateMaterial(int contextIdx);
88 
89  /**
90  * Update light to program
91  * @param contextIdx context index
92  * @param lightId light id
93  */
94  void updateLight(int contextIdx, int32_t lightId);
95 
96  /**
97  * Update matrices to program
98  * @param contextIdx context index
99  */
100  void updateMatrices(int contextIdx);
101 
102  /**
103  * Update texture matrix to program
104  * @param contextIdx context index
105  */
106  void updateTextureMatrix(int contextIdx);
107 
108  /**
109  * Update shader parameters
110  * @param context
111  */
112  void updateShaderParameters(int contextIdx);
113 
114  /**
115  * Set shader
116  * @param contextIdx context index
117  * @param id id
118  */
119  void setShader(int contextIdx, const string& id);
120 
121  /**
122  * Bind texture
123  * @param contextIdx context index
124  * @param textureId texture id
125  */
126  void bindTexture(int contextIdx, int32_t textureId);
127 
128  /**
129  * Returns if shader with given shader id does exist
130  * @param shaderId shader id
131  * @return if shader exists
132  */
133  bool hasShader(const string& shaderId) {
134  return shaders.find(shaderId) != shaders.end();
135  }
136 
137  /**
138  * Returns shader for given shader id
139  * @param shaderId shader id
140  * @return if shader exists
141  */
142  LightingShaderImplementation* getShader(const string& shaderId) {
143  auto shaderIt = shaders.find(shaderId);
144  if (shaderIt == shaders.end()) return nullptr;
145  return shaderIt->second;
146  }
147 
148  /**
149  * Unload textures
150  * @param pathName path name
151  */
153 
154  /**
155  * Load textures
156  * @param pathName path name
157  */
158  void loadTextures(const string& pathName);
159 
160 };
Engine main class.
Definition: Engine.h:131
Interface to lighting shader program.
LightingShaderImplementation * getShader(const string &shaderId)
Returns shader for given shader id.
void updateLight(int contextIdx, int32_t lightId)
Update light to program.
void updateMatrices(int contextIdx)
Update matrices to program.
void updateEffect(int contextIdx)
Update effect to program.
bool hasShader(const string &shaderId)
Returns if shader with given shader id does exist.
void useProgram(Engine *engine)
Use lighting program.
void setShader(int contextIdx, const string &id)
Set shader.
void updateTextureMatrix(int contextIdx)
Update texture matrix to program.
void updateShaderParameters(int contextIdx)
Update shader parameters.
LightingShader(Renderer *renderer)
Public constructor.
void updateMaterial(int contextIdx)
Update material to program.
void bindTexture(int contextIdx, int32_t textureId)
Bind texture.
void loadTextures(const string &pathName)
Load textures.
unordered_map< string, LightingShaderImplementation * > shaders
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6