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 QOPENGL_H
5#define QOPENGL_H
6
7#include <QtGui/qtguiglobal.h>
8
9#ifndef QT_NO_OPENGL
10
11// Windows always needs this to ensure that APIENTRY gets defined
12#if defined(Q_OS_WIN)
13# include <QtCore/qt_windows.h>
14#endif
15
16// Note: Apple is a "controlled platform" for OpenGL ABI so we
17// use the system provided headers there. Controlled means that the
18// headers always match the actual driver implementation so there
19// is no possibility of drivers exposing additional functionality
20// from the system headers. Also it means that the vendor can
21// (and does) make different choices about some OpenGL types. For
22// e.g. Apple uses void* for GLhandleARB whereas other platforms
23// use unsigned int.
24//
25// For the "uncontrolled" Windows and Linux platforms we use the
26// official Khronos headers. On these platforms this gives
27// access to additional functionality the drivers may expose but
28// which the system headers do not.
29
30#if QT_CONFIG(opengles2)
31# if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
32# if QT_CONFIG(opengles3)
33# include <OpenGLES/ES3/gl.h>
34# include <OpenGLES/ES3/glext.h>
35# else
36# include <OpenGLES/ES2/gl.h>
37# include <OpenGLES/ES2/glext.h>
38# endif
39
40/*
41 OES_EGL_image_external is not included in the Apple provided
42 system headers yet, but we define the missing typedef so that
43 the qopenglextensions.cpp code will magically work once Apple
44 include the extension in their drivers.
45*/
46typedef void* GLeglImageOES;
47
48# elif !defined(Q_OS_DARWIN) // "uncontrolled" ES2 platforms
49
50// In "es2" builds (QT_CONFIG(opengles2)) additional defines indicate GLES 3.0 or
51// higher is available *at build time*. In this case include the corresponding
52// header. These are backwards compatible and it should be safe to include
53// headers on top of each other, meaning that applications can include gl2.h
54// even if gl31.h gets included here.
55
56// NB! The fact that Qt was built against an SDK with GLES 2 only does not mean
57// applications cannot be deployed on a GLES 3 system. Therefore
58// QOpenGLFunctions and friends must do everything dynamically and must not rely
59// on these macros, except in special cases for controlled build/run environments.
60
61// Some Khronos headers use the ext proto guard in the standard headers as well,
62// which is bad. Work it around, but avoid spilling over to the ext header.
63# ifndef GL_GLEXT_PROTOTYPES
64# define GL_GLEXT_PROTOTYPES
65# define QGL_TEMP_GLEXT_PROTO
66# endif
67
68# if QT_CONFIG(opengles32)
69# include <GLES3/gl32.h>
70# elif QT_CONFIG(opengles31)
71# include <GLES3/gl31.h>
72# elif QT_CONFIG(opengles3)
73# include <GLES3/gl3.h>
74# else
75# include <GLES2/gl2.h>
76# endif
77
78# ifdef QGL_TEMP_GLEXT_PROTO
79# undef GL_GLEXT_PROTOTYPES
80# undef QGL_TEMP_GLEXT_PROTO
81# endif
82
83/*
84 Some GLES2 implementations (like the one on Harmattan) are missing the
85 typedef for GLchar. Work around it here by adding it. The Kkronos headers
86 specify GLChar as a typedef to char, so if an implementation already
87 provides it, then this doesn't do any harm.
88*/
89typedef char GLchar;
90
91# include <QtGui/qopengles2ext.h>
92# endif
93#else // non-ES2 platforms
94# if defined(Q_OS_MACOS)
95# include <OpenGL/gl.h>
96# define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
97# include <OpenGL/gl3.h>
98# include <OpenGL/glext.h>
99# else
100# define GL_GLEXT_LEGACY // Prevents GL/gl.h from #including system glext.h
101// Some Khronos headers use the ext proto guard in the standard headers as well,
102// which is bad. Work it around, but avoid spilling over to the ext header.
103# ifndef GL_GLEXT_PROTOTYPES
104# define GL_GLEXT_PROTOTYPES
105# include <GL/gl.h>
106# undef GL_GLEXT_PROTOTYPES
107# else
108# include <GL/gl.h>
109# endif
110# include <QtGui/qopenglext.h>
111# endif
112#endif // !QT_CONFIG(opengles2)
113
114// Desktops can support OpenGL 4.
115#if !QT_CONFIG(opengles2)
116#define QT_OPENGL_3
117#define QT_OPENGL_3_2
118#define QT_OPENGL_4
119# if !defined(Q_OS_MAC)
120# define QT_OPENGL_4_3
121# endif
122#endif
123
124
125// When all else fails we provide sensible fallbacks - this is needed to
126// allow compilation on OS X 10.6
127#if !QT_CONFIG(opengles2)
128
129// OS X 10.6 doesn't define these which are needed below
130// OS X 10.7 and later define them in gl3.h
131#ifndef APIENTRY
132#define APIENTRY
133#endif
134#ifndef APIENTRYP
135#define APIENTRYP APIENTRY *
136#endif
137#ifndef GLAPI
138#define GLAPI extern
139#endif
140
141
142// This block is copied from glext.h and defines the types needed by
143// a few extension classes.
144
145#include <stddef.h>
146#ifndef GL_VERSION_2_0
147/* GL type for program/shader text */
148typedef char GLchar;
149#endif
150
151#ifndef GL_VERSION_1_5
152/* GL types for handling large vertex buffer objects */
153typedef ptrdiff_t GLintptr;
154typedef ptrdiff_t GLsizeiptr;
155#endif
156
157#ifndef GL_ARB_vertex_buffer_object
158/* GL types for handling large vertex buffer objects */
159typedef ptrdiff_t GLintptrARB;
160typedef ptrdiff_t GLsizeiptrARB;
161#endif
162
163#ifndef GL_ARB_shader_objects
164/* GL types for program/shader text and shader object handles */
165typedef char GLcharARB;
166# ifdef Q_OS_DARWIN
167typedef void *GLhandleARB;
168# else
169typedef unsigned int GLhandleARB;
170# endif // Q_OS_DARWIN
171#endif
172
173/* GL type for "half" precision (s10e5) float data in host memory */
174#ifndef GL_ARB_half_float_pixel
175typedef unsigned short GLhalfARB;
176#endif
177
178#ifndef GL_NV_half_float
179typedef unsigned short GLhalfNV;
180#endif
181
182#ifndef GLEXT_64_TYPES_DEFINED
183/* This code block is duplicated in glxext.h, so must be protected */
184#define GLEXT_64_TYPES_DEFINED
185/* Define int32_t, int64_t, and uint64_t types for UST/MSC */
186/* (as used in the GL_EXT_timer_query extension). */
187#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
188#include <inttypes.h>
189#elif defined(__sun__) || defined(__digital__)
190#include <inttypes.h>
191#if defined(__STDC__)
192#if defined(__arch64__) || defined(_LP64)
193typedef long int int64_t;
194typedef unsigned long int uint64_t;
195#else
196typedef long long int int64_t;
197typedef unsigned long long int uint64_t;
198#endif /* __arch64__ */
199#endif /* __STDC__ */
200#elif defined(__UNIXOS2__) || defined(__SOL64__)
201typedef long int int32_t;
202typedef long long int int64_t;
203typedef unsigned long long int uint64_t;
204#elif defined(_WIN32) && (defined(__GNUC__) || defined(_MSC_VER))
205#include <stdint.h>
206#elif defined(_WIN32)
207typedef __int32 int32_t;
208typedef __int64 int64_t;
209typedef unsigned __int64 uint64_t;
210#else
211/* Fallback if nothing above works */
212#include <inttypes.h>
213#endif
214#endif
215
216#ifndef GL_EXT_timer_query
217typedef int64_t GLint64EXT;
218typedef uint64_t GLuint64EXT;
219#endif
220
221#ifndef GL_ARB_sync
222typedef int64_t GLint64;
223typedef uint64_t GLuint64;
224typedef struct __GLsync *GLsync;
225#endif
226
227#ifndef GL_ARB_cl_event
228/* These incomplete types let us declare types compatible with OpenCL's cl_context and cl_event */
229struct _cl_context;
230struct _cl_event;
231#endif
232
233#ifndef GL_ARB_debug_output
234typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const GLvoid *userParam);
235#endif
236
237#ifndef GL_AMD_debug_output
238typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
239#endif
240
241#ifndef GL_KHR_debug
242typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const GLvoid *userParam);
243#endif
244
245#ifndef GL_NV_vdpau_interop
246typedef GLintptr GLvdpauSurfaceNV;
247#endif
248
249// End of block copied from glext.h
250#endif
251
252QT_BEGIN_NAMESPACE
253
254// Types that aren't defined in all system's gl.h files.
255typedef ptrdiff_t qopengl_GLintptr;
256typedef ptrdiff_t qopengl_GLsizeiptr;
257
258
259#if defined(APIENTRY) && !defined(QOPENGLF_APIENTRY)
260# define QOPENGLF_APIENTRY APIENTRY
261#endif
262
263# ifndef QOPENGLF_APIENTRYP
264# ifdef QOPENGLF_APIENTRY
265# define QOPENGLF_APIENTRYP QOPENGLF_APIENTRY *
266# else
267# define QOPENGLF_APIENTRY
268# define QOPENGLF_APIENTRYP *
269# endif
270# endif
271
272QT_END_NAMESPACE
273
274#endif // QT_NO_OPENGL
275
276#endif // QOPENGL_H
277

source code of qtbase/src/gui/opengl/qopengl.h