52 #include <ACG/GL/acg_glew.hh>
53 #include <ACG/GL/GLError.hh>
54 #include "UniformPool.hh"
58 #define snprintf sprintf_s
93 for (UniformListIt it =
pool_.begin(); it !=
pool_.end(); ++it)
101 return pool_.empty();
117 for (UniformList::const_iterator it =
pool_.begin(); it !=
pool_.end(); ++it) {
129 for (UniformListIt it =
pool_.begin(); it !=
pool_.end(); ++it){
130 if ((*it)->id.compare(_name) == 0)
143 for (UniformList::const_iterator it = _src.
pool_.begin(); it != _src.
pool_.end(); ++it){
166 addBuf(pBuf->id.c_str(), pBuf->val, pBuf->size, pBuf->integer);
176 checkGLError2(
"prev opengl error");
177 GLint location = glGetUniformLocation(_progID,
id.c_str());
178 checkGLError2(
id.c_str());
182 glUniform1fv(location, 1, val.data());
185 glUniform2fv(location, 1, val.data());
188 glUniform3fv(location, 1, val.data());
191 glUniform4fv(location, 1, val.data());
195 std::cerr <<
"UniformPool::UniformVecf : invalid size " << size << std::endl;
199 checkGLError2(
id.c_str());
207 checkGLError2(
"prev opengl error");
208 GLint location = glGetUniformLocation(_progID,
id.c_str());
209 checkGLError2(
id.c_str());
213 glUniform1iv(location, 1, (GLint*)val.data());
216 glUniform2iv(location, 1, (GLint*)val.data());
219 glUniform3iv(location, 1, (GLint*)val.data());
222 glUniform4iv(location, 1, (GLint*)val.data());
226 std::cerr <<
"UniformPool::UniformVeci : invalid size " << size << std::endl;
230 checkGLError2(
id.c_str());
238 checkGLError2(
"prev opengl error");
239 GLint location = glGetUniformLocation(_progID,
id.c_str());
240 checkGLError2(
id.c_str());
244 glUniform1uiv(location, 1, (GLuint*)val.data());
247 glUniform2uiv(location, 1, (GLuint*)val.data());
250 glUniform3uiv(location, 1, (GLuint*)val.data());
253 glUniform4uiv(location, 1, (GLuint*)val.data());
257 std::cerr <<
"UniformPool::UniformVecui : invalid size " << size << std::endl;
261 checkGLError2(
id.c_str());
269 checkGLError2(
"prev opengl error");
270 GLint location = glGetUniformLocation(_progID,
id.c_str());
271 checkGLError2(
id.c_str());
276 for (
int i = 0; i < 2; ++i)
277 for (
int k = 0; k < 2; ++k)
278 tmp[i*2+k] = val.data()[i*4+k];
279 glUniformMatrix2fv(location, 1, transposed, tmp);
284 for (
int i = 0; i < 3; ++i)
285 for (
int k = 0; k < 3; ++k)
286 tmp[i*3+k] = val.data()[i*4+k];
287 glUniformMatrix3fv(location, 1, transposed, tmp);
290 case 4: glUniformMatrix4fv(location, 1, transposed, val.data());
break;
293 std::cerr <<
"UniformPool::UniformMat : invalid size " << size << std::endl;
297 checkGLError2(
id.c_str());
305 checkGLError2(
"prev opengl error");
306 GLint location = glGetUniformLocation(_progID,
id.c_str());
307 checkGLError2(
id.c_str());
310 glUniform1iv(location, size, (GLint*)val);
313 glUniform1fv(location, size, val);
316 checkGLError2(
id.c_str());
322 : val(0), integer(false), size(0)
344 if ( it ==
pool_.end() ){
347 pool_.push_back(dst);
354 std::cerr <<
"UniformPool::addVecf type of " << _vec.id <<
" incorrect." << std::endl;
360 dst->size = _vec.size;
377 if ( it ==
pool_.end() ){
380 pool_.push_back(dst);
387 std::cerr <<
"UniformPool::addVeci type of " << _vec.id <<
" incorrect." << std::endl;
393 dst->size = _vec.size;
410 if ( it ==
pool_.end() ){
413 pool_.push_back(dst);
420 std::cerr <<
"UniformPool::addVecui type of " << _vec.id <<
" incorrect." << std::endl;
426 dst->size = _vec.size;
443 if ( it ==
pool_.end() ){
446 pool_.push_back(dst);
453 std::cerr <<
"UniformPool::addMatrix type of " << _mat.id <<
" incorrect." << std::endl;
459 dst->size = _mat.size;
460 dst->transposed = _mat.transposed;
479 if ( it ==
pool_.end() ){
482 pool_.push_back(dst);
489 std::cerr <<
"UniformPool::addBuf type of " << _name <<
" incorrect." << std::endl;
496 if (dst->size < _count)
500 dst->val =
new float[_count];
506 memcpy(dst->val, _values, _count *
sizeof(
float));
537 tmp.val[0] = _value[0];
538 tmp.val[1] = _value[1];
554 tmp.val[0] = _value[0];
555 tmp.val[1] = _value[1];
556 tmp.val[2] = _value[2];
604 tmp.val[0] = _value[0];
605 tmp.val[1] = _value[1];
621 tmp.val[0] = _value[0];
622 tmp.val[1] = _value[1];
623 tmp.val[2] = _value[2];
672 tmp.val[0] = _value[0];
673 tmp.val[1] = _value[1];
689 tmp.val[0] = _value[0];
690 tmp.val[1] = _value[1];
691 tmp.val[2] = _value[2];
723 tmp.transposed = _transposed;
741 tmp.transposed = _transposed;
757 addBuf(_name, _values, _count,
true);
768 addBuf(_name, _values, _count,
false);
void addVeci(const UniformVeci &_vec)
Add or update a vector type uniform in pool.
UniformList pool_
list of uniform params
void clear()
Clear the pool.
void bind(GLuint _progID) const
Bind uniform float vector to shader.
void bind(GLuint _progID) const
Bind uniform matrix to shader.
bool empty() const
returns if the pool is empty
void bind(GLuint _progID) const
Bind uniform uint vector to shader.
void addVecui(const UniformVecui &_vec)
Add or update a vector type uniform in pool.
void bind(GLuint _progID) const
Bind uniform array to shader.
virtual ~UniformPool()
Destructor.
void operator=(const UniformPool &_other)
copy
void addMatrix(const UniformMat &_mat)
Add or update a matrix type uniform in pool.
void bind(GLuint _progID) const
Bind uniform int vector to shader.
void addPool(const UniformPool &_src)
Add all uniforms of a pool to this pool.
UniformListIt findEntry(std::string _name)
Search the pool for an existing value for a uniform name.
void setUniformMat3(const char *_name, const ACG::GLMatrixf &_value, bool _transposed=false)
Set 3x3fMatrix uniform to specified value.
This namespace contains all the classes and functions for handling GLSL shader and program objects...
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
UniformBuf()
Creates a copy of input data.
void addBuf(const char *_name, void *_values, int _count, bool _integer)
Add or update an array type uniform in pool.
void bind(PtrProgram _prog) const
Send all stored uniforms to program.
UniformPool()
Constructor.
GLuint getProgramId()
Returns opengl id.
void addVecf(const UniformVecf &_vec)
Add or update a vector type uniform in pool.