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 QtOpenGL 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 <QtOpenGL/qtopenglglobal.h>
44
45#include <QtGui/qopengl.h>
46#include <QtGui/qpaintdevice.h>
47
48#include <QtCore/qscopedpointer.h>
49
50#if defined(Q_CLANG_QDOC)
51#undef GLuint
52typedef unsigned int GLuint;
53#undef GLenum
54typedef unsigned int GLenum;
55#undef GL_TEXTURE_2D
56#define GL_TEXTURE_2D 0x0DE1
57#undef GLbitfield
58typedef unsigned int GLbitfield;
59#endif
60
61QT_BEGIN_NAMESPACE
62
63class QOpenGLFramebufferObjectPrivate;
64class QOpenGLFramebufferObjectFormat;
65
66class Q_OPENGL_EXPORT QOpenGLFramebufferObject
67{
68 Q_DECLARE_PRIVATE(QOpenGLFramebufferObject)
69public:
70 enum Attachment {
71 NoAttachment,
72 CombinedDepthStencil,
73 Depth
74 };
75
76 explicit QOpenGLFramebufferObject(const QSize &size, GLenum target = GL_TEXTURE_2D);
77 QOpenGLFramebufferObject(int width, int height, GLenum target = GL_TEXTURE_2D);
78
79 QOpenGLFramebufferObject(const QSize &size, Attachment attachment,
80 GLenum target = GL_TEXTURE_2D, GLenum internalFormat = 0);
81 QOpenGLFramebufferObject(int width, int height, Attachment attachment,
82 GLenum target = GL_TEXTURE_2D, GLenum internalFormat = 0);
83
84 QOpenGLFramebufferObject(const QSize &size, const QOpenGLFramebufferObjectFormat &format);
85 QOpenGLFramebufferObject(int width, int height, const QOpenGLFramebufferObjectFormat &format);
86
87 virtual ~QOpenGLFramebufferObject();
88
89 void addColorAttachment(const QSize &size, GLenum internalFormat = 0);
90 void addColorAttachment(int width, int height, GLenum internalFormat = 0);
91
92 QOpenGLFramebufferObjectFormat format() const;
93
94 bool isValid() const;
95 bool isBound() const;
96 bool bind();
97 bool release();
98
99 int width() const { return size().width(); }
100 int height() const { return size().height(); }
101
102 GLuint texture() const;
103 QList<GLuint> textures() const;
104
105 GLuint takeTexture();
106 GLuint takeTexture(int colorAttachmentIndex);
107
108 QSize size() const;
109 QList<QSize> sizes() const;
110
111 QImage toImage(bool flipped = true) const;
112 QImage toImage(bool flipped, int colorAttachmentIndex) const;
113
114 Attachment attachment() const;
115 void setAttachment(Attachment attachment);
116
117 GLuint handle() const;
118
119 static bool bindDefault();
120
121 static bool hasOpenGLFramebufferObjects();
122
123 static bool hasOpenGLFramebufferBlit();
124
125 enum FramebufferRestorePolicy {
126 DontRestoreFramebufferBinding,
127 RestoreFramebufferBindingToDefault,
128 RestoreFrameBufferBinding
129 };
130
131 static void blitFramebuffer(QOpenGLFramebufferObject *target, const QRect &targetRect,
132 QOpenGLFramebufferObject *source, const QRect &sourceRect,
133 GLbitfield buffers,
134 GLenum filter,
135 int readColorAttachmentIndex,
136 int drawColorAttachmentIndex,
137 FramebufferRestorePolicy restorePolicy);
138 static void blitFramebuffer(QOpenGLFramebufferObject *target, const QRect &targetRect,
139 QOpenGLFramebufferObject *source, const QRect &sourceRect,
140 GLbitfield buffers,
141 GLenum filter,
142 int readColorAttachmentIndex,
143 int drawColorAttachmentIndex);
144 static void blitFramebuffer(QOpenGLFramebufferObject *target, const QRect &targetRect,
145 QOpenGLFramebufferObject *source, const QRect &sourceRect,
146 GLbitfield buffers = GL_COLOR_BUFFER_BIT,
147 GLenum filter = GL_NEAREST);
148 static void blitFramebuffer(QOpenGLFramebufferObject *target,
149 QOpenGLFramebufferObject *source,
150 GLbitfield buffers = GL_COLOR_BUFFER_BIT,
151 GLenum filter = GL_NEAREST);
152
153private:
154 Q_DISABLE_COPY(QOpenGLFramebufferObject)
155 QScopedPointer<QOpenGLFramebufferObjectPrivate> d_ptr;
156 friend class QOpenGLPaintDevice;
157 friend class QOpenGLFBOGLPaintDevice;
158};
159
160class QOpenGLFramebufferObjectFormatPrivate;
161class Q_OPENGL_EXPORT QOpenGLFramebufferObjectFormat
162{
163public:
164 QOpenGLFramebufferObjectFormat();
165 QOpenGLFramebufferObjectFormat(const QOpenGLFramebufferObjectFormat &other);
166 QOpenGLFramebufferObjectFormat &operator=(const QOpenGLFramebufferObjectFormat &other);
167 ~QOpenGLFramebufferObjectFormat();
168
169 void setSamples(int samples);
170 int samples() const;
171
172 void setMipmap(bool enabled);
173 bool mipmap() const;
174
175 void setAttachment(QOpenGLFramebufferObject::Attachment attachment);
176 QOpenGLFramebufferObject::Attachment attachment() const;
177
178 void setTextureTarget(GLenum target);
179 GLenum textureTarget() const;
180
181 void setInternalTextureFormat(GLenum internalTextureFormat);
182 GLenum internalTextureFormat() const;
183
184 bool operator==(const QOpenGLFramebufferObjectFormat& other) const;
185 bool operator!=(const QOpenGLFramebufferObjectFormat& other) const;
186
187private:
188 QOpenGLFramebufferObjectFormatPrivate *d;
189
190 void detach();
191};
192
193QT_END_NAMESPACE
194
195#endif // QOPENGLFRAMEBUFFEROBJECT_H
196