1 ##########################################################################
3 # Copyright 2011 Jose Fonseca
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 ##########################################################################/
27 '''Describe GL types.'''
35 GLboolean = Enum("GLboolean", [
40 GLvoid = Alias("GLvoid", Void)
41 GLbyte = Alias("GLbyte", SChar)
42 GLshort = Alias("GLshort", Short)
43 GLint = Alias("GLint", Int)
44 GLint64 = Alias("GLint64", Int64)
45 GLubyte = Alias("GLubyte", UChar)
46 GLushort = Alias("GLushort", UShort)
47 GLuint = Alias("GLuint", UInt)
48 GLuint64 = Alias("GLuint64", UInt64)
49 GLsizei = Alias("GLsizei", Int)
50 GLintptr = Alias("GLintptr", Int)
51 GLsizeiptr = Alias("GLsizeiptr", Int)
52 GLfloat = Alias("GLfloat", Float)
53 GLclampf = Alias("GLclampf", Float)
54 GLdouble = Alias("GLdouble", Double)
55 GLclampd = Alias("GLclampd", Double)
56 GLchar = Alias("GLchar", Char)
58 GLcharARB = Alias("GLcharARB", SChar)
59 GLintptrARB = Alias("GLintptrARB", Int)
60 GLsizeiptrARB = Alias("GLsizeiptrARB", Int)
61 GLhandleARB = Handle("handleARB", Alias("GLhandleARB", UInt))
62 GLhalfARB = Alias("GLhalfARB", UShort)
63 GLhalfNV = Alias("GLhalfNV", UShort)
64 GLint64EXT = Alias("GLint64EXT", Int64)
65 GLuint64EXT = Alias("GLuint64EXT", UInt64)
66 GLDEBUGPROC = Opaque("GLDEBUGPROC")
67 GLDEBUGPROCARB = Opaque("GLDEBUGPROCARB")
68 GLDEBUGPROCAMD = Opaque("GLDEBUGPROCAMD")
70 GLstring = String(GLchar)
71 GLstringConst = String(Const(GLchar))
72 GLstringARB = String(GLcharARB)
73 GLstringConstARB = String(Const(GLcharARB))
75 GLpointer = OpaquePointer(GLvoid)
76 GLpointerConst = OpaquePointer(Const(GLvoid))
78 GLlist = Handle("list", GLuint)
79 GLtexture = Handle("texture", GLuint)
80 GLbuffer = Handle("buffer", GLuint)
81 GLquery = Handle("query", GLuint)
82 GLfenceNV = Handle("fenceNV", GLuint)
83 GLprogram = Handle("program", GLuint)
84 GLshader = Handle("shader", GLuint)
86 # Share the same mapping table for uniform locations of both core and
87 # GL_ARB_shader_objects programs. For a combination of reasons:
89 # - all OpenGL implementations appear to alias the names for both kind of
92 # - most applications will use only one kind of shader programs;
94 # - some applications actually mix glUniformXxx calls with
95 # GL_ARB_shader_objects programs and glUniformXxxARB calls with core
96 # programs, and therefore, rely on a joint implementation.
98 # We use GLhandleARB as program key, since it is wider (void *) on MacOSX.
100 GLlocation = Handle("location", GLint, key=('program', GLhandleARB))
101 GLlocationARB = Handle("location", GLint, key=('programObj', GLhandleARB))
103 contextKey = ('reinterpret_cast<uintptr_t>(glretrace::getCurrentContext())', UIntPtr)
105 GLprogramARB = Handle("programARB", GLuint)
106 GLframebuffer = Handle("framebuffer", GLuint)
107 GLrenderbuffer = Handle("renderbuffer", GLuint)
108 GLfragmentShaderATI = Handle("fragmentShaderATI", GLuint)
109 GLarray = Handle("array", GLuint, key=contextKey) # per-context
110 GLarrayAPPLE = Handle("arrayAPPLE", GLuint) # shared
111 GLregion = Handle("region", GLuint)
112 GLpipeline = Handle("pipeline", GLuint)
113 GLsampler = Handle("sampler", GLuint)
114 GLfeedback = Handle("feedback", GLuint)
115 GLfence = Handle("fence", GLuint)
117 # GL mappings are pointers to linear memory regions.
119 # The map length is not always available in the function prototype, and must be
120 # reconstructed from other state.
121 GLmap = LinearPointer(GLvoid, "length")
123 GLsync = Handle("sync", IntPointer("GLsync"))
125 GLenum = Enum("GLenum", [
126 # Parameters are added later from glparams.py's parameter table
129 # Some functions take GLenum disguised as GLint, and need special treatment so
130 # that symbolic names are traced correctly.
131 GLenum_int = Alias("GLint", GLenum)
133 GLenum_mode = FakeEnum(GLenum, [
134 "GL_POINTS", # 0x0000
136 "GL_LINE_LOOP", # 0x0002
137 "GL_LINE_STRIP", # 0x0003
138 "GL_TRIANGLES", # 0x0004
139 "GL_TRIANGLE_STRIP", # 0x0005
140 "GL_TRIANGLE_FAN", # 0x0006
142 "GL_QUAD_STRIP", # 0x0008
143 "GL_POLYGON", # 0x0009
144 "GL_LINES_ADJACENCY", # 0x000A
145 "GL_LINE_STRIP_ADJACENCY", # 0x000B
146 "GL_TRIANGLES_ADJACENCY", # 0x000C
147 "GL_TRIANGLE_STRIP_ADJACENCY", # 0x000D
148 "GL_PATCHES", # 0x000E
151 GLenum_error = FakeEnum(GLenum, [
153 "GL_INVALID_ENUM", # 0x0500
154 "GL_INVALID_VALUE", # 0x0501
155 "GL_INVALID_OPERATION", # 0x0502
156 "GL_STACK_OVERFLOW", # 0x0503
157 "GL_STACK_UNDERFLOW", # 0x0504
158 "GL_OUT_OF_MEMORY", # 0x0505
159 "GL_INVALID_FRAMEBUFFER_OPERATION", # 0x0506
160 "GL_TABLE_TOO_LARGE", # 0x8031
163 GLbitfield = Alias("GLbitfield", UInt)
165 GLbitfield_attrib = Flags(GLbitfield, [
166 "GL_ALL_ATTRIB_BITS", # 0x000FFFFF
167 "GL_CURRENT_BIT", # 0x00000001
168 "GL_POINT_BIT", # 0x00000002
169 "GL_LINE_BIT", # 0x00000004
170 "GL_POLYGON_BIT", # 0x00000008
171 "GL_POLYGON_STIPPLE_BIT", # 0x00000010
172 "GL_PIXEL_MODE_BIT", # 0x00000020
173 "GL_LIGHTING_BIT", # 0x00000040
174 "GL_FOG_BIT", # 0x00000080
175 "GL_DEPTH_BUFFER_BIT", # 0x00000100
176 "GL_ACCUM_BUFFER_BIT", # 0x00000200
177 "GL_STENCIL_BUFFER_BIT", # 0x00000400
178 "GL_VIEWPORT_BIT", # 0x00000800
179 "GL_TRANSFORM_BIT", # 0x00001000
180 "GL_ENABLE_BIT", # 0x00002000
181 "GL_COLOR_BUFFER_BIT", # 0x00004000
182 "GL_HINT_BIT", # 0x00008000
183 "GL_EVAL_BIT", # 0x00010000
184 "GL_LIST_BIT", # 0x00020000
185 "GL_TEXTURE_BIT", # 0x00040000
186 "GL_SCISSOR_BIT", # 0x00080000
187 "GL_MULTISAMPLE_BIT", # 0x20000000
190 GLbitfield_client_attrib = Flags(GLbitfield, [
191 "GL_CLIENT_ALL_ATTRIB_BITS", # 0xFFFFFFFF
192 "GL_CLIENT_PIXEL_STORE_BIT", # 0x00000001
193 "GL_CLIENT_VERTEX_ARRAY_BIT", # 0x00000002
196 GLbitfield_shader = Flags(GLbitfield, [
197 "GL_ALL_SHADER_BITS", # 0xFFFFFFFF
198 "GL_VERTEX_SHADER_BIT", # 0x00000001
199 "GL_FRAGMENT_SHADER_BIT", # 0x00000002
200 "GL_GEOMETRY_SHADER_BIT", # 0x00000004
201 "GL_TESS_CONTROL_SHADER_BIT", # 0x00000008
202 "GL_TESS_EVALUATION_SHADER_BIT", # 0x00000010
203 "GL_COMPUTE_SHADER_BIT", # 0x00000020
206 GLbitfield_access = Flags(GLbitfield, [
207 "GL_MAP_READ_BIT", # 0x0001
208 "GL_MAP_WRITE_BIT", # 0x0002
209 "GL_MAP_INVALIDATE_RANGE_BIT", # 0x0004
210 "GL_MAP_INVALIDATE_BUFFER_BIT", # 0x0008
211 "GL_MAP_FLUSH_EXPLICIT_BIT", # 0x0010
212 "GL_MAP_UNSYNCHRONIZED_BIT", # 0x0020
215 GLbitfield_sync_flush = Flags(GLbitfield, [
216 "GL_SYNC_FLUSH_COMMANDS_BIT", # 0x00000001
219 GLbitfield_barrier = Flags(GLbitfield, [
220 "GL_ALL_BARRIER_BITS", # 0xFFFFFFFF
221 "GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT", # 0x00000001
222 "GL_ELEMENT_ARRAY_BARRIER_BIT", # 0x00000002
223 "GL_UNIFORM_BARRIER_BIT", # 0x00000004
224 "GL_TEXTURE_FETCH_BARRIER_BIT", # 0x00000008
225 "GL_SHADER_GLOBAL_ACCESS_BARRIER_BIT_NV", # 0x00000010
226 "GL_SHADER_IMAGE_ACCESS_BARRIER_BIT", # 0x00000020
227 "GL_COMMAND_BARRIER_BIT", # 0x00000040
228 "GL_PIXEL_BUFFER_BARRIER_BIT", # 0x00000080
229 "GL_TEXTURE_UPDATE_BARRIER_BIT", # 0x00000100
230 "GL_BUFFER_UPDATE_BARRIER_BIT", # 0x00000200
231 "GL_FRAMEBUFFER_BARRIER_BIT", # 0x00000400
232 "GL_TRANSFORM_FEEDBACK_BARRIER_BIT", # 0x00000800
233 "GL_ATOMIC_COUNTER_BARRIER_BIT", # 0x00001000
236 # GL_ARB_vertex_array_bgra
237 size_bgra = FakeEnum(GLint, [
242 def GLindexBuffer(countExpr, typeExpr):
243 # Indices arguments are polymorphic:
244 # - offsets when element array buffer is bound
245 # - or a blob otherwise.
246 sizeExpr = '%s*_gl_type_size(%s)' % (countExpr, typeExpr)
247 return Polymorphic('_element_array_buffer_binding()', [
248 ('0', Blob(Const(GLvoid), sizeExpr)),
250 IntPointer("const GLvoid *"),
254 # Polymorphic object name
255 def GLname(targetExpr):
256 return Polymorphic(targetExpr, [
257 ('GL_BUFFER', GLbuffer),
258 ('GL_SHADER', GLshader),
259 ('GL_PROGRAM', GLprogram),
260 ('GL_VERTEX_ARRAY', GLarray),
261 ('GL_QUERY', GLquery),
262 ('GL_PROGRAM_PIPELINE', GLpipeline),
263 ('GL_TRANSFORM_FEEDBACK', GLuint),
264 ('GL_SAMPLER', GLsampler),
265 ('GL_TEXTURE', GLtexture),
266 ('GL_TEXTURE_1D', GLtexture),
267 ('GL_TEXTURE_1D_ARRAY', GLtexture),
268 ('GL_TEXTURE_2D', GLtexture),
269 ('GL_TEXTURE_2D_MULTISAMPLE', GLtexture),
270 ('GL_TEXTURE_2D_ARRAY', GLtexture),
271 ('GL_TEXTURE_RECTANGLE', GLtexture),
272 ('GL_TEXTURE_CUBE_MAP', GLtexture),
273 ('GL_TEXTURE_CUBE_MAP_POSITIVE_X', GLtexture),
274 ('GL_TEXTURE_CUBE_MAP_NEGATIVE_X', GLtexture),
275 ('GL_TEXTURE_CUBE_MAP_POSITIVE_Y', GLtexture),
276 ('GL_TEXTURE_CUBE_MAP_NEGATIVE_Y', GLtexture),
277 ('GL_TEXTURE_CUBE_MAP_POSITIVE_Z', GLtexture),
278 ('GL_TEXTURE_CUBE_MAP_NEGATIVE_Z', GLtexture),
279 ('GL_TEXTURE_CUBE_MAP_ARRAY', GLtexture),
280 ('GL_TEXTURE_3D', GLtexture),
281 ('GL_RENDERBUFFER', GLrenderbuffer),
282 ('GL_FRAMEBUFFER', GLframebuffer),
283 ('GL_DISPLAY_LIST', GLlist),
284 ('GL_FENCE_APPLE', GLfence),
285 ('GL_DRAW_PIXELS_APPLE', GLuint), # GL_APPLE_fence
289 # GL_AMD_performance_monitor
290 GLperfMonitorCounterInfoAMD = Polymorphic('pname', [
291 ('GL_COUNTER_TYPE_AMD', Pointer(GLenum)),
292 ('GL_PERCENTAGE_AMD', Pointer(Float)),
293 ('GL_COUNTER_RANGE_AMD', Array(Float, 2)),
295 OpaquePointer(GLvoid),