Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qopenglframebufferobject.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QOPENGLFRAMEBUFFEROBJECT_H
6#define QOPENGLFRAMEBUFFEROBJECT_H
7
8#include <QtOpenGL/qtopenglglobal.h>
9
10#include <QtGui/qopengl.h>
11#include <QtGui/qpaintdevice.h>
12
13#include <QtCore/qscopedpointer.h>
14
15#if defined(Q_QDOC)
16#undef GLuint
17typedef unsigned int GLuint;
18#undef GLenum
19typedef unsigned int GLenum;
20#undef GL_TEXTURE_2D
21#define GL_TEXTURE_2D 0x0DE1
22#undef GLbitfield
23typedef unsigned int GLbitfield;
24#endif
25
26QT_BEGIN_NAMESPACE
27
28class QOpenGLFramebufferObjectPrivate;
29class QOpenGLFramebufferObjectFormat;
30
31class Q_OPENGL_EXPORT QOpenGLFramebufferObject
32{
33 Q_DECLARE_PRIVATE(QOpenGLFramebufferObject)
34public:
35 enum Attachment {
36 NoAttachment,
37 CombinedDepthStencil,
38 Depth
39 };
40
41 explicit QOpenGLFramebufferObject(const QSize &size, GLenum target = GL_TEXTURE_2D);
42 QOpenGLFramebufferObject(int width, int height, GLenum target = GL_TEXTURE_2D);
43
44 QOpenGLFramebufferObject(const QSize &size, Attachment attachment,
45 GLenum target = GL_TEXTURE_2D, GLenum internalFormat = 0);
46 QOpenGLFramebufferObject(int width, int height, Attachment attachment,
47 GLenum target = GL_TEXTURE_2D, GLenum internalFormat = 0);
48
49 QOpenGLFramebufferObject(const QSize &size, const QOpenGLFramebufferObjectFormat &format);
50 QOpenGLFramebufferObject(int width, int height, const QOpenGLFramebufferObjectFormat &format);
51
52 virtual ~QOpenGLFramebufferObject();
53
54 void addColorAttachment(const QSize &size, GLenum internalFormat = 0);
55 void addColorAttachment(int width, int height, GLenum internalFormat = 0);
56
57 QOpenGLFramebufferObjectFormat format() const;
58
59 bool isValid() const;
60 bool isBound() const;
61 bool bind();
62 bool release();
63
64 int width() const { return size().width(); }
65 int height() const { return size().height(); }
66
67 GLuint texture() const;
68 QList<GLuint> textures() const;
69
71 GLuint takeTexture(int colorAttachmentIndex);
72
73 QSize size() const;
74 QList<QSize> sizes() const;
75
76 QImage toImage(bool flipped = true) const;
77 QImage toImage(bool flipped, int colorAttachmentIndex) const;
78
79 Attachment attachment() const;
80 void setAttachment(Attachment attachment);
81
82 GLuint handle() const;
83
84 static bool bindDefault();
85
86 static bool hasOpenGLFramebufferObjects();
87
88 static bool hasOpenGLFramebufferBlit();
89
95
96 static void blitFramebuffer(QOpenGLFramebufferObject *target, const QRect &targetRect,
97 QOpenGLFramebufferObject *source, const QRect &sourceRect,
98 GLbitfield buffers,
99 GLenum filter,
100 int readColorAttachmentIndex,
101 int drawColorAttachmentIndex,
102 FramebufferRestorePolicy restorePolicy);
103 static void blitFramebuffer(QOpenGLFramebufferObject *target, const QRect &targetRect,
104 QOpenGLFramebufferObject *source, const QRect &sourceRect,
105 GLbitfield buffers,
106 GLenum filter,
107 int readColorAttachmentIndex,
108 int drawColorAttachmentIndex);
109 static void blitFramebuffer(QOpenGLFramebufferObject *target, const QRect &targetRect,
110 QOpenGLFramebufferObject *source, const QRect &sourceRect,
111 GLbitfield buffers = GL_COLOR_BUFFER_BIT,
112 GLenum filter = GL_NEAREST);
113 static void blitFramebuffer(QOpenGLFramebufferObject *target,
114 QOpenGLFramebufferObject *source,
115 GLbitfield buffers = GL_COLOR_BUFFER_BIT,
116 GLenum filter = GL_NEAREST);
117
118private:
119 Q_DISABLE_COPY(QOpenGLFramebufferObject)
120 QScopedPointer<QOpenGLFramebufferObjectPrivate> d_ptr;
121 friend class QOpenGLPaintDevice;
123};
124
127{
128public:
129 QOpenGLFramebufferObjectFormat();
130 QOpenGLFramebufferObjectFormat(const QOpenGLFramebufferObjectFormat &other);
131 QOpenGLFramebufferObjectFormat &operator=(const QOpenGLFramebufferObjectFormat &other);
132 ~QOpenGLFramebufferObjectFormat();
133
134 void setSamples(int samples);
135 int samples() const;
136
137 void setMipmap(bool enabled);
138 bool mipmap() const;
139
140 void setAttachment(QOpenGLFramebufferObject::Attachment attachment);
141 QOpenGLFramebufferObject::Attachment attachment() const;
142
143 void setTextureTarget(GLenum target);
144 GLenum textureTarget() const;
145
146 void setInternalTextureFormat(GLenum internalTextureFormat);
147 GLenum internalTextureFormat() const;
148
149 bool operator==(const QOpenGLFramebufferObjectFormat& other) const;
150 bool operator!=(const QOpenGLFramebufferObjectFormat& other) const;
151
152private:
153 QOpenGLFramebufferObjectFormatPrivate *d;
154
155 void detach();
156};
157
158QT_END_NAMESPACE
159
160#endif // QOPENGLFRAMEBUFFEROBJECT_H
QByteArray format() const
Returns the format QImageReader uses for reading images.
QSize size() const
Returns the size of the image, without actually reading the image contents.
The QOpenGLFramebufferObjectFormat class specifies the format of an OpenGL framebuffer object.
bool checkFramebufferStatus(QOpenGLContext *ctx) const
The QOpenGLFramebufferObject class encapsulates an OpenGL framebuffer object.
Attachment attachment() const
Returns the status of the depth and stencil buffers attached to this framebuffer object.
QImage toImage(bool flipped, int colorAttachmentIndex) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static void blitFramebuffer(QOpenGLFramebufferObject *target, const QRect &targetRect, QOpenGLFramebufferObject *source, const QRect &sourceRect, GLbitfield buffers, GLenum filter, int readColorAttachmentIndex, int drawColorAttachmentIndex, FramebufferRestorePolicy restorePolicy)
QOpenGLFramebufferObject(int width, int height, GLenum target=GL_TEXTURE_2D)
Constructs an OpenGL framebuffer object and binds a 2D OpenGL texture to the buffer of the given widt...
static bool bindDefault()
Switches rendering back to the default, windowing system provided framebuffer.
void setAttachment(Attachment attachment)
Sets the attachments of the framebuffer object to attachment.
GLuint takeTexture()
Returns the texture id for the texture attached to this framebuffer object.
QOpenGLFramebufferObject(const QSize &size, Attachment attachment, GLenum target=GL_TEXTURE_2D, GLenum internalFormat=0)
Constructs an OpenGL framebuffer object and binds a texture to the buffer of the given size.
GLuint takeTexture(int colorAttachmentIndex)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static bool hasOpenGLFramebufferBlit()
Returns true if the OpenGL {GL_EXT_framebuffer_blit} extension is present on this system; otherwise r...
void addColorAttachment(const QSize &size, GLenum internalFormat=0)
Creates and attaches an additional texture or renderbuffer of size width and height.
QOpenGLFramebufferObject(int width, int height, Attachment attachment, GLenum target=GL_TEXTURE_2D, GLenum internalFormat=0)
Constructs an OpenGL framebuffer object and binds a texture to the buffer of the given width and heig...
bool release()
Switches rendering back to the default, windowing system provided framebuffer.
QOpenGLFramebufferObject(const QSize &size, GLenum target=GL_TEXTURE_2D)
Constructs an OpenGL framebuffer object and binds a 2D OpenGL texture to the buffer of the size size.
bool isBound() const
Returns true if the framebuffer object is currently bound to the current context, otherwise false is ...
GLuint handle() const
Returns the OpenGL framebuffer object handle for this framebuffer object (returned by the {glGenFrame...
QImage toImage(bool flipped=true) const
Returns the contents of this framebuffer object as a QImage.
QOpenGLFramebufferObject(int width, int height, const QOpenGLFramebufferObjectFormat &format)
Constructs an OpenGL framebuffer object of the given width and height based on the supplied format.
static bool hasOpenGLFramebufferObjects()
Returns true if the OpenGL {GL_EXT_framebuffer_object} extension is present on this system; otherwise...
GLuint texture() const
Returns the texture id for the texture attached as the default rendering target in this framebuffer o...
QList< GLuint > textures() const
Returns the texture id for all attached textures.
void addColorAttachment(int width, int height, GLenum internalFormat=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool bind()
Switches rendering from the default, windowing system provided framebuffer to this framebuffer object...
QOpenGLFramebufferObject(const QSize &size, const QOpenGLFramebufferObjectFormat &format)
Constructs an OpenGL framebuffer object of the given size based on the supplied format.
qreal width() const
Returns the width of the generated outlines.
virtual bool isValid() const
Combined button and popup list for selecting options.
Q_TRACE_METADATA(qtcore, "ENUM { AUTO, RANGE User ... MaxUser } QEvent::Type;")
#define GL_CONTEXT_LOST
Definition qopengl.cpp:30
#define GL_RENDERBUFFER_SAMPLES
#define GL_DEPTH24_STENCIL8
#define GL_RGBA16F
Definition qopenglext.h:913
#define GL_RGB16F
Definition qopenglext.h:914
#define GL_BGRA
Definition qopenglext.h:97
#define GL_DRAW_FRAMEBUFFER
#define GL_MAX_SAMPLES
#define GL_HALF_FLOAT
#define GL_READ_FRAMEBUFFER
#define GL_RGBA32F
Definition qopenglext.h:911
#define GL_DEPTH_COMPONENT24
Definition qopenglext.h:329
#define GL_RGB32F
Definition qopenglext.h:912
#define GL_UNSIGNED_INT_8_8_8_8_REV
Definition qopenglext.h:94
#define GL_RGB10
#define GL_RGB16
#define QT_RESET_GLERROR()
#define GL_RGB8
#define QT_CHECK_GLERROR()
Q_TRACE_PARAM_REPLACE(GLenum, int)
#define GL_RGBA16
#define GL_UNSIGNED_INT_2_10_10_10_REV
#define GL_RGBA8
QFixed height() const