diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index a494822009..92415f951a 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -1096,6 +1096,23 @@ void GLShader::bindAttributeLocation(int index, const char* name) // TODO: relink the shader } +QMatrix4x4 GLShader::getUniformMatrix4x4(const char* name) +{ + int location = uniformLocation(name); + if (location >= 0) { + GLfloat m[16]; + glGetUniformfv(mProgram, location, m); + QMatrix4x4 matrix(m[0], m[1], m[2], m[3], + m[4], m[5], m[6], m[7], + m[8], m[9], m[10], m[11], + m[12], m[13], m[14], m[15]); + matrix.optimize(); + return matrix; + } else { + return QMatrix4x4(); + } +} + //**************************************** // ShaderManager //**************************************** diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index 7e9eebb705..c11bf1e524 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -269,6 +269,11 @@ class KWIN_EXPORT GLShader * @since 4.7 */ void bindAttributeLocation(int index, const char* name); + /** + * @return The value of the uniform as a matrix + * @since 4.7 + **/ + QMatrix4x4 getUniformMatrix4x4(const char* name); void setTextureWidth( float width ); void setTextureHeight( float height );