base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / gl / generate_bindings.py
blobaf1bdc84b563876082359726f9b16c82c8f2e5a5
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """code generator for GL/GLES extension wrangler."""
8 import optparse
9 import os
10 import collections
11 import re
12 import sys
14 """In case there are multiple versions of the same function, one that's listed
15 first takes priority if its conditions are met. If the function is an extension
16 function, finding the extension from the extension string is a condition for
17 binding it. The last version of the function is treated as a fallback option in
18 case no other versions were bound, so a non-null function pointer in the
19 bindings does not guarantee that the function is supported.
21 Function binding conditions can be specified manually by supplying a versions
22 array instead of the names array. Each version has the following keys:
23 name: Mandatory. Name of the function. Multiple versions can have the same
24 name but different conditions.
25 gl_versions: List of GL versions where the function is found.
26 extensions: Extensions where the function is found. If not specified, the
27 extensions are determined based on GL header files.
28 If the function exists in an extension header, you may specify
29 an empty array to prevent making that a condition for binding.
31 By default, the function gets its name from the first name in its names or
32 versions array. This can be overridden by supplying a 'known_as' key.
33 """
34 GL_FUNCTIONS = [
35 { 'return_type': 'void',
36 'names': ['glActiveTexture'],
37 'arguments': 'GLenum texture', },
38 { 'return_type': 'void',
39 'names': ['glAttachShader'],
40 'arguments': 'GLuint program, GLuint shader', },
41 { 'return_type': 'void',
42 'versions': [{ 'name': 'glBeginQuery',
43 'gl_versions': ['gl3', 'gl4', 'es3'] }],
44 'arguments': 'GLenum target, GLuint id', },
45 { 'return_type': 'void',
46 'names': ['glBeginQueryARB', 'glBeginQueryEXT'],
47 'arguments': 'GLenum target, GLuint id', },
48 { 'return_type': 'void',
49 'versions': [{ 'name': 'glBeginTransformFeedback',
50 'gl_versions': ['gl3', 'gl4', 'es3'] }],
51 'arguments': 'GLenum primitiveMode', },
52 { 'return_type': 'void',
53 'names': ['glBindAttribLocation'],
54 'arguments': 'GLuint program, GLuint index, const char* name', },
55 { 'return_type': 'void',
56 'names': ['glBindBuffer'],
57 'arguments': 'GLenum target, GLuint buffer', },
58 { 'return_type': 'void',
59 'versions': [{ 'name': 'glBindBufferBase',
60 'gl_versions': ['gl3', 'gl4', 'es3'] }],
61 'arguments': 'GLenum target, GLuint index, GLuint buffer', },
62 { 'return_type': 'void',
63 'versions': [{ 'name': 'glBindBufferRange',
64 'gl_versions': ['gl3', 'gl4', 'es3'] }],
65 'arguments': 'GLenum target, GLuint index, GLuint buffer, GLintptr offset, '
66 'GLsizeiptr size', },
67 { 'return_type': 'void',
68 'names': ['glBindFragDataLocation'],
69 'arguments': 'GLuint program, GLuint colorNumber, const char* name', },
70 { 'return_type': 'void',
71 'names': ['glBindFragDataLocationIndexed'],
72 'arguments':
73 'GLuint program, GLuint colorNumber, GLuint index, const char* name', },
74 { 'return_type': 'void',
75 'names': ['glBindFramebufferEXT', 'glBindFramebuffer'],
76 'arguments': 'GLenum target, GLuint framebuffer', },
77 { 'return_type': 'void',
78 'names': ['glBindRenderbufferEXT', 'glBindRenderbuffer'],
79 'arguments': 'GLenum target, GLuint renderbuffer', },
80 { 'return_type': 'void',
81 'versions': [{ 'name': 'glBindSampler',
82 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.2 or higher.
83 'arguments': 'GLuint unit, GLuint sampler', },
84 { 'return_type': 'void',
85 'names': ['glBindTexture'],
86 'arguments': 'GLenum target, GLuint texture', },
87 { 'return_type': 'void',
88 'versions': [{ 'name': 'glBindTransformFeedback',
89 'gl_versions': ['gl4', 'es3'] }],
90 'arguments': 'GLenum target, GLuint id', },
91 { 'return_type': 'void',
92 'known_as': 'glBindVertexArrayOES',
93 'versions': [{ 'name': 'glBindVertexArray',
94 'gl_versions': ['gl3', 'gl4', 'es3'] },
95 { 'name': 'glBindVertexArray',
96 'extensions': ['GL_ARB_vertex_array_object'] },
97 { 'name': 'glBindVertexArrayOES' },
98 { 'name': 'glBindVertexArrayAPPLE',
99 'extensions': ['GL_APPLE_vertex_array_object'] }],
100 'arguments': 'GLuint array' },
101 { 'return_type': 'void',
102 'known_as': 'glBlendBarrierKHR',
103 'versions': [{ 'name': 'glBlendBarrierNV',
104 'extensions': ['GL_NV_blend_equation_advanced'] },
105 { 'name': 'glBlendBarrierKHR',
106 'extensions': ['GL_KHR_blend_equation_advanced'] }],
107 'arguments': 'void' },
108 { 'return_type': 'void',
109 'names': ['glBlendColor'],
110 'arguments': 'GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha', },
111 { 'return_type': 'void',
112 'names': ['glBlendEquation'],
113 'arguments': ' GLenum mode ', },
114 { 'return_type': 'void',
115 'names': ['glBlendEquationSeparate'],
116 'arguments': 'GLenum modeRGB, GLenum modeAlpha', },
117 { 'return_type': 'void',
118 'names': ['glBlendFunc'],
119 'arguments': 'GLenum sfactor, GLenum dfactor', },
120 { 'return_type': 'void',
121 'names': ['glBlendFuncSeparate'],
122 'arguments':
123 'GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha', },
124 { 'return_type': 'void',
125 'names': ['glBlitFramebuffer'],
126 'arguments': 'GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, '
127 'GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, '
128 'GLbitfield mask, GLenum filter', },
129 { 'return_type': 'void',
130 'names': ['glBlitFramebufferANGLE', 'glBlitFramebuffer'],
131 'arguments': 'GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, '
132 'GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, '
133 'GLbitfield mask, GLenum filter', },
134 { 'return_type': 'void',
135 'names': ['glBlitFramebufferEXT', 'glBlitFramebuffer'],
136 'arguments': 'GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, '
137 'GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, '
138 'GLbitfield mask, GLenum filter', },
139 { 'return_type': 'void',
140 'names': ['glBufferData'],
141 'arguments':
142 'GLenum target, GLsizeiptr size, const void* data, GLenum usage', },
143 { 'return_type': 'void',
144 'names': ['glBufferSubData'],
145 'arguments':
146 'GLenum target, GLintptr offset, GLsizeiptr size, const void* data', },
147 { 'return_type': 'GLenum',
148 'names': ['glCheckFramebufferStatusEXT',
149 'glCheckFramebufferStatus'],
150 'arguments': 'GLenum target',
151 'logging_code': """
152 GL_SERVICE_LOG("GL_RESULT: " << GLES2Util::GetStringEnum(result));
153 """, },
154 { 'return_type': 'void',
155 'names': ['glClear'],
156 'arguments': 'GLbitfield mask', },
157 { 'return_type': 'void',
158 'versions': [{ 'name': 'glClearBufferfi',
159 'gl_versions': ['gl3', 'gl4', 'es3'] }],
160 'arguments': 'GLenum buffer, GLint drawbuffer, const GLfloat depth, '
161 'GLint stencil', },
162 { 'return_type': 'void',
163 'versions': [{ 'name': 'glClearBufferfv',
164 'gl_versions': ['gl3', 'gl4', 'es3'] }],
165 'arguments': 'GLenum buffer, GLint drawbuffer, const GLfloat* value', },
166 { 'return_type': 'void',
167 'versions': [{ 'name': 'glClearBufferiv',
168 'gl_versions': ['gl3', 'gl4', 'es3'] }],
169 'arguments': 'GLenum buffer, GLint drawbuffer, const GLint* value', },
170 { 'return_type': 'void',
171 'versions': [{ 'name': 'glClearBufferuiv',
172 'gl_versions': ['gl3', 'gl4', 'es3'] }],
173 'arguments': 'GLenum buffer, GLint drawbuffer, const GLuint* value', },
174 { 'return_type': 'void',
175 'names': ['glClearColor'],
176 'arguments': 'GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha', },
177 { 'return_type': 'void',
178 'names': ['glClearDepth'],
179 'arguments': 'GLclampd depth', },
180 { 'return_type': 'void',
181 'names': ['glClearDepthf'],
182 'arguments': 'GLclampf depth', },
183 { 'return_type': 'void',
184 'names': ['glClearStencil'],
185 'arguments': 'GLint s', },
186 { 'return_type': 'GLenum',
187 'names': ['glClientWaitSync'],
188 'arguments': 'GLsync sync, GLbitfield flags, GLuint64 timeout', },
189 { 'return_type': 'void',
190 'names': ['glColorMask'],
191 'arguments':
192 'GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha', },
193 { 'return_type': 'void',
194 'names': ['glCompileShader'],
195 'arguments': 'GLuint shader', },
196 { 'return_type': 'void',
197 'names': ['glCompressedTexImage2D'],
198 'arguments':
199 'GLenum target, GLint level, GLenum internalformat, GLsizei width, '
200 'GLsizei height, GLint border, GLsizei imageSize, const void* data', },
201 { 'return_type': 'void',
202 'versions': [{ 'name': 'glCompressedTexImage3D',
203 'gl_versions': ['gl3', 'gl4', 'es3'] }],
204 'arguments':
205 'GLenum target, GLint level, GLenum internalformat, GLsizei width, '
206 'GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, '
207 'const void* data', },
208 { 'return_type': 'void',
209 'names': ['glCompressedTexSubImage2D'],
210 'arguments':
211 'GLenum target, GLint level, GLint xoffset, GLint yoffset, '
212 'GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, '
213 'const void* data', },
214 # TODO(zmo): wait for MOCK_METHOD11.
215 # { 'return_type': 'void',
216 # 'versions': [{ 'name': 'glCompressedTexSubImage3D',
217 # 'gl_versions': ['gl3', 'gl4', 'es3'] }],
218 # 'arguments':
219 # 'GLenum target, GLint level, GLint xoffset, GLint yoffset, '
220 # 'GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, '
221 # 'GLenum format, GLsizei imageSize, const void* data', },
222 { 'return_type': 'void',
223 'versions': [{ 'name': 'glCopyBufferSubData',
224 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.1 or higher.
225 'arguments':
226 'GLenum readTarget, GLenum writeTarget, GLintptr readOffset, '
227 'GLintptr writeOffset, GLsizeiptr size', },
228 { 'return_type': 'void',
229 'names': ['glCopyTexImage2D'],
230 'arguments':
231 'GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, '
232 'GLsizei width, GLsizei height, GLint border', },
233 { 'return_type': 'void',
234 'names': ['glCopyTexSubImage2D'],
235 'arguments':
236 'GLenum target, GLint level, GLint xoffset, '
237 'GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height', },
238 { 'return_type': 'void',
239 'versions': [{ 'name': 'glCopyTexSubImage3D',
240 'gl_versions': ['gl3', 'gl4', 'es3'] }],
241 'arguments':
242 'GLenum target, GLint level, GLint xoffset, GLint yoffset, '
243 'GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height', },
244 { 'return_type': 'GLuint',
245 'names': ['glCreateProgram'],
246 'arguments': 'void', },
247 { 'return_type': 'GLuint',
248 'names': ['glCreateShader'],
249 'arguments': 'GLenum type', },
250 { 'return_type': 'void',
251 'names': ['glCullFace'],
252 'arguments': 'GLenum mode', },
253 { 'return_type': 'void',
254 'names': ['glDeleteBuffersARB', 'glDeleteBuffers'],
255 'arguments': 'GLsizei n, const GLuint* buffers', },
256 { 'return_type': 'void',
257 'known_as': 'glDeleteFencesAPPLE',
258 'versions': [{ 'name': 'glDeleteFencesAPPLE',
259 'extensions': ['GL_APPLE_fence'] }],
260 'arguments': 'GLsizei n, const GLuint* fences', },
261 { 'return_type': 'void',
262 'names': ['glDeleteFencesNV'],
263 'arguments': 'GLsizei n, const GLuint* fences', },
264 { 'return_type': 'void',
265 'names': ['glDeleteFramebuffersEXT', 'glDeleteFramebuffers'],
266 'arguments': 'GLsizei n, const GLuint* framebuffers', },
267 { 'return_type': 'void',
268 'names': ['glDeleteProgram'],
269 'arguments': 'GLuint program', },
270 { 'return_type': 'void',
271 'versions': [{ 'name': 'glDeleteQueries',
272 'gl_versions': ['gl3', 'gl4', 'es3'] }],
273 'arguments': 'GLsizei n, const GLuint* ids', },
274 { 'return_type': 'void',
275 'names': ['glDeleteQueriesARB', 'glDeleteQueriesEXT'],
276 'arguments': 'GLsizei n, const GLuint* ids', },
277 { 'return_type': 'void',
278 'names': ['glDeleteRenderbuffersEXT', 'glDeleteRenderbuffers'],
279 'arguments': 'GLsizei n, const GLuint* renderbuffers', },
280 { 'return_type': 'void',
281 'versions': [{ 'name': 'glDeleteSamplers',
282 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.2 or higher.
283 'arguments': 'GLsizei n, const GLuint* samplers', },
284 { 'return_type': 'void',
285 'names': ['glDeleteShader'],
286 'arguments': 'GLuint shader', },
287 { 'return_type': 'void',
288 'names': ['glDeleteSync'],
289 'arguments': 'GLsync sync', },
290 { 'return_type': 'void',
291 'names': ['glDeleteTextures'],
292 'arguments': 'GLsizei n, const GLuint* textures', },
293 { 'return_type': 'void',
294 'versions': [{ 'name': 'glDeleteTransformFeedbacks',
295 'gl_versions': ['gl4', 'es3'] }],
296 'arguments': 'GLsizei n, const GLuint* ids', },
297 { 'return_type': 'void',
298 'known_as': 'glDeleteVertexArraysOES',
299 'versions': [{ 'name': 'glDeleteVertexArrays',
300 'gl_versions': ['gl3', 'gl4', 'es3'] },
301 { 'name': 'glDeleteVertexArrays',
302 'extensions': ['GL_ARB_vertex_array_object'] },
303 { 'name': 'glDeleteVertexArraysOES' },
304 { 'name': 'glDeleteVertexArraysAPPLE',
305 'extensions': ['GL_APPLE_vertex_array_object'] }],
306 'arguments': 'GLsizei n, const GLuint* arrays' },
307 { 'return_type': 'void',
308 'names': ['glDepthFunc'],
309 'arguments': 'GLenum func', },
310 { 'return_type': 'void',
311 'names': ['glDepthMask'],
312 'arguments': 'GLboolean flag', },
313 { 'return_type': 'void',
314 'names': ['glDepthRange'],
315 'arguments': 'GLclampd zNear, GLclampd zFar', },
316 { 'return_type': 'void',
317 'names': ['glDepthRangef'],
318 'arguments': 'GLclampf zNear, GLclampf zFar', },
319 { 'return_type': 'void',
320 'names': ['glDetachShader'],
321 'arguments': 'GLuint program, GLuint shader', },
322 { 'return_type': 'void',
323 'names': ['glDisable'],
324 'arguments': 'GLenum cap', },
325 { 'return_type': 'void',
326 'names': ['glDisableVertexAttribArray'],
327 'arguments': 'GLuint index', },
328 { 'return_type': 'void',
329 'versions': [{ 'name': 'glDiscardFramebufferEXT',
330 'extensions': ['GL_EXT_discard_framebuffer'] }],
331 'arguments': 'GLenum target, GLsizei numAttachments, '
332 'const GLenum* attachments' },
333 { 'return_type': 'void',
334 'names': ['glDrawArrays'],
335 'arguments': 'GLenum mode, GLint first, GLsizei count', },
336 { 'return_type': 'void',
337 'known_as': 'glDrawArraysInstancedANGLE',
338 'names': ['glDrawArraysInstancedARB', 'glDrawArraysInstancedANGLE',
339 'glDrawArraysInstanced'],
340 'arguments': 'GLenum mode, GLint first, GLsizei count, GLsizei primcount', },
341 { 'return_type': 'void',
342 'names': ['glDrawBuffer'],
343 'arguments': 'GLenum mode', },
344 { 'return_type': 'void',
345 'names': ['glDrawBuffersARB', 'glDrawBuffersEXT', 'glDrawBuffers'],
346 'arguments': 'GLsizei n, const GLenum* bufs', },
347 { 'return_type': 'void',
348 'names': ['glDrawElements'],
349 'arguments':
350 'GLenum mode, GLsizei count, GLenum type, const void* indices', },
351 { 'return_type': 'void',
352 'known_as': 'glDrawElementsInstancedANGLE',
353 'names': ['glDrawElementsInstancedARB', 'glDrawElementsInstancedANGLE',
354 'glDrawElementsInstanced'],
355 'arguments':
356 'GLenum mode, GLsizei count, GLenum type, const void* indices, '
357 'GLsizei primcount', },
358 { 'return_type': 'void',
359 'versions': [{ 'name': 'glDrawRangeElements',
360 'gl_versions': ['gl3', 'gl4', 'es3'] }],
361 'arguments': 'GLenum mode, GLuint start, GLuint end, GLsizei count, '
362 'GLenum type, const void* indices', },
363 { 'return_type': 'void',
364 'names': ['glEGLImageTargetRenderbufferStorageOES'],
365 'arguments': 'GLenum target, GLeglImageOES image', },
366 { 'return_type': 'void',
367 'names': ['glEGLImageTargetTexture2DOES'],
368 'arguments': 'GLenum target, GLeglImageOES image', },
369 { 'return_type': 'void',
370 'names': ['glEnable'],
371 'arguments': 'GLenum cap', },
372 { 'return_type': 'void',
373 'names': ['glEnableVertexAttribArray'],
374 'arguments': 'GLuint index', },
375 { 'return_type': 'void',
376 'versions': [{ 'name': 'glEndQuery',
377 'gl_versions': ['gl3', 'gl4', 'es3'] }],
378 'arguments': 'GLenum target', },
379 { 'return_type': 'void',
380 'names': ['glEndQueryARB', 'glEndQueryEXT'],
381 'arguments': 'GLenum target', },
382 { 'return_type': 'void',
383 'versions': [{ 'name': 'glEndTransformFeedback',
384 'gl_versions': ['gl3', 'gl4', 'es3'] }],
385 'arguments': 'void', },
386 { 'return_type': 'GLsync',
387 'names': ['glFenceSync'],
388 'arguments': 'GLenum condition, GLbitfield flags', },
389 { 'return_type': 'void',
390 'names': ['glFinish'],
391 'arguments': 'void', },
392 { 'return_type': 'void',
393 'known_as': 'glFinishFenceAPPLE',
394 'versions': [{ 'name': 'glFinishFenceAPPLE',
395 'extensions': ['GL_APPLE_fence'] }],
396 'arguments': 'GLuint fence', },
397 { 'return_type': 'void',
398 'names': ['glFinishFenceNV'],
399 'arguments': 'GLuint fence', },
400 { 'return_type': 'void',
401 'names': ['glFlush'],
402 'arguments': 'void', },
403 { 'return_type': 'void',
404 'names': ['glFlushMappedBufferRange'],
405 'arguments': 'GLenum target, GLintptr offset, GLsizeiptr length', },
406 { 'return_type': 'void',
407 'names': ['glFramebufferRenderbufferEXT', 'glFramebufferRenderbuffer'],
408 'arguments':
409 'GLenum target, GLenum attachment, GLenum renderbuffertarget, '
410 'GLuint renderbuffer', },
411 { 'return_type': 'void',
412 'names': ['glFramebufferTexture2DEXT', 'glFramebufferTexture2D'],
413 'arguments':
414 'GLenum target, GLenum attachment, GLenum textarget, GLuint texture, '
415 'GLint level', },
416 { 'return_type': 'void',
417 'names': ['glFramebufferTexture2DMultisampleEXT'],
418 'arguments':
419 'GLenum target, GLenum attachment, GLenum textarget, GLuint texture, '
420 'GLint level, GLsizei samples', },
421 { 'return_type': 'void',
422 'names': ['glFramebufferTexture2DMultisampleIMG'],
423 'arguments':
424 'GLenum target, GLenum attachment, GLenum textarget, GLuint texture, '
425 'GLint level, GLsizei samples', },
426 { 'return_type': 'void',
427 'versions': [{ 'name': 'glFramebufferTextureLayer',
428 'gl_versions': ['gl3', 'gl4', 'es3'] }],
429 'arguments': 'GLenum target, GLenum attachment, GLuint texture, GLint level, '
430 'GLint layer', },
431 { 'return_type': 'void',
432 'names': ['glFrontFace'],
433 'arguments': 'GLenum mode', },
434 { 'return_type': 'void',
435 'names': ['glGenBuffersARB', 'glGenBuffers'],
436 'arguments': 'GLsizei n, GLuint* buffers', },
437 { 'return_type': 'void',
438 'names': ['glGenerateMipmapEXT', 'glGenerateMipmap'],
439 'arguments': 'GLenum target', },
440 { 'return_type': 'void',
441 'known_as': 'glGenFencesAPPLE',
442 'versions': [{ 'name': 'glGenFencesAPPLE',
443 'extensions': ['GL_APPLE_fence'] }],
444 'arguments': 'GLsizei n, GLuint* fences', },
445 { 'return_type': 'void',
446 'names': ['glGenFencesNV'],
447 'arguments': 'GLsizei n, GLuint* fences', },
448 { 'return_type': 'void',
449 'names': ['glGenFramebuffersEXT', 'glGenFramebuffers'],
450 'arguments': 'GLsizei n, GLuint* framebuffers', },
451 { 'return_type': 'void',
452 'versions': [{ 'name': 'glGenQueries',
453 'gl_versions': ['gl3', 'gl4', 'es3'] }],
454 'arguments': 'GLsizei n, GLuint* ids', },
455 { 'return_type': 'void',
456 'names': ['glGenQueriesARB', 'glGenQueriesEXT'],
457 'arguments': 'GLsizei n, GLuint* ids', },
458 { 'return_type': 'void',
459 'names': ['glGenRenderbuffersEXT', 'glGenRenderbuffers'],
460 'arguments': 'GLsizei n, GLuint* renderbuffers', },
461 { 'return_type': 'void',
462 'versions': [{ 'name': 'glGenSamplers',
463 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.2 or higher.
464 'arguments': 'GLsizei n, GLuint* samplers', },
465 { 'return_type': 'void',
466 'names': ['glGenTextures'],
467 'arguments': 'GLsizei n, GLuint* textures', },
468 { 'return_type': 'void',
469 'versions': [{ 'name': 'glGenTransformFeedbacks',
470 'gl_versions': ['gl4', 'es3'] }],
471 'arguments': 'GLsizei n, GLuint* ids', },
472 { 'return_type': 'void',
473 'known_as': 'glGenVertexArraysOES',
474 'versions': [{ 'name': 'glGenVertexArrays',
475 'gl_versions': ['gl3', 'gl4', 'es3'] },
476 { 'name': 'glGenVertexArrays',
477 'extensions': ['GL_ARB_vertex_array_object'] },
478 { 'name': 'glGenVertexArraysOES' },
479 { 'name': 'glGenVertexArraysAPPLE',
480 'extensions': ['GL_APPLE_vertex_array_object'] }],
481 'arguments': 'GLsizei n, GLuint* arrays', },
482 { 'return_type': 'void',
483 'names': ['glGetActiveAttrib'],
484 'arguments':
485 'GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, '
486 'GLint* size, GLenum* type, char* name', },
487 { 'return_type': 'void',
488 'names': ['glGetActiveUniform'],
489 'arguments':
490 'GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, '
491 'GLint* size, GLenum* type, char* name', },
492 { 'return_type': 'void',
493 'versions': [{ 'name': 'glGetActiveUniformBlockiv',
494 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.1 or higher.
495 'arguments': 'GLuint program, GLuint uniformBlockIndex, GLenum pname, '
496 'GLint* params', },
497 { 'return_type': 'void',
498 'versions': [{ 'name': 'glGetActiveUniformBlockName',
499 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.1 or higher.
500 'arguments': 'GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, '
501 'GLsizei* length, char* uniformBlockName', },
502 { 'return_type': 'void',
503 'versions': [{ 'name': 'glGetActiveUniformsiv',
504 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.1 or higher.
505 'arguments': 'GLuint program, GLsizei uniformCount, '
506 'const GLuint* uniformIndices, GLenum pname, GLint* params', },
507 { 'return_type': 'void',
508 'names': ['glGetAttachedShaders'],
509 'arguments':
510 'GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders', },
511 { 'return_type': 'GLint',
512 'names': ['glGetAttribLocation'],
513 'arguments': 'GLuint program, const char* name', },
514 { 'return_type': 'void',
515 'names': ['glGetBooleanv'],
516 'arguments': 'GLenum pname, GLboolean* params', },
517 { 'return_type': 'void',
518 'names': ['glGetBufferParameteriv'],
519 'arguments': 'GLenum target, GLenum pname, GLint* params', },
520 { 'return_type': 'GLenum',
521 'names': ['glGetError'],
522 'arguments': 'void',
523 'logging_code': """
524 GL_SERVICE_LOG("GL_RESULT: " << GLES2Util::GetStringError(result));
525 """, },
526 { 'return_type': 'void',
527 'names': ['glGetFenceivNV'],
528 'arguments': 'GLuint fence, GLenum pname, GLint* params', },
529 { 'return_type': 'void',
530 'names': ['glGetFloatv'],
531 'arguments': 'GLenum pname, GLfloat* params', },
532 { 'return_type': 'GLint',
533 'versions': [{ 'name': 'glGetFragDataLocation',
534 'gl_versions': ['gl3', 'gl4', 'es3'] }],
535 'arguments': 'GLuint program, const char* name', },
536 { 'return_type': 'void',
537 'names': ['glGetFramebufferAttachmentParameterivEXT',
538 'glGetFramebufferAttachmentParameteriv'],
539 'arguments': 'GLenum target, '
540 'GLenum attachment, GLenum pname, GLint* params', },
541 { 'return_type': 'GLenum',
542 'names': ['glGetGraphicsResetStatusARB',
543 'glGetGraphicsResetStatusKHR',
544 'glGetGraphicsResetStatusEXT',
545 'glGetGraphicsResetStatus'],
546 'arguments': 'void', },
547 { 'return_type': 'void',
548 'versions': [{ 'name': 'glGetInteger64i_v',
549 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.2 or higher.
550 'arguments': 'GLenum target, GLuint index, GLint64* data', },
551 { 'return_type': 'void',
552 'names': ['glGetInteger64v'],
553 'arguments': 'GLenum pname, GLint64* params', },
554 { 'return_type': 'void',
555 'versions': [{ 'name': 'glGetIntegeri_v',
556 'gl_versions': ['gl3', 'gl4', 'es3'] }],
557 'arguments': 'GLenum target, GLuint index, GLint* data', },
558 { 'return_type': 'void',
559 'names': ['glGetIntegerv'],
560 'arguments': 'GLenum pname, GLint* params', },
561 { 'return_type': 'void',
562 'versions': [{ 'name': 'glGetInternalformativ',
563 'gl_versions': ['gl4', 'es3'] }], # GL 4.2 or higher.
564 'arguments': 'GLenum target, GLenum internalformat, GLenum pname, '
565 'GLsizei bufSize, GLint* params', },
566 { 'return_type': 'void',
567 'known_as': 'glGetProgramBinary',
568 'versions': [{ 'name': 'glGetProgramBinaryOES' },
569 { 'name': 'glGetProgramBinary',
570 'extensions': ['GL_ARB_get_program_binary'] },
571 { 'name': 'glGetProgramBinary' }],
572 'arguments': 'GLuint program, GLsizei bufSize, GLsizei* length, '
573 'GLenum* binaryFormat, GLvoid* binary' },
574 { 'return_type': 'void',
575 'names': ['glGetProgramInfoLog'],
576 'arguments':
577 'GLuint program, GLsizei bufsize, GLsizei* length, char* infolog', },
578 { 'return_type': 'void',
579 'names': ['glGetProgramiv'],
580 'arguments': 'GLuint program, GLenum pname, GLint* params', },
581 { 'return_type': 'void',
582 'versions': [{ 'name': 'glGetQueryiv',
583 'gl_versions': ['gl3', 'gl4', 'es3'] }],
584 'arguments': 'GLenum target, GLenum pname, GLint* params', },
585 { 'return_type': 'void',
586 'names': ['glGetQueryivARB', 'glGetQueryivEXT'],
587 'arguments': 'GLenum target, GLenum pname, GLint* params', },
588 { 'return_type': 'void',
589 'names': ['glGetQueryObjecti64v'],
590 'arguments': 'GLuint id, GLenum pname, GLint64* params', },
591 { 'return_type': 'void',
592 'versions': [{ 'name': 'glGetQueryObjectiv',
593 'gl_versions': ['gl3', 'gl4', 'es3'] }],
594 'arguments': 'GLuint id, GLenum pname, GLint* params', },
595 { 'return_type': 'void',
596 'names': ['glGetQueryObjectivARB', 'glGetQueryObjectivEXT'],
597 'arguments': 'GLuint id, GLenum pname, GLint* params', },
598 { 'return_type': 'void',
599 'names': ['glGetQueryObjectui64v', 'glGetQueryObjectui64vEXT'],
600 'arguments': 'GLuint id, GLenum pname, GLuint64* params', },
601 { 'return_type': 'void',
602 'versions': [{ 'name': 'glGetQueryObjectuiv',
603 'gl_versions': ['gl3', 'gl4', 'es3'] }],
604 'arguments': 'GLuint id, GLenum pname, GLuint* params', },
605 { 'return_type': 'void',
606 'names': ['glGetQueryObjectuivARB', 'glGetQueryObjectuivEXT'],
607 'arguments': 'GLuint id, GLenum pname, GLuint* params', },
608 { 'return_type': 'void',
609 'names': ['glGetRenderbufferParameterivEXT', 'glGetRenderbufferParameteriv'],
610 'arguments': 'GLenum target, GLenum pname, GLint* params', },
611 { 'return_type': 'void',
612 'versions': [{ 'name': 'glGetSamplerParameterfv',
613 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.2 or higher.
614 'arguments': 'GLuint sampler, GLenum pname, GLfloat* params', },
615 { 'return_type': 'void',
616 'versions': [{ 'name': 'glGetSamplerParameteriv',
617 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.2 or higher.
618 'arguments': 'GLuint sampler, GLenum pname, GLint* params', },
619 { 'return_type': 'void',
620 'names': ['glGetShaderInfoLog'],
621 'arguments':
622 'GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog', },
623 { 'return_type': 'void',
624 'names': ['glGetShaderiv'],
625 'arguments': 'GLuint shader, GLenum pname, GLint* params', },
626 { 'return_type': 'void',
627 'names': ['glGetShaderPrecisionFormat'],
628 'arguments': 'GLenum shadertype, GLenum precisiontype, '
629 'GLint* range, GLint* precision', },
630 { 'return_type': 'void',
631 'names': ['glGetShaderSource'],
632 'arguments':
633 'GLuint shader, GLsizei bufsize, GLsizei* length, char* source', },
634 { 'return_type': 'const GLubyte*',
635 'names': ['glGetString'],
636 'arguments': 'GLenum name', },
637 { 'return_type': 'void',
638 'names': ['glGetSynciv'],
639 'arguments':
640 'GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length,'
641 'GLint* values', },
642 { 'return_type': 'void',
643 'names': ['glGetTexLevelParameterfv'],
644 'arguments': 'GLenum target, GLint level, GLenum pname, GLfloat* params', },
645 { 'return_type': 'void',
646 'names': ['glGetTexLevelParameteriv'],
647 'arguments': 'GLenum target, GLint level, GLenum pname, GLint* params', },
648 { 'return_type': 'void',
649 'names': ['glGetTexParameterfv'],
650 'arguments': 'GLenum target, GLenum pname, GLfloat* params', },
651 { 'return_type': 'void',
652 'names': ['glGetTexParameteriv'],
653 'arguments': 'GLenum target, GLenum pname, GLint* params', },
654 { 'return_type': 'void',
655 'versions': [{ 'name': 'glGetTransformFeedbackVarying',
656 'gl_versions': ['gl3', 'gl4', 'es3'] }],
657 'arguments': 'GLuint program, GLuint index, GLsizei bufSize, '
658 'GLsizei* length, GLenum* type, char* name', },
659 { 'return_type': 'void',
660 'names': ['glGetTranslatedShaderSourceANGLE'],
661 'arguments':
662 'GLuint shader, GLsizei bufsize, GLsizei* length, char* source', },
663 { 'return_type': 'GLuint',
664 'versions': [{ 'name': 'glGetUniformBlockIndex',
665 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.1 or higher.
666 'arguments': 'GLuint program, const char* uniformBlockName', },
667 { 'return_type': 'void',
668 'names': ['glGetUniformfv'],
669 'arguments': 'GLuint program, GLint location, GLfloat* params', },
670 { 'return_type': 'void',
671 'versions': [{ 'name': 'glGetUniformIndices',
672 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.1 or higher.
673 'arguments': 'GLuint program, GLsizei uniformCount, '
674 'const char* const* uniformNames, GLuint* uniformIndices', },
675 { 'return_type': 'void',
676 'names': ['glGetUniformiv'],
677 'arguments': 'GLuint program, GLint location, GLint* params', },
678 { 'return_type': 'GLint',
679 'names': ['glGetUniformLocation'],
680 'arguments': 'GLuint program, const char* name', },
681 { 'return_type': 'void',
682 'names': ['glGetVertexAttribfv'],
683 'arguments': 'GLuint index, GLenum pname, GLfloat* params', },
684 { 'return_type': 'void',
685 'names': ['glGetVertexAttribiv'],
686 'arguments': 'GLuint index, GLenum pname, GLint* params', },
687 { 'return_type': 'void',
688 'names': ['glGetVertexAttribPointerv'],
689 'arguments': 'GLuint index, GLenum pname, void** pointer', },
690 { 'return_type': 'void',
691 'names': ['glHint'],
692 'arguments': 'GLenum target, GLenum mode', },
693 { 'return_type': 'void',
694 'names': ['glInsertEventMarkerEXT'],
695 'arguments': 'GLsizei length, const char* marker', },
696 { 'return_type': 'void',
697 'versions': [{ 'name': 'glInvalidateFramebuffer',
698 'gl_versions': ['gl4', 'es3'] }], # GL 4.3 or higher.
699 'arguments': 'GLenum target, GLsizei numAttachments, '
700 'const GLenum* attachments' },
701 { 'return_type': 'void',
702 'versions': [{ 'name': 'glInvalidateSubFramebuffer',
703 'gl_versions': ['gl4', 'es3'] }], # GL 4.3 or higher.
704 'arguments':
705 'GLenum target, GLsizei numAttachments, const GLenum* attachments, '
706 'GLint x, GLint y, GLint width, GLint height', },
707 { 'return_type': 'GLboolean',
708 'names': ['glIsBuffer'],
709 'arguments': 'GLuint buffer', },
710 { 'return_type': 'GLboolean',
711 'names': ['glIsEnabled'],
712 'arguments': 'GLenum cap', },
713 { 'return_type': 'GLboolean',
714 'known_as': 'glIsFenceAPPLE',
715 'versions': [{ 'name': 'glIsFenceAPPLE',
716 'extensions': ['GL_APPLE_fence'] }],
717 'arguments': 'GLuint fence', },
718 { 'return_type': 'GLboolean',
719 'names': ['glIsFenceNV'],
720 'arguments': 'GLuint fence', },
721 { 'return_type': 'GLboolean',
722 'names': ['glIsFramebufferEXT', 'glIsFramebuffer'],
723 'arguments': 'GLuint framebuffer', },
724 { 'return_type': 'GLboolean',
725 'names': ['glIsProgram'],
726 'arguments': 'GLuint program', },
727 { 'return_type': 'GLboolean',
728 'versions': [{ 'name': 'glIsQuery',
729 'gl_versions': ['gl3', 'gl4', 'es3'] }],
730 'arguments': 'GLuint query', },
731 { 'return_type': 'GLboolean',
732 'names': ['glIsQueryARB', 'glIsQueryEXT'],
733 'arguments': 'GLuint query', },
734 { 'return_type': 'GLboolean',
735 'names': ['glIsRenderbufferEXT', 'glIsRenderbuffer'],
736 'arguments': 'GLuint renderbuffer', },
737 { 'return_type': 'GLboolean',
738 'versions': [{ 'name': 'glIsSampler',
739 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.2 or higher.
740 'arguments': 'GLuint sampler', },
741 { 'return_type': 'GLboolean',
742 'names': ['glIsShader'],
743 'arguments': 'GLuint shader', },
744 { 'return_type': 'GLboolean',
745 'names': ['glIsSync'],
746 'arguments': 'GLsync sync', },
747 { 'return_type': 'GLboolean',
748 'names': ['glIsTexture'],
749 'arguments': 'GLuint texture', },
750 { 'return_type': 'GLboolean',
751 'versions': [{ 'name': 'glIsTransformFeedback',
752 'gl_versions': ['gl4', 'es3'] }],
753 'arguments': 'GLuint id', },
754 { 'return_type': 'GLboolean',
755 'known_as': 'glIsVertexArrayOES',
756 'versions': [{ 'name': 'glIsVertexArray',
757 'gl_versions': ['gl3', 'gl4', 'es3'] },
758 { 'name': 'glIsVertexArray',
759 'extensions': ['GL_ARB_vertex_array_object'] },
760 { 'name': 'glIsVertexArrayOES' },
761 { 'name': 'glIsVertexArrayAPPLE',
762 'extensions': ['GL_APPLE_vertex_array_object'] }],
763 'arguments': 'GLuint array' },
764 { 'return_type': 'void',
765 'names': ['glLineWidth'],
766 'arguments': 'GLfloat width', },
767 { 'return_type': 'void',
768 'names': ['glLinkProgram'],
769 'arguments': 'GLuint program', },
770 { 'return_type': 'void*',
771 'known_as': 'glMapBuffer',
772 'names': ['glMapBufferOES', 'glMapBuffer'],
773 'arguments': 'GLenum target, GLenum access', },
774 { 'return_type': 'void*',
775 'known_as': 'glMapBufferRange',
776 'versions': [{ 'name': 'glMapBufferRange',
777 'gl_versions': ['gl3', 'gl4', 'es3'] },
778 { 'name': 'glMapBufferRange',
779 'extensions': ['GL_ARB_map_buffer_range'] },
780 { 'name': 'glMapBufferRangeEXT',
781 'extensions': ['GL_EXT_map_buffer_range'] }],
782 'arguments':
783 'GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access', },
784 { 'return_type': 'void',
785 'known_as': 'glMatrixLoadfEXT',
786 'versions': [{ 'name': 'glMatrixLoadfEXT',
787 'gl_versions': ['gl4'],
788 'extensions': ['GL_EXT_direct_state_access'] },
789 { 'name': 'glMatrixLoadfEXT',
790 'gl_versions': ['es3'],
791 'extensions': ['GL_NV_path_rendering'] }],
792 'arguments': 'GLenum matrixMode, const GLfloat* m' },
793 { 'return_type': 'void',
794 'known_as': 'glMatrixLoadIdentityEXT',
795 'versions': [{ 'name': 'glMatrixLoadIdentityEXT',
796 'gl_versions': ['gl4'],
797 'extensions': ['GL_EXT_direct_state_access'] },
798 { 'name': 'glMatrixLoadIdentityEXT',
799 'gl_versions': ['es3'],
800 'extensions': ['GL_NV_path_rendering'] }],
801 'arguments': 'GLenum matrixMode' },
802 { 'return_type': 'void',
803 'versions': [{ 'name': 'glPauseTransformFeedback',
804 'gl_versions': ['gl4', 'es3'] }],
805 'arguments': 'void', },
806 { 'return_type': 'void',
807 'names': ['glPixelStorei'],
808 'arguments': 'GLenum pname, GLint param', },
809 { 'return_type': 'void',
810 'names': ['glPointParameteri'],
811 'arguments': 'GLenum pname, GLint param', },
812 { 'return_type': 'void',
813 'names': ['glPolygonOffset'],
814 'arguments': 'GLfloat factor, GLfloat units', },
815 { 'return_type': 'void',
816 'names': ['glPopGroupMarkerEXT'],
817 'arguments': 'void', },
818 { 'return_type': 'void',
819 'known_as': 'glProgramBinary',
820 'versions': [{ 'name': 'glProgramBinaryOES' },
821 { 'name': 'glProgramBinary',
822 'extensions': ['GL_ARB_get_program_binary'] },
823 { 'name': 'glProgramBinary' }],
824 'arguments': 'GLuint program, GLenum binaryFormat, '
825 'const GLvoid* binary, GLsizei length' },
826 { 'return_type': 'void',
827 'versions': [{ 'name': 'glProgramParameteri',
828 'extensions': ['GL_ARB_get_program_binary'] },
829 { 'name': 'glProgramParameteri' }],
830 'arguments': 'GLuint program, GLenum pname, GLint value' },
831 { 'return_type': 'void',
832 'names': ['glPushGroupMarkerEXT'],
833 'arguments': 'GLsizei length, const char* marker', },
834 { 'return_type': 'void',
835 'names': ['glQueryCounter', 'glQueryCounterEXT'],
836 'arguments': 'GLuint id, GLenum target', },
837 { 'return_type': 'void',
838 'names': ['glReadBuffer'],
839 'arguments': 'GLenum src', },
840 { 'return_type': 'void',
841 'names': ['glReadPixels'],
842 'arguments':
843 'GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, '
844 'GLenum type, void* pixels', },
845 { 'return_type': 'void',
846 'names': ['glReleaseShaderCompiler'],
847 'arguments': 'void', },
848 # Multisampling API is different in different GL versions, some require an
849 # explicit resolve step for renderbuffers and/or FBO texture attachments and
850 # some do not. Multiple alternatives might be present in a single
851 # implementation, which require different use of the API and may have
852 # different performance (explicit resolve performing worse, for example).
853 # So even though the function signature is the same across versions, we split
854 # their definitions so that the function to use can be chosen correctly at a
855 # higher level.
856 # TODO(oetuaho@nvidia.com): Some of these might still be possible to combine.
857 # This could also fix weirdness in the mock bindings that's caused by the same
858 # function name appearing multiple times.
859 # This is the ES3 function, which requires explicit resolve:
860 { 'return_type': 'void',
861 'names': ['glRenderbufferStorageEXT', 'glRenderbufferStorage'],
862 'arguments':
863 'GLenum target, GLenum internalformat, GLsizei width, GLsizei height', },
864 { 'return_type': 'void',
865 'names': ['glRenderbufferStorageMultisample'],
866 'arguments': 'GLenum target, GLsizei samples, GLenum internalformat, '
867 'GLsizei width, GLsizei height', },
868 { 'return_type': 'void',
869 'names': ['glRenderbufferStorageMultisampleANGLE',
870 'glRenderbufferStorageMultisample'],
871 'arguments': 'GLenum target, GLsizei samples, GLenum internalformat, '
872 'GLsizei width, GLsizei height', },
873 # In desktop GL, EXT and core versions both have an explicit resolve step,
874 # though desktop core GL implicitly resolves when drawing to a window.
875 # TODO(oetuaho@nvidia.com): Right now this function also doubles as ES2 EXT
876 # function, which has implicit resolve, and for which the fallback is wrong.
877 # Fix this.
878 { 'return_type': 'void',
879 'names': ['glRenderbufferStorageMultisampleEXT',
880 'glRenderbufferStorageMultisample'],
881 'arguments': 'GLenum target, GLsizei samples, GLenum internalformat, '
882 'GLsizei width, GLsizei height', },
883 { 'return_type': 'void',
884 'names': ['glRenderbufferStorageMultisampleIMG'],
885 'arguments': 'GLenum target, GLsizei samples, GLenum internalformat, '
886 'GLsizei width, GLsizei height', },
887 { 'return_type': 'void',
888 'versions': [{ 'name': 'glResumeTransformFeedback',
889 'gl_versions': ['gl4', 'es3'] }],
890 'arguments': 'void', },
891 { 'return_type': 'void',
892 'names': ['glSampleCoverage'],
893 'arguments': 'GLclampf value, GLboolean invert', },
894 { 'return_type': 'void',
895 'versions': [{ 'name': 'glSamplerParameterf',
896 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.2 or higher.
897 'arguments': 'GLuint sampler, GLenum pname, GLfloat param', },
898 { 'return_type': 'void',
899 'versions': [{ 'name': 'glSamplerParameterfv',
900 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.2 or higher.
901 'arguments': 'GLuint sampler, GLenum pname, const GLfloat* params', },
902 { 'return_type': 'void',
903 'versions': [{ 'name': 'glSamplerParameteri',
904 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.2 or higher.
905 'arguments': 'GLuint sampler, GLenum pname, GLint param', },
906 { 'return_type': 'void',
907 'versions': [{ 'name': 'glSamplerParameteriv',
908 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.2 or higher.
909 'arguments': 'GLuint sampler, GLenum pname, const GLint* params', },
910 { 'return_type': 'void',
911 'names': ['glScissor'],
912 'arguments': 'GLint x, GLint y, GLsizei width, GLsizei height', },
913 { 'return_type': 'void',
914 'known_as': 'glSetFenceAPPLE',
915 'versions': [{ 'name': 'glSetFenceAPPLE',
916 'extensions': ['GL_APPLE_fence'] }],
917 'arguments': 'GLuint fence', },
918 { 'return_type': 'void',
919 'names': ['glSetFenceNV'],
920 'arguments': 'GLuint fence, GLenum condition', },
921 { 'return_type': 'void',
922 'names': ['glShaderBinary'],
923 'arguments': 'GLsizei n, const GLuint* shaders, GLenum binaryformat, '
924 'const void* binary, GLsizei length', },
925 { 'return_type': 'void',
926 'names': ['glShaderSource'],
927 'arguments': 'GLuint shader, GLsizei count, const char* const* str, '
928 'const GLint* length',
929 'logging_code': """
930 GL_SERVICE_LOG_CODE_BLOCK({
931 for (GLsizei ii = 0; ii < count; ++ii) {
932 if (str[ii]) {
933 if (length && length[ii] >= 0) {
934 std::string source(str[ii], length[ii]);
935 GL_SERVICE_LOG(" " << ii << ": ---\\n" << source << "\\n---");
936 } else {
937 GL_SERVICE_LOG(" " << ii << ": ---\\n" << str[ii] << "\\n---");
939 } else {
940 GL_SERVICE_LOG(" " << ii << ": NULL");
944 """, },
945 { 'return_type': 'void',
946 'names': ['glStencilFunc'],
947 'arguments': 'GLenum func, GLint ref, GLuint mask', },
948 { 'return_type': 'void',
949 'names': ['glStencilFuncSeparate'],
950 'arguments': 'GLenum face, GLenum func, GLint ref, GLuint mask', },
951 { 'return_type': 'void',
952 'names': ['glStencilMask'],
953 'arguments': 'GLuint mask', },
954 { 'return_type': 'void',
955 'names': ['glStencilMaskSeparate'],
956 'arguments': 'GLenum face, GLuint mask', },
957 { 'return_type': 'void',
958 'names': ['glStencilOp'],
959 'arguments': 'GLenum fail, GLenum zfail, GLenum zpass', },
960 { 'return_type': 'void',
961 'names': ['glStencilOpSeparate'],
962 'arguments': 'GLenum face, GLenum fail, GLenum zfail, GLenum zpass', },
963 { 'return_type': 'GLboolean',
964 'known_as': 'glTestFenceAPPLE',
965 'versions': [{ 'name': 'glTestFenceAPPLE',
966 'extensions': ['GL_APPLE_fence'] }],
967 'arguments': 'GLuint fence', },
968 { 'return_type': 'GLboolean',
969 'names': ['glTestFenceNV'],
970 'arguments': 'GLuint fence', },
971 { 'return_type': 'void',
972 'names': ['glTexImage2D'],
973 'arguments':
974 'GLenum target, GLint level, GLint internalformat, GLsizei width, '
975 'GLsizei height, GLint border, GLenum format, GLenum type, '
976 'const void* pixels', },
977 { 'return_type': 'void',
978 'versions': [{ 'name': 'glTexImage3D',
979 'gl_versions': ['gl3', 'gl4', 'es3'] }],
980 'arguments':
981 'GLenum target, GLint level, GLint internalformat, GLsizei width, '
982 'GLsizei height, GLsizei depth, GLint border, GLenum format, '
983 'GLenum type, const void* pixels', },
984 { 'return_type': 'void',
985 'names': ['glTexParameterf'],
986 'arguments': 'GLenum target, GLenum pname, GLfloat param', },
987 { 'return_type': 'void',
988 'names': ['glTexParameterfv'],
989 'arguments': 'GLenum target, GLenum pname, const GLfloat* params', },
990 { 'return_type': 'void',
991 'names': ['glTexParameteri'],
992 'arguments': 'GLenum target, GLenum pname, GLint param', },
993 { 'return_type': 'void',
994 'names': ['glTexParameteriv'],
995 'arguments': 'GLenum target, GLenum pname, const GLint* params', },
996 { 'return_type': 'void',
997 'known_as': 'glTexStorage2DEXT',
998 'versions': [{ 'name': 'glTexStorage2D',
999 'gl_versions': ['es3'] },
1000 { 'name': 'glTexStorage2D',
1001 'extensions': ['GL_ARB_texture_storage'] },
1002 { 'name': 'glTexStorage2DEXT',
1003 'extensions': ['GL_EXT_texture_storage'] }],
1004 'arguments': 'GLenum target, GLsizei levels, GLenum internalformat, '
1005 'GLsizei width, GLsizei height', },
1006 { 'return_type': 'void',
1007 'versions': [{ 'name': 'glTexStorage3D',
1008 'gl_versions': ['gl4', 'es3'] }], # GL 4.2 or higher.
1009 'arguments': 'GLenum target, GLsizei levels, GLenum internalformat, '
1010 'GLsizei width, GLsizei height, GLsizei depth', },
1011 { 'return_type': 'void',
1012 'names': ['glTexSubImage2D'],
1013 'arguments':
1014 'GLenum target, GLint level, GLint xoffset, GLint yoffset, '
1015 'GLsizei width, GLsizei height, GLenum format, GLenum type, '
1016 'const void* pixels', },
1017 # TODO(zmo): wait for MOCK_METHOD11.
1018 # { 'return_type': 'void',
1019 # 'versions': [{ 'name': 'glTexSubImage3D',
1020 # 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1021 # 'arguments':
1022 # 'GLenum target, GLint level, GLint xoffset, GLint yoffset, '
1023 # 'GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, '
1024 # 'GLenum format, GLenum type, const void* pixels', },
1025 { 'return_type': 'void',
1026 'versions': [{ 'name': 'glTransformFeedbackVaryings',
1027 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1028 'arguments': 'GLuint program, GLsizei count, const char* const* varyings, '
1029 'GLenum bufferMode', },
1030 { 'return_type': 'void',
1031 'names': ['glUniform1f'],
1032 'arguments': 'GLint location, GLfloat x', },
1033 { 'return_type': 'void',
1034 'names': ['glUniform1fv'],
1035 'arguments': 'GLint location, GLsizei count, const GLfloat* v', },
1036 { 'return_type': 'void',
1037 'names': ['glUniform1i'],
1038 'arguments': 'GLint location, GLint x', },
1039 { 'return_type': 'void',
1040 'names': ['glUniform1iv'],
1041 'arguments': 'GLint location, GLsizei count, const GLint* v', },
1042 { 'return_type': 'void',
1043 'versions': [{ 'name': 'glUniform1ui',
1044 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1045 'arguments': 'GLint location, GLuint v0', },
1046 { 'return_type': 'void',
1047 'versions': [{ 'name': 'glUniform1uiv',
1048 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1049 'arguments': 'GLint location, GLsizei count, const GLuint* v', },
1050 { 'return_type': 'void',
1051 'names': ['glUniform2f'],
1052 'arguments': 'GLint location, GLfloat x, GLfloat y', },
1053 { 'return_type': 'void',
1054 'names': ['glUniform2fv'],
1055 'arguments': 'GLint location, GLsizei count, const GLfloat* v', },
1056 { 'return_type': 'void',
1057 'names': ['glUniform2i'],
1058 'arguments': 'GLint location, GLint x, GLint y', },
1059 { 'return_type': 'void',
1060 'names': ['glUniform2iv'],
1061 'arguments': 'GLint location, GLsizei count, const GLint* v', },
1062 { 'return_type': 'void',
1063 'versions': [{ 'name': 'glUniform2ui',
1064 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1065 'arguments': 'GLint location, GLuint v0, GLuint v1', },
1066 { 'return_type': 'void',
1067 'versions': [{ 'name': 'glUniform2uiv',
1068 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1069 'arguments': 'GLint location, GLsizei count, const GLuint* v', },
1070 { 'return_type': 'void',
1071 'names': ['glUniform3f'],
1072 'arguments': 'GLint location, GLfloat x, GLfloat y, GLfloat z', },
1073 { 'return_type': 'void',
1074 'names': ['glUniform3fv'],
1075 'arguments': 'GLint location, GLsizei count, const GLfloat* v', },
1076 { 'return_type': 'void',
1077 'names': ['glUniform3i'],
1078 'arguments': 'GLint location, GLint x, GLint y, GLint z', },
1079 { 'return_type': 'void',
1080 'names': ['glUniform3iv'],
1081 'arguments': 'GLint location, GLsizei count, const GLint* v', },
1082 { 'return_type': 'void',
1083 'versions': [{ 'name': 'glUniform3ui',
1084 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1085 'arguments': 'GLint location, GLuint v0, GLuint v1, GLuint v2', },
1086 { 'return_type': 'void',
1087 'versions': [{ 'name': 'glUniform3uiv',
1088 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1089 'arguments': 'GLint location, GLsizei count, const GLuint* v', },
1090 { 'return_type': 'void',
1091 'names': ['glUniform4f'],
1092 'arguments': 'GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w', },
1093 { 'return_type': 'void',
1094 'names': ['glUniform4fv'],
1095 'arguments': 'GLint location, GLsizei count, const GLfloat* v', },
1096 { 'return_type': 'void',
1097 'names': ['glUniform4i'],
1098 'arguments': 'GLint location, GLint x, GLint y, GLint z, GLint w', },
1099 { 'return_type': 'void',
1100 'names': ['glUniform4iv'],
1101 'arguments': 'GLint location, GLsizei count, const GLint* v', },
1102 { 'return_type': 'void',
1103 'versions': [{ 'name': 'glUniform4ui',
1104 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1105 'arguments': 'GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3', },
1106 { 'return_type': 'void',
1107 'versions': [{ 'name': 'glUniform4uiv',
1108 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1109 'arguments': 'GLint location, GLsizei count, const GLuint* v', },
1110 { 'return_type': 'void',
1111 'versions': [{ 'name': 'glUniformBlockBinding',
1112 'gl_versions': ['gl3', 'gl4', 'es3'] }], # GL 3.1 or higher.
1113 'arguments': 'GLuint program, GLuint uniformBlockIndex, '
1114 'GLuint uniformBlockBinding', },
1115 { 'return_type': 'void',
1116 'names': ['glUniformMatrix2fv'],
1117 'arguments': 'GLint location, GLsizei count, '
1118 'GLboolean transpose, const GLfloat* value', },
1119 { 'return_type': 'void',
1120 'versions': [{ 'name': 'glUniformMatrix2x3fv',
1121 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1122 'arguments': 'GLint location, GLsizei count, '
1123 'GLboolean transpose, const GLfloat* value', },
1124 { 'return_type': 'void',
1125 'versions': [{ 'name': 'glUniformMatrix2x4fv',
1126 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1127 'arguments': 'GLint location, GLsizei count, '
1128 'GLboolean transpose, const GLfloat* value', },
1129 { 'return_type': 'void',
1130 'names': ['glUniformMatrix3fv'],
1131 'arguments': 'GLint location, GLsizei count, '
1132 'GLboolean transpose, const GLfloat* value', },
1133 { 'return_type': 'void',
1134 'versions': [{ 'name': 'glUniformMatrix3x2fv',
1135 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1136 'arguments': 'GLint location, GLsizei count, '
1137 'GLboolean transpose, const GLfloat* value', },
1138 { 'return_type': 'void',
1139 'versions': [{ 'name': 'glUniformMatrix3x4fv',
1140 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1141 'arguments': 'GLint location, GLsizei count, '
1142 'GLboolean transpose, const GLfloat* value', },
1143 { 'return_type': 'void',
1144 'names': ['glUniformMatrix4fv'],
1145 'arguments': 'GLint location, GLsizei count, '
1146 'GLboolean transpose, const GLfloat* value', },
1147 { 'return_type': 'void',
1148 'versions': [{ 'name': 'glUniformMatrix4x2fv',
1149 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1150 'arguments': 'GLint location, GLsizei count, '
1151 'GLboolean transpose, const GLfloat* value', },
1152 { 'return_type': 'void',
1153 'versions': [{ 'name': 'glUniformMatrix4x3fv',
1154 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1155 'arguments': 'GLint location, GLsizei count, '
1156 'GLboolean transpose, const GLfloat* value', },
1157 { 'return_type': 'GLboolean',
1158 'known_as': 'glUnmapBuffer',
1159 'names': ['glUnmapBufferOES', 'glUnmapBuffer'],
1160 'arguments': 'GLenum target', },
1161 { 'return_type': 'void',
1162 'names': ['glUseProgram'],
1163 'arguments': 'GLuint program', },
1164 { 'return_type': 'void',
1165 'names': ['glValidateProgram'],
1166 'arguments': 'GLuint program', },
1167 { 'return_type': 'void',
1168 'names': ['glVertexAttrib1f'],
1169 'arguments': 'GLuint indx, GLfloat x', },
1170 { 'return_type': 'void',
1171 'names': ['glVertexAttrib1fv'],
1172 'arguments': 'GLuint indx, const GLfloat* values', },
1173 { 'return_type': 'void',
1174 'names': ['glVertexAttrib2f'],
1175 'arguments': 'GLuint indx, GLfloat x, GLfloat y', },
1176 { 'return_type': 'void',
1177 'names': ['glVertexAttrib2fv'],
1178 'arguments': 'GLuint indx, const GLfloat* values', },
1179 { 'return_type': 'void',
1180 'names': ['glVertexAttrib3f'],
1181 'arguments': 'GLuint indx, GLfloat x, GLfloat y, GLfloat z', },
1182 { 'return_type': 'void',
1183 'names': ['glVertexAttrib3fv'],
1184 'arguments': 'GLuint indx, const GLfloat* values', },
1185 { 'return_type': 'void',
1186 'names': ['glVertexAttrib4f'],
1187 'arguments': 'GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w', },
1188 { 'return_type': 'void',
1189 'names': ['glVertexAttrib4fv'],
1190 'arguments': 'GLuint indx, const GLfloat* values', },
1191 { 'return_type': 'void',
1192 'known_as': 'glVertexAttribDivisorANGLE',
1193 'names': ['glVertexAttribDivisorARB', 'glVertexAttribDivisorANGLE',
1194 'glVertexAttribDivisor'],
1195 'arguments':
1196 'GLuint index, GLuint divisor', },
1197 { 'return_type': 'void',
1198 'versions': [{ 'name': 'glVertexAttribI4i',
1199 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1200 'arguments': 'GLuint indx, GLint x, GLint y, GLint z, GLint w', },
1201 { 'return_type': 'void',
1202 'versions': [{ 'name': 'glVertexAttribI4iv',
1203 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1204 'arguments': 'GLuint indx, const GLint* values', },
1205 { 'return_type': 'void',
1206 'versions': [{ 'name': 'glVertexAttribI4ui',
1207 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1208 'arguments': 'GLuint indx, GLuint x, GLuint y, GLuint z, GLuint w', },
1209 { 'return_type': 'void',
1210 'versions': [{ 'name': 'glVertexAttribI4uiv',
1211 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1212 'arguments': 'GLuint indx, const GLuint* values', },
1213 { 'return_type': 'void',
1214 'versions': [{ 'name': 'glVertexAttribIPointer',
1215 'gl_versions': ['gl3', 'gl4', 'es3'] }],
1216 'arguments': 'GLuint indx, GLint size, GLenum type, GLsizei stride, '
1217 'const void* ptr', },
1218 { 'return_type': 'void',
1219 'names': ['glVertexAttribPointer'],
1220 'arguments': 'GLuint indx, GLint size, GLenum type, GLboolean normalized, '
1221 'GLsizei stride, const void* ptr', },
1222 { 'return_type': 'void',
1223 'names': ['glViewport'],
1224 'arguments': 'GLint x, GLint y, GLsizei width, GLsizei height', },
1225 { 'return_type': 'GLenum',
1226 'names': ['glWaitSync'],
1227 'arguments':
1228 'GLsync sync, GLbitfield flags, GLuint64 timeout', },
1231 OSMESA_FUNCTIONS = [
1232 { 'return_type': 'void',
1233 'names': ['OSMesaColorClamp'],
1234 'arguments': 'GLboolean enable', },
1235 { 'return_type': 'OSMesaContext',
1236 'names': ['OSMesaCreateContext'],
1237 'arguments': 'GLenum format, OSMesaContext sharelist', },
1238 { 'return_type': 'OSMesaContext',
1239 'names': ['OSMesaCreateContextExt'],
1240 'arguments':
1241 'GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, '
1242 'OSMesaContext sharelist', },
1243 { 'return_type': 'void',
1244 'names': ['OSMesaDestroyContext'],
1245 'arguments': 'OSMesaContext ctx', },
1246 { 'return_type': 'GLboolean',
1247 'names': ['OSMesaGetColorBuffer'],
1248 'arguments': 'OSMesaContext c, GLint* width, GLint* height, GLint* format, '
1249 'void** buffer', },
1250 { 'return_type': 'OSMesaContext',
1251 'names': ['OSMesaGetCurrentContext'],
1252 'arguments': 'void', },
1253 { 'return_type': 'GLboolean',
1254 'names': ['OSMesaGetDepthBuffer'],
1255 'arguments':
1256 'OSMesaContext c, GLint* width, GLint* height, GLint* bytesPerValue, '
1257 'void** buffer', },
1258 { 'return_type': 'void',
1259 'names': ['OSMesaGetIntegerv'],
1260 'arguments': 'GLint pname, GLint* value', },
1261 { 'return_type': 'OSMESAproc',
1262 'names': ['OSMesaGetProcAddress'],
1263 'arguments': 'const char* funcName', },
1264 { 'return_type': 'GLboolean',
1265 'names': ['OSMesaMakeCurrent'],
1266 'arguments': 'OSMesaContext ctx, void* buffer, GLenum type, GLsizei width, '
1267 'GLsizei height', },
1268 { 'return_type': 'void',
1269 'names': ['OSMesaPixelStore'],
1270 'arguments': 'GLint pname, GLint value', },
1273 EGL_FUNCTIONS = [
1274 { 'return_type': 'EGLBoolean',
1275 'names': ['eglBindAPI'],
1276 'arguments': 'EGLenum api', },
1277 { 'return_type': 'EGLBoolean',
1278 'names': ['eglBindTexImage'],
1279 'arguments': 'EGLDisplay dpy, EGLSurface surface, EGLint buffer', },
1280 { 'return_type': 'EGLBoolean',
1281 'names': ['eglChooseConfig'],
1282 'arguments': 'EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, '
1283 'EGLint config_size, EGLint* num_config', },
1284 { 'return_type': 'EGLint',
1285 'versions': [{ 'name': 'eglClientWaitSyncKHR',
1286 'extensions': ['EGL_KHR_fence_sync'] }],
1287 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, '
1288 'EGLTimeKHR timeout' },
1289 { 'return_type': 'EGLBoolean',
1290 'names': ['eglCopyBuffers'],
1291 'arguments':
1292 'EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target', },
1293 { 'return_type': 'EGLContext',
1294 'names': ['eglCreateContext'],
1295 'arguments': 'EGLDisplay dpy, EGLConfig config, EGLContext share_context, '
1296 'const EGLint* attrib_list', },
1297 { 'return_type': 'EGLImageKHR',
1298 'versions': [{ 'name': 'eglCreateImageKHR',
1299 'extensions':
1300 ['EGL_KHR_image_base', 'EGL_KHR_gl_texture_2D_image'] }],
1301 'arguments':
1302 'EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, '
1303 'const EGLint* attrib_list' },
1304 { 'return_type': 'EGLSurface',
1305 'names': ['eglCreatePbufferFromClientBuffer'],
1306 'arguments':
1307 'EGLDisplay dpy, EGLenum buftype, void* buffer, EGLConfig config, '
1308 'const EGLint* attrib_list', },
1309 { 'return_type': 'EGLSurface',
1310 'names': ['eglCreatePbufferSurface'],
1311 'arguments': 'EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list', },
1312 { 'return_type': 'EGLSurface',
1313 'names': ['eglCreatePixmapSurface'],
1314 'arguments': 'EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, '
1315 'const EGLint* attrib_list', },
1316 { 'return_type': 'EGLSyncKHR',
1317 'versions': [{ 'name': 'eglCreateSyncKHR',
1318 'extensions': ['EGL_KHR_fence_sync'] }],
1319 'arguments': 'EGLDisplay dpy, EGLenum type, const EGLint* attrib_list' },
1320 { 'return_type': 'EGLSurface',
1321 'names': ['eglCreateWindowSurface'],
1322 'arguments': 'EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, '
1323 'const EGLint* attrib_list', },
1324 { 'return_type': 'EGLBoolean',
1325 'names': ['eglDestroyContext'],
1326 'arguments': 'EGLDisplay dpy, EGLContext ctx', },
1327 { 'return_type': 'EGLBoolean',
1328 'versions': [{ 'name' : 'eglDestroyImageKHR',
1329 'extensions': ['EGL_KHR_image_base'] }],
1330 'arguments': 'EGLDisplay dpy, EGLImageKHR image' },
1331 { 'return_type': 'EGLBoolean',
1332 'names': ['eglDestroySurface'],
1333 'arguments': 'EGLDisplay dpy, EGLSurface surface', },
1334 { 'return_type': 'EGLBoolean',
1335 'versions': [{ 'name': 'eglDestroySyncKHR',
1336 'extensions': ['EGL_KHR_fence_sync'] }],
1337 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync' },
1338 { 'return_type': 'EGLBoolean',
1339 'names': ['eglGetConfigAttrib'],
1340 'arguments':
1341 'EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint* value', },
1342 { 'return_type': 'EGLBoolean',
1343 'names': ['eglGetConfigs'],
1344 'arguments': 'EGLDisplay dpy, EGLConfig* configs, EGLint config_size, '
1345 'EGLint* num_config', },
1346 { 'return_type': 'EGLContext',
1347 'names': ['eglGetCurrentContext'],
1348 'arguments': 'void', },
1349 { 'return_type': 'EGLDisplay',
1350 'names': ['eglGetCurrentDisplay'],
1351 'arguments': 'void', },
1352 { 'return_type': 'EGLSurface',
1353 'names': ['eglGetCurrentSurface'],
1354 'arguments': 'EGLint readdraw', },
1355 { 'return_type': 'EGLDisplay',
1356 'names': ['eglGetDisplay'],
1357 'arguments': 'EGLNativeDisplayType display_id', },
1358 { 'return_type': 'EGLint',
1359 'names': ['eglGetError'],
1360 'arguments': 'void', },
1361 { 'return_type': 'EGLDisplay',
1362 'known_as': 'eglGetPlatformDisplayEXT',
1363 'versions': [{ 'name': 'eglGetPlatformDisplayEXT',
1364 'extensions': ['EGL_ANGLE_platform_angle'] }],
1365 'arguments': 'EGLenum platform, void* native_display, '
1366 'const EGLint* attrib_list', },
1367 { 'return_type': '__eglMustCastToProperFunctionPointerType',
1368 'names': ['eglGetProcAddress'],
1369 'arguments': 'const char* procname', },
1370 { 'return_type': 'EGLBoolean',
1371 'versions': [{ 'name': 'eglGetSyncAttribKHR',
1372 'extensions': ['EGL_KHR_fence_sync'] }],
1373 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, '
1374 'EGLint* value' },
1375 { 'return_type': 'EGLBoolean',
1376 'names': ['eglGetSyncValuesCHROMIUM'],
1377 'arguments':
1378 'EGLDisplay dpy, EGLSurface surface, '
1379 'EGLuint64CHROMIUM* ust, EGLuint64CHROMIUM* msc, '
1380 'EGLuint64CHROMIUM* sbc', },
1381 { 'return_type': 'EGLBoolean',
1382 'names': ['eglInitialize'],
1383 'arguments': 'EGLDisplay dpy, EGLint* major, EGLint* minor', },
1384 { 'return_type': 'EGLBoolean',
1385 'names': ['eglMakeCurrent'],
1386 'arguments':
1387 'EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx', },
1388 { 'return_type': 'EGLBoolean',
1389 'names': ['eglPostSubBufferNV'],
1390 'arguments': 'EGLDisplay dpy, EGLSurface surface, '
1391 'EGLint x, EGLint y, EGLint width, EGLint height', },
1392 { 'return_type': 'EGLenum',
1393 'names': ['eglQueryAPI'],
1394 'arguments': 'void', },
1395 { 'return_type': 'EGLBoolean',
1396 'names': ['eglQueryContext'],
1397 'arguments':
1398 'EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* value', },
1399 { 'return_type': 'const char*',
1400 'names': ['eglQueryString'],
1401 'arguments': 'EGLDisplay dpy, EGLint name', },
1402 { 'return_type': 'EGLBoolean',
1403 'names': ['eglQuerySurface'],
1404 'arguments':
1405 'EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint* value', },
1406 { 'return_type': 'EGLBoolean',
1407 'names': ['eglQuerySurfacePointerANGLE'],
1408 'arguments':
1409 'EGLDisplay dpy, EGLSurface surface, EGLint attribute, void** value', },
1410 { 'return_type': 'EGLBoolean',
1411 'names': ['eglReleaseTexImage'],
1412 'arguments': 'EGLDisplay dpy, EGLSurface surface, EGLint buffer', },
1413 { 'return_type': 'EGLBoolean',
1414 'names': ['eglReleaseThread'],
1415 'arguments': 'void', },
1416 { 'return_type': 'EGLBoolean',
1417 'names': ['eglSurfaceAttrib'],
1418 'arguments':
1419 'EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value', },
1420 { 'return_type': 'EGLBoolean',
1421 'names': ['eglSwapBuffers'],
1422 'arguments': 'EGLDisplay dpy, EGLSurface surface', },
1423 { 'return_type': 'EGLBoolean',
1424 'names': ['eglSwapInterval'],
1425 'arguments': 'EGLDisplay dpy, EGLint interval', },
1426 { 'return_type': 'EGLBoolean',
1427 'names': ['eglTerminate'],
1428 'arguments': 'EGLDisplay dpy', },
1429 { 'return_type': 'EGLBoolean',
1430 'names': ['eglWaitClient'],
1431 'arguments': 'void', },
1432 { 'return_type': 'EGLBoolean',
1433 'names': ['eglWaitGL'],
1434 'arguments': 'void', },
1435 { 'return_type': 'EGLBoolean',
1436 'names': ['eglWaitNative'],
1437 'arguments': 'EGLint engine', },
1438 { 'return_type': 'EGLint',
1439 'versions': [{ 'name': 'eglWaitSyncKHR',
1440 'extensions': ['EGL_KHR_fence_sync', 'EGL_KHR_wait_sync'] }],
1441 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync, EGLint flags' },
1444 WGL_FUNCTIONS = [
1445 { 'return_type': 'BOOL',
1446 'names': ['wglChoosePixelFormatARB'],
1447 'arguments':
1448 'HDC dc, const int* int_attrib_list, const float* float_attrib_list, '
1449 'UINT max_formats, int* formats, UINT* num_formats', },
1450 { 'return_type': 'BOOL',
1451 'names': ['wglCopyContext'],
1452 'arguments': 'HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask', },
1453 { 'return_type': 'HGLRC',
1454 'names': ['wglCreateContext'],
1455 'arguments': 'HDC hdc', },
1456 { 'return_type': 'HGLRC',
1457 'names': ['wglCreateLayerContext'],
1458 'arguments': 'HDC hdc, int iLayerPlane', },
1459 { 'return_type': 'HPBUFFERARB',
1460 'names': ['wglCreatePbufferARB'],
1461 'arguments': 'HDC hDC, int iPixelFormat, int iWidth, int iHeight, '
1462 'const int* piAttribList', },
1463 { 'return_type': 'BOOL',
1464 'names': ['wglDeleteContext'],
1465 'arguments': 'HGLRC hglrc', },
1466 { 'return_type': 'BOOL',
1467 'names': ['wglDestroyPbufferARB'],
1468 'arguments': 'HPBUFFERARB hPbuffer', },
1469 { 'return_type': 'HGLRC',
1470 'names': ['wglGetCurrentContext'],
1471 'arguments': '', },
1472 { 'return_type': 'HDC',
1473 'names': ['wglGetCurrentDC'],
1474 'arguments': '', },
1475 { 'return_type': 'const char*',
1476 'names': ['wglGetExtensionsStringARB'],
1477 'arguments': 'HDC hDC', },
1478 { 'return_type': 'const char*',
1479 'names': ['wglGetExtensionsStringEXT'],
1480 'arguments': '', },
1481 { 'return_type': 'HDC',
1482 'names': ['wglGetPbufferDCARB'],
1483 'arguments': 'HPBUFFERARB hPbuffer', },
1484 { 'return_type': 'BOOL',
1485 'names': ['wglMakeCurrent'],
1486 'arguments': 'HDC hdc, HGLRC hglrc', },
1487 { 'return_type': 'BOOL',
1488 'names': ['wglQueryPbufferARB'],
1489 'arguments': 'HPBUFFERARB hPbuffer, int iAttribute, int* piValue', },
1490 { 'return_type': 'int',
1491 'names': ['wglReleasePbufferDCARB'],
1492 'arguments': 'HPBUFFERARB hPbuffer, HDC hDC', },
1493 { 'return_type': 'BOOL',
1494 'names': ['wglShareLists'],
1495 'arguments': 'HGLRC hglrc1, HGLRC hglrc2', },
1496 { 'return_type': 'BOOL',
1497 'names': ['wglSwapIntervalEXT'],
1498 'arguments': 'int interval', },
1499 { 'return_type': 'BOOL',
1500 'names': ['wglSwapLayerBuffers'],
1501 'arguments': 'HDC hdc, UINT fuPlanes', },
1504 GLX_FUNCTIONS = [
1505 { 'return_type': 'void',
1506 'names': ['glXBindTexImageEXT'],
1507 'arguments':
1508 'Display* dpy, GLXDrawable drawable, int buffer, int* attribList', },
1509 { 'return_type': 'GLXFBConfig*',
1510 'names': ['glXChooseFBConfig'],
1511 'arguments':
1512 'Display* dpy, int screen, const int* attribList, int* nitems', },
1513 { 'return_type': 'XVisualInfo*',
1514 'names': ['glXChooseVisual'],
1515 'arguments': 'Display* dpy, int screen, int* attribList', },
1516 { 'return_type': 'void',
1517 'names': ['glXCopyContext'],
1518 'arguments':
1519 'Display* dpy, GLXContext src, GLXContext dst, unsigned long mask', },
1520 { 'return_type': 'void',
1521 'names': ['glXCopySubBufferMESA'],
1522 'arguments': 'Display* dpy, GLXDrawable drawable, '
1523 'int x, int y, int width, int height', },
1524 { 'return_type': 'GLXContext',
1525 'names': ['glXCreateContext'],
1526 'arguments':
1527 'Display* dpy, XVisualInfo* vis, GLXContext shareList, int direct', },
1528 { 'return_type': 'GLXContext',
1529 'names': ['glXCreateContextAttribsARB'],
1530 'arguments':
1531 'Display* dpy, GLXFBConfig config, GLXContext share_context, int direct, '
1532 'const int* attrib_list', },
1533 { 'return_type': 'GLXPixmap',
1534 'names': ['glXCreateGLXPixmap'],
1535 'arguments': 'Display* dpy, XVisualInfo* visual, Pixmap pixmap', },
1536 { 'return_type': 'GLXContext',
1537 'names': ['glXCreateNewContext'],
1538 'arguments': 'Display* dpy, GLXFBConfig config, int renderType, '
1539 'GLXContext shareList, int direct', },
1540 { 'return_type': 'GLXPbuffer',
1541 'names': ['glXCreatePbuffer'],
1542 'arguments': 'Display* dpy, GLXFBConfig config, const int* attribList', },
1543 { 'return_type': 'GLXPixmap',
1544 'names': ['glXCreatePixmap'],
1545 'arguments': 'Display* dpy, GLXFBConfig config, '
1546 'Pixmap pixmap, const int* attribList', },
1547 { 'return_type': 'GLXWindow',
1548 'names': ['glXCreateWindow'],
1549 'arguments':
1550 'Display* dpy, GLXFBConfig config, Window win, const int* attribList', },
1551 { 'return_type': 'void',
1552 'names': ['glXDestroyContext'],
1553 'arguments': 'Display* dpy, GLXContext ctx', },
1554 { 'return_type': 'void',
1555 'names': ['glXDestroyGLXPixmap'],
1556 'arguments': 'Display* dpy, GLXPixmap pixmap', },
1557 { 'return_type': 'void',
1558 'names': ['glXDestroyPbuffer'],
1559 'arguments': 'Display* dpy, GLXPbuffer pbuf', },
1560 { 'return_type': 'void',
1561 'names': ['glXDestroyPixmap'],
1562 'arguments': 'Display* dpy, GLXPixmap pixmap', },
1563 { 'return_type': 'void',
1564 'names': ['glXDestroyWindow'],
1565 'arguments': 'Display* dpy, GLXWindow window', },
1566 { 'return_type': 'const char*',
1567 'names': ['glXGetClientString'],
1568 'arguments': 'Display* dpy, int name', },
1569 { 'return_type': 'int',
1570 'names': ['glXGetConfig'],
1571 'arguments': 'Display* dpy, XVisualInfo* visual, int attrib, int* value', },
1572 { 'return_type': 'GLXContext',
1573 'names': ['glXGetCurrentContext'],
1574 'arguments': 'void', },
1575 { 'return_type': 'Display*',
1576 'names': ['glXGetCurrentDisplay'],
1577 'arguments': 'void', },
1578 { 'return_type': 'GLXDrawable',
1579 'names': ['glXGetCurrentDrawable'],
1580 'arguments': 'void', },
1581 { 'return_type': 'GLXDrawable',
1582 'names': ['glXGetCurrentReadDrawable'],
1583 'arguments': 'void', },
1584 { 'return_type': 'int',
1585 'names': ['glXGetFBConfigAttrib'],
1586 'arguments': 'Display* dpy, GLXFBConfig config, int attribute, int* value', },
1587 { 'return_type': 'GLXFBConfig',
1588 'names': ['glXGetFBConfigFromVisualSGIX'],
1589 'arguments': 'Display* dpy, XVisualInfo* visualInfo', },
1590 { 'return_type': 'GLXFBConfig*',
1591 'names': ['glXGetFBConfigs'],
1592 'arguments': 'Display* dpy, int screen, int* nelements', },
1593 { 'return_type': 'bool',
1594 'names': ['glXGetMscRateOML'],
1595 'arguments':
1596 'Display* dpy, GLXDrawable drawable, int32* numerator, '
1597 'int32* denominator' },
1598 { 'return_type': 'void',
1599 'names': ['glXGetSelectedEvent'],
1600 'arguments': 'Display* dpy, GLXDrawable drawable, unsigned long* mask', },
1601 { 'return_type': 'bool',
1602 'names': ['glXGetSyncValuesOML'],
1603 'arguments':
1604 'Display* dpy, GLXDrawable drawable, int64* ust, int64* msc, '
1605 'int64* sbc' },
1606 { 'return_type': 'XVisualInfo*',
1607 'names': ['glXGetVisualFromFBConfig'],
1608 'arguments': 'Display* dpy, GLXFBConfig config', },
1609 { 'return_type': 'int',
1610 'names': ['glXIsDirect'],
1611 'arguments': 'Display* dpy, GLXContext ctx', },
1612 { 'return_type': 'int',
1613 'names': ['glXMakeContextCurrent'],
1614 'arguments':
1615 'Display* dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx', },
1616 { 'return_type': 'int',
1617 'names': ['glXMakeCurrent'],
1618 'arguments': 'Display* dpy, GLXDrawable drawable, GLXContext ctx', },
1619 { 'return_type': 'int',
1620 'names': ['glXQueryContext'],
1621 'arguments': 'Display* dpy, GLXContext ctx, int attribute, int* value', },
1622 { 'return_type': 'void',
1623 'names': ['glXQueryDrawable'],
1624 'arguments':
1625 'Display* dpy, GLXDrawable draw, int attribute, unsigned int* value', },
1626 { 'return_type': 'int',
1627 'names': ['glXQueryExtension'],
1628 'arguments': 'Display* dpy, int* errorb, int* event', },
1629 { 'return_type': 'const char*',
1630 'names': ['glXQueryExtensionsString'],
1631 'arguments': 'Display* dpy, int screen', },
1632 { 'return_type': 'const char*',
1633 'names': ['glXQueryServerString'],
1634 'arguments': 'Display* dpy, int screen, int name', },
1635 { 'return_type': 'int',
1636 'names': ['glXQueryVersion'],
1637 'arguments': 'Display* dpy, int* maj, int* min', },
1638 { 'return_type': 'void',
1639 'names': ['glXReleaseTexImageEXT'],
1640 'arguments': 'Display* dpy, GLXDrawable drawable, int buffer', },
1641 { 'return_type': 'void',
1642 'names': ['glXSelectEvent'],
1643 'arguments': 'Display* dpy, GLXDrawable drawable, unsigned long mask', },
1644 { 'return_type': 'void',
1645 'names': ['glXSwapBuffers'],
1646 'arguments': 'Display* dpy, GLXDrawable drawable', },
1647 { 'return_type': 'void',
1648 'names': ['glXSwapIntervalEXT'],
1649 'arguments': 'Display* dpy, GLXDrawable drawable, int interval', },
1650 { 'return_type': 'void',
1651 'names': ['glXSwapIntervalMESA'],
1652 'arguments': 'unsigned int interval', },
1653 { 'return_type': 'void',
1654 'names': ['glXUseXFont'],
1655 'arguments': 'Font font, int first, int count, int list', },
1656 { 'return_type': 'void',
1657 'names': ['glXWaitGL'],
1658 'arguments': 'void', },
1659 { 'return_type': 'int',
1660 'names': ['glXWaitVideoSyncSGI'],
1661 'arguments': 'int divisor, int remainder, unsigned int* count', },
1662 { 'return_type': 'void',
1663 'names': ['glXWaitX'],
1664 'arguments': 'void', },
1667 FUNCTION_SETS = [
1668 [GL_FUNCTIONS, 'gl', [
1669 'GL/glext.h',
1670 'GLES2/gl2ext.h',
1671 # Files below are Chromium-specific and shipped with Chromium sources.
1672 'GL/glextchromium.h',
1673 'GLES2/gl2chromium.h',
1674 'GLES2/gl2extchromium.h'
1675 ], []],
1676 [OSMESA_FUNCTIONS, 'osmesa', [], []],
1677 [EGL_FUNCTIONS, 'egl', [
1678 'EGL/eglext.h',
1679 # Files below are Chromium-specific and shipped with Chromium sources.
1680 'EGL/eglextchromium.h',
1683 'EGL_ANGLE_d3d_share_handle_client_buffer',
1684 'EGL_ANGLE_surface_d3d_texture_2d_share_handle',
1687 [WGL_FUNCTIONS, 'wgl', ['GL/wglext.h'], []],
1688 [GLX_FUNCTIONS, 'glx', ['GL/glx.h', 'GL/glxext.h'], []],
1692 def GenerateHeader(file, functions, set_name, used_extensions):
1693 """Generates gl_bindings_autogen_x.h"""
1695 # Write file header.
1696 file.write(
1697 """// Copyright (c) 2012 The Chromium Authors. All rights reserved.
1698 // Use of this source code is governed by a BSD-style license that can be
1699 // found in the LICENSE file.
1701 // This file is automatically generated.
1703 #ifndef UI_GFX_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_
1704 #define UI_GFX_GL_GL_BINDINGS_AUTOGEN_%(name)s_H_
1706 namespace gfx {
1708 class GLContext;
1710 """ % {'name': set_name.upper()})
1712 # Write typedefs for function pointer types. Always use the GL name for the
1713 # typedef.
1714 file.write('\n')
1715 for func in functions:
1716 file.write('typedef %s (GL_BINDING_CALL *%sProc)(%s);\n' %
1717 (func['return_type'], func['known_as'], func['arguments']))
1719 # Write declarations for booleans indicating which extensions are available.
1720 file.write('\n')
1721 file.write("struct Extensions%s {\n" % set_name.upper())
1722 for extension in sorted(used_extensions):
1723 file.write(' bool b_%s;\n' % extension)
1724 file.write('};\n')
1725 file.write('\n')
1727 # Write Procs struct.
1728 file.write("struct Procs%s {\n" % set_name.upper())
1729 for func in functions:
1730 file.write(' %sProc %sFn;\n' % (func['known_as'], func['known_as']))
1731 file.write('};\n')
1732 file.write('\n')
1734 # Write Api class.
1735 file.write(
1736 """class GL_EXPORT %(name)sApi {
1737 public:
1738 %(name)sApi();
1739 virtual ~%(name)sApi();
1741 """ % {'name': set_name.upper()})
1742 for func in functions:
1743 file.write(' virtual %s %sFn(%s) = 0;\n' %
1744 (func['return_type'], func['known_as'], func['arguments']))
1745 file.write('};\n')
1746 file.write('\n')
1748 file.write( '} // namespace gfx\n')
1750 # Write macros to invoke function pointers. Always use the GL name for the
1751 # macro.
1752 file.write('\n')
1753 for func in functions:
1754 file.write('#define %s ::gfx::g_current_%s_context->%sFn\n' %
1755 (func['known_as'], set_name.lower(), func['known_as']))
1757 file.write('\n')
1758 file.write('#endif // UI_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' %
1759 set_name.upper())
1762 def GenerateAPIHeader(file, functions, set_name):
1763 """Generates gl_bindings_api_autogen_x.h"""
1765 # Write file header.
1766 file.write(
1767 """// Copyright (c) 2012 The Chromium Authors. All rights reserved.
1768 // Use of this source code is governed by a BSD-style license that can be
1769 // found in the LICENSE file.
1771 // This file is automatically generated.
1773 """ % {'name': set_name.upper()})
1775 # Write API declaration.
1776 for func in functions:
1777 file.write(' %s %sFn(%s) override;\n' %
1778 (func['return_type'], func['known_as'], func['arguments']))
1780 file.write('\n')
1783 def GenerateMockHeader(file, functions, set_name):
1784 """Generates gl_mock_autogen_x.h"""
1786 # Write file header.
1787 file.write(
1788 """// Copyright (c) 2012 The Chromium Authors. All rights reserved.
1789 // Use of this source code is governed by a BSD-style license that can be
1790 // found in the LICENSE file.
1792 // This file is automatically generated.
1794 """ % {'name': set_name.upper()})
1796 # Write API declaration.
1797 for func in functions:
1798 args = func['arguments']
1799 if args == 'void':
1800 args = ''
1801 arg_count = 0
1802 if len(args):
1803 arg_count = func['arguments'].count(',') + 1
1804 file.write(' MOCK_METHOD%d(%s, %s(%s));\n' %
1805 (arg_count, func['known_as'][2:], func['return_type'], args))
1807 file.write('\n')
1810 def GenerateSource(file, functions, set_name, used_extensions):
1811 """Generates gl_bindings_autogen_x.cc"""
1813 # Write file header.
1814 file.write(
1815 """// Copyright (c) 2011 The Chromium Authors. All rights reserved.
1816 // Use of this source code is governed by a BSD-style license that can be
1817 // found in the LICENSE file.
1819 // This file is automatically generated.
1821 #include <string>
1822 #include "base/debug/trace_event.h"
1823 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
1824 #include "ui/gl/gl_bindings.h"
1825 #include "ui/gl/gl_context.h"
1826 #include "ui/gl/gl_implementation.h"
1827 #include "ui/gl/gl_version_info.h"
1828 #include "ui/gl/gl_%s_api_implementation.h"
1830 using gpu::gles2::GLES2Util;
1832 namespace gfx {
1833 """ % set_name.lower())
1835 file.write('\n')
1836 file.write('static bool g_debugBindingsInitialized;\n')
1837 file.write('Driver%s g_driver_%s;\n' % (set_name.upper(), set_name.lower()))
1838 file.write('\n')
1840 # Write stub functions that take the place of some functions before a context
1841 # is initialized. This is done to provide clear asserts on debug build and to
1842 # avoid crashing in case of a bug on release build.
1843 file.write('\n')
1844 for func in functions:
1845 unique_names = set([version['name'] for version in func['versions']])
1846 if len(unique_names) > 1:
1847 file.write('%s %sNotBound(%s) {\n' %
1848 (func['return_type'], func['known_as'], func['arguments']))
1849 file.write(' NOTREACHED();\n')
1850 return_type = func['return_type'].lower()
1851 # Returning 0 works for booleans, integers and pointers.
1852 if return_type != 'void':
1853 file.write(' return 0;\n')
1854 file.write('}\n')
1856 # Write function to initialize the function pointers that are always the same
1857 # and to initialize bindings where choice of the function depends on the
1858 # extension string or the GL version to point to stub functions.
1859 file.write('\n')
1860 file.write('void Driver%s::InitializeStaticBindings() {\n' %
1861 set_name.upper())
1863 def WriteFuncBinding(file, known_as, version_name):
1864 file.write(
1865 ' fn.%sFn = reinterpret_cast<%sProc>(GetGLProcAddress("%s"));\n' %
1866 (known_as, known_as, version_name))
1868 for func in functions:
1869 unique_names = set([version['name'] for version in func['versions']])
1870 if len(unique_names) == 1:
1871 WriteFuncBinding(file, func['known_as'], func['known_as'])
1872 else:
1873 file.write(' fn.%sFn = reinterpret_cast<%sProc>(%sNotBound);\n' %
1874 (func['known_as'], func['known_as'], func['known_as']))
1876 file.write('}\n')
1877 file.write('\n')
1879 # Write function to initialize bindings where choice of the function depends
1880 # on the extension string or the GL version.
1881 file.write("""void Driver%s::InitializeDynamicBindings(GLContext* context) {
1882 DCHECK(context && context->IsCurrent(NULL));
1883 const GLVersionInfo* ver = context->GetVersionInfo();
1884 ALLOW_UNUSED_LOCAL(ver);
1885 std::string extensions = context->GetExtensions() + " ";
1886 ALLOW_UNUSED_LOCAL(extensions);
1888 """ % set_name.upper())
1889 for extension in sorted(used_extensions):
1890 # Extra space at the end of the extension name is intentional, it is used
1891 # as a separator
1892 file.write(' ext.b_%s = extensions.find("%s ") != std::string::npos;\n' %
1893 (extension, extension))
1895 def WrapOr(cond):
1896 if ' || ' in cond:
1897 return '(%s)' % cond
1898 return cond
1900 def WrapAnd(cond):
1901 if ' && ' in cond:
1902 return '(%s)' % cond
1903 return cond
1905 def VersionCondition(version):
1906 conditions = []
1907 if 'gl_versions' in version:
1908 gl_versions = version['gl_versions']
1909 version_cond = ' || '.join(['ver->is_%s' % gl for gl in gl_versions])
1910 conditions.append(WrapOr(version_cond))
1911 if 'extensions' in version and version['extensions']:
1912 ext_cond = ' || '.join(['ext.b_%s' % e for e in version['extensions']])
1913 conditions.append(WrapOr(ext_cond))
1914 return ' && '.join(conditions)
1916 def WriteConditionalFuncBinding(file, func):
1917 # Functions with only one version are always bound unconditionally
1918 assert len(func['versions']) > 1
1919 known_as = func['known_as']
1920 i = 0
1921 first_version = True
1922 while i < len(func['versions']):
1923 version = func['versions'][i]
1924 cond = VersionCondition(version)
1925 combined_conditions = [WrapAnd(cond)]
1926 last_version = i + 1 == len(func['versions'])
1927 while not last_version and \
1928 func['versions'][i + 1]['name'] == version['name']:
1929 i += 1
1930 combinable_cond = VersionCondition(func['versions'][i])
1931 combined_conditions.append(WrapAnd(combinable_cond))
1932 last_version = i + 1 == len(func['versions'])
1933 if len(combined_conditions) > 1:
1934 if [1 for cond in combined_conditions if cond == '']:
1935 cond = ''
1936 else:
1937 cond = ' || '.join(combined_conditions)
1938 # Don't make the last possible binding conditional on anything else but
1939 # that the function isn't already bound to avoid verbose specification
1940 # of functions which have both ARB and core versions with the same name,
1941 # and to be able to bind to mock extension functions in unit tests which
1942 # call InitializeDynamicGLBindings with a stub context that doesn't have
1943 # extensions in its extension string.
1944 # TODO(oetuaho@nvidia.com): Get rid of the fallback.
1945 # http://crbug.com/325668
1946 if cond != '' and not last_version:
1947 if not first_version:
1948 file.write(' if (!fn.%sFn && (%s))\n ' % (known_as, cond))
1949 else:
1950 file.write(' if (%s)\n ' % cond)
1951 elif not first_version:
1952 file.write(' if (!fn.%sFn)\n ' % known_as)
1953 WriteFuncBinding(file, known_as, version['name'])
1954 i += 1
1955 first_version = False
1957 for func in functions:
1958 unique_names = set([version['name'] for version in func['versions']])
1959 if len(unique_names) > 1:
1960 file.write('\n')
1961 file.write(' fn.%sFn = 0;\n' % func['known_as'])
1962 file.write(' debug_fn.%sFn = 0;\n' % func['known_as'])
1963 WriteConditionalFuncBinding(file, func)
1965 # Some new function pointers have been added, so update them in debug bindings
1966 file.write('\n')
1967 file.write(' if (g_debugBindingsInitialized)\n')
1968 file.write(' InitializeDebugBindings();\n')
1969 file.write('}\n')
1970 file.write('\n')
1972 # Write logging wrappers for each function.
1973 file.write('extern "C" {\n')
1974 for func in functions:
1975 return_type = func['return_type']
1976 arguments = func['arguments']
1977 file.write('\n')
1978 file.write('static %s GL_BINDING_CALL Debug_%s(%s) {\n' %
1979 (return_type, func['known_as'], arguments))
1980 argument_names = re.sub(
1981 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments)
1982 argument_names = re.sub(
1983 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names)
1984 log_argument_names = re.sub(
1985 r'const char\* ([a-zA-Z0-9_]+)', r'CONSTCHAR_\1', arguments)
1986 log_argument_names = re.sub(
1987 r'(const )?[a-zA-Z0-9_]+\* ([a-zA-Z0-9_]+)',
1988 r'CONSTVOID_\2', log_argument_names)
1989 log_argument_names = re.sub(
1990 r'(?<!E)GLenum ([a-zA-Z0-9_]+)', r'GLenum_\1', log_argument_names)
1991 log_argument_names = re.sub(
1992 r'(?<!E)GLboolean ([a-zA-Z0-9_]+)', r'GLboolean_\1', log_argument_names)
1993 log_argument_names = re.sub(
1994 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2',
1995 log_argument_names)
1996 log_argument_names = re.sub(
1997 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2',
1998 log_argument_names)
1999 log_argument_names = re.sub(
2000 r'CONSTVOID_([a-zA-Z0-9_]+)',
2001 r'static_cast<const void*>(\1)', log_argument_names)
2002 log_argument_names = re.sub(
2003 r'CONSTCHAR_([a-zA-Z0-9_]+)', r'\1', log_argument_names)
2004 log_argument_names = re.sub(
2005 r'GLenum_([a-zA-Z0-9_]+)', r'GLES2Util::GetStringEnum(\1)',
2006 log_argument_names)
2007 log_argument_names = re.sub(
2008 r'GLboolean_([a-zA-Z0-9_]+)', r'GLES2Util::GetStringBool(\1)',
2009 log_argument_names)
2010 log_argument_names = log_argument_names.replace(',', ' << ", " <<')
2011 if argument_names == 'void' or argument_names == '':
2012 argument_names = ''
2013 log_argument_names = ''
2014 else:
2015 log_argument_names = " << " + log_argument_names
2016 function_name = func['known_as']
2017 if return_type == 'void':
2018 file.write(' GL_SERVICE_LOG("%s" << "(" %s << ")");\n' %
2019 (function_name, log_argument_names))
2020 file.write(' g_driver_%s.debug_fn.%sFn(%s);\n' %
2021 (set_name.lower(), function_name, argument_names))
2022 if 'logging_code' in func:
2023 file.write("%s\n" % func['logging_code'])
2024 else:
2025 file.write(' GL_SERVICE_LOG("%s" << "(" %s << ")");\n' %
2026 (function_name, log_argument_names))
2027 file.write(' %s result = g_driver_%s.debug_fn.%sFn(%s);\n' %
2028 (return_type, set_name.lower(), function_name, argument_names))
2029 if 'logging_code' in func:
2030 file.write("%s\n" % func['logging_code'])
2031 else:
2032 file.write(' GL_SERVICE_LOG("GL_RESULT: " << result);\n')
2033 file.write(' return result;\n')
2034 file.write('}\n')
2035 file.write('} // extern "C"\n')
2037 # Write function to initialize the debug function pointers.
2038 file.write('\n')
2039 file.write('void Driver%s::InitializeDebugBindings() {\n' %
2040 set_name.upper())
2041 for func in functions:
2042 first_name = func['known_as']
2043 file.write(' if (!debug_fn.%sFn) {\n' % first_name)
2044 file.write(' debug_fn.%sFn = fn.%sFn;\n' % (first_name, first_name))
2045 file.write(' fn.%sFn = Debug_%s;\n' % (first_name, first_name))
2046 file.write(' }\n')
2047 file.write(' g_debugBindingsInitialized = true;\n')
2048 file.write('}\n')
2050 # Write function to clear all function pointers.
2051 file.write('\n')
2052 file.write("""void Driver%s::ClearBindings() {
2053 memset(this, 0, sizeof(*this));
2055 """ % set_name.upper())
2057 def MakeArgNames(arguments):
2058 argument_names = re.sub(
2059 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments)
2060 argument_names = re.sub(
2061 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names)
2062 if argument_names == 'void' or argument_names == '':
2063 argument_names = ''
2064 return argument_names
2066 # Write GLApiBase functions
2067 for func in functions:
2068 function_name = func['known_as']
2069 return_type = func['return_type']
2070 arguments = func['arguments']
2071 file.write('\n')
2072 file.write('%s %sApiBase::%sFn(%s) {\n' %
2073 (return_type, set_name.upper(), function_name, arguments))
2074 argument_names = MakeArgNames(arguments)
2075 if return_type == 'void':
2076 file.write(' driver_->fn.%sFn(%s);\n' %
2077 (function_name, argument_names))
2078 else:
2079 file.write(' return driver_->fn.%sFn(%s);\n' %
2080 (function_name, argument_names))
2081 file.write('}\n')
2083 # Write TraceGLApi functions
2084 for func in functions:
2085 function_name = func['known_as']
2086 return_type = func['return_type']
2087 arguments = func['arguments']
2088 file.write('\n')
2089 file.write('%s Trace%sApi::%sFn(%s) {\n' %
2090 (return_type, set_name.upper(), function_name, arguments))
2091 argument_names = MakeArgNames(arguments)
2092 file.write(' TRACE_EVENT_BINARY_EFFICIENT0("gpu", "TraceGLAPI::%s")\n' %
2093 function_name)
2094 if return_type == 'void':
2095 file.write(' %s_api_->%sFn(%s);\n' %
2096 (set_name.lower(), function_name, argument_names))
2097 else:
2098 file.write(' return %s_api_->%sFn(%s);\n' %
2099 (set_name.lower(), function_name, argument_names))
2100 file.write('}\n')
2102 # Write NoContextGLApi functions
2103 if set_name.upper() == "GL":
2104 for func in functions:
2105 function_name = func['known_as']
2106 return_type = func['return_type']
2107 arguments = func['arguments']
2108 file.write('\n')
2109 file.write('%s NoContextGLApi::%sFn(%s) {\n' %
2110 (return_type, function_name, arguments))
2111 argument_names = MakeArgNames(arguments)
2112 no_context_error = "Trying to call %s() without current GL context" % function_name
2113 file.write(' NOTREACHED() << "%s";\n' % no_context_error)
2114 file.write(' LOG(ERROR) << "%s";\n' % no_context_error)
2115 default_value = { 'GLenum': 'static_cast<GLenum>(0)',
2116 'GLuint': '0U',
2117 'GLint': '0',
2118 'GLboolean': 'GL_FALSE',
2119 'GLbyte': '0',
2120 'GLubyte': '0',
2121 'GLbutfield': '0',
2122 'GLushort': '0',
2123 'GLsizei': '0',
2124 'GLfloat': '0.0f',
2125 'GLdouble': '0.0',
2126 'GLsync': 'NULL'}
2127 if return_type.endswith('*'):
2128 file.write(' return NULL;\n')
2129 elif return_type != 'void':
2130 file.write(' return %s;\n' % default_value[return_type])
2131 file.write('}\n')
2133 file.write('\n')
2134 file.write('} // namespace gfx\n')
2137 def GetUniquelyNamedFunctions(functions):
2138 uniquely_named_functions = {}
2140 for func in functions:
2141 for version in func['versions']:
2142 uniquely_named_functions[version['name']] = ({
2143 'name': version['name'],
2144 'return_type': func['return_type'],
2145 'arguments': func['arguments'],
2146 'known_as': func['known_as']
2148 return uniquely_named_functions
2151 def GenerateMockBindingsHeader(file, functions):
2152 """Headers for functions that invoke MockGLInterface members"""
2154 file.write(
2155 """// Copyright (c) 2014 The Chromium Authors. All rights reserved.
2156 // Use of this source code is governed by a BSD-style license that can be
2157 // found in the LICENSE file.
2159 // This file is automatically generated.
2161 """)
2162 uniquely_named_functions = GetUniquelyNamedFunctions(functions)
2164 for key in sorted(uniquely_named_functions.iterkeys()):
2165 func = uniquely_named_functions[key]
2166 file.write('static %s GL_BINDING_CALL Mock_%s(%s);\n' %
2167 (func['return_type'], func['name'], func['arguments']))
2170 def GenerateMockBindingsSource(file, functions):
2171 """Generates functions that invoke MockGLInterface members and a
2172 GetGLProcAddress function that returns addresses to those functions."""
2174 file.write(
2175 """// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2176 // Use of this source code is governed by a BSD-style license that can be
2177 // found in the LICENSE file.
2179 // This file is automatically generated.
2181 #include <string.h>
2183 #include "ui/gl/gl_mock.h"
2185 namespace gfx {
2187 // This is called mainly to prevent the compiler combining the code of mock
2188 // functions with identical contents, so that their function pointers will be
2189 // different.
2190 void MakeFunctionUnique(const char *func_name) {
2191 VLOG(2) << "Calling mock " << func_name;
2194 """)
2195 # Write functions that trampoline into the set MockGLInterface instance.
2196 uniquely_named_functions = GetUniquelyNamedFunctions(functions)
2197 sorted_function_names = sorted(uniquely_named_functions.iterkeys())
2199 for key in sorted_function_names:
2200 func = uniquely_named_functions[key]
2201 file.write('\n')
2202 file.write('%s GL_BINDING_CALL MockGLInterface::Mock_%s(%s) {\n' %
2203 (func['return_type'], func['name'], func['arguments']))
2204 file.write(' MakeFunctionUnique("%s");\n' % func['name'])
2205 arg_re = r'(const )?[a-zA-Z0-9]+((\s*const\s*)?\*)* ([a-zA-Z0-9]+)'
2206 argument_names = re.sub(arg_re, r'\4', func['arguments'])
2207 if argument_names == 'void':
2208 argument_names = ''
2209 function_name = func['known_as'][2:]
2210 if func['return_type'] == 'void':
2211 file.write(' interface_->%s(%s);\n' %
2212 (function_name, argument_names))
2213 else:
2214 file.write(' return interface_->%s(%s);\n' %
2215 (function_name, argument_names))
2216 file.write('}\n')
2218 # Write an 'invalid' function to catch code calling through uninitialized
2219 # function pointers or trying to interpret the return value of
2220 # GLProcAddress().
2221 file.write('\n')
2222 file.write('static void MockInvalidFunction() {\n')
2223 file.write(' NOTREACHED();\n')
2224 file.write('}\n')
2226 # Write a function to lookup a mock GL function based on its name.
2227 file.write('\n')
2228 file.write('void* GL_BINDING_CALL ' +
2229 'MockGLInterface::GetGLProcAddress(const char* name) {\n')
2230 for key in sorted_function_names:
2231 name = uniquely_named_functions[key]['name']
2232 file.write(' if (strcmp(name, "%s") == 0)\n' % name)
2233 file.write(' return reinterpret_cast<void*>(Mock_%s);\n' % name)
2234 # Always return a non-NULL pointer like some EGL implementations do.
2235 file.write(' return reinterpret_cast<void*>(&MockInvalidFunction);\n')
2236 file.write('}\n')
2238 file.write('\n')
2239 file.write('} // namespace gfx\n')
2242 def ParseExtensionFunctionsFromHeader(header_file):
2243 """Parse a C extension header file and return a map from extension names to
2244 a list of functions.
2246 Args:
2247 header_file: Line-iterable C header file.
2248 Returns:
2249 Map of extension name => functions.
2251 extension_start = re.compile(
2252 r'#ifndef ((?:GL|EGL|WGL|GLX)_[A-Z]+_[a-zA-Z]\w+)')
2253 extension_function = re.compile(r'.+\s+([a-z]+\w+)\s*\(')
2254 typedef = re.compile(r'typedef .*')
2255 macro_start = re.compile(r'^#(if|ifdef|ifndef).*')
2256 macro_end = re.compile(r'^#endif.*')
2257 macro_depth = 0
2258 current_extension = None
2259 current_extension_depth = 0
2260 extensions = collections.defaultdict(lambda: [])
2261 for line in header_file:
2262 if macro_start.match(line):
2263 macro_depth += 1
2264 elif macro_end.match(line):
2265 macro_depth -= 1
2266 if macro_depth < current_extension_depth:
2267 current_extension = None
2268 match = extension_start.match(line)
2269 if match:
2270 current_extension = match.group(1)
2271 current_extension_depth = macro_depth
2272 assert current_extension not in extensions, \
2273 "Duplicate extension: " + current_extension
2274 match = extension_function.match(line)
2275 if match and current_extension and not typedef.match(line):
2276 extensions[current_extension].append(match.group(1))
2277 return extensions
2280 def GetExtensionFunctions(extension_headers):
2281 """Parse extension functions from a list of header files.
2283 Args:
2284 extension_headers: List of header file names.
2285 Returns:
2286 Map of extension name => list of functions.
2288 extensions = {}
2289 for header in extension_headers:
2290 extensions.update(ParseExtensionFunctionsFromHeader(open(header)))
2291 return extensions
2294 def GetFunctionToExtensionMap(extensions):
2295 """Construct map from a function names to extensions which define the
2296 function.
2298 Args:
2299 extensions: Map of extension name => functions.
2300 Returns:
2301 Map of function name => extension name.
2303 function_to_extensions = {}
2304 for extension, functions in extensions.items():
2305 for function in functions:
2306 if not function in function_to_extensions:
2307 function_to_extensions[function] = []
2308 function_to_extensions[function].append(extension)
2309 return function_to_extensions
2312 def LooksLikeExtensionFunction(function):
2313 """Heuristic to see if a function name is consistent with extension function
2314 naming."""
2315 vendor = re.match(r'\w+?([A-Z][A-Z]+)$', function)
2316 return vendor is not None and not vendor.group(1) in ['GL', 'API', 'DC']
2319 def FillExtensionsFromHeaders(functions, extension_headers, extra_extensions):
2320 """Determine which functions belong to extensions based on extension headers,
2321 and fill in this information to the functions table for functions that don't
2322 already have the information.
2324 Args:
2325 functions: List of (return type, function versions, arguments).
2326 extension_headers: List of header file names.
2327 extra_extensions: Extensions to add to the list.
2328 Returns:
2329 Set of used extensions.
2331 # Parse known extensions.
2332 extensions = GetExtensionFunctions(extension_headers)
2333 functions_to_extensions = GetFunctionToExtensionMap(extensions)
2335 # Fill in the extension information.
2336 used_extensions = set()
2337 for func in functions:
2338 for version in func['versions']:
2339 name = version['name']
2340 # Make sure we know about all extensions and extension functions.
2341 if 'extensions' in version:
2342 used_extensions.update(version['extensions'])
2343 elif name in functions_to_extensions:
2344 # If there are multiple versions with the same name, assume that they
2345 # already have all the correct conditions, we can't just blindly add
2346 # the same extension conditions to all of them
2347 if len([v for v in func['versions'] if v['name'] == name]) == 1:
2348 version['extensions'] = functions_to_extensions[name]
2349 used_extensions.update(version['extensions'])
2350 elif LooksLikeExtensionFunction(name):
2351 raise RuntimeError('%s looks like an extension function but does not '
2352 'belong to any of the known extensions.' % name)
2354 # Add extensions that do not have any functions.
2355 used_extensions.update(extra_extensions)
2357 return used_extensions
2360 def ResolveHeader(header, header_paths):
2361 paths = header_paths.split(':')
2363 for path in paths:
2364 result = os.path.join(path, header)
2365 if not os.path.isabs(path):
2366 result = os.path.relpath(os.path.join(os.getcwd(), result), os.getcwd())
2367 if os.path.exists(result):
2368 # Always use forward slashes as path separators. Otherwise backslashes
2369 # may be incorrectly interpreted as escape characters.
2370 return result.replace(os.path.sep, '/')
2372 raise Exception('Header %s not found.' % header)
2375 def main(argv):
2376 """This is the main function."""
2378 parser = optparse.OptionParser()
2379 parser.add_option('--inputs', action='store_true')
2380 parser.add_option('--header-paths')
2381 parser.add_option('--verify-order', action='store_true')
2383 options, args = parser.parse_args(argv)
2385 if options.inputs:
2386 for [_, _, headers, _] in FUNCTION_SETS:
2387 for header in headers:
2388 print ResolveHeader(header, options.header_paths)
2389 return 0
2391 directory = '.'
2392 if len(args) >= 1:
2393 directory = args[0]
2395 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS:
2396 # Function names can be specified in two ways (list of unique names or list
2397 # of versions with different binding conditions). Fill in the data to the
2398 # versions list in case it is missing, so that can be used from here on:
2399 for func in functions:
2400 assert 'versions' in func or 'names' in func, 'Function with no names'
2401 if 'versions' not in func:
2402 func['versions'] = [{'name': n} for n in func['names']]
2403 # Use the first version's name unless otherwise specified
2404 if 'known_as' not in func:
2405 func['known_as'] = func['versions'][0]['name']
2406 # Make sure that 'names' is not accidentally used instead of 'versions'
2407 if 'names' in func:
2408 del func['names']
2410 # Check function names in each set is sorted in alphabetical order.
2411 for index in range(len(functions) - 1):
2412 func_name = functions[index]['known_as']
2413 next_func_name = functions[index + 1]['known_as']
2414 if func_name.lower() > next_func_name.lower():
2415 raise Exception(
2416 'function %s is not in alphabetical order' % next_func_name)
2417 if options.verify_order:
2418 continue
2420 extension_headers = [ResolveHeader(h, options.header_paths)
2421 for h in extension_headers]
2422 used_extensions = FillExtensionsFromHeaders(
2423 functions, extension_headers, extensions)
2425 header_file = open(
2426 os.path.join(directory, 'gl_bindings_autogen_%s.h' % set_name), 'wb')
2427 GenerateHeader(header_file, functions, set_name, used_extensions)
2428 header_file.close()
2430 header_file = open(
2431 os.path.join(directory, 'gl_bindings_api_autogen_%s.h' % set_name),
2432 'wb')
2433 GenerateAPIHeader(header_file, functions, set_name)
2434 header_file.close()
2436 source_file = open(
2437 os.path.join(directory, 'gl_bindings_autogen_%s.cc' % set_name), 'wb')
2438 GenerateSource(source_file, functions, set_name, used_extensions)
2439 source_file.close()
2441 if not options.verify_order:
2442 header_file = open(
2443 os.path.join(directory, 'gl_mock_autogen_gl.h'), 'wb')
2444 GenerateMockHeader(header_file, GL_FUNCTIONS, 'gl')
2445 header_file.close()
2447 header_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.h'),
2448 'wb')
2449 GenerateMockBindingsHeader(header_file, GL_FUNCTIONS)
2450 header_file.close()
2452 source_file = open(os.path.join(directory, 'gl_bindings_autogen_mock.cc'),
2453 'wb')
2454 GenerateMockBindingsSource(source_file, GL_FUNCTIONS)
2455 source_file.close()
2456 return 0
2459 if __name__ == '__main__':
2460 sys.exit(main(sys.argv[1:]))