1 #*************************************************************************
2 # Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 # TUNGSTEN GRAPHICS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
20 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 #*************************************************************************
26 import APIspecutil
as apiutil
28 # These dictionary entries are used for automatic conversion.
29 # The string will be used as a format string with the conversion
33 'GLdouble': "(GLdouble) (%s)",
34 'GLfixed' : "(GLint) (%s * 65536)",
37 'GLfloat': "(GLfloat) (%s / 65536.0f)",
38 'GLdouble': "(GLdouble) (%s / 65536.0)",
41 'GLfloat': "(GLfloat) (%s)",
42 'GLfixed': "(GLfixed) (%s * 65536)",
45 'GLclampd': "(GLclampd) (%s)",
46 'GLclampx': "(GLclampx) (%s * 65536)",
49 'GLclampf': "(GLclampf) (%s / 65536.0f)",
50 'GLclampd': "(GLclampd) (%s / 65536.0)",
53 'GLfloat': "(GLfloat) (%s / 255.0f)",
57 def GetBaseType(type):
58 typeTokens
= type.split(' ')
62 if t
in ['const', '*']:
63 typeModifiers
.append(t
)
66 return (baseType
, typeModifiers
)
68 def ConvertValue(value
, fromType
, toType
):
69 """Returns a string that represents the given parameter string,
70 type-converted if necessary."""
72 if not Converters
.has_key(fromType
):
73 print >> sys
.stderr
, "No base converter for type '%s' found. Ignoring." % fromType
76 if not Converters
[fromType
].has_key(toType
):
77 print >> sys
.stderr
, "No converter found for type '%s' to type '%s'. Ignoring." % (fromType
, toType
)
80 # This part is simple. Return the proper conversion.
81 conversionString
= Converters
[fromType
][toType
]
82 return conversionString
% value
88 'GLbitfield' : '0x%x',
90 def GetFormatString(type):
91 if FormatStrings
.has_key(type):
92 return FormatStrings
[type]
97 ######################################################################
98 # Version-specific values to be used in the main script
99 # header: which header file to include
100 # api: what text specifies an API-level function
101 VersionSpecificValues
= {
103 'description' : 'GLES1.1 functions',
104 'header' : 'GLES/gl.h',
105 'extheader' : 'GLES/glext.h',
108 'description' : 'GLES2.0 functions',
109 'header' : 'GLES2/gl2.h',
110 'extheader' : 'GLES2/gl2ext.h',
115 ######################################################################
116 # Main code for the script begins here.
118 # Get the name of the program (without the directory part) for use in
120 program
= os
.path
.basename(sys
.argv
[0])
124 functionList
= "APIspec.xml"
127 # Allow for command-line switches
131 optlist
, args
= getopt
.getopt(sys
.argv
[1:], options
)
132 except getopt
.GetoptError
, message
:
133 sys
.stderr
.write("%s: %s. Use -h for help.\n" % (program
, message
))
136 for option
, optarg
in optlist
:
138 sys
.stderr
.write("Usage: %s [-%s]\n" % (program
, options
))
139 sys
.stderr
.write("Parse an API specification file and generate wrapper functions for a given GLES version\n")
140 sys
.stderr
.write("-h gives help\n")
141 sys
.stderr
.write("-v is verbose\n")
142 sys
.stderr
.write("-V specifies GLES version to generate [%s]:\n" % version
)
143 for key
in VersionSpecificValues
.keys():
144 sys
.stderr
.write(" %s - %s\n" % (key
, VersionSpecificValues
[key
]['description']))
145 sys
.stderr
.write("-S specifies API specification file to use [%s]\n" % functionList
)
152 functionList
= optarg
154 # Beyond switches, we support no further command-line arguments
156 sys
.stderr
.write("%s: only switch arguments are supported - use -h for help\n" % program
)
159 # If we don't have a valid version, abort.
160 if not VersionSpecificValues
.has_key(version
):
161 sys
.stderr
.write("%s: version '%s' is not valid - use -h for help\n" % (program
, version
))
164 # Grab the version-specific items we need to use
165 versionHeader
= VersionSpecificValues
[version
]['header']
166 versionExtHeader
= VersionSpecificValues
[version
]['extheader']
168 # If we get to here, we're good to go. The "version" parameter
169 # directs GetDispatchedFunctions to only allow functions from
170 # that "category" (version in our parlance). This allows
171 # functions with different declarations in different categories
172 # to exist (glTexImage2D, for example, is different between
174 keys
= apiutil
.GetAllFunctions(functionList
, version
)
176 allSpecials
= apiutil
.AllSpecials()
178 print """/* DO NOT EDIT *************************************************
179 * THIS FILE AUTOMATICALLY GENERATED BY THE %s SCRIPT
180 * API specification file: %s
184 """ % (program
, functionList
, version
, time
.strftime("%Y-%m-%d %H:%M:%S"))
186 # The headers we choose are version-specific.
190 """ % (versionHeader
, versionExtHeader
)
192 # Everyone needs these types.
194 /* These types are needed for the Mesa veneer, but are not defined in
195 * the standard GLES headers.
197 typedef double GLdouble;
198 typedef double GLclampd;
200 /* This type is normally in glext.h, but needed here */
203 /* Mesa error handling requires these */
204 extern void *_mesa_get_current_context(void);
205 extern void _mesa_error(void *ctx, GLenum error, const char *fmtString, ... );
207 #include "main/compiler.h"
208 #include "main/api_exec.h"
210 #include "main/dispatch.h"
212 typedef void (*_glapi_proc)(void); /* generic function pointer */
215 # Finally we get to the all-important functions
216 print """/*************************************************************
217 * Generated functions begin here
220 for funcName
in keys
:
221 if verbose
> 0: sys
.stderr
.write("%s: processing function %s\n" % (program
, funcName
))
223 # start figuring out what this function will look like.
224 returnType
= apiutil
.ReturnType(funcName
)
225 props
= apiutil
.Properties(funcName
)
226 params
= apiutil
.Parameters(funcName
)
227 declarationString
= apiutil
.MakeDeclarationString(params
)
229 # In case of error, a function may have to return. Make
230 # sure we have valid return values in this case.
231 if returnType
== "void":
232 errorReturn
= "return"
233 elif returnType
== "GLboolean":
234 errorReturn
= "return GL_FALSE"
236 errorReturn
= "return (%s) 0" % returnType
238 # These are the output of this large calculation block.
239 # passthroughDeclarationString: a typed set of parameters that
240 # will be used to create the "extern" reference for the
241 # underlying Mesa or support function. Note that as generated
242 # these have an extra ", " at the beginning, which will be
243 # removed before use.
245 # passthroughDeclarationString: an untyped list of parameters
246 # that will be used to call the underlying Mesa or support
247 # function (including references to converted parameters).
248 # This will also be generated with an extra ", " at the
249 # beginning, which will be removed before use.
251 # variables: C code to create any local variables determined to
253 # conversionCodeOutgoing: C code to convert application parameters
254 # to a necessary type before calling the underlying support code.
255 # May be empty if no conversion is required.
256 # conversionCodeIncoming: C code to do the converse: convert
257 # values returned by underlying Mesa code to the types needed
258 # by the application.
259 # Note that *either* the conversionCodeIncoming will be used (for
260 # generated query functions), *or* the conversionCodeOutgoing will
261 # be used (for generated non-query functions), never both.
262 passthroughFuncName
= ""
263 passthroughDeclarationString
= ""
264 passthroughCallString
= ""
266 conversionCodeOutgoing
= []
267 conversionCodeIncoming
= []
270 # Calculate the name of the underlying support function to call.
271 # By default, the passthrough function is named _mesa_<funcName>.
272 # We're allowed to override the prefix and/or the function name
273 # for each function record, though. The "ConversionFunction"
274 # utility is poorly named, BTW...
275 if funcName
in allSpecials
:
276 # perform checks and pass through
277 funcPrefix
= "_check_"
281 aliasprefix
= apiutil
.AliasPrefix(funcName
)
282 alias
= apiutil
.ConversionFunction(funcName
)
284 # There may still be a Mesa alias for the function
285 if apiutil
.Alias(funcName
):
286 passthroughFuncName
= "%s%s" % (aliasprefix
, apiutil
.Alias(funcName
))
288 passthroughFuncName
= "%s%s" % (aliasprefix
, funcName
)
289 else: # a specific alias is provided
290 passthroughFuncName
= "%s%s" % (aliasprefix
, alias
)
292 # Look at every parameter: each one may have only specific
293 # allowed values, or dependent parameters to check, or
294 # variant-sized vector arrays to calculate
295 for (paramName
, paramType
, paramMaxVecSize
, paramConvertToType
, paramValidValues
, paramValueConversion
) in params
:
296 # We'll need this below if we're doing conversions
297 (paramBaseType
, paramTypeModifiers
) = GetBaseType(paramType
)
299 # Conversion management.
300 # We'll handle three cases, easiest to hardest: a parameter
301 # that doesn't require conversion, a scalar parameter that
302 # requires conversion, and a vector parameter that requires
304 if paramConvertToType
== None:
305 # Unconverted parameters are easy, whether they're vector
306 # or scalar - just add them to the call list. No conversions
307 # or anything to worry about.
308 passthroughDeclarationString
+= ", %s %s" % (paramType
, paramName
)
309 passthroughCallString
+= ", %s" % paramName
311 elif paramMaxVecSize
== 0: # a scalar parameter that needs conversion
312 # A scalar to hold a converted parameter
313 variables
.append(" %s converted_%s;" % (paramConvertToType
, paramName
))
315 # Outgoing conversion depends on whether we have to conditionally
316 # perform value conversion.
317 if paramValueConversion
== "none":
318 conversionCodeOutgoing
.append(" converted_%s = (%s) %s;" % (paramName
, paramConvertToType
, paramName
))
319 elif paramValueConversion
== "some":
320 # We'll need a conditional variable to keep track of
321 # whether we're converting values or not.
322 if (" int convert_%s_value = 1;" % paramName
) not in variables
:
323 variables
.append(" int convert_%s_value = 1;" % paramName
)
325 # Write code based on that conditional.
326 conversionCodeOutgoing
.append(" if (convert_%s_value) {" % paramName
)
327 conversionCodeOutgoing
.append(" converted_%s = %s;" % (paramName
, ConvertValue(paramName
, paramBaseType
, paramConvertToType
)))
328 conversionCodeOutgoing
.append(" } else {")
329 conversionCodeOutgoing
.append(" converted_%s = (%s) %s;" % (paramName
, paramConvertToType
, paramName
))
330 conversionCodeOutgoing
.append(" }")
331 else: # paramValueConversion == "all"
332 conversionCodeOutgoing
.append(" converted_%s = %s;" % (paramName
, ConvertValue(paramName
, paramBaseType
, paramConvertToType
)))
334 # Note that there can be no incoming conversion for a
335 # scalar parameter; changing the scalar will only change
336 # the local value, and won't ultimately change anything
337 # that passes back to the application.
339 # Call strings. The unusual " ".join() call will join the
340 # array of parameter modifiers with spaces as separators.
341 passthroughDeclarationString
+= ", %s %s %s" % (paramConvertToType
, " ".join(paramTypeModifiers
), paramName
)
342 passthroughCallString
+= ", converted_%s" % paramName
344 else: # a vector parameter that needs conversion
345 # We'll need an index variable for conversions
346 if " register unsigned int i;" not in variables
:
347 variables
.append(" register unsigned int i;")
349 # This variable will hold the (possibly variant) size of
350 # this array needing conversion. By default, we'll set
351 # it to the maximal size (which is correct for functions
352 # with a constant-sized vector parameter); for true
353 # variant arrays, we'll modify it with other code.
354 variables
.append(" unsigned int n_%s = %d;" % (paramName
, paramMaxVecSize
))
356 # This array will hold the actual converted values.
357 variables
.append(" %s converted_%s[%d];" % (paramConvertToType
, paramName
, paramMaxVecSize
))
359 # Again, we choose the conversion code based on whether we
360 # have to always convert values, never convert values, or
361 # conditionally convert values.
362 if paramValueConversion
== "none":
363 conversionCodeOutgoing
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
364 conversionCodeOutgoing
.append(" converted_%s[i] = (%s) %s[i];" % (paramName
, paramConvertToType
, paramName
))
365 conversionCodeOutgoing
.append(" }")
366 elif paramValueConversion
== "some":
367 # We'll need a conditional variable to keep track of
368 # whether we're converting values or not.
369 if (" int convert_%s_value = 1;" % paramName
) not in variables
:
370 variables
.append(" int convert_%s_value = 1;" % paramName
)
371 # Write code based on that conditional.
372 conversionCodeOutgoing
.append(" if (convert_%s_value) {" % paramName
)
373 conversionCodeOutgoing
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
374 conversionCodeOutgoing
.append(" converted_%s[i] = %s;" % (paramName
, ConvertValue("%s[i]" % paramName
, paramBaseType
, paramConvertToType
)))
375 conversionCodeOutgoing
.append(" }")
376 conversionCodeOutgoing
.append(" } else {")
377 conversionCodeOutgoing
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
378 conversionCodeOutgoing
.append(" converted_%s[i] = (%s) %s[i];" % (paramName
, paramConvertToType
, paramName
))
379 conversionCodeOutgoing
.append(" }")
380 conversionCodeOutgoing
.append(" }")
381 else: # paramValueConversion == "all"
382 conversionCodeOutgoing
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
383 conversionCodeOutgoing
.append(" converted_%s[i] = %s;" % (paramName
, ConvertValue("%s[i]" % paramName
, paramBaseType
, paramConvertToType
)))
385 conversionCodeOutgoing
.append(" }")
387 # If instead we need an incoming conversion (i.e. results
388 # from Mesa have to be converted before handing back
389 # to the application), this is it. Fortunately, we don't
390 # have to worry about conditional value conversion - the
391 # functions that do (e.g. glGetFixedv()) are handled
392 # specially, outside this code generation.
394 # Whether we use incoming conversion or outgoing conversion
395 # is determined later - we only ever use one or the other.
397 if paramValueConversion
== "none":
398 conversionCodeIncoming
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
399 conversionCodeIncoming
.append(" %s[i] = (%s) converted_%s[i];" % (paramName
, paramConvertToType
, paramName
))
400 conversionCodeIncoming
.append(" }")
401 elif paramValueConversion
== "some":
402 # We'll need a conditional variable to keep track of
403 # whether we're converting values or not.
404 if (" int convert_%s_value = 1;" % paramName
) not in variables
:
405 variables
.append(" int convert_%s_value = 1;" % paramName
)
407 # Write code based on that conditional.
408 conversionCodeIncoming
.append(" if (convert_%s_value) {" % paramName
)
409 conversionCodeIncoming
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
410 conversionCodeIncoming
.append(" %s[i] = %s;" % (paramName
, ConvertValue("converted_%s[i]" % paramName
, paramConvertToType
, paramBaseType
)))
411 conversionCodeIncoming
.append(" }")
412 conversionCodeIncoming
.append(" } else {")
413 conversionCodeIncoming
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
414 conversionCodeIncoming
.append(" %s[i] = (%s) converted_%s[i];" % (paramName
, paramBaseType
, paramName
))
415 conversionCodeIncoming
.append(" }")
416 conversionCodeIncoming
.append(" }")
417 else: # paramValueConversion == "all"
418 conversionCodeIncoming
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
419 conversionCodeIncoming
.append(" %s[i] = %s;" % (paramName
, ConvertValue("converted_%s[i]" % paramName
, paramConvertToType
, paramBaseType
)))
420 conversionCodeIncoming
.append(" }")
422 # Call strings. The unusual " ".join() call will join the
423 # array of parameter modifiers with spaces as separators.
424 passthroughDeclarationString
+= ", %s %s %s" % (paramConvertToType
, " ".join(paramTypeModifiers
), paramName
)
425 passthroughCallString
+= ", converted_%s" % paramName
427 # endif conversion management
429 # Parameter checking. If the parameter has a specific list of
430 # valid values, we have to make sure that the passed-in values
431 # match these, or we make an error.
432 if len(paramValidValues
) > 0:
433 # We're about to make a big switch statement with an
434 # error at the end. By default, the error is GL_INVALID_ENUM,
435 # unless we find a "case" statement in the middle with a
437 errorDefaultCase
= "GL_INVALID_ENUM"
439 # This parameter has specific valid values. Make a big
440 # switch statement to handle it. Note that the original
441 # parameters are always what is checked, not the
442 # converted parameters.
443 switchCode
.append(" switch(%s) {" % paramName
)
445 for valueIndex
in range(len(paramValidValues
)):
446 (paramValue
, dependentVecSize
, dependentParamName
, dependentValidValues
, errorCode
, valueConvert
) = paramValidValues
[valueIndex
]
448 # We're going to need information on the dependent param
450 if dependentParamName
:
451 depParamIndex
= apiutil
.FindParamIndex(params
, dependentParamName
)
452 if depParamIndex
== None:
453 sys
.stderr
.write("%s: can't find dependent param '%s' for function '%s'\n" % (program
, dependentParamName
, funcName
))
455 (depParamName
, depParamType
, depParamMaxVecSize
, depParamConvertToType
, depParamValidValues
, depParamValueConversion
) = params
[depParamIndex
]
457 (depParamName
, depParamType
, depParamMaxVecSize
, depParamConvertToType
, depParamValidValues
, depParamValueConversion
) = (None, None, None, None, [], None)
459 # This is a sneaky trick. It's valid syntax for a parameter
460 # that is *not* going to be converted to be declared
461 # with a dependent vector size; but in this case, the
462 # dependent vector size is unused and unnecessary.
463 # So check for this and ignore the dependent vector size
464 # if the parameter is not going to be converted.
465 if depParamConvertToType
:
466 usedDependentVecSize
= dependentVecSize
468 usedDependentVecSize
= None
470 # We'll peek ahead at the next parameter, to see whether
471 # we can combine cases
472 if valueIndex
+ 1 < len(paramValidValues
) :
473 (nextParamValue
, nextDependentVecSize
, nextDependentParamName
, nextDependentValidValues
, nextErrorCode
, nextValueConvert
) = paramValidValues
[valueIndex
+ 1]
474 if depParamConvertToType
:
475 usedNextDependentVecSize
= nextDependentVecSize
477 usedNextDependentVecSize
= None
479 # Create a case for this value. As a mnemonic,
480 # if we have a dependent vector size that we're ignoring,
481 # add it as a comment.
482 if usedDependentVecSize
== None and dependentVecSize
!= None:
483 switchCode
.append(" case %s: /* size %s */" % (paramValue
, dependentVecSize
))
485 switchCode
.append(" case %s:" % paramValue
)
487 # If this is not a GLenum case, then switch our error
488 # if no value is matched to be GL_INVALID_VALUE instead
489 # of GL_INVALID_ENUM. (Yes, this does get confused
490 # if there are both values and GLenums in the same
491 # switch statement, which shouldn't happen.)
492 if paramValue
[0:3] != "GL_":
493 errorDefaultCase
= "GL_INVALID_VALUE"
495 # If all the remaining parameters are identical to the
496 # next set, then we're done - we'll just create the
497 # official code on the next pass through, and the two
498 # cases will share the code.
499 if valueIndex
+ 1 < len(paramValidValues
) and usedDependentVecSize
== usedNextDependentVecSize
and dependentParamName
== nextDependentParamName
and dependentValidValues
== nextDependentValidValues
and errorCode
== nextErrorCode
and valueConvert
== nextValueConvert
:
502 # Otherwise, we'll have to generate code for this case.
503 # Start off with a check: if there is a dependent parameter,
504 # and a list of valid values for that parameter, we need
505 # to generate an error if something other than one
506 # of those values is passed.
507 if len(dependentValidValues
) > 0:
510 # If the parameter being checked is actually an array,
511 # check only its first element.
512 if depParamMaxVecSize
== 0:
513 valueToCheck
= dependentParamName
515 valueToCheck
= "%s[0]" % dependentParamName
517 for v
in dependentValidValues
:
518 conditional
+= " && %s != %s" % (valueToCheck
, v
)
519 switchCode
.append(" if (%s) {" % conditional
[4:])
520 if errorCode
== None:
521 errorCode
= "GL_INVALID_ENUM"
522 switchCode
.append(' _mesa_error(_mesa_get_current_context(), %s, "gl%s(%s=0x%s)", %s);' % (errorCode
, funcName
, paramName
, "%x", paramName
))
523 switchCode
.append(" %s;" % errorReturn
)
524 switchCode
.append(" }")
525 # endif there are dependent valid values
527 # The dependent parameter may require conditional
528 # value conversion. If it does, and we don't want
529 # to convert values, we'll have to generate code for that
530 if depParamValueConversion
== "some" and valueConvert
== "noconvert":
531 switchCode
.append(" convert_%s_value = 0;" % dependentParamName
)
533 # If there's a dependent vector size for this parameter
534 # that we're actually going to use (i.e. we need conversion),
536 if usedDependentVecSize
:
537 switchCode
.append(" n_%s = %s;" % (dependentParamName
, dependentVecSize
))
539 # In all cases, break out of the switch if any valid
541 switchCode
.append(" break;")
544 # Need a default case to catch all the other, invalid
545 # parameter values. These will all generate errors.
546 switchCode
.append(" default:")
547 if errorCode
== None:
548 errorCode
= "GL_INVALID_ENUM"
549 formatString
= GetFormatString(paramType
)
550 if formatString
== None:
551 switchCode
.append(' _mesa_error(_mesa_get_current_context(), %s, "gl%s(%s)");' % (errorCode
, funcName
, paramName
))
553 switchCode
.append(' _mesa_error(_mesa_get_current_context(), %s, "gl%s(%s=%s)", %s);' % (errorCode
, funcName
, paramName
, formatString
, paramName
))
554 switchCode
.append(" %s;" % errorReturn
)
556 # End of our switch code.
557 switchCode
.append(" }")
559 # endfor every recognized parameter value
563 # Here, the passthroughDeclarationString and passthroughCallString
564 # are complete; remove the extra ", " at the front of each.
565 passthroughDeclarationString
= passthroughDeclarationString
[2:]
566 passthroughCallString
= passthroughCallString
[2:]
568 # The Mesa functions are scattered across all the Mesa
569 # header files. The easiest way to manage declarations
570 # is to create them ourselves.
571 if funcName
in allSpecials
:
572 print "/* this function is special and is defined elsewhere */"
573 print "extern %s GLAPIENTRY %s(%s);" % (returnType
, passthroughFuncName
, passthroughDeclarationString
)
575 # A function may be a core function (i.e. it exists in
576 # the core specification), a core addition (extension
577 # functions added officially to the core), a required
578 # extension (usually an extension for an earlier version
579 # that has been officially adopted), or an optional extension.
581 # Core functions have a simple category (e.g. "GLES1.1");
582 # we generate only a simple callback for them.
584 # Core additions have two category listings, one simple
585 # and one compound (e.g. ["GLES1.1", "GLES1.1:OES_fixed_point"]).
586 # We generate the core function, and also an extension function.
588 # Required extensions and implemented optional extensions
589 # have a single compound category "GLES1.1:OES_point_size_array".
590 # For these we generate just the extension function.
591 for categorySpec
in apiutil
.Categories(funcName
):
592 compoundCategory
= categorySpec
.split(":")
594 # This category isn't for us, if the base category doesn't match
596 if compoundCategory
[0] != version
:
599 # Otherwise, determine if we're writing code for a core
600 # function (no suffix) or an extension function.
601 if len(compoundCategory
) == 1:
602 # This is a core function
606 # This is an extension function. We'll need to append
607 # the extension suffix.
608 extensionName
= compoundCategory
[1]
609 extensionSuffix
= extensionName
.split("_")[0]
610 fullFuncName
= funcPrefix
+ funcName
+ extensionSuffix
612 # Now the generated function. The text used to mark an API-level
613 # function, oddly, is version-specific.
615 print "/* Extension %s */" % extensionName
617 if (not variables
and
619 not conversionCodeOutgoing
and
620 not conversionCodeIncoming
):
621 # pass through directly
622 print "#define %s %s" % (fullFuncName
, passthroughFuncName
)
626 print "static %s %s(%s)" % (returnType
, fullFuncName
, declarationString
)
629 # Start printing our code pieces. Start with any local
630 # variables we need. This unusual syntax joins the
631 # lines in the variables[] array with the "\n" separator.
632 if len(variables
) > 0:
633 print "\n".join(variables
) + "\n"
635 # If there's any sort of parameter checking or variable
636 # array sizing, the switch code will contain it.
637 if len(switchCode
) > 0:
638 print "\n".join(switchCode
) + "\n"
640 # In the case of an outgoing conversion (i.e. parameters must
641 # be converted before calling the underlying Mesa function),
642 # use the appropriate code.
643 if "get" not in props
and len(conversionCodeOutgoing
) > 0:
644 print "\n".join(conversionCodeOutgoing
) + "\n"
646 # Call the Mesa function. Note that there are very few functions
647 # that return a value (i.e. returnType is not "void"), and that
648 # none of them require incoming translation; so we're safe
649 # to generate code that directly returns in those cases,
650 # even though it's not completely independent.
652 if returnType
== "void":
653 print " %s(%s);" % (passthroughFuncName
, passthroughCallString
)
655 print " return %s(%s);" % (passthroughFuncName
, passthroughCallString
)
657 # If the function is one that returns values (i.e. "get" in props),
658 # it might return values of a different type than we need, that
659 # require conversion before passing back to the application.
660 if "get" in props
and len(conversionCodeIncoming
) > 0:
661 print "\n".join(conversionCodeIncoming
)
666 # end for each category provided for a function
668 # end for each function
671 print "_mesa_init_exec_table(struct _glapi_table *exec)"
674 prefix
= "_es_" if func
not in allSpecials
else "_check_"
675 for spec
in apiutil
.Categories(func
):
676 ext
= spec
.split(":")
677 # version does not match
678 if ext
.pop(0) != version
:
682 suffix
= ext
[0].split("_")[0]
684 print " SET_%s(exec, %s%s);" % (entry
, prefix
, entry
)