20 #ifndef _STELQGLGLSLSHADER_HPP_
21 #define _STELQGLGLSLSHADER_HPP_
24 #include <QGLShaderProgram>
28 #include "StelGLSLShader.hpp"
29 #include "StelGLUtilityFunctions.hpp"
33 typedef float RAW_GL_MATRIX [4][4];
77 UniformType_float = 1,
97 static const unsigned int UNIFORM_STORAGE = 512;
100 static const int MAX_UNIFORMS = 32;
105 static int UNIFORM_SIZES[UniformType_max];
119 Q_ASSERT_X(!
bound, Q_FUNC_INFO,
120 "Forgot to release() a bound shader before destroying");
131 virtual bool build();
133 virtual QString
log()
const
146 state = State_Unlocked;
151 virtual bool addVertexShader(
const QString& name,
const QString& source);
161 "Trying to enable a vertex shader with an unknown name");
162 Q_ASSERT_X(
state == State_Unlocked ||
state == State_Modified, Q_FUNC_INFO,
163 "Can't enable a vertex shader after the shader has been built");
166 if(shader.enabled) {
return;}
167 shader.enabled =
true;
168 state = State_Modified;
174 "Trying to disable a vertex shader with an unknown name");
175 Q_ASSERT_X(
state == State_Unlocked ||
state == State_Modified, Q_FUNC_INFO,
176 "Can't disable a vertex shader after the shader has been built");
179 if(!shader.enabled) {
return;}
180 shader.enabled =
false;
181 state = State_Modified;
199 Q_FUNC_INFO,
"Trying to use an unbound shader for drawing");
217 Q_ASSERT_X(
bound &&
state == State_Built, Q_FUNC_INFO,
218 "uploadUniforms called on a shader that is not bound");
222 const UniformType type =
static_cast<UniformType
>(
uniformTypes[u]);
225 case UniformType_float:
227 const float& value(*reinterpret_cast<const float* const>(data));
231 case UniformType_vec2:
233 const Vec2f& v(*reinterpret_cast<const Vec2f* const>(data));
237 case UniformType_vec3:
239 const Vec3f& v(*reinterpret_cast<const Vec3f* const>(data));
243 case UniformType_vec4:
245 const Vec4f& v(*reinterpret_cast<const Vec4f* const>(data));
249 case UniformType_mat4:
251 const RAW_GL_MATRIX& m(*reinterpret_cast<const RAW_GL_MATRIX* const>(data));
255 case UniformType_bool:
257 const bool& value(*reinterpret_cast<const bool* const>(data));
261 case UniformType_int:
263 const int& value(*reinterpret_cast<const int* const>(data));
268 Q_ASSERT_X(
false, Q_FUNC_INFO,
"Unknown or invalid uniform type");
270 data += UNIFORM_SIZES[type];
293 Q_ASSERT_X(
bound &&
state == State_Built, Q_FUNC_INFO,
294 "pushUniformStorage() called when the shader is not bound");
296 "Too many uniform storage stack pushes");
307 Q_ASSERT_X(
bound &&
state == State_Built, Q_FUNC_INFO,
308 "popUniformStorage() called when the shader is not bound");
310 "Too many uniform storage stack pops (nothing left to pop)");
322 Q_ASSERT_X(
bound &&
state == State_Built, Q_FUNC_INFO,
323 "clearUniforms() called when the shader is not bound");
434 Q_ASSERT_X(
bound, Q_FUNC_INFO,
435 "Trying to set a uniform value with an unbound shader");
436 Q_ASSERT_X(
uniformCount < MAX_UNIFORMS, Q_FUNC_INFO,
"Too many uniforms");
438 "Uniform storage exceeded");
448 Q_ASSERT_X(
bound, Q_FUNC_INFO,
449 "Trying to set a uniform value with an unbound shader");
450 Q_ASSERT_X(
uniformCount < MAX_UNIFORMS, Q_FUNC_INFO,
"Too many uniforms");
452 "Uniform storage exceeded");
463 Q_ASSERT_X(
bound, Q_FUNC_INFO,
464 "Trying to set a uniform value with an unbound shader");
465 Q_ASSERT_X(
uniformCount < MAX_UNIFORMS, Q_FUNC_INFO,
"Too many uniforms");
467 "Uniform storage exceeded");
478 Q_ASSERT_X(
bound, Q_FUNC_INFO,
479 "Trying to set a uniform value with an unbound shader");
480 Q_ASSERT_X(
uniformCount < MAX_UNIFORMS, Q_FUNC_INFO,
"Too many uniforms");
483 "Uniform storage exceeded");
493 Q_ASSERT_X(
bound, Q_FUNC_INFO,
494 "Trying to set a uniform value with an unbound shader");
495 Q_ASSERT_X(
uniformCount < MAX_UNIFORMS, Q_FUNC_INFO,
"Too many uniforms");
497 "Uniform storage exceeded");
508 Q_ASSERT_X(
bound, Q_FUNC_INFO,
509 "Trying to set a uniform value with an unbound shader");
510 Q_ASSERT_X(
uniformCount < MAX_UNIFORMS, Q_FUNC_INFO,
"Too many uniforms");
512 "Uniform storage exceeded");
523 Q_ASSERT_X(
bound, Q_FUNC_INFO,
524 "Trying to set a uniform value with an unbound shader");
525 Q_ASSERT_X(
uniformCount < MAX_UNIFORMS, Q_FUNC_INFO,
"Too many uniforms");
527 "Uniform storage exceeded");
542 QGLShaderProgram* getProgramFromCache();
549 QGLShader* createVertexShader(
const QString& source);
552 #endif // _STELQGLGLSLSHADER_HPP_