1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QOPENGLFRAMEBUFFEROBJECT_H
41#define QOPENGLFRAMEBUFFEROBJECT_H
42
43#include <QtGui/qtguiglobal.h>
44
45#ifndef QT_NO_OPENGL
46
47#include <QtGui/qopengl.h>
48#include <QtGui/qpaintdevice.h>
49
50#include <QtCore/qscopedpointer.h>
51
52#if defined(Q_CLANG_QDOC)
53#undef GLuint
54typedef unsigned int GLuint;
55#undef GLenum
56typedef unsigned int GLenum;
57#undef GL_TEXTURE_2D
58#define GL_TEXTURE_2D 0x0DE1
59#undef GLbitfield
60typedef unsigned int GLbitfield;
61#endif
62
63QT_BEGIN_NAMESPACE
64
65class QOpenGLFramebufferObjectPrivate;
66class QOpenGLFramebufferObjectFormat;
67
68class Q_GUI_EXPORT QOpenGLFramebufferObject
69{
70 Q_DECLARE_PRIVATE(QOpenGLFramebufferObject)
71public:
72 enum Attachment {
73 NoAttachment,
74 CombinedDepthStencil,
75 Depth
76 };
77
78 explicit QOpenGLFramebufferObject(const QSize &size, GLenum target = GL_TEXTURE_2D);
79 QOpenGLFramebufferObject(int width, int height, GLenum target = GL_TEXTURE_2D);
80
81 QOpenGLFramebufferObject(const QSize &size, Attachment attachment,
82 GLenum target = GL_TEXTURE_2D, GLenum internalFormat = 0);
83 QOpenGLFramebufferObject(int width, int height, Attachment attachment,
84 GLenum target = GL_TEXTURE_2D, GLenum internalFormat = 0);
85
86 QOpenGLFramebufferObject(const QSize &size, const QOpenGLFramebufferObjectFormat &format);
87 QOpenGLFramebufferObject(int width, int height, const QOpenGLFramebufferObjectFormat &format);
88
89 virtual ~QOpenGLFramebufferObject();
90
91 void addColorAttachment(const QSize &size, GLenum internalFormat = 0);
92 void addColorAttachment(int width, int height, GLenum internalFormat = 0);
93
94 QOpenGLFramebufferObjectFormat format() const;
95
96 bool isValid() const;
97 bool isBound() const;
98 bool bind();
99 bool release();
100
101 int width() const { return size().width(); }
102 int height() const { return size().height(); }
103
104 GLuint texture() const;
105 QVector<GLuint> textures() const;
106
107 GLuint takeTexture();
108 GLuint takeTexture(int colorAttachmentIndex);
109
110 QSize size() const;
111 QVector<QSize> sizes() const;
112
113 QImage toImage() const;
114 QImage toImage(bool flipped) const;
115 QImage toImage(bool flipped, int colorAttachmentIndex) const;
116
117 Attachment attachment() const;
118 void setAttachment(Attachment attachment);
119
120 GLuint handle() const;
121
122 static bool bindDefault();
123
124 static bool hasOpenGLFramebufferObjects();
125
126 static bool hasOpenGLFramebufferBlit();
127
128 enum FramebufferRestorePolicy {
129 DontRestoreFramebufferBinding,
130 RestoreFramebufferBindingToDefault,
131 RestoreFrameBufferBinding
132 };
133
134 static void blitFramebuffer(QOpenGLFramebufferObject *target, const QRect &targetRect,
135 QOpenGLFramebufferObject *source, const QRect &sourceRect,
136 GLbitfield buffers,
137 GLenum filter,
138 int readColorAttachmentIndex,
139 int drawColorAttachmentIndex,
140 FramebufferRestorePolicy restorePolicy);
141 static void blitFramebuffer(QOpenGLFramebufferObject *target, const QRect &targetRect,
142 QOpenGLFramebufferObject *source, const QRect &sourceRect,
143 GLbitfield buffers,
144 GLenum filter,
145 int readColorAttachmentIndex,
146 int drawColorAttachmentIndex);
147 static void blitFramebuffer(QOpenGLFramebufferObject *target, const QRect &targetRect,
148 QOpenGLFramebufferObject *source, const QRect &sourceRect,
149 GLbitfield buffers = GL_COLOR_BUFFER_BIT,
150 GLenum filter = GL_NEAREST);
151 static void blitFramebuffer(QOpenGLFramebufferObject *target,
152 QOpenGLFramebufferObject *source,
153 GLbitfield buffers = GL_COLOR_BUFFER_BIT,
154 GLenum filter = GL_NEAREST);
155
156private:
157 Q_DISABLE_COPY(QOpenGLFramebufferObject)
158 QScopedPointer<QOpenGLFramebufferObjectPrivate> d_ptr;
159 friend class QOpenGLPaintDevice;
160 friend class QOpenGLFBOGLPaintDevice;
161};
162
163class QOpenGLFramebufferObjectFormatPrivate;
164class Q_GUI_EXPORT QOpenGLFramebufferObjectFormat
165{
166public:
167 QOpenGLFramebufferObjectFormat();
168 QOpenGLFramebufferObjectFormat(const QOpenGLFramebufferObjectFormat &other);
169 QOpenGLFramebufferObjectFormat &operator=(const QOpenGLFramebufferObjectFormat &other);
170 ~QOpenGLFramebufferObjectFormat();
171
172 void setSamples(int samples);
173 int samples() const;
174
175 void setMipmap(bool enabled);
176 bool mipmap() const;
177
178 void setAttachment(QOpenGLFramebufferObject::Attachment attachment);
179 QOpenGLFramebufferObject::Attachment attachment() const;
180
181 void setTextureTarget(GLenum target);
182 GLenum textureTarget() const;
183
184 void setInternalTextureFormat(GLenum internalTextureFormat);
185 GLenum internalTextureFormat() const;
186
187 bool operator==(const QOpenGLFramebufferObjectFormat& other) const;
188 bool operator!=(const QOpenGLFramebufferObjectFormat& other) const;
189
190private:
191 QOpenGLFramebufferObjectFormatPrivate *d;
192
193 void detach();
194};
195
196QT_END_NAMESPACE
197
198#endif // QT_NO_OPENGL
199
200#endif // QOPENGLFRAMEBUFFEROBJECT_H
201

source code of qtbase/src/gui/opengl/qopenglframebufferobject.h