Commit 50c3080e authored by Jan Möbius's avatar Jan Möbius
Browse files

ShaderUtils improvement to handle matrices.

ShaderUtils function to handle code given as QStringList.

refs #901



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@14706 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 1f6718ec
......@@ -130,6 +130,24 @@ namespace GLSL {
delete[] stringArray;
}
/** \brief Upload the source of the shader.
*/
void Shader::setSource(const QStringList& source) {
if ( this->m_shaderId == 0 ) {
std::cerr << "shader not initialized" << std::endl;
return;
}
StringList strlist;
for (QStringList::const_iterator it = source.begin();it != source.end();++it)
strlist.push_back(std::string((const char*)it->toAscii()) + '\n');
setSource(strlist);
}
/** \brief Compile the shader object.
*
* \returns True if compilation was successful, or false if it failed. Also
......@@ -359,6 +377,28 @@ namespace GLSL {
setUniform(varName, value);
}
void Program::setUniform( const char *name, const ACG::GLMatrixf &value, bool transposed){
checkGLError();
GLint location = glGetUniformLocation(this->m_programId, name);
checkGLError2(name);
glUniformMatrix4fv(location, 1, transposed, value.data());
checkGLError();
}
void Program::setUniformMat3( const char *name, const ACG::GLMatrixf &value, bool transposed){
checkGLError();
GLint location = glGetUniformLocation(this->m_programId, name);
checkGLError2(name);
float tmp[9];
for (int i = 0; i < 3; ++i)
for (int k = 0; k < 3; ++k)
tmp[i*3+k] = value.data()[i*4+k];
glUniformMatrix3fv(location, 1, transposed, tmp);
checkGLError();
}
void Program::bindAttributeLocation(unsigned int index, const char *name) {
glBindAttribLocation(this->m_programId, index, name);
checkGLError2(name);
......
......@@ -56,9 +56,11 @@
#include "../Config/ACGDefines.hh"
#include <ACG/Math/VectorT.hh>
#include <ACG/Math/GLMatrixT.hh>
#include <list>
#include <string>
#include <QStringList>
//==============================================================================
......@@ -79,6 +81,7 @@ namespace GLSL {
Shader(GLenum shaderType);
virtual ~Shader();
void setSource(StringList source);
void setSource(const QStringList& source);
// FIXME implement StringList getSource();
bool compile();
......@@ -157,6 +160,9 @@ namespace GLSL {
void setUniform(const char *name, const ACG::Vec3f &value);
void setUniform(const char *name, const ACG::Vec4f &value);
void setUniform(const char *name, const ACG::GLMatrixf &value, bool transposed = false);
void setUniformMat3(const char *name, const ACG::GLMatrixf &value, bool transposed = false);
void setUniform(const char *name, GLint *value, int count);
void setUniform(const char *name, GLfloat *value, int count);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment