44 #include <QTextStream> 46 #include <ACG/GL/acg_glew.hh> 47 #include <ACG/GL/GLError.hh> 48 #include "UniformPool.hh" 52 #define snprintf sprintf_s 88 for (UniformListIt it =
pool_.begin(); it !=
pool_.end(); ++it)
103 QTextStream resultStrm(&result);
105 for (UniformList::const_iterator it =
pool_.begin(); it !=
pool_.end(); ++it) {
106 resultStrm << (*it)->toString() <<
"\n";
125 for (UniformList::const_iterator it =
pool_.begin(); it !=
pool_.end(); ++it) {
137 for (UniformListIt it =
pool_.begin(); it !=
pool_.end(); ++it){
138 if ((*it)->id.compare(_name) == 0)
151 for (UniformList::const_iterator it = _src.
pool_.begin(); it != _src.
pool_.end(); ++it){
174 addBuf(pBuf->id.c_str(), pBuf->val, pBuf->size, pBuf->integer);
184 checkGLError2(
"prev opengl error");
185 GLint location = glGetUniformLocation(_progID,
id.c_str());
186 checkGLError2(
id.c_str());
190 glUniform1fv(location, 1, val.data());
193 glUniform2fv(location, 1, val.data());
196 glUniform3fv(location, 1, val.data());
199 glUniform4fv(location, 1, val.data());
203 std::cerr <<
"UniformPool::UniformVecf : invalid size " << size << std::endl;
207 checkGLError2(
id.c_str());
215 const char* fmt = size > 1 ?
"uniform vec%2 %1 = vec%2(" :
"uniform float %1 = ";
216 QString str = QString(fmt).arg(
id.c_str()).arg(size);
217 for (
int i = 0; i < size; ++i) {
218 str += QString::number(val[i]);
232 checkGLError2(
"prev opengl error");
233 GLint location = glGetUniformLocation(_progID,
id.c_str());
234 checkGLError2(
id.c_str());
238 glUniform1iv(location, 1, (GLint*)val.data());
241 glUniform2iv(location, 1, (GLint*)val.data());
244 glUniform3iv(location, 1, (GLint*)val.data());
247 glUniform4iv(location, 1, (GLint*)val.data());
251 std::cerr <<
"UniformPool::UniformVeci : invalid size " << size << std::endl;
255 checkGLError2(
id.c_str());
263 const char* fmt = size > 1 ?
"uniform ivec%2 %1 = ivec%2(" :
"uniform int %1 = ";
264 QString str = QString(fmt).arg(
id.c_str()).arg(size);
265 for (
int i = 0; i < size; ++i) {
266 str += QString::number(val[i]);
280 checkGLError2(
"prev opengl error");
281 GLint location = glGetUniformLocation(_progID,
id.c_str());
282 checkGLError2(
id.c_str());
286 glUniform1uiv(location, 1, (GLuint*)val.data());
289 glUniform2uiv(location, 1, (GLuint*)val.data());
292 glUniform3uiv(location, 1, (GLuint*)val.data());
295 glUniform4uiv(location, 1, (GLuint*)val.data());
299 std::cerr <<
"UniformPool::UniformVecui : invalid size " << size << std::endl;
303 checkGLError2(
id.c_str());
311 const char* fmt = size > 1 ?
"uniform uvec%2 %1 = uvec%2(" :
"uniform uint %1 = ";
312 QString str = QString(fmt).arg(
id.c_str()).arg(size);
313 for (
int i = 0; i < size; ++i) {
314 str += QString::number(val[i]);
328 checkGLError2(
"prev opengl error");
329 GLint location = glGetUniformLocation(_progID,
id.c_str());
330 checkGLError2(
id.c_str());
335 for (
int i = 0; i < 2; ++i)
336 for (
int k = 0; k < 2; ++k)
337 tmp[i*2+k] = val.data()[i*4+k];
338 glUniformMatrix2fv(location, 1, transposed, tmp);
343 for (
int i = 0; i < 3; ++i)
344 for (
int k = 0; k < 3; ++k)
345 tmp[i*3+k] = val.data()[i*4+k];
346 glUniformMatrix3fv(location, 1, transposed, tmp);
349 case 4: glUniformMatrix4fv(location, 1, transposed, val.data());
break;
352 std::cerr <<
"UniformPool::UniformMat : invalid size " << size << std::endl;
356 checkGLError2(
id.c_str());
364 QString str = QString(
"uniform mat%2 %1 = {").arg(
id.c_str()).arg(size);
365 for (
int y = 0; y < size; ++y) {
367 for (
int x = 0; x < size; ++x) {
368 str += QString::number(val(y,x));
385 checkGLError2(
"prev opengl error");
386 GLint location = glGetUniformLocation(_progID,
id.c_str());
387 checkGLError2(
id.c_str());
390 glUniform1iv(location, size, (GLint*)val);
393 glUniform1fv(location, size, val);
396 checkGLError2(
id.c_str());
404 QString str = QString(
"uniform %3 %2[%1] = {").arg(
id.c_str()).arg(size).arg(integer ?
"int" :
"float");
405 for (
int y = 0; y < size; ++y) {
407 str += QString::number(((GLint*)val)[y]);
409 str += QString::number(val[y]);
420 : val(0), integer(false), size(0)
442 if ( it ==
pool_.end() ){
445 pool_.push_back(dst);
452 std::cerr <<
"UniformPool::addVecf type of " << _vec.id <<
" incorrect." << std::endl;
458 dst->size = _vec.size;
475 if ( it ==
pool_.end() ){
478 pool_.push_back(dst);
485 std::cerr <<
"UniformPool::addVeci type of " << _vec.id <<
" incorrect." << std::endl;
491 dst->size = _vec.size;
508 if ( it ==
pool_.end() ){
511 pool_.push_back(dst);
518 std::cerr <<
"UniformPool::addVecui type of " << _vec.id <<
" incorrect." << std::endl;
524 dst->size = _vec.size;
541 if ( it ==
pool_.end() ){
544 pool_.push_back(dst);
551 std::cerr <<
"UniformPool::addMatrix type of " << _mat.id <<
" incorrect." << std::endl;
557 dst->size = _mat.size;
558 dst->transposed = _mat.transposed;
577 if ( it ==
pool_.end() ){
580 pool_.push_back(dst);
587 std::cerr <<
"UniformPool::addBuf type of " << _name <<
" incorrect." << std::endl;
594 if (dst->size < _count)
598 dst->val =
new float[_count];
604 memcpy(dst->val, _values, _count *
sizeof(
float));
635 tmp.val[0] = _value[0];
636 tmp.val[1] = _value[1];
652 tmp.val[0] = _value[0];
653 tmp.val[1] = _value[1];
654 tmp.val[2] = _value[2];
702 tmp.val[0] = _value[0];
703 tmp.val[1] = _value[1];
719 tmp.val[0] = _value[0];
720 tmp.val[1] = _value[1];
721 tmp.val[2] = _value[2];
770 tmp.val[0] = _value[0];
771 tmp.val[1] = _value[1];
787 tmp.val[0] = _value[0];
788 tmp.val[1] = _value[1];
789 tmp.val[2] = _value[2];
821 tmp.transposed = _transposed;
839 tmp.transposed = _transposed;
855 addBuf(_name, _values, _count,
true);
866 addBuf(_name, _values, _count,
false);
GLuint getProgramId()
Returns opengl id.
This namespace contains all the classes and functions for handling GLSL shader and program objects...