1 | /******************************************************************** |
2 | KWin - the KDE window manager |
3 | This file is part of the KDE project. |
4 | |
5 | Copyright (C) 2006-2007 Rivo Laks <rivolaks@hot.ee> |
6 | Copyright (C) 2010, 2011 Martin Gräßlin <mgraesslin@kde.org> |
7 | |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | *********************************************************************/ |
21 | |
22 | #ifndef KWIN_GLTEXTURE_H |
23 | #define KWIN_GLTEXTURE_H |
24 | |
25 | #include "kwinglobals.h" |
26 | |
27 | #include <QSize> |
28 | #include <QRegion> |
29 | #include <QSharedPointer> |
30 | #include <QExplicitlySharedDataPointer> |
31 | #include <QtGui/QMatrix4x4> |
32 | |
33 | class QImage; |
34 | class QPixmap; |
35 | |
36 | /** @addtogroup kwineffects */ |
37 | /** @{ */ |
38 | |
39 | namespace KWin |
40 | { |
41 | |
42 | class GLVertexBuffer; |
43 | class GLTexturePrivate; |
44 | |
45 | enum TextureCoordinateType { |
46 | NormalizedCoordinates = 0, |
47 | UnnormalizedCoordinates |
48 | }; |
49 | |
50 | class KWIN_EXPORT GLTexture |
51 | { |
52 | public: |
53 | GLTexture(); |
54 | GLTexture(const GLTexture& tex); |
55 | explicit GLTexture(const QImage& image, GLenum target = GL_TEXTURE_2D); |
56 | explicit GLTexture(const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D); |
57 | explicit GLTexture(const QString& fileName); |
58 | GLTexture(int width, int height); |
59 | virtual ~GLTexture(); |
60 | |
61 | GLTexture & operator = (const GLTexture& tex); |
62 | |
63 | bool isNull() const; |
64 | QSize size() const; |
65 | int width() const; |
66 | int height() const; |
67 | /** |
68 | * @since 4.7 |
69 | **/ |
70 | bool isYInverted() const; |
71 | /** |
72 | * @since 4.8 |
73 | **/ |
74 | void setYInverted(bool inverted); |
75 | |
76 | /** |
77 | * Returns a matrix that transforms texture coordinates of the given type, |
78 | * taking the texture target and the y-inversion flag into account. |
79 | * |
80 | * @since 4.11 |
81 | */ |
82 | QMatrix4x4 matrix(TextureCoordinateType type) const; |
83 | |
84 | virtual bool load(const QImage& image, GLenum target = GL_TEXTURE_2D); |
85 | virtual bool load(const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D); |
86 | virtual bool load(const QString& fileName); |
87 | void update(const QImage& image, const QPoint &offset = QPoint(0, 0), const QRect &src = QRect()); |
88 | virtual void discard(); |
89 | void bind(); |
90 | void unbind(); |
91 | void render(QRegion region, const QRect& rect, bool hardwareClipping = false); |
92 | |
93 | GLuint texture() const; |
94 | GLenum target() const; |
95 | GLenum filter() const; |
96 | /** @short |
97 | * Make the texture fully transparent |
98 | * Warning: this clobbers the current framebuffer binding except on fglrx |
99 | */ |
100 | void clear(); |
101 | bool isDirty() const; |
102 | void setFilter(GLenum filter); |
103 | void setWrapMode(GLenum mode); |
104 | void setDirty(); |
105 | |
106 | static bool NPOTTextureSupported(); |
107 | static bool framebufferObjectSupported(); |
108 | static bool saturationSupported(); |
109 | |
110 | protected: |
111 | QExplicitlySharedDataPointer<GLTexturePrivate> d_ptr; |
112 | GLTexture(GLTexturePrivate& dd); |
113 | |
114 | private: |
115 | Q_DECLARE_PRIVATE(GLTexture) |
116 | }; |
117 | |
118 | } // namespace |
119 | |
120 | /** @} */ |
121 | |
122 | #endif |
123 | |