Support QMatrix4x4 as Uniform value
This commit is contained in:
parent
ea12f95b27
commit
f240fc2196
4 changed files with 24 additions and 0 deletions
|
@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <QVector2D>
|
||||
#include <QVector3D>
|
||||
#include <QVector4D>
|
||||
#include <QMatrix4x4>
|
||||
|
||||
|
||||
#define DEBUG_GLRENDERTARGET 0
|
||||
|
@ -999,6 +1000,23 @@ bool GLShader::setUniform(const char* name, const QVector4D& value)
|
|||
return (location >= 0);
|
||||
}
|
||||
|
||||
bool GLShader::setUniform(const char* name, const QMatrix4x4& value)
|
||||
{
|
||||
const int location = uniformLocation(name);
|
||||
if (location >= 0) {
|
||||
GLfloat m[16];
|
||||
const qreal *data = value.constData();
|
||||
// i is column, j is row for m
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int j=0; j < 4; ++j) {
|
||||
m[i*4+j] = data[j*4+i];
|
||||
}
|
||||
}
|
||||
glUniformMatrix4fv(location, 1, GL_FALSE, m);
|
||||
}
|
||||
return (location >= 0);
|
||||
}
|
||||
|
||||
int GLShader::attributeLocation(const char* name)
|
||||
{
|
||||
int location = glGetAttribLocation(mProgram, name);
|
||||
|
|
|
@ -38,6 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
class QVector2D;
|
||||
class QVector3D;
|
||||
class QVector4D;
|
||||
class QMatrix4x4;
|
||||
|
||||
template< class K, class V > class QHash;
|
||||
|
||||
|
@ -252,6 +253,7 @@ class KWIN_EXPORT GLShader
|
|||
bool setUniform(const char* name, const QVector2D& value);
|
||||
bool setUniform(const char* name, const QVector3D& value);
|
||||
bool setUniform(const char* name, const QVector4D& value);
|
||||
bool setUniform(const char* name, const QMatrix4x4& value);
|
||||
int attributeLocation(const char* name);
|
||||
bool setAttribute(const char* name, float value);
|
||||
/**
|
||||
|
|
|
@ -103,6 +103,7 @@ glUniform1fv_func glUniform1fv;
|
|||
glUniform2fv_func glUniform2fv;
|
||||
glUniform3fv_func glUniform3fv;
|
||||
glUniform4fv_func glUniform4fv;
|
||||
glUniformMatrix4fv_func glUniformMatrix4fv;
|
||||
glValidateProgram_func glValidateProgram;
|
||||
glGetUniformLocation_func glGetUniformLocation;
|
||||
glVertexAttrib1f_func glVertexAttrib1f;
|
||||
|
@ -260,6 +261,7 @@ void glResolveFunctions()
|
|||
GL_RESOLVE_WITH_EXT( glUniform2fv, glUniform2fvARB );
|
||||
GL_RESOLVE_WITH_EXT( glUniform3fv, glUniform3fvARB );
|
||||
GL_RESOLVE_WITH_EXT( glUniform4fv, glUniform4fvARB );
|
||||
GL_RESOLVE_WITH_EXT( glUniformMatrix4fv, glUniformMatrix4fvARB );
|
||||
GL_RESOLVE_WITH_EXT( glValidateProgram, glValidateProgramARB );
|
||||
GL_RESOLVE_WITH_EXT( glGetUniformLocation, glGetUniformLocationARB );
|
||||
GL_RESOLVE_WITH_EXT( glVertexAttrib1f, glVertexAttrib1fARB );
|
||||
|
|
|
@ -285,6 +285,7 @@ typedef GLvoid (*glUniform1fv_func)(GLint, GLsizei, const GLfloat*);
|
|||
typedef GLvoid (*glUniform2fv_func)(GLint, GLsizei, const GLfloat*);
|
||||
typedef GLvoid (*glUniform3fv_func)(GLint, GLsizei, const GLfloat*);
|
||||
typedef GLvoid (*glUniform4fv_func)(GLint, GLsizei, const GLfloat*);
|
||||
typedef GLvoid (*glUniformMatrix4fv_func)(GLint, GLsizei, GLboolean, const GLfloat*);
|
||||
typedef GLvoid (*glValidateProgram_func)(GLuint);
|
||||
typedef GLint (*glGetUniformLocation_func)(GLuint, const GLchar*);
|
||||
typedef GLvoid (*glVertexAttrib1f_func)(GLuint, GLfloat);
|
||||
|
@ -318,6 +319,7 @@ extern KWIN_EXPORT glUniform1fv_func glUniform1fv;
|
|||
extern KWIN_EXPORT glUniform2fv_func glUniform2fv;
|
||||
extern KWIN_EXPORT glUniform3fv_func glUniform3fv;
|
||||
extern KWIN_EXPORT glUniform4fv_func glUniform4fv;
|
||||
extern KWIN_EXPORT glUniformMatrix4fv_func glUniformMatrix4fv;
|
||||
extern KWIN_EXPORT glValidateProgram_func glValidateProgram;
|
||||
extern KWIN_EXPORT glGetUniformLocation_func glGetUniformLocation;
|
||||
extern KWIN_EXPORT glVertexAttrib1f_func glVertexAttrib1f;
|
||||
|
|
Loading…
Reference in a new issue