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 #if FEATURE_remap_table
214 #include "main/remap.h"
217 #define _GLAPI_USE_REMAP_TABLE
220 #define need_MESA_remap_table
221 #include "main/remap_helper.h"
224 _mesa_init_remap_table(void)
226 _mesa_do_init_remap_table(_mesa_function_pool,
227 driDispatchRemapTable_size,
228 MESA_remap_table_functions);
232 _mesa_map_static_functions(void)
238 typedef void (*_glapi_proc)(void); /* generic function pointer */
241 # Finally we get to the all-important functions
242 print """/*************************************************************
243 * Generated functions begin here
246 for funcName
in keys
:
247 if verbose
> 0: sys
.stderr
.write("%s: processing function %s\n" % (program
, funcName
))
249 # start figuring out what this function will look like.
250 returnType
= apiutil
.ReturnType(funcName
)
251 props
= apiutil
.Properties(funcName
)
252 params
= apiutil
.Parameters(funcName
)
253 declarationString
= apiutil
.MakeDeclarationString(params
)
255 # In case of error, a function may have to return. Make
256 # sure we have valid return values in this case.
257 if returnType
== "void":
258 errorReturn
= "return"
259 elif returnType
== "GLboolean":
260 errorReturn
= "return GL_FALSE"
262 errorReturn
= "return (%s) 0" % returnType
264 # These are the output of this large calculation block.
265 # passthroughDeclarationString: a typed set of parameters that
266 # will be used to create the "extern" reference for the
267 # underlying Mesa or support function. Note that as generated
268 # these have an extra ", " at the beginning, which will be
269 # removed before use.
271 # passthroughDeclarationString: an untyped list of parameters
272 # that will be used to call the underlying Mesa or support
273 # function (including references to converted parameters).
274 # This will also be generated with an extra ", " at the
275 # beginning, which will be removed before use.
277 # variables: C code to create any local variables determined to
279 # conversionCodeOutgoing: C code to convert application parameters
280 # to a necessary type before calling the underlying support code.
281 # May be empty if no conversion is required.
282 # conversionCodeIncoming: C code to do the converse: convert
283 # values returned by underlying Mesa code to the types needed
284 # by the application.
285 # Note that *either* the conversionCodeIncoming will be used (for
286 # generated query functions), *or* the conversionCodeOutgoing will
287 # be used (for generated non-query functions), never both.
288 passthroughFuncName
= ""
289 passthroughDeclarationString
= ""
290 passthroughCallString
= ""
292 conversionCodeOutgoing
= []
293 conversionCodeIncoming
= []
296 # Calculate the name of the underlying support function to call.
297 # By default, the passthrough function is named _mesa_<funcName>.
298 # We're allowed to override the prefix and/or the function name
299 # for each function record, though. The "ConversionFunction"
300 # utility is poorly named, BTW...
301 if funcName
in allSpecials
:
302 # perform checks and pass through
303 funcPrefix
= "_check_"
307 aliasprefix
= apiutil
.AliasPrefix(funcName
)
308 alias
= apiutil
.ConversionFunction(funcName
)
310 # There may still be a Mesa alias for the function
311 if apiutil
.Alias(funcName
):
312 passthroughFuncName
= "%s%s" % (aliasprefix
, apiutil
.Alias(funcName
))
314 passthroughFuncName
= "%s%s" % (aliasprefix
, funcName
)
315 else: # a specific alias is provided
316 passthroughFuncName
= "%s%s" % (aliasprefix
, alias
)
318 # Look at every parameter: each one may have only specific
319 # allowed values, or dependent parameters to check, or
320 # variant-sized vector arrays to calculate
321 for (paramName
, paramType
, paramMaxVecSize
, paramConvertToType
, paramValidValues
, paramValueConversion
) in params
:
322 # We'll need this below if we're doing conversions
323 (paramBaseType
, paramTypeModifiers
) = GetBaseType(paramType
)
325 # Conversion management.
326 # We'll handle three cases, easiest to hardest: a parameter
327 # that doesn't require conversion, a scalar parameter that
328 # requires conversion, and a vector parameter that requires
330 if paramConvertToType
== None:
331 # Unconverted parameters are easy, whether they're vector
332 # or scalar - just add them to the call list. No conversions
333 # or anything to worry about.
334 passthroughDeclarationString
+= ", %s %s" % (paramType
, paramName
)
335 passthroughCallString
+= ", %s" % paramName
337 elif paramMaxVecSize
== 0: # a scalar parameter that needs conversion
338 # A scalar to hold a converted parameter
339 variables
.append(" %s converted_%s;" % (paramConvertToType
, paramName
))
341 # Outgoing conversion depends on whether we have to conditionally
342 # perform value conversion.
343 if paramValueConversion
== "none":
344 conversionCodeOutgoing
.append(" converted_%s = (%s) %s;" % (paramName
, paramConvertToType
, paramName
))
345 elif paramValueConversion
== "some":
346 # We'll need a conditional variable to keep track of
347 # whether we're converting values or not.
348 if (" int convert_%s_value = 1;" % paramName
) not in variables
:
349 variables
.append(" int convert_%s_value = 1;" % paramName
)
351 # Write code based on that conditional.
352 conversionCodeOutgoing
.append(" if (convert_%s_value) {" % paramName
)
353 conversionCodeOutgoing
.append(" converted_%s = %s;" % (paramName
, ConvertValue(paramName
, paramBaseType
, paramConvertToType
)))
354 conversionCodeOutgoing
.append(" } else {")
355 conversionCodeOutgoing
.append(" converted_%s = (%s) %s;" % (paramName
, paramConvertToType
, paramName
))
356 conversionCodeOutgoing
.append(" }")
357 else: # paramValueConversion == "all"
358 conversionCodeOutgoing
.append(" converted_%s = %s;" % (paramName
, ConvertValue(paramName
, paramBaseType
, paramConvertToType
)))
360 # Note that there can be no incoming conversion for a
361 # scalar parameter; changing the scalar will only change
362 # the local value, and won't ultimately change anything
363 # that passes back to the application.
365 # Call strings. The unusual " ".join() call will join the
366 # array of parameter modifiers with spaces as separators.
367 passthroughDeclarationString
+= ", %s %s %s" % (paramConvertToType
, " ".join(paramTypeModifiers
), paramName
)
368 passthroughCallString
+= ", converted_%s" % paramName
370 else: # a vector parameter that needs conversion
371 # We'll need an index variable for conversions
372 if " register unsigned int i;" not in variables
:
373 variables
.append(" register unsigned int i;")
375 # This variable will hold the (possibly variant) size of
376 # this array needing conversion. By default, we'll set
377 # it to the maximal size (which is correct for functions
378 # with a constant-sized vector parameter); for true
379 # variant arrays, we'll modify it with other code.
380 variables
.append(" unsigned int n_%s = %d;" % (paramName
, paramMaxVecSize
))
382 # This array will hold the actual converted values.
383 variables
.append(" %s converted_%s[%d];" % (paramConvertToType
, paramName
, paramMaxVecSize
))
385 # Again, we choose the conversion code based on whether we
386 # have to always convert values, never convert values, or
387 # conditionally convert values.
388 if paramValueConversion
== "none":
389 conversionCodeOutgoing
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
390 conversionCodeOutgoing
.append(" converted_%s[i] = (%s) %s[i];" % (paramName
, paramConvertToType
, paramName
))
391 conversionCodeOutgoing
.append(" }")
392 elif paramValueConversion
== "some":
393 # We'll need a conditional variable to keep track of
394 # whether we're converting values or not.
395 if (" int convert_%s_value = 1;" % paramName
) not in variables
:
396 variables
.append(" int convert_%s_value = 1;" % paramName
)
397 # Write code based on that conditional.
398 conversionCodeOutgoing
.append(" if (convert_%s_value) {" % paramName
)
399 conversionCodeOutgoing
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
400 conversionCodeOutgoing
.append(" converted_%s[i] = %s;" % (paramName
, ConvertValue("%s[i]" % paramName
, paramBaseType
, paramConvertToType
)))
401 conversionCodeOutgoing
.append(" }")
402 conversionCodeOutgoing
.append(" } else {")
403 conversionCodeOutgoing
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
404 conversionCodeOutgoing
.append(" converted_%s[i] = (%s) %s[i];" % (paramName
, paramConvertToType
, paramName
))
405 conversionCodeOutgoing
.append(" }")
406 conversionCodeOutgoing
.append(" }")
407 else: # paramValueConversion == "all"
408 conversionCodeOutgoing
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
409 conversionCodeOutgoing
.append(" converted_%s[i] = %s;" % (paramName
, ConvertValue("%s[i]" % paramName
, paramBaseType
, paramConvertToType
)))
411 conversionCodeOutgoing
.append(" }")
413 # If instead we need an incoming conversion (i.e. results
414 # from Mesa have to be converted before handing back
415 # to the application), this is it. Fortunately, we don't
416 # have to worry about conditional value conversion - the
417 # functions that do (e.g. glGetFixedv()) are handled
418 # specially, outside this code generation.
420 # Whether we use incoming conversion or outgoing conversion
421 # is determined later - we only ever use one or the other.
423 if paramValueConversion
== "none":
424 conversionCodeIncoming
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
425 conversionCodeIncoming
.append(" %s[i] = (%s) converted_%s[i];" % (paramName
, paramConvertToType
, paramName
))
426 conversionCodeIncoming
.append(" }")
427 elif paramValueConversion
== "some":
428 # We'll need a conditional variable to keep track of
429 # whether we're converting values or not.
430 if (" int convert_%s_value = 1;" % paramName
) not in variables
:
431 variables
.append(" int convert_%s_value = 1;" % paramName
)
433 # Write code based on that conditional.
434 conversionCodeIncoming
.append(" if (convert_%s_value) {" % paramName
)
435 conversionCodeIncoming
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
436 conversionCodeIncoming
.append(" %s[i] = %s;" % (paramName
, ConvertValue("converted_%s[i]" % paramName
, paramConvertToType
, paramBaseType
)))
437 conversionCodeIncoming
.append(" }")
438 conversionCodeIncoming
.append(" } else {")
439 conversionCodeIncoming
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
440 conversionCodeIncoming
.append(" %s[i] = (%s) converted_%s[i];" % (paramName
, paramBaseType
, paramName
))
441 conversionCodeIncoming
.append(" }")
442 conversionCodeIncoming
.append(" }")
443 else: # paramValueConversion == "all"
444 conversionCodeIncoming
.append(" for (i = 0; i < n_%s; i++) {" % paramName
)
445 conversionCodeIncoming
.append(" %s[i] = %s;" % (paramName
, ConvertValue("converted_%s[i]" % paramName
, paramConvertToType
, paramBaseType
)))
446 conversionCodeIncoming
.append(" }")
448 # Call strings. The unusual " ".join() call will join the
449 # array of parameter modifiers with spaces as separators.
450 passthroughDeclarationString
+= ", %s %s %s" % (paramConvertToType
, " ".join(paramTypeModifiers
), paramName
)
451 passthroughCallString
+= ", converted_%s" % paramName
453 # endif conversion management
455 # Parameter checking. If the parameter has a specific list of
456 # valid values, we have to make sure that the passed-in values
457 # match these, or we make an error.
458 if len(paramValidValues
) > 0:
459 # We're about to make a big switch statement with an
460 # error at the end. By default, the error is GL_INVALID_ENUM,
461 # unless we find a "case" statement in the middle with a
463 errorDefaultCase
= "GL_INVALID_ENUM"
465 # This parameter has specific valid values. Make a big
466 # switch statement to handle it. Note that the original
467 # parameters are always what is checked, not the
468 # converted parameters.
469 switchCode
.append(" switch(%s) {" % paramName
)
471 for valueIndex
in range(len(paramValidValues
)):
472 (paramValue
, dependentVecSize
, dependentParamName
, dependentValidValues
, errorCode
, valueConvert
) = paramValidValues
[valueIndex
]
474 # We're going to need information on the dependent param
476 if dependentParamName
:
477 depParamIndex
= apiutil
.FindParamIndex(params
, dependentParamName
)
478 if depParamIndex
== None:
479 sys
.stderr
.write("%s: can't find dependent param '%s' for function '%s'\n" % (program
, dependentParamName
, funcName
))
481 (depParamName
, depParamType
, depParamMaxVecSize
, depParamConvertToType
, depParamValidValues
, depParamValueConversion
) = params
[depParamIndex
]
483 (depParamName
, depParamType
, depParamMaxVecSize
, depParamConvertToType
, depParamValidValues
, depParamValueConversion
) = (None, None, None, None, [], None)
485 # This is a sneaky trick. It's valid syntax for a parameter
486 # that is *not* going to be converted to be declared
487 # with a dependent vector size; but in this case, the
488 # dependent vector size is unused and unnecessary.
489 # So check for this and ignore the dependent vector size
490 # if the parameter is not going to be converted.
491 if depParamConvertToType
:
492 usedDependentVecSize
= dependentVecSize
494 usedDependentVecSize
= None
496 # We'll peek ahead at the next parameter, to see whether
497 # we can combine cases
498 if valueIndex
+ 1 < len(paramValidValues
) :
499 (nextParamValue
, nextDependentVecSize
, nextDependentParamName
, nextDependentValidValues
, nextErrorCode
, nextValueConvert
) = paramValidValues
[valueIndex
+ 1]
500 if depParamConvertToType
:
501 usedNextDependentVecSize
= nextDependentVecSize
503 usedNextDependentVecSize
= None
505 # Create a case for this value. As a mnemonic,
506 # if we have a dependent vector size that we're ignoring,
507 # add it as a comment.
508 if usedDependentVecSize
== None and dependentVecSize
!= None:
509 switchCode
.append(" case %s: /* size %s */" % (paramValue
, dependentVecSize
))
511 switchCode
.append(" case %s:" % paramValue
)
513 # If this is not a GLenum case, then switch our error
514 # if no value is matched to be GL_INVALID_VALUE instead
515 # of GL_INVALID_ENUM. (Yes, this does get confused
516 # if there are both values and GLenums in the same
517 # switch statement, which shouldn't happen.)
518 if paramValue
[0:3] != "GL_":
519 errorDefaultCase
= "GL_INVALID_VALUE"
521 # If all the remaining parameters are identical to the
522 # next set, then we're done - we'll just create the
523 # official code on the next pass through, and the two
524 # cases will share the code.
525 if valueIndex
+ 1 < len(paramValidValues
) and usedDependentVecSize
== usedNextDependentVecSize
and dependentParamName
== nextDependentParamName
and dependentValidValues
== nextDependentValidValues
and errorCode
== nextErrorCode
and valueConvert
== nextValueConvert
:
528 # Otherwise, we'll have to generate code for this case.
529 # Start off with a check: if there is a dependent parameter,
530 # and a list of valid values for that parameter, we need
531 # to generate an error if something other than one
532 # of those values is passed.
533 if len(dependentValidValues
) > 0:
536 # If the parameter being checked is actually an array,
537 # check only its first element.
538 if depParamMaxVecSize
== 0:
539 valueToCheck
= dependentParamName
541 valueToCheck
= "%s[0]" % dependentParamName
543 for v
in dependentValidValues
:
544 conditional
+= " && %s != %s" % (valueToCheck
, v
)
545 switchCode
.append(" if (%s) {" % conditional
[4:])
546 if errorCode
== None:
547 errorCode
= "GL_INVALID_ENUM"
548 switchCode
.append(' _mesa_error(_mesa_get_current_context(), %s, "gl%s(%s=0x%s)", %s);' % (errorCode
, funcName
, paramName
, "%x", paramName
))
549 switchCode
.append(" %s;" % errorReturn
)
550 switchCode
.append(" }")
551 # endif there are dependent valid values
553 # The dependent parameter may require conditional
554 # value conversion. If it does, and we don't want
555 # to convert values, we'll have to generate code for that
556 if depParamValueConversion
== "some" and valueConvert
== "noconvert":
557 switchCode
.append(" convert_%s_value = 0;" % dependentParamName
)
559 # If there's a dependent vector size for this parameter
560 # that we're actually going to use (i.e. we need conversion),
562 if usedDependentVecSize
:
563 switchCode
.append(" n_%s = %s;" % (dependentParamName
, dependentVecSize
))
565 # In all cases, break out of the switch if any valid
567 switchCode
.append(" break;")
570 # Need a default case to catch all the other, invalid
571 # parameter values. These will all generate errors.
572 switchCode
.append(" default:")
573 if errorCode
== None:
574 errorCode
= "GL_INVALID_ENUM"
575 formatString
= GetFormatString(paramType
)
576 if formatString
== None:
577 switchCode
.append(' _mesa_error(_mesa_get_current_context(), %s, "gl%s(%s)");' % (errorCode
, funcName
, paramName
))
579 switchCode
.append(' _mesa_error(_mesa_get_current_context(), %s, "gl%s(%s=%s)", %s);' % (errorCode
, funcName
, paramName
, formatString
, paramName
))
580 switchCode
.append(" %s;" % errorReturn
)
582 # End of our switch code.
583 switchCode
.append(" }")
585 # endfor every recognized parameter value
589 # Here, the passthroughDeclarationString and passthroughCallString
590 # are complete; remove the extra ", " at the front of each.
591 passthroughDeclarationString
= passthroughDeclarationString
[2:]
592 passthroughCallString
= passthroughCallString
[2:]
594 # The Mesa functions are scattered across all the Mesa
595 # header files. The easiest way to manage declarations
596 # is to create them ourselves.
597 if funcName
in allSpecials
:
598 print "/* this function is special and is defined elsewhere */"
599 print "extern %s GLAPIENTRY %s(%s);" % (returnType
, passthroughFuncName
, passthroughDeclarationString
)
601 # A function may be a core function (i.e. it exists in
602 # the core specification), a core addition (extension
603 # functions added officially to the core), a required
604 # extension (usually an extension for an earlier version
605 # that has been officially adopted), or an optional extension.
607 # Core functions have a simple category (e.g. "GLES1.1");
608 # we generate only a simple callback for them.
610 # Core additions have two category listings, one simple
611 # and one compound (e.g. ["GLES1.1", "GLES1.1:OES_fixed_point"]).
612 # We generate the core function, and also an extension function.
614 # Required extensions and implemented optional extensions
615 # have a single compound category "GLES1.1:OES_point_size_array".
616 # For these we generate just the extension function.
617 for categorySpec
in apiutil
.Categories(funcName
):
618 compoundCategory
= categorySpec
.split(":")
620 # This category isn't for us, if the base category doesn't match
622 if compoundCategory
[0] != version
:
625 # Otherwise, determine if we're writing code for a core
626 # function (no suffix) or an extension function.
627 if len(compoundCategory
) == 1:
628 # This is a core function
632 # This is an extension function. We'll need to append
633 # the extension suffix.
634 extensionName
= compoundCategory
[1]
635 extensionSuffix
= extensionName
.split("_")[0]
636 fullFuncName
= funcPrefix
+ funcName
+ extensionSuffix
638 # Now the generated function. The text used to mark an API-level
639 # function, oddly, is version-specific.
641 print "/* Extension %s */" % extensionName
643 if (not variables
and
645 not conversionCodeOutgoing
and
646 not conversionCodeIncoming
):
647 # pass through directly
648 print "#define %s %s" % (fullFuncName
, passthroughFuncName
)
652 print "static %s %s(%s)" % (returnType
, fullFuncName
, declarationString
)
655 # Start printing our code pieces. Start with any local
656 # variables we need. This unusual syntax joins the
657 # lines in the variables[] array with the "\n" separator.
658 if len(variables
) > 0:
659 print "\n".join(variables
) + "\n"
661 # If there's any sort of parameter checking or variable
662 # array sizing, the switch code will contain it.
663 if len(switchCode
) > 0:
664 print "\n".join(switchCode
) + "\n"
666 # In the case of an outgoing conversion (i.e. parameters must
667 # be converted before calling the underlying Mesa function),
668 # use the appropriate code.
669 if "get" not in props
and len(conversionCodeOutgoing
) > 0:
670 print "\n".join(conversionCodeOutgoing
) + "\n"
672 # Call the Mesa function. Note that there are very few functions
673 # that return a value (i.e. returnType is not "void"), and that
674 # none of them require incoming translation; so we're safe
675 # to generate code that directly returns in those cases,
676 # even though it's not completely independent.
678 if returnType
== "void":
679 print " %s(%s);" % (passthroughFuncName
, passthroughCallString
)
681 print " return %s(%s);" % (passthroughFuncName
, passthroughCallString
)
683 # If the function is one that returns values (i.e. "get" in props),
684 # it might return values of a different type than we need, that
685 # require conversion before passing back to the application.
686 if "get" in props
and len(conversionCodeIncoming
) > 0:
687 print "\n".join(conversionCodeIncoming
)
692 # end for each category provided for a function
694 # end for each function
696 print "struct _glapi_table *"
697 print "_mesa_create_exec_table(void)"
699 print " struct _glapi_table *exec;"
700 print " exec = _mesa_alloc_dispatch_table(sizeof *exec);"
701 print " if (exec == NULL)"
702 print " return NULL;"
706 prefix
= "_es_" if func
not in allSpecials
else "_check_"
707 for spec
in apiutil
.Categories(func
):
708 ext
= spec
.split(":")
709 # version does not match
710 if ext
.pop(0) != version
:
714 suffix
= ext
[0].split("_")[0]
716 print " SET_%s(exec, %s%s);" % (entry
, prefix
, entry
)
718 print " return exec;"