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 QtQuick 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#ifndef QSGOPENGLLAYER_P_H
40#define QSGOPENGLLAYER_P_H
41
42//
43// W A R N I N G
44// -------------
45//
46// This file is not part of the Qt API. It exists purely as an
47// implementation detail. This header file may change from version to
48// version without notice, or even be removed.
49//
50// We mean it.
51//
52
53#include <private/qsgadaptationlayer_p.h>
54#include <private/qsgcontext_p.h>
55#include <private/qsgtexture_p.h>
56#include <qsgsimplerectnode.h>
57
58QT_BEGIN_NAMESPACE
59
60#define QSG_DEBUG_FBO_OVERLAY
61
62class QOpenGLFramebufferObject;
63class QSGDepthStencilBuffer;
64class QSGDefaultRenderContext;
65class QSGOpenGLLayerPrivate;
66
67class Q_QUICK_PRIVATE_EXPORT QSGOpenGLLayer : public QSGLayer
68{
69 Q_DECLARE_PRIVATE(QSGOpenGLLayer)
70 Q_OBJECT
71public:
72 QSGOpenGLLayer(QSGRenderContext *context);
73 ~QSGOpenGLLayer();
74
75 bool updateTexture() override;
76
77 // The item's "paint node", not effect node.
78 QSGNode *item() const { return m_item; }
79 void setItem(QSGNode *item) override;
80
81 QRectF rect() const { return m_rect; }
82 void setRect(const QRectF &rect) override;
83
84 QSize size() const { return m_size; }
85 void setSize(const QSize &size) override;
86
87 void setHasMipmaps(bool mipmap) override;
88
89 void bind() override;
90
91 bool hasAlphaChannel() const override;
92 bool hasMipmaps() const override;
93 int textureId() const override;
94 QSize textureSize() const override { return m_size; }
95
96 GLenum format() const { return m_format; }
97 void setFormat(GLenum format) override;
98
99 bool live() const { return bool(m_live); }
100 void setLive(bool live) override;
101
102 bool recursive() const { return bool(m_recursive); }
103 void setRecursive(bool recursive) override;
104
105 void setDevicePixelRatio(qreal ratio) override { m_device_pixel_ratio = ratio; }
106
107 bool mirrorHorizontal() const { return bool(m_mirrorHorizontal); }
108 void setMirrorHorizontal(bool mirror) override;
109
110 bool mirrorVertical() const { return bool(m_mirrorVertical); }
111 void setMirrorVertical(bool mirror) override;
112
113 void scheduleUpdate() override;
114
115 QImage toImage() const override;
116
117 QRectF normalizedTextureSubRect() const override;
118
119 int samples() const { return m_samples; }
120 void setSamples(int samples) override { m_samples = samples; }
121
122public Q_SLOTS:
123 void markDirtyTexture() override;
124 void invalidated() override;
125
126private:
127 void grab();
128
129 QSGNode *m_item;
130 QRectF m_rect;
131 QSize m_size;
132 qreal m_device_pixel_ratio;
133 GLenum m_format;
134
135 QSGRenderer *m_renderer;
136 QOpenGLFramebufferObject *m_fbo;
137 QOpenGLFramebufferObject *m_secondaryFbo;
138 QSharedPointer<QSGDepthStencilBuffer> m_depthStencilBuffer;
139
140 GLuint m_transparentTexture;
141
142#ifdef QSG_DEBUG_FBO_OVERLAY
143 QSGSimpleRectNode *m_debugOverlay;
144#endif
145
146 QSGDefaultRenderContext *m_context;
147 int m_samples;
148
149 uint m_mipmap : 1;
150 uint m_live : 1;
151 uint m_recursive : 1;
152 uint m_dirtyTexture : 1;
153 uint m_multisamplingChecked : 1;
154 uint m_multisampling : 1;
155 uint m_grab : 1;
156 uint m_mirrorHorizontal : 1;
157 uint m_mirrorVertical : 1;
158};
159
160class QSGOpenGLLayerPrivate : public QSGTexturePrivate
161{
162 Q_DECLARE_PUBLIC(QSGOpenGLLayer)
163public:
164 int comparisonKey() const override;
165};
166
167QT_END_NAMESPACE
168
169#endif // QSGOPENGLLAYER_P_H
170