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 QOPENGL_EXTENSIONS_P_H
41 #define QOPENGL_EXTENSIONS_P_H
42 
43 //
44 //  W A R N I N G
45 //  -------------
46 //
47 // This file is not part of the Qt API.  It exists for the convenience
48 // of the Qt OpenGL classes.  This header file may change from
49 // version to version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <QtGui/private/qtguiglobal_p.h>
55 #include "qopenglextrafunctions.h"
56 
57 QT_BEGIN_NAMESPACE
58 
59 class QOpenGLExtensionsPrivate;
60 
61 class Q_GUI_EXPORT QOpenGLExtensions : public QOpenGLExtraFunctions
62 {
63     Q_DECLARE_PRIVATE(QOpenGLExtensions)
64 public:
65     QOpenGLExtensions();
66     QOpenGLExtensions(QOpenGLContext *context);
~QOpenGLExtensions()67     ~QOpenGLExtensions() {}
68 
69     enum OpenGLExtension {
70         TextureRectangle        = 0x00000001,
71         GenerateMipmap          = 0x00000002,
72         TextureCompression      = 0x00000004,
73         MirroredRepeat          = 0x00000008,
74         FramebufferMultisample  = 0x00000010,
75         StencilTwoSide          = 0x00000020,
76         StencilWrap             = 0x00000040,
77         PackedDepthStencil      = 0x00000080,
78         NVFloatBuffer           = 0x00000100,
79         PixelBufferObject       = 0x00000200,
80         FramebufferBlit         = 0x00000400,
81         BGRATextureFormat       = 0x00000800,
82         DDSTextureCompression   = 0x00001000,
83         ETC1TextureCompression  = 0x00002000,
84         PVRTCTextureCompression = 0x00004000,
85         ElementIndexUint        = 0x00008000,
86         Depth24                 = 0x00010000,
87         SRGBFrameBuffer         = 0x00020000,
88         MapBuffer               = 0x00040000,
89         GeometryShaders         = 0x00080000,
90         MapBufferRange          = 0x00100000,
91         Sized8Formats           = 0x00200000,
92         DiscardFramebuffer      = 0x00400000,
93         Sized16Formats          = 0x00800000,
94         TextureSwizzle          = 0x01000000,
95     };
96     Q_DECLARE_FLAGS(OpenGLExtensions, OpenGLExtension)
97 
98     OpenGLExtensions openGLExtensions();
99     bool hasOpenGLExtension(QOpenGLExtensions::OpenGLExtension extension) const;
100 
101     GLvoid *glMapBuffer(GLenum target, GLenum access);
102     void glGetBufferSubData(GLenum target, qopengl_GLintptr offset, qopengl_GLsizeiptr size, GLvoid *data);
103     void glDiscardFramebufferEXT (GLenum target, GLsizei numAttachments, const GLenum *attachments);
104 
105     void flushShared();
106 
107     QOpenGLExtensionsPrivate *d() const;
108 
109 private:
isInitialized(const QOpenGLFunctionsPrivate * d)110     static bool isInitialized(const QOpenGLFunctionsPrivate *d) { return d != nullptr; }
111 };
112 
Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLExtensions::OpenGLExtensions)113 Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLExtensions::OpenGLExtensions)
114 
115 class QOpenGLExtensionsPrivate : public QOpenGLExtraFunctionsPrivate
116 {
117 public:
118     explicit QOpenGLExtensionsPrivate(QOpenGLContext *ctx);
119 
120     GLvoid* (QOPENGLF_APIENTRYP MapBuffer)(GLenum target, GLenum access);
121     void (QOPENGLF_APIENTRYP GetBufferSubData)(GLenum target, qopengl_GLintptr offset, qopengl_GLsizeiptr size, GLvoid *data);
122     void (QOPENGLF_APIENTRYP DiscardFramebuffer)(GLenum target, GLsizei numAttachments, const GLenum *attachments);
123 
124     bool flushVendorChecked;
125     bool flushIsSufficientToSyncContexts;
126 };
127 
d()128 inline QOpenGLExtensionsPrivate *QOpenGLExtensions::d() const
129 {
130     return static_cast<QOpenGLExtensionsPrivate *>(d_ptr);
131 }
132 
glMapBuffer(GLenum target,GLenum access)133 inline GLvoid *QOpenGLExtensions::glMapBuffer(GLenum target, GLenum access)
134 {
135     Q_D(QOpenGLExtensions);
136     Q_ASSERT(QOpenGLExtensions::isInitialized(d));
137     GLvoid *result = d->MapBuffer(target, access);
138     Q_OPENGL_FUNCTIONS_DEBUG
139     return result;
140 }
141 
glGetBufferSubData(GLenum target,qopengl_GLintptr offset,qopengl_GLsizeiptr size,GLvoid * data)142 inline void QOpenGLExtensions::glGetBufferSubData(GLenum target, qopengl_GLintptr offset, qopengl_GLsizeiptr size, GLvoid *data)
143 {
144     Q_D(QOpenGLExtensions);
145     Q_ASSERT(QOpenGLExtensions::isInitialized(d));
146     d->GetBufferSubData(target, offset, size, data);
147     Q_OPENGL_FUNCTIONS_DEBUG
148 }
149 
150 
glDiscardFramebufferEXT(GLenum target,GLsizei numAttachments,const GLenum * attachments)151 inline void QOpenGLExtensions::glDiscardFramebufferEXT (GLenum target, GLsizei numAttachments, const GLenum *attachments)
152 {
153     Q_D(QOpenGLExtensions);
154     Q_ASSERT(QOpenGLExtensions::isInitialized(d));
155     d->DiscardFramebuffer(target,numAttachments, attachments);
156     Q_OPENGL_FUNCTIONS_DEBUG
157 }
158 QT_END_NAMESPACE
159 
160 #endif // QOPENGL_EXTENSIONS_P_H
161