File indexing completed on 2024-05-12 05:31:43
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2006-2007 Rivo Laks <rivolaks@hot.ee> 0006 SPDX-FileCopyrightText: 2010, 2011 Martin Gräßlin <mgraesslin@kde.org> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #pragma once 0012 0013 #include "core/output.h" 0014 0015 #include <QExplicitlySharedDataPointer> 0016 #include <QMatrix4x4> 0017 #include <QRegion> 0018 #include <QSize> 0019 0020 #include <epoxy/gl.h> 0021 0022 class QImage; 0023 class QPixmap; 0024 0025 /** @addtogroup kwineffects */ 0026 /** @{ */ 0027 0028 namespace KWin 0029 { 0030 0031 class GLVertexBuffer; 0032 class GLTexturePrivate; 0033 0034 enum TextureCoordinateType { 0035 NormalizedCoordinates = 0, 0036 UnnormalizedCoordinates, 0037 }; 0038 0039 class KWIN_EXPORT GLTexture 0040 { 0041 public: 0042 explicit GLTexture(GLenum target); 0043 0044 /** 0045 * Creates the underlying texture object. Returns @c true if the texture has been created 0046 * successfully; otherwise returns @c false. Note that this does not allocate any storage 0047 * for the texture. 0048 */ 0049 bool create(); 0050 virtual ~GLTexture(); 0051 0052 bool isNull() const; 0053 QSize size() const; 0054 void setSize(const QSize &size); 0055 int width() const; 0056 int height() const; 0057 0058 /** 0059 * sets the transform between the content and the buffer 0060 */ 0061 void setContentTransform(OutputTransform transform); 0062 0063 /** 0064 * @returns the transform between the content and the buffer 0065 */ 0066 OutputTransform contentTransform() const; 0067 0068 /** 0069 * Specifies which component of a texel is placed in each respective 0070 * component of the vector returned to the shader. 0071 * 0072 * Valid values are GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_ONE and GL_ZERO. 0073 * 0074 * @see swizzleSupported() 0075 * @since 5.2 0076 */ 0077 void setSwizzle(GLenum red, GLenum green, GLenum blue, GLenum alpha); 0078 0079 /** 0080 * Returns a matrix that transforms texture coordinates of the given type, 0081 * taking the texture target and the y-inversion flag into account. 0082 * 0083 * @since 4.11 0084 */ 0085 QMatrix4x4 matrix(TextureCoordinateType type) const; 0086 0087 void update(const QImage &image, const QPoint &offset = QPoint(0, 0), const QRect &src = QRect()); 0088 void bind(); 0089 void unbind(); 0090 void render(const QSizeF &size); 0091 void render(const QRegion ®ion, const QSizeF &size, bool hardwareClipping = false); 0092 void render(const QRectF &source, const QRegion ®ion, const QSizeF &targetSize, bool hardwareClipping = false); 0093 0094 GLuint texture() const; 0095 GLenum target() const; 0096 GLenum filter() const; 0097 GLenum internalFormat() const; 0098 0099 QImage toImage(); 0100 0101 /** @short 0102 * Make the texture fully transparent 0103 */ 0104 void clear(); 0105 /** 0106 * @deprecated track modifications to the texture yourself 0107 */ 0108 void setDirty(); 0109 bool isDirty() const; 0110 void setFilter(GLenum filter); 0111 void setWrapMode(GLenum mode); 0112 0113 void generateMipmaps(); 0114 0115 static bool framebufferObjectSupported(); 0116 0117 /** 0118 * Returns true if texture swizzle is supported, and false otherwise 0119 * 0120 * Texture swizzle requires OpenGL 3.3, GL_ARB_texture_swizzle, or OpenGL ES 3.0. 0121 * 0122 * @since 5.2 0123 */ 0124 static bool supportsSwizzle(); 0125 0126 /** 0127 * Returns @c true if texture formats R* are supported, and @c false otherwise. 0128 * 0129 * This requires OpenGL 3.0, GL_ARB_texture_rg or OpenGL ES 3.0 or GL_EXT_texture_rg. 0130 * 0131 * @since 5.2.1 0132 */ 0133 static bool supportsFormatRG(); 0134 0135 static std::unique_ptr<GLTexture> createNonOwningWrapper(GLuint textureId, GLenum internalFormat, const QSize &size); 0136 static std::unique_ptr<GLTexture> allocate(GLenum internalFormat, const QSize &size, int levels = 1); 0137 static std::unique_ptr<GLTexture> upload(const QImage &image); 0138 static std::unique_ptr<GLTexture> upload(const QPixmap &pixmap); 0139 0140 protected: 0141 explicit GLTexture(GLenum target, GLuint textureId, GLenum internalFormat, const QSize &size, int levels, bool owning, OutputTransform transform); 0142 0143 const std::unique_ptr<GLTexturePrivate> d; 0144 0145 virtual void onDamage(); 0146 }; 0147 0148 } // namespace 0149 0150 /** @} */