52 #include <ACG/GL/acg_glew.hh> 53 #include <ACG/GL/GLError.hh> 54 #include "UniformPool.hh" 58 #define snprintf sprintf_s 88 for (UniformListIt it =
pool_.begin(); it !=
pool_.end(); ++it)
112 for (UniformList::const_iterator it =
pool_.begin(); it !=
pool_.end(); ++it) {
124 for (UniformListIt it =
pool_.begin(); it !=
pool_.end(); ++it){
125 if ((*it)->id.compare(_name) == 0)
138 for (UniformList::const_iterator it = _src.
pool_.begin(); it != _src.
pool_.end(); ++it){
161 addBuf(pBuf->id.c_str(), pBuf->val, pBuf->size, pBuf->integer);
171 checkGLError2(
"prev opengl error");
172 GLint location = glGetUniformLocation(_progID,
id.c_str());
173 checkGLError2(
id.c_str());
177 glUniform1fv(location, 1, val.data());
180 glUniform2fv(location, 1, val.data());
183 glUniform3fv(location, 1, val.data());
186 glUniform4fv(location, 1, val.data());
190 std::cerr <<
"UniformPool::UniformVecf : invalid size " << size << std::endl;
194 checkGLError2(
id.c_str());
202 checkGLError2(
"prev opengl error");
203 GLint location = glGetUniformLocation(_progID,
id.c_str());
204 checkGLError2(
id.c_str());
208 glUniform1iv(location, 1, (GLint*)val.data());
211 glUniform2iv(location, 1, (GLint*)val.data());
214 glUniform3iv(location, 1, (GLint*)val.data());
217 glUniform4iv(location, 1, (GLint*)val.data());
221 std::cerr <<
"UniformPool::UniformVeci : invalid size " << size << std::endl;
225 checkGLError2(
id.c_str());
233 checkGLError2(
"prev opengl error");
234 GLint location = glGetUniformLocation(_progID,
id.c_str());
235 checkGLError2(
id.c_str());
239 glUniform1uiv(location, 1, (GLuint*)val.data());
242 glUniform2uiv(location, 1, (GLuint*)val.data());
245 glUniform3uiv(location, 1, (GLuint*)val.data());
248 glUniform4uiv(location, 1, (GLuint*)val.data());
252 std::cerr <<
"UniformPool::UniformVecui : invalid size " << size << std::endl;
256 checkGLError2(
id.c_str());
264 checkGLError2(
"prev opengl error");
265 GLint location = glGetUniformLocation(_progID,
id.c_str());
266 checkGLError2(
id.c_str());
271 for (
int i = 0; i < 2; ++i)
272 for (
int k = 0; k < 2; ++k)
273 tmp[i*2+k] = val.data()[i*4+k];
274 glUniformMatrix2fv(location, 1, transposed, tmp);
279 for (
int i = 0; i < 3; ++i)
280 for (
int k = 0; k < 3; ++k)
281 tmp[i*3+k] = val.data()[i*4+k];
282 glUniformMatrix3fv(location, 1, transposed, tmp);
285 case 4: glUniformMatrix4fv(location, 1, transposed, val.data());
break;
288 std::cerr <<
"UniformPool::UniformMat : invalid size " << size << std::endl;
292 checkGLError2(
id.c_str());
300 checkGLError2(
"prev opengl error");
301 GLint location = glGetUniformLocation(_progID,
id.c_str());
302 checkGLError2(
id.c_str());
305 glUniform1iv(location, size, (GLint*)val);
308 glUniform1fv(location, size, val);
311 checkGLError2(
id.c_str());
318 : val(0), integer(false), size(0)
340 if ( it ==
pool_.end() ){
343 pool_.push_back(dst);
350 std::cerr <<
"UniformPool::addVecf type of " << _vec.id <<
" incorrect." << std::endl;
356 dst->size = _vec.size;
373 if ( it ==
pool_.end() ){
376 pool_.push_back(dst);
383 std::cerr <<
"UniformPool::addVeci type of " << _vec.id <<
" incorrect." << std::endl;
389 dst->size = _vec.size;
406 if ( it ==
pool_.end() ){
409 pool_.push_back(dst);
416 std::cerr <<
"UniformPool::addVecui type of " << _vec.id <<
" incorrect." << std::endl;
422 dst->size = _vec.size;
439 if ( it ==
pool_.end() ){
442 pool_.push_back(dst);
449 std::cerr <<
"UniformPool::addMatrix type of " << _mat.id <<
" incorrect." << std::endl;
455 dst->size = _mat.size;
456 dst->transposed = _mat.transposed;
475 if ( it ==
pool_.end() ){
478 pool_.push_back(dst);
485 std::cerr <<
"UniformPool::addBuf type of " << _name <<
" incorrect." << std::endl;
492 if (dst->size < _count)
496 dst->val =
new float[_count];
502 memcpy(dst->val, _values, _count *
sizeof(
float));
533 tmp.val[0] = _value[0];
534 tmp.val[1] = _value[1];
550 tmp.val[0] = _value[0];
551 tmp.val[1] = _value[1];
552 tmp.val[2] = _value[2];
600 tmp.val[0] = _value[0];
601 tmp.val[1] = _value[1];
617 tmp.val[0] = _value[0];
618 tmp.val[1] = _value[1];
619 tmp.val[2] = _value[2];
668 tmp.val[0] = _value[0];
669 tmp.val[1] = _value[1];
685 tmp.val[0] = _value[0];
686 tmp.val[1] = _value[1];
687 tmp.val[2] = _value[2];
719 tmp.transposed = _transposed;
737 tmp.transposed = _transposed;
753 addBuf(_name, _values, _count,
true);
764 addBuf(_name, _values, _count,
false);
void addVeci(const UniformVeci &_vec)
Add or update a vector type uniform in pool.
void addMatrix(const UniformMat &_mat)
Add or update a matrix type uniform in pool.
void addPool(const UniformPool &_src)
Add all uniforms of a pool to this pool.
void bind(GLuint _progID) const
Bind uniform float vector to shader.
void addBuf(const char *_name, void *_values, int _count, bool _integer)
Add or update an array type uniform in pool.
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
void setUniformMat3(const char *_name, const ACG::GLMatrixf &_value, bool _transposed=false)
Set 3x3fMatrix uniform to specified value.
void bind(PtrProgram _prog) const
Send all stored uniforms to program.
void addVecui(const UniformVecui &_vec)
Add or update a vector type uniform in pool.
void bind(GLuint _progID) const
Bind uniform uint vector to shader.
UniformListIt findEntry(std::string _name)
Search the pool for an existing value for a uniform name.
void bind(GLuint _progID) const
Bind uniform int vector to shader.
bool empty() const
returns if the pool is empty
UniformBuf()
Creates a copy of input data.
void bind(GLuint _progID) const
Bind uniform array to shader.
void clear()
Clear the pool.
void addVecf(const UniformVecf &_vec)
Add or update a vector type uniform in pool.
virtual ~UniformPool()
Destructor.
This namespace contains all the classes and functions for handling GLSL shader and program objects...
UniformList pool_
list of uniform params
UniformPool()
Constructor.
void bind(GLuint _progID) const
Bind uniform matrix to shader.
GLuint getProgramId()
Returns opengl id.