import sys, os
-import apiutil
+import APIspecutil as apiutil
# These dictionary entries are used for automatic conversion.
# The string will be used as a format string with the conversion
conversionString = Converters[fromType][toType]
return conversionString % value
-def GetLoopSizeExpression(funcName, paramName, paramMaxVecSize):
- # The VariantArrays() list will have all the information (for all
- # parameters) on how to calculate variant array sizes.
- variantArrays = apiutil.VariantArrays(funcName)
- defaultSize = paramMaxVecSize
- loopSizeExpression = ''
-
- # There can be many different entries in the variantArrays for the
- # same parameter. We have to look at all of them and pick out the
- # ones of interest.
- for (variantName, variantSize, controllingParam, controllingValues) in variantArrays:
- if paramName == variantName:
- # This variant specification applies to us. It may be of
- # the form "param size default", meaning that the value should
- # replace the default size, or it may be
- # "param size controlParam value...", in which case the size should
- # be used if the controlParam has any one of the given values.
- if len(controllingValues) == 0:
- defaultSize = variantSize
- else:
- # Create a compound conditional that expresses
- # all the possible values in the list
- conditional = ''
- for value in controllingValues:
- if len(conditional) > 0:
- conditional = conditional + " || "
- conditional = conditional + "%s == %s" % (controllingParam, value)
-
- # Add the possibly compound conditional and
- # the associated vector size to the
- # loop control expression
- loopSizeExpression = loopSizeExpression + "(%s) ? %s : " % (conditional, variantSize)
-
- # end if the name matches
- # end for the list of all variant array declarations
-
- # Return the expression that returns the actual size of the
- # array. Note that 'loopSizeExpression' will already have a
- # trailing ": " if it is nonempty.
- if len(loopSizeExpression) > 0:
- return "(%s%s)" % (loopSizeExpression, defaultSize)
- else:
- return "%s" % defaultSize
-
FormatStrings = {
'GLenum' : '0x%x',
'GLfloat' : '%f',
# Version-specific values to be used in the main script
# header: which header file to include
# api: what text specifies an API-level function
-# special: the name of the "specials" file
VersionSpecificValues = {
'GLES1.1' : {
'description' : 'GLES1.1 functions',
'header' : 'GLES/gl.h',
'extheader' : 'GLES/glext.h',
- 'special' : 'es1_special',
},
'GLES2.0': {
'description' : 'GLES2.0 functions',
'header' : 'GLES2/gl2.h',
'extheader' : 'GLES2/gl2ext.h',
- 'special' : 'es2_special',
}
}
# error messages.
program = os.path.basename(sys.argv[0])
-# We assume that the directory that the Python script is in also
-# houses the "special" files.
-programDir = os.path.dirname(sys.argv[0])
-
# Set default values
verbose = 0
-functionList = "APIspec.txt"
+functionList = "APIspec.xml"
version = "GLES1.1"
# Allow for command-line switches
# Grab the version-specific items we need to use
versionHeader = VersionSpecificValues[version]['header']
versionExtHeader = VersionSpecificValues[version]['extheader']
-versionSpecial = VersionSpecificValues[version]['special']
-
-# We're probably being invoked from a different directory,
-# so look for the "special" file in the same directory that
-# holds the Python script
-specialFile = os.path.join(programDir, versionSpecial)
-if not os.path.isfile(specialFile):
- sys.stderr.write("%s: can't find special file '%s' for version '%s' - aborting" % (program, specialFile, version))
- sys.exit(1)
-
-allSpecials = apiutil.AllSpecials(specialFile.split("_")[0])
# If we get to here, we're good to go. The "version" parameter
# directs GetDispatchedFunctions to only allow functions from
# GLES1 and GLES2).
keys = apiutil.GetAllFunctions(functionList, version)
+allSpecials = apiutil.AllSpecials()
+
print """/* DO NOT EDIT *************************************************
* THIS FILE AUTOMATICALLY GENERATED BY THE %s SCRIPT
* API specification file: %s
#include "main/compiler.h"
#include "main/api_exec.h"
-#include "glapi/dispatch.h"
+#include "main/dispatch.h"
typedef void (*_glapi_proc)(void); /* generic function pointer */
"""
-# All variant-length arrays in the GLES API are controlled by some
-# selector parameter. Almost all of those are constant length based
-# on the selector parameter (e.g., in glFogfv(), if the "pname"
-# parameter is GL_FOG_COLOR, the "params" array is considered to be
-# 4 floats long; for any other value of "pname", the "params' array
-# is considered to be 1 float long.
-#
-# There are a very few instances where the selector parameter chooses
-# a runtime-determined value:
-# glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS)
-# glGetIntegerv(GL_SHADER_BINARY_FORMATS)
-# plus the glGetBooleanv, glGetFloatv, glGetFixedv counterparts.
-#
-# The number of formats in both cases is not a constant, but is a
-# runtime-determined value (based on the return value of
-# glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS) or
-# glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS).
-#
-# Rather than hard-code some value (and risk memory errors when we
-# overshoot arrays), in these cases we'll use a constant expresssion
-# (e.g. _get_size(GL_NUM_COMPRESSED_TEXTURE_FORMATS)) to get the
-# value of the variant array. Note, though, that in these cases the
-# "vector" parameter should be set to some size large enough to hold
-# all values (and must be set for GLfixed-based conversions, which
-# need it to define an auxiliary array size).
-#
-# Here's the function itself. Although we only need a couple of values,
-# we'll make it general.
-print """
-extern void GLAPIENTRY _mesa_GetIntegerv(GLenum, GLint *);
-static INLINE unsigned int _get_size(GLenum pname)
-{
- /* In case of error, make sure the value returned is 0. */
- GLint value = 0;
- _mesa_GetIntegerv(pname, &value);
- return (unsigned int) value;
-}
-"""
-
# Finally we get to the all-important functions
print """/*************************************************************
* Generated functions begin here
# We're allowed to override the prefix and/or the function name
# for each function record, though. The "ConversionFunction"
# utility is poorly named, BTW...
- aliasprefix = apiutil.AliasPrefix(funcName)
+ if funcName in allSpecials:
+ # perform checks and pass through
+ funcPrefix = "_check_"
+ aliasprefix = "_es_"
+ else:
+ funcPrefix = "_es_"
+ aliasprefix = apiutil.AliasPrefix(funcName)
alias = apiutil.ConversionFunction(funcName)
if not alias:
# There may still be a Mesa alias for the function
# The Mesa functions are scattered across all the Mesa
# header files. The easiest way to manage declarations
# is to create them ourselves.
- if funcName not in allSpecials:
- print "extern %s GLAPIENTRY %s(%s);" % (returnType, passthroughFuncName, passthroughDeclarationString)
+ if funcName in allSpecials:
+ print "/* this function is special and is defined elsewhere */"
+ print "extern %s GLAPIENTRY %s(%s);" % (returnType, passthroughFuncName, passthroughDeclarationString)
# A function may be a core function (i.e. it exists in
# the core specification), a core addition (extension
if len(compoundCategory) == 1:
# This is a core function
extensionName = None
- fullFuncName = "_es_" + funcName
+ extensionSuffix = ""
else:
# This is an extension function. We'll need to append
# the extension suffix.
extensionName = compoundCategory[1]
extensionSuffix = extensionName.split("_")[0]
- fullFuncName = "_es_" + funcName + extensionSuffix
+ fullFuncName = funcPrefix + funcName + extensionSuffix
# Now the generated function. The text used to mark an API-level
# function, oddly, is version-specific.
if extensionName:
print "/* Extension %s */" % extensionName
- if funcName in allSpecials:
- print "/* this function is special and is defined elsewhere */"
- print "extern %s %s(%s);" % (returnType, fullFuncName, declarationString)
+ if (not variables and
+ not switchCode and
+ not conversionCodeOutgoing and
+ not conversionCodeIncoming):
+ # pass through directly
+ print "#define %s %s" % (fullFuncName, passthroughFuncName)
print
continue
# end for each function
-print "void"
-print "_mesa_init_exec_table(struct _glapi_table *exec)"
+print "struct _glapi_table *"
+print "_mesa_create_exec_table(void)"
print "{"
+print " struct _glapi_table *exec;"
+print " exec = _mesa_alloc_dispatch_table(sizeof *exec);"
+print " if (exec == NULL)"
+print " return NULL;"
+print ""
+
for func in keys:
+ prefix = "_es_" if func not in allSpecials else "_check_"
for spec in apiutil.Categories(func):
ext = spec.split(":")
# version does not match
if ext:
suffix = ext[0].split("_")[0]
entry += suffix
- print " SET_%s(exec, _es_%s);" % (entry, entry)
+ print " SET_%s(exec, %s%s);" % (entry, prefix, entry)
+print ""
+print " return exec;"
print "}"