glapi: Remove handling of mesa_name XML attribute.
[mesa.git] / src / mapi / glapi / gen / gl_genexec.py
1 #!/usr/bin/env python
2
3 # Copyright (C) 2012 Intel Corporation
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 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # 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 NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS 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 # This script generates the file api_exec.c, which contains
25 # _mesa_create_exec_table(). It is responsible for populating all
26 # entries in the "exec" dispatch table that aren't dynamic.
27
28 import collections
29 import license
30 import gl_XML
31 import sys, getopt
32
33
34 exec_flavor_map = {
35 'check': '_check_',
36 'dynamic': None,
37 'es': '_es_',
38 'loopback': 'loopback_',
39 'mesa': '_mesa_',
40 'skip': None,
41 }
42
43
44 header = """/**
45 * \\file api_exec.c
46 * Initialize dispatch table.
47 */
48
49
50 #include "main/mfeatures.h"
51 #include "main/accum.h"
52 #include "main/api_loopback.h"
53 #include "main/api_exec.h"
54 #include "main/arbprogram.h"
55 #include "main/atifragshader.h"
56 #include "main/attrib.h"
57 #include "main/blend.h"
58 #include "main/bufferobj.h"
59 #include "main/arrayobj.h"
60 #include "main/buffers.h"
61 #include "main/clear.h"
62 #include "main/clip.h"
63 #include "main/colortab.h"
64 #include "main/condrender.h"
65 #include "main/context.h"
66 #include "main/convolve.h"
67 #include "main/depth.h"
68 #include "main/dlist.h"
69 #include "main/drawpix.h"
70 #include "main/drawtex.h"
71 #include "main/rastpos.h"
72 #include "main/enable.h"
73 #include "main/errors.h"
74 #include "main/es1_conversion.h"
75 #include "main/eval.h"
76 #include "main/get.h"
77 #include "main/feedback.h"
78 #include "main/fog.h"
79 #include "main/fbobject.h"
80 #include "main/framebuffer.h"
81 #include "main/hint.h"
82 #include "main/histogram.h"
83 #include "main/imports.h"
84 #include "main/light.h"
85 #include "main/lines.h"
86 #include "main/matrix.h"
87 #include "main/multisample.h"
88 #include "main/pixel.h"
89 #include "main/pixelstore.h"
90 #include "main/points.h"
91 #include "main/polygon.h"
92 #include "main/querymatrix.h"
93 #include "main/queryobj.h"
94 #include "main/readpix.h"
95 #include "main/samplerobj.h"
96 #include "main/scissor.h"
97 #include "main/stencil.h"
98 #include "main/texenv.h"
99 #include "main/texgetimage.h"
100 #include "main/teximage.h"
101 #include "main/texgen.h"
102 #include "main/texobj.h"
103 #include "main/texparam.h"
104 #include "main/texstate.h"
105 #include "main/texstorage.h"
106 #include "main/texturebarrier.h"
107 #include "main/transformfeedback.h"
108 #include "main/mtypes.h"
109 #include "main/varray.h"
110 #include "main/viewport.h"
111 #include "main/shaderapi.h"
112 #include "main/uniforms.h"
113 #include "main/syncobj.h"
114 #include "main/dispatch.h"
115
116
117 /**
118 * Initialize a dispatch table with pointers to Mesa's immediate-mode
119 * commands.
120 *
121 * Pointers to glBegin()/glEnd() object commands and a few others
122 * are provided via the GLvertexformat interface.
123 *
124 * \param ctx GL context to which \c exec belongs.
125 * \param exec dispatch table.
126 */
127 struct _glapi_table *
128 _mesa_create_exec_table(struct gl_context *ctx)
129 {
130 struct _glapi_table *exec;
131
132 exec = _mesa_alloc_dispatch_table(_gloffset_COUNT);
133 if (exec == NULL)
134 return NULL;
135
136 """
137
138
139 footer = """
140 return exec;
141 }
142 """
143
144
145 class PrintCode(gl_XML.gl_print_base):
146
147 def __init__(self):
148 gl_XML.gl_print_base.__init__(self)
149
150 self.name = 'gl_genexec.py'
151 self.license = license.bsd_license_template % (
152 'Copyright (C) 2012 Intel Corporation',
153 'Intel Corporation')
154
155 def printRealHeader(self):
156 print header
157
158 def printRealFooter(self):
159 print footer
160
161 def printBody(self, api):
162 # Collect SET_* calls by the condition under which they should
163 # be called.
164 settings_by_condition = collections.defaultdict(lambda: [])
165 for f in api.functionIterateAll():
166 if f.exec_flavor not in exec_flavor_map:
167 raise Exception(
168 'Unrecognized exec flavor {0!r}'.format(f.exec_flavor))
169 condition_parts = []
170 if f.desktop:
171 if f.deprecated:
172 condition_parts.append('ctx->API == API_OPENGL')
173 else:
174 condition_parts.append('_mesa_is_desktop_gl(ctx)')
175 if 'es1' in f.api_map:
176 condition_parts.append('ctx->API == API_OPENGLES')
177 if 'es2' in f.api_map:
178 if f.api_map['es2'] == 3:
179 condition_parts.append('_mesa_is_gles3(ctx)')
180 else:
181 condition_parts.append('ctx->API == API_OPENGLES2')
182 if not condition_parts:
183 # This function does not exist in any API.
184 continue
185 condition = ' || '.join(condition_parts)
186 prefix = exec_flavor_map[f.exec_flavor]
187 if prefix is None:
188 # This function is not implemented, or is dispatched
189 # dynamically.
190 continue
191 settings_by_condition[condition].append(
192 'SET_{0}(exec, {1}{0});'.format(f.name, prefix, f.name))
193 # Print out an if statement for each unique condition, with
194 # the SET_* calls nested inside it.
195 for condition in sorted(settings_by_condition.keys()):
196 print ' if ({0}) {{'.format(condition)
197 for setting in sorted(settings_by_condition[condition]):
198 print ' {0}'.format(setting)
199 print ' }'
200
201
202 def show_usage():
203 print "Usage: %s [-f input_file_name]" % sys.argv[0]
204 sys.exit(1)
205
206
207 if __name__ == '__main__':
208 file_name = "gl_and_es_API.xml"
209
210 try:
211 (args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
212 except Exception,e:
213 show_usage()
214
215 for (arg,val) in args:
216 if arg == "-f":
217 file_name = val
218
219 printer = PrintCode()
220
221 api = gl_XML.parse_GL_API(file_name)
222 printer.Print(api)