2011-06-22 10:55:04 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2006-2007 Rivo Laks <rivolaks@hot.ee>
|
|
|
|
Copyright (C) 2010, 2011 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#ifndef KWIN_GLTEXTURE_H
|
|
|
|
#define KWIN_GLTEXTURE_H
|
|
|
|
|
2013-12-03 09:43:57 +00:00
|
|
|
#include <kwinglutils_export.h>
|
2011-06-22 10:55:04 +00:00
|
|
|
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QSize>
|
2013-02-26 07:02:27 +00:00
|
|
|
#include <QRegion>
|
2011-07-18 15:55:39 +00:00
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QExplicitlySharedDataPointer>
|
2018-06-05 10:52:57 +00:00
|
|
|
#include <QMatrix4x4>
|
2011-06-22 10:55:04 +00:00
|
|
|
|
2016-08-08 13:46:25 +00:00
|
|
|
#include <epoxy/gl.h>
|
|
|
|
|
2011-06-22 10:55:04 +00:00
|
|
|
class QImage;
|
|
|
|
class QPixmap;
|
|
|
|
|
|
|
|
/** @addtogroup kwineffects */
|
|
|
|
/** @{ */
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
class GLVertexBuffer;
|
2011-07-18 15:55:39 +00:00
|
|
|
class GLTexturePrivate;
|
2011-06-22 10:55:04 +00:00
|
|
|
|
2012-09-27 19:22:05 +00:00
|
|
|
enum TextureCoordinateType {
|
|
|
|
NormalizedCoordinates = 0,
|
|
|
|
UnnormalizedCoordinates
|
|
|
|
};
|
|
|
|
|
2013-12-03 09:43:57 +00:00
|
|
|
class KWINGLUTILS_EXPORT GLTexture
|
2011-06-22 10:55:04 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
GLTexture();
|
2011-07-18 15:55:39 +00:00
|
|
|
GLTexture(const GLTexture& tex);
|
2011-06-22 10:55:04 +00:00
|
|
|
explicit GLTexture(const QImage& image, GLenum target = GL_TEXTURE_2D);
|
|
|
|
explicit GLTexture(const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D);
|
2012-12-29 06:34:38 +00:00
|
|
|
explicit GLTexture(const QString& fileName);
|
2014-12-13 13:28:33 +00:00
|
|
|
GLTexture(GLenum internalFormat, int width, int height, int levels = 1);
|
|
|
|
explicit GLTexture(GLenum internalFormat, const QSize &size, int levels = 1);
|
2019-09-25 13:27:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a GLTexture wrapper around an existing texture.
|
|
|
|
* Management of the underlying texture remains the responsibility of the caller.
|
|
|
|
* @since 5.18
|
|
|
|
*/
|
|
|
|
explicit GLTexture(GLuint textureId, GLenum internalFormat, const QSize &size, int levels = 1);
|
2011-06-22 10:55:04 +00:00
|
|
|
virtual ~GLTexture();
|
|
|
|
|
2011-07-18 15:55:39 +00:00
|
|
|
GLTexture & operator = (const GLTexture& tex);
|
|
|
|
|
2011-06-22 10:55:04 +00:00
|
|
|
bool isNull() const;
|
|
|
|
QSize size() const;
|
2011-07-18 15:55:39 +00:00
|
|
|
int width() const;
|
|
|
|
int height() const;
|
2011-07-03 07:30:38 +00:00
|
|
|
/**
|
|
|
|
* @since 4.7
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2011-07-03 07:30:38 +00:00
|
|
|
bool isYInverted() const;
|
2011-07-18 15:55:39 +00:00
|
|
|
/**
|
|
|
|
* @since 4.8
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2011-07-18 15:55:39 +00:00
|
|
|
void setYInverted(bool inverted);
|
2011-06-22 10:55:04 +00:00
|
|
|
|
2014-12-13 13:30:59 +00:00
|
|
|
/**
|
|
|
|
* Specifies which component of a texel is placed in each respective
|
|
|
|
* component of the vector returned to the shader.
|
|
|
|
*
|
|
|
|
* Valid values are GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_ONE and GL_ZERO.
|
|
|
|
*
|
|
|
|
* @see swizzleSupported()
|
|
|
|
* @since 5.2
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2014-12-13 13:30:59 +00:00
|
|
|
void setSwizzle(GLenum red, GLenum green, GLenum blue, GLenum alpha);
|
|
|
|
|
2012-09-27 19:22:05 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2012-09-27 19:22:05 +00:00
|
|
|
QMatrix4x4 matrix(TextureCoordinateType type) const;
|
|
|
|
|
2013-02-22 09:13:46 +00:00
|
|
|
void update(const QImage& image, const QPoint &offset = QPoint(0, 0), const QRect &src = QRect());
|
2011-06-22 10:55:04 +00:00
|
|
|
virtual void discard();
|
2011-07-18 15:55:39 +00:00
|
|
|
void bind();
|
|
|
|
void unbind();
|
2012-02-12 15:42:09 +00:00
|
|
|
void render(QRegion region, const QRect& rect, bool hardwareClipping = false);
|
2011-06-22 10:55:04 +00:00
|
|
|
|
|
|
|
GLuint texture() const;
|
|
|
|
GLenum target() const;
|
|
|
|
GLenum filter() const;
|
2014-12-13 13:28:33 +00:00
|
|
|
GLenum internalFormat() const;
|
|
|
|
|
2013-09-05 19:10:13 +00:00
|
|
|
/** @short
|
|
|
|
* Make the texture fully transparent
|
|
|
|
* Warning: this clobbers the current framebuffer binding except on fglrx
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2013-09-05 19:10:13 +00:00
|
|
|
void clear();
|
2012-01-07 21:26:50 +00:00
|
|
|
bool isDirty() const;
|
2011-06-22 10:55:04 +00:00
|
|
|
void setFilter(GLenum filter);
|
|
|
|
void setWrapMode(GLenum mode);
|
2012-01-07 21:26:50 +00:00
|
|
|
void setDirty();
|
2011-06-22 10:55:04 +00:00
|
|
|
|
2014-12-11 21:22:08 +00:00
|
|
|
void generateMipmaps();
|
|
|
|
|
2011-07-18 15:55:39 +00:00
|
|
|
static bool framebufferObjectSupported();
|
2011-06-22 10:55:04 +00:00
|
|
|
|
2014-12-13 13:30:59 +00:00
|
|
|
/**
|
|
|
|
* Returns true if texture swizzle is supported, and false otherwise
|
|
|
|
*
|
|
|
|
* Texture swizzle requires OpenGL 3.3, GL_ARB_texture_swizzle, or OpenGL ES 3.0.
|
|
|
|
*
|
|
|
|
* @since 5.2
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2014-12-13 13:30:59 +00:00
|
|
|
static bool supportsSwizzle();
|
|
|
|
|
2015-02-18 08:06:37 +00:00
|
|
|
/**
|
|
|
|
* Returns @c true if texture formats R* are supported, and @c false otherwise.
|
|
|
|
*
|
|
|
|
* This requires OpenGL 3.0, GL_ARB_texture_rg or OpenGL ES 3.0 or GL_EXT_texture_rg.
|
|
|
|
*
|
|
|
|
* @since 5.2.1
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2015-02-18 08:06:37 +00:00
|
|
|
static bool supportsFormatRG();
|
|
|
|
|
2011-06-22 10:55:04 +00:00
|
|
|
protected:
|
2011-07-18 15:55:39 +00:00
|
|
|
QExplicitlySharedDataPointer<GLTexturePrivate> d_ptr;
|
|
|
|
GLTexture(GLTexturePrivate& dd);
|
2011-06-22 10:55:04 +00:00
|
|
|
|
|
|
|
private:
|
2011-08-27 07:31:38 +00:00
|
|
|
Q_DECLARE_PRIVATE(GLTexture)
|
2011-06-22 10:55:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
#endif
|