1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//
// Copyright 2020 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://opensubdiv.org/license.
//
/// OpenGL Loading Library Support
///
/// An OpenGL loading library is required in order to load extended GL API
/// function entry points at run-time and to define types, enum values,
/// and function prototypes needed at compile-time.
///
/// There are three components to this library:
/// glLoader.h -- interface (this header file)
/// glApi.h -- low-level generated OpenGL API loader
/// khrplatform.h -- khronos.org abstraction for low-level platform types
///
/// To use:
/// - Include "glloader.h"
///
/// - Initialize from example applications or from the library by calling;
///
/// internal::GLLoader::applicationInitializeGL();
/// -or-
/// internal::GLLoader::libraryInitializeGL();
///
/// There are distinct compile-time and run-time requirements for developing
/// OpenGL software which will build and run in a variety of situations.
///
/// 1) Compile-time definitions of core types
///
/// These are the core data types used as the argument and return value types
/// of GL API functions. In this implementation, they are defined in terms
/// of the types defined by Khronos Group in "khrplatform.h"
///
/// These types are defined in the global namespace.
///
/// 2) Compile-time definitions of enum values
///
/// These are GLenum data values used by the GL API. They are implemented
/// as preprocessor definitions, e.g.
///
/// #define GL_UNIFORM_BUFFER 0x8A0F
///
/// These preprocessor symbols are defined in the global namespace.
///
/// 3) Compile-time definitions for versions and extensions
///
/// The GL API and extension specifications specify standard preprocessor
/// symbols which can be tested at compile-time to protect sections of source
/// code which require a specific version or extension, e.g.
///
/// #if defined(GL_VERSION_4_0)
/// // ... GL_VERSION_4_0 specific code
/// #endif
///
/// #if defined(GL_ARB_tessellation_shader)
/// // ... ARB_tessellation_shader specific code
/// #endif
///
/// These preprocessor symbols are defined in the global namespace.
///
/// 4) Compile-time declarations of function prototypes
///
/// Each GL API function has a typedef for the function prototype and
/// a function pointer (initialized to nullptr) which implements the
/// function, e.g.
///
/// typedef void (GLAPIENTRY * PFNGLBINDBUFFERBASEPROC)(
/// GLenum target, GLuint index, GLuint buffer);
/// PFNGLBINDBUFFERBASEPROC glBindBufferBase;
///
/// These types and function pointers are defined in an internal namespace.
///
/// 5) Run-time loading of supported functions
///
/// Because a GL program may be compiled and run in different environments,
/// GL API functions must be loaded dynamically at run time. This is taken
/// care of by executing the low-level OpenGL API loader, e.g.
///
/// bool internal::GLLoader::libraryInitializeGL() {
/// ...
/// glBindBufferBase = (PFNGLBINDBUFFERBASEPROC)
/// loadFunction("glBindBufferBase");
/// ...
/// }
///
/// The loaded function pointers are defined in an internal namespace.
///
/// 6) Run-time queries for supported versions and extensions
///
/// Finally, a GL program should check for the availability of required
/// features at run-time. Typically, this requires inspection of the
/// strings or string lists returned by calling the glGetString functions.
///
/// This loader library processes these queries when loading the GL API
/// and saves the results in boolean variables which follow a naming
/// convention similar to the preprocessor symbols described above.
///
/// This loader further provides macros which wrap evaluation of these
/// boolean variables in order to help isolate source code from details
/// of the specific naming (prefixes, etc) of these variables, e.g.
///
/// #if defined(GL_VERSION_4_0)
/// if (OSD_OPENGL_HAS(VERSION_4_0)) {
/// // ... GL_VERSION_4_0 specific code
/// }
/// #endif
///
/// #if defined(GL_ARB_tessellation_shader)
/// if (OSD_OPENGL_HAS(ARB_tessellation_shader)) {
/// // ... ARB_tessellation_shader specific code
/// }
/// #endif
///
/// The boolean variables described here are defined in an internal namespace.
///
// -- GLAPILOADER
// -- GLEW
namespace OpenSubdiv // namespace OpenSubdiv
using namespace OpenSubdiv::internal::GLApi;
// OPENSUBDIV3_GLLOADER_H