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',
109 'description' : 'GLES2.0 functions',
110 'header' : 'GLES2/gl2.h',
111 'extheader' : 'GLES2/gl2ext.h',
117 ######################################################################
118 # Main code for the script begins here.
120 # Get the name of the program (without the directory part) for use in
122 program
= os
.path
.basename(sys
.argv
[0])
126 functionList
= "APIspec.xml"
129 # Allow for command-line switches
133 optlist
, args
= getopt
.getopt(sys
.argv
[1:], options
)
134 except getopt
.GetoptError
, message
:
135 sys
.stderr
.write("%s: %s. Use -h for help.\n" % (program
, message
))
138 for option
, optarg
in optlist
:
140 sys
.stderr
.write("Usage: %s [-%s]\n" % (program
, options
))
141 sys
.stderr
.write("Parse an API specification file and generate wrapper functions for a given GLES version\n")
142 sys
.stderr
.write("-h gives help\n")
143 sys
.stderr
.write("-v is verbose\n")
144 sys
.stderr
.write("-V specifies GLES version to generate [%s]:\n" % version
)
145 for key
in VersionSpecificValues
.keys():
146 sys
.stderr
.write(" %s - %s\n" % (key
, VersionSpecificValues
[key
]['description']))
147 sys
.stderr
.write("-S specifies API specification file to use [%s]\n" % functionList
)
154 functionList
= optarg
156 # Beyond switches, we support no further command-line arguments
158 sys
.stderr
.write("%s: only switch arguments are supported - use -h for help\n" % program
)
161 # If we don't have a valid version, abort.
162 if not VersionSpecificValues
.has_key(version
):
163 sys
.stderr
.write("%s: version '%s' is not valid - use -h for help\n" % (program
, version
))
166 # Grab the version-specific items we need to use
167 versionHeader
= VersionSpecificValues
[version
]['header']
168 versionExtHeader
= VersionSpecificValues
[version
]['extheader']
169 shortname
= VersionSpecificValues
[version
]['shortname']
171 # If we get to here, we're good to go. The "version" parameter
172 # directs GetDispatchedFunctions to only allow functions from
173 # that "category" (version in our parlance). This allows
174 # functions with different declarations in different categories
175 # to exist (glTexImage2D, for example, is different between
177 keys
= apiutil
.GetAllFunctions(functionList
, version
)
179 allSpecials
= apiutil
.AllSpecials()
181 print """/* DO NOT EDIT *************************************************
182 * THIS FILE AUTOMATICALLY GENERATED BY THE %s SCRIPT
183 * API specification file: %s
187 """ % (program
, functionList
, version
, time
.strftime("%Y-%m-%d %H:%M:%S"))
189 # The headers we choose are version-specific.
193 #include "main/mfeatures.h"
196 """ % (versionHeader
, versionExtHeader
, shortname
.upper())
198 # Everyone needs these types.
200 /* These types are needed for the Mesa veneer, but are not defined in
201 * the standard GLES headers.
203 typedef double GLdouble;
204 typedef double GLclampd;
206 /* Mesa error handling requires these */
207 extern void *_mesa_get_current_context(void);
208 extern void _mesa_error(void *ctx, GLenum error, const char *fmtString, ... );
210 #include "main/compiler.h"
211 #include "main/api_exec.h"
212 #include "main/remap.h"
214 /* cannot include main/dispatch.h here */
216 #define _GLAPI_USE_REMAP_TABLE
218 #include "%sapi/glapi/glapitable.h"
219 #include "%sapi/glapi/glapioffsets.h"
220 #include "%sapi/glapi/glapidispatch.h"
222 #if FEATURE_remap_table
225 int driDispatchRemapTable[driDispatchRemapTable_size];
228 #define need_MESA_remap_table
230 #include "%sapi/main/remap_helper.h"
233 _mesa_init_remap_table_%s(void)
235 _mesa_do_init_remap_table(_mesa_function_pool,
236 driDispatchRemapTable_size,
237 MESA_remap_table_functions);
241 _mesa_map_static_functions_%s(void)
247 typedef void (*_glapi_proc)(void); /* generic function pointer */
248 """ % (shortname
, shortname
, shortname
, shortname
, shortname
, shortname
);
250 # Finally we get to the all-important functions
251 print """/*************************************************************
252 * Generated functions begin here
255 for funcName
in keys
:
256 if verbose
> 0: sys
.stderr
.write("%s: processing function %s\n" % (program
, funcName
))
258 # start figuring out what this function will look like.
259 returnType
= apiutil
.ReturnType(funcName
)
260 props
= apiutil
.Properties(funcName
)
261 params
= apiutil
.Parameters(funcName
)
262 declarationString
= apiutil
.MakeDeclarationString(params
)
264 # In case of error, a function may have to return. Make
265 # sure we have valid return values in this case.
266 if returnType
== "void":
267 errorReturn
= "return"
268 elif returnType
== "GLboolean":
269 errorReturn
= "return GL_FALSE"
271 errorReturn
= "return (%s) 0" % returnType
273 # These are the output of this large calculation block.
274 # passthroughDeclarationString: a typed set of parameters that
275 # will be used to create the "extern" reference for the
276 # underlying Mesa or support function. Note that as generated
277 # these have an extra ", " at the beginning, which will be
278 # removed before use.
280 # passthroughDeclarationString: an untyped list of parameters
281 # that will be used to call the underlying Mesa or support
282 # function (including references to converted parameters).
283 # This will also be generated with an extra ", " at the
284 # beginning, which will be removed before use.
286 # variables: C code to create any local variables determined to
288 # conversionCodeOutgoing: C code to convert application parameters
289 # to a necessary type before calling the underlying support code.
290 # May be empty if no conversion is required.
291 # conversionCodeIncoming: C code to do the converse: convert
292 # values returned by underlying Mesa code to the types needed
293 # by the application.
294 # Note that *either* the conversionCodeIncoming will be used (for
295 # generated query functions), *or* the conversionCodeOutgoing will
296 # be used (for generated non-query functions), never both.
297 passthroughFuncName
= ""
298 passthroughDeclarationString
= ""
299 passthroughCallString
= ""
300 prefixOverride
= None
302 conversionCodeOutgoing
= []
303 conversionCodeIncoming
= []
306 # Calculate the name of the underlying support function to call.
307 # By default, the passthrough function is named _mesa_<funcName>.
308 # We're allowed to override the prefix and/or the function name
309 # for each function record, though. The "ConversionFunction"
310 # utility is poorly named, BTW...
311 if funcName
in allSpecials
:
312 # perform checks and pass through
313 funcPrefix
= "_check_"
317 aliasprefix
= apiutil
.AliasPrefix(funcName
)
318 alias
= apiutil
.ConversionFunction(funcName
)
319 prefixOverride
= apiutil
.FunctionPrefix(funcName
)
320 if prefixOverride
!= "_mesa_":
321 aliasprefix
= apiutil
.FunctionPrefix(funcName
)
323 # There may still be a Mesa alias for the function
324 if apiutil
.Alias(funcName
):
325 passthroughFuncName
= "%s%s" % (aliasprefix
, apiutil
.Alias(funcName
))
327 passthroughFuncName
= "%s%s" % (aliasprefix
, funcName
)
328 else: # a specific alias is provided
329 passthroughFuncName
= "%s%s" % (aliasprefix
, alias
)
331 # Look at every parameter: each one may have only specific
332 # allowed values, or dependent parameters to check, or
333 # variant-sized vector arrays to calculate
334 for (paramName
, paramType
, paramMaxVecSize
, paramConvertToType
, paramValidValues
, paramValueConversion
) in params
:
335 # We'll need this below if we're doing conversions
336 (paramBaseType
, paramTypeModifiers
) = GetBaseType(paramType
)
338 # Conversion management.
339 # We'll handle three cases, easiest to hardest: a parameter
340 # that doesn't require conversion, a scalar parameter that
341 # requires conversion, and a vector parameter that requires
343 if paramConvertToType
== None:
344 # Unconverted parameters are easy, whether they're vector
345 # or scalar - just add them to the call list. No conversions
346 # or anything to worry about.
347 passthroughDeclarationString
+= ", %s %s" % (paramType
, paramName
)
348 passthroughCallString
+= ", %s" % paramName
350 elif paramMaxVecSize
== 0: # a scalar parameter that needs conversion
351 # A scalar to hold a converted parameter
352 variables
.append(" %s converted_%s;" % (paramConvertToType
, paramName
))
354 # Outgoing conversion depends on whether we have to conditionally
355 # perform value conversion.
356 if paramValueConversion
== "none":
357 conversionCodeOutgoing
.append(" converted_%s = (%s) %s;" % (paramName
, paramConvertToType
, paramName
))
358 elif paramValueConversion
== "some":
359 # We'll need a conditional variable to keep track of
360 # whether we're converting values or not.
361 if (" int convert_%s_value = 1;" % paramName
) not in variables
:
362 variables
.append(" int convert_%s_value = 1;" % paramName
)
364 # Write code based on that conditional.
365 conversionCodeOutgoing
.append(" if (convert_%s_value) {" % paramName
)
366 conversionCodeOutgoing
.append(" converted_%s = %s;" % (paramName
, ConvertValue(paramName
, paramBaseType
, paramConvertToType
)))
367 conversionCodeOutgoing
.append(" } else {")
368 conversionCodeOutgoing
.append(" converted_%s = (%s) %s;" % (paramName
, paramConvertToType
, paramName
))
369 conversionCodeOutgoing
.append(" }")
370 else: # paramValueConversion == "all"
371 conversionCodeOutgoing
.append(" converted_%s = %s;" % (paramName
, ConvertValue(paramName
, paramBaseType
, paramConvertToType
)))
373 # Note that there can be no incoming conversion for a
374 # scalar parameter; changing the scalar will only change
375 # the local value, and won't ultimately change anything
376 # that passes back to the application.
378 # Call strings. The unusual " ".join() call will join the
379 # array of parameter modifiers with spaces as separators.
380 passthroughDeclarationString
+= ", %s %s %s" % (paramConvertToType
, " ".join(paramTypeModifiers
), paramName
)
381 passthroughCallString
+= ", converted_%s" % paramName
383 else: # a vector parameter that needs conversion
384 # We'll need an index variable for conversions
385 if " register unsigned int i;" not in variables
:
386 variables
.append(" register unsigned int i;")
388 # This variable will hold the (possibly variant) size of
389 # this array needing conversion. By default, we'll set
390 # it to the maximal size (which is correct for functions
391 # with a constant-sized vector parameter); for true
392 # variant arrays, we'll modify it with other code.
393 variables
.append(" unsigned int n_%s = %d;" % (paramName
, paramMaxVecSize
))
395 # This array will hold the actual converted values.
396 variables
.append(" %s converted_%s[%d];" % (paramConvertToType
, paramName
, paramMaxVecSize
))
398 # Again, we choose the conversion code based on whether we
399 # have to always convert values, never convert values, or
400 # conditionally convert values.
401 if paramValueConversion
== "none":
402 conversionCodeOutgoing
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
403 conversionCodeOutgoing
.append(" converted_%s[i] = (%s) %s[i];" % (paramName
, paramConvertToType
, paramName
))
404 conversionCodeOutgoing
.append(" }")
405 elif paramValueConversion
== "some":
406 # We'll need a conditional variable to keep track of
407 # whether we're converting values or not.
408 if (" int convert_%s_value = 1;" % paramName
) not in variables
:
409 variables
.append(" int convert_%s_value = 1;" % paramName
)
410 # Write code based on that conditional.
411 conversionCodeOutgoing
.append(" if (convert_%s_value) {" % paramName
)
412 conversionCodeOutgoing
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
413 conversionCodeOutgoing
.append(" converted_%s[i] = %s;" % (paramName
, ConvertValue("%s[i]" % paramName
, paramBaseType
, paramConvertToType
)))
414 conversionCodeOutgoing
.append(" }")
415 conversionCodeOutgoing
.append(" } else {")
416 conversionCodeOutgoing
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
417 conversionCodeOutgoing
.append(" converted_%s[i] = (%s) %s[i];" % (paramName
, paramConvertToType
, paramName
))
418 conversionCodeOutgoing
.append(" }")
419 conversionCodeOutgoing
.append(" }")
420 else: # paramValueConversion == "all"
421 conversionCodeOutgoing
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
422 conversionCodeOutgoing
.append(" converted_%s[i] = %s;" % (paramName
, ConvertValue("%s[i]" % paramName
, paramBaseType
, paramConvertToType
)))
424 conversionCodeOutgoing
.append(" }")
426 # If instead we need an incoming conversion (i.e. results
427 # from Mesa have to be converted before handing back
428 # to the application), this is it. Fortunately, we don't
429 # have to worry about conditional value conversion - the
430 # functions that do (e.g. glGetFixedv()) are handled
431 # specially, outside this code generation.
433 # Whether we use incoming conversion or outgoing conversion
434 # is determined later - we only ever use one or the other.
436 if paramValueConversion
== "none":
437 conversionCodeIncoming
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
438 conversionCodeIncoming
.append(" %s[i] = (%s) converted_%s[i];" % (paramName
, paramConvertToType
, paramName
))
439 conversionCodeIncoming
.append(" }")
440 elif paramValueConversion
== "some":
441 # We'll need a conditional variable to keep track of
442 # whether we're converting values or not.
443 if (" int convert_%s_value = 1;" % paramName
) not in variables
:
444 variables
.append(" int convert_%s_value = 1;" % paramName
)
446 # Write code based on that conditional.
447 conversionCodeIncoming
.append(" if (convert_%s_value) {" % paramName
)
448 conversionCodeIncoming
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
449 conversionCodeIncoming
.append(" %s[i] = %s;" % (paramName
, ConvertValue("converted_%s[i]" % paramName
, paramConvertToType
, paramBaseType
)))
450 conversionCodeIncoming
.append(" }")
451 conversionCodeIncoming
.append(" } else {")
452 conversionCodeIncoming
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
453 conversionCodeIncoming
.append(" %s[i] = (%s) converted_%s[i];" % (paramName
, paramBaseType
, paramName
))
454 conversionCodeIncoming
.append(" }")
455 conversionCodeIncoming
.append(" }")
456 else: # paramValueConversion == "all"
457 conversionCodeIncoming
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
458 conversionCodeIncoming
.append(" %s[i] = %s;" % (paramName
, ConvertValue("converted_%s[i]" % paramName
, paramConvertToType
, paramBaseType
)))
459 conversionCodeIncoming
.append(" }")
461 # Call strings. The unusual " ".join() call will join the
462 # array of parameter modifiers with spaces as separators.
463 passthroughDeclarationString
+= ", %s %s %s" % (paramConvertToType
, " ".join(paramTypeModifiers
), paramName
)
464 passthroughCallString
+= ", converted_%s" % paramName
466 # endif conversion management
468 # Parameter checking. If the parameter has a specific list of
469 # valid values, we have to make sure that the passed-in values
470 # match these, or we make an error.
471 if len(paramValidValues
) > 0:
472 # We're about to make a big switch statement with an
473 # error at the end. By default, the error is GL_INVALID_ENUM,
474 # unless we find a "case" statement in the middle with a
476 errorDefaultCase
= "GL_INVALID_ENUM"
478 # This parameter has specific valid values. Make a big
479 # switch statement to handle it. Note that the original
480 # parameters are always what is checked, not the
481 # converted parameters.
482 switchCode
.append(" switch(%s) {" % paramName
)
484 for valueIndex
in range(len(paramValidValues
)):
485 (paramValue
, dependentVecSize
, dependentParamName
, dependentValidValues
, errorCode
, valueConvert
) = paramValidValues
[valueIndex
]
487 # We're going to need information on the dependent param
489 if dependentParamName
:
490 depParamIndex
= apiutil
.FindParamIndex(params
, dependentParamName
)
491 if depParamIndex
== None:
492 sys
.stderr
.write("%s: can't find dependent param '%s' for function '%s'\n" % (program
, dependentParamName
, funcName
))
494 (depParamName
, depParamType
, depParamMaxVecSize
, depParamConvertToType
, depParamValidValues
, depParamValueConversion
) = params
[depParamIndex
]
496 (depParamName
, depParamType
, depParamMaxVecSize
, depParamConvertToType
, depParamValidValues
, depParamValueConversion
) = (None, None, None, None, [], None)
498 # This is a sneaky trick. It's valid syntax for a parameter
499 # that is *not* going to be converted to be declared
500 # with a dependent vector size; but in this case, the
501 # dependent vector size is unused and unnecessary.
502 # So check for this and ignore the dependent vector size
503 # if the parameter is not going to be converted.
504 if depParamConvertToType
:
505 usedDependentVecSize
= dependentVecSize
507 usedDependentVecSize
= None
509 # We'll peek ahead at the next parameter, to see whether
510 # we can combine cases
511 if valueIndex
+ 1 < len(paramValidValues
) :
512 (nextParamValue
, nextDependentVecSize
, nextDependentParamName
, nextDependentValidValues
, nextErrorCode
, nextValueConvert
) = paramValidValues
[valueIndex
+ 1]
513 if depParamConvertToType
:
514 usedNextDependentVecSize
= nextDependentVecSize
516 usedNextDependentVecSize
= None
518 # Create a case for this value. As a mnemonic,
519 # if we have a dependent vector size that we're ignoring,
520 # add it as a comment.
521 if usedDependentVecSize
== None and dependentVecSize
!= None:
522 switchCode
.append(" case %s: /* size %s */" % (paramValue
, dependentVecSize
))
524 switchCode
.append(" case %s:" % paramValue
)
526 # If this is not a GLenum case, then switch our error
527 # if no value is matched to be GL_INVALID_VALUE instead
528 # of GL_INVALID_ENUM. (Yes, this does get confused
529 # if there are both values and GLenums in the same
530 # switch statement, which shouldn't happen.)
531 if paramValue
[0:3] != "GL_":
532 errorDefaultCase
= "GL_INVALID_VALUE"
534 # If all the remaining parameters are identical to the
535 # next set, then we're done - we'll just create the
536 # official code on the next pass through, and the two
537 # cases will share the code.
538 if valueIndex
+ 1 < len(paramValidValues
) and usedDependentVecSize
== usedNextDependentVecSize
and dependentParamName
== nextDependentParamName
and dependentValidValues
== nextDependentValidValues
and errorCode
== nextErrorCode
and valueConvert
== nextValueConvert
:
541 # Otherwise, we'll have to generate code for this case.
542 # Start off with a check: if there is a dependent parameter,
543 # and a list of valid values for that parameter, we need
544 # to generate an error if something other than one
545 # of those values is passed.
546 if len(dependentValidValues
) > 0:
549 # If the parameter being checked is actually an array,
550 # check only its first element.
551 if depParamMaxVecSize
== 0:
552 valueToCheck
= dependentParamName
554 valueToCheck
= "%s[0]" % dependentParamName
556 for v
in dependentValidValues
:
557 conditional
+= " && %s != %s" % (valueToCheck
, v
)
558 switchCode
.append(" if (%s) {" % conditional
[4:])
559 if errorCode
== None:
560 errorCode
= "GL_INVALID_ENUM"
561 switchCode
.append(' _mesa_error(_mesa_get_current_context(), %s, "gl%s(%s=0x%s)", %s);' % (errorCode
, funcName
, paramName
, "%x", paramName
))
562 switchCode
.append(" %s;" % errorReturn
)
563 switchCode
.append(" }")
564 # endif there are dependent valid values
566 # The dependent parameter may require conditional
567 # value conversion. If it does, and we don't want
568 # to convert values, we'll have to generate code for that
569 if depParamValueConversion
== "some" and valueConvert
== "noconvert":
570 switchCode
.append(" convert_%s_value = 0;" % dependentParamName
)
572 # If there's a dependent vector size for this parameter
573 # that we're actually going to use (i.e. we need conversion),
575 if usedDependentVecSize
:
576 switchCode
.append(" n_%s = %s;" % (dependentParamName
, dependentVecSize
))
578 # In all cases, break out of the switch if any valid
580 switchCode
.append(" break;")
583 # Need a default case to catch all the other, invalid
584 # parameter values. These will all generate errors.
585 switchCode
.append(" default:")
586 if errorCode
== None:
587 errorCode
= "GL_INVALID_ENUM"
588 formatString
= GetFormatString(paramType
)
589 if formatString
== None:
590 switchCode
.append(' _mesa_error(_mesa_get_current_context(), %s, "gl%s(%s)");' % (errorCode
, funcName
, paramName
))
592 switchCode
.append(' _mesa_error(_mesa_get_current_context(), %s, "gl%s(%s=%s)", %s);' % (errorCode
, funcName
, paramName
, formatString
, paramName
))
593 switchCode
.append(" %s;" % errorReturn
)
595 # End of our switch code.
596 switchCode
.append(" }")
598 # endfor every recognized parameter value
602 # Here, the passthroughDeclarationString and passthroughCallString
603 # are complete; remove the extra ", " at the front of each.
604 passthroughDeclarationString
= passthroughDeclarationString
[2:]
605 passthroughCallString
= passthroughCallString
[2:]
607 # The Mesa functions are scattered across all the Mesa
608 # header files. The easiest way to manage declarations
609 # is to create them ourselves.
610 if funcName
in allSpecials
:
611 print "/* this function is special and is defined elsewhere */"
612 print "extern %s GLAPIENTRY %s(%s);" % (returnType
, passthroughFuncName
, passthroughDeclarationString
)
614 # A function may be a core function (i.e. it exists in
615 # the core specification), a core addition (extension
616 # functions added officially to the core), a required
617 # extension (usually an extension for an earlier version
618 # that has been officially adopted), or an optional extension.
620 # Core functions have a simple category (e.g. "GLES1.1");
621 # we generate only a simple callback for them.
623 # Core additions have two category listings, one simple
624 # and one compound (e.g. ["GLES1.1", "GLES1.1:OES_fixed_point"]).
625 # We generate the core function, and also an extension function.
627 # Required extensions and implemented optional extensions
628 # have a single compound category "GLES1.1:OES_point_size_array".
629 # For these we generate just the extension function.
630 for categorySpec
in apiutil
.Categories(funcName
):
631 compoundCategory
= categorySpec
.split(":")
633 # This category isn't for us, if the base category doesn't match
635 if compoundCategory
[0] != version
:
638 # Otherwise, determine if we're writing code for a core
639 # function (no suffix) or an extension function.
640 if len(compoundCategory
) == 1:
641 # This is a core function
645 # This is an extension function. We'll need to append
646 # the extension suffix.
647 extensionName
= compoundCategory
[1]
648 extensionSuffix
= extensionName
.split("_")[0]
649 fullFuncName
= funcPrefix
+ funcName
+ extensionSuffix
651 # Now the generated function. The text used to mark an API-level
652 # function, oddly, is version-specific.
654 print "/* Extension %s */" % extensionName
656 if (not variables
and
658 not conversionCodeOutgoing
and
659 not conversionCodeIncoming
):
660 # pass through directly
661 print "#define %s %s" % (fullFuncName
, passthroughFuncName
)
665 print "static %s %s(%s)" % (returnType
, fullFuncName
, declarationString
)
668 # Start printing our code pieces. Start with any local
669 # variables we need. This unusual syntax joins the
670 # lines in the variables[] array with the "\n" separator.
671 if len(variables
) > 0:
672 print "\n".join(variables
) + "\n"
674 # If there's any sort of parameter checking or variable
675 # array sizing, the switch code will contain it.
676 if len(switchCode
) > 0:
677 print "\n".join(switchCode
) + "\n"
679 # In the case of an outgoing conversion (i.e. parameters must
680 # be converted before calling the underlying Mesa function),
681 # use the appropriate code.
682 if "get" not in props
and len(conversionCodeOutgoing
) > 0:
683 print "\n".join(conversionCodeOutgoing
) + "\n"
685 # Call the Mesa function. Note that there are very few functions
686 # that return a value (i.e. returnType is not "void"), and that
687 # none of them require incoming translation; so we're safe
688 # to generate code that directly returns in those cases,
689 # even though it's not completely independent.
691 if returnType
== "void":
692 print " %s(%s);" % (passthroughFuncName
, passthroughCallString
)
694 print " return %s(%s);" % (passthroughFuncName
, passthroughCallString
)
696 # If the function is one that returns values (i.e. "get" in props),
697 # it might return values of a different type than we need, that
698 # require conversion before passing back to the application.
699 if "get" in props
and len(conversionCodeIncoming
) > 0:
700 print "\n".join(conversionCodeIncoming
)
705 # end for each category provided for a function
707 # end for each function
710 struct _glapi_table *
711 _mesa_create_exec_table_%s(void)
713 struct _glapi_table *exec;
714 exec = _mesa_alloc_dispatch_table(sizeof *exec);
721 prefix
= "_es_" if func
not in allSpecials
else "_check_"
722 for spec
in apiutil
.Categories(func
):
723 ext
= spec
.split(":")
724 # version does not match
725 if ext
.pop(0) != version
:
729 suffix
= ext
[0].split("_")[0]
731 print " SET_%s(exec, %s%s);" % (entry
, prefix
, entry
)
733 print " return exec;"
737 #endif /* FEATURE_%s */""" % (shortname
.upper())