def generateErrorSource(apis, args):

  funcDefine = apiErrorFuncDefineCode( apis, args )
  funcInit   = apiDispatchFuncInitCode( apis, args, 'error' )

  substitute = {}
  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['COPYRIGHT']       = args.copyright
  substitute['DISPATCH_NAME'] = 'Error'
  substitute['LOCAL_INCLUDE'] = ''
  substitute['LOCAL_CODE']    = ''
  substitute['API_DISPATCH_FUNC_DEFINE'] = funcDefine
  substitute['API_DISPATCH_FUNC_INIT'] = funcInit
  substitute['API_DISPATCH_GLOBAL_FUNC_INIT'] = ''
  substitute['IFDEF'] = '#if REGAL_ERROR\n\n'
  substitute['ENDIF'] = '#endif\n'
  outputCode( '%s/RegalDispatchError.cpp' % args.srcdir, dispatchSourceTemplate.substitute(substitute))
Exemplo n.º 2
0
def generateMissingSource(apis, args):

  # Output

  substitute = {}

  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['COPYRIGHT']       = args.copyright
  substitute['DISPATCH_NAME'] = 'Missing'
  substitute['LOCAL_INCLUDE'] = ''
  substitute['LOCAL_CODE']    = ''
  substitute['API_DISPATCH_FUNC_DEFINE'] = apiMissingFuncDefineCode( apis, args )
  substitute['API_DISPATCH_FUNC_INIT']   = apiDispatchFuncInitCode( apis, args, None )
  substitute['API_DISPATCH_GLOBAL_FUNC_INIT']   = apiDispatchGlobalFuncInitCode( apis, args, None )
  substitute['IFDEF'] = '#if REGAL_MISSING\n\n'
  substitute['ENDIF'] = '#endif\n'

  outputCode( '%s/RegalDispatchMissing.cpp' % args.srcdir, missingSourceTemplate.substitute(substitute))
Exemplo n.º 3
0
def generateTraceSource(apis, args):

  funcDefine     = apiTraceFuncDefineCode( apis, args )
  funcInit       = apiDispatchFuncInitCode( apis, args, 'trace', exclude, lambda x : True, traceCond )
  globalFuncInit = apiDispatchGlobalFuncInitCode( apis, args, 'trace', exclude, lambda x : True, traceCond )

  substitute = {}
  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['COPYRIGHT']       = args.copyright
  substitute['DISPATCH_NAME'] = 'Trace'
  substitute['LOCAL_INCLUDE'] = '#include "RegalDispatcherGlobal.h"\n'
  substitute['LOCAL_CODE']    = ''
  substitute['API_DISPATCH_FUNC_DEFINE'] = funcDefine
  substitute['API_DISPATCH_FUNC_INIT'] = funcInit
  substitute['API_DISPATCH_GLOBAL_FUNC_INIT'] = globalFuncInit
  substitute['IFDEF'] = '#if REGAL_TRACE\n\n#ifdef REGAL_NAMESPACE\n#undef REGAL_NAMESPACE\n#endif\n\n'
  substitute['ENDIF'] = '#endif\n'
  outputCode( '%s/RegalDispatchTrace.cpp' % args.srcdir, dispatchSourceTemplate.substitute(substitute))
Exemplo n.º 4
0
def generateTraceSource(apis, args):

  funcDefine     = apiTraceFuncDefineCode( apis, args )
  funcInit       = apiDispatchFuncInitCode( apis, args, 'trace', exclude )
  globalFuncInit = apiDispatchGlobalFuncInitCode( apis, args, 'trace', exclude )

  substitute = {}
  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['COPYRIGHT']       = args.copyright
  substitute['DISPATCH_NAME'] = 'Trace'
  substitute['LOCAL_INCLUDE'] = '#include "RegalDispatcherGlobal.h"\n'
  substitute['LOCAL_CODE']    = ''
  substitute['API_DISPATCH_FUNC_DEFINE'] = funcDefine
  substitute['API_DISPATCH_FUNC_INIT'] = funcInit
  substitute['API_DISPATCH_GLOBAL_FUNC_INIT'] = globalFuncInit
  substitute['IFDEF'] = '#if REGAL_TRACE\n\n#ifdef REGAL_NAMESPACE\n#undef REGAL_NAMESPACE\n#endif\n\n'
  substitute['ENDIF'] = '#endif\n'
  outputCode( '%s/RegalDispatchTrace.cpp' % args.srcdir, dispatchSourceTemplate.substitute(substitute))
Exemplo n.º 5
0
def generateDebugSource(apis, args):

  funcDefine = apiDebugFuncDefineCode( apis, args )
  funcInit   = apiDispatchFuncInitCode( apis, args, 'debug' )

  # Output

  substitute = {}

  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['COPYRIGHT']       = args.copyright
  substitute['DISPATCH_NAME']   = 'Debug'
  substitute['LOCAL_INCLUDE']   = debugGlobalCode
  substitute['LOCAL_CODE']      = debugLocalCode
  substitute['API_DISPATCH_FUNC_DEFINE'] = funcDefine
  substitute['API_DISPATCH_FUNC_INIT'] = funcInit
  substitute['API_DISPATCH_GLOBAL_FUNC_INIT'] = ''
  substitute['IFDEF'] = '#if REGAL_DEBUG\n\n'
  substitute['ENDIF'] = '#endif\n'

  outputCode( '%s/RegalDispatchDebug.cpp' % args.srcdir, dispatchSourceTemplate.substitute(substitute))
Exemplo n.º 6
0
def generateLoaderSource(apis, args):

  funcDefine = apiLoaderFuncDefineCode( apis, args )
  funcInit   = apiDispatchFuncInitCode( apis, args, None )
  globalFuncInit   = apiDispatchGlobalFuncInitCode( apis, args, None )

  # Output

  substitute = {}

  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['COPYRIGHT']       = args.copyright
  substitute['DISPATCH_NAME']   = 'Loader'
  substitute['LOCAL_CODE']      = ''
  substitute['LOCAL_INCLUDE']   = ''
  substitute['API_DISPATCH_FUNC_DEFINE'] = funcDefine
  substitute['API_DISPATCH_FUNC_INIT'] = funcInit
  substitute['API_DISPATCH_GLOBAL_FUNC_INIT'] = globalFuncInit
  substitute['IFDEF'] = '#if REGAL_DRIVER && REGAL_LOADER\n\n'
  substitute['ENDIF'] = '#endif\n'

  outputCode( '%s/RegalDispatchLoader.cpp' % args.srcdir, loaderSourceTemplate.substitute(substitute))
Exemplo n.º 7
0
def generateDebugSource(apis, args):

    funcDefine = apiDebugFuncDefineCode(apis, args)
    funcInit = apiDispatchFuncInitCode(apis, args, 'debug')

    # Output

    substitute = {}

    substitute['LICENSE'] = args.license
    substitute['AUTOGENERATED'] = args.generated
    substitute['COPYRIGHT'] = args.copyright
    substitute['DISPATCH_NAME'] = 'Debug'
    substitute['LOCAL_INCLUDE'] = debugGlobalCode
    substitute['LOCAL_CODE'] = debugLocalCode
    substitute['API_DISPATCH_FUNC_DEFINE'] = funcDefine
    substitute['API_DISPATCH_FUNC_INIT'] = funcInit
    substitute['API_DISPATCH_GLOBAL_FUNC_INIT'] = ''
    substitute['IFDEF'] = '#if REGAL_DEBUG\n\n'
    substitute['ENDIF'] = '#endif\n'

    outputCode('%s/RegalDispatchDebug.cpp' % args.srcdir,
               dispatchSourceTemplate.substitute(substitute))
def generateMissingSource(apis, args):

    # Output

    substitute = {}

    substitute['LICENSE'] = args.license
    substitute['AUTOGENERATED'] = args.generated
    substitute['COPYRIGHT'] = args.copyright
    substitute['DISPATCH_NAME'] = 'Missing'
    substitute['LOCAL_INCLUDE'] = ''
    substitute['LOCAL_CODE'] = ''
    substitute['API_DISPATCH_FUNC_DEFINE'] = apiMissingFuncDefineCode(
        apis, args)
    substitute['API_DISPATCH_FUNC_INIT'] = apiDispatchFuncInitCode(
        apis, args, None)
    substitute[
        'API_DISPATCH_GLOBAL_FUNC_INIT'] = apiDispatchGlobalFuncInitCode(
            apis, args, None)
    substitute['IFDEF'] = '#if REGAL_MISSING\n\n'
    substitute['ENDIF'] = '#endif\n'

    outputCode('%s/RegalDispatchMissing.cpp' % args.srcdir,
               missingSourceTemplate.substitute(substitute))
Exemplo n.º 9
0
def generateDispatchGLX(apis, args):

  # CodeGen for API functions.

  code = ''
  categoryPrev = None

  for api in apis:

    if api.name != 'glx':
      continue

    code += '\n'

    for function in api.functions:

      if getattr(function,'regalOnly',False)==True:
        continue

      name   = function.name
      params = paramsDefaultCode(function.parameters, True)
      callParams = paramsNameCode(function.parameters)
      rType  = typeCode(function.ret.type)
      category  = getattr(function, 'category', None)
      version   = getattr(function, 'version', None)

      if category:
        category = category.replace('_DEPRECATED', '')
      elif version:
        category = version.replace('.', '_')
        category = 'GL_VERSION_' + category

      # Close prev category block.
      if categoryPrev and not (category == categoryPrev):
        code += '\n'

      # Begin new category block.
      if category and not (category == categoryPrev):
        code += '// %s\n\n' % category

      categoryPrev = category

      code += 'static %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'GLX_', name, params)

      if not function.needsContext:
        code += '    DispatchTableGlobal *_next = dispatcherGlobal.glx.next();\n'

      code += '    RegalAssert(_next);\n'

      match = emuFindEntry(function,formulae,None)
      if match and 'impl' in match:
#       print match
        code += listToString(indent(match['impl'],'    '))

      code += '    '
      if not typeIsVoid(rType):
        code += '%s ret = '%(rType)
      code += '_next->call(&_next->%s)(%s);\n' % ( name, callParams )

      if not typeIsVoid(rType):
        code += '    return ret;\n'
      code += '}\n\n'

    code += '\n'

  # Close pending if block.
  if categoryPrev:
    code += '\n'

  # Output

  substitute = {}
  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['COPYRIGHT']       = args.copyright
  substitute['API_FUNC_DEFINE'] = code
  substitute['API_GL_DISPATCH_INIT']     = apiDispatchFuncInitCode( apis, args, 'GLX', [], filterGLX )
  substitute['API_GLOBAL_DISPATCH_INIT'] = apiDispatchGlobalFuncInitCode( apis, args, 'GLX', [], filterGLX )

  outputCode( '%s/RegalDispatchGLX.cpp' % args.srcdir, dispatchGLXTemplate.substitute(substitute))
Exemplo n.º 10
0
def generateDispatchHttp(apis, args):

  # CodeGen for API functions.

  code = ''
  categoryPrev = None

  for api in apis:

    code += '\n'
    if api.name in cond:
      code += '#if %s\n' % cond[api.name]

    for function in api.functions:

      if getattr(function,'regalOnly',False)==True:
        continue

      name   = function.name
      params = paramsDefaultCode(function.parameters, True)
      callParams = paramsNameCode(function.parameters)
      rType  = typeCode(function.ret.type)
      rTypes    = rType.strip()
      category  = getattr(function, 'category', None)
      version   = getattr(function, 'version', None)

      if category:
        category = category.replace('_DEPRECATED', '')
      elif version:
        category = version.replace('.', '_')
        category = 'GL_VERSION_' + category

      # Close prev category block.
      if categoryPrev and not (category == categoryPrev):
        code += '\n'

      # Begin new category block.
      if category and not (category == categoryPrev):
        code += '// %s\n\n' % category

      categoryPrev = category

      code += 'static %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'http_', name, params)

      generated = dispatchGenCode( function, formulae )

      retInit = ''
      if not typeIsVoid(rType):
        if rTypes in api.defaults:
          retInit += '%s' % ( api.defaults[rTypes] )
        else:
          if rType[-1]=='*' or typeIsVoidPointer(rType):
            retInit += 'NULL'
          else:
            retInit += '(%s) 0' % ( rTypes )

      if not typeIsVoid(rType):
        code += '    %s ret = %s;\n' % (rType, retInit)
      code += '    RegalContext *_context = REGAL_GET_CONTEXT();\n'
      if function.needsContext:
        code += '    RegalAssert( _context );\n'

      code += '    if( _context ) {\n'
      if generated and 'pre' in generated:
        for i in generated['pre']:
          code += '      %s\n' % i

      code += '      if( _context->http.runState == RS_Next ) {\n'
      code += '        _context->http.runState = RS_Pause;\n'
      code += '      }\n'
      code += '      _context->http.YieldToHttpServer( _context );\n'

      code += '    }\n'

      if function.needsContext:
        code += '    DispatchTableGL *_next = _context ? _context->dispatcher.http.next() : NULL;\n'
      else:
        code += '    DispatchTableGlobal *_next = dispatcherGlobal.http.next();\n'

      code += '    RegalAssert(_next);\n'

      code += '    '

      if not typeIsVoid(rType):
        code += 'ret = '
      code += '_next->call(&_next->%s)(%s);\n' % ( name, callParams )

      if generated and 'post' in generated:
        code += '    if( _context ) {\n'
        for i in generated['post']:
          code += '      %s\n' % i
        code += '    }\n'

      if not typeIsVoid(rType):
        code += '    return ret;\n'
      code += '}\n\n'

    if api.name in cond:
      code += '#endif // %s\n' % cond[api.name]
    code += '\n'

  # Close pending if block.
  if categoryPrev:
    code += '\n'

  # Output

  substitute = {}
  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['COPYRIGHT']       = args.copyright
  substitute['API_FUNC_DEFINE'] = code
  substitute['API_GL_DISPATCH_INIT']     = apiDispatchFuncInitCode( apis, args, 'http' )
  substitute['API_GLOBAL_DISPATCH_INIT'] = apiDispatchGlobalFuncInitCode( apis, args, 'http' )

  outputCode( '%s/RegalDispatchHttp.cpp' % args.srcdir, dispatchHttpTemplate.substitute(substitute))
def generateDispatchGLX(apis, args):

    # CodeGen for API functions.

    code = ''
    categoryPrev = None

    for api in apis:

        if api.name != 'glx':
            continue

        code += '\n'

        for function in api.functions:

            if getattr(function, 'regalOnly', False) == True:
                continue

            name = function.name
            params = paramsDefaultCode(function.parameters, True)
            callParams = paramsNameCode(function.parameters)
            rType = typeCode(function.ret.type)
            category = getattr(function, 'category', None)
            version = getattr(function, 'version', None)

            if category:
                category = category.replace('_DEPRECATED', '')
            elif version:
                category = version.replace('.', '_')
                category = 'GL_VERSION_' + category

            # Close prev category block.
            if categoryPrev and not (category == categoryPrev):
                code += '\n'

            # Begin new category block.
            if category and not (category == categoryPrev):
                code += '// %s\n\n' % category

            categoryPrev = category

            code += 'static %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'GLX_',
                                                            name, params)

            if not function.needsContext:
                code += '    DispatchTableGlobal *_next = dispatcherGlobal.glx.next();\n'

            code += '    RegalAssert(_next);\n'

            match = emuFindEntry(function, formulae, None)
            if match and 'impl' in match:
                #       print match
                code += listToString(indent(match['impl'], '    '))

            code += '    '
            if not typeIsVoid(rType):
                code += '%s ret = ' % (rType)
            code += '_next->call(&_next->%s)(%s);\n' % (name, callParams)

            if not typeIsVoid(rType):
                code += '    return ret;\n'
            code += '}\n\n'

        code += '\n'

    # Close pending if block.
    if categoryPrev:
        code += '\n'

    # Output

    substitute = {}
    substitute['LICENSE'] = args.license
    substitute['AUTOGENERATED'] = args.generated
    substitute['COPYRIGHT'] = args.copyright
    substitute['API_FUNC_DEFINE'] = code
    substitute['API_GL_DISPATCH_INIT'] = apiDispatchFuncInitCode(
        apis, args, 'GLX', [], filterGLX)
    substitute['API_GLOBAL_DISPATCH_INIT'] = apiDispatchGlobalFuncInitCode(
        apis, args, 'GLX', [], filterGLX)

    outputCode('%s/RegalDispatchGLX.cpp' % args.srcdir,
               dispatchGLXTemplate.substitute(substitute))
def generateDispatchHttp(apis, args):

    # CodeGen for API functions.

    code = ''
    categoryPrev = None

    for api in apis:

        code += '\n'
        if api.name in cond:
            code += '#if %s\n' % cond[api.name]

        for function in api.functions:

            if getattr(function, 'regalOnly', False) == True:
                continue

            name = function.name
            params = paramsDefaultCode(function.parameters, True)
            callParams = paramsNameCode(function.parameters)
            rType = typeCode(function.ret.type)
            rTypes = rType.strip()
            category = getattr(function, 'category', None)
            version = getattr(function, 'version', None)

            if category:
                category = category.replace('_DEPRECATED', '')
            elif version:
                category = version.replace('.', '_')
                category = 'GL_VERSION_' + category

            # Close prev category block.
            if categoryPrev and not (category == categoryPrev):
                code += '\n'

            # Begin new category block.
            if category and not (category == categoryPrev):
                code += '// %s\n\n' % category

            categoryPrev = category

            code += 'static %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'http_',
                                                            name, params)

            generated = dispatchGenCode(function, formulae)

            retInit = ''
            if not typeIsVoid(rType):
                if rTypes in api.defaults:
                    retInit += '%s' % (api.defaults[rTypes])
                else:
                    if rType[-1] == '*' or typeIsVoidPointer(rType):
                        retInit += 'NULL'
                    else:
                        retInit += '(%s) 0' % (rTypes)

            if not typeIsVoid(rType):
                code += '    %s ret = %s;\n' % (rType, retInit)
            code += '    RegalContext *_context = REGAL_GET_CONTEXT();\n'
            if function.needsContext:
                code += '    RegalAssert( _context );\n'

            code += '    if( _context ) {\n'
            if generated and 'pre' in generated:
                for i in generated['pre']:
                    code += '      %s\n' % i

            code += '#if REGAL_HTTP\n'
            code += '      if( _context->http.runState == RS_Next ) {\n'
            code += '        _context->http.runState = RS_Pause;\n'
            code += '      }\n'
            code += '      _context->http.YieldToHttpServer( _context );\n'
            code += '#endif\n'

            code += '    }\n'

            code += '#if REGAL_HTTP\n'

            if function.needsContext:
                code += '    DispatchTableGL *_next = _context ? _context->dispatcher.http.next() : NULL;\n'
            else:
                code += '    DispatchTableGlobal *_next = dispatcherGlobal.http.next();\n'

            code += '    RegalAssert(_next);\n'

            code += '    '

            if not typeIsVoid(rType):
                code += 'ret = '
            code += '_next->call(&_next->%s)(%s);\n' % (name, callParams)

            code += '#endif\n'

            if generated and 'post' in generated:
                code += '    if( _context ) {\n'
                for i in generated['post']:
                    code += '      %s\n' % i
                code += '    }\n'

            if not typeIsVoid(rType):
                code += '    return ret;\n'
            code += '}\n\n'

        if api.name in cond:
            code += '#endif // %s\n' % cond[api.name]
        code += '\n'

    # Close pending if block.
    if categoryPrev:
        code += '\n'

    # Output

    substitute = {}
    substitute['LICENSE'] = args.license
    substitute['AUTOGENERATED'] = args.generated
    substitute['COPYRIGHT'] = args.copyright
    substitute['API_FUNC_DEFINE'] = code
    substitute['API_GL_DISPATCH_INIT'] = apiDispatchFuncInitCode(
        apis, args, 'http')
    substitute['API_GLOBAL_DISPATCH_INIT'] = apiDispatchGlobalFuncInitCode(
        apis, args, 'http')

    outputCode('%s/RegalDispatchHttp.cpp' % args.srcdir,
               dispatchHttpTemplate.substitute(substitute))
Exemplo n.º 13
0
def generateDispatchLog(apis, args):

  # CodeGen for API functions.

  code = ''
  categoryPrev = None

  for api in apis:

    code += '\n'
    if api.name in cond:
      code += '#if %s\n' % cond[api.name]

    for function in api.functions:

      if getattr(function,'regalOnly',False)==True:
        continue

      name   = function.name
      params = paramsDefaultCode(function.parameters, True)
      callParams = paramsNameCode(function.parameters)
      rType  = typeCode(function.ret.type)
      category  = getattr(function, 'category', None)
      version   = getattr(function, 'version', None)

      if category:
        category = category.replace('_DEPRECATED', '')
      elif version:
        category = version.replace('.', '_')
        category = 'GL_VERSION_' + category

      # Close prev category block.
      if categoryPrev and not (category == categoryPrev):
        code += '\n'

      # Begin new category block.
      if category and not (category == categoryPrev):
        code += '// %s\n\n' % category

      categoryPrev = category

      code += 'static %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'log_', name, params)
#     code += '    %s\n' % logFunction( function, 'Driver', True, False )

      if function.needsContext:
        code += '    RegalContext *_context = REGAL_GET_CONTEXT();\n'
        code += '    RegalAssert(_context);\n'

      # Temporarily adjust the context begin/end depth for proper indentation
      # of the glBegin call

      if name=='glBegin':
        code += '    RegalAssert(_context->depthBeginEnd>0);\n'
        code += '    Push<size_t> pushDepth(_context->depthBeginEnd);\n'
        code += '    _context->depthBeginEnd--;\n'

      # Temporarily adjust the context push/pop matrix depth for proper indentation
      # of the glPushMatrix call

      if name=='glPushMatrix':
        code += '    RegalAssert(_context->depthPushMatrix>0);\n'
        code += '    Push<size_t> pushDepth(_context->depthPushMatrix);\n'
        code += '    _context->depthPushMatrix--;\n'

      # Temporarily adjust the depth for proper indentation
      # of the glNewList call

      if name=='glNewList':
        code += '    RegalAssert(_context->depthNewList>0);\n'
        code += '    Push<size_t> pushDepth(_context->depthNewList);\n'
        code += '    _context->depthNewList--;\n'

      if function.needsContext:
        code += '    DispatchTableGL *_next = _context->dispatcher.logging.next();\n'
      else:
        code += '    DispatchTableGlobal *_next = dispatcherGlobal.logging.next();\n'

      code += '    RegalAssert(_next);\n'
      code += '    '
      if not typeIsVoid(rType):
        code += '%s ret = '%(rType)
      code += '_next->call(&_next->%s)(%s);\n' % ( name, callParams )

      if typeIsVoid(rType):
        code += '    %s\n' % logFunction( function, 'Driver', True, True )
      else:
        code += '    %s\n' % logFunction( function, 'Driver', True, True, True )

      # Special handling for glUseProgram - log the attached shaders.

      if name=='glUseProgram':
        code += '    #if !REGAL_SYS_PPAPI\n'
        code += '    if (Logging::enableDriver && program && log_glIsProgram(program))\n'
        code += '    {\n'
        code += '      GLuint  _shaders[16];\n'
        code += '      GLsizei _count;\n'
        code += '      log_glGetAttachedShaders(program,16,&_count,_shaders);\n'
        code += '    }\n'
        code += '    #endif // REGAL_SYS_PPAPI\n'

      if not typeIsVoid(rType):
        code += '    return ret;\n'
      code += '}\n\n'

    if api.name in cond:
      code += '#endif // %s\n' % cond[api.name]
    code += '\n'

  # Close pending if block.
  if categoryPrev:
    code += '\n'

  # Output

  substitute = {}
  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['COPYRIGHT']       = args.copyright
  substitute['API_FUNC_DEFINE'] = code
  substitute['API_GL_DISPATCH_INIT']     = apiDispatchFuncInitCode( apis, args, 'log' )
  substitute['API_GLOBAL_DISPATCH_INIT'] = apiDispatchGlobalFuncInitCode( apis, args, 'log' )

  outputCode( '%s/RegalDispatchLog.cpp' % args.srcdir, dispatchLogTemplate.substitute(substitute))
Exemplo n.º 14
0
def generateDispatchLog(apis, args):

    # CodeGen for API functions.

    code = ''
    categoryPrev = None

    for api in apis:

        code += '\n'
        if api.name in cond:
            code += '#if %s\n' % cond[api.name]

        for function in api.functions:

            if getattr(function, 'regalOnly', False) == True:
                continue

            name = function.name
            params = paramsDefaultCode(function.parameters, True)
            callParams = paramsNameCode(function.parameters)
            rType = typeCode(function.ret.type)
            category = getattr(function, 'category', None)
            version = getattr(function, 'version', None)

            if category:
                category = category.replace('_DEPRECATED', '')
            elif version:
                category = version.replace('.', '_')
                category = 'GL_VERSION_' + category

            # Close prev category block.
            if categoryPrev and not (category == categoryPrev):
                code += '\n'

            # Begin new category block.
            if category and not (category == categoryPrev):
                code += '// %s\n\n' % category

            categoryPrev = category

            code += 'static %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'log_',
                                                            name, params)
            #     code += '    %s\n' % logFunction( function, 'Driver', True, False )

            if function.needsContext:
                code += '    RegalContext *_context = REGAL_GET_CONTEXT();\n'
                code += '    RegalAssert(_context);\n'

            # Temporarily adjust the context begin/end depth for proper indentation
            # of the glBegin call

            if name == 'glBegin':
                code += '    RegalAssert(_context->depthBeginEnd>0);\n'
                code += '    Push<size_t> pushDepth(_context->depthBeginEnd);\n'
                code += '    _context->depthBeginEnd--;\n'

            # Temporarily adjust the context push/pop matrix depth for proper indentation
            # of the glPushMatrix call

            if name == 'glPushMatrix':
                code += '    RegalAssert(_context->depthPushMatrix>0);\n'
                code += '    Push<size_t> pushDepth(_context->depthPushMatrix);\n'
                code += '    _context->depthPushMatrix--;\n'

            # Temporarily adjust the depth for proper indentation
            # of the glNewList call

            if name == 'glNewList':
                code += '    RegalAssert(_context->depthNewList>0);\n'
                code += '    Push<size_t> pushDepth(_context->depthNewList);\n'
                code += '    _context->depthNewList--;\n'

            if function.needsContext:
                code += '    DispatchTableGL *_next = _context->dispatcher.logging.next();\n'
            else:
                code += '    DispatchTableGlobal *_next = dispatcherGlobal.logging.next();\n'

            code += '    RegalAssert(_next);\n'
            code += '    '
            if not typeIsVoid(rType):
                code += '%s ret = ' % (rType)
            code += '_next->call(&_next->%s)(%s);\n' % (name, callParams)

            if typeIsVoid(rType):
                code += '    %s\n' % logFunction(function, 'Driver', True,
                                                 True)
            else:
                code += '    %s\n' % logFunction(function, 'Driver', True,
                                                 True, True)

            # Special handling for glUseProgram - log the attached shaders.

            if name == 'glUseProgram':
                code += '    #if !REGAL_SYS_PPAPI\n'
                code += '    if (Logging::enableDriver && program && log_glIsProgram(program))\n'
                code += '    {\n'
                code += '      GLuint  _shaders[16];\n'
                code += '      GLsizei _count;\n'
                code += '      log_glGetAttachedShaders(program,16,&_count,_shaders);\n'
                code += '    }\n'
                code += '    #endif // REGAL_SYS_PPAPI\n'

            if not typeIsVoid(rType):
                code += '    return ret;\n'
            code += '}\n\n'

        if api.name in cond:
            code += '#endif // %s\n' % cond[api.name]
        code += '\n'

    # Close pending if block.
    if categoryPrev:
        code += '\n'

    # Output

    substitute = {}
    substitute['LICENSE'] = args.license
    substitute['AUTOGENERATED'] = args.generated
    substitute['COPYRIGHT'] = args.copyright
    substitute['API_FUNC_DEFINE'] = code
    substitute['API_GL_DISPATCH_INIT'] = apiDispatchFuncInitCode(
        apis, args, 'log')
    substitute['API_GLOBAL_DISPATCH_INIT'] = apiDispatchGlobalFuncInitCode(
        apis, args, 'log')

    outputCode('%s/RegalDispatchLog.cpp' % args.srcdir,
               dispatchLogTemplate.substitute(substitute))