TDME2  1.9.200
PostProcessingShader.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 #include <unordered_map>
5 
6 #include <tdme/tdme.h>
16 #include <tdme/engine/Engine.h>
17 
18 using std::string;
19 using std::unordered_map;
20 
32 
33 PostProcessingShader::PostProcessingShader(Renderer* renderer)
34 {
42  implementation = nullptr;
43 }
44 
46 {
47  for (const auto& [shaderId, shader]: shaders) {
48  delete shader;
49  }
50 }
51 
53 {
54  auto initialized = true;
55  for (const auto& [shaderId, shader]: shaders) {
56  initialized&= shader->isInitialized();
57  }
58  return initialized;
59 }
60 
62 {
63  for (const auto& [shaderId, shader]: shaders) {
64  shader->initialize();
65  }
66 }
67 
69 {
70  for (const auto& [shaderId, shader]: shaders) {
71  shader->unloadTextures();
72  }
73 }
74 
76 {
77  running = true;
78 }
79 
81 {
82  running = false;
83  if (implementation != nullptr) {
85  }
86  implementation = nullptr;
87 }
88 
89 bool PostProcessingShader::hasShader(const string& id) {
90  return shaders.find(id) != shaders.end();
91 }
92 
93 void PostProcessingShader::setShader(int contextIdx, const string& id) {
94  if (running == false) return;
95 
96  auto currentImplementation = implementation;
97  auto shaderIt = shaders.find(id);
98  if (shaderIt == shaders.end()) {
99  shaderIt = shaders.find("default");
100  }
101  implementation = shaderIt->second;
102 
103  if (currentImplementation != implementation) {
104  if (currentImplementation != nullptr) currentImplementation->unUseProgram();
105  implementation->useProgram(contextIdx);
106  }
107 }
108 
109 void PostProcessingShader::setBufferPixelWidth(int contextIdx, float pixelWidth) {
110  if (implementation == nullptr) return;
111  implementation->setBufferPixelWidth(contextIdx, pixelWidth);
112 }
113 
114 void PostProcessingShader::setBufferPixelHeight(int contextIdx, float pixelHeight) {
115  if (implementation == nullptr) return;
116  implementation->setBufferPixelHeight(contextIdx, pixelHeight);
117 }
118 
119 void PostProcessingShader::setShaderParameters(int contextIdx, Engine* engine) {
120  if (implementation == nullptr) return;
121  implementation->setShaderParameters(contextIdx, engine);
122 }
123 
124 void PostProcessingShader::loadTextures(const string& pathName) {
125  for (const auto& [shaderId, shader]: shaders) {
126  shader->unloadTextures();
127  shader->loadTextures(pathName);
128  }
129 }
Engine main class.
Definition: Engine.h:131
static bool isSupported(Renderer *renderer)
Returns if shader is supported on given renderer.
static bool isSupported(Renderer *renderer)
Returns if shader is supported on given renderer.
static bool isSupported(Renderer *renderer)
Returns if shader is supported on given renderer.
static bool isSupported(Renderer *renderer)
Returns if shader is supported on given renderer.
static bool isSupported(Renderer *renderer)
Returns if shader is supported on given renderer.
static bool isSupported(Renderer *renderer)
Returns if shader is supported on given renderer.
void setShader(int contextIdx, const string &id)
Set post processing shader.
void setBufferPixelWidth(int contextIdx, float pixelWidth)
Set source buffer pixel width.
unordered_map< string, PostProcessingShaderImplementation * > shaders
bool hasShader(const string &id)
Has post processing shader.
void setShaderParameters(int contextIdx, Engine *engine)
Set shader parameters.
void setBufferPixelHeight(int contextIdx, float pixelHeight)
Set source buffer pixel height.
virtual void setShaderParameters(int contextIdx, Engine *engine)=0
Set shader parameters.
virtual void setBufferPixelHeight(int contextIdx, float pixelHeight)=0
Set source buffer pixel height.
virtual void setBufferPixelWidth(int contextIdx, float pixelWidth)=0
Set source buffer pixel width.