diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index b1389f4d06..fc82b2c54a 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -318,6 +318,46 @@ void addQuadVertices(QVector& verts, float x1, float y1, float x2, float verts << x2 << y1; } +void pushMatrix() +{ +#ifndef KWIN_HAVE_OPENGLES + glPushMatrix(); +#endif +} + +void pushMatrix(const QMatrix4x4 &matrix) +{ +#ifdef KWIN_HAVE_OPENGLES + Q_UNUSED(matrix) +#else + glPushMatrix(); + multiplyMatrix(matrix); +#endif +} + +void multiplyMatrix(const QMatrix4x4 &matrix) +{ +#ifdef KWIN_HAVE_OPENGLES + Q_UNUSED(matrix) +#else + GLfloat m[16]; + const qreal *data = matrix.constData(); + for (int i = 0; i < 4; ++i) { + for (int j=0; j < 4; ++j) { + m[i*4+j] = data[i*4+j]; + } + } + glMultMatrixf(m); +#endif +} + +void popMatrix() +{ +#ifndef KWIN_HAVE_OPENGLES + glPopMatrix(); +#endif +} + //**************************************** // GLTexture //**************************************** diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index 7dffd6c03b..e50deab132 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -125,6 +125,40 @@ KWIN_EXPORT void renderGLGeometryImmediate( int count, **/ KWIN_EXPORT void addQuadVertices( QVector& verts, float x1, float y1, float x2, float y2 ); +/** + * Push a new matrix on the GL matrix stack. + * In GLES this method is a noop. This method should be preferred over glPushMatrix + * as it also handles GLES. + * @since 4.7 + **/ +KWIN_EXPORT void pushMatrix(); +/** + * Multiplies current matrix on GL stack with @p matrix and pushes the result on the matrix stack. + * This method is the same as pushMatrix followed by multiplyMatrix. + * In GLES this method is a noop. This method should be preferred over glPushMatrix + * as it also handles GLES. + * @param matrix The matrix the current matrix on the stack should be multiplied with. + * @see pushMatrix + * @see multiplyMatrix + * @since 4.7 + **/ +KWIN_EXPORT void pushMatrix(const QMatrix4x4 &matrix); +/** + * Multiplies the current matrix on GL stack with @p matrix. + * In GLES this method is a noop. This method should be preferred over glMultMatrix + * as it also handles GLES. + * @param matrix The matrix the current matrix on the stack should be multiplied with. + * @since 4.7 + **/ +KWIN_EXPORT void multiplyMatrix(const QMatrix4x4 &matrix); +/** + * Pops the current matrix from the GL matrix stack. + * In GLES this method is a noop. This method should be preferred over glPopMatrix + * as it also handles GLES. + * @since 4.7 + **/ +KWIN_EXPORT void popMatrix(); + class KWIN_EXPORT GLTexture : public QSharedData