diff options
Diffstat (limited to 'src/mesa/glapi/gltable.py')
-rw-r--r-- | src/mesa/glapi/gltable.py | 298 |
1 files changed, 43 insertions, 255 deletions
diff --git a/src/mesa/glapi/gltable.py b/src/mesa/glapi/gltable.py index 8f48366ba7f..54dacb18d2c 100644 --- a/src/mesa/glapi/gltable.py +++ b/src/mesa/glapi/gltable.py @@ -1,11 +1,11 @@ #!/usr/bin/env python -# $Id: gltable.py,v 1.2 2000/05/11 17:44:42 brianp Exp $ +# $Id: gltable.py,v 1.3 2001/11/18 22:42:57 brianp Exp $ # Mesa 3-D graphics library -# Version: 3.3 +# Version: 4.1 # -# Copyright (C) 1999-2000 Brian Paul All Rights Reserved. +# Copyright (C) 1999-2001 Brian Paul All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -28,273 +28,61 @@ # Generate the glapitable.h file. # # Usage: -# gltable.py >glapitable.h +# gloffsets.py >glapitable.h # # Dependencies: -# The gl.spec file from the SI must be in the current directory. -# -# Brian Paul 3 February 2000 - - -import string -import re - - -# -# This table maps types from the gl.spec file to the OpenGL C types. -# -TypeTable = { - 'AttribMask' : 'GLbitfield', - 'Boolean' : 'GLboolean', - 'CheckedFloat32' : 'GLfloat', - 'CheckedInt32' : 'GLint', - 'ClampedColorF' : 'GLclampf', - 'ClampedFloat32' : 'GLclampf', - 'ClampedFloat64' : 'GLclampd', - 'ClampedStencilValue' : 'GLint', - 'ClearBufferMask' : 'GLbitfield', - 'ClientAttribMask' : 'GLbitfield', - 'ColorB' : 'GLbyte', - 'ColorD' : 'GLdouble', - 'ColorF' : 'GLfloat', - 'ColorI' : 'GLint', - 'ColorIndexValueD' : 'GLdouble', - 'ColorIndexValueF' : 'GLfloat', - 'ColorIndexValueI' : 'GLint', - 'ColorIndexValueS' : 'GLshort', - 'ColorIndexValueUB' : 'GLubyte', - 'ColorS' : 'GLshort', - 'ColorUB' : 'GLubyte', - 'ColorUI' : 'GLuint', - 'ColorUS' : 'GLushort', - 'CoordF' : 'GLfloat', - 'CoordD' : 'GLdouble', - 'CoordI' : 'GLint', - 'CoordS' : 'GLshort', - 'FeedbackElement' : 'GLfloat', - 'Float32' : 'GLfloat', - 'Float64' : 'GLdouble', - 'Float32Pointer' : 'GLfloat', - 'Float64Pointer' : 'GLdouble', - 'Int8' : 'GLbyte', - 'Int16' : 'GLshort', - 'Int32' : 'GLint', - 'LineStipple' : 'GLushort', - 'List' : 'GLuint', - 'MaskedColorIndexValueF' : 'GLfloat', - 'MaskedColorIndexValueI' : 'GLuint', - 'MaskedStencilValue' : 'GLuint', - 'PixelInternalFormat' : 'GLenum', - 'SelectName' : 'GLuint', - 'SizeI' : 'GLsizei', - 'StencilValue' : 'GLint', - 'String' : 'const GLubyte *', - 'TexelInternalFormat' : 'GLint', - 'TextureComponentCount' : 'GLint', - 'WinCoord' : 'GLint', - 'UInt8' : 'GLubyte', - 'UInt16' : 'GLushort', - 'UInt32' : 'GLuint', - 'Void' : 'GLvoid', - 'VoidPointer' : 'GLvoid *', - 'void' : 'void', -} - - - -# -# Return C-style argument type string. -# Input: t = a type like ListMode, Int16, CoordF, etc. -# pointerQual = '' or '*' -# constQual = '' or 'const ' -# Return: a string like "const GLubyte *' -# -def ActualType(t, pointerQual, constQual): - if TypeTable.has_key(t): - type = TypeTable[t] - else: - type = 'GLenum' - if pointerQual == '': - s = constQual + type - else: - s = constQual + type + ' ' + pointerQual - return s -#enddef - - - -# -# Convert a Python list of arguments into a string. -# -def ArgListToString(argList): - result = '' - i = 1 - n = len(argList) - for pair in argList: - result = result + pair[0] + ' ' + pair[1] - if i < n: - result = result + ', ' - i = i + 1 - - if result == '': - result = 'void' - return result -#enddef - - -# -# Return a dispatch table entry, like "void (*Enable)(GLenum cap);" -# -def MakeTableEntry(retType, funcName, argList, offset): - s = ' ' - s = s + ActualType(retType, '', '') - s = s + ' (*' - s = s + funcName - s = s + ')(' - s = s + ArgListToString(argList) - s = s + '); /* ' - s = s + str(offset) - s = s + ' */' - return s -#enddef +# The apispec file must be in the current directory. +import apiparser; -def GroupFromCategory(category): - baseCats = [ - 'display-list', - 'drawing', - 'drawing-control', - 'feedback', - 'framebuf', - 'misc', - 'modeling', - 'pixel-op', - 'pixel-rw', - 'state-req', - 'xform' - ] - if baseCats.count(category) > 0: - return 'GL_1_0' - else: - return 'GL_' + category - #endif +def PrintHead(): + print '/* DO NOT EDIT - This file generated automatically with gltable.py script */' + print '#ifndef _GLAPI_TABLE_H_' + print '#define _GLAPI_TABLE_H_' + print '' + print '#include <GL/gl.h>' + print '' + print 'struct _glapi_table' + print '{' + return #endif -def PrintGroup(group): - s = ' /* ' - s = s + group - s = s + ' */' - print s -#enddef - - - -# -# Parse gl.spec to generate all the function pointers in the dispatch struct. -# -def PrintTableEntries(): - functionPattern = re.compile('^[a-zA-Z0-9]+\(') - functionNamePattern = re.compile('^[a-zA-Z0-9]+') - - prevGroup = '' - funcName = '' - returnType = '' - argList = [ ] - maxOffset = 0 - table = { } - - f = open('gl.spec') - for line in f.readlines(): - - m = functionPattern.match(line) - if m: - # extract funcName - n = functionNamePattern.findall(line) - funcName = n[0] - argList = [ ] - #endif - - m = string.split(line) - if len(m) > 1: - # return datatype - if m[0] == 'return': - returnType = m[1] - #endif - - # function parameter - if m[0] == 'param': - constQual = '' - pointerQual = '' - if len(m) >= 5 and m[4] == 'array': - pointerQual = '*' - if m[3] == 'in': - constQual = 'const ' - paramName = m[1] - paramType = ActualType(m[2], pointerQual, constQual) - - argList.append( (paramType, paramName) ) - #endif - -# # category - if m[0] == 'category': - category = m[1] - group = GroupFromCategory(category) - if group != prevGroup: -# PrintGroup(group) - prevGroup = group - #endif - - # end of function spec - if m[0] == 'offset': - if m[1] == '?': - #print 'WARNING: skipping', funcName - noop = 0 - else: - funcOffset = int(m[1]) - if funcOffset > maxOffset: - maxOffset = funcOffset - #PrintProto(returnType, funcName, argList) - s = MakeTableEntry(returnType, funcName, argList, funcOffset) -# print s - table[funcOffset] = s; - #endif - #endif - #endif - #endfor - - # Now dump the table, this effectively does the sort by offset number - for i in range(0, maxOffset + 1): - if table.has_key(i): - print table[i] - -#enddef +def PrintTail(): + print '};' + print '' + print '#endif' +#endif +records = {} -def PrintHead(): - print '/* DO NOT EDIT - This file generated automatically with gltable.py script */' - print '#ifndef _GLAPI_TABLE_H_' - print '#define _GLAPI_TABLE_H_' - print '' - print '#include <GL/gl.h>' - print '' - print 'struct _glapi_table' - print '{' - return +def DoRecord(name, returnType, argTypeList, argNameList, alias, offset): + argList = apiparser.MakeArgList(argTypeList, argNameList) + if offset >= 0 and not records.has_key(offset): + records[offset] = (name, returnType, argList) + #print '#define _gloffset_%s %d' % (name, offset) #endif -def PrintTail(): - print '};' - print '' - print '#endif' -#endif +def PrintRecords(): + keys = records.keys() + keys.sort() + prevk = -1 + for k in keys: + if k != prevk + 1: + #print 'Missing offset %d' % (prevk) + pass + prevk = int(k) + (name, returnType, argList) = records[k] + print ' %s (*%s)(%s); /* %d */' % (returnType, name, argList, k) +#endef +PrintHead() +apiparser.ProcessSpecFile("APIspec", DoRecord) +PrintRecords() +PrintTail() -PrintHead() -PrintTableEntries() -PrintTail()
\ No newline at end of file |