63 virtual void setUniform(GLint location)
const = 0;
64 virtual void setAttrib(GLuint location)
const = 0;
65 virtual QTextStream& read(QTextStream& s) = 0;
66 virtual QTextStream& write(QTextStream& s)
const = 0;
67 virtual std::istream& read(std::istream& s) = 0;
68 virtual std::ostream& write(std::ostream& s)
const = 0;
69 virtual Value* copy() = 0;
72 template <
typename T>
class ValueImpl :
public Value {
74 typedef typename T::value_type value_type;
75 typedef void (*uniform_fct)(GLint, GLsizei,
const value_type*);
76 typedef void (*attrib_fct)(GLuint,
const value_type*);
78 ValueImpl(uniform_fct ufct, attrib_fct afct,
const T* v,
int count)
82 , glVertexAttrib(afct)
86 ValueImpl(uniform_fct ufct, attrib_fct afct)
89 , glVertexAttrib(afct)
93 ValueImpl(
const ValueImpl& copy)
96 , glUniform(copy.glUniform)
97 , glVertexAttrib(copy.glVertexAttrib)
101 virtual Value* copy() {
102 return new ValueImpl(*
this);
105 virtual void setUniform(GLint location)
const {
106 glUniform(location, (GLint)value.size(), value[0].c_data());
108 virtual void setAttrib(GLuint location)
const {
109 glVertexAttrib(location, value[0].c_data());
111 virtual QTextStream& read(QTextStream& s)
117 virtual QTextStream& write(QTextStream& s)
const
122 virtual std::istream& read(std::istream& s)
128 virtual std::ostream& write(std::ostream& s)
const
133 std::vector<T> value;
134 uniform_fct glUniform;
135 attrib_fct glVertexAttrib;
152 value = copy.value->copy();
155 template <
typename T>
162 template <
typename T>
169 template <
typename T>
173 setValue(val, count);
184 value = copy.value->copy();
189 value->setUniform(location);
192 value->setAttrib(location);
194 std::istream& read(std::istream& s);
195 std::ostream& write(std::ostream& s)
const;
196 QTextStream& read(QTextStream& s);
197 QTextStream& write(QTextStream& s)
const;
199 void setValue(
const GLint* value,
int count);
200 void setValue(
const ivec1* value,
int count);
201 void setValue(
const ivec2* value,
int count);
202 void setValue(
const ivec3* value,
int count);
203 void setValue(
const ivec4* value,
int count);
204 void setValue(
const GLfloat* value,
int count);
205 void setValue(
const vec1* value,
int count);
206 void setValue(
const vec2* value,
int count);
207 void setValue(
const vec3* value,
int count);
208 void setValue(
const vec4* value,
int count);
209 void setValue(
const mat2* value,
int count);
210 void setValue(
const mat3* value,
int count);
211 void setValue(
const mat4* value,
int count);
295 Shader(
int verbosity = 1);
298 glfuncs->glActiveTexture(at + GL_TEXTURE0);
302 glfuncs->glActiveTexture(at + GL_TEXTURE0);
307 _initialized =
false;
314 static bool stopUsingShaders();
317 return vertex_shaders_code[pos].second;
321 return fragment_shaders_code[pos].second;
325 return vertex_shaders_code[pos].first;
329 return fragment_shaders_code[pos].first;
332 void addVertexShaderCode(
const QString& code);
333 bool changeVertexShaderCode(
int pos,
const QString& code);
334 void removeVertexShaderCode(
const QString& code);
335 void addFragmentShaderCode(
const QString& code);
336 bool changeFragmentShaderCode(
int pos,
const QString& code);
337 void removeFragmentShaderCode(
const QString& code);
339 void addVertexShader(
const QString& filename);
340 bool changeVertexShader(
int pos,
const QString& filename);
341 void removeVertexShader(
const QString& filename);
342 void addFragmentShader(
const QString& filename);
343 bool changeFragmentShader(
int pos,
const QString& filename);
344 void removeFragmentShader(
const QString& filename);
349 QString shaderTypeName(GLenum shader_type);
351 GLuint compileShaderFile(GLenum shader_type, QString filename);
352 GLuint compileShader(GLenum shader_type, QString content);
354 void printProgramInfoLog(GLuint
object);
355 void printShaderInfoLog(GLuint
object);
366 void setupUniforms();
368 GLuint attribLocation(
const QString& name);
370 void setAttrib(
const QString& name,
const GLSLValue& value);
371 void setAttrib(GLuint loc,
const GLSLValue& value);
373 bool setUniform(
const QString& name,
const GLSLValue& value);
374 void setUniform_instant(
const QString& name,
const GLSLValue& value);
381 void loadUniform(GLint program,
const QString& name,
const GLSLValue& value);