#
# This file defines a bunch of utility functions for OpenGL API code
# generation.
#======================================================================
def CopyrightC( ):
print """/* Copyright (c) 2001, Stanford University
All rights reserved.
See the file LICENSE.txt for information on redistributing this software. */
"""
def CopyrightDef( ):
print """; Copyright (c) 2001, Stanford University
; All rights reserved.
;
; See the file LICENSE.txt for information on redistributing this software.
"""
#======================================================================
class APIFunction:
"""Class to represent a GL API function (name, return type,
parameters, etc)."""
self.paramaction = []
"""Open the named API spec file and call userFunc(record) for each record
processed."""
if not specFile:
print "Error: couldn't open %s file!" % filename
record = APIFunction()
# split line into tokens
# process the function now
# reset the record
record = APIFunction()
vecSize = 0
enums = []
list = []
vec = []
result = []
if tset == '[':
nlist = []
elif tset == ']':
nlist = []
else:
if result != []:
list = []
else:
break
else:
#endif
#endif
#endfor
#enddef
# Dictionary [name] of APIFunction:
__FunctionDict = {}
# Dictionary [name] of name
__VectorVersion = {}
# Reverse mapping of function name aliases
__ReverseAliases = {}
#if not "omit" in record.chromium:
if not specFile:
# Look for vector aliased functions
if va != '':
#endif
# and look for regular aliases (for glloader)
if a:
__ReverseAliases[a] = func
#endif
#endfor
#endif
return __FunctionDict
"""Return sorted list of all functions known to Chromium."""
d = GetFunctionDict(specFile)
funcs = []
return funcs
"""Return sorted list of all functions known to Chromium."""
d = GetFunctionDict(specFile)
funcs = []
return funcs
"""Return sorted list of all functions handled by SPU dispatch table."""
d = GetFunctionDict(specFile)
funcs = []
return funcs
#======================================================================
"""Return the C return type of named function.
Examples: "void" or "const GLubyte *". """
d = GetFunctionDict()
return d[funcName].returnType
"""Return list of tuples (name, type, vecSize) of function parameters.
Example: if funcName=="ClipPlane" return
[ ("plane", "GLenum", 0), ("equation", "const GLdouble *", 4) ] """
d = GetFunctionDict()
"""Return list of names of actions for testing.
For PackerTest only."""
d = GetFunctionDict()
return d[funcName].paramaction
"""Return list of tuples (name, list of values) of function parameters.
For PackerTest only."""
d = GetFunctionDict()
"""Return list of tuples (name, vector of values) of function parameters.
For PackerTest only."""
d = GetFunctionDict()
"""Return list of tuples (name, list of values) of function parameters.
For PackerTest only."""
d = GetFunctionDict()
"""Return list of properties of the named GL function."""
d = GetFunctionDict()
"""Return list of functions that have the named property."""
funcs = []
for funcName in GetDispatchedFunctions():
return funcs
"""Return the category of the named GL function."""
d = GetFunctionDict()
"""Return list of Chromium-specific properties of the named GL function."""
d = GetFunctionDict()
"""Return list of Chromium-specific properties of the named GL function."""
d = GetFunctionDict()
return d[funcName].chrelopcode
"""Return list of Parameter-specific properties of the named GL function."""
d = GetFunctionDict()
"""Return the function that the named function is an alias of.
Ex: Alias('DrawArraysEXT') = 'DrawArrays'.
"""
d = GetFunctionDict()
"""Like Alias(), but the inverse."""
d = GetFunctionDict()
return __ReverseAliases[funcName]
else:
return ''
"""Return the non-vector version of the given function, or ''.
For example: NonVectorFunction("Color3fv") = "Color3f"."""
d = GetFunctionDict()
return d[funcName].vectoralias
"""Return the vector version of the given non-vector-valued function,
or ''.
For example: VectorVersion("Color3f") = "Color3fv"."""
d = GetFunctionDict()
return __VectorVersion[funcName]
else:
return ''
"""Return a C preprocessor token to test in order to wrap code.
This handles extensions.
Example: GetTestWrapper("glActiveTextureARB") = "CR_multitexture"
Example: GetTestWrapper("glBegin") = ""
"""
if (cat == "1.0" or
cat == "1.1" or
cat == "1.2" or
cat == "Chromium" or
cat == "GL_chromium" or
cat == "VBox"):
return ''
elif (cat == '1.3' or
cat == '1.4' or
cat == '1.5' or
cat == '2.0' or
cat == '2.1'):
# i.e. OpenGL 1.3 or 1.4 or 1.5
else:
assert cat != ''
"""Return 1 if the function can be compiled into display lists, else 0."""
if ("nolist" in props or
"get" in props or
"setclient" in props):
return 0
else:
return 1
"""Return 1 if the function or any alias has any property in the
propertyList"""
if funcAlias:
for p in propertyList:
if p in props:
return 1
return 0
"""Return 1 if the function can be packed, else 0."""
"""Return 1 if the function has a true pack opcode"""
"""Return 1 if the function sets server-side state, else 0."""
# Exceptions. The first set of these functions *do* have
# server-side state-changing effects, but will be missed
# by the general query, because they either render (e.g.
# Bitmap) or do not compile into display lists (e.g. all the others).
#
# The second set do *not* have server-side state-changing
# effects, despite the fact that they do not render
# and can be compiled. They are control functions
# that are not trackable via state.
'RenderMode', 'BindBufferARB', 'DeleteFencesNV']:
return 1
elif funcName in ['ExecuteProgramNV']:
return 0
# All compilable functions that do not render and that do
# not set or use client-side state (e.g. DrawArrays, et al.), set
# server-side state.
if CanCompile(funcName) and "render" not in props and "useclient" not in props and "setclient" not in props:
return 1
# All others don't set server-side state.
return 0
"""Return 1 if the function sets client-side state, else 0."""
if "setclient" in props:
return 1
return 0
"""Return 1 if the function sets state that is tracked by
the state tracker, else 0."""
# These functions set state, but aren't tracked by the state
# tracker for various reasons:
# - because the state tracker doesn't manage display lists
# (e.g. CallList and CallLists)
# - because the client doesn't have information about what
# the server supports, so the function has to go to the
# server (e.g. CompressedTexImage calls)
# - because they require a round-trip to the server (e.g.
# the CopyTexImage calls, SetFenceNV, TrackMatrixNV)
if funcName in [
'CopyTexImage1D', 'CopyTexImage2D',
'CopyTexSubImage1D', 'CopyTexSubImage2D', 'CopyTexSubImage3D',
'CallList', 'CallLists',
'CompressedTexImage1DARB', 'CompressedTexSubImage1DARB',
'CompressedTexImage2DARB', 'CompressedTexSubImage2DARB',
'CompressedTexImage3DARB', 'CompressedTexSubImage3DARB',
'SetFenceNV'
]:
return 0
# Anything else that affects client-side state is trackable.
if SetsClientState(funcName):
return 1
# Anything else that doesn't set state at all is certainly
# not trackable.
return 0
# Per-vertex state isn't tracked the way other state is
# tracked, so it is specifically excluded.
return 0
# Everything else is fine
return 1
"""Return 1 if the function uses client-side state, else 0."""
return 1
return 0
"""Return 1 if the function returns information to the user, else 0."""
if "get" in props:
return 1
return 0
"""Return 1 if the function gets GL state, else 0."""
d = GetFunctionDict()
if "get" in props:
return 1
else:
return 0
"""Determine if the datatype is a pointer. Return 1 or 0."""
return 0
else:
return 1
"""Return the type of a pointer.
Ex: PointerType('const GLubyte *') = 'GLubyte'
"""
if t[0] == "const":
t[0] = t[1]
return t[0]
"""Return the C token for the opcode for the given function."""
"""Return the C token for the extended opcode for the given function."""
#======================================================================
"""Given a list of (name, type, vectorSize) parameters, make a C-style
formal parameter string.
Ex return: 'index, x, y, z'.
"""
result = ''
i = 1
if i < n:
i += 1
#endfor
return result
#enddef
"""Given a list of (name, type, vectorSize) parameters, make a C-style
parameter declaration string.
Ex return: 'GLuint index, GLfloat x, GLfloat y, GLfloat z'.
"""
if n == 0:
return 'void'
else:
result = ''
i = 1
if i < n:
i += 1
#endfor
return result
#endif
#enddef
"""Same as MakeDeclarationString, but adds a context macro
"""
if n == 0:
return ctx_macro_prefix + '_ARGSINGLEDECL'
else:
#endif
#enddef
"""Given a list of (name, type, vectorSize) parameters, make a C-style
parameter prototype string (types only).
Ex return: 'GLuint, GLfloat, GLfloat, GLfloat'.
"""
if n == 0:
return 'void'
else:
result = ''
i = 1
# see if we need a comma separator
if i < n:
i += 1
#endfor
return result
#endif
#enddef
#======================================================================
__lengths = {
'GLbyte': 1,
'GLubyte': 1,
'GLshort': 2,
'GLushort': 2,
'GLint': 4,
'GLuint': 4,
'GLfloat': 4,
'GLclampf': 4,
'GLdouble': 8,
'GLclampd': 8,
'GLenum': 4,
'GLboolean': 1,
'GLsizei': 4,
'GLbitfield': 4,
'void': 0, # XXX why?
'int': 4,
'GLintptrARB': 4, # XXX or 8 bytes?
'GLsizeiptrARB': 4, # XXX or 8 bytes?
'VBoxGLhandleARB': 4,
'GLcharARB': 1,
'uintptr_t': 4
}
"""Return size of C datatype, in bytes."""
#======================================================================
# if we want double-alignment take word-alignment instead,
# yes, this is super-lame, but we know what we are doing
if alignment > 4:
alignment = 4
return pos
def PointerSize():
return 8 # Leave room for a 64 bit pointer
len = 0
size = PointerSize()
else:
return len
#======================================================================
__specials = {}
table = {}
try:
except:
# try:
# except:
# __specials[filename] = {}
# print "%s not present" % filename
# return {}
continue
return table
table = {}
try:
except KeyError:
try:
return 1
else:
return 0 #should never happen
except KeyError:
return 0
table = {}
try:
except KeyError:
return keys
table = {}
try:
except KeyError:
return ret
table = {}
try:
except KeyError:
prefix = "cr"
else:
prefix = "gl"
#ProcessSpecFile("APIspec.txt", PrintRecord)