GLProgram::setParameter() now handles more types of matrices

metadata
Wenzel Jakob 2011-02-10 11:44:49 +01:00
parent a9efb5cd1a
commit 111574dcbc
3 changed files with 73 additions and 8 deletions

View File

@ -83,8 +83,14 @@ public:
/// Set a Point4 parameter
void setParameter(int id, const Point4 &value);
/// Set a Transform parameter
void setParameter(int id, const Transform &value);
/// Set a Matrix2x2 parameter
void setParameter(int id, const Matrix2x2 &value);
/// Set a Matrix3x3 parameter
void setParameter(int id, const Matrix3x3 &value);
/// Set a Matrix4x4 parameter
void setParameter(int id, const Matrix4x4 &value);
/// Set a Spectrum parameter (will be converted to linear RGB)
void setParameter(int id, const Spectrum &value);

View File

@ -135,10 +135,28 @@ public:
setParameter(getParameterID(name, failIfMissing), value);
}
/// Set a Matrix2x2 parameter by name
inline void setParameter(const std::string &name, const Matrix2x2 &value,
bool failIfMissing = true) {
setParameter(getParameterID(name, failIfMissing), value);
}
/// Set a Matrix3x3 parameter by name
inline void setParameter(const std::string &name, const Matrix3x3 &value,
bool failIfMissing = true) {
setParameter(getParameterID(name, failIfMissing), value);
}
/// Set a Matrix4x4 parameter by name
inline void setParameter(const std::string &name, const Matrix4x4 &value,
bool failIfMissing = true) {
setParameter(getParameterID(name, failIfMissing), value);
}
/// Set a Transform parameter by name
inline void setParameter(const std::string &name, const Transform &value,
bool failIfMissing = true) {
setParameter(getParameterID(name, failIfMissing), value);
setParameter(getParameterID(name, failIfMissing), value.getMatrix());
}
/// Set a Spectrum parameter (will be converted to linear RGB) by name
@ -190,8 +208,19 @@ public:
/// Set a Point4 parameter
virtual void setParameter(int id, const Point4 &value) = 0;
/// Set a Matrix2x2 parameter
virtual void setParameter(int id, const Matrix2x2 &value) = 0;
/// Set a Matrix3x3 parameter
virtual void setParameter(int id, const Matrix3x3 &value) = 0;
/// Set a Matrix4x4 parameter
virtual void setParameter(int id, const Matrix4x4 &value) = 0;
/// Set a Transform parameter
virtual void setParameter(int id, const Transform &value) = 0;
inline void setParameter(int id, const Transform &value) {
setParameter(id, value.getMatrix());
}
/// Set a Spectrum parameter (will be converted to linear RGB)
virtual void setParameter(int id, const Spectrum &value) = 0;

View File

@ -237,18 +237,48 @@ void GLProgram::setParameter(int id, const GPUTexture *value) {
value->getName().c_str(), getName().c_str());
}
void GLProgram::setParameter(int id, const Transform &trafo) {
void GLProgram::setParameter(int id, const Matrix2x2 &matrix) {
if (id == -1)
return;
#ifdef SINGLE_PRECISION
glUniformMatrix4fv(id, 1, true, reinterpret_cast<const GLfloat *>
(trafo.getMatrix().m));
glUniformMatrix2fv(id, 1, true, reinterpret_cast<const GLfloat *>(matrix.m));
#else
GLfloat tmp[4];
int idx=0;
for (int i=0; i<2; i++)
for (int j=0; j<2; j++)
tmp[idx++] = (GLfloat) matrix.m[i][j];
glUniformMatrix2fv(id, 1, true, tmp);
#endif
}
void GLProgram::setParameter(int id, const Matrix3x3 &matrix) {
if (id == -1)
return;
#ifdef SINGLE_PRECISION
glUniformMatrix3fv(id, 1, true, reinterpret_cast<const GLfloat *>(matrix.m));
#else
GLfloat tmp[9];
int idx=0;
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
tmp[idx++] = (GLfloat) matrix.m[i][j];
glUniformMatrix3fv(id, 1, true, tmp);
#endif
}
void GLProgram::setParameter(int id, const Matrix4x4 &matrix) {
if (id == -1)
return;
#ifdef SINGLE_PRECISION
glUniformMatrix4fv(id, 1, true, reinterpret_cast<const GLfloat *>(matrix.m));
#else
GLfloat tmp[16];
int idx=0;
for (int i=0; i<4; i++)
for (int j=0; j<4; j++)
tmp[idx++] = (GLfloat) trafo.getMatrix().m[i][j];
tmp[idx++] = (GLfloat) matrix.m[i][j];
glUniformMatrix4fv(id, 1, true, tmp);
#endif
}