3 # (C) Copyright IBM Corporation 2004, 2005
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # on the rights to use, copy, modify, merge, publish, distribute, sub
10 # license, and/or sell copies of the Software, and to permit persons to whom
11 # the Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice (including the next
14 # paragraph) shall be included in all copies or substantial portions of the
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 # Ian Romanick <idr@us.ibm.com>
29 import gl_XML
, glX_XML
32 class PrintGlProcs(gl_XML
.gl_print_base
):
33 def __init__(self
, long_strings
, es
=False):
34 gl_XML
.gl_print_base
.__init
__(self
)
37 self
.long_strings
= long_strings
38 self
.name
= "gl_procs.py (from Mesa)"
39 self
.license
= license
.bsd_license_template
% ( \
40 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
41 (C) Copyright IBM Corporation 2004, 2006""", "BRIAN PAUL, IBM")
44 def printRealHeader(self
):
46 /* This file is only included by glapi.c and is used for
47 * the GetProcAddress() function
52 #if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING)
58 #if !defined(NEED_FUNCTION_POINTER) && !defined(GLX_INDIRECT_RENDERING)
59 # define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , o }
60 #elif defined(NEED_FUNCTION_POINTER) && !defined(GLX_INDIRECT_RENDERING)
61 # define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f1 , o }
62 #elif defined(NEED_FUNCTION_POINTER) && defined(GLX_INDIRECT_RENDERING)
63 # define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f2 , o }
64 #elif !defined(NEED_FUNCTION_POINTER) && defined(GLX_INDIRECT_RENDERING)
65 # define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f3 , o }
71 def printRealFooter(self
):
73 print '#undef NAME_FUNC_OFFSET'
76 def printFunctionString(self
, name
):
78 print ' "gl%s\\0"' % (name
)
87 def printBody(self
, api
):
90 print 'static const char gl_string_table[] ='
92 print 'static const char gl_string_table[] = {'
96 for func
in api
.functionIterateByOffset():
97 name
= func
.dispatch_name()
98 self
.printFunctionString(func
.name
)
99 table
.append((base_offset
, "gl" + name
, "gl" + name
, "NULL", func
.offset
))
101 # The length of the function's name, plus 2 for "gl",
102 # plus 1 for the NUL.
104 base_offset
+= len(func
.name
) + 3
107 for func
in api
.functionIterateByOffset():
108 for n
in func
.entry_points
:
110 # AROS: call into a static dispach instead of alliased function dispatch
111 # This will be needed as long as gl_procs.h is used to generate the
112 # AROSMesaGetProcAddress function table which is located in libGL.a
113 # name = func.dispatch_name()
115 self
.printFunctionString( n
)
117 if func
.has_different_protocol(n
):
118 alt_name
= "gl" + func
.static_glx_name(n
)
119 table
.append((base_offset
, "gl" + name
, alt_name
, alt_name
, func
.offset
))
121 table
.append((base_offset
, "gl" + name
, "gl" + name
, "NULL", func
.offset
))
123 base_offset
+= len(n
) + 3
126 if self
.long_strings
:
133 print "#ifdef USE_MGL_NAMESPACE"
134 for func
in api
.functionIterateByOffset():
135 for n
in func
.entry_points
:
136 if (not func
.is_static_entry_point(func
.name
)) or (func
.has_different_protocol(n
) and not func
.is_static_entry_point(n
)):
137 print '#define gl_dispatch_stub_%u mgl_dispatch_stub_%u' % (func
.offset
, func
.offset
)
139 print "#endif /* USE_MGL_NAMESPACE */"
142 print '#if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING)'
143 for func
in api
.functionIterateByOffset():
144 for n
in func
.entry_points
:
145 if (not func
.is_static_entry_point(func
.name
)) or (func
.has_different_protocol(n
) and not func
.is_static_entry_point(n
)):
146 print '%s GLAPIENTRY gl_dispatch_stub_%u(%s);' % (func
.return_type
, func
.offset
, func
.get_parameter_string())
151 for func
in api
.functionIterateByOffset():
152 for n
in func
.entry_points
:
153 cat
, num
= api
.get_category_for_name(n
)
154 if (cat
.startswith("es") or cat
.startswith("GL_OES")):
155 if not categories
.has_key(cat
):
157 proto
= 'GLAPI %s GLAPIENTRY %s(%s);' \
158 % (func
.return_type
, "gl" + n
, func
.get_parameter_string(n
))
159 categories
[cat
].append(proto
)
162 print '/* OpenGL ES specific prototypes */'
164 keys
= categories
.keys()
167 print '/* category %s */' % key
168 print "\n".join(categories
[key
])
171 print '#endif /* defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) */'
174 print 'static const glprocs_table_t static_functions[] = {'
177 print ' NAME_FUNC_OFFSET(%5u, %s, %s, %s, %d),' % info
179 print ' NAME_FUNC_OFFSET(-1, NULL, NULL, NULL, 0)'
185 print "Usage: %s [-f input_file_name] [-m mode] [-c]" % sys
.argv
[0]
186 print "-c Enable compatibility with OpenGL ES."
187 print "-m mode mode can be one of:"
188 print " long - Create code for compilers that can handle very"
189 print " long string constants. (default)"
190 print " short - Create code for compilers that can only handle"
191 print " ANSI C89 string constants."
194 if __name__
== '__main__':
195 file_name
= "gl_API.xml"
198 (args
, trail
) = getopt
.getopt(sys
.argv
[1:], "f:m:c")
204 for (arg
,val
) in args
:
217 api
= gl_XML
.parse_GL_API(file_name
, glX_XML
.glx_item_factory())
218 printer
= PrintGlProcs(long_string
, es
)