1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB).
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 QOPENGLQUERYHELPER_P_H
41 #define QOPENGLQUERYHELPER_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 purely as an
48 // implementation detail.  This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <QtGui/private/qtguiglobal_p.h>
55 
56 #if !defined(QT_OPENGL_ES_2)
57 
58 #include <QtGui/QOpenGLContext>
59 
60 QT_BEGIN_NAMESPACE
61 
62 // Helper class used by QOpenGLTimerQuery and later will be used by
63 // QOpenGLOcclusionQuery
64 class QOpenGLQueryHelper
65 {
66 public:
QOpenGLQueryHelper(QOpenGLContext * context)67     QOpenGLQueryHelper(QOpenGLContext *context)
68         : GetQueryObjectuiv(nullptr),
69           GetQueryObjectiv(nullptr),
70           GetQueryiv(nullptr),
71           EndQuery(nullptr),
72           BeginQuery(nullptr),
73           IsQuery(nullptr),
74           DeleteQueries(nullptr),
75           GenQueries(nullptr),
76           GetInteger64v(nullptr),
77           GetQueryObjectui64v(nullptr),
78           GetQueryObjecti64v(nullptr),
79           QueryCounter(nullptr)
80     {
81         Q_ASSERT(context);
82 
83         // Core in OpenGL >=1.5
84         GetQueryObjectuiv = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint , GLenum , GLuint *)>(context->getProcAddress("glGetQueryObjectuiv"));
85         GetQueryObjectiv = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint , GLenum , GLint *)>(context->getProcAddress("glGetQueryObjectiv"));
86         GetQueryiv = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLenum , GLenum , GLint *)>(context->getProcAddress("glGetQueryiv"));
87         EndQuery = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLenum )>(context->getProcAddress("glEndQuery"));
88         BeginQuery = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLenum , GLuint )>(context->getProcAddress("glBeginQuery"));
89         IsQuery = reinterpret_cast<GLboolean (QOPENGLF_APIENTRYP)(GLuint )>(context->getProcAddress("glIsQuery"));
90         DeleteQueries = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , const GLuint *)>(context->getProcAddress("glDeleteQueries"));
91         GenQueries = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , GLuint *)>(context->getProcAddress("glGenQueries"));
92 
93         // Core in OpenGL >=3.2
94         GetInteger64v = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLenum , GLint64 *)>(context->getProcAddress("glGetInteger64v"));
95 
96         // Core in OpenGL >=3.3 / ARB_timer_query
97         GetQueryObjectui64v = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint , GLenum , GLuint64 *)>(context->getProcAddress("glGetQueryObjectui64v"));
98         GetQueryObjecti64v = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint , GLenum , GLint64 *)>(context->getProcAddress("glGetQueryObjecti64v"));
99         QueryCounter = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint , GLenum )>(context->getProcAddress("glQueryCounter"));
100     }
101 
glGetQueryObjectuiv(GLuint id,GLenum pname,GLuint * params)102     inline void glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
103     {
104         GetQueryObjectuiv(id, pname, params);
105     }
106 
glGetQueryObjectiv(GLuint id,GLenum pname,GLint * params)107     inline void glGetQueryObjectiv(GLuint id, GLenum pname, GLint *params)
108     {
109         GetQueryObjectiv(id, pname, params);
110     }
111 
glGetQueryiv(GLenum target,GLenum pname,GLint * params)112     inline void glGetQueryiv(GLenum target, GLenum pname, GLint *params)
113     {
114         GetQueryiv(target, pname, params);
115     }
116 
glEndQuery(GLenum target)117     inline void glEndQuery(GLenum target)
118     {
119         EndQuery(target);
120     }
121 
glBeginQuery(GLenum target,GLuint id)122     inline void glBeginQuery(GLenum target, GLuint id)
123     {
124         BeginQuery(target, id);
125     }
126 
glIsQuery(GLuint id)127     inline GLboolean glIsQuery(GLuint id)
128     {
129         return IsQuery(id);
130     }
131 
glDeleteQueries(GLsizei n,const GLuint * ids)132     inline void glDeleteQueries(GLsizei n, const GLuint *ids)
133     {
134         DeleteQueries(n, ids);
135     }
136 
glGenQueries(GLsizei n,GLuint * ids)137     inline void glGenQueries(GLsizei n, GLuint *ids)
138     {
139         GenQueries(n, ids);
140     }
141 
glGetInteger64v(GLenum pname,GLint64 * params)142     inline void glGetInteger64v(GLenum pname, GLint64 *params)
143     {
144         GetInteger64v(pname, params);
145     }
146 
glGetQueryObjectui64v(GLuint id,GLenum pname,GLuint64 * params)147     inline void glGetQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
148     {
149         GetQueryObjectui64v(id, pname, params);
150     }
151 
glGetQueryObjecti64v(GLuint id,GLenum pname,GLint64 * params)152     inline void glGetQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
153     {
154         GetQueryObjecti64v(id, pname, params);
155     }
156 
glQueryCounter(GLuint id,GLenum target)157     inline void glQueryCounter(GLuint id, GLenum target)
158     {
159         QueryCounter(id, target);
160     }
161 
162 private:
163     // Core in OpenGL >=1.5
164     void (QOPENGLF_APIENTRYP GetQueryObjectuiv)(GLuint id, GLenum pname, GLuint *params);
165     void (QOPENGLF_APIENTRYP GetQueryObjectiv)(GLuint id, GLenum pname, GLint *params);
166     void (QOPENGLF_APIENTRYP GetQueryiv)(GLenum target, GLenum pname, GLint *params);
167     void (QOPENGLF_APIENTRYP EndQuery)(GLenum target);
168     void (QOPENGLF_APIENTRYP BeginQuery)(GLenum target, GLuint id);
169     GLboolean (QOPENGLF_APIENTRYP IsQuery)(GLuint id);
170     void (QOPENGLF_APIENTRYP DeleteQueries)(GLsizei n, const GLuint *ids);
171     void (QOPENGLF_APIENTRYP GenQueries)(GLsizei n, GLuint *ids);
172 
173     // Core in OpenGL >=3.2
174     void (QOPENGLF_APIENTRYP GetInteger64v)(GLenum pname, GLint64 *params);
175 
176     // Core in OpenGL >=3.3 and provided by ARB_timer_query
177     void (QOPENGLF_APIENTRYP GetQueryObjectui64v)(GLuint id, GLenum pname, GLuint64 *params);
178     void (QOPENGLF_APIENTRYP GetQueryObjecti64v)(GLuint id, GLenum pname, GLint64 *params);
179     void (QOPENGLF_APIENTRYP QueryCounter)(GLuint id, GLenum target);
180 };
181 
182 QT_END_NAMESPACE
183 
184 #endif
185 
186 #endif // QOPENGLQUERYHELPER_P_H
187