OLD | NEW |
| (Empty) |
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. | |
5 | |
6 """code generator for GL/GLES extension wrangler.""" | |
7 | |
8 import os | |
9 import collections | |
10 import re | |
11 import sys | |
12 | |
13 GL_FUNCTIONS = [ | |
14 { 'return_type': 'void', | |
15 'names': ['glActiveTexture'], | |
16 'arguments': 'GLenum texture', }, | |
17 { 'return_type': 'void', | |
18 'names': ['glAttachShader'], | |
19 'arguments': 'GLuint program, GLuint shader', }, | |
20 { 'return_type': 'void', | |
21 'names': ['glBeginQuery'], | |
22 'arguments': 'GLenum target, GLuint id', }, | |
23 { 'return_type': 'void', | |
24 'names': ['glBeginQueryARB', 'glBeginQueryEXT'], | |
25 'arguments': 'GLenum target, GLuint id', }, | |
26 { 'return_type': 'void', | |
27 'names': ['glBindAttribLocation'], | |
28 'arguments': 'GLuint program, GLuint index, const char* name', }, | |
29 { 'return_type': 'void', | |
30 'names': ['glBindBuffer'], | |
31 'arguments': 'GLenum target, GLuint buffer', }, | |
32 { 'return_type': 'void', | |
33 'names': ['glBindFragDataLocation'], | |
34 'arguments': 'GLuint program, GLuint colorNumber, const char* name', }, | |
35 { 'return_type': 'void', | |
36 'names': ['glBindFragDataLocationIndexed'], | |
37 'arguments': | |
38 'GLuint program, GLuint colorNumber, GLuint index, const char* name', }, | |
39 { 'return_type': 'void', | |
40 'names': ['glBindFramebufferEXT', 'glBindFramebuffer'], | |
41 'arguments': 'GLenum target, GLuint framebuffer', }, | |
42 { 'return_type': 'void', | |
43 'names': ['glBindRenderbufferEXT', 'glBindRenderbuffer'], | |
44 'arguments': 'GLenum target, GLuint renderbuffer', }, | |
45 { 'return_type': 'void', | |
46 'names': ['glBindTexture'], | |
47 'arguments': 'GLenum target, GLuint texture', }, | |
48 { 'return_type': 'void', | |
49 'names': ['glBlendColor'], | |
50 'arguments': 'GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha', }, | |
51 { 'return_type': 'void', | |
52 'names': ['glBlendEquation'], | |
53 'arguments': ' GLenum mode ', }, | |
54 { 'return_type': 'void', | |
55 'names': ['glBlendEquationSeparate'], | |
56 'arguments': 'GLenum modeRGB, GLenum modeAlpha', }, | |
57 { 'return_type': 'void', | |
58 'names': ['glBlendFunc'], | |
59 'arguments': 'GLenum sfactor, GLenum dfactor', }, | |
60 { 'return_type': 'void', | |
61 'names': ['glBlendFuncSeparate'], | |
62 'arguments': | |
63 'GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha', }, | |
64 { 'return_type': 'void', | |
65 'names': ['glBlitFramebufferEXT', 'glBlitFramebuffer'], | |
66 'arguments': 'GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, ' | |
67 'GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, ' | |
68 'GLbitfield mask, GLenum filter', }, | |
69 { 'return_type': 'void', | |
70 'names': ['glBlitFramebufferANGLE', 'glBlitFramebuffer'], | |
71 'arguments': 'GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, ' | |
72 'GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, ' | |
73 'GLbitfield mask, GLenum filter', }, | |
74 { 'return_type': 'void', | |
75 'names': ['glBufferData'], | |
76 'arguments': 'GLenum target, GLsizei size, const void* data, GLenum usage', }, | |
77 { 'return_type': 'void', | |
78 'names': ['glBufferSubData'], | |
79 'arguments': 'GLenum target, GLint offset, GLsizei size, const void* data', }, | |
80 { 'return_type': 'GLenum', | |
81 'names': ['glCheckFramebufferStatusEXT', | |
82 'glCheckFramebufferStatus'], | |
83 'arguments': 'GLenum target', | |
84 'logging_code': """ | |
85 GL_SERVICE_LOG("GL_RESULT: " << GLES2Util::GetStringEnum(result)); | |
86 """, }, | |
87 { 'return_type': 'void', | |
88 'names': ['glClear'], | |
89 'arguments': 'GLbitfield mask', }, | |
90 { 'return_type': 'void', | |
91 'names': ['glClearColor'], | |
92 'arguments': 'GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha', }, | |
93 { 'return_type': 'void', | |
94 'names': ['glClearDepth'], | |
95 'arguments': 'GLclampd depth', }, | |
96 { 'return_type': 'void', | |
97 'names': ['glClearDepthf'], | |
98 'arguments': 'GLclampf depth', }, | |
99 { 'return_type': 'void', | |
100 'names': ['glClearStencil'], | |
101 'arguments': 'GLint s', }, | |
102 { 'return_type': 'void', | |
103 'names': ['glColorMask'], | |
104 'arguments': | |
105 'GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha', }, | |
106 { 'return_type': 'void', | |
107 'names': ['glCompileShader'], | |
108 'arguments': 'GLuint shader', }, | |
109 { 'return_type': 'void', | |
110 'names': ['glCompressedTexImage2D'], | |
111 'arguments': | |
112 'GLenum target, GLint level, GLenum internalformat, GLsizei width, ' | |
113 'GLsizei height, GLint border, GLsizei imageSize, const void* data', }, | |
114 { 'return_type': 'void', | |
115 'names': ['glCompressedTexSubImage2D'], | |
116 'arguments': | |
117 'GLenum target, GLint level, GLint xoffset, GLint yoffset, ' | |
118 'GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, ' | |
119 'const void* data', }, | |
120 { 'return_type': 'void', | |
121 'names': ['glCopyTexImage2D'], | |
122 'arguments': | |
123 'GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, ' | |
124 'GLsizei width, GLsizei height, GLint border', }, | |
125 { 'return_type': 'void', | |
126 'names': ['glCopyTexSubImage2D'], | |
127 'arguments': | |
128 'GLenum target, GLint level, GLint xoffset, ' | |
129 'GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height', }, | |
130 { 'return_type': 'GLuint', | |
131 'names': ['glCreateProgram'], | |
132 'arguments': 'void', }, | |
133 { 'return_type': 'GLuint', | |
134 'names': ['glCreateShader'], | |
135 'arguments': 'GLenum type', }, | |
136 { 'return_type': 'void', | |
137 'names': ['glCullFace'], | |
138 'arguments': 'GLenum mode', }, | |
139 { 'return_type': 'void', | |
140 'names': ['glDeleteBuffersARB', 'glDeleteBuffers'], | |
141 'arguments': 'GLsizei n, const GLuint* buffers', }, | |
142 { 'return_type': 'void', | |
143 'names': ['glDeleteFramebuffersEXT', 'glDeleteFramebuffers'], | |
144 'arguments': 'GLsizei n, const GLuint* framebuffers', }, | |
145 { 'return_type': 'void', | |
146 'names': ['glDeleteProgram'], | |
147 'arguments': 'GLuint program', }, | |
148 { 'return_type': 'void', | |
149 'names': ['glDeleteQueries'], | |
150 'arguments': 'GLsizei n, const GLuint* ids', }, | |
151 { 'return_type': 'void', | |
152 'names': ['glDeleteQueriesARB', 'glDeleteQueriesEXT'], | |
153 'arguments': 'GLsizei n, const GLuint* ids', }, | |
154 { 'return_type': 'void', | |
155 'names': ['glDeleteRenderbuffersEXT', 'glDeleteRenderbuffers'], | |
156 'arguments': 'GLsizei n, const GLuint* renderbuffers', }, | |
157 { 'return_type': 'void', | |
158 'names': ['glDeleteShader'], | |
159 'arguments': 'GLuint shader', }, | |
160 { 'return_type': 'void', | |
161 'names': ['glDeleteTextures'], | |
162 'arguments': 'GLsizei n, const GLuint* textures', }, | |
163 { 'return_type': 'void', | |
164 'names': ['glDepthFunc'], | |
165 'arguments': 'GLenum func', }, | |
166 { 'return_type': 'void', | |
167 'names': ['glDepthMask'], | |
168 'arguments': 'GLboolean flag', }, | |
169 { 'return_type': 'void', | |
170 'names': ['glDepthRange'], | |
171 'arguments': 'GLclampd zNear, GLclampd zFar', }, | |
172 { 'return_type': 'void', | |
173 'names': ['glDepthRangef'], | |
174 'arguments': 'GLclampf zNear, GLclampf zFar', }, | |
175 { 'return_type': 'void', | |
176 'names': ['glDetachShader'], | |
177 'arguments': 'GLuint program, GLuint shader', }, | |
178 { 'return_type': 'void', | |
179 'names': ['glDisable'], | |
180 'arguments': 'GLenum cap', }, | |
181 { 'return_type': 'void', | |
182 'names': ['glDisableVertexAttribArray'], | |
183 'arguments': 'GLuint index', }, | |
184 { 'return_type': 'void', | |
185 'names': ['glDrawArrays'], | |
186 'arguments': 'GLenum mode, GLint first, GLsizei count', }, | |
187 { 'return_type': 'void', | |
188 'names': ['glDrawBuffer'], | |
189 'arguments': 'GLenum mode', }, | |
190 { 'return_type': 'void', | |
191 'names': ['glDrawBuffersARB'], | |
192 'arguments': 'GLsizei n, const GLenum* bufs', }, | |
193 { 'return_type': 'void', | |
194 'names': ['glDrawElements'], | |
195 'arguments': | |
196 'GLenum mode, GLsizei count, GLenum type, const void* indices', }, | |
197 { 'return_type': 'void', | |
198 'names': ['glEGLImageTargetTexture2DOES'], | |
199 'arguments': 'GLenum target, GLeglImageOES image', }, | |
200 { 'return_type': 'void', | |
201 'names': ['glEGLImageTargetRenderbufferStorageOES'], | |
202 'arguments': 'GLenum target, GLeglImageOES image', }, | |
203 { 'return_type': 'void', | |
204 'names': ['glEnable'], | |
205 'arguments': 'GLenum cap', }, | |
206 { 'return_type': 'void', | |
207 'names': ['glEnableVertexAttribArray'], | |
208 'arguments': 'GLuint index', }, | |
209 { 'return_type': 'void', | |
210 'names': ['glEndQuery'], | |
211 'arguments': 'GLenum target', }, | |
212 { 'return_type': 'void', | |
213 'names': ['glEndQueryARB', 'glEndQueryEXT'], | |
214 'arguments': 'GLenum target', }, | |
215 { 'return_type': 'void', | |
216 'names': ['glFinish'], | |
217 'arguments': 'void', }, | |
218 { 'return_type': 'void', | |
219 'names': ['glFlush'], | |
220 'arguments': 'void', }, | |
221 { 'return_type': 'void', | |
222 'names': ['glFramebufferRenderbufferEXT', 'glFramebufferRenderbuffer'], | |
223 'arguments': \ | |
224 'GLenum target, GLenum attachment, GLenum renderbuffertarget, ' | |
225 'GLuint renderbuffer', }, | |
226 { 'return_type': 'void', | |
227 'names': ['glFramebufferTexture2DEXT', 'glFramebufferTexture2D'], | |
228 'arguments': | |
229 'GLenum target, GLenum attachment, GLenum textarget, GLuint texture, ' | |
230 'GLint level', }, | |
231 { 'return_type': 'void', | |
232 'names': ['glFrontFace'], | |
233 'arguments': 'GLenum mode', }, | |
234 { 'return_type': 'void', | |
235 'names': ['glGenBuffersARB', 'glGenBuffers'], | |
236 'arguments': 'GLsizei n, GLuint* buffers', }, | |
237 { 'return_type': 'void', | |
238 'names': ['glGenQueries'], | |
239 'arguments': 'GLsizei n, GLuint* ids', }, | |
240 { 'return_type': 'void', | |
241 'names': ['glGenQueriesARB', 'glGenQueriesEXT'], | |
242 'arguments': 'GLsizei n, GLuint* ids', }, | |
243 { 'return_type': 'void', | |
244 'names': ['glGenerateMipmapEXT', 'glGenerateMipmap'], | |
245 'arguments': 'GLenum target', }, | |
246 { 'return_type': 'void', | |
247 'names': ['glGenFramebuffersEXT', 'glGenFramebuffers'], | |
248 'arguments': 'GLsizei n, GLuint* framebuffers', }, | |
249 { 'return_type': 'void', | |
250 'names': ['glGenRenderbuffersEXT', 'glGenRenderbuffers'], | |
251 'arguments': 'GLsizei n, GLuint* renderbuffers', }, | |
252 { 'return_type': 'void', | |
253 'names': ['glGenTextures'], | |
254 'arguments': 'GLsizei n, GLuint* textures', }, | |
255 { 'return_type': 'void', | |
256 'names': ['glGetActiveAttrib'], | |
257 'arguments': | |
258 'GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, ' | |
259 'GLint* size, GLenum* type, char* name', }, | |
260 { 'return_type': 'void', | |
261 'names': ['glGetActiveUniform'], | |
262 'arguments': | |
263 'GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, ' | |
264 'GLint* size, GLenum* type, char* name', }, | |
265 { 'return_type': 'void', | |
266 'names': ['glGetAttachedShaders'], | |
267 'arguments': | |
268 'GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders', }, | |
269 { 'return_type': 'GLint', | |
270 'names': ['glGetAttribLocation'], | |
271 'arguments': 'GLuint program, const char* name', }, | |
272 { 'return_type': 'void', | |
273 'names': ['glGetBooleanv'], | |
274 'arguments': 'GLenum pname, GLboolean* params', }, | |
275 { 'return_type': 'void', | |
276 'names': ['glGetBufferParameteriv'], | |
277 'arguments': 'GLenum target, GLenum pname, GLint* params', }, | |
278 { 'return_type': 'GLenum', | |
279 'names': ['glGetError'], | |
280 'arguments': 'void', | |
281 'logging_code': """ | |
282 GL_SERVICE_LOG("GL_RESULT: " << GLES2Util::GetStringError(result)); | |
283 """, }, | |
284 { 'return_type': 'void', | |
285 'names': ['glGetFloatv'], | |
286 'arguments': 'GLenum pname, GLfloat* params', }, | |
287 { 'return_type': 'void', | |
288 'names': ['glGetFramebufferAttachmentParameterivEXT', | |
289 'glGetFramebufferAttachmentParameteriv'], | |
290 'arguments': 'GLenum target, ' | |
291 'GLenum attachment, GLenum pname, GLint* params', }, | |
292 { 'return_type': 'GLenum', | |
293 'names': ['glGetGraphicsResetStatusARB'], | |
294 'arguments': 'void', }, | |
295 { 'return_type': 'void', | |
296 'names': ['glGetIntegerv'], | |
297 'arguments': 'GLenum pname, GLint* params', }, | |
298 { 'return_type': 'void', | |
299 'names': ['glGetProgramiv'], | |
300 'arguments': 'GLuint program, GLenum pname, GLint* params', }, | |
301 { 'return_type': 'void', | |
302 'names': ['glGetProgramInfoLog'], | |
303 'arguments': | |
304 'GLuint program, GLsizei bufsize, GLsizei* length, char* infolog', }, | |
305 { 'return_type': 'void', | |
306 'names': ['glGetQueryiv'], | |
307 'arguments': 'GLenum target, GLenum pname, GLint* params', }, | |
308 { 'return_type': 'void', | |
309 'names': ['glGetQueryivARB', 'glGetQueryivEXT'], | |
310 'arguments': 'GLenum target, GLenum pname, GLint* params', }, | |
311 { 'return_type': 'void', | |
312 'names': ['glGetQueryObjecti64v'], | |
313 'arguments': 'GLuint id, GLenum pname, GLint64* params', }, | |
314 { 'return_type': 'void', | |
315 'names': ['glGetQueryObjectiv'], | |
316 'arguments': 'GLuint id, GLenum pname, GLint* params', }, | |
317 { 'return_type': 'void', | |
318 'names': ['glGetQueryObjectui64v'], | |
319 'arguments': 'GLuint id, GLenum pname, GLuint64* params', }, | |
320 { 'return_type': 'void', | |
321 'names': ['glGetQueryObjectuiv'], | |
322 'arguments': 'GLuint id, GLenum pname, GLuint* params', }, | |
323 { 'return_type': 'void', | |
324 'names': ['glGetQueryObjectuivARB', 'glGetQueryObjectuivEXT'], | |
325 'arguments': 'GLuint id, GLenum pname, GLuint* params', }, | |
326 { 'return_type': 'void', | |
327 'names': ['glGetRenderbufferParameterivEXT', 'glGetRenderbufferParameteriv'], | |
328 'arguments': 'GLenum target, GLenum pname, GLint* params', }, | |
329 { 'return_type': 'void', | |
330 'names': ['glGetShaderiv'], | |
331 'arguments': 'GLuint shader, GLenum pname, GLint* params', }, | |
332 { 'return_type': 'void', | |
333 'names': ['glGetShaderInfoLog'], | |
334 'arguments': | |
335 'GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog', }, | |
336 { 'return_type': 'void', | |
337 'names': ['glGetShaderPrecisionFormat'], | |
338 'arguments': 'GLenum shadertype, GLenum precisiontype, ' | |
339 'GLint* range, GLint* precision', }, | |
340 { 'return_type': 'void', | |
341 'names': ['glGetShaderSource'], | |
342 'arguments': | |
343 'GLuint shader, GLsizei bufsize, GLsizei* length, char* source', }, | |
344 { 'return_type': 'const GLubyte*', | |
345 'names': ['glGetString'], | |
346 'arguments': 'GLenum name', }, | |
347 { 'return_type': 'void', | |
348 'names': ['glGetTexLevelParameterfv'], | |
349 'arguments': 'GLenum target, GLint level, GLenum pname, GLfloat* params', }, | |
350 { 'return_type': 'void', | |
351 'names': ['glGetTexLevelParameteriv'], | |
352 'arguments': 'GLenum target, GLint level, GLenum pname, GLint* params', }, | |
353 { 'return_type': 'void', | |
354 'names': ['glGetTexParameterfv'], | |
355 'arguments': 'GLenum target, GLenum pname, GLfloat* params', }, | |
356 { 'return_type': 'void', | |
357 'names': ['glGetTexParameteriv'], | |
358 'arguments': 'GLenum target, GLenum pname, GLint* params', }, | |
359 { 'return_type': 'void', | |
360 'names': ['glGetTranslatedShaderSourceANGLE'], | |
361 'arguments': | |
362 'GLuint shader, GLsizei bufsize, GLsizei* length, char* source', }, | |
363 { 'return_type': 'void', | |
364 'names': ['glGetUniformfv'], | |
365 'arguments': 'GLuint program, GLint location, GLfloat* params', }, | |
366 { 'return_type': 'void', | |
367 'names': ['glGetUniformiv'], | |
368 'arguments': 'GLuint program, GLint location, GLint* params', }, | |
369 { 'return_type': 'GLint', | |
370 'names': ['glGetUniformLocation'], | |
371 'arguments': 'GLuint program, const char* name', }, | |
372 { 'return_type': 'void', | |
373 'names': ['glGetVertexAttribfv'], | |
374 'arguments': 'GLuint index, GLenum pname, GLfloat* params', }, | |
375 { 'return_type': 'void', | |
376 'names': ['glGetVertexAttribiv'], | |
377 'arguments': 'GLuint index, GLenum pname, GLint* params', }, | |
378 { 'return_type': 'void', | |
379 'names': ['glGetVertexAttribPointerv'], | |
380 'arguments': 'GLuint index, GLenum pname, void** pointer', }, | |
381 { 'return_type': 'void', | |
382 'names': ['glHint'], | |
383 'arguments': 'GLenum target, GLenum mode', }, | |
384 { 'return_type': 'GLboolean', | |
385 'names': ['glIsBuffer'], | |
386 'arguments': 'GLuint buffer', }, | |
387 { 'return_type': 'GLboolean', | |
388 'names': ['glIsEnabled'], | |
389 'arguments': 'GLenum cap', }, | |
390 { 'return_type': 'GLboolean', | |
391 'names': ['glIsFramebufferEXT', 'glIsFramebuffer'], | |
392 'arguments': 'GLuint framebuffer', }, | |
393 { 'return_type': 'GLboolean', | |
394 'names': ['glIsProgram'], | |
395 'arguments': 'GLuint program', }, | |
396 { 'return_type': 'GLboolean', | |
397 'names': ['glIsQueryARB', 'glIsQueryEXT'], | |
398 'arguments': 'GLuint query', }, | |
399 { 'return_type': 'GLboolean', | |
400 'names': ['glIsRenderbufferEXT', 'glIsRenderbuffer'], | |
401 'arguments': 'GLuint renderbuffer', }, | |
402 { 'return_type': 'GLboolean', | |
403 'names': ['glIsShader'], | |
404 'arguments': 'GLuint shader', }, | |
405 { 'return_type': 'GLboolean', | |
406 'names': ['glIsTexture'], | |
407 'arguments': 'GLuint texture', }, | |
408 { 'return_type': 'void', | |
409 'names': ['glLineWidth'], | |
410 'arguments': 'GLfloat width', }, | |
411 { 'return_type': 'void', | |
412 'names': ['glLinkProgram'], | |
413 'arguments': 'GLuint program', }, | |
414 { 'return_type': 'void*', | |
415 'names': ['glMapBuffer', 'glMapBufferOES'], | |
416 'arguments': 'GLenum target, GLenum access', }, | |
417 { 'return_type': 'void', | |
418 'names': ['glPixelStorei'], | |
419 'arguments': 'GLenum pname, GLint param', }, | |
420 { 'return_type': 'void', | |
421 'names': ['glPolygonOffset'], | |
422 'arguments': 'GLfloat factor, GLfloat units', }, | |
423 { 'return_type': 'void', | |
424 'names': ['glQueryCounter'], | |
425 'arguments': 'GLuint id, GLenum target', }, | |
426 { 'return_type': 'void', | |
427 'names': ['glReadBuffer'], | |
428 'arguments': 'GLenum src', }, | |
429 { 'return_type': 'void', | |
430 'names': ['glReadPixels'], | |
431 'arguments': | |
432 'GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, ' | |
433 'GLenum type, void* pixels', }, | |
434 { 'return_type': 'void', | |
435 'names': ['glReleaseShaderCompiler'], | |
436 'arguments': 'void', }, | |
437 { 'return_type': 'void', | |
438 'names': ['glRenderbufferStorageMultisampleEXT', | |
439 'glRenderbufferStorageMultisample'], | |
440 'arguments': 'GLenum target, GLsizei samples, GLenum internalformat, ' | |
441 'GLsizei width, GLsizei height', }, | |
442 { 'return_type': 'void', | |
443 'names': ['glRenderbufferStorageMultisampleANGLE', | |
444 'glRenderbufferStorageMultisample'], | |
445 'arguments': 'GLenum target, GLsizei samples, GLenum internalformat, ' | |
446 'GLsizei width, GLsizei height', }, | |
447 { 'return_type': 'void', | |
448 'names': ['glRenderbufferStorageEXT', 'glRenderbufferStorage'], | |
449 'arguments': | |
450 'GLenum target, GLenum internalformat, GLsizei width, GLsizei height', }, | |
451 { 'return_type': 'void', | |
452 'names': ['glSampleCoverage'], | |
453 'arguments': 'GLclampf value, GLboolean invert', }, | |
454 { 'return_type': 'void', | |
455 'names': ['glScissor'], | |
456 'arguments': 'GLint x, GLint y, GLsizei width, GLsizei height', }, | |
457 { 'return_type': 'void', | |
458 'names': ['glShaderBinary'], | |
459 'arguments': 'GLsizei n, const GLuint* shaders, GLenum binaryformat, ' | |
460 'const void* binary, GLsizei length', }, | |
461 { 'return_type': 'void', | |
462 'names': ['glShaderSource'], | |
463 'arguments': | |
464 'GLuint shader, GLsizei count, const char** str, const GLint* length', | |
465 'logging_code': """ | |
466 GL_SERVICE_LOG_CODE_BLOCK({ | |
467 for (GLsizei ii = 0; ii < count; ++ii) { | |
468 if (str[ii]) { | |
469 if (length && length[ii] >= 0) { | |
470 std::string source(str[ii], length[ii]); | |
471 GL_SERVICE_LOG(" " << ii << ": ---\\n" << source << "\\n---"); | |
472 } else { | |
473 GL_SERVICE_LOG(" " << ii << ": ---\\n" << str[ii] << "\\n---"); | |
474 } | |
475 } else { | |
476 GL_SERVICE_LOG(" " << ii << ": NULL"); | |
477 } | |
478 } | |
479 }); | |
480 """, }, | |
481 { 'return_type': 'void', | |
482 'names': ['glStencilFunc'], | |
483 'arguments': 'GLenum func, GLint ref, GLuint mask', }, | |
484 { 'return_type': 'void', | |
485 'names': ['glStencilFuncSeparate'], | |
486 'arguments': 'GLenum face, GLenum func, GLint ref, GLuint mask', }, | |
487 { 'return_type': 'void', | |
488 'names': ['glStencilMask'], | |
489 'arguments': 'GLuint mask', }, | |
490 { 'return_type': 'void', | |
491 'names': ['glStencilMaskSeparate'], | |
492 'arguments': 'GLenum face, GLuint mask', }, | |
493 { 'return_type': 'void', | |
494 'names': ['glStencilOp'], | |
495 'arguments': 'GLenum fail, GLenum zfail, GLenum zpass', }, | |
496 { 'return_type': 'void', | |
497 'names': ['glStencilOpSeparate'], | |
498 'arguments': 'GLenum face, GLenum fail, GLenum zfail, GLenum zpass', }, | |
499 { 'return_type': 'void', | |
500 'names': ['glTexImage2D'], | |
501 'arguments': | |
502 'GLenum target, GLint level, GLint internalformat, GLsizei width, ' | |
503 'GLsizei height, GLint border, GLenum format, GLenum type, ' | |
504 'const void* pixels', }, | |
505 { 'return_type': 'void', | |
506 'names': ['glTexParameterf'], | |
507 'arguments': 'GLenum target, GLenum pname, GLfloat param', }, | |
508 { 'return_type': 'void', | |
509 'names': ['glTexParameterfv'], | |
510 'arguments': 'GLenum target, GLenum pname, const GLfloat* params', }, | |
511 { 'return_type': 'void', | |
512 'names': ['glTexParameteri'], | |
513 'arguments': 'GLenum target, GLenum pname, GLint param', }, | |
514 { 'return_type': 'void', | |
515 'names': ['glTexParameteriv'], | |
516 'arguments': 'GLenum target, GLenum pname, const GLint* params', }, | |
517 { 'return_type': 'void', | |
518 'names': ['glTexStorage2DEXT'], | |
519 'arguments': 'GLenum target, GLsizei levels, GLenum internalformat, ' | |
520 'GLsizei width, GLsizei height', }, | |
521 { 'return_type': 'void', | |
522 'names': ['glTexSubImage2D'], | |
523 'arguments': | |
524 'GLenum target, GLint level, GLint xoffset, GLint yoffset, ' | |
525 'GLsizei width, GLsizei height, GLenum format, GLenum type, ' | |
526 'const void* pixels', }, | |
527 { 'return_type': 'void', | |
528 'names': ['glUniform1f'], | |
529 'arguments': 'GLint location, GLfloat x', }, | |
530 { 'return_type': 'void', | |
531 'names': ['glUniform1fv'], | |
532 'arguments': 'GLint location, GLsizei count, const GLfloat* v', }, | |
533 { 'return_type': 'void', | |
534 'names': ['glUniform1i'], | |
535 'arguments': 'GLint location, GLint x', }, | |
536 { 'return_type': 'void', | |
537 'names': ['glUniform1iv'], | |
538 'arguments': 'GLint location, GLsizei count, const GLint* v', }, | |
539 { 'return_type': 'void', | |
540 'names': ['glUniform2f'], | |
541 'arguments': 'GLint location, GLfloat x, GLfloat y', }, | |
542 { 'return_type': 'void', | |
543 'names': ['glUniform2fv'], | |
544 'arguments': 'GLint location, GLsizei count, const GLfloat* v', }, | |
545 { 'return_type': 'void', | |
546 'names': ['glUniform2i'], | |
547 'arguments': 'GLint location, GLint x, GLint y', }, | |
548 { 'return_type': 'void', | |
549 'names': ['glUniform2iv'], | |
550 'arguments': 'GLint location, GLsizei count, const GLint* v', }, | |
551 { 'return_type': 'void', | |
552 'names': ['glUniform3f'], | |
553 'arguments': 'GLint location, GLfloat x, GLfloat y, GLfloat z', }, | |
554 { 'return_type': 'void', | |
555 'names': ['glUniform3fv'], | |
556 'arguments': 'GLint location, GLsizei count, const GLfloat* v', }, | |
557 { 'return_type': 'void', | |
558 'names': ['glUniform3i'], | |
559 'arguments': 'GLint location, GLint x, GLint y, GLint z', }, | |
560 { 'return_type': 'void', | |
561 'names': ['glUniform3iv'], | |
562 'arguments': 'GLint location, GLsizei count, const GLint* v', }, | |
563 { 'return_type': 'void', | |
564 'names': ['glUniform4f'], | |
565 'arguments': 'GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w', }, | |
566 { 'return_type': 'void', | |
567 'names': ['glUniform4fv'], | |
568 'arguments': 'GLint location, GLsizei count, const GLfloat* v', }, | |
569 { 'return_type': 'void', | |
570 'names': ['glUniform4i'], | |
571 'arguments': 'GLint location, GLint x, GLint y, GLint z, GLint w', }, | |
572 { 'return_type': 'void', | |
573 'names': ['glUniform4iv'], | |
574 'arguments': 'GLint location, GLsizei count, const GLint* v', }, | |
575 { 'return_type': 'void', | |
576 'names': ['glUniformMatrix2fv'], | |
577 'arguments': 'GLint location, GLsizei count, ' | |
578 'GLboolean transpose, const GLfloat* value', }, | |
579 { 'return_type': 'void', | |
580 'names': ['glUniformMatrix3fv'], | |
581 'arguments': 'GLint location, GLsizei count, ' | |
582 'GLboolean transpose, const GLfloat* value', }, | |
583 { 'return_type': 'void', | |
584 'names': ['glUniformMatrix4fv'], | |
585 'arguments': 'GLint location, GLsizei count, ' | |
586 'GLboolean transpose, const GLfloat* value', }, | |
587 { 'return_type': 'GLboolean', | |
588 'names': ['glUnmapBuffer', 'glUnmapBufferOES'], | |
589 'arguments': 'GLenum target', }, | |
590 { 'return_type': 'void', | |
591 'names': ['glUseProgram'], | |
592 'arguments': 'GLuint program', }, | |
593 { 'return_type': 'void', | |
594 'names': ['glValidateProgram'], | |
595 'arguments': 'GLuint program', }, | |
596 { 'return_type': 'void', | |
597 'names': ['glVertexAttrib1f'], | |
598 'arguments': 'GLuint indx, GLfloat x', }, | |
599 { 'return_type': 'void', | |
600 'names': ['glVertexAttrib1fv'], | |
601 'arguments': 'GLuint indx, const GLfloat* values', }, | |
602 { 'return_type': 'void', | |
603 'names': ['glVertexAttrib2f'], | |
604 'arguments': 'GLuint indx, GLfloat x, GLfloat y', }, | |
605 { 'return_type': 'void', | |
606 'names': ['glVertexAttrib2fv'], | |
607 'arguments': 'GLuint indx, const GLfloat* values', }, | |
608 { 'return_type': 'void', | |
609 'names': ['glVertexAttrib3f'], | |
610 'arguments': 'GLuint indx, GLfloat x, GLfloat y, GLfloat z', }, | |
611 { 'return_type': 'void', | |
612 'names': ['glVertexAttrib3fv'], | |
613 'arguments': 'GLuint indx, const GLfloat* values', }, | |
614 { 'return_type': 'void', | |
615 'names': ['glVertexAttrib4f'], | |
616 'arguments': 'GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w', }, | |
617 { 'return_type': 'void', | |
618 'names': ['glVertexAttrib4fv'], | |
619 'arguments': 'GLuint indx, const GLfloat* values', }, | |
620 { 'return_type': 'void', | |
621 'names': ['glVertexAttribPointer'], | |
622 'arguments': 'GLuint indx, GLint size, GLenum type, GLboolean normalized, ' | |
623 'GLsizei stride, const void* ptr', }, | |
624 { 'return_type': 'void', | |
625 'names': ['glViewport'], | |
626 'arguments': 'GLint x, GLint y, GLsizei width, GLsizei height', }, | |
627 { 'return_type': 'void', | |
628 'names': ['glGenFencesNV'], | |
629 'arguments': 'GLsizei n, GLuint* fences', }, | |
630 { 'return_type': 'void', | |
631 'names': ['glDeleteFencesNV'], | |
632 'arguments': 'GLsizei n, const GLuint* fences', }, | |
633 { 'return_type': 'void', | |
634 'names': ['glSetFenceNV'], | |
635 'arguments': 'GLuint fence, GLenum condition', }, | |
636 { 'return_type': 'GLboolean', | |
637 'names': ['glTestFenceNV'], | |
638 'arguments': 'GLuint fence', }, | |
639 { 'return_type': 'void', | |
640 'names': ['glFinishFenceNV'], | |
641 'arguments': 'GLuint fence', }, | |
642 { 'return_type': 'GLboolean', | |
643 'names': ['glIsFenceNV'], | |
644 'arguments': 'GLuint fence', }, | |
645 { 'return_type': 'void', | |
646 'names': ['glGetFenceivNV'], | |
647 'arguments': 'GLuint fence, GLenum pname, GLint* params', }, | |
648 { 'return_type': 'GLsync', | |
649 'names': ['glFenceSync'], | |
650 'arguments': 'GLenum condition, GLbitfield flags', }, | |
651 { 'return_type': 'void', | |
652 'names': ['glDeleteSync'], | |
653 'arguments': 'GLsync sync', }, | |
654 { 'return_type': 'void', | |
655 'names': ['glGetSynciv'], | |
656 'arguments': | |
657 'GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length,' | |
658 'GLint* values', }, | |
659 { 'return_type': 'void', | |
660 'names': ['glDrawArraysInstancedANGLE', 'glDrawArraysInstancedARB'], | |
661 'arguments': 'GLenum mode, GLint first, GLsizei count, GLsizei primcount', }, | |
662 { 'return_type': 'void', | |
663 'names': ['glDrawElementsInstancedANGLE', 'glDrawElementsInstancedARB'], | |
664 'arguments': | |
665 'GLenum mode, GLsizei count, GLenum type, const void* indices, ' | |
666 'GLsizei primcount', }, | |
667 { 'return_type': 'void', | |
668 'names': ['glVertexAttribDivisorANGLE', 'glVertexAttribDivisorARB'], | |
669 'arguments': | |
670 'GLuint index, GLuint divisor', }, | |
671 ] | |
672 | |
673 OSMESA_FUNCTIONS = [ | |
674 { 'return_type': 'OSMesaContext', | |
675 'names': ['OSMesaCreateContext'], | |
676 'arguments': 'GLenum format, OSMesaContext sharelist', }, | |
677 { 'return_type': 'OSMesaContext', | |
678 'names': ['OSMesaCreateContextExt'], | |
679 'arguments': | |
680 'GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, ' | |
681 'OSMesaContext sharelist', }, | |
682 { 'return_type': 'void', | |
683 'names': ['OSMesaDestroyContext'], | |
684 'arguments': 'OSMesaContext ctx', }, | |
685 { 'return_type': 'GLboolean', | |
686 'names': ['OSMesaMakeCurrent'], | |
687 'arguments': 'OSMesaContext ctx, void* buffer, GLenum type, GLsizei width, ' | |
688 'GLsizei height', }, | |
689 { 'return_type': 'OSMesaContext', | |
690 'names': ['OSMesaGetCurrentContext'], | |
691 'arguments': 'void', }, | |
692 { 'return_type': 'void', | |
693 'names': ['OSMesaPixelStore'], | |
694 'arguments': 'GLint pname, GLint value', }, | |
695 { 'return_type': 'void', | |
696 'names': ['OSMesaGetIntegerv'], | |
697 'arguments': 'GLint pname, GLint* value', }, | |
698 { 'return_type': 'GLboolean', | |
699 'names': ['OSMesaGetDepthBuffer'], | |
700 'arguments': | |
701 'OSMesaContext c, GLint* width, GLint* height, GLint* bytesPerValue, ' | |
702 'void** buffer', }, | |
703 { 'return_type': 'GLboolean', | |
704 'names': ['OSMesaGetColorBuffer'], | |
705 'arguments': 'OSMesaContext c, GLint* width, GLint* height, GLint* format, ' | |
706 'void** buffer', }, | |
707 { 'return_type': 'OSMESAproc', | |
708 'names': ['OSMesaGetProcAddress'], | |
709 'arguments': 'const char* funcName', }, | |
710 { 'return_type': 'void', | |
711 'names': ['OSMesaColorClamp'], | |
712 'arguments': 'GLboolean enable', }, | |
713 ] | |
714 | |
715 EGL_FUNCTIONS = [ | |
716 { 'return_type': 'EGLint', | |
717 'names': ['eglGetError'], | |
718 'arguments': 'void', }, | |
719 { 'return_type': 'EGLDisplay', | |
720 'names': ['eglGetDisplay'], | |
721 'arguments': 'EGLNativeDisplayType display_id', }, | |
722 { 'return_type': 'EGLBoolean', | |
723 'names': ['eglInitialize'], | |
724 'arguments': 'EGLDisplay dpy, EGLint* major, EGLint* minor', }, | |
725 { 'return_type': 'EGLBoolean', | |
726 'names': ['eglTerminate'], | |
727 'arguments': 'EGLDisplay dpy', }, | |
728 { 'return_type': 'const char*', | |
729 'names': ['eglQueryString'], | |
730 'arguments': 'EGLDisplay dpy, EGLint name', }, | |
731 { 'return_type': 'EGLBoolean', | |
732 'names': ['eglGetConfigs'], | |
733 'arguments': 'EGLDisplay dpy, EGLConfig* configs, EGLint config_size, ' | |
734 'EGLint* num_config', }, | |
735 { 'return_type': 'EGLBoolean', | |
736 'names': ['eglChooseConfig'], | |
737 'arguments': 'EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, ' | |
738 'EGLint config_size, EGLint* num_config', }, | |
739 { 'return_type': 'EGLBoolean', | |
740 'names': ['eglGetConfigAttrib'], | |
741 'arguments': | |
742 'EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint* value', }, | |
743 { 'return_type': 'EGLImageKHR', | |
744 'names': ['eglCreateImageKHR'], | |
745 'arguments': | |
746 'EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, ' | |
747 'const EGLint* attrib_list', | |
748 'other_extensions': ['EGL_KHR_image_base'] }, | |
749 { 'return_type': 'EGLBoolean', | |
750 'names': ['eglDestroyImageKHR'], | |
751 'arguments': 'EGLDisplay dpy, EGLImageKHR image', | |
752 'other_extensions': ['EGL_KHR_image_base'] }, | |
753 { 'return_type': 'EGLSurface', | |
754 'names': ['eglCreateWindowSurface'], | |
755 'arguments': 'EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, ' | |
756 'const EGLint* attrib_list', }, | |
757 { 'return_type': 'EGLSurface', | |
758 'names': ['eglCreatePbufferSurface'], | |
759 'arguments': 'EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list', }, | |
760 { 'return_type': 'EGLSurface', | |
761 'names': ['eglCreatePixmapSurface'], | |
762 'arguments': 'EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, ' | |
763 'const EGLint* attrib_list', }, | |
764 { 'return_type': 'EGLBoolean', | |
765 'names': ['eglDestroySurface'], | |
766 'arguments': 'EGLDisplay dpy, EGLSurface surface', }, | |
767 { 'return_type': 'EGLBoolean', | |
768 'names': ['eglQuerySurface'], | |
769 'arguments': | |
770 'EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint* value', }, | |
771 { 'return_type': 'EGLBoolean', | |
772 'names': ['eglBindAPI'], | |
773 'arguments': 'EGLenum api', }, | |
774 { 'return_type': 'EGLenum', | |
775 'names': ['eglQueryAPI'], | |
776 'arguments': 'void', }, | |
777 { 'return_type': 'EGLBoolean', | |
778 'names': ['eglWaitClient'], | |
779 'arguments': 'void', }, | |
780 { 'return_type': 'EGLBoolean', | |
781 'names': ['eglReleaseThread'], | |
782 'arguments': 'void', }, | |
783 { 'return_type': 'EGLSurface', | |
784 'names': ['eglCreatePbufferFromClientBuffer'], | |
785 'arguments': | |
786 'EGLDisplay dpy, EGLenum buftype, void* buffer, EGLConfig config, ' | |
787 'const EGLint* attrib_list', }, | |
788 { 'return_type': 'EGLBoolean', | |
789 'names': ['eglSurfaceAttrib'], | |
790 'arguments': | |
791 'EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value', }, | |
792 { 'return_type': 'EGLBoolean', | |
793 'names': ['eglBindTexImage'], | |
794 'arguments': 'EGLDisplay dpy, EGLSurface surface, EGLint buffer', }, | |
795 { 'return_type': 'EGLBoolean', | |
796 'names': ['eglReleaseTexImage'], | |
797 'arguments': 'EGLDisplay dpy, EGLSurface surface, EGLint buffer', }, | |
798 { 'return_type': 'EGLBoolean', | |
799 'names': ['eglSwapInterval'], | |
800 'arguments': 'EGLDisplay dpy, EGLint interval', }, | |
801 { 'return_type': 'EGLContext', | |
802 'names': ['eglCreateContext'], | |
803 'arguments': 'EGLDisplay dpy, EGLConfig config, EGLContext share_context, ' | |
804 'const EGLint* attrib_list', }, | |
805 { 'return_type': 'EGLBoolean', | |
806 'names': ['eglDestroyContext'], | |
807 'arguments': 'EGLDisplay dpy, EGLContext ctx', }, | |
808 { 'return_type': 'EGLBoolean', | |
809 'names': ['eglMakeCurrent'], | |
810 'arguments': | |
811 'EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx', }, | |
812 { 'return_type': 'EGLContext', | |
813 'names': ['eglGetCurrentContext'], | |
814 'arguments': 'void', }, | |
815 { 'return_type': 'EGLSurface', | |
816 'names': ['eglGetCurrentSurface'], | |
817 'arguments': 'EGLint readdraw', }, | |
818 { 'return_type': 'EGLDisplay', | |
819 'names': ['eglGetCurrentDisplay'], | |
820 'arguments': 'void', }, | |
821 { 'return_type': 'EGLBoolean', | |
822 'names': ['eglQueryContext'], | |
823 'arguments': | |
824 'EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* value', }, | |
825 { 'return_type': 'EGLBoolean', | |
826 'names': ['eglWaitGL'], | |
827 'arguments': 'void', }, | |
828 { 'return_type': 'EGLBoolean', | |
829 'names': ['eglWaitNative'], | |
830 'arguments': 'EGLint engine', }, | |
831 { 'return_type': 'EGLBoolean', | |
832 'names': ['eglSwapBuffers'], | |
833 'arguments': 'EGLDisplay dpy, EGLSurface surface', }, | |
834 { 'return_type': 'EGLBoolean', | |
835 'names': ['eglCopyBuffers'], | |
836 'arguments': | |
837 'EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target', }, | |
838 { 'return_type': '__eglMustCastToProperFunctionPointerType', | |
839 'names': ['eglGetProcAddress'], | |
840 'arguments': 'const char* procname', }, | |
841 { 'return_type': 'EGLBoolean', | |
842 'names': ['eglPostSubBufferNV'], | |
843 'arguments': 'EGLDisplay dpy, EGLSurface surface, ' | |
844 'EGLint x, EGLint y, EGLint width, EGLint height', }, | |
845 { 'return_type': 'EGLBoolean', | |
846 'names': ['eglQuerySurfacePointerANGLE'], | |
847 'arguments': | |
848 'EGLDisplay dpy, EGLSurface surface, EGLint attribute, void** value', }, | |
849 ] | |
850 | |
851 WGL_FUNCTIONS = [ | |
852 { 'return_type': 'HGLRC', | |
853 'names': ['wglCreateContext'], | |
854 'arguments': 'HDC hdc', }, | |
855 { 'return_type': 'HGLRC', | |
856 'names': ['wglCreateLayerContext'], | |
857 'arguments': 'HDC hdc, int iLayerPlane', }, | |
858 { 'return_type': 'BOOL', | |
859 'names': ['wglCopyContext'], | |
860 'arguments': 'HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask', }, | |
861 { 'return_type': 'BOOL', | |
862 'names': ['wglDeleteContext'], | |
863 'arguments': 'HGLRC hglrc', }, | |
864 { 'return_type': 'HGLRC', | |
865 'names': ['wglGetCurrentContext'], | |
866 'arguments': '', }, | |
867 { 'return_type': 'HDC', | |
868 'names': ['wglGetCurrentDC'], | |
869 'arguments': '', }, | |
870 { 'return_type': 'BOOL', | |
871 'names': ['wglMakeCurrent'], | |
872 'arguments': 'HDC hdc, HGLRC hglrc', }, | |
873 { 'return_type': 'BOOL', | |
874 'names': ['wglShareLists'], | |
875 'arguments': 'HGLRC hglrc1, HGLRC hglrc2', }, | |
876 { 'return_type': 'BOOL', | |
877 'names': ['wglSwapIntervalEXT'], | |
878 'arguments': 'int interval', }, | |
879 { 'return_type': 'BOOL', | |
880 'names': ['wglSwapLayerBuffers'], | |
881 'arguments': 'HDC hdc, UINT fuPlanes', }, | |
882 { 'return_type': 'const char*', | |
883 'names': ['wglGetExtensionsStringARB'], | |
884 'arguments': 'HDC hDC', }, | |
885 { 'return_type': 'const char*', | |
886 'names': ['wglGetExtensionsStringEXT'], | |
887 'arguments': '', }, | |
888 { 'return_type': 'BOOL', | |
889 'names': ['wglChoosePixelFormatARB'], | |
890 'arguments': | |
891 'HDC dc, const int* int_attrib_list, const float* float_attrib_list, ' | |
892 'UINT max_formats, int* formats, UINT* num_formats', }, | |
893 { 'return_type': 'HPBUFFERARB', | |
894 'names': ['wglCreatePbufferARB'], | |
895 'arguments': 'HDC hDC, int iPixelFormat, int iWidth, int iHeight, ' | |
896 'const int* piAttribList', }, | |
897 { 'return_type': 'HDC', | |
898 'names': ['wglGetPbufferDCARB'], | |
899 'arguments': 'HPBUFFERARB hPbuffer', }, | |
900 { 'return_type': 'int', | |
901 'names': ['wglReleasePbufferDCARB'], | |
902 'arguments': 'HPBUFFERARB hPbuffer, HDC hDC', }, | |
903 { 'return_type': 'BOOL', | |
904 'names': ['wglDestroyPbufferARB'], | |
905 'arguments': 'HPBUFFERARB hPbuffer', }, | |
906 { 'return_type': 'BOOL', | |
907 'names': ['wglQueryPbufferARB'], | |
908 'arguments': 'HPBUFFERARB hPbuffer, int iAttribute, int* piValue', }, | |
909 ] | |
910 | |
911 GLX_FUNCTIONS = [ | |
912 { 'return_type': 'XVisualInfo*', | |
913 'names': ['glXChooseVisual'], | |
914 'arguments': 'Display* dpy, int screen, int* attribList', }, | |
915 { 'return_type': 'void', | |
916 'names': ['glXCopySubBufferMESA'], | |
917 'arguments': 'Display* dpy, GLXDrawable drawable, ' | |
918 'int x, int y, int width, int height', }, | |
919 { 'return_type': 'GLXContext', | |
920 'names': ['glXCreateContext'], | |
921 'arguments': | |
922 'Display* dpy, XVisualInfo* vis, GLXContext shareList, int direct', }, | |
923 { 'return_type': 'void', | |
924 'names': ['glXBindTexImageEXT'], | |
925 'arguments': | |
926 'Display* dpy, GLXDrawable drawable, int buffer, int* attribList', }, | |
927 { 'return_type': 'void', | |
928 'names': ['glXReleaseTexImageEXT'], | |
929 'arguments': 'Display* dpy, GLXDrawable drawable, int buffer', }, | |
930 { 'return_type': 'void', | |
931 'names': ['glXDestroyContext'], | |
932 'arguments': 'Display* dpy, GLXContext ctx', }, | |
933 { 'return_type': 'int', | |
934 'names': ['glXMakeCurrent'], | |
935 'arguments': 'Display* dpy, GLXDrawable drawable, GLXContext ctx', }, | |
936 { 'return_type': 'void', | |
937 'names': ['glXCopyContext'], | |
938 'arguments': | |
939 'Display* dpy, GLXContext src, GLXContext dst, unsigned long mask', }, | |
940 { 'return_type': 'void', | |
941 'names': ['glXSwapBuffers'], | |
942 'arguments': 'Display* dpy, GLXDrawable drawable', }, | |
943 { 'return_type': 'GLXPixmap', | |
944 'names': ['glXCreateGLXPixmap'], | |
945 'arguments': 'Display* dpy, XVisualInfo* visual, Pixmap pixmap', }, | |
946 { 'return_type': 'void', | |
947 'names': ['glXDestroyGLXPixmap'], | |
948 'arguments': 'Display* dpy, GLXPixmap pixmap', }, | |
949 { 'return_type': 'int', | |
950 'names': ['glXQueryExtension'], | |
951 'arguments': 'Display* dpy, int* errorb, int* event', }, | |
952 { 'return_type': 'int', | |
953 'names': ['glXQueryVersion'], | |
954 'arguments': 'Display* dpy, int* maj, int* min', }, | |
955 { 'return_type': 'int', | |
956 'names': ['glXIsDirect'], | |
957 'arguments': 'Display* dpy, GLXContext ctx', }, | |
958 { 'return_type': 'int', | |
959 'names': ['glXGetConfig'], | |
960 'arguments': 'Display* dpy, XVisualInfo* visual, int attrib, int* value', }, | |
961 { 'return_type': 'GLXContext', | |
962 'names': ['glXGetCurrentContext'], | |
963 'arguments': 'void', }, | |
964 { 'return_type': 'GLXDrawable', | |
965 'names': ['glXGetCurrentDrawable'], | |
966 'arguments': 'void', }, | |
967 { 'return_type': 'void', | |
968 'names': ['glXWaitGL'], | |
969 'arguments': 'void', }, | |
970 { 'return_type': 'void', | |
971 'names': ['glXWaitX'], | |
972 'arguments': 'void', }, | |
973 { 'return_type': 'void', | |
974 'names': ['glXUseXFont'], | |
975 'arguments': 'Font font, int first, int count, int list', }, | |
976 { 'return_type': 'const char*', | |
977 'names': ['glXQueryExtensionsString'], | |
978 'arguments': 'Display* dpy, int screen', }, | |
979 { 'return_type': 'const char*', | |
980 'names': ['glXQueryServerString'], | |
981 'arguments': 'Display* dpy, int screen, int name', }, | |
982 { 'return_type': 'const char*', | |
983 'names': ['glXGetClientString'], | |
984 'arguments': 'Display* dpy, int name', }, | |
985 { 'return_type': 'Display*', | |
986 'names': ['glXGetCurrentDisplay'], | |
987 'arguments': 'void', }, | |
988 { 'return_type': 'GLXFBConfig*', | |
989 'names': ['glXChooseFBConfig'], | |
990 'arguments': | |
991 'Display* dpy, int screen, const int* attribList, int* nitems', }, | |
992 { 'return_type': 'int', | |
993 'names': ['glXGetFBConfigAttrib'], | |
994 'arguments': 'Display* dpy, GLXFBConfig config, int attribute, int* value', }, | |
995 { 'return_type': 'GLXFBConfig*', | |
996 'names': ['glXGetFBConfigs'], | |
997 'arguments': 'Display* dpy, int screen, int* nelements', }, | |
998 { 'return_type': 'XVisualInfo*', | |
999 'names': ['glXGetVisualFromFBConfig'], | |
1000 'arguments': 'Display* dpy, GLXFBConfig config', }, | |
1001 { 'return_type': 'GLXWindow', | |
1002 'names': ['glXCreateWindow'], | |
1003 'arguments': | |
1004 'Display* dpy, GLXFBConfig config, Window win, const int* attribList', }, | |
1005 { 'return_type': 'void', | |
1006 'names': ['glXDestroyWindow'], | |
1007 'arguments': 'Display* dpy, GLXWindow window', }, | |
1008 { 'return_type': 'GLXPixmap', | |
1009 'names': ['glXCreatePixmap'], | |
1010 'arguments': 'Display* dpy, GLXFBConfig config, ' | |
1011 'Pixmap pixmap, const int* attribList', }, | |
1012 { 'return_type': 'void', | |
1013 'names': ['glXDestroyPixmap'], | |
1014 'arguments': 'Display* dpy, GLXPixmap pixmap', }, | |
1015 { 'return_type': 'GLXPbuffer', | |
1016 'names': ['glXCreatePbuffer'], | |
1017 'arguments': 'Display* dpy, GLXFBConfig config, const int* attribList', }, | |
1018 { 'return_type': 'void', | |
1019 'names': ['glXDestroyPbuffer'], | |
1020 'arguments': 'Display* dpy, GLXPbuffer pbuf', }, | |
1021 { 'return_type': 'void', | |
1022 'names': ['glXQueryDrawable'], | |
1023 'arguments': | |
1024 'Display* dpy, GLXDrawable draw, int attribute, unsigned int* value', }, | |
1025 { 'return_type': 'GLXContext', | |
1026 'names': ['glXCreateNewContext'], | |
1027 'arguments': 'Display* dpy, GLXFBConfig config, int renderType, ' | |
1028 'GLXContext shareList, int direct', }, | |
1029 { 'return_type': 'int', | |
1030 'names': ['glXMakeContextCurrent'], | |
1031 'arguments': | |
1032 'Display* dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx', }, | |
1033 { 'return_type': 'GLXDrawable', | |
1034 'names': ['glXGetCurrentReadDrawable'], | |
1035 'arguments': 'void', }, | |
1036 { 'return_type': 'int', | |
1037 'names': ['glXQueryContext'], | |
1038 'arguments': 'Display* dpy, GLXContext ctx, int attribute, int* value', }, | |
1039 { 'return_type': 'void', | |
1040 'names': ['glXSelectEvent'], | |
1041 'arguments': 'Display* dpy, GLXDrawable drawable, unsigned long mask', }, | |
1042 { 'return_type': 'void', | |
1043 'names': ['glXGetSelectedEvent'], | |
1044 'arguments': 'Display* dpy, GLXDrawable drawable, unsigned long* mask', }, | |
1045 { 'return_type': 'void', | |
1046 'names': ['glXSwapIntervalEXT'], | |
1047 'arguments': 'Display* dpy, GLXDrawable drawable, int interval', }, | |
1048 { 'return_type': 'GLXFBConfig', | |
1049 'names': ['glXGetFBConfigFromVisualSGIX'], | |
1050 'arguments': 'Display* dpy, XVisualInfo* visualInfo', }, | |
1051 { 'return_type': 'GLXContext', | |
1052 'names': ['glXCreateContextAttribsARB'], | |
1053 'arguments': | |
1054 'Display* dpy, GLXFBConfig config, GLXContext share_context, int direct, ' | |
1055 'const int* attrib_list', }, | |
1056 ] | |
1057 | |
1058 FUNCTION_SETS = [ | |
1059 [GL_FUNCTIONS, 'gl', ['../../../third_party/mesa/MesaLib/include/GL/glext.h', | |
1060 '../../../third_party/khronos/GLES2/gl2ext.h'], []], | |
1061 [OSMESA_FUNCTIONS, 'osmesa', [], []], | |
1062 [EGL_FUNCTIONS, 'egl', ['../../../third_party/khronos/EGL/eglext.h'], | |
1063 [ | |
1064 'EGL_ANGLE_d3d_share_handle_client_buffer', | |
1065 ], | |
1066 ], | |
1067 [WGL_FUNCTIONS, 'wgl', [ | |
1068 '../../../third_party/mesa/MesaLib/include/GL/wglext.h'], []], | |
1069 [GLX_FUNCTIONS, 'glx', [ | |
1070 '../../../third_party/mesa/MesaLib/include/GL/glxext.h'], []], | |
1071 ] | |
1072 | |
1073 def GenerateHeader(file, functions, set_name, used_extension_functions): | |
1074 """Generates gl_binding_autogen_x.h""" | |
1075 | |
1076 # Write file header. | |
1077 file.write('// Copyright (c) 2011 The Chromium Authors. All rights reserved.\n
') | |
1078 file.write('// Use of this source code is governed by a BSD-style license that
can be\n') | |
1079 file.write('// found in the LICENSE file.\n') | |
1080 file.write('\n') | |
1081 file.write('// This file is automatically generated.\n') | |
1082 file.write('\n') | |
1083 file.write('#ifndef UI_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % set_name.upper()) | |
1084 file.write('#define UI_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % set_name.upper()) | |
1085 | |
1086 # Write prototype for initialization function. | |
1087 file.write('\n') | |
1088 file.write('namespace gfx {\n') | |
1089 file.write('\n') | |
1090 file.write('class GLContext;\n') | |
1091 file.write('\n') | |
1092 file.write('void InitializeGLBindings%s();\n' % set_name.upper()) | |
1093 file.write('void InitializeGLExtensionBindings%s(GLContext* context);\n' % | |
1094 set_name.upper()) | |
1095 file.write('void InitializeDebugGLBindings%s();\n' % set_name.upper()) | |
1096 file.write('void ClearGLBindings%s();\n' % set_name.upper()) | |
1097 | |
1098 # Write typedefs for function pointer types. Always use the GL name for the | |
1099 # typedef. | |
1100 file.write('\n') | |
1101 for func in functions: | |
1102 file.write('typedef %s (GL_BINDING_CALL *%sProc)(%s);\n' % | |
1103 (func['return_type'], func['names'][0], func['arguments'])) | |
1104 | |
1105 # Write declarations for booleans indicating which extensions are available. | |
1106 file.write('\n') | |
1107 for extension, ext_functions in used_extension_functions: | |
1108 file.write('GL_EXPORT extern bool g_%s;\n' % extension) | |
1109 | |
1110 # Write declarations for function pointers. Always use the GL name for the | |
1111 # declaration. | |
1112 file.write('\n') | |
1113 for func in functions: | |
1114 file.write('GL_EXPORT extern %sProc g_%s;\n' % | |
1115 (func['names'][0], func['names'][0])) | |
1116 file.write('\n') | |
1117 file.write( '} // namespace gfx\n') | |
1118 | |
1119 # Write macros to invoke function pointers. Always use the GL name for the | |
1120 # macro. | |
1121 file.write('\n') | |
1122 for func in functions: | |
1123 file.write('#define %s ::gfx::g_%s\n' % | |
1124 (func['names'][0], func['names'][0])) | |
1125 | |
1126 file.write('\n') | |
1127 file.write('#endif // UI_GFX_GL_GL_BINDINGS_AUTOGEN_%s_H_\n' % | |
1128 set_name.upper()) | |
1129 | |
1130 | |
1131 def GenerateSource(file, functions, set_name, used_extension_functions): | |
1132 """Generates gl_binding_autogen_x.cc""" | |
1133 | |
1134 # Write file header. | |
1135 file.write('// Copyright (c) 2011 The Chromium Authors. All rights reserved.\n
') | |
1136 file.write('// Use of this source code is governed by a BSD-style license that
can be\n') | |
1137 file.write('// found in the LICENSE file.\n') | |
1138 file.write('\n') | |
1139 file.write('// This file is automatically generated.\n') | |
1140 file.write('\n') | |
1141 file.write('#include <string>\n') | |
1142 file.write('#include "gpu/command_buffer/common/gles2_cmd_utils.h"\n') | |
1143 file.write('#include "ui/gfx/gl/gl_bindings.h"\n') | |
1144 file.write('#include "ui/gfx/gl/gl_context.h"\n') | |
1145 file.write('#include "ui/gfx/gl/gl_implementation.h"\n') | |
1146 | |
1147 # Write definitions for booleans indicating which extensions are available. | |
1148 file.write('\n') | |
1149 file.write('using gpu::gles2::GLES2Util;\n') | |
1150 file.write('\n') | |
1151 file.write('namespace gfx {\n') | |
1152 file.write('\n') | |
1153 for extension, ext_functions in used_extension_functions: | |
1154 file.write('bool g_%s;\n' % extension) | |
1155 | |
1156 # Write definitions of function pointers. | |
1157 file.write('\n') | |
1158 file.write('static bool g_debugBindingsInitialized;\n') | |
1159 file.write('static void UpdateDebugGLExtensionBindings();\n') | |
1160 file.write('\n') | |
1161 for func in functions: | |
1162 file.write('%sProc g_%s;\n' % (func['names'][0], func['names'][0])) | |
1163 | |
1164 file.write('\n') | |
1165 for func in functions: | |
1166 file.write('static %sProc g_debug_%s;\n' % | |
1167 (func['names'][0], func['names'][0])) | |
1168 | |
1169 # Write function to initialize the core function pointers. The code assumes | |
1170 # any non-NULL pointer returned by GetGLCoreProcAddress() is valid, although | |
1171 # it may be overwritten by an extension function pointer later. | |
1172 file.write('\n') | |
1173 file.write('void InitializeGLBindings%s() {\n' % set_name.upper()) | |
1174 for func in functions: | |
1175 first_name = func['names'][0] | |
1176 for i, name in enumerate(func['names']): | |
1177 if i: | |
1178 file.write(' if (!g_%s)\n ' % first_name) | |
1179 file.write( | |
1180 ' g_%s = reinterpret_cast<%sProc>(GetGLCoreProcAddress("%s"));\n' % | |
1181 (first_name, first_name, name)) | |
1182 file.write('}\n') | |
1183 file.write('\n') | |
1184 | |
1185 # Write function to initialize the extension function pointers. This function | |
1186 # uses a current context to query which extensions are actually supported. | |
1187 file.write('void InitializeGLExtensionBindings%s(GLContext* context) {\n' % | |
1188 set_name.upper()) | |
1189 file.write(' DCHECK(context && context->IsCurrent(NULL));\n') | |
1190 for extension, ext_functions in used_extension_functions: | |
1191 file.write(' g_%s = context->HasExtension("%s");\n' % | |
1192 (extension, extension)) | |
1193 file.write(' if (g_%s) {\n' % | |
1194 (extension)) | |
1195 queried_entry_points = set() | |
1196 for entry_point_name, function_name in ext_functions: | |
1197 # Replace the pointer unconditionally unless this extension has several | |
1198 # alternatives for the same entry point (e.g., | |
1199 # GL_ARB_blend_func_extended). | |
1200 if entry_point_name in queried_entry_points: | |
1201 file.write(' if (!g_%s)\n ' % entry_point_name) | |
1202 file.write( | |
1203 ' g_%s = reinterpret_cast<%sProc>(GetGLProcAddress("%s"));\n' % | |
1204 (entry_point_name, entry_point_name, function_name)) | |
1205 queried_entry_points.add(entry_point_name) | |
1206 file.write(' }\n') | |
1207 file.write(' if (g_debugBindingsInitialized)\n') | |
1208 file.write(' UpdateDebugGLExtensionBindings();\n') | |
1209 file.write('}\n') | |
1210 file.write('\n') | |
1211 | |
1212 # Write logging wrappers for each function. | |
1213 file.write('extern "C" {\n') | |
1214 for func in functions: | |
1215 names = func['names'] | |
1216 return_type = func['return_type'] | |
1217 arguments = func['arguments'] | |
1218 file.write('\n') | |
1219 file.write('static %s GL_BINDING_CALL Debug_%s(%s) {\n' % | |
1220 (return_type, names[0], arguments)) | |
1221 argument_names = re.sub( | |
1222 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', arguments) | |
1223 argument_names = re.sub( | |
1224 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', argument_names) | |
1225 log_argument_names = re.sub( | |
1226 r'const char\* ([a-zA-Z0-9_]+)', r'CONSTCHAR_\1', arguments) | |
1227 log_argument_names = re.sub( | |
1228 r'(const )?[a-zA-Z0-9_]+\* ([a-zA-Z0-9_]+)', | |
1229 r'CONSTVOID_\2', log_argument_names) | |
1230 log_argument_names = re.sub( | |
1231 r'(?<!E)GLenum ([a-zA-Z0-9_]+)', r'GLenum_\1', log_argument_names) | |
1232 log_argument_names = re.sub( | |
1233 r'(?<!E)GLboolean ([a-zA-Z0-9_]+)', r'GLboolean_\1', log_argument_names) | |
1234 log_argument_names = re.sub( | |
1235 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', | |
1236 log_argument_names) | |
1237 log_argument_names = re.sub( | |
1238 r'(const )?[a-zA-Z0-9_]+\** ([a-zA-Z0-9_]+)', r'\2', | |
1239 log_argument_names) | |
1240 log_argument_names = re.sub( | |
1241 r'CONSTVOID_([a-zA-Z0-9_]+)', | |
1242 r'static_cast<const void*>(\1)', log_argument_names); | |
1243 log_argument_names = re.sub( | |
1244 r'CONSTCHAR_([a-zA-Z0-9_]+)', r'\1', log_argument_names); | |
1245 log_argument_names = re.sub( | |
1246 r'GLenum_([a-zA-Z0-9_]+)', r'GLES2Util::GetStringEnum(\1)', | |
1247 log_argument_names) | |
1248 log_argument_names = re.sub( | |
1249 r'GLboolean_([a-zA-Z0-9_]+)', r'GLES2Util::GetStringBool(\1)', | |
1250 log_argument_names) | |
1251 log_argument_names = log_argument_names.replace(',', ' << ", " <<') | |
1252 if argument_names == 'void' or argument_names == '': | |
1253 argument_names = '' | |
1254 log_argument_names = '' | |
1255 else: | |
1256 log_argument_names = " << " + log_argument_names | |
1257 function_name = names[0] | |
1258 if return_type == 'void': | |
1259 file.write(' GL_SERVICE_LOG("%s" << "(" %s << ")");\n' % | |
1260 (function_name, log_argument_names)) | |
1261 file.write(' g_debug_%s(%s);\n' % | |
1262 (function_name, argument_names)) | |
1263 if 'logging_code' in func: | |
1264 file.write("%s\n" % func['logging_code']) | |
1265 else: | |
1266 file.write(' GL_SERVICE_LOG("%s" << "(" %s << ")");\n' % | |
1267 (function_name, log_argument_names)) | |
1268 file.write(' %s result = g_debug_%s(%s);\n' % | |
1269 (return_type, function_name, argument_names)) | |
1270 if 'logging_code' in func: | |
1271 file.write("%s\n" % func['logging_code']) | |
1272 else: | |
1273 file.write(' GL_SERVICE_LOG("GL_RESULT: " << result);\n'); | |
1274 file.write(' return result;\n') | |
1275 file.write('}\n') | |
1276 file.write('} // extern "C"\n') | |
1277 | |
1278 # Write function to initialize the debug function pointers. | |
1279 file.write('\n') | |
1280 file.write('void InitializeDebugGLBindings%s() {\n' % set_name.upper()) | |
1281 for func in functions: | |
1282 first_name = func['names'][0] | |
1283 file.write(' if (!g_debug_%s) {\n' % first_name) | |
1284 file.write(' g_debug_%s = g_%s;\n' % (first_name, first_name)) | |
1285 file.write(' g_%s = Debug_%s;\n' % (first_name, first_name)) | |
1286 file.write(' }\n') | |
1287 file.write(' g_debugBindingsInitialized = true;\n') | |
1288 file.write('}\n') | |
1289 | |
1290 # Write function to update the debug function pointers to extension functions | |
1291 # after the extensions have been initialized. | |
1292 file.write('\n') | |
1293 file.write('static void UpdateDebugGLExtensionBindings() {\n') | |
1294 for extension, ext_functions in used_extension_functions: | |
1295 for name, _ in ext_functions: | |
1296 file.write(' if (g_debug_%s != g_%s &&\n' % (name, name)) | |
1297 file.write(' g_%s != Debug_%s) {\n' % (name, name)) | |
1298 file.write(' g_debug_%s = g_%s;\n' % (name, name)) | |
1299 file.write(' g_%s = Debug_%s;\n' % (name, name)) | |
1300 file.write(' }\n') | |
1301 file.write('}\n') | |
1302 | |
1303 # Write function to clear all function pointers. | |
1304 file.write('\n') | |
1305 file.write('void ClearGLBindings%s() {\n' % set_name.upper()) | |
1306 # Clear the availability of GL extensions. | |
1307 for extension, ext_functions in used_extension_functions: | |
1308 file.write(' g_%s = false;\n' % extension) | |
1309 # Clear GL bindings. | |
1310 file.write('\n') | |
1311 for func in functions: | |
1312 file.write(' g_%s = NULL;\n' % func['names'][0]) | |
1313 # Clear debug GL bindings. | |
1314 file.write('\n') | |
1315 for func in functions: | |
1316 file.write(' g_debug_%s = NULL;\n' % func['names'][0]) | |
1317 file.write(' g_debugBindingsInitialized = false;\n') | |
1318 file.write('}\n') | |
1319 | |
1320 file.write('\n') | |
1321 file.write('} // namespace gfx\n') | |
1322 | |
1323 | |
1324 def GenerateMockSource(file, functions): | |
1325 """Generates functions that invoke a mock GLInterface""" | |
1326 | |
1327 file.write('// Copyright (c) 2011 The Chromium Authors. All rights reserved.\n
') | |
1328 file.write('// Use of this source code is governed by a BSD-style license that
can be\n') | |
1329 file.write('// found in the LICENSE file.\n') | |
1330 file.write('\n') | |
1331 file.write('// This file is automatically generated.\n') | |
1332 file.write('\n') | |
1333 file.write('#include <string.h>\n') | |
1334 file.write('\n') | |
1335 file.write('#include "ui/gfx/gl/gl_interface.h"\n') | |
1336 | |
1337 file.write('\n') | |
1338 file.write('namespace gfx {\n') | |
1339 | |
1340 # Write function that trampoline into the GLInterface. | |
1341 for func in functions: | |
1342 file.write('\n') | |
1343 file.write('%s GL_BINDING_CALL Mock_%s(%s) {\n' % | |
1344 (func['return_type'], func['names'][0], func['arguments'])) | |
1345 argument_names = re.sub(r'(const )?[a-zA-Z0-9]+\** ([a-zA-Z0-9]+)', r'\2', | |
1346 func['arguments']) | |
1347 if argument_names == 'void': | |
1348 argument_names = '' | |
1349 function_name = func['names'][0][2:] | |
1350 if func['return_type'] == 'void': | |
1351 file.write(' GLInterface::GetGLInterface()->%s(%s);\n' % | |
1352 (function_name, argument_names)) | |
1353 else: | |
1354 file.write(' return GLInterface::GetGLInterface()->%s(%s);\n' % | |
1355 (function_name, argument_names)) | |
1356 file.write('}\n') | |
1357 | |
1358 # Write an 'invalid' function to catch code calling through uninitialized | |
1359 # function pointers or trying to interpret the return value of | |
1360 # GLProcAddress(). | |
1361 file.write('\n') | |
1362 file.write('static void MockInvalidFunction() {\n') | |
1363 file.write(' NOTREACHED();\n') | |
1364 file.write('}\n') | |
1365 | |
1366 # Write a function to lookup a mock GL function based on its name. | |
1367 file.write('\n') | |
1368 file.write('void* GL_BINDING_CALL GetMockGLProcAddress(const char* name) {\n') | |
1369 for func in functions: | |
1370 first_name = func['names'][0] | |
1371 file.write(' if (strcmp(name, "%s") == 0)\n' % first_name) | |
1372 file.write(' return reinterpret_cast<void*>(Mock_%s);\n' % first_name) | |
1373 # Always return a non-NULL pointer like some EGL implementations do. | |
1374 file.write(' return reinterpret_cast<void*>(&MockInvalidFunction);\n') | |
1375 file.write('}\n'); | |
1376 | |
1377 file.write('\n') | |
1378 file.write('} // namespace gfx\n') | |
1379 | |
1380 | |
1381 def ParseExtensionFunctionsFromHeader(header_file): | |
1382 """Parse a C extension header file and return a map from extension names to | |
1383 a list of functions. | |
1384 | |
1385 Args: | |
1386 header_file: Line-iterable C header file. | |
1387 Returns: | |
1388 Map of extension name => functions. | |
1389 """ | |
1390 extension_start = re.compile(r'#define ([A-Z]+_[A-Z]+_[a-zA-Z]\w+) 1') | |
1391 extension_function = re.compile(r'.+\s+([a-z]+\w+)\s*\(.+\);') | |
1392 typedef = re.compile(r'typedef .*') | |
1393 macro_start = re.compile(r'^#(if|ifdef|ifndef).*') | |
1394 macro_end = re.compile(r'^#endif.*') | |
1395 macro_depth = 0 | |
1396 current_extension = None | |
1397 current_extension_depth = 0 | |
1398 extensions = collections.defaultdict(lambda: []) | |
1399 for line in header_file: | |
1400 if macro_start.match(line): | |
1401 macro_depth += 1 | |
1402 elif macro_end.match(line): | |
1403 macro_depth -= 1 | |
1404 if macro_depth < current_extension_depth: | |
1405 current_extension = None | |
1406 match = extension_start.match(line) | |
1407 if match: | |
1408 current_extension = match.group(1) | |
1409 current_extension_depth = macro_depth | |
1410 assert current_extension not in extensions, \ | |
1411 "Duplicate extension: " + current_extension | |
1412 match = extension_function.match(line) | |
1413 if match and current_extension and not typedef.match(line): | |
1414 extensions[current_extension].append(match.group(1)) | |
1415 return extensions | |
1416 | |
1417 | |
1418 def GetExtensionFunctions(extension_headers): | |
1419 """Parse extension functions from a list of header files. | |
1420 | |
1421 Args: | |
1422 extension_headers: List of header file names. | |
1423 Returns: | |
1424 Map of extension name => list of functions. | |
1425 """ | |
1426 extensions = {} | |
1427 for header in extension_headers: | |
1428 extensions.update(ParseExtensionFunctionsFromHeader(open(header))) | |
1429 return extensions | |
1430 | |
1431 | |
1432 def GetFunctionToExtensionMap(extensions): | |
1433 """Construct map from a function names to extensions which define the | |
1434 function. | |
1435 | |
1436 Args: | |
1437 extensions: Map of extension name => functions. | |
1438 Returns: | |
1439 Map of function name => extension name. | |
1440 """ | |
1441 function_to_extensions = {} | |
1442 for extension, functions in extensions.items(): | |
1443 for function in functions: | |
1444 if not function in function_to_extensions: | |
1445 function_to_extensions[function] = [] | |
1446 function_to_extensions[function].append(extension) | |
1447 return function_to_extensions | |
1448 | |
1449 | |
1450 def LooksLikeExtensionFunction(function): | |
1451 """Heuristic to see if a function name is consistent with extension function | |
1452 naming.""" | |
1453 vendor = re.match(r'\w+?([A-Z][A-Z]+)$', function) | |
1454 return vendor is not None and not vendor.group(1) in ['GL', 'API', 'DC'] | |
1455 | |
1456 | |
1457 def GetUsedExtensionFunctions(functions, extension_headers, extra_extensions): | |
1458 """Determine which functions belong to extensions. | |
1459 | |
1460 Args: | |
1461 functions: List of (return type, function names, arguments). | |
1462 extension_headers: List of header file names. | |
1463 Returns: | |
1464 List of (extension name, [function name alternatives]) sorted with least | |
1465 preferred extensions first. | |
1466 """ | |
1467 # Parse known extensions. | |
1468 extensions = GetExtensionFunctions(extension_headers) | |
1469 functions_to_extensions = GetFunctionToExtensionMap(extensions) | |
1470 | |
1471 # Collect all used extension functions. | |
1472 used_extension_functions = collections.defaultdict(lambda: []) | |
1473 for func in functions: | |
1474 for name in func['names']: | |
1475 # Make sure we know about all extension functions. | |
1476 if (LooksLikeExtensionFunction(name) and | |
1477 not name in functions_to_extensions): | |
1478 raise RuntimeError('%s looks like an extension function but does not ' | |
1479 'belong to any of the known extensions.' % name) | |
1480 if name in functions_to_extensions: | |
1481 extensions = functions_to_extensions[name][:] | |
1482 if 'other_extensions' in func: | |
1483 extensions.extend(func['other_extensions']) | |
1484 for extension in extensions: | |
1485 used_extension_functions[extension].append((func['names'][0], name)) | |
1486 | |
1487 # Add extensions that do not have any functions. | |
1488 used_extension_functions.update(dict( | |
1489 [(e, []) for e in extra_extensions if e not in used_extension_functions])) | |
1490 | |
1491 def ExtensionSortKey(name): | |
1492 # Prefer ratified extensions and EXTs. | |
1493 preferences = ['_ARB_', '_OES_', '_EXT_', ''] | |
1494 for i, category in enumerate(preferences): | |
1495 if category in name: | |
1496 return -i | |
1497 used_extension_functions = sorted(used_extension_functions.items(), | |
1498 key = lambda item: ExtensionSortKey(item[0])) | |
1499 return used_extension_functions | |
1500 | |
1501 | |
1502 def main(argv): | |
1503 """This is the main function.""" | |
1504 | |
1505 if len(argv) >= 1: | |
1506 dir = argv[0] | |
1507 else: | |
1508 dir = '.' | |
1509 | |
1510 for [functions, set_name, extension_headers, extensions] in FUNCTION_SETS: | |
1511 used_extension_functions = GetUsedExtensionFunctions( | |
1512 functions, extension_headers, extensions) | |
1513 | |
1514 header_file = open( | |
1515 os.path.join(dir, 'gl_bindings_autogen_%s.h' % set_name), 'wb') | |
1516 GenerateHeader(header_file, functions, set_name, used_extension_functions) | |
1517 header_file.close() | |
1518 | |
1519 source_file = open( | |
1520 os.path.join(dir, 'gl_bindings_autogen_%s.cc' % set_name), 'wb') | |
1521 GenerateSource(source_file, functions, set_name, used_extension_functions) | |
1522 source_file.close() | |
1523 | |
1524 source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb') | |
1525 GenerateMockSource(source_file, GL_FUNCTIONS) | |
1526 source_file.close() | |
1527 return 0 | |
1528 | |
1529 | |
1530 if __name__ == '__main__': | |
1531 sys.exit(main(sys.argv[1:])) | |
OLD | NEW |