mesa: add KHR_no_error support to glDrawBuffer()
[mesa.git] / src / mapi / glapi / gen / gl_procs.py
1
2 # (C) Copyright IBM Corporation 2004, 2005
3 # All Rights Reserved.
4 #
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:
11 #
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
14 # 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 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
22 # IN THE SOFTWARE.
23 #
24 # Authors:
25 # Ian Romanick <idr@us.ibm.com>
26
27 import argparse
28
29 import license
30 import gl_XML
31 import glX_XML
32
33
34 class PrintGlProcs(gl_XML.gl_print_base):
35 def __init__(self, es=False):
36 gl_XML.gl_print_base.__init__(self)
37
38 self.es = es
39 self.name = "gl_procs.py (from Mesa)"
40 self.license = license.bsd_license_template % ( \
41 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
42 (C) Copyright IBM Corporation 2004, 2006""", "BRIAN PAUL, IBM")
43
44 def printRealHeader(self):
45 print """
46 /* This file is only included by glapi.c and is used for
47 * the GetProcAddress() function
48 */
49
50 typedef struct {
51 GLint Name_offset;
52 #if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING)
53 _glapi_proc Address;
54 #endif
55 GLuint Offset;
56 } glprocs_table_t;
57
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 }
66 #endif
67
68 """
69 return
70
71 def printRealFooter(self):
72 print ''
73 print '#undef NAME_FUNC_OFFSET'
74 return
75
76 def printFunctionString(self, name):
77 print ' "gl%s\\0"' % (name)
78
79 def printBody(self, api):
80 print ''
81 print 'static const char gl_string_table[] ='
82
83 base_offset = 0
84 table = []
85 for func in api.functionIterateByOffset():
86 name = func.dispatch_name()
87 self.printFunctionString(func.name)
88 table.append((base_offset, "gl" + name, "gl" + name, "NULL", func.offset))
89
90 # The length of the function's name, plus 2 for "gl",
91 # plus 1 for the NUL.
92
93 base_offset += len(func.name) + 3
94
95
96 for func in api.functionIterateByOffset():
97 for n in func.entry_points:
98 if n != func.name:
99 name = func.dispatch_name()
100 self.printFunctionString( n )
101
102 if func.has_different_protocol(n):
103 alt_name = "gl" + func.static_glx_name(n)
104 table.append((base_offset, "gl" + name, alt_name, alt_name, func.offset))
105 else:
106 table.append((base_offset, "gl" + name, "gl" + name, "NULL", func.offset))
107
108 base_offset += len(n) + 3
109
110
111 print ' ;'
112 print ''
113 print ''
114 print "#ifdef USE_MGL_NAMESPACE"
115 for func in api.functionIterateByOffset():
116 for n in func.entry_points:
117 if (not func.is_static_entry_point(func.name)) or (func.has_different_protocol(n) and not func.is_static_entry_point(n)):
118 print '#define gl_dispatch_stub_%u mgl_dispatch_stub_%u' % (func.offset, func.offset)
119 break
120 print "#endif /* USE_MGL_NAMESPACE */"
121 print ''
122 print ''
123 print '#if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING)'
124 for func in api.functionIterateByOffset():
125 for n in func.entry_points:
126 if (not func.is_static_entry_point(func.name)) or (func.has_different_protocol(n) and not func.is_static_entry_point(n)):
127 print '%s GLAPIENTRY gl_dispatch_stub_%u(%s);' % (func.return_type, func.offset, func.get_parameter_string())
128 break
129
130 if self.es:
131 categories = {}
132 for func in api.functionIterateByOffset():
133 for n in func.entry_points:
134 cat, num = api.get_category_for_name(n)
135 if (cat.startswith("es") or cat.startswith("GL_OES")):
136 if not categories.has_key(cat):
137 categories[cat] = []
138 proto = 'GLAPI %s GLAPIENTRY %s(%s);' \
139 % (func.return_type, "gl" + n, func.get_parameter_string(n))
140 categories[cat].append(proto)
141 if categories:
142 print ''
143 print '/* OpenGL ES specific prototypes */'
144 print ''
145 keys = categories.keys()
146 keys.sort()
147 for key in keys:
148 print '/* category %s */' % key
149 print "\n".join(categories[key])
150 print ''
151
152 print '#endif /* defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) */'
153
154 print ''
155 print 'static const glprocs_table_t static_functions[] = {'
156
157 for info in table:
158 print ' NAME_FUNC_OFFSET(%5u, %s, %s, %s, %d),' % info
159
160 print ' NAME_FUNC_OFFSET(-1, NULL, NULL, NULL, 0)'
161 print '};'
162 return
163
164
165 def _parser():
166 """Parse arguments and return a namepsace."""
167
168 parser = argparse.ArgumentParser()
169 parser.add_argument('-f', '--filename',
170 default='gl_API.xml',
171 metavar="input_file_name",
172 dest='file_name',
173 help="Path to an XML description of OpenGL API.")
174 parser.add_argument('-c', '--es-version',
175 dest='es',
176 action="store_true",
177 help="filter functions for es")
178 return parser.parse_args()
179
180
181 def main():
182 """Main function."""
183 args = _parser()
184 api = gl_XML.parse_GL_API(args.file_name, glX_XML.glx_item_factory())
185 PrintGlProcs(args.es).Print(api)
186
187
188 if __name__ == '__main__':
189 main()