def GenerateEntrypoints(): apiutil.CopyrightC() print '#include "chromium.h"' print '#include "stub.h"' print '' print '#define NAKED __declspec(naked)' print '#define UNUSED(x) ((void)(x))' print '' # Get sorted list of dispatched functions. # The order is very important - it must match cr_opcodes.h # and spu_dispatch_table.h keys = apiutil.GetDispatchedFunctions("../glapi_parser/APIspec.txt") for index in range(len(keys)): func_name = keys[index] if apiutil.Category(func_name) == "Chromium": continue return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print "NAKED %s cr_gl%s( %s )" % ( return_type, func_name, apiutil.MakeDeclarationString(params)) print "{" print "\t__asm jmp [glim.%s]" % func_name for (name, type, vecSize) in params: print "\tUNUSED( %s );" % name print "}" print "" print '/*' print '* Aliases' print '*/' # Now loop over all the functions and take care of any aliases allkeys = apiutil.GetAllFunctions("../glapi_parser/APIspec.txt") for func_name in allkeys: if "omit" in apiutil.ChromiumProps(func_name): continue if func_name in keys: # we already processed this function earlier continue # alias is the function we're aliasing alias = apiutil.Alias(func_name) if alias: return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print "NAKED %s cr_gl%s( %s )" % ( return_type, func_name, apiutil.MakeDeclarationString(params)) print "{" print "\t__asm jmp [glim.%s]" % alias for (name, type, vecSize) in params: print "\tUNUSED( %s );" % name print "}" print "" print '/*' print '* No-op stubs' print '*/' # Now generate no-op stub functions for func_name in allkeys: if "stub" in apiutil.ChromiumProps(func_name): return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print "NAKED %s cr_gl%s( %s )" % ( return_type, func_name, apiutil.MakeDeclarationString(params)) print "{" if return_type != "void": print "return (%s) 0" % return_type print "}" print ""
print """ /* DO NOT EDIT - generated by feedback.py */ #include <stdio.h> #include "cr_spu.h" #include "feedbackspu.h" #include "feedbackspu_proto.h" #include "cr_packfunctions.h" #include "cr_glstate.h" """ keys = apiutil.GetDispatchedFunctions("../../glapi_parser/APIspec.txt") for func_name in keys: return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) if apiutil.FindSpecial( "feedback", func_name ): print 'static %s FEEDBACKSPU_APIENTRY feedbackspu_%s( %s )' % ( return_type, func_name, apiutil.MakeDeclarationString(params) ) print '{' print '\tfeedback_spu.super.%s( %s );' % ( func_name, apiutil.MakeCallString(params) ) print '}' print """ #define CHANGE( name, func ) crSPUChangeInterface( (void *)&(feedback_spu.self), (void *)feedback_spu.self.name, (void *)((SPUGenericFunction) func) ) #define CHANGESWAP( name, swapfunc, regfunc ) crSPUChangeInterface( (void *)&(feedback_spu.self), (void *)feedback_spu.self.name, (void *)((SPUGenericFunction) (feedback_spu.swap ? swapfunc: regfunc )) ) static void __loadFeedbackAPI( void ) {
#ifdef __cplusplus extern "C" { #endif """) keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt") for func_name in keys: if ("pack" in apiutil.ChromiumProps(func_name) or "extpack" in apiutil.ChromiumProps(func_name) or apiutil.NonVectorFunction(func_name) != '' or apiutil.FindSpecial('packer', func_name)): # OK, generate a crPackFooBar() prototype for this function return_type = apiutil.ReturnType(func_name) args = apiutil.Parameters(func_name) if return_type != 'void': if apiutil.IsPointer(return_type): args.append(("return_value", return_type, 0)) else: args.append(("return_value", return_type + "*", 0)) elif "pixelstore" in apiutil.Properties(func_name): args.append(("packstate", "const CRPixelPackState *", 0)) if "get" in apiutil.Properties(func_name): args.append(("writeback", "int *", 0)) print('void PACK_APIENTRY crPack%s(%s);' % (func_name, apiutil.MakeDeclarationStringWithContext(
def wrap_compile(functionName): params = apiutil.Parameters(functionName) return_type = apiutil.ReturnType(functionName) # Make sure the return type is void. It's nonsensical to compile # an element with any other return type. if return_type != 'void': print '/* Nonsense: DL function %s has a %s return type?!? */' % (functionName, return_type) # Define a structure to hold all the parameters. Note that the # top parameters must exactly match the DLMInstanceList structure # in include/cr_dlm.h, or everything will break horribly. # Start off by getting all the pointer info we could ever use # from the parameters (pointers, pointername, pointerarg, pointertype, pointersize, pointercomment) = GetPointerInfo(functionName) # Finally, the compile wrapper. This one will diverge strongly # depending on whether or not there are pointer parameters. callstring = apiutil.MakeCallString(params) argstring = apiutil.MakeDeclarationString(params) props = apiutil.Properties(functionName) if "useclient" in props or "pixelstore" in props: callstring += ", c" argstring += ", CRClientState *c" print 'void DLM_APIENTRY crDLMCompile%s(%s)' % (functionName, argstring) print '{' print ' CRDLMContextState *state = CURRENT_STATE();' print ' struct instance%s *instance;' % (functionName) # The calling SPU is supposed to verify that the element is supposed to be # compiled before it is actually compiled; typically, this is done based # on whether a glNewList has been executed more recently than a glEndList. # But some functions are dual-natured, sometimes being compiled, and sometimes # being executed immediately. We can check for this here. if "checklist" in apiutil.ChromiumProps(functionName): print ' if (crDLMCheckList%s(%s))' % (functionName, apiutil.MakeCallString(params)) print ' {' print ' crdlm_error(__LINE__, __FILE__, GL_INVALID_OPERATION,' print ' "this instance of function %s should not be compiled");' % functionName; print ' return;' print ' }' if len(pointers) > 1 or pointersize == 'special': # Pass NULL, to just allocate space print ' instance = crCalloc(sizeof(struct instance%s) + crdlm_pointers_%s(NULL, %s));' % (functionName, functionName, callstring) else: print ' instance = crCalloc(sizeof(struct instance%s));' % (functionName) print ' if (!instance)' print ' {' print ' crdlm_error(__LINE__, __FILE__, GL_OUT_OF_MEMORY,' print ' "out of memory adding %s to display list");' % (functionName) print ' return;' print ' }' # Put in the fields that must always exist print ' instance->execute = execute%s;' % functionName # Apply all the simple (i.e. non-pointer) parameters for index in range(len(params)): if index not in pointers: name = params[index][0] print ' instance->%s = %s;' % (name, name) # We need to know instance size in bytes in order to save its state later. print ' instance->cbInstance = sizeof(struct instance%s);' % functionName # Set OPCODE. print ' instance->iVBoxOpCode = VBOX_DL_OPCODE_%s;' % functionName # If there's a pointer parameter, apply it. if len(pointers) == 1: print ' if (%s == NULL)' % (params[pointers[0]][0]) print ' instance->%s = NULL;' % (params[pointers[0]][0]) print ' else' print ' instance->%s = instance->%s;' % (params[pointers[0]][0], pointerarg) if pointersize == 'special': print ' instance->cbInstance += crdlm_pointers_%s(instance, %s);' % (functionName, callstring) else: print ' crMemcpy((void *)instance->%s, (void *) %s, %s*sizeof(%s));' % (params[pointers[0]][0], params[pointers[0]][0], pointersize, pointertype) elif len(pointers) == 2: # this seems to work print ' instance->cbInstance += crdlm_pointers_%s(instance, %s);' % (functionName, callstring) elif len(pointers) > 2: print "#error don't know how to handle pointer parameters for %s" % (functionName) # Add the element to the current display list AddInstanceToList(' ') # If the element is a state-changing element, add it to the current state list if apiutil.SetsTrackedState(functionName): AddInstanceToStateList(' ') print '}'
'GetProgramEnvParameterfvARB', 'GetProgramivARB', 'AreProgramsResidentNV', 'GetProgramiv', 'GetShaderiv', 'GetObjectParameterfvARB', 'GetObjectParameterivARB', 'GetRenderbufferParameterivEXT', 'GetFramebufferAttachmentParameterivEXT' ] convert_bufferid = [ 'GetVertexAttribdvARB', 'GetVertexAttribdvNV', 'GetVertexAttribfvARB', 'GetVertexAttribfvNV', 'GetVertexAttribivARB', 'GetVertexAttribivNV' ] keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt") for func_name in keys: #(return_type, arg_names, arg_types) = gl_mapping[func_name] if ("get" in apiutil.Properties(func_name) and apiutil.ReturnType(func_name) == "void" and not apiutil.FindSpecial("server", func_name)): params = apiutil.Parameters(func_name) print('void SERVER_DISPATCH_APIENTRY crServerDispatch%s(%s)' % (func_name, apiutil.MakeDeclarationString(params))) print('{') lastParam = params[-1] assert apiutil.IsPointer(lastParam[1]) local_argtype = apiutil.PointerType(lastParam[1]) local_argname = 'local_%s' % lastParam[0] print('\t%s %s[%d];' % (local_argtype, local_argname, max_components[func_name]))
def GenerateEntrypoints(hacks = []): """Emit code for all the OpenGL/Chromium entrypoints. hacks is an optional list of functions which are special cased. """ apiutil.CopyrightC() print('#define GL_GLEXT_PROTOTYPES') print('#include <stdio.h>') print('#include <stdlib.h>') print('#include <GL/gl.h>') print('#include "chromium.h"') print('#include "stub.h"') print('#include "dri_glx.h"') print('') print('#ifdef __GNUC__') print('# if (__GNUC__ << 16) + __GNUC_MINOR__ >= 0x40002') print('# pragma GCC diagnostic ignored "-Wunused-parameter"') print('# endif') print('#endif') # Get sorted list of dispatched functions. # The order is very important - it must match cr_opcodes.h # and spu_dispatch_table.h keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt") for index in range(len(keys)): func_name = keys[index] if apiutil.Category(func_name) == "Chromium": # this function is defined in stub.c continue return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) if func_name in hacks: print("/* hacked entrypoint: %s */" % func_name) if func_name == "TexImage3D": # Pretty common: internalformat is GLenum, not GLint print("void glTexImage3D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )") print("{") print("\tglim.TexImage3D( target, level, (GLint) internalformat, width, height, depth, border, format, type, pixels );") print("}") elif func_name == "TexImage2D": # Pretty common: internalformat is GLenum, not GLint print("void glTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )") print("{") print("\tglim.TexImage2D( target, level, (GLint) internalformat, width, height, border, format, type, pixels );") print("}") elif func_name == "TexImage1D": # Pretty common: internalformat is GLenum, not GLint print("void glTexImage1D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )") print("{") print("\tglim.TexImage1D( target, level, (GLint) internalformat, width, border, format, type, pixels );") print("}") elif func_name == "EdgeFlagPointer": # second arg is GLboolean instead of GLvoid print("void glEdgeFlagPointer( GLsizei stride, const GLboolean *pointer )") print("{") print("\tglim.EdgeFlagPointer( stride, pointer );") print("}") elif func_name == "ProgramParameters4fvNV": print("void glProgramParameters4fvNV( GLenum target, GLuint index, GLuint num, const GLfloat *params )") print("{") print("\tglim.ProgramParameters4fvNV( target, index, num, params );") print("}") elif func_name == "MultiDrawElementsEXT": print("void glMultiDrawElementsEXT(GLenum mode, GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount)") print("{") print("\tglim.MultiDrawElementsEXT(mode, count,type, indices, primcount);") print("}") elif func_name == "ProgramParameters4dvNV": print("void glProgramParameters4dvNV( GLenum target, GLuint index, GLuint num, const GLdouble *params )") print("{") print("\tglim.ProgramParameters4dvNV( target, index, num, params );") print("}") else: # the usual path print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("") print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("{") print("\t", end="") if return_type != "void": print("return ", end=" ") print("glim.%s(%s);" % (func_name, apiutil.MakeCallString(params))) print("}") print("") print('/*') print('* Aliases') print('*/') # Now loop over all the functions and take care of any aliases allkeys = apiutil.GetAllFunctions(sys.argv[1]+"/APIspec.txt") for func_name in allkeys: if "omit" in apiutil.ChromiumProps(func_name): continue if func_name in keys: # we already processed this function earlier continue # alias is the function we're aliasing alias = apiutil.Alias(func_name) if alias: if func_name in hacks: print("/* hacked entrypoint: %s */" % func_name) if func_name == "MultiDrawArrays": print("void glMultiDrawArrays( GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount )") print("{") print("\tglim.MultiDrawArraysEXT( mode, (GLint*)first, (GLsizei*)count, primcount );") print("}") elif func_name == "BufferData": print("void glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage)") print("{") print("\tglim.BufferDataARB(target, size, data, usage);") print("}") elif func_name == "BufferSubData": print("void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data)") print("{") print("\tglim.BufferSubDataARB(target, offset, size, data);") print("}") elif func_name == "GetBufferSubData": print("void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data)") print("{") print("\tglim.GetBufferSubDataARB(target, offset, size, data);") print("}") else: return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("") print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("{") print("\t", end="") if return_type != "void": print("return ", end=" ") print("glim.%s(%s);" % (alias, apiutil.MakeCallString(params))) print("}") print("") print('/*') print('* No-op stubs') print('*/') # Now generate no-op stub functions for func_name in allkeys: if "stub" in apiutil.ChromiumProps(func_name): return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("") print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("{") if return_type != "void": print("return (%s) 0" % return_type) print("}") print("")
def PrintTableFunc( func_name, params, can_have_pointers,f): """Emit a packer test function.""" #print "PrintTableFunc (%s,%s,%d,f)" % (func_name,str(params),can_have_pointers) # Save original function name orig_func_name = func_name # Convert to a non-vector version of the function if possible #func_name = apiutil.NonVectorFunction( func_name ) if not func_name: func_name = orig_func_name # Check if there are any pointer parameters. # That's usually a problem so we'll emit an error function. nonVecParams = apiutil.Parameters(func_name) return_type = apiutil.ReturnType(func_name) f.write("\nstruct %s_params {\n" % func_name) for (name, type, vecSize) in nonVecParams: if not apiutil.IsPointer(type) : f.write("\t%s %s_%s;\n" % (type,func_name,name)) if verbose: f.write( '\tchar *prgstr;\n') f.write( '} %s_tab[] = {\n' % func_name) bail_out = 0 for (name, type, vecSize) in nonVecParams: if apiutil.IsPointer(type) and vecSize == 0 and not can_have_pointers: bail_out = 1 counter = 0 # generate the calls if len(params) == 0: argstr = "" else: argstr = ", " printfstr = "" argstr = "" if return_type != 'void': # Yet another gross hack for glGetString if string.find( return_type, '*' ) == 1: return_type = return_type + " *" f.write( '\t%s return_val;\n' % return_type) # At this point all of the declarations have been generated # The argument lists with the various parameter values have to # be permuted # Generate the lists to be permuted argLists = GenParmLists(func_name,f) #print argLists #print len(argLists) # # Now iterate over the permuted argument lists generating gl calls with # the permuted arguments # for ki in range(len(argLists)): argList = argLists[ki] ncount = 0 if len(argList) > 0: allargstr = "" for i in range(len(argList)): #print argList[i] q = argList[i] ll = 0 f.write("{ ") ncount = ncount + 1 for k in range(len(q)): (name, type, vecSize) = params[k] # # ordinary typed parameter, or vector of unknown size # # TODO Vector arg # #if vecSize >= 1: #f.write('%s /* VEC1 */' % name) #f.write( "\t%s %s[%d]; /* VECTOR1 */\n" % (type[0:type.index('*')],name, vecSize)) #if apiutil.IsPointer ( type ): # POINTER #f.write( "\t(%s)%s /* VEC3 */" % (type,name)) if printf_mapping.has_key( type ): (format_str, cast) = printf_mapping[type] printfstr += format_str cast_str = '' if cast != '': cast_str = '(%s)' % cast if type == 'GLenum': argstr += "%s" % q[k] elif type == 'GLboolean': argstr += "%s" % q[k] else: argstr += '%s %s' % (cast_str,q[k]) #elif type.find( "*" ): #printfstr += "%p" #argstr += "(void *)" #argstr += '%s' % q[k] else: argstr = "" printfstr = "???" break if ll != len(params): printfstr += ", " argstr += ", " ll += 1 f.write( '\t%s' % argstr) allargstr = allargstr + argstr argstr = "" printfstr = "" if verbose: f.write( '\n\t\"%s\"' % (allargstr)) #f.write( '\n\t\"%s_tab.%s\"' % (func_name,allargstr)) allargstr = "" f.write( '},\n') # finish up f.write( '};\n\n' ) f.write( '/* COUNT = %d */\n' % ncount) f.write( 'void crPackTest%s(void)\n' % (func_name)) f.write( '{\n') f.write( '\tint i;\n') for (name, type, vecSize) in nonVecParams: if apiutil.IsPointer(type) and vecSize == 0 and not can_have_pointers: if vecSize == 0: if type == "GLvoid *" or type == "GLvoid **" or type == "GLubyte *" or type == "const GLvoid *" or type == "const GLubyte *": f.write( "\t%s %s[100000];/* VECP2b (%s,%s)*/\n" % (type,name,type,name)) elif type == "const GLfloat *" or type == "GLfloat *" or type == "const GLint *" or type == "GLint *" or type == "GLdouble *" or type == "const GLdouble *" or type == "const GLuint *" or type == "GLuint *" or type == "const GLushort *" or type == "GLushort *": f.write( "\t%s %s[100000];/* VECP2a (%s,%s)*/\n" % (type[0:type.index('*')],name,type,name)) #f.write( "\t%s %s[100000];/* VECP2a */\n" % (type,name)) bail_out = 1 elif apiutil.IsPointer(type) : if vecSize == 0: if type == "GLvoid *" or type == "GLvoid **" or type == "GLubyte *" or type == "const GLvoid *" or type == "const GLubyte *" or type == "GLint *" or type == "const GLint *" or type == "const GLfloat *" or type == "GLfloat *" or type == "GLdouble *" or type == "const GLdouble *" or type == "const GLuint *" or type == "GLuint *" or type == "const GLushort *" or type == "GLushort *": f.write( "\t%s %s[100000];/* VECP9 (%s,%s)*/\n" % (type[0:type.index('*')],name,type,name)) else: f.write( "\tGLubyte %s[100000];/* VECP7 */\n" % name) PerformAction(func_name,f) f.write('\tfor ( i = 0; i < %d; i++) {\n' % ncount) if verbose: f.write('\tif (verbose)\n\tcrDebug(\"gl%s( %%s )\",%s_tab[i].prgstr);\n' % (func_name,func_name)) if return_type != 'void': f.write( '\t\treturn_val = gl%s(' % func_name) else: f.write( '\t\tgl%s(' % func_name) ll = 0 for (name, type, vecSize) in nonVecParams: if apiutil.IsPointer(type) and vecSize == 0 and not can_have_pointers: if vecSize == 0: if type == "GLvoid *" or type == "GLvoid **" or type == "GLubyte *" or type == "const GLvoid *" or type == "const GLubyte *": f.write( "%s /* VECS2 */\n" % name) bail_out = 1 elif apiutil.IsPointer(type) : if vecSize == 0: if type == "GLvoid *" or type == "GLvoid **" or type == "GLubyte *" or type == "const GLvoid *" or type == "const GLubyte *" or type == "GLint *" or type == "const GLint *" or type == "GLfloat *" or type == "GLdouble *" or type == "const GLdouble *" or type == "const GLuint *" or type == "GLuint *": f.write( "\t%s/* VECS4 */\n" % name) else: f.write( "\t%s/* VECS5 */\n" % name) else: f.write("\t%s_tab[i].%s_%s" % (func_name,func_name,name)) if ll != len(nonVecParams) -1: f.write(', ') ll = ll + 1 # f.write(');\n') if return_type != 'void': f.write('\n\t\tif(errChk) {\n') f.write('\t\t\tchar buf[1024];\n') f.write('\t\t\tsprintf(buf,\"gl%s( %%s )\",%s_tab[i].prgstr);\n' % (func_name,func_name)) f.write('\t\t\tprintError(buf);\n') f.write( '\t}\n') else: f.write('\n\t\tif(errChk) {\n') f.write('\t\t\tchar buf[1024];\n') f.write('\t\t\tsprintf(buf,\"gl%s( %%s )\",%s_tab[i].prgstr);\n' % (func_name,func_name)) f.write('\t\t\tprintError(buf);\n') f.write( '\t}\n') f.write( '\t}\n' ) f.write( '}\n' )
def GenParmLists(func_name,f): # Fetch the parameter properties params = apiutil.Parameters(func_name) return_type = apiutil.ReturnType(func_name) if return_type != 'void': # Yet another gross hack for glGetString if string.find( return_type, '*' ) == -1: return_type = return_type + " *" #print "" #print "FUNC_NAME %s PARAMS %s" % (func_name,params) pvec = [] tvec = [] rlist = GenParmSetLists(func_name) #print "RETURNLIST" #print rlist # # At this point rlist is constructed as # # # fvec = copy.deepcopy(apiutil.ParamProps(func_name)) vallist = copy.deepcopy(apiutil.ParamList(func_name)) valinit = copy.deepcopy(apiutil.ParamVec(func_name)) multiList = [] if rlist != []: for kk in range(len(rlist)): #print "RLIST-KK" pvec = [] #print rlist[kk] rvec = rlist[kk] params = apiutil.Parameters(func_name) for index in range(len(params)): (name, type, vecSize) = params[index] action = apiutil.ParamAction(func_name) #print "name = %s type = %s" % (name,type) if vecSize >= 1: # # Vector arg # #print "/* VECTOR */" f.write( "\t%s %s[%d]; /* VECTOR1 */\n" % (type[0:type.index('*')],name, vecSize)) # TODO: Add dummy vars to vector/matrix tvec = name if type == "GLenum": #print "name = %s type = %s" % (name,type) if rvec != []: fvec = rvec else: fvec = copy.deepcopy(apiutil.ParamProps(func_name)) #print "fvec = %s" % fvec for k in range(len(fvec)): d = fvec.pop(0) if d[0] == name: tvec = d[1] break elif vallist != []: #print "name = %s type = %s" % (name,type) vallist = copy.deepcopy(apiutil.ParamList(func_name)) #print "vallist = %s" % vallist for k in range(len(vallist)): d = vallist[k] (dname,vec) = d #print d[0] if d[0] == name : #print "name = %s (dname,vec) = (%s) %s" % (name,dname,vec) tvec = vec break; elif valinit != []: #print "name = %s type = %s" % (name,type) valinit = copy.deepcopy(apiutil.ParamVec(func_name)) #print "valinit = %s" % valinit cnt = 0 d = valinit[k] (dname,vec) = d #print d[0] if d[0] == name : #print "name = %s (dname,vec) = (%s) %s" % (name,dname,vec) for nint in range(len(vec)): f.write("\t%s[%d] = %s;/* VA1 */\n" % (name,nint,vec[nint])) #print "\t%s[%d] = %s;\n" % (name,nint,vec[nint]) break; elif range_mapping.has_key( type ): #print "name = %s type = %s" % (name,type) if rvec != []: #print "rvec = %s" % rvec fvec = rvec #print "fvec = %s" % fvec for k in range(len(fvec)): d = fvec.pop(0) if d[0] == name: tvec = d[1] break else: fvec = copy.deepcopy(apiutil.ParamProps(func_name)) else: tvec = range_mapping[type] else: tvec = [0] pvec.append(tvec) #print "PVEC.APPEND(%s)" % tvec #print "PVEC %s" % pvec #print "PVECLEN = %d" % len(pvec) #for i in range(len(pvec)): #print pvec[i] argLists = permute2(pvec) #print argLists #print "ARGLIST = %d" % len(argLists) #for i in range(len(argLists)): #print argLists[i] multiList.append(argLists) else: for index in range(len(params)): (name, type, vecSize) = params[index] action = apiutil.ParamAction(func_name) #print "name = %s type = %s" % (name,type) #print valinit if vecSize >= 1: # # Vector arg # #print "/* VECTOR */" if type[0:5] == "const" : f.write( "\t%s %s[%d]; /* VECTOR2a */\n" % (type[6:type.index('*')],name, vecSize)) else: f.write( "\t%s %s[%d]; /* VECTOR2 */\n" % (type[0:type.index('*')],name, vecSize)) # TODO: Add dummy vars to vector/matrix tvec = name for index in range(len(params)): (name, type, vecSize) = params[index] action = apiutil.ParamAction(func_name) if type == "GLenum": fvec = copy.deepcopy(apiutil.ParamProps(func_name)) for k in range(len(fvec)): d = fvec.pop(0) if d[0] == name: tvec = d[1] break elif vallist != []: vallist = copy.deepcopy(apiutil.ParamList(func_name)) for k in range(len(vallist)): d = vallist.pop(0) if d[0] == name: tvec = d[1] break; elif valinit != []: #print "name = %s type = %s" % (name,type) valinit = copy.deepcopy(apiutil.ParamVec(func_name)) #print "valinit = %s" % valinit cnt = 0 for k in range(len(valinit)): d = valinit[k] (dname,vec) = d #print d[0] if d[0] == name : #print "name = %s (dname,vec) = (%s) %s" % (name,dname,vec) for nint in range(len(vec)): f.write("\t%s[%d] = (%s)%s;/* VA2 */\n" % (name,nint,type[0:type.index('*')],vec[nint])) #print "\t%s[%d] = %s;\n" % (name,nint,vec[nint]) break; elif range_mapping.has_key( type ): tvec = range_mapping[type] else: tvec = [0] pvec.append(tvec) #print tvec #print "PVEC %s" % pvec #print "PVEC %s" % pvec #print "PVECLEN = %d" % len(pvec) #for i in range(len(pvec)): #print pvec[i] argLists = permute2(pvec) #print argLists #print "ARGLIST = %d" % len(argLists) #for i in range(len(argLists)): #print argLists[i] multiList.append(argLists) return multiList
def PrintFunc( func_name, params, can_have_pointers,f): f.write( 'void crPackTest%s(void)\n' % (func_name)) f.write( '{\n') # Save original function name orig_func_name = func_name # Convert to a non-vector version of the function if possible #func_name = apiutil.NonVectorFunction( func_name ) if not func_name: func_name = orig_func_name # Check if there are any pointer parameters. # That's usually a problem so we'll emit an error function. nonVecParams = apiutil.Parameters(func_name) return_type = apiutil.ReturnType(func_name) bail_out = 0 for (name, type, vecSize) in nonVecParams: if apiutil.IsPointer(type) and vecSize == 0 and not can_have_pointers: if vecSize == 0: if type == "GLvoid *" or type == "GLvoid **" or type == "GLubyte *" or type == "const GLvoid *" or type == "const GLubyte *": f.write( "\t%s %s[100000];/* VECP7b (%s,%s)*/\n" % (type,name,type,name)) elif type == "GLfloat *" or type == "GLint *" or type == "GLdouble *" or type == "GLuint *" or type == "GLushort *": f.write( "\t%s %s[100000];/* VECP7a (%s,%s)*/\n" % (type[0:type.index('*')],name,type,name)) elif type == "const GLfloat *" or type == "const GLint *" or type == "const GLdouble *" or type == "const GLuint *" or type == "const GLushort *": f.write( "\t%s %s[100000];/* VECP7b (%s,%s)*/\n" % (type[6:type.index('*')],name,type,name)) #f.write( "\t%s %s[100000];/* VECP7a */\n" % (type,name)) bail_out = 1 elif apiutil.IsPointer(type) : if vecSize == 0: if type == "GLsizei *" or type == "GLubyte *" or type == "const GLvoid *" or type == "const GLubyte *" or type == "GLint *" or type == "const GLint *" or type == "const GLfloat *" or type == "GLfloat *" or type == "GLdouble *" or type == "const GLdouble *" or type == "const GLuint *" or type == "GLuint *": f.write( "\t%s %s[100000];/* VECP5a (%s,%s)*/\n" % (type[0:type.index('*')],name,type,name)) else: f.write( "\t%s %s[100000];/* VECP5 */\n" % (type,name)) PerformAction(func_name,f) # if bail_out: # for (name, type, vecSize) in nonVecParams: # print '\t(void)%s;' % (name) # # Special casing indicates that some arbitrary data appropriate to # the call must be supplied # f.write( '\tcrDebug ( "%s needs to be special cased %d %d!");\n' % (func_name, vecSize, can_have_pointers)) if "extpack" in apiutil.ChromiumProps(func_name): is_extended = 1 else: is_extended = 0 counter = 0 # generate the calls if len(params) == 0: argstr = "" else: argstr = ", " printfstr = "" argstr = "" if return_type != 'void': # Yet another gross hack for glGetString if string.find( return_type, '*' ) == 1: return_type = return_type + " *" f.write( '\t%s return_val;\n' % return_type) # At this point all of the declarations have been generated # The argument lists with the various parameter values have to # be permuted # Generate the lists to be permuted argLists = GenParmLists(func_name,f) #print argLists #print len(argLists) # # Now iterate over the permuted argument lists generating gl calls with # the permuted arguments # for ki in range(len(argLists)): argList = argLists[ki] if len(argList) > 0: allargstr = "" for i in range(len(argList)): #print argList[i] q = argList[i] if return_type != 'void': f.write( '\treturn_val = gl%s(' % func_name) else: f.write( '\tgl%s(' % func_name) ll = 0 nparms = len(params) if len(q) > nparms: nparms = len(q) #for k in range(len(q)): for k in range(nparms): (name, type, vecSize) = params[k] # ordinary typed parameter, or vector of unknown size # # TODO Vector arg # if vecSize >= 1: f.write("%s /* VEC2a */" % name) elif apiutil.IsPointer ( type ): # POINTER f.write( "\t(%s)%s /* VEC3a */\n" % (type,name)) # (format_str, cast) = printf_mapping[type] # printfstr += format_str # cast_str = '' # if cast != '': # cast_str = '(%s)' % cast # if type == 'GLenum': # argstr += "%s" % q[k] # elif type == 'GLboolean': # argstr += "%s" % q[k] # else: # argstr += '%s %s' % (cast_str,q[k]) elif printf_mapping.has_key( type ): (format_str, cast) = printf_mapping[type] printfstr += format_str cast_str = '' if cast != '': cast_str = '(%s)' % cast if type == 'GLenum': argstr += "%s" % q[k] elif type == 'GLboolean': argstr += "%s" % q[k] else: argstr += '%s %s' % (cast_str,q[k]) elif type.find( "*" ): printfstr += "%p" argstr += "(void *)" argstr += '%s' % q[k] else: argstr = "" printfstr = "???" break; if ll != len(params) - 1: printfstr += ", " argstr += ", " ll += 1 f.write( '%s' % argstr) allargstr = allargstr + argstr argstr = "" printfstr = "" f.write( ');\n\tif(errChk)\n\t\tprintError(\"gl%s(%s)\");\n' % (func_name,allargstr)) if verbose: f.write('\tif (verbose)\n\t\tcrDebug(\"gl%s( %s )\");\n' % (func_name,allargstr)) allargstr = "" #f.write( ');\n') else: if return_type != 'void': f.write( '\treturn_val = gl%s();\n\tif(errChk)\n\t\tprintError(\"gl(%s)\");\n' % (func_name,func_name)) else: f.write( '\tgl%s();\n\tif(errChk)\n\t\tprintError(\"gl(%s)\");\n' % (func_name,func_name)) if verbose: f.write('\tif (verbose)\n\t\tcrDebug(\"gl%s( )\");\n' % (func_name)) # finish up f.write( '}\n' )