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
4#ifndef QOPENGLWIDGET_H
5#define QOPENGLWIDGET_H
6
7#include <QtOpenGLWidgets/qtopenglwidgetsglobal.h>
8
9#include <QtWidgets/QWidget>
10#include <QtGui/QSurfaceFormat>
11#include <QtGui/qopengl.h>
12
13QT_BEGIN_NAMESPACE
14
15class QOpenGLWidgetPrivate;
16
17class Q_OPENGLWIDGETS_EXPORT QOpenGLWidget : public QWidget
18{
19 Q_OBJECT
20 Q_DECLARE_PRIVATE(QOpenGLWidget)
21
22public:
23 enum UpdateBehavior {
24 NoPartialUpdate,
25 PartialUpdate
26 };
27 Q_ENUM(UpdateBehavior)
28
29 enum TargetBuffer : uint8_t {
30 LeftBuffer = 0, // Default
31 RightBuffer // Only used when QSurfaceFormat::StereoBuffers is enabled
32 };
33 Q_ENUM(TargetBuffer)
34
35 explicit QOpenGLWidget(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
36 ~QOpenGLWidget();
37
38 void setUpdateBehavior(UpdateBehavior updateBehavior);
39 UpdateBehavior updateBehavior() const;
40
41 void setFormat(const QSurfaceFormat &format);
42 QSurfaceFormat format() const;
43
44 GLenum textureFormat() const;
45 void setTextureFormat(GLenum texFormat);
46
47 bool isValid() const;
48
49 void makeCurrent();
50 void makeCurrent(TargetBuffer targetBuffer);
51 void doneCurrent();
52
53 QOpenGLContext *context() const;
54 GLuint defaultFramebufferObject() const;
55 GLuint defaultFramebufferObject(TargetBuffer targetBuffer) const;
56
57 QImage grabFramebuffer();
58 QImage grabFramebuffer(TargetBuffer targetBuffer);
59
60 TargetBuffer currentTargetBuffer() const;
61
62Q_SIGNALS:
63 void aboutToCompose();
64 void frameSwapped();
65 void aboutToResize();
66 void resized();
67
68protected:
69 virtual void initializeGL();
70 virtual void resizeGL(int w, int h);
71 virtual void paintGL();
72
73 void paintEvent(QPaintEvent *e) override;
74 void resizeEvent(QResizeEvent *e) override;
75 bool event(QEvent *e) override;
76
77 int metric(QPaintDevice::PaintDeviceMetric metric) const override;
78 QPaintDevice *redirected(QPoint *p) const override;
79 QPaintEngine *paintEngine() const override;
80
81private:
82 Q_DISABLE_COPY(QOpenGLWidget)
83};
84
85QT_END_NAMESPACE
86
87#endif // QOPENGLWIDGET_H
88

source code of qtbase/src/openglwidgets/qopenglwidget.h