blob: 1842ee575b7fcbe190306564412475d9c095d527 [file] [log] [blame]
José Fonsecac6b49ce2010-11-28 16:43:04 +00001##########################################################################
2#
3# Copyright 2010 VMware, Inc.
4# All Rights Reserved.
5#
6# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to deal
8# in the Software without restriction, including without limitation the rights
9# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10# copies of the Software, and to permit persons to whom the Software is
11# furnished to do so, subject to the following conditions:
12#
13# The above copyright notice and this permission notice shall be included in
14# all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22# THE SOFTWARE.
23#
24##########################################################################/
25
26
José Fonseca4a826ed2010-11-30 16:58:22 +000027"""Generated an header, glproc.hpp, which does pretty much what GLEW does, but
28covers all the functions we support.
29"""
30
31
José Fonsecae91f5bc2014-07-17 20:42:35 +010032import sys
33
José Fonseca669b2002011-02-20 13:32:19 +000034from dispatch import Dispatcher
José Fonseca4f242f42012-04-14 18:13:25 +010035import specs.stdapi as stdapi
José Fonsecabd86a222011-09-27 09:21:38 +010036from specs.glapi import glapi
37from specs.glxapi import glxapi
38from specs.wglapi import wglapi
39from specs.cglapi import cglapi
Chia-I Wue50c14b2011-11-03 12:24:53 +080040from specs.eglapi import eglapi
Chia-I Wue889ac72011-11-03 12:45:00 +080041from specs.glesapi import glesapi
José Fonsecac6b49ce2010-11-28 16:43:04 +000042
43
José Fonseca68ec4122011-02-20 11:25:25 +000044# See http://www.opengl.org/registry/ABI/
José Fonsecac6b49ce2010-11-28 16:43:04 +000045public_symbols = set([
José Fonsecab87c2292011-10-09 14:56:16 +010046 # GL 1.2 and ARB_multitexture
47 "glAccum",
48 "glAlphaFunc",
49 "glAreTexturesResident",
50 "glArrayElement",
51 "glBegin",
52 "glBindTexture",
53 "glBitmap",
54 "glBlendFunc",
55 "glCallList",
56 "glCallLists",
57 "glClear",
58 "glClearAccum",
59 "glClearColor",
60 "glClearDepth",
61 "glClearIndex",
62 "glClearStencil",
63 "glClipPlane",
64 "glColor3b",
65 "glColor3bv",
66 "glColor3d",
67 "glColor3dv",
68 "glColor3f",
69 "glColor3fv",
70 "glColor3i",
71 "glColor3iv",
72 "glColor3s",
73 "glColor3sv",
74 "glColor3ub",
75 "glColor3ubv",
76 "glColor3ui",
77 "glColor3uiv",
78 "glColor3us",
79 "glColor3usv",
80 "glColor4b",
81 "glColor4bv",
82 "glColor4d",
83 "glColor4dv",
84 "glColor4f",
85 "glColor4fv",
86 "glColor4i",
87 "glColor4iv",
88 "glColor4s",
89 "glColor4sv",
90 "glColor4ub",
91 "glColor4ubv",
92 "glColor4ui",
93 "glColor4uiv",
94 "glColor4us",
95 "glColor4usv",
96 "glColorMask",
97 "glColorMaterial",
98 "glColorPointer",
99 "glCopyPixels",
100 "glCopyTexImage1D",
101 "glCopyTexImage2D",
102 "glCopyTexSubImage1D",
103 "glCopyTexSubImage2D",
104 "glCullFace",
105 "glDeleteLists",
106 "glDeleteTextures",
107 "glDepthFunc",
108 "glDepthMask",
109 "glDepthRange",
110 "glDisable",
111 "glDisableClientState",
112 "glDrawArrays",
113 "glDrawBuffer",
114 "glDrawElements",
115 "glDrawPixels",
116 "glEdgeFlag",
117 "glEdgeFlagPointer",
118 "glEdgeFlagv",
119 "glEnable",
120 "glEnableClientState",
121 "glEnd",
122 "glEndList",
123 "glEvalCoord1d",
124 "glEvalCoord1dv",
125 "glEvalCoord1f",
126 "glEvalCoord1fv",
127 "glEvalCoord2d",
128 "glEvalCoord2dv",
129 "glEvalCoord2f",
130 "glEvalCoord2fv",
131 "glEvalMesh1",
132 "glEvalMesh2",
133 "glEvalPoint1",
134 "glEvalPoint2",
135 "glFeedbackBuffer",
136 "glFinish",
137 "glFlush",
138 "glFogf",
139 "glFogfv",
140 "glFogi",
141 "glFogiv",
142 "glFrontFace",
143 "glFrustum",
144 "glGenLists",
145 "glGenTextures",
146 "glGetBooleanv",
147 "glGetClipPlane",
148 "glGetDoublev",
149 "glGetError",
150 "glGetFloatv",
151 "glGetIntegerv",
152 "glGetLightfv",
153 "glGetLightiv",
154 "glGetMapdv",
155 "glGetMapfv",
156 "glGetMapiv",
157 "glGetMaterialfv",
158 "glGetMaterialiv",
159 "glGetPixelMapfv",
160 "glGetPixelMapuiv",
161 "glGetPixelMapusv",
162 "glGetPointerv",
163 "glGetPolygonStipple",
164 "glGetString",
165 "glGetTexEnvfv",
166 "glGetTexEnviv",
167 "glGetTexGendv",
168 "glGetTexGenfv",
169 "glGetTexGeniv",
170 "glGetTexImage",
171 "glGetTexLevelParameterfv",
172 "glGetTexLevelParameteriv",
173 "glGetTexParameterfv",
174 "glGetTexParameteriv",
175 "glHint",
176 "glIndexMask",
177 "glIndexPointer",
178 "glIndexd",
179 "glIndexdv",
180 "glIndexf",
181 "glIndexfv",
182 "glIndexi",
183 "glIndexiv",
184 "glIndexs",
185 "glIndexsv",
186 "glIndexub",
187 "glIndexubv",
188 "glInitNames",
189 "glInterleavedArrays",
190 "glIsEnabled",
191 "glIsList",
192 "glIsTexture",
193 "glLightModelf",
194 "glLightModelfv",
195 "glLightModeli",
196 "glLightModeliv",
197 "glLightf",
198 "glLightfv",
199 "glLighti",
200 "glLightiv",
201 "glLineStipple",
202 "glLineWidth",
203 "glListBase",
204 "glLoadIdentity",
205 "glLoadMatrixd",
206 "glLoadMatrixf",
207 "glLoadName",
208 "glLogicOp",
209 "glMap1d",
210 "glMap1f",
211 "glMap2d",
212 "glMap2f",
213 "glMapGrid1d",
214 "glMapGrid1f",
215 "glMapGrid2d",
216 "glMapGrid2f",
217 "glMaterialf",
218 "glMaterialfv",
219 "glMateriali",
220 "glMaterialiv",
221 "glMatrixMode",
222 "glMultMatrixd",
223 "glMultMatrixf",
224 "glNewList",
225 "glNormal3b",
226 "glNormal3bv",
227 "glNormal3d",
228 "glNormal3dv",
229 "glNormal3f",
230 "glNormal3fv",
231 "glNormal3i",
232 "glNormal3iv",
233 "glNormal3s",
234 "glNormal3sv",
235 "glNormalPointer",
236 "glOrtho",
237 "glPassThrough",
238 "glPixelMapfv",
239 "glPixelMapuiv",
240 "glPixelMapusv",
241 "glPixelStoref",
242 "glPixelStorei",
243 "glPixelTransferf",
244 "glPixelTransferi",
245 "glPixelZoom",
246 "glPointSize",
247 "glPolygonMode",
248 "glPolygonOffset",
249 "glPolygonStipple",
250 "glPopAttrib",
251 "glPopClientAttrib",
252 "glPopMatrix",
253 "glPopName",
254 "glPrioritizeTextures",
255 "glPushAttrib",
256 "glPushClientAttrib",
257 "glPushMatrix",
258 "glPushName",
259 "glRasterPos2d",
260 "glRasterPos2dv",
261 "glRasterPos2f",
262 "glRasterPos2fv",
263 "glRasterPos2i",
264 "glRasterPos2iv",
265 "glRasterPos2s",
266 "glRasterPos2sv",
267 "glRasterPos3d",
268 "glRasterPos3dv",
269 "glRasterPos3f",
270 "glRasterPos3fv",
271 "glRasterPos3i",
272 "glRasterPos3iv",
273 "glRasterPos3s",
274 "glRasterPos3sv",
275 "glRasterPos4d",
276 "glRasterPos4dv",
277 "glRasterPos4f",
278 "glRasterPos4fv",
279 "glRasterPos4i",
280 "glRasterPos4iv",
281 "glRasterPos4s",
282 "glRasterPos4sv",
283 "glReadBuffer",
284 "glReadPixels",
285 "glRectd",
286 "glRectdv",
287 "glRectf",
288 "glRectfv",
289 "glRecti",
290 "glRectiv",
291 "glRects",
292 "glRectsv",
293 "glRenderMode",
294 "glRotated",
295 "glRotatef",
296 "glScaled",
297 "glScalef",
298 "glScissor",
299 "glSelectBuffer",
300 "glShadeModel",
301 "glStencilFunc",
302 "glStencilMask",
303 "glStencilOp",
304 "glTexCoord1d",
305 "glTexCoord1dv",
306 "glTexCoord1f",
307 "glTexCoord1fv",
308 "glTexCoord1i",
309 "glTexCoord1iv",
310 "glTexCoord1s",
311 "glTexCoord1sv",
312 "glTexCoord2d",
313 "glTexCoord2dv",
314 "glTexCoord2f",
315 "glTexCoord2fv",
316 "glTexCoord2i",
317 "glTexCoord2iv",
318 "glTexCoord2s",
319 "glTexCoord2sv",
320 "glTexCoord3d",
321 "glTexCoord3dv",
322 "glTexCoord3f",
323 "glTexCoord3fv",
324 "glTexCoord3i",
325 "glTexCoord3iv",
326 "glTexCoord3s",
327 "glTexCoord3sv",
328 "glTexCoord4d",
329 "glTexCoord4dv",
330 "glTexCoord4f",
331 "glTexCoord4fv",
332 "glTexCoord4i",
333 "glTexCoord4iv",
334 "glTexCoord4s",
335 "glTexCoord4sv",
336 "glTexCoordPointer",
337 "glTexEnvf",
338 "glTexEnvfv",
339 "glTexEnvi",
340 "glTexEnviv",
341 "glTexGend",
342 "glTexGendv",
343 "glTexGenf",
344 "glTexGenfv",
345 "glTexGeni",
346 "glTexGeniv",
347 "glTexImage1D",
348 "glTexImage2D",
349 "glTexParameterf",
350 "glTexParameterfv",
351 "glTexParameteri",
352 "glTexParameteriv",
353 "glTexSubImage1D",
354 "glTexSubImage2D",
355 "glTranslated",
356 "glTranslatef",
357 "glVertex2d",
358 "glVertex2dv",
359 "glVertex2f",
360 "glVertex2fv",
361 "glVertex2i",
362 "glVertex2iv",
363 "glVertex2s",
364 "glVertex2sv",
365 "glVertex3d",
366 "glVertex3dv",
367 "glVertex3f",
368 "glVertex3fv",
369 "glVertex3i",
370 "glVertex3iv",
371 "glVertex3s",
372 "glVertex3sv",
373 "glVertex4d",
374 "glVertex4dv",
375 "glVertex4f",
376 "glVertex4fv",
377 "glVertex4i",
378 "glVertex4iv",
379 "glVertex4s",
380 "glVertex4sv",
381 "glVertexPointer",
382 "glViewport",
José Fonseca68ec4122011-02-20 11:25:25 +0000383
José Fonsecab87c2292011-10-09 14:56:16 +0100384 # GLX 1.3 and GLX_ARB_get_proc_address
385 "glXChooseVisual",
386 "glXCreateContext",
387 "glXDestroyContext",
388 "glXMakeCurrent",
389 "glXCopyContext",
390 "glXSwapBuffers",
391 "glXCreateGLXPixmap",
392 "glXDestroyGLXPixmap",
393 "glXQueryExtension",
394 "glXQueryVersion",
395 "glXIsDirect",
396 "glXGetConfig",
397 "glXGetCurrentContext",
398 "glXGetCurrentDrawable",
399 "glXWaitGL",
400 "glXWaitX",
401 "glXUseXFont",
402 "glXQueryExtensionsString",
403 "glXQueryServerString",
404 "glXGetClientString",
405 "glXGetCurrentDisplay",
406 "glXChooseFBConfig",
407 "glXGetFBConfigAttrib",
408 "glXGetFBConfigs",
409 "glXGetVisualFromFBConfig",
410 "glXCreateWindow",
411 "glXDestroyWindow",
412 "glXCreatePixmap",
413 "glXDestroyPixmap",
414 "glXCreatePbuffer",
415 "glXDestroyPbuffer",
416 "glXQueryDrawable",
417 "glXCreateNewContext",
418 "glXMakeContextCurrent",
419 "glXGetCurrentReadDrawable",
420 "glXQueryContext",
421 "glXSelectEvent",
422 "glXGetSelectedEvent",
José Fonseca68ec4122011-02-20 11:25:25 +0000423 "glXGetProcAddressARB",
424 "glXGetProcAddress",
José Fonsecab87c2292011-10-09 14:56:16 +0100425
426 # WGL
427 #"glDebugEntry",
428 "wglChoosePixelFormat",
429 "wglCopyContext",
430 "wglCreateContext",
431 "wglCreateLayerContext",
432 "wglDeleteContext",
433 "wglDescribeLayerPlane",
434 "wglDescribePixelFormat",
435 "wglGetCurrentContext",
436 "wglGetCurrentDC",
437 "wglGetDefaultProcAddress",
438 "wglGetLayerPaletteEntries",
439 "wglGetPixelFormat",
440 "wglGetProcAddress",
441 "wglMakeCurrent",
442 "wglRealizeLayerPalette",
443 "wglSetLayerPaletteEntries",
444 "wglSetPixelFormat",
445 "wglShareLists",
446 "wglSwapBuffers",
447 "wglSwapLayerBuffers",
448 "wglSwapMultipleBuffers",
449 "wglUseFontBitmapsA",
450 "wglUseFontBitmapsW",
451 "wglUseFontOutlinesA",
452 "wglUseFontOutlinesW",
453
José Fonsecac6b49ce2010-11-28 16:43:04 +0000454])
455
Chia-I Wue50c14b2011-11-03 12:24:53 +0800456# EGL 1.4
457public_symbols.update([
458 "eglBindAPI",
459 "eglBindTexImage",
460 "eglChooseConfig",
461 "eglCopyBuffers",
462 "eglCreateContext",
463 "eglCreatePbufferFromClientBuffer",
464 "eglCreatePbufferSurface",
465 "eglCreatePixmapSurface",
466 "eglCreateWindowSurface",
467 "eglDestroyContext",
468 "eglDestroySurface",
469 "eglGetConfigAttrib",
470 "eglGetConfigs",
471 "eglGetCurrentContext",
472 "eglGetCurrentDisplay",
473 "eglGetCurrentSurface",
474 "eglGetDisplay",
475 "eglGetError",
476 "eglGetProcAddress",
477 "eglInitialize",
478 "eglMakeCurrent",
479 "eglQueryAPI",
480 "eglQueryContext",
481 "eglQueryString",
482 "eglQuerySurface",
483 "eglReleaseTexImage",
484 "eglReleaseThread",
485 "eglSurfaceAttrib",
486 "eglSwapBuffers",
487 "eglSwapInterval",
488 "eglTerminate",
489 "eglWaitClient",
490 "eglWaitGL",
491 "eglWaitNative",
492])
José Fonsecac6b49ce2010-11-28 16:43:04 +0000493
José Fonseca68ec4122011-02-20 11:25:25 +0000494class GlDispatcher(Dispatcher):
495
José Fonseca81301932012-11-11 00:10:20 +0000496 def isFunctionPublic(self, module, function):
José Fonseca3bcb33c2011-05-27 20:14:31 +0100497 return function.name in public_symbols or function.name.startswith('CGL')
José Fonsecac6b49ce2010-11-28 16:43:04 +0000498
José Fonseca7989f932014-07-17 19:45:15 +0100499 def getProcAddressName(self, module, function):
500 if self.isFunctionPublic(module, function):
501 return '_getPublicProcAddress'
502 else:
503 return '_getPrivateProcAddress'
504
Peter Lohrmann9d9eb812013-07-12 16:15:25 -0400505 def failFunction(self, function):
José Fonseca71f5a352014-07-28 12:19:50 +0100506 # We fake these when they are not available
507 if function.name in (
508 # GL_KHR_debug
509 'glDebugMessageControl',
510 'glDebugMessageInsert',
511 'glDebugMessageCallback',
512 'glPushDebugGroup',
513 'glPopDebugGroup',
514 'glObjectLabel',
515 'glObjectPtrLabel',
516 # GL_ARB_debug_output
517 'glDebugMessageControlARB',
518 'glDebugMessageInsertARB',
519 'glDebugMessageCallbackARB',
520 # GL_AMD_debug_output
521 'glDebugMessageEnableAMD',
522 'glDebugMessageInsertAMD',
523 'glDebugMessageCallbackAMD',
524 # GL_EXT_debug_label
525 'glLabelObjectEXT',
526 # GL_EXT_debug_marker
527 'glInsertEventMarkerEXT',
528 'glPushGroupMarkerEXT',
529 'glPopGroupMarkerEXT',
530 ):
531 return
José Fonseca7ff82412014-02-04 19:01:22 +0000532 if function.name in ('glGetObjectLabel', 'glGetObjectPtrLabel', 'glGetObjectLabelEXT'):
Peter Lohrmann9d9eb812013-07-12 16:15:25 -0400533 print r' if (length != 0) *length = 0;'
534 print r' if (label != 0 && bufSize > 0) *label = 0;'
535 return
536 if function.name in ('glGetDebugMessageLog', 'glGetDebugMessageLogARB'):
537 print r' if (sources != 0) *sources = 0;'
538 print r' if (types != 0) *types = 0;'
539 print r' if (ids != 0) *ids = 0;'
540 print r' if (severities != 0) *severities = 0;'
541 print r' if (lengths != 0) *lengths = 0;'
542 print r' if (messageLog != 0 && bufsize > 0) *messageLog = 0;'
José Fonseca31215642014-07-17 20:32:12 +0100543 print r' return 0;'
Peter Lohrmann9d9eb812013-07-12 16:15:25 -0400544 return
545 if function.name in ('glGetDebugMessageLogAMD'):
546 print r' if (categories != 0) *categories = 0;'
547 print r' if (ids != 0) *ids = 0;'
548 print r' if (severities != 0) *severities = 0;'
549 print r' if (lengths != 0) *lengths = 0;'
550 print r' if (message != 0 && bufsize > 0) *message = 0;'
José Fonseca31215642014-07-17 20:32:12 +0100551 print r' return 0;'
Peter Lohrmann9d9eb812013-07-12 16:15:25 -0400552 return
553
554 Dispatcher.failFunction(self, function)
555
José Fonsecac6b49ce2010-11-28 16:43:04 +0000556
557if __name__ == '__main__':
José Fonsecae91f5bc2014-07-17 20:42:35 +0100558 decl, impl = sys.argv[1:]
559
560 sys.stdout = open(decl, 'wt')
José Fonsecac6b49ce2010-11-28 16:43:04 +0000561 print
José Fonseca669b2002011-02-20 13:32:19 +0000562 print '#ifndef _GLPROC_HPP_'
563 print '#define _GLPROC_HPP_'
José Fonsecae91f5bc2014-07-17 20:42:35 +0100564 print
José Fonsecac6b49ce2010-11-28 16:43:04 +0000565 print '#include "glimports.hpp"'
José Fonsecae91f5bc2014-07-17 20:42:35 +0100566 print
567 print '#if defined(_WIN32)'
568 print 'extern HMODULE _libGlHandle;'
569 print '#else'
570 print 'extern void * _libGlHandle;'
571 print '#endif'
572 print
573 print 'void * _getPublicProcAddress(const char *procName);'
574 print 'void * _getPrivateProcAddress(const char *procName);'
575 print
576 dispatcher = GlDispatcher()
577 print
578 dispatcher.dispatchModuleDecl(eglapi)
579 print
580 print '#if defined(_WIN32)'
581 print
582 dispatcher.dispatchModuleDecl(wglapi)
583 print
584 print '#elif defined(__APPLE__)'
585 print
586 dispatcher.dispatchModuleDecl(cglapi)
587 print
588 print '#elif defined(HAVE_X11)'
589 print
590 dispatcher.dispatchModuleDecl(glxapi)
591 print
592 print '#endif'
593 print
594 dispatcher.dispatchModuleDecl(glapi)
595 print
596 dispatcher.dispatchModuleDecl(glesapi)
597 print
598 print '#endif /* !_GLPROC_HPP_ */'
599 print
600
601 sys.stdout = open(impl, 'wt')
602 print
603 print '#include "glproc.hpp"'
José Fonsecac6b49ce2010-11-28 16:43:04 +0000604 print '#include "os.hpp"'
605 print
José Fonseca68ec4122011-02-20 11:25:25 +0000606 dispatcher = GlDispatcher()
José Fonsecaafc32ba2012-03-30 00:18:16 +0100607 print
José Fonsecae91f5bc2014-07-17 20:42:35 +0100608 dispatcher.dispatchModuleImpl(eglapi)
José Fonsecaafc32ba2012-03-30 00:18:16 +0100609 print
610 print '#if defined(_WIN32)'
José Fonseca68ec4122011-02-20 11:25:25 +0000611 print
José Fonsecae91f5bc2014-07-17 20:42:35 +0100612 dispatcher.dispatchModuleImpl(wglapi)
José Fonsecaafc32ba2012-03-30 00:18:16 +0100613 print
José Fonseca3dabe542011-05-19 17:57:18 +0100614 print '#elif defined(__APPLE__)'
José Fonsecaafc32ba2012-03-30 00:18:16 +0100615 print
José Fonsecae91f5bc2014-07-17 20:42:35 +0100616 dispatcher.dispatchModuleImpl(cglapi)
José Fonsecaafc32ba2012-03-30 00:18:16 +0100617 print
José Fonseca5409d1e2012-03-30 19:58:20 +0100618 print '#elif defined(HAVE_X11)'
José Fonseca68ec4122011-02-20 11:25:25 +0000619 print
José Fonsecae91f5bc2014-07-17 20:42:35 +0100620 dispatcher.dispatchModuleImpl(glxapi)
José Fonsecaafc32ba2012-03-30 00:18:16 +0100621 print
José Fonseca3dabe542011-05-19 17:57:18 +0100622 print '#endif'
José Fonseca43648602011-05-15 12:56:59 +0100623 print
José Fonsecae91f5bc2014-07-17 20:42:35 +0100624 dispatcher.dispatchModuleImpl(glapi)
José Fonsecac6b49ce2010-11-28 16:43:04 +0000625 print
José Fonsecae91f5bc2014-07-17 20:42:35 +0100626 dispatcher.dispatchModuleImpl(glesapi)
José Fonseca669b2002011-02-20 13:32:19 +0000627 print