kwin: Add GLTexture::matrix()
This method returns a matrix that transforms normalized or un-normalized texture coordinates, taking the texture target and y-inversion flag into account.
This commit is contained in:
parent
38678bb84f
commit
7a99b8c0ef
5 changed files with 54 additions and 1 deletions
|
@ -376,6 +376,7 @@ bool EglTexture::loadTexture(const Pixmap &pix, const QSize &size, int depth)
|
||||||
checkGLError("load texture");
|
checkGLError("load texture");
|
||||||
q->setYInverted(true);
|
q->setYInverted(true);
|
||||||
m_size = size;
|
m_size = size;
|
||||||
|
updateMatrix();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -612,6 +612,9 @@ bool GlxTexture::loadTexture(const Pixmap& pix, const QSize& size, int depth)
|
||||||
#ifdef CHECK_GL_ERROR
|
#ifdef CHECK_GL_ERROR
|
||||||
checkGLError("TextureLoad0");
|
checkGLError("TextureLoad0");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
updateMatrix();
|
||||||
|
|
||||||
unbind();
|
unbind();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,8 @@ GLTexture::GLTexture(int width, int height)
|
||||||
d->m_size = QSize(width, height);
|
d->m_size = QSize(width, height);
|
||||||
d->m_canUseMipmaps = true;
|
d->m_canUseMipmaps = true;
|
||||||
|
|
||||||
|
d->updateMatrix();
|
||||||
|
|
||||||
glGenTextures(1, &d->m_texture);
|
glGenTextures(1, &d->m_texture);
|
||||||
bind();
|
bind();
|
||||||
#ifdef KWIN_HAVE_OPENGLES
|
#ifdef KWIN_HAVE_OPENGLES
|
||||||
|
@ -204,6 +206,8 @@ bool GLTexture::load(const QImage& image, GLenum target)
|
||||||
d->m_size = img.size();
|
d->m_size = img.size();
|
||||||
d->m_yInverted = true;
|
d->m_yInverted = true;
|
||||||
|
|
||||||
|
d->updateMatrix();
|
||||||
|
|
||||||
img = d->convertToGLFormat(img);
|
img = d->convertToGLFormat(img);
|
||||||
|
|
||||||
if (isNull()) {
|
if (isNull()) {
|
||||||
|
@ -526,6 +530,27 @@ QImage GLTexturePrivate::convertToGLFormat(const QImage& img) const
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLTexturePrivate::updateMatrix()
|
||||||
|
{
|
||||||
|
m_matrix[NormalizedCoordinates].setToIdentity();
|
||||||
|
m_matrix[UnnormalizedCoordinates].setToIdentity();
|
||||||
|
|
||||||
|
#ifndef KWIN_HAVE_OPENGLES
|
||||||
|
if (m_target == GL_TEXTURE_RECTANGLE_ARB)
|
||||||
|
m_matrix[NormalizedCoordinates].scale(m_size.width(), m_size.height());
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
m_matrix[UnnormalizedCoordinates].scale(1.0 / m_size.width(), 1.0 / m_size.height());
|
||||||
|
|
||||||
|
if (!m_yInverted) {
|
||||||
|
m_matrix[NormalizedCoordinates].translate(0.0, 1.0);
|
||||||
|
m_matrix[NormalizedCoordinates].scale(1.0, -1.0);
|
||||||
|
|
||||||
|
m_matrix[UnnormalizedCoordinates].translate(0.0, m_size.height());
|
||||||
|
m_matrix[UnnormalizedCoordinates].scale(1.0, -1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool GLTexture::isYInverted() const
|
bool GLTexture::isYInverted() const
|
||||||
{
|
{
|
||||||
Q_D(const GLTexture);
|
Q_D(const GLTexture);
|
||||||
|
@ -536,6 +561,7 @@ void GLTexture::setYInverted(bool inverted)
|
||||||
{
|
{
|
||||||
Q_D(GLTexture);
|
Q_D(GLTexture);
|
||||||
d->m_yInverted = inverted;
|
d->m_yInverted = inverted;
|
||||||
|
d->updateMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
int GLTexture::width() const
|
int GLTexture::width() const
|
||||||
|
@ -550,6 +576,12 @@ int GLTexture::height() const
|
||||||
return d->m_size.height();
|
return d->m_size.height();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMatrix4x4 GLTexture::matrix(TextureCoordinateType type) const
|
||||||
|
{
|
||||||
|
Q_D(const GLTexture);
|
||||||
|
return d->m_matrix[type];
|
||||||
|
}
|
||||||
|
|
||||||
bool GLTexture::NPOTTextureSupported()
|
bool GLTexture::NPOTTextureSupported()
|
||||||
{
|
{
|
||||||
return GLTexturePrivate::sNPOTTextureSupported;
|
return GLTexturePrivate::sNPOTTextureSupported;
|
||||||
|
|
|
@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include <QRegion>
|
#include <QRegion>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QExplicitlySharedDataPointer>
|
#include <QExplicitlySharedDataPointer>
|
||||||
|
#include <QtGui/QMatrix4x4>
|
||||||
|
|
||||||
class QImage;
|
class QImage;
|
||||||
class QPixmap;
|
class QPixmap;
|
||||||
|
@ -41,6 +42,11 @@ namespace KWin
|
||||||
class GLVertexBuffer;
|
class GLVertexBuffer;
|
||||||
class GLTexturePrivate;
|
class GLTexturePrivate;
|
||||||
|
|
||||||
|
enum TextureCoordinateType {
|
||||||
|
NormalizedCoordinates = 0,
|
||||||
|
UnnormalizedCoordinates
|
||||||
|
};
|
||||||
|
|
||||||
class KWIN_EXPORT GLTexture
|
class KWIN_EXPORT GLTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -67,6 +73,14 @@ public:
|
||||||
**/
|
**/
|
||||||
void setYInverted(bool inverted);
|
void setYInverted(bool inverted);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a matrix that transforms texture coordinates of the given type,
|
||||||
|
* taking the texture target and the y-inversion flag into account.
|
||||||
|
*
|
||||||
|
* @since 4.11
|
||||||
|
*/
|
||||||
|
QMatrix4x4 matrix(TextureCoordinateType type) const;
|
||||||
|
|
||||||
virtual bool load(const QImage& image, GLenum target = GL_TEXTURE_2D);
|
virtual bool load(const QImage& image, GLenum target = GL_TEXTURE_2D);
|
||||||
virtual bool load(const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D);
|
virtual bool load(const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D);
|
||||||
virtual bool load(const QString& fileName);
|
virtual bool load(const QString& fileName);
|
||||||
|
|
|
@ -48,13 +48,16 @@ public:
|
||||||
|
|
||||||
QImage convertToGLFormat(const QImage& img) const;
|
QImage convertToGLFormat(const QImage& img) const;
|
||||||
|
|
||||||
|
void updateMatrix();
|
||||||
|
|
||||||
GLuint m_texture;
|
GLuint m_texture;
|
||||||
GLenum m_target;
|
GLenum m_target;
|
||||||
GLenum m_filter;
|
GLenum m_filter;
|
||||||
GLenum m_wrapMode;
|
GLenum m_wrapMode;
|
||||||
QSize m_size;
|
QSize m_size;
|
||||||
QSizeF m_scale; // to un-normalize GL_TEXTURE_2D
|
QSizeF m_scale; // to un-normalize GL_TEXTURE_2D
|
||||||
bool m_yInverted; // texture has y inverted
|
QMatrix4x4 m_matrix[2];
|
||||||
|
bool m_yInverted; // texture is y-inverted
|
||||||
bool m_canUseMipmaps;
|
bool m_canUseMipmaps;
|
||||||
bool m_markedDirty;
|
bool m_markedDirty;
|
||||||
bool m_filterChanged;
|
bool m_filterChanged;
|
||||||
|
|
Loading…
Reference in a new issue