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