From 8bc586e613ead9cada4b7eb2e61f2e7a1f634bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Fri, 4 Feb 2011 19:57:19 +0100 Subject: [PATCH] kwin: Add overloads for setUniform() that take a location. --- lib/kwinglutils.cpp | 71 +++++++++++++++++++++++++++++++++------------ lib/kwinglutils.h | 10 +++++++ 2 files changed, 63 insertions(+), 18 deletions(-) diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index 82ebb1fa6e..ff75932a39 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -854,60 +854,96 @@ void GLShader::unbind() glUseProgram(0); } -int GLShader::uniformLocation(const char* name) +int GLShader::uniformLocation(const char *name) { int location = glGetUniformLocation(mProgram, name); return location; } -bool GLShader::setUniform(const char* name, float value) +bool GLShader::setUniform(const char *name, float value) +{ + const int location = uniformLocation(name); + return setUniform(location, value); +} + +bool GLShader::setUniform(const char *name, int value) +{ + const int location = uniformLocation(name); + return setUniform(location, value); +} + +bool GLShader::setUniform(const char *name, const QVector2D& value) +{ + const int location = uniformLocation(name); + return setUniform(location, value); +} + +bool GLShader::setUniform(const char *name, const QVector3D& value) +{ + const int location = uniformLocation(name); + return setUniform(location, value); +} + +bool GLShader::setUniform(const char *name, const QVector4D& value) +{ + const int location = uniformLocation(name); + return setUniform(location, value); +} + +bool GLShader::setUniform(const char *name, const QMatrix4x4& value) +{ + const int location = uniformLocation(name); + return setUniform(location, value); +} + +bool GLShader::setUniform(const char *name, const QColor& color) +{ + const int location = uniformLocation(name); + return setUniform(location, color); +} + +bool GLShader::setUniform(int location, float value) { - int location = uniformLocation(name); if (location >= 0) { glUniform1f(location, value); } return (location >= 0); } -bool GLShader::setUniform(const char* name, int value) +bool GLShader::setUniform(int location, int value) { - int location = uniformLocation(name); if (location >= 0) { glUniform1i(location, value); } return (location >= 0); } -bool GLShader::setUniform(const char* name, const QVector2D& value) +bool GLShader::setUniform(int location, const QVector2D &value) { - const int location = uniformLocation(name); if (location >= 0) { - glUniform2f(location, value.x(), value.y()); + glUniform2fv(location, 1, (const GLfloat*)&value); } return (location >= 0); } -bool GLShader::setUniform(const char* name, const QVector3D& value) +bool GLShader::setUniform(int location, const QVector3D &value) { - const int location = uniformLocation(name); if (location >= 0) { - glUniform3f(location, value.x(), value.y(), value.z()); + glUniform3fv(location, 1, (const GLfloat*)&value); } return (location >= 0); } -bool GLShader::setUniform(const char* name, const QVector4D& value) +bool GLShader::setUniform(int location, const QVector4D &value) { - const int location = uniformLocation(name); if (location >= 0) { - glUniform4f(location, value.x(), value.y(), value.z(), value.w()); + glUniform4fv(location, 1, (const GLfloat*)&value); } return (location >= 0); } -bool GLShader::setUniform(const char* name, const QMatrix4x4& value) +bool GLShader::setUniform(int location, const QMatrix4x4 &value) { - const int location = uniformLocation(name); if (location >= 0) { GLfloat m[16]; const qreal *data = value.constData(); @@ -922,9 +958,8 @@ bool GLShader::setUniform(const char* name, const QMatrix4x4& value) return (location >= 0); } -bool GLShader::setUniform(const char* name, const QColor& color) +bool GLShader::setUniform(int location, const QColor &color) { - const int location = uniformLocation(name); if (location >= 0) { glUniform4f(location, color.redF(), color.greenF(), color.blueF(), color.alphaF()); } diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index a7cff39d89..37820981ca 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -252,6 +252,7 @@ public: } int uniformLocation(const char* name); + bool setUniform(const char* name, float value); bool setUniform(const char* name, int value); bool setUniform(const char* name, const QVector2D& value); @@ -259,6 +260,15 @@ public: bool setUniform(const char* name, const QVector4D& value); bool setUniform(const char* name, const QMatrix4x4& value); bool setUniform(const char* name, const QColor& color); + + bool setUniform(int location, float value); + bool setUniform(int location, int value); + bool setUniform(int location, const QVector2D &value); + bool setUniform(int location, const QVector3D &value); + bool setUniform(int location, const QVector4D &value); + bool setUniform(int location, const QMatrix4x4 &value); + bool setUniform(int location, const QColor &value); + int attributeLocation(const char* name); bool setAttribute(const char* name, float value); /**