OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """code generator for GL/GLES extension wrangler.""" | 6 """code generator for GL/GLES extension wrangler.""" |
7 | 7 |
8 import os | 8 import os |
9 import collections | 9 import collections |
10 import re | 10 import re |
11 import sys | 11 import sys |
12 | 12 |
13 GL_FUNCTIONS = [ | 13 GL_FUNCTIONS = [ |
14 { 'return_type': 'void', | 14 { 'return_type': 'void', |
15 'names': ['glActiveTexture'], | 15 'names': ['glActiveTexture'], |
16 'arguments': 'GLenum texture', }, | 16 'arguments': 'GLenum texture', }, |
17 { 'return_type': 'void', | 17 { 'return_type': 'void', |
18 'names': ['glAttachShader'], | 18 'names': ['glAttachShader'], |
19 'arguments': 'GLuint program, GLuint shader', }, | 19 'arguments': 'GLuint program, GLuint shader', }, |
20 { 'return_type': 'void', | 20 { 'return_type': 'void', |
21 'names': ['glBeginQuery'], | 21 'names': ['glBeginQuery', 'glBeginQueryEXT', 'glBeginQueryARB'], |
22 'arguments': 'GLenum target, GLuint id', }, | 22 'arguments': 'GLenum target, GLuint id', }, |
23 { 'return_type': 'void', | 23 { 'return_type': 'void', |
24 'names': ['glBindAttribLocation'], | 24 'names': ['glBindAttribLocation'], |
25 'arguments': 'GLuint program, GLuint index, const char* name', }, | 25 'arguments': 'GLuint program, GLuint index, const char* name', }, |
26 { 'return_type': 'void', | 26 { 'return_type': 'void', |
27 'names': ['glBindBuffer'], | 27 'names': ['glBindBuffer'], |
28 'arguments': 'GLenum target, GLuint buffer', }, | 28 'arguments': 'GLenum target, GLuint buffer', }, |
29 { 'return_type': 'void', | 29 { 'return_type': 'void', |
30 'names': ['glBindFragDataLocation'], | 30 'names': ['glBindFragDataLocation'], |
31 'arguments': 'GLuint program, GLuint colorNumber, const char* name', }, | 31 'arguments': 'GLuint program, GLuint colorNumber, const char* name', }, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 { 'return_type': 'GLuint', | 127 { 'return_type': 'GLuint', |
128 'names': ['glCreateProgram'], | 128 'names': ['glCreateProgram'], |
129 'arguments': 'void', }, | 129 'arguments': 'void', }, |
130 { 'return_type': 'GLuint', | 130 { 'return_type': 'GLuint', |
131 'names': ['glCreateShader'], | 131 'names': ['glCreateShader'], |
132 'arguments': 'GLenum type', }, | 132 'arguments': 'GLenum type', }, |
133 { 'return_type': 'void', | 133 { 'return_type': 'void', |
134 'names': ['glCullFace'], | 134 'names': ['glCullFace'], |
135 'arguments': 'GLenum mode', }, | 135 'arguments': 'GLenum mode', }, |
136 { 'return_type': 'void', | 136 { 'return_type': 'void', |
137 'names': ['glDeleteBuffersARB', 'glDeleteBuffers'], | 137 'names': ['glDeleteBuffersARB', 'glDeleteBuffers', 'glDeleteQueriesEXT'], |
138 'arguments': 'GLsizei n, const GLuint* buffers', }, | 138 'arguments': 'GLsizei n, const GLuint* buffers', }, |
139 { 'return_type': 'void', | 139 { 'return_type': 'void', |
140 'names': ['glDeleteFramebuffersEXT', 'glDeleteFramebuffers'], | 140 'names': ['glDeleteFramebuffersEXT', 'glDeleteFramebuffers'], |
141 'arguments': 'GLsizei n, const GLuint* framebuffers', }, | 141 'arguments': 'GLsizei n, const GLuint* framebuffers', }, |
142 { 'return_type': 'void', | 142 { 'return_type': 'void', |
143 'names': ['glDeleteProgram'], | 143 'names': ['glDeleteProgram'], |
144 'arguments': 'GLuint program', }, | 144 'arguments': 'GLuint program', }, |
145 { 'return_type': 'void', | 145 { 'return_type': 'void', |
146 'names': ['glDeleteQueries'], | 146 'names': ['glDeleteQueries'], |
147 'arguments': 'GLsizei n, const GLuint* ids', }, | 147 'arguments': 'GLsizei n, const GLuint* ids', }, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 { 'return_type': 'void', | 194 { 'return_type': 'void', |
195 'names': ['glEGLImageTargetRenderbufferStorageOES'], | 195 'names': ['glEGLImageTargetRenderbufferStorageOES'], |
196 'arguments': 'GLenum target, GLeglImageOES image', }, | 196 'arguments': 'GLenum target, GLeglImageOES image', }, |
197 { 'return_type': 'void', | 197 { 'return_type': 'void', |
198 'names': ['glEnable'], | 198 'names': ['glEnable'], |
199 'arguments': 'GLenum cap', }, | 199 'arguments': 'GLenum cap', }, |
200 { 'return_type': 'void', | 200 { 'return_type': 'void', |
201 'names': ['glEnableVertexAttribArray'], | 201 'names': ['glEnableVertexAttribArray'], |
202 'arguments': 'GLuint index', }, | 202 'arguments': 'GLuint index', }, |
203 { 'return_type': 'void', | 203 { 'return_type': 'void', |
204 'names': ['glEndQuery'], | 204 'names': ['glEndQuery', 'glEndQueryARB', 'glEndQueryEXT'], |
205 'arguments': 'GLenum target', }, | 205 'arguments': 'GLenum target', }, |
206 { 'return_type': 'void', | 206 { 'return_type': 'void', |
207 'names': ['glFinish'], | 207 'names': ['glFinish'], |
208 'arguments': 'void', }, | 208 'arguments': 'void', }, |
209 { 'return_type': 'void', | 209 { 'return_type': 'void', |
210 'names': ['glFlush'], | 210 'names': ['glFlush'], |
211 'arguments': 'void', }, | 211 'arguments': 'void', }, |
212 { 'return_type': 'void', | 212 { 'return_type': 'void', |
213 'names': ['glFramebufferRenderbufferEXT', 'glFramebufferRenderbuffer'], | 213 'names': ['glFramebufferRenderbufferEXT', 'glFramebufferRenderbuffer'], |
214 'arguments': \ | 214 'arguments': \ |
215 'GLenum target, GLenum attachment, GLenum renderbuffertarget, ' | 215 'GLenum target, GLenum attachment, GLenum renderbuffertarget, ' |
216 'GLuint renderbuffer', }, | 216 'GLuint renderbuffer', }, |
217 { 'return_type': 'void', | 217 { 'return_type': 'void', |
218 'names': ['glFramebufferTexture2DEXT', 'glFramebufferTexture2D'], | 218 'names': ['glFramebufferTexture2DEXT', 'glFramebufferTexture2D'], |
219 'arguments': | 219 'arguments': |
220 'GLenum target, GLenum attachment, GLenum textarget, GLuint texture, ' | 220 'GLenum target, GLenum attachment, GLenum textarget, GLuint texture, ' |
221 'GLint level', }, | 221 'GLint level', }, |
222 { 'return_type': 'void', | 222 { 'return_type': 'void', |
223 'names': ['glFrontFace'], | 223 'names': ['glFrontFace'], |
224 'arguments': 'GLenum mode', }, | 224 'arguments': 'GLenum mode', }, |
225 { 'return_type': 'void', | 225 { 'return_type': 'void', |
226 'names': ['glGenBuffersARB', 'glGenBuffers'], | 226 'names': ['glGenBuffersARB', 'glGenBuffers'], |
227 'arguments': 'GLsizei n, GLuint* buffers', }, | 227 'arguments': 'GLsizei n, GLuint* buffers', }, |
228 { 'return_type': 'void', | 228 { 'return_type': 'void', |
229 'names': ['glGenQueries'], | 229 'names': ['glGenQueries', 'glGenQueriesARB', 'glGenQueriesEXT'], |
230 'arguments': 'GLsizei n, GLuint* ids', }, | 230 'arguments': 'GLsizei n, GLuint* ids', }, |
231 { 'return_type': 'void', | 231 { 'return_type': 'void', |
232 'names': ['glGenerateMipmapEXT', 'glGenerateMipmap'], | 232 'names': ['glGenerateMipmapEXT', 'glGenerateMipmap'], |
233 'arguments': 'GLenum target', }, | 233 'arguments': 'GLenum target', }, |
234 { 'return_type': 'void', | 234 { 'return_type': 'void', |
235 'names': ['glGenFramebuffersEXT', 'glGenFramebuffers'], | 235 'names': ['glGenFramebuffersEXT', 'glGenFramebuffers'], |
236 'arguments': 'GLsizei n, GLuint* framebuffers', }, | 236 'arguments': 'GLsizei n, GLuint* framebuffers', }, |
237 { 'return_type': 'void', | 237 { 'return_type': 'void', |
238 'names': ['glGenRenderbuffersEXT', 'glGenRenderbuffers'], | 238 'names': ['glGenRenderbuffersEXT', 'glGenRenderbuffers'], |
239 'arguments': 'GLsizei n, GLuint* renderbuffers', }, | 239 'arguments': 'GLsizei n, GLuint* renderbuffers', }, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 'names': ['glGetIntegerv'], | 284 'names': ['glGetIntegerv'], |
285 'arguments': 'GLenum pname, GLint* params', }, | 285 'arguments': 'GLenum pname, GLint* params', }, |
286 { 'return_type': 'void', | 286 { 'return_type': 'void', |
287 'names': ['glGetProgramiv'], | 287 'names': ['glGetProgramiv'], |
288 'arguments': 'GLuint program, GLenum pname, GLint* params', }, | 288 'arguments': 'GLuint program, GLenum pname, GLint* params', }, |
289 { 'return_type': 'void', | 289 { 'return_type': 'void', |
290 'names': ['glGetProgramInfoLog'], | 290 'names': ['glGetProgramInfoLog'], |
291 'arguments': | 291 'arguments': |
292 'GLuint program, GLsizei bufsize, GLsizei* length, char* infolog', }, | 292 'GLuint program, GLsizei bufsize, GLsizei* length, char* infolog', }, |
293 { 'return_type': 'void', | 293 { 'return_type': 'void', |
294 'names': ['glGetQueryiv'], | 294 'names': ['glGetQueryiv', 'glGetQueryivARB', 'glGetQueryivEXT'], |
295 'arguments': 'GLenum target, GLenum pname, GLint* params', }, | 295 'arguments': 'GLenum target, GLenum pname, GLint* params', }, |
296 { 'return_type': 'void', | 296 { 'return_type': 'void', |
297 'names': ['glGetQueryObjecti64v'], | 297 'names': ['glGetQueryObjecti64v'], |
298 'arguments': 'GLuint id, GLenum pname, GLint64* params', }, | 298 'arguments': 'GLuint id, GLenum pname, GLint64* params', }, |
299 { 'return_type': 'void', | 299 { 'return_type': 'void', |
300 'names': ['glGetQueryObjectiv'], | 300 'names': ['glGetQueryObjectiv'], |
301 'arguments': 'GLuint id, GLenum pname, GLint* params', }, | 301 'arguments': 'GLuint id, GLenum pname, GLint* params', }, |
302 { 'return_type': 'void', | 302 { 'return_type': 'void', |
303 'names': ['glGetQueryObjectui64v'], | 303 'names': ['glGetQueryObjectui64v'], |
304 'arguments': 'GLuint id, GLenum pname, GLuint64* params', }, | 304 'arguments': 'GLuint id, GLenum pname, GLuint64* params', }, |
305 { 'return_type': 'void', | 305 { 'return_type': 'void', |
306 'names': ['glGetQueryObjectuiv'], | 306 'names': ['glGetQueryObjectuiv', 'glGetQueryObjectuivARB', |
| 307 'glGetQueryObjectuivEXT'], |
307 'arguments': 'GLuint id, GLenum pname, GLuint* params', }, | 308 'arguments': 'GLuint id, GLenum pname, GLuint* params', }, |
308 { 'return_type': 'void', | 309 { 'return_type': 'void', |
309 'names': ['glGetRenderbufferParameterivEXT', 'glGetRenderbufferParameteriv'], | 310 'names': ['glGetRenderbufferParameterivEXT', 'glGetRenderbufferParameteriv'], |
310 'arguments': 'GLenum target, GLenum pname, GLint* params', }, | 311 'arguments': 'GLenum target, GLenum pname, GLint* params', }, |
311 { 'return_type': 'void', | 312 { 'return_type': 'void', |
312 'names': ['glGetShaderiv'], | 313 'names': ['glGetShaderiv'], |
313 'arguments': 'GLuint shader, GLenum pname, GLint* params', }, | 314 'arguments': 'GLuint shader, GLenum pname, GLint* params', }, |
314 { 'return_type': 'void', | 315 { 'return_type': 'void', |
315 'names': ['glGetShaderInfoLog'], | 316 'names': ['glGetShaderInfoLog'], |
316 'arguments': | 317 'arguments': |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1391 | 1392 |
1392 def GetFunctionToExtensionMap(extensions): | 1393 def GetFunctionToExtensionMap(extensions): |
1393 """Construct map from a function names to extensions which define the | 1394 """Construct map from a function names to extensions which define the |
1394 function. | 1395 function. |
1395 | 1396 |
1396 Args: | 1397 Args: |
1397 extensions: Map of extension name => functions. | 1398 extensions: Map of extension name => functions. |
1398 Returns: | 1399 Returns: |
1399 Map of function name => extension name. | 1400 Map of function name => extension name. |
1400 """ | 1401 """ |
1401 function_to_extension = {} | 1402 function_to_extensions = {} |
1402 for extension, functions in extensions.items(): | 1403 for extension, functions in extensions.items(): |
1403 for function in functions: | 1404 for function in functions: |
1404 assert function not in function_to_extension, \ | 1405 if not function in function_to_extensions: |
1405 "Duplicate function: " + function | 1406 function_to_extensions[function] = [] |
1406 function_to_extension[function] = extension | 1407 function_to_extensions[function].append(extension) |
1407 return function_to_extension | 1408 return function_to_extensions |
1408 | 1409 |
1409 | 1410 |
1410 def LooksLikeExtensionFunction(function): | 1411 def LooksLikeExtensionFunction(function): |
1411 """Heuristic to see if a function name is consistent with extension function | 1412 """Heuristic to see if a function name is consistent with extension function |
1412 naming.""" | 1413 naming.""" |
1413 vendor = re.match(r'\w+?([A-Z][A-Z]+)$', function) | 1414 vendor = re.match(r'\w+?([A-Z][A-Z]+)$', function) |
1414 return vendor is not None and not vendor.group(1) in ['GL', 'API', 'DC'] | 1415 return vendor is not None and not vendor.group(1) in ['GL', 'API', 'DC'] |
1415 | 1416 |
1416 | 1417 |
1417 def GetUsedExtensionFunctions(functions, extension_headers, extra_extensions): | 1418 def GetUsedExtensionFunctions(functions, extension_headers, extra_extensions): |
1418 """Determine which functions belong to extensions. | 1419 """Determine which functions belong to extensions. |
1419 | 1420 |
1420 Args: | 1421 Args: |
1421 functions: List of (return type, function names, arguments). | 1422 functions: List of (return type, function names, arguments). |
1422 extension_headers: List of header file names. | 1423 extension_headers: List of header file names. |
1423 Returns: | 1424 Returns: |
1424 List of (extension name, [function name alternatives]) sorted with least | 1425 List of (extension name, [function name alternatives]) sorted with least |
1425 preferred extensions first. | 1426 preferred extensions first. |
1426 """ | 1427 """ |
1427 # Parse known extensions. | 1428 # Parse known extensions. |
1428 extensions = GetExtensionFunctions(extension_headers) | 1429 extensions = GetExtensionFunctions(extension_headers) |
1429 functions_to_extension = GetFunctionToExtensionMap(extensions) | 1430 functions_to_extensions = GetFunctionToExtensionMap(extensions) |
1430 | 1431 |
1431 # Collect all used extension functions. | 1432 # Collect all used extension functions. |
1432 used_extension_functions = collections.defaultdict(lambda: []) | 1433 used_extension_functions = collections.defaultdict(lambda: []) |
1433 for func in functions: | 1434 for func in functions: |
1434 for name in func['names']: | 1435 for name in func['names']: |
1435 # Make sure we know about all extension functions. | 1436 # Make sure we know about all extension functions. |
1436 if (LooksLikeExtensionFunction(name) and | 1437 if (LooksLikeExtensionFunction(name) and |
1437 not name in functions_to_extension): | 1438 not name in functions_to_extensions): |
1438 raise RuntimeError('%s looks like an extension function but does not ' | 1439 raise RuntimeError('%s looks like an extension function but does not ' |
1439 'belong to any of the known extensions.' % name) | 1440 'belong to any of the known extensions.' % name) |
1440 if name in functions_to_extension: | 1441 if name in functions_to_extensions: |
1441 extensions = [functions_to_extension[name]] | 1442 extensions = functions_to_extensions[name][:] |
1442 if 'other_extensions' in func: | 1443 if 'other_extensions' in func: |
1443 extensions.extend(func['other_extensions']) | 1444 extensions.extend(func['other_extensions']) |
1444 for extension in extensions: | 1445 for extension in extensions: |
1445 used_extension_functions[extension].append((func['names'][0], name)) | 1446 used_extension_functions[extension].append((func['names'][0], name)) |
1446 | 1447 |
1447 # Add extensions that do not have any functions. | 1448 # Add extensions that do not have any functions. |
1448 used_extension_functions.update(dict( | 1449 used_extension_functions.update(dict( |
1449 [(e, []) for e in extra_extensions if e not in used_extension_functions])) | 1450 [(e, []) for e in extra_extensions if e not in used_extension_functions])) |
1450 | 1451 |
1451 def ExtensionSortKey(name): | 1452 def ExtensionSortKey(name): |
(...skipping 30 matching lines...) Expand all Loading... |
1482 source_file.close() | 1483 source_file.close() |
1483 | 1484 |
1484 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') | 1485 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') |
1485 GenerateMockSource(source_file, GL_FUNCTIONS) | 1486 GenerateMockSource(source_file, GL_FUNCTIONS) |
1486 source_file.close() | 1487 source_file.close() |
1487 return 0 | 1488 return 0 |
1488 | 1489 |
1489 | 1490 |
1490 if __name__ == '__main__': | 1491 if __name__ == '__main__': |
1491 sys.exit(main(sys.argv[1:])) | 1492 sys.exit(main(sys.argv[1:])) |
OLD | NEW |