2 # (C) Copyright IBM Corporation 2004, 2005
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # on the rights to use, copy, modify, merge, publish, distribute, sub
9 # license, and/or sell copies of the Software, and to permit persons to whom
10 # the Software is furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
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 NON-INFRINGEMENT. IN NO EVENT SHALL
19 # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 # Ian Romanick <idr@us.ibm.com>
27 from __future__
import print_function
36 class PrintGlProcs(gl_XML
.gl_print_base
):
37 def __init__(self
, es
=False):
38 gl_XML
.gl_print_base
.__init
__(self
)
41 self
.name
= "gl_procs.py (from Mesa)"
42 self
.license
= license
.bsd_license_template
% ( \
43 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
44 (C) Copyright IBM Corporation 2004, 2006""", "BRIAN PAUL, IBM")
46 def printRealHeader(self
):
48 /* This file is only included by glapi.c and is used for
49 * the GetProcAddress() function
54 #if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING)
60 #if !defined(NEED_FUNCTION_POINTER) && !defined(GLX_INDIRECT_RENDERING)
61 # define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , o }
62 #elif defined(NEED_FUNCTION_POINTER) && !defined(GLX_INDIRECT_RENDERING)
63 # define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f1 , o }
64 #elif defined(NEED_FUNCTION_POINTER) && defined(GLX_INDIRECT_RENDERING)
65 # define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f2 , o }
66 #elif !defined(NEED_FUNCTION_POINTER) && defined(GLX_INDIRECT_RENDERING)
67 # define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f3 , o }
73 def printRealFooter(self
):
75 print('#undef NAME_FUNC_OFFSET')
78 def printFunctionString(self
, name
):
79 print(' "gl%s\\0"' % (name
))
81 def printBody(self
, api
):
83 print('static const char gl_string_table[] =')
87 for func
in api
.functionIterateByOffset():
88 name
= func
.dispatch_name()
89 self
.printFunctionString(func
.name
)
90 table
.append((base_offset
, "gl" + name
, "gl" + name
, "NULL", func
.offset
))
92 # The length of the function's name, plus 2 for "gl",
95 base_offset
+= len(func
.name
) + 3
98 for func
in api
.functionIterateByOffset():
99 for n
in func
.entry_points
:
101 name
= func
.dispatch_name()
102 self
.printFunctionString( n
)
104 if func
.has_different_protocol(n
):
105 alt_name
= "gl" + func
.static_glx_name(n
)
106 table
.append((base_offset
, "gl" + name
, alt_name
, alt_name
, func
.offset
))
108 table
.append((base_offset
, "gl" + name
, "gl" + name
, "NULL", func
.offset
))
110 base_offset
+= len(n
) + 3
116 print("#ifdef USE_MGL_NAMESPACE")
117 for func
in api
.functionIterateByOffset():
118 for n
in func
.entry_points
:
119 if (not func
.is_static_entry_point(func
.name
)) or (func
.has_different_protocol(n
) and not func
.is_static_entry_point(n
)):
120 print('#define gl_dispatch_stub_%u mgl_dispatch_stub_%u' % (func
.offset
, func
.offset
))
122 print("#endif /* USE_MGL_NAMESPACE */")
125 print('#if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING)')
126 for func
in api
.functionIterateByOffset():
127 for n
in func
.entry_points
:
128 if (not func
.is_static_entry_point(func
.name
)) or (func
.has_different_protocol(n
) and not func
.is_static_entry_point(n
)):
129 print('%s GLAPIENTRY gl_dispatch_stub_%u(%s);' % (func
.return_type
, func
.offset
, func
.get_parameter_string()))
134 for func
in api
.functionIterateByOffset():
135 for n
in func
.entry_points
:
136 cat
, num
= api
.get_category_for_name(n
)
137 if (cat
.startswith("es") or cat
.startswith("GL_OES")):
138 if cat
not in categories
:
140 proto
= 'GLAPI %s GLAPIENTRY %s(%s);' \
141 % (func
.return_type
, "gl" + n
, func
.get_parameter_string(n
))
142 categories
[cat
].append(proto
)
145 print('/* OpenGL ES specific prototypes */')
147 keys
= sorted(categories
.keys())
149 print('/* category %s */' % key
)
150 print("\n".join(categories
[key
]))
153 print('#endif /* defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) */')
156 print('static const glprocs_table_t static_functions[] = {')
159 print(' NAME_FUNC_OFFSET(%5u, %s, %s, %s, %d),' % info
)
161 print(' NAME_FUNC_OFFSET(-1, NULL, NULL, NULL, 0)')
167 """Parse arguments and return a namepsace."""
169 parser
= argparse
.ArgumentParser()
170 parser
.add_argument('-f', '--filename',
171 default
='gl_API.xml',
172 metavar
="input_file_name",
174 help="Path to an XML description of OpenGL API.")
175 parser
.add_argument('-c', '--es-version',
178 help="filter functions for es")
179 return parser
.parse_args()
185 api
= gl_XML
.parse_GL_API(args
.file_name
, glX_XML
.glx_item_factory())
186 PrintGlProcs(args
.es
).Print(api
)
189 if __name__
== '__main__':