From 1ba818044f697c0c0853799b02a8800476d37e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sat, 18 Dec 2010 08:45:47 +0100 Subject: [PATCH] Read a matrix uniform back from shader. Might require additions to kwinglutils_func in desktop profile --- lib/kwinglutils.cpp | 17 +++++++++++++++++ lib/kwinglutils.h | 5 +++++ 2 files changed, 22 insertions(+) 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 );