コード例 #1
0
def apiPpapiFuncDefineCode(apis, args):

    code = ''

    for api in apis:

        if api.name == 'gl':

            for function in api.functions:
                if not function.needsContext:
                    continue
                if getattr(function, 'esVersions',
                           None) == None or 2.0 not in function.esVersions:
                    continue
                if getattr(function, 'regalOnly', False) == True:
                    continue

                name = function.name
                params = paramsDefaultCode(function.parameters, True)
                callParams = paramsNameCode(function.parameters)

                # Workaround for const difference between Regal.h and Pepper API

                if function.name == 'glShaderSource':
                    callParams = callParams.replace(
                        ', string,', ',const_cast<const GLchar **>(string),')

                rType = typeCode(function.ret.type)
                ppapiName = name
                if ppapiName.startswith('gl'):
                    ppapiName = ppapiName[2:]

                code += 'static %sREGAL_CALL %s%s(%s) \n{\n' % (
                    rType, 'ppapi_', name, params)
                code += '  Internal("ppapi_%s","()");\n' % name
                code += '  RegalContext * rCtx = REGAL_GET_CONTEXT();\n'
                code += '  RegalAssert(rCtx)\n'
                code += '  RegalAssert(rCtx->ppapiES2)\n'
                code += '  RegalAssert(rCtx->ppapiES2->%s)\n' % (ppapiName)
                code += '  RegalAssert(rCtx->ppapiResource)\n'
                if not typeIsVoid(rType):
                    code += '  %s ret = ' % rType
                else:
                    code += '  '
                if len(callParams):
                    callParams = 'rCtx->ppapiResource, %s' % callParams
                else:
                    callParams = 'rCtx->ppapiResource'
                code += 'rCtx->ppapiES2->%s(%s);\n' % (ppapiName, callParams)
                if not typeIsVoid(rType):
                    code += '  return ret;\n'
                code += '}\n\n'

    return code
コード例 #2
0
ファイル: RegalDispatchPpapi.py プロジェクト: LosingLin/regal
def apiPpapiFuncDefineCode(apis, args):

  code = ''

  for api in apis:

    if api.name=='gl':

      for function in api.functions:
        if not function.needsContext:
          continue
        if getattr(function,'esVersions',None)==None or 2.0 not in function.esVersions:
          continue
        if getattr(function,'regalOnly',False)==True:
          continue

        name   = function.name
        params = paramsDefaultCode(function.parameters, True)
        callParams = paramsNameCode(function.parameters)

        # Workaround for const difference between Regal.h and Pepper API

        if function.name=='glShaderSource':
          callParams = callParams.replace(', string,',',const_cast<const GLchar **>(string),')

        rType  = typeCode(function.ret.type)
        ppapiName = name
        if ppapiName.startswith('gl'):
          ppapiName = ppapiName[2:]

        code += 'static %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'ppapi_', name, params)
        code += '  Internal("ppapi_%s","()");\n' % name
        code += '  RegalContext * rCtx = REGAL_GET_CONTEXT();\n'
        code += '  RegalAssert(rCtx)\n'
        code += '  RegalAssert(rCtx->ppapiES2)\n'
        code += '  RegalAssert(rCtx->ppapiES2->%s)\n'%(ppapiName)
        code += '  RegalAssert(rCtx->ppapiResource)\n'
        if not typeIsVoid(rType):
          code += '  %s ret = ' % rType
        else:
          code += '  '
        if len(callParams):
          callParams = 'rCtx->ppapiResource, %s'%callParams
        else:
          callParams = 'rCtx->ppapiResource'
        code += 'rCtx->ppapiES2->%s(%s);\n' % ( ppapiName, callParams )
        if not typeIsVoid(rType):
          code += '  return ret;\n'
        code += '}\n\n'

  return code
コード例 #3
0
ファイル: RegalDispatchNacl.py プロジェクト: kmixter/regal
def apiNaclFuncDefineCode(apis, args):

    code = ''

    for api in apis:

        if api.name == 'gl':

            for function in api.functions:
                if not function.needsContext:
                    continue
                if getattr(function, 'esVersions',
                           None) == None or 2.0 not in function.esVersions:
                    continue
                if getattr(function, 'regalOnly', False) == True:
                    continue

                name = function.name
                params = paramsDefaultCode(function.parameters, True)
                callParams = paramsNameCode(function.parameters)
                rType = typeCode(function.ret.type)
                naclName = name
                if naclName.startswith('gl'):
                    naclName = naclName[2:]

                code += 'static %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'nacl_',
                                                                name, params)
                code += '  Internal("nacl_%s","()");\n' % name
                code += '  RegalContext * rCtx = GET_REGAL_CONTEXT();\n'
                code += '  RegalAssert(rCtx)\n'
                code += '  RegalAssert(rCtx->naclES2)\n'
                code += '  RegalAssert(rCtx->naclES2->%s)\n' % (naclName)
                code += '  RegalAssert(rCtx->naclResource)\n'
                if not typeIsVoid(rType):
                    code += '  %s ret = ' % rType
                else:
                    code += '  '
                if len(callParams):
                    callParams = 'rCtx->naclResource, %s' % callParams
                else:
                    callParams = 'rCtx->naclResource'
                code += 'rCtx->naclES2->%s(%s);\n' % (naclName, callParams)
                if not typeIsVoid(rType):
                    code += '  return ret;\n'
                code += '}\n\n'

    return code
コード例 #4
0
ファイル: RegalDispatchMissing.py プロジェクト: kmixter/regal
def apiMissingFuncDefineCode(apis, args):

    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 not function.needsContext:
                continue

            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 += '%sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'missing_', name,
                                                     params)
            for param in function.parameters:
                code += '  UNUSED_PARAMETER(%s);\n' % param.name
            code += '  Warning( "%s not available." );\n' % name
            if not typeIsVoid(rType):
                if rType[-1] != '*':
                    code += '  return (%s)0;\n' % (rType)
                else:
                    code += '  return NULL;\n'
            code += '}\n\n'

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

    return code
コード例 #5
0
def apiMissingFuncDefineCode(apis, args):

  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 not function.needsContext:
        continue

      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, 'missing_', name, params)
      for param in function.parameters:
        code += '  UNUSED_PARAMETER(%s);\n' % param.name
      code += '  Warning( "%s not available." );\n' % name
      if not typeIsVoid(rType):
        if rType[-1] != '*':
          code += '  return (%s)0;\n' % ( rType )
        else:
          code += '  return NULL;\n'
      code += '}\n\n'

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

  return code
コード例 #6
0
def apiNaclFuncDefineCode(apis, args):

  code = ''

  for api in apis:

    if api.name=='gl':

      for function in api.functions:
        if not function.needsContext:
          continue
        if getattr(function,'esVersions',None)==None or 2.0 not in function.esVersions:
          continue
        if getattr(function,'regalOnly',False)==True:
          continue

        name   = function.name
        params = paramsDefaultCode(function.parameters, True)
        callParams = paramsNameCode(function.parameters)
        rType  = typeCode(function.ret.type)
        naclName = name
        if naclName.startswith('gl'):
          naclName = naclName[2:]

        code += 'static %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'nacl_', name, params)
        code += '  Internal("nacl_%s","()");\n' % name
        code += '  RegalContext * rCtx = GET_REGAL_CONTEXT();\n'
        code += '  RegalAssert(rCtx)\n'
        code += '  RegalAssert(rCtx->naclES2)\n'
        code += '  RegalAssert(rCtx->naclES2->%s)\n'%(naclName)
        code += '  RegalAssert(rCtx->naclResource)\n'
        if not typeIsVoid(rType):
          code += '  %s ret = ' % rType
        else:
          code += '  '
        if len(callParams):
          callParams = 'rCtx->naclResource, %s'%callParams
        else:
          callParams = 'rCtx->naclResource'
        code += 'rCtx->naclES2->%s(%s);\n' % ( naclName, callParams )
        if not typeIsVoid(rType):
          code += '  return ret;\n'
        code += '}\n\n'

  return code
コード例 #7
0
def apiEmuFuncDefineCode(apis, args):
    categoryPrev = None
    code = ''

    for api in apis:

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

        for function in api.functions:
            if not function.needsContext:
                continue
            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

            emue = [
                emuFindEntry(function, i['formulae'], i['member']) for i in emu
            ]

            if all(i is None for i in emue) and (
                    getattr(function, 'regalRemap', None) == None
                    or isinstance(function.regalRemap, str)
                    or isinstance(function.regalRemap, unicode)):
                continue

            code += '\nstatic %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'emu_',
                                                              name, params)
            code += '   RegalContext *_context = GET_REGAL_CONTEXT();\n'
            code += '   RegalAssert(_context);\n'
            code += '\n'

            level = [(emu[i],
                      emuFindEntry(function, emu[i]['formulae'],
                                   emu[i]['member']))
                     for i in range(len(emue) - 1)]

            if not all(
                    i[1] == None or not 'prefix' in i[1] and not 'impl' in i[1]
                    for i in level):
                code += '   // prefix\n'
                code += '   switch( _context->emuLevel ) {\n'
                for i in level:
                    l, e = i[0], i[1]
                    code += '       case %d :\n' % l['level']
                    if l['ifdef']:
                        code += '         #if %s\n' % l['ifdef']
                    if e != None and 'prefix' in e and len(e['prefix']):
                        if l['member']:
                            code += '         if (_context->%s) {\n' % l[
                                'member']
                            code += '           Push<int> pushLevel(_context->emuLevel);\n'
                            code += '           _context->emuLevel = %d;\n' % (
                                int(l['level']) - 1)
                        for j in e['prefix']:
                            code += '           %s\n' % j
                        if l['member']:
                            code += '         }\n'
                    if e != None and 'impl' in e and l['member']:
                        code += '         if (_context->%s) break;\n' % l[
                            'member']
                    if l['ifdef']:
                        code += '         #endif\n'
                code += '       default:\n'
                code += '           break;\n'
                code += '   }\n\n'

            # Remap, as necessary
            remap = getattr(function, 'regalRemap', None)
            es2Name = None
            if remap != None:
                es2Name = remap.get('ES2.0', None)
                es2Params = callParams
                if es2Name != None:
                    j = es2Name.find('(')
                    if j != -1:
                        es2Params = es2Name[j + 1:-1]
                        es2Name = es2Name[0:j]

            if not all(i[1] == None or not 'impl' in i[1] for i in level):
                code += '   // impl\n'
                code += '   switch( _context->emuLevel ) {\n'
                for i in level:
                    l, e = i[0], i[1]
                    code += '       case %d :\n' % l['level']
                    if l['ifdef']:
                        code += '         #if %s\n' % l['ifdef']
                    if e != None and 'impl' in e and len(e['impl']):
                        if l['member']:
                            code += '         if (_context->%s) {\n' % l[
                                'member']
                            code += '           Push<int> pushLevel(_context->emuLevel);\n'
                            code += '           _context->emuLevel = %d;\n' % (
                                int(l['level']) - 1)
                        for j in e['impl']:
                            code += '           %s\n' % j
                        if l['member']:
                            if typeIsVoid(rType):
                                code += '           return;\n'
                            code += '         }\n'
                    if l['ifdef']:
                        code += '         #endif\n'
                code += '       default: {\n'

                # glEnable/glDisable/glIsEnabled constraints for ES 2.0
                # http://www.khronos.org/opengles/sdk/docs/man/xhtml/glEnable.xml

                if name == 'glEnable' or name == 'glDisable' or name == 'glIsEnabled':
                    code += '         if (_context->info->gles)\n'
                    code += '           switch (cap)\n'
                    code += '           {\n'
                    for i in api.enums:
                        if i.name == 'defines':
                            for j in i.enumerants:
                                if getattr(
                                        j, 'esVersions', None
                                ) != None and getattr(
                                        j, 'enableCap', None
                                ) != None and 2.0 in j.esVersions and j.enableCap == True:
                                    code += '             case %s:\n' % (
                                        j.name)
                    code += '               break;\n'
                    code += '             default:\n'
                    code += '               Warning("%s does not support ",GLenumToString(cap)," for ES 2.0.");\n' % (
                        name)
                    if name == 'glIsEnabled':
                        code += '               return GL_FALSE;\n'
                    else:
                        code += '               return;\n'
                    code += '           }\n'

                # glHint constraints for ES 2.0
                # http://www.khronos.org/opengles/sdk/docs/man/xhtml/glHint.xml

                if name == 'glHint':
                    code += '         if (_context->info->gles)\n'
                    code += '           switch (target)\n'
                    code += '           {\n'
                    for i in api.enums:
                        if i.name == 'defines':
                            for j in i.enumerants:
                                if getattr(j, 'esVersions', None) == None:
                                    continue
                                if getattr(j, 'hint', None) == None:
                                    continue
                                if getattr(
                                        j, 'esVersions', None
                                ) != None and getattr(
                                        j, 'hint', None
                                ) != None and 2.0 in j.esVersions and j.hint == True:
                                    code += '             case %s:\n' % (
                                        j.name)
                    code += '               break;\n'
                    code += '             default:\n'
                    code += '               Warning("%s does not support ",GLenumToString(target)," for ES 2.0.");\n' % (
                        name)
                    code += '               return;\n'
                    code += '           }\n'

                code += '         DispatchTable *_next = _context->dispatcher.emulation._next;\n'
                code += '         RegalAssert(_next);\n'

                if es2Name != None:
                    code += '         '
                    code += 'if (_context->info->gles)\n'
                    code += '         '
                    if not typeIsVoid(rType):
                        code += '  return '
                    code += '  _next->call(&_next->%s)(%s);\n' % (es2Name,
                                                                  es2Params)
                    code += '         else\n  '

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

                code += '         break;\n'
                code += '       }\n\n'
                code += '   }\n\n'
            else:
                code += '   DispatchTable *_next = _context->dispatcher.emulation._next;\n'
                code += '   RegalAssert(_next);\n'
                code += '   '

                if es2Name != None:
                    code += 'if (_context->info->gles)\n'
                    code += '     '
                    if not typeIsVoid(rType):
                        code += 'return '
                    code += ' _next->call(& _next->%s)(%s);\n' % (es2Name,
                                                                  es2Params)
                    code += '   else\n     '

                if not typeIsVoid(rType):
                    code += 'return '
                code += ' _next->call(& _next->%s)(%s);\n' % (name, callParams)
            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'

    return code
コード例 #8
0
def apiDebugFuncDefineCode(apis, args):
  categoryPrev = None
  code = ''

  for api in apis:

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

    for function in api.functions:
      if not function.needsContext:
        continue
      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, 'debug_', name, params)
      code += '  RegalContext *_context = GET_REGAL_CONTEXT();\n'
      code += '  RegalAssert(_context);\n'
      code += '  DispatchTable *_next = _context->dispatcher.debug._next;\n'
      code += '  RegalAssert(_next);\n'
      e = emuFindEntry( function, debugDispatchFormulae, '' )
      if e != None and 'prefix' in e :
        for l in e['prefix'] :
          code += '  %s\n' % l
      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'

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

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

  return code
コード例 #9
0
ファイル: Regal.py プロジェクト: hitpointstudios/regal
def apiFuncDefineCode(apis, args):

  code = ''
  for api in apis:

    tmp = []
    for function in api.functions:

      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

      c = ''
      c += 'REGAL_DECL %sREGAL_CALL %s(%s) \n{\n' % (rType, name, params)

      emue = [ emuFindEntry( function, i['formulae'], i['member'] ) for i in emuRegal ]

      if function.needsContext:
        c += '  RegalContext *_context = REGAL_GET_CONTEXT();\n'
        c += '  %s\n' % logFunction( function, 'App' )
        c += '  if (!_context) return'
        if typeIsVoid(rType):
          c += ';\n'
        else:
          if rType[-1] != '*':
            c += ' (%s)0;\n' % ( rType )
          else:
            c += ' NULL;\n'

        c += listToString(indent(emuCodeGen(emue,'impl'),'  '))

        if getattr(function,'regalRemap',None)!=None and (isinstance(function.regalRemap, list) or isinstance(function.regalRemap, str) or isinstance(function.regalRemap, unicode)):
          c += '  '
          if not typeIsVoid(rType):
            c += 'return '
          if isinstance(function.regalRemap, list):
            c += '\n  '.join(function.regalRemap) + '\n'
          else:
            c += '%s;\n'%(function.regalRemap)
        else:
          if getattr(function,'regalOnly',False)==False:
            c += '  DispatchTable *_next = &_context->dispatcher.front();\n'
            c += '  RegalAssert(_next);\n'

            c += listToString(indent(emuCodeGen(emue,'suffix'),'  '))

            c += '  '
            if not typeIsVoid(rType):
              c += 'return '
            c += '_next->call(&_next->%s)(%s);\n' % ( name, callParams )
      else:
        c += '  %s\n' % logFunction(function, 'App' )

        c += listToString(indent(emuCodeGen(emue,'prefix'),'  '))

        if api.name=='egl':
          c += '\n'
          c += '  #if !REGAL_STATIC_EGL\n'

        c += '  if (!dispatchTableGlobal.%s)\n' % name
        c += '  {\n'
        c += '    GetProcAddress( dispatchTableGlobal.%s, "%s" );\n' % ( name, name )
        c += '    RegalAssert(dispatchTableGlobal.%s!=%s);\n' % ( name, name )
        c += '    if (dispatchTableGlobal.%s==%s)\n' % ( name, name )
        c += '      dispatchTableGlobal.%s = NULL;\n' % ( name )
        c += '  }\n'

        if api.name=='egl':
          c += '  #endif // !REGAL_STATIC_EGL\n\n'

        if not typeIsVoid(rType):
          if rType[-1] != '*':
            c += '  %s ret = (%s)0;\n' % ( rType, rType )
          else:
            c += '  %s ret = NULL;\n' % rType

        c += listToString(indent(emuCodeGen(emue,'impl'),'  '))

        c += '  if (dispatchTableGlobal.%s)\n' % name
        c += '  {\n'
        c += '    %s\n' % logFunction( function, 'Driver' )
        c += '    '
        if not typeIsVoid(rType):
          c += 'ret = '
        c += 'dispatchTableGlobal.%s(%s);\n' % ( name, callParams )
        if name == 'wglMakeCurrent':
          c += '    Init::makeCurrent(RegalSystemContext(hglrc));\n'
        elif name == 'CGLSetCurrentContext':
          c += '    Init::makeCurrent( ctx );\n'
        elif name == 'glXMakeCurrent':
          c += '    Init::makeCurrent( RegalSystemContext(ctx) );\n'
        elif name == 'eglMakeCurrent':
          c += '    Init::makeCurrent( ctx );\n'
        elif name == 'wglDeleteContext':
          c += '    Init::destroyContext( RegalSystemContext(hglrc) );\n'
        elif name == 'CGLDestroyContext':
          c += '    Init::destroyContext( RegalSystemContext(ctx) );\n'
        elif name == 'glXDestroyContext':
          c += '    Init::destroyContext( RegalSystemContext(ctx) );\n'
        elif name == 'eglDestroyContext':
          c += '    Init::destroyContext( RegalSystemContext(ctx) );\n'
        c += '  }\n'
        c += '  else\n'
        c += '    Warning( "%s not available." );\n' % name

        c += listToString(indent(emuCodeGen(emue,'suffix'),'  '))

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

      tmp.append( (category, indent(c,'  ') ) )

    tmp = listToString(unfoldCategory(tmp,'  /* %s */'))

    if api.name in cond:
      tmp = wrapIf(cond[api.name], tmp)

    code += tmp

  return code
コード例 #10
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 not function.needsContext:
        continue
      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' % debugPrintFunction( function, 'Driver' )
      code += '    RegalContext *_context = GET_REGAL_CONTEXT();\n'
      code += '    RegalAssert(_context);\n'
      code += '    DispatchTable *_next = _context->dispatcher.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 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'

  funcInit   = apiDispatchFuncInitCode( apis, args, 'log' )

  # Output

  substitute = {}
  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['COPYRIGHT']       = args.copyright
  substitute['API_FUNC_DEFINE'] = code
  substitute['API_GLOBAL_DISPATCH_INIT'] = funcInit

  outputCode( '%s/RegalDispatchLog.cpp' % args.outdir, dispatchLogTemplate.substitute(substitute))
コード例 #11
0
def apiLoaderFuncDefineCode(apis, args):
  categoryPrev = None
  code = ''

  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, 'loader_', name, params)

      # Get a reference to the appropriate dispatch table and attempt GetProcAddress

      if function.needsContext:
        code += '  RegalContext * _context = REGAL_GET_CONTEXT();\n'
        code += '  RegalAssert(_context);\n'
        code += '  DispatchTableGL &_driver = _context->dispatcher.driver;\n'
      else:
        code += '  DispatchTableGlobal &_driver = dispatcherGlobal.driver;\n'

      code += '  GetProcAddress(_driver.%s, "%s");\n' % (name, name)

      # Check that Regal didn't load itself, somehow

      code += '  RegalAssert(_driver.%s!=%s);\n'%(name,name)
      code += '  if (_driver.%s==%s)\n'%(name,name)
      code += '    _driver.%s = NULL;\n'%(name)

      # Call the driver dispatch, if possible

      code += '  if (_driver.%s)\n' % name

      if typeIsVoid(rType):
        code += '  {\n    '
      else:
        code += '    return '
      code += '_driver.%s(%s);\n' % ( name, callParams )
      if typeIsVoid(rType):
        code += '    return;\n'
        code += '  }\n'

      if function.needsContext:
        code += '  DispatchTableGL *_next = _driver.next();\n'
      else:
        code += '  DispatchTableGlobal *_next = _driver.next();\n'

      code += '  RegalAssert(_next);\n'
      code += '  '
      if not typeIsVoid(rType):
        code += 'return '
      code += '_next->call(&_next->%s)(%s);\n'%(name, callParams)
      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'

  return code
コード例 #12
0
def apiLoaderFuncDefineCode(apis, args):
    categoryPrev = None
    code = ''

    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, 'loader_',
                                                            name, params)

            # Get a reference to the appropriate dispatch table and attempt GetProcAddress

            if function.needsContext:
                code += '  RegalContext * _context = REGAL_GET_CONTEXT();\n'
                code += '  RegalAssert(_context);\n'
                code += '  DispatchTableGL &_driver = _context->dispatcher.driver;\n'
            else:
                code += '  DispatchTableGlobal &_driver = dispatcherGlobal.driver;\n'

            code += '  GetProcAddress(_driver.%s, "%s");\n' % (name, name)

            # Check that Regal didn't load itself, somehow

            code += '  RegalAssert(_driver.%s!=%s);\n' % (name, name)
            code += '  if (_driver.%s==%s)\n' % (name, name)
            code += '    _driver.%s = NULL;\n' % (name)

            # Call the driver dispatch, if possible

            code += '  if (_driver.%s)\n' % name

            if typeIsVoid(rType):
                code += '  {\n    '
            else:
                code += '    return '
            code += '_driver.%s(%s);\n' % (name, callParams)
            if typeIsVoid(rType):
                code += '    return;\n'
                code += '  }\n'

            if function.needsContext:
                code += '  DispatchTableGL *_next = _driver.next();\n'
            else:
                code += '  DispatchTableGlobal *_next = _driver.next();\n'

            code += '  RegalAssert(_next);\n'
            code += '  '
            if not typeIsVoid(rType):
                code += 'return '
            code += '_next->call(&_next->%s)(%s);\n' % (name, callParams)
            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'

    return code
コード例 #13
0
def apiLoaderFuncDefineCode(apis, args):
    categoryPrev = None
    code = ''

    for api in apis:

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

        for function in api.functions:
            if not function.needsContext:
                continue
            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, 'loader_',
                                                            name, params)
            code += '  RegalContext * _context = GET_REGAL_CONTEXT();\n'
            code += '  RegalAssert(_context);\n'
            code += '  DispatchTable &_driver = _context->dispatcher.driver;\n'
            code += '  GetProcAddress(_driver.%s, "%s");\n' % (name, name)
            code += '  if (_driver.%s) {\n    ' % name
            if not typeIsVoid(rType):
                code += 'return '
            code += '_driver.%s(%s);\n' % (name, callParams)
            if typeIsVoid(rType):
                code += '    return;\n'
            code += '  }\n'
            code += '  DispatchTable *_next = _driver._next;\n'
            code += '  RegalAssert(_next);\n'
            code += '  '
            if not typeIsVoid(rType):
                code += 'return '
            code += '_next->call(&_next->%s)(%s);\n' % (name, callParams)
            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'

    return code
コード例 #14
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))
コード例 #15
0
ファイル: RegalDispatchEmu.py プロジェクト: quaxquax/regal
def apiEmuFuncDefineCode(apis, args):
    categoryPrev = None
    code = ""

    for api in apis:

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

        for function in api.functions:
            if not function.needsContext:
                continue
            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

            emue = [emuFindEntry(function, i["formulae"], i["member"]) for i in emu]

            if all(i is None for i in emue) and (
                getattr(function, "regalRemap", None) == None
                or isinstance(function.regalRemap, str)
                or isinstance(function.regalRemap, unicode)
            ):
                continue

            code += "\nstatic %sREGAL_CALL %s%s(%s) \n{\n" % (rType, "emu_", name, params)
            code += "  RegalContext *_context = REGAL_GET_CONTEXT();\n"
            code += "  RegalAssert(_context);\n"
            code += "  DispatchTableGL &_dispatch = _context->dispatcher.emulation;\n"
            code += "\n"

            level = [
                (emu[i], emuFindEntry(function, emu[i]["formulae"], emu[i]["member"])) for i in range(len(emue) - 1)
            ]

            # PREFIX

            if not all(i[1] == None or not "prefix" in i[1] and not "impl" in i[1] for i in level):
                code += "  // prefix\n"
                code += "  switch( _context->emuLevel )\n"
                code += "  {\n"
                for i in level:
                    l, e = i[0], i[1]
                    code += "    case %d :\n" % l["level"]
                    if l["ifdef"]:
                        code += "      #if %s\n" % l["ifdef"]
                    if e != None and "prefix" in e and len(e["prefix"]):

                        if l["member"]:
                            code += "      if (_context->%s)\n" % l["member"]
                            code += "      {\n"
                            code += "        Push<int> pushLevel(_context->emuLevel);\n"
                            code += "        _context->emuLevel = %d;\n" % (int(l["level"]) - 1)

                        if l["plugin"]:
                            code += "        #if REGAL_PLUGIN\n"
                            code += "        Thread::ThreadLocal &_instance = Thread::ThreadLocal::instance();\n"
                            code += "        Push<DispatchTableGL *> pushDispatchTable(_instance.nextDispatchTable);\n"
                            code += "        _instance.nextDispatchTable = &_context->dispatcher.emulation;\n"
                            code += "        #endif\n"

                        code += listToString(indent(e["prefix"], "        "))
                        if l["member"]:
                            code += "      }\n"
                    if e != None and "impl" in e and l["member"]:
                        code += "      if (_context->%s) break;\n" % l["member"]
                    if l["ifdef"]:
                        code += "      #endif\n"
                code += "    default:\n"
                code += "      break;\n"
                code += "  }\n\n"

            # Remap, as necessary
            remap = getattr(function, "regalRemap", None)
            es2Name = None
            if remap != None and isinstance(remap, dict):
                es2Name = remap.get("ES2.0", None)
                es2Params = callParams
                if es2Name != None:
                    j = es2Name.find("(")
                    if j != -1:
                        es2Params = es2Name[j + 1 : -1]
                        es2Name = es2Name[0:j]

            # IMPL

            if not all(i[1] == None or not "impl" in i[1] for i in level):
                code += "  // impl\n"
                code += "  switch( _context->emuLevel )\n"
                code += "  {\n"
                for i in level:
                    l, e = i[0], i[1]
                    code += "    case %d :\n" % l["level"]
                    if l["ifdef"]:
                        code += "      #if %s\n" % l["ifdef"]
                    if e != None and "impl" in e and len(e["impl"]):

                        if l["member"]:
                            code += "      if (_context->%s)\n" % l["member"]
                            code += "      {\n"
                            code += "        Push<int> pushLevel(_context->emuLevel);\n"
                            code += "        _context->emuLevel = %d;\n" % (int(l["level"]) - 1)

                        if l["plugin"]:
                            code += "        #if REGAL_PLUGIN\n"
                            code += "        Thread::ThreadLocal &_instance = Thread::ThreadLocal::instance();\n"
                            code += "        Push<DispatchTableGL *> pushDispatchTable(_instance.nextDispatchTable);\n"
                            code += "        _instance.nextDispatchTable = &_context->dispatcher.emulation;\n"
                            code += "        #endif\n"

                        code += listToString(indent(e["impl"], "        "))
                        if l["member"]:
                            if l["member"] != "filt" and typeIsVoid(rType):
                                code += "        return;\n"
                            code += "      }\n"
                    if l["ifdef"]:
                        code += "      #endif\n"
                code += "    default: \n"
                code += "    {\n"

                # glEnable/glDisable/glIsEnabled constraints for ES 2.0
                # http://www.khronos.org/opengles/sdk/docs/man/xhtml/glEnable.xml

                if name == "glEnable" or name == "glDisable" or name == "glIsEnabled":
                    code += "       if (_context->isES2())\n"
                    code += "         switch (cap)\n"
                    code += "         {\n"
                    for i in api.enums:
                        if i.name == "defines":
                            for j in i.enumerantsByName:
                                if (
                                    getattr(j, "esVersions", None) != None
                                    and getattr(j, "enableCap", None) != None
                                    and 2.0 in j.esVersions
                                    and j.enableCap == True
                                ):
                                    code += "           case %s:\n" % (j.name)
                    code += "             break;\n"
                    code += "           default:\n"
                    code += '             Warning("%s does not support ",GLenumToString(cap)," for ES 2.0.");\n' % (
                        name
                    )
                    if name == "glIsEnabled":
                        code += "             return GL_FALSE;\n"
                    else:
                        code += "             return;\n"
                    code += "         }\n"

                # glBindTexture constraints for ES 2.0
                # http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindTexture.xml

                if name == "glBindTexture":
                    code += "       if (_context->isES2())\n"
                    code += "         switch (target)\n"
                    code += "         {\n"
                    for i in api.enums:
                        if i.name == "defines":
                            for j in i.enumerantsByName:
                                if getattr(j, "esVersions", None) == None:
                                    continue
                                if getattr(j, "bindTexture", None) == None:
                                    continue
                                if 2.0 in j.esVersions and j.bindTexture == True:
                                    code += "           case %s:\n" % (j.name)
                    code += "             break;\n"
                    code += "           default:\n"
                    code += '             Warning("%s does not support ",GLenumToString(target)," for ES 2.0.");\n' % (
                        name
                    )
                    code += "             return;\n"
                    code += "         }\n"

                # glTexSubImage2D constraints for ES 2.0
                # http://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexSubImage2D.xml

                if name == "glTexSubImage2D":
                    code += "       if (_context->isES2())\n"
                    code += "         switch (target)\n"
                    code += "         {\n"
                    for i in api.enums:
                        if i.name == "defines":
                            for j in i.enumerantsByName:
                                if getattr(j, "esVersions", None) == None:
                                    continue
                                if getattr(j, "texImage", None) == None:
                                    continue
                                if 2.0 in j.esVersions and j.texImage:
                                    code += "           case %s:\n" % (j.name)
                    code += "             break;\n"
                    code += "           default:\n"
                    code += '             Warning("%s does not support ",GLenumToString(target)," for ES 2.0.");\n' % (
                        name
                    )
                    code += "             return;\n"
                    code += "         }\n"

                code += "      DispatchTableGL *_next = _dispatch.next();\n"
                code += "      RegalAssert(_next);\n"

                if es2Name != None:
                    code += "      "
                    code += "if (_context->isES2())\n"
                    code += "        "
                    if not typeIsVoid(rType):
                        code += "return "
                    code += "_next->call(&_next->%s)(%s);\n" % (es2Name, es2Params)
                    code += "      else\n  "

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

                code += "      break;\n"
                code += "    }\n\n"
                code += "  }\n\n"
            else:

                # glTexImage2D internalformat constraints for ES 2.0
                # http://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexImage2D.xml

                if name == "glTexImage2D":
                    code += "  if (_context->isES2())\n"
                    code += "  {\n"
                    code += "    switch (internalformat)\n"
                    code += "    {\n"
                    for i in api.enums:
                        if i.name == "defines":
                            for j in i.enumerantsByName:
                                if getattr(j, "esVersions", None) == None:
                                    continue
                                if getattr(j, "internalformat", None) == None:
                                    continue
                                if 2.0 in j.esVersions and j.internalformat == True:
                                    code += "      case %s:\n" % (j.name)
                    code += "        break;\n"
                    code += "      default:\n"
                    code += (
                        '        Warning("%s does not support ",GLenumToString(internalformat)," for ES 2.0.");\n'
                        % (name)
                    )
                    code += "        return;\n"
                    code += "    }\n"
                    code += "    if (format!=GLenum(internalformat))\n"
                    code += "    {\n"
                    code += (
                        '        Warning("%s does not support mismatching format and internalformat ",GLenumToString(format),"!=",GLenumToString(internalformat)," for ES 2.0.");\n'
                        % (name)
                    )
                    code += "        return;\n"
                    code += "    }\n"
                    code += "  }\n"

                code += "  DispatchTableGL *_next = _dispatch.next();\n"
                code += "  RegalAssert(_next);\n"
                code += "  "

                if es2Name != None:
                    code += "if (_context->isES2())\n"
                    code += "    "
                    if not typeIsVoid(rType):
                        code += "return "
                    code += "_next->call(& _next->%s)(%s);\n" % (es2Name, es2Params)
                    code += "   else\n     "

                if not typeIsVoid(rType):
                    code += "return "
                code += "_next->call(& _next->%s)(%s);\n" % (name, callParams)
            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"

    return code
コード例 #16
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 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))
コード例 #17
0
ファイル: Regal.py プロジェクト: phuang/regal
def apiFuncDefineCode(apis, args):

    #

    code = ""
    for api in apis:

        tmp = []
        for function in api.functions:

            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

            c = ""
            c += "REGAL_DECL %sREGAL_CALL %s(%s) \n{\n" % (rType, name, params)

            emue = [emuFindEntry(function, i["formulae"], i["member"]) for i in emuRegal]

            if function.needsContext:
                c += "  RegalContext *_context = REGAL_GET_CONTEXT();\n"
                c += listToString(indent(emuCodeGen(emue, "prefix"), "  "))
                c += "  %s\n" % logFunction(function, "App")
                c += "  if (!_context) return"
                if typeIsVoid(rType):
                    c += ";\n"
                else:
                    if rTypes in api.defaults:
                        c += " %s;\n" % (api.defaults[rTypes])
                    else:
                        if rType[-1] == "*" or typeIsVoidPointer(rType):
                            c += " NULL;\n"
                        else:
                            c += " (%s) 0;\n" % (rTypes)

                c += listToString(indent(emuCodeGen(emue, "impl"), "  "))

                if getattr(function, "regalRemap", None) != None and (
                    isinstance(function.regalRemap, list)
                    or isinstance(function.regalRemap, str)
                    or isinstance(function.regalRemap, unicode)
                ):

                    # For an ES1 context, pass the call into the dispatch layers...

                    if function.category in ["GL_REGAL_ES1_0_compatibility", "GL_REGAL_ES1_1_compatibility"]:
                        c += "  #if REGAL_SYS_ES1\n"
                        c += "  if (_context->isES1()) // Pass-through for ES1 only\n"
                        c += "  {\n"
                        c += "    DispatchTableGL *_next = &_context->dispatcher.front();\n"
                        c += "    RegalAssert(_next);\n    "
                        if not typeIsVoid(rType):
                            c += "return "
                        c += "_next->call(&_next->%s)(%s);\n" % (name, callParams)
                        if typeIsVoid(rType):
                            c += "    return;\n"
                        c += "  }\n"
                        c += "  #endif\n"

                    # For ES2 or GL context, remap the ES1 call

                    c += "  "
                    if not typeIsVoid(rType):
                        c += "return "
                    if isinstance(function.regalRemap, list):
                        c += "\n  ".join(function.regalRemap) + "\n"
                    else:
                        c += "%s;\n" % (function.regalRemap)
                else:
                    if getattr(function, "regalOnly", False) == False:
                        t = ""
                        t += "DispatchTableGL *_next = &_context->dispatcher.front();\n"
                        t += "RegalAssert(_next);\n"

                        t += listToString(indent(emuCodeGen(emue, "pre"), ""))

                        if not typeIsVoid(rType):
                            t += "return "
                        t += "_next->call(&_next->%s)(%s);\n" % (name, callParams)

                        t += listToString(indent(emuCodeGen(emue, "post"), ""))

                        for i in emue:
                            if i != None and i["cond"] != None:
                                t = wrapCIf(i["cond"], indent(t))

                        c += indent(t)

                        c += listToString(indent(emuCodeGen(emue, "suffix"), "  "))

            else:
                c += "  %s\n" % logFunction(function, "App")
                c += listToString(indent(emuCodeGen(emue, "prefix"), "  "))

                if getattr(function, "regalOnly", False) == False:
                    c += "  DispatchTableGlobal *_next = &dispatcherGlobal.front();\n"
                    c += "  RegalAssert(_next);\n"

                    if not typeIsVoid(rType):
                        if rTypes in api.defaults:
                            c += "  %s ret = %s;\n" % (rTypes, api.defaults[rTypes])
                        else:
                            if rType[-1] == "*" or typeIsVoidPointer(rType):
                                c += "  %s ret = NULL;\n" % rTypes
                            else:
                                c += "  %s ret = (%s) 0;\n" % (rTypes, rTypes)

                    c += listToString(indent(emuCodeGen(emue, "impl"), "  "))
                    c += "  "
                    if not typeIsVoid(rType):
                        c += "ret = "
                    c += "_next->call(&_next->%s)(%s);\n" % (name, callParams)

                c += listToString(indent(emuCodeGen(emue, "init"), "  "))

                c += listToString(indent(emuCodeGen(emue, "suffix"), "  "))
                if not typeIsVoid(rType):
                    c += "  return ret;\n"
            c += "}\n\n"

            tmp.append((category, indent(c, "  ")))

        tmp = listToString(unfoldCategory(tmp, "  /* %s */"))

        if api.name in cond:
            tmp = wrapIf(cond[api.name], tmp)

        code += tmp

    return code
コード例 #18
0
ファイル: RegalDispatchEmu.py プロジェクト: achienbsi/regal
def apiEmuFuncDefineCode(apis, args):
    categoryPrev = None
    code = ''

    for api in apis:

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

        for function in api.functions:
            if not function.needsContext:
                continue
            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

            emue = [ emuFindEntry( function, i['formulae'], i['member'] ) for i in emu ]

            if all(i is None for i in emue) and (getattr(function,'regalRemap',None)==None or isinstance(function.regalRemap, str) or isinstance(function.regalRemap, unicode)):
                continue

            code += '\nstatic %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'emu_', name, params)
            code += '  RegalContext *_context = REGAL_GET_CONTEXT();\n'
            code += '  RegalAssert(_context);\n'
            code += '  DispatchTable &_dispatch = _context->dispatcher.emulation;\n'
            code += '\n'

            level = [ (emu[i], emuFindEntry( function, emu[i]['formulae'], emu[i]['member'] )) for i in range( len( emue ) - 1 ) ]

            if not all(i[1]==None or not 'prefix' in i[1] and not 'impl' in i[1] for i in level):
              code += '  // prefix\n'
              code += '  switch( _context->emuLevel )\n'
              code += '  {\n'
              for i in level:
                  l,e = i[0], i[1]
                  code += '    case %d :\n' % l['level']
                  if l['ifdef']:
                      code += '      #if %s\n' % l['ifdef']
                  if e != None and 'prefix' in e and len(e['prefix']):
                      if l['member'] :
                          code += '      if (_context->%s)\n' % l['member']
                          code += '      {\n'
                          code += '        Push<int> pushLevel(_context->emuLevel);\n'
                          code += '        _context->emuLevel = %d;\n' %( int(l['level']) - 1 )
                      for j in e['prefix'] :
                          code += '        %s\n' % j
                      if l['member'] :
                          code += '      }\n'
                  if e!= None and 'impl' in e and l['member']:
                      code += '      if (_context->%s) break;\n' % l['member'];
                  if l['ifdef']:
                      code += '      #endif\n'
              code += '    default:\n'
              code += '      break;\n'
              code += '  }\n\n'

            # Remap, as necessary
            remap = getattr(function, 'regalRemap', None)
            es2Name = None
            if remap!=None and isinstance(remap, dict):
              es2Name = remap.get('ES2.0',None)
              es2Params = callParams
              if es2Name != None:
                j = es2Name.find('(')
                if j!=-1:
                  es2Params = es2Name[j+1:-1]
                  es2Name   = es2Name[0:j]

            if not all(i[1]==None or not 'impl' in i[1] for i in level):
              code += '  // impl\n'
              code += '  switch( _context->emuLevel )\n'
              code += '  {\n'
              for i in level:
                  l,e = i[0], i[1]
                  code += '    case %d :\n' % l['level']
                  if l['ifdef']:
                      code += '      #if %s\n' % l['ifdef']
                  if e != None and 'impl' in e and len(e['impl']):
                      if l['member'] :
                        code += '      if (_context->%s)\n' % l['member']
                        code += '      {\n'
                        code += '        Push<int> pushLevel(_context->emuLevel);\n'
                        code += '        _context->emuLevel = %d;\n' %( int(l['level']) - 1 )
                      for j in e['impl'] :
                          code += '        %s\n' % j
                      if l['member'] :
                          if l['member'] != "filt" and typeIsVoid(rType):
                              code += '        return;\n'
                          code += '      }\n'
                  if l['ifdef']:
                      code += '      #endif\n'
              code += '    default: \n'
              code += '    {\n'

              # glEnable/glDisable/glIsEnabled constraints for ES 2.0
              # http://www.khronos.org/opengles/sdk/docs/man/xhtml/glEnable.xml

              if name=='glEnable' or name=='glDisable' or name=='glIsEnabled':
                code += '       #if !REGAL_FORCE_ES2_PROFILE\n'
                code += '       if (_context->info->es2)\n'
                code += '       #endif\n'
                code += '         switch (cap)\n'
                code += '         {\n'
                for i in api.enums:
                  if i.name=='defines':
                    for j in i.enumerants:
                      if getattr(j,'esVersions',None) != None and getattr(j,'enableCap',None) != None and 2.0 in j.esVersions and j.enableCap == True:
                        code += '           case %s:\n'%(j.name)
                code += '             break;\n'
                code += '           default:\n'
                code += '             Warning("%s does not support ",GLenumToString(cap)," for ES 2.0.");\n'%(name)
                if name=='glIsEnabled':
                  code += '             return GL_FALSE;\n'
                else:
                  code += '             return;\n'
                code += '         }\n'

              # glHint constraints for ES 2.0
              # http://www.khronos.org/opengles/sdk/docs/man/xhtml/glHint.xml

              if name=='glHint':
                code += '       #if !REGAL_FORCE_ES2_PROFILE\n'
                code += '       if (_context->info->es2)\n'
                code += '       #endif\n'
                code += '         switch (target)\n'
                code += '         {\n'
                for i in api.enums:
                  if i.name=='defines':
                    for j in i.enumerants:
                      if getattr(j,'esVersions',None)==None:
                        continue
                      if getattr(j,'hint',None)==None:
                        continue
                      if 2.0 in j.esVersions and j.hint == True:
                        code += '           case %s:\n'%(j.name)
                code += '             break;\n'
                code += '           default:\n'
                code += '             Warning("%s does not support ",GLenumToString(target)," for ES 2.0.");\n'%(name)
                code += '             return;\n'
                code += '         }\n'

              # glBindTexture constraints for ES 2.0
              # http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindTexture.xml

              if name=='glBindTexture':
                code += '       #if !REGAL_FORCE_ES2_PROFILE\n'
                code += '       if (_context->info->es2)\n'
                code += '       #endif\n'
                code += '         switch (target)\n'
                code += '         {\n'
                for i in api.enums:
                  if i.name=='defines':
                    for j in i.enumerants:
                      if getattr(j,'esVersions',None)==None:
                        continue
                      if getattr(j,'bindTexture',None)==None:
                        continue
                      if 2.0 in j.esVersions and j.bindTexture == True:
                        code += '           case %s:\n'%(j.name)
                code += '             break;\n'
                code += '           default:\n'
                code += '             Warning("%s does not support ",GLenumToString(target)," for ES 2.0.");\n'%(name)
                code += '             return;\n'
                code += '         }\n'

              # glTexSubImage2D constraints for ES 2.0
              # http://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexSubImage2D.xml

              if name=='glTexSubImage2D':
                code += '       #if !REGAL_FORCE_ES2_PROFILE\n'
                code += '       if (_context->info->es2)\n'
                code += '       #endif\n'
                code += '         switch (target)\n'
                code += '         {\n'
                for i in api.enums:
                  if i.name=='defines':
                    for j in i.enumerants:
                      if getattr(j,'esVersions',None)==None:
                        continue
                      if getattr(j,'texImage',None)==None:
                        continue
                      if 2.0 in j.esVersions and j.texImage:
                        code += '           case %s:\n'%(j.name)
                code += '             break;\n'
                code += '           default:\n'
                code += '             Warning("%s does not support ",GLenumToString(target)," for ES 2.0.");\n'%(name)
                code += '             return;\n'
                code += '         }\n'

              code += '      DispatchTable *_next = _dispatch._next;\n'
              code += '      RegalAssert(_next);\n'

              if es2Name != None:
                code += '      '
                code += 'if (_context->info->es2)\n'
                code += '        '
                if not typeIsVoid(rType):
                    code += 'return '
                code += '_next->call(&_next->%s)(%s);\n' % ( es2Name, es2Params )
                code += '      else\n  '

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

              code += '      break;\n'
              code += '    }\n\n'
              code += '  }\n\n'
            else:

              # glTexImage2D internalformat constraints for ES 2.0
              # http://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexImage2D.xml

              if name=='glTexImage2D':
                code += '  #if !REGAL_FORCE_ES2_PROFILE\n'
                code += '  if (_context->info->es2)\n'
                code += '  #endif\n'
                code += '  {\n'
                code += '    switch (internalformat)\n'
                code += '    {\n'
                for i in api.enums:
                  if i.name=='defines':
                    for j in i.enumerants:
                      if getattr(j,'esVersions',None)==None:
                        continue
                      if getattr(j,'internalformat',None)==None:
                        continue
                      if 2.0 in j.esVersions and j.internalformat == True:
                        code += '      case %s:\n'%(j.name)
                code += '        break;\n'
                code += '      default:\n'
                code += '        Warning("%s does not support ",GLenumToString(internalformat)," for ES 2.0.");\n'%(name)
                code += '        return;\n'
                code += '    }\n'
                code += '    if (format!=GLenum(internalformat))\n'
                code += '    {\n'
                code += '        Warning("%s does not support mismatching format and internalformat ",GLenumToString(format),"!=",GLenumToString(internalformat)," for ES 2.0.");\n'%(name)
                code += '        return;\n'
                code += '    }\n'
                code += '  }\n'

              code += '  DispatchTable *_next = _dispatch._next;\n'
              code += '  RegalAssert(_next);\n'
              code += '  '

              if es2Name != None:
                code += 'if (_context->info->es2)\n'
                code += '    '
                if not typeIsVoid(rType):
                    code += 'return '
                code += '_next->call(& _next->%s)(%s);\n' % ( es2Name, es2Params )
                code += '   else\n     '

              if not typeIsVoid(rType):
                  code += 'return '
              code += '_next->call(& _next->%s)(%s);\n' % ( name, callParams )
            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'

    return code
コード例 #19
0
def apiStatisticsFuncDefineCode(apis, args):
    categoryPrev = None
    code = ''

    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

            if not function.needsContext:
                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, 'statistics_', name, params)
            code += '  RegalContext *_context = REGAL_GET_CONTEXT();\n'
            code += '  RegalAssert(_context);\n'
            code += '\n'
            code += '  RegalAssert(_context->statistics);\n'
            code += '  Statistics &statistics = *_context->statistics;\n'
            code += '  statistics.%s++;\n' % (name)
            code += '\n'

            # Extension

            for i in api.extensions:
                if name in i.functions:
                    code += '  statistics.%s++;\n' % (i.name.lower())
                code += '\n'

            # glEnable

            if name == 'glEnable':
                code += '  switch (cap)\n'
                code += '  {\n'
                for i in api.enums:
                    if i.name == 'defines':
                        for j in i.enumerantsByName:
                            if getattr(j, 'enableCap', False) == True:
                                code += '    case %-40s %-60s break;\n' % (
                                    j.name + ':',
                                    'statistics.enable_%s++;' % j.name)
                code += '    default: break;\n'
                code += '  }\n\n'

            # glDisable

            if name == 'glDisable':
                code += '  switch (cap)\n'
                code += '  {\n'
                for i in api.enums:
                    if i.name == 'defines':
                        for j in i.enumerantsByName:
                            if getattr(j, 'enableCap', False) == True:
                                code += '    case %-40s %-60s break;\n' % (
                                    j.name + ':',
                                    'statistics.disable_%s++;' % j.name)
                code += '    default: break;\n'
                code += '  }\n\n'

            if function.needsContext:
                code += '  DispatchTableGL *_next = _context->dispatcher.statistics.next();\n'
            else:
                code += '  DispatchTableGlobal *_next = dispatcherGlobal.statistics.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 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'

    return code
コード例 #20
0
def apiFuncDefineCode(apis, args):

    code = ''
    for api in apis:

        tmp = []
        for function in api.functions:

            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

            c = ''
            c += 'REGAL_DECL %sREGAL_CALL %s(%s) \n{\n' % (rType, name, params)

            emue = [
                emuFindEntry(function, i['formulae'], i['member'])
                for i in emuRegal
            ]

            if function.needsContext:
                c += '  RegalContext *_context = GET_REGAL_CONTEXT();\n'
                c += '  %s\n' % debugPrintFunction(function, 'App')
                c += '  if (!_context) return'
                if typeIsVoid(rType):
                    c += ';\n'
                else:
                    if rType[-1] != '*':
                        c += ' (%s)0;\n' % (rType)
                    else:
                        c += ' NULL;\n'

                c += listToString(indent(emuCodeGen(emue, 'impl'), '  '))

                if getattr(function, 'regalRemap', None) != None and (
                        isinstance(function.regalRemap, list)
                        or isinstance(function.regalRemap, str)
                        or isinstance(function.regalRemap, unicode)):
                    c += '  '
                    if not typeIsVoid(rType):
                        c += 'return '
                    if isinstance(function.regalRemap, list):
                        c += '\n  '.join(function.regalRemap) + '\n'
                    else:
                        c += '%s;\n' % (function.regalRemap)
                else:
                    if getattr(function, 'regalOnly', False) == False:
                        c += '  DispatchTable *_next = &_context->dispatcher.front();\n'
                        c += '  RegalAssert(_next);\n'
                        c += '  '
                        if not typeIsVoid(rType):
                            c += 'return '
                        c += '_next->call(&_next->%s)(%s);\n' % (name,
                                                                 callParams)
            else:
                c += '  %s\n' % debugPrintFunction(function, 'App')

                if api.name == 'egl':
                    c += '\n'
                    c += '  #if !REGAL_STATIC_EGL\n'

                c += '  if (dispatchTableGlobal.%s == NULL) {\n' % name
                c += '    GetProcAddress( dispatchTableGlobal.%s, "%s" );\n' % (
                    name, name)
                c += '    RegalAssert(dispatchTableGlobal.%s!=%s);\n' % (name,
                                                                         name)
                c += '    if (dispatchTableGlobal.%s==%s)\n' % (name, name)
                c += '      dispatchTableGlobal.%s = NULL;\n' % (name)
                c += '  }\n'

                if api.name == 'egl':
                    c += '  #endif // !REGAL_STATIC_EGL\n\n'

                if not typeIsVoid(rType):
                    if rType[-1] != '*':
                        c += '  %s ret = (%s)0;\n' % (rType, rType)
                    else:
                        c += '  %s ret = NULL;\n' % rType

                c += listToString(indent(emuCodeGen(emue, 'impl'), '  '))

                c += '  if (dispatchTableGlobal.%s) {\n' % name
                c += '    %s\n' % debugPrintFunction(function, 'Driver')
                c += '    '
                if not typeIsVoid(rType):
                    c += 'ret = '
                c += 'dispatchTableGlobal.%s(%s);\n' % (name, callParams)
                if name == 'wglMakeCurrent':
                    c += '    RegalMakeCurrent(RegalSystemContext(hglrc));\n'
                elif name == 'CGLSetCurrentContext':
                    c += '    RegalMakeCurrent( ctx );\n'
                elif name == 'glXMakeCurrent':
                    c += '    RegalMakeCurrent( RegalSystemContext(ctx) );\n'
                elif name == 'eglMakeCurrent':
                    c += '    RegalMakeCurrent( ctx );\n'
                c += '  }\n'
                c += '  else\n'
                c += '    Warning( "%s not available." );\n' % name

                c += listToString(indent(emuCodeGen(emue, 'suffix'), '  '))

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

            tmp.append((category, c))

        tmp = listToString(unfoldCategory(tmp))

        if api.name in cond:
            tmp = wrapIf(cond[api.name], tmp)

        code += tmp

    return code
コード例 #21
0
ファイル: RegalDispatchTrace.py プロジェクト: Shalmezad/regal
def apiTraceFuncDefineCode(apis, args):
  categoryPrev = None
  code = ''

  code += 'namespace Trace\n'
  code += '{\n'

  for api in apis:

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

    for function in api.functions:
      if getattr(function,'regalOnly',False)==True:
        continue
      if function.name in exclude or function.category in exclude:
        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 += '  %s %s(%s);\n' % (rType, name, params)

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

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

  code += '} // namespace Trace \n\n'

  for api in apis:

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

    for function in api.functions:
      if getattr(function,'regalOnly',False)==True:
        continue
      if function.name in exclude or function.category in exclude:
        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, 'trace_', name, params)
      code += '  Internal("trace_%s","()");\n' % name
      code += '  Thread::ThreadLocal &_instance = Thread::ThreadLocal::instance();\n'
      if function.needsContext:
        code += '  RegalAssert(_instance.currentContext);\n'
        code += '  Push<DispatchTableGL *> _push(_instance.nextDispatchTable);\n'
        code += '  _instance.nextDispatchTable = _instance.currentContext->dispatcher.trace.next();\n'
      else:
        code += '  Push<DispatchTableGlobal *> _push(_instance.nextDispatchTableGlobal);\n'
        code += '  _instance.nextDispatchTableGlobal = dispatcherGlobal.trace.next();\n'
      code += '  '
      if not typeIsVoid(rType):
        code += '%s ret = ' % rType
      #code += '_next->call(&_next->%s)(%s);\n' % ( name, callParams )
      code += 'Trace::%s(%s);\n' % ( name, callParams )
      if not typeIsVoid(rType):
        code += '  return ret;\n'
      code += '}\n\n'

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

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

  return code
コード例 #22
0
def apiTraceFuncDefineCode(apis, args):
    categoryPrev = None
    code = ''

    code += 'namespace Trace\n'
    code += '{\n'

    for api in apis:

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

        for function in api.functions:
            if getattr(function, 'regalOnly', False) == True:
                continue
            if function.name in exclude or function.category in exclude:
                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 += '  %s %s(%s);\n' % (rType, name, params)

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

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

    code += '} // namespace Trace \n\n'

    for api in apis:

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

        for function in api.functions:
            if getattr(function, 'regalOnly', False) == True:
                continue
            if function.name in exclude or function.category in exclude:
                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, 'trace_',
                                                            name, params)
            code += '  Internal("trace_%s","()");\n' % name
            code += '  Thread::ThreadLocal &_instance = Thread::ThreadLocal::instance();\n'
            if function.needsContext:
                code += '  RegalAssert(_instance.currentContext);\n'
                code += '  Push<DispatchTableGL *> _push(_instance.nextDispatchTable);\n'
                code += '  _instance.nextDispatchTable = _instance.currentContext->dispatcher.trace.next();\n'
            else:
                code += '  Push<DispatchTableGlobal *> _push(_instance.nextDispatchTableGlobal);\n'
                code += '  _instance.nextDispatchTableGlobal = dispatcherGlobal.trace.next();\n'
            code += '  '
            if not typeIsVoid(rType):
                code += '%s ret = ' % rType
            #code += '_next->call(&_next->%s)(%s);\n' % ( name, callParams )
            code += 'Trace::%s(%s);\n' % (name, callParams)
            if not typeIsVoid(rType):
                code += '  return ret;\n'
            code += '}\n\n'

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

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

    return code
コード例 #23
0
ファイル: RegalDispatchEmu.py プロジェクト: greggman/regal
def apiEmuFuncDefineCode(apis, args):
    categoryPrev = None
    code = ''

    for api in apis:

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

        for function in api.functions:
            if not function.needsContext:
                continue
            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

            emue = [ emuFindEntry( function, i['formulae'], i['member'] ) for i in emu ]

            if all(i is None for i in emue) and (getattr(function,'regalRemap',None)==None or isinstance(function.regalRemap, str) or isinstance(function.regalRemap, unicode)):
                continue

            code += '\nstatic %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'emu_', name, params)
            code += '   RegalContext *_context = GET_REGAL_CONTEXT();\n'
            code += '   RegalAssert(_context);\n'
            code += '\n'

            level = [ (emu[i], emuFindEntry( function, emu[i]['formulae'], emu[i]['member'] )) for i in range( len( emue ) - 1 ) ]

            if not all(i[1]==None or not 'prefix' in i[1] and not 'impl' in i[1] for i in level):
              code += '   // prefix\n'
              code += '   switch( _context->emuLevel ) {\n'
              for i in level:
                  l,e = i[0], i[1]
                  code += '       case %d :\n' % l['level']
                  if l['ifdef']:
                      code += '         #if %s\n' % l['ifdef']
                  if e != None and 'prefix' in e :
                      if l['member'] :
                          code += '         if (_context->%s) {\n' % l['member']
                          code += '             RegalEmuScopedActivate activate( _context, _context->%s );\n' % l['member']
                      for j in e['prefix'] :
                          code += '             %s\n' % j
                      if l['member'] :
                          code += '         }\n'
                  if e!= None and 'impl' in e and l['member']:
                      code += '         if (_context->%s) break;\n' % l['member'];
                  if l['ifdef']:
                      code += '         #endif\n'
              code += '       default:\n'
              code += '           break;\n'
              code += '   }\n\n'

            # Remap, as necessary
            remap = getattr(function, 'regalRemap', None)
            es2Name = None
            if remap != None:
              es2Name = remap.get('ES2.0',None)
              es2Params = callParams
              if es2Name != None:
                j = es2Name.find('(')
                if j!=-1:
                  es2Params = es2Name[j+1:-1]
                  es2Name   = es2Name[0:j]

            if not all(i[1]==None or not 'impl' in i[1] for i in level):
              code += '   // impl\n'
              code += '   switch( _context->emuLevel ) {\n'
              for i in level:
                  l,e = i[0], i[1]
                  code += '       case %d :\n' % l['level']
                  if l['ifdef']:
                      code += '         #if %s\n' % l['ifdef']
                  if e != None and 'impl' in e :
                      if l['member'] :
                        code += '         if (_context->%s) {\n' % l['member']
                        code += '             RegalEmuScopedActivate activate( _context, _context->%s );\n' % l['member']
                      for j in e['impl'] :
                          code += '             %s\n' % j
                      if l['member'] :
                          if typeIsVoid(rType):
                              code += '             return;\n'
                          code += '         }\n'
                  if l['ifdef']:
                      code += '         #endif\n'
              code += '       default: {\n'
              # debug print
              # code += '           %s\n' % debugPrintFunction( function, 'GTrace' )
              # debug print

              if name=='glEnable' or name=='glDisable' or name=='glIsEnabled':
                code += '         if (_context->info->gles)\n'
                code += '           switch (cap)\n'
                code += '           {\n'
                for i in api.enums:
                  if i.name=='defines':
                    for j in i.enumerants:
                      if getattr(j,'esVersions',None) != None and getattr(j,'enableCap',None) != None and 2.0 in j.esVersions and j.enableCap == True:
                        code += '             case %s:\n'%(j.name)
                code += '               break;\n'
                code += '             default:\n'
                code += '               Warning("%s does not support ",GLenumToString(cap)," for ES 2.0.");\n'%(name)
                if name=='glIsEnabled':
                  code += '               return GL_FALSE;\n'
                else:
                  code += '               return;\n'
                code += '           }\n'

              code += '         Dispatcher::ScopedStep stepDown(_context->dispatcher);\n'

              if es2Name != None:
                code += '         '
                code += 'if (_context->info->gles)\n'
                code += '         '
                if not typeIsVoid(rType):
                    code += '  return '
                code += '  _context->dispatcher.call(&_context->dispatcher.table().%s)(%s);\n' % ( es2Name, es2Params )
                code += '         else\n  '

              code += '         '
              if not typeIsVoid(rType):
                  code += 'return '
              code += '_context->dispatcher.call(&_context->dispatcher.table().%s)(%s);\n' % ( name, callParams )

              code += '         break;\n'
              code += '       }\n\n'
              code += '   }\n\n'
            else:
              code += '   Dispatcher::ScopedStep stepDown(_context->dispatcher);\n'
              code += '   '

              if es2Name != None:
                code += 'if (_context->info->gles)\n'
                code += '     '
                if not typeIsVoid(rType):
                    code += 'return '
                code += '_context->dispatcher.call(&_context->dispatcher.table().%s)(%s);\n' % ( es2Name, es2Params )
                code += '   else\n     '

              if not typeIsVoid(rType):
                  code += 'return '
              code += '_context->dispatcher.call(&_context->dispatcher.table().%s)(%s);\n' % ( name, callParams )
            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'

    return code
コード例 #24
0
ファイル: RegalPlugin.py プロジェクト: vvuk/regal
def generatePluginSource(apis, args):

    code = ''
    for api in apis:

        tmp = []
        for function in api.functions:

            if getattr(function, 'regalOnly', False):
                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

            c = ''
            c += '%sREGAL_CALL plugin_%s(%s) \n{\n' % (rType, name, params)

            c += '  ::REGAL_NAMESPACE_INTERNAL::Thread::ThreadLocal &_instance = ::REGAL_NAMESPACE_INTERNAL::Thread::ThreadLocal::instance();\n'
            if function.needsContext:
                c += '  ::REGAL_NAMESPACE_INTERNAL::DispatchTableGL *_next = _instance.nextDispatchTable;\n'
            else:
                c += '  ::REGAL_NAMESPACE_INTERNAL::DispatchTableGlobal *_next = _instance.nextDispatchTableGlobal;\n'
            c += '  RegalAssert(_next);\n'
            if not typeIsVoid(rType):
                c += '  return '
            else:
                c += '  '
            c += '_next->call(&_next->%s)(%s);\n}\n' % (name, callParams)

            tmp.append((category, indent(c, '  ')))

        tmp = listToString(unfoldCategory(tmp, '  /* %s */'))

        if api.name in cond:
            tmp = wrapIf(cond[api.name], tmp)

        code += tmp

    # lookup by name

    code2 = ''
    size = {}
    for i in apis:
        tmp = []

        names = []
        for j in i.functions:
            if getattr(j, 'regalOnly', False):
                continue
            names.append(j.name)

        size[i.name] = len(names)
        tmp.extend(
            pointerLookupByNameCode(
                [(j, 'plugin_%s' % j) for j in names],
                ("lookup_%s_Name" % i.name, "lookup_%s_Value" % i.name),
                valueCast='(void *)(%s)'))

        tmp = '\n'.join(tmp)
        if i.name in cond:
            tmp = wrapIf(cond[i.name], tmp)

        code2 += '\n' + indent(tmp, '  ')

    # glGetProcAddress

    code3 = '''
  using namespace ::REGAL_NAMESPACE_INTERNAL::Lookup;
  using namespace ::REGAL_NAMESPACE_INTERNAL::Plugin;

  void * REGAL_CALL
  plugin_glGetProcAddress(const char *name)
  {
    const char **res;
'''

    for i in apis:
        tmp = '    res = (const char **) std::bsearch(&name, %s, %d, sizeof(const char *), NameCmp);\n' % (
            'lookup_%s_Name' % i.name, size[i.name] - 1)
        tmp += '    if (res) return const_cast<void *>(%s[(size_t) (res - %s)]);\n' % (
            'lookup_%s_Value' % i.name, 'lookup_%s_Name' % i.name)
        if i.name in cond:
            tmp = wrapIf(cond[i.name], tmp)
        code3 += '\n' + tmp

    code3 += '''
    return NULL;
  }
'''

    # Output

    substitute = {}

    substitute['LICENSE'] = args.license
    substitute['AUTOGENERATED'] = args.generated
    substitute['PLUGIN_SOURCE'] = code
    substitute['PLUGIN_SOURCE2'] = code2
    substitute['PLUGIN_SOURCE3'] = code3

    outputCode('%s/RegalPlugin.cpp' % args.srcdir,
               pluginHeaderTemplate.substitute(substitute))
コード例 #25
0
def apiDebugFuncDefineCode(apis, args):
    categoryPrev = None
    code = ''

    for api in apis:

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

        for function in api.functions:
            if not function.needsContext:
                continue
            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, 'debug_',
                                                            name, params)
            code += '  RegalContext *_context = GET_REGAL_CONTEXT();\n'
            code += '  RegalAssert(_context);\n'
            code += '  DispatchTable *_next = _context->dispatcher.debug._next;\n'
            code += '  RegalAssert(_next);\n'
            e = emuFindEntry(function, debugDispatchFormulae, '')
            if e != None and 'prefix' in e:
                for l in e['prefix']:
                    code += '  %s\n' % l
            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'

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

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

    return code
コード例 #26
0
ファイル: Regal.py プロジェクト: chadaustin/regal
def apiFuncDefineCode(apis, args):

    #

    code = ''
    for api in apis:

        tmp = []
        for function in api.functions:

            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

            c = ''
            c += 'REGAL_DECL %sREGAL_CALL %s(%s) \n{\n' % (rType, name, params)

            emue = [
                emuFindEntry(function, i['formulae'], i['member'], i['ifdef'])
                for i in emuRegal
            ]

            if function.needsContext:
                c += '  RegalContext *_context = REGAL_GET_CONTEXT();\n'
                c += listToString(
                    indent(stripVertical(emuCodeGen(emue, 'prefix')), '  '))
                c += '  %s\n' % logFunction(function, 'App')
                c += '  if (!_context) return'
                if typeIsVoid(rType):
                    c += ';\n'
                else:
                    if rTypes in api.defaults:
                        c += ' %s;\n' % (api.defaults[rTypes])
                    else:
                        if rType[-1] == '*' or typeIsVoidPointer(rType):
                            c += ' NULL;\n'
                        else:
                            c += ' (%s) 0;\n' % (rTypes)

                c += listToString(
                    indent(stripVertical(emuCodeGen(emue, 'impl')), '  '))

                if getattr(function, 'regalRemap', None) != None and (
                        isinstance(function.regalRemap, list)
                        or isinstance(function.regalRemap, str)
                        or isinstance(function.regalRemap, unicode)):

                    # For an ES1 context, pass the call into the dispatch layers...

                    if function.category in [
                            'GL_REGAL_ES1_0_compatibility',
                            'GL_REGAL_ES1_1_compatibility'
                    ]:
                        c += '  #if REGAL_SYS_ES1\n'
                        c += '  if (_context->isES1()) // Pass-through for ES1 only\n'
                        c += '  {\n'
                        c += '    DispatchTableGL *_next = &_context->dispatcher.front();\n'
                        c += '    RegalAssert(_next);\n    '
                        if not typeIsVoid(rType):
                            c += 'return '
                        c += '_next->call(&_next->%s)(%s);\n' % (name,
                                                                 callParams)
                        if typeIsVoid(rType):
                            c += '    return;\n'
                        c += '  }\n'
                        c += '  #endif\n'

                    # For ES2 or GL context, remap the ES1 call

                    c += '  '
                    if not typeIsVoid(rType):
                        c += 'return '
                    if isinstance(function.regalRemap, list):
                        c += '\n  '.join(function.regalRemap) + '\n'
                    else:
                        c += '%s;\n' % (function.regalRemap)
                else:
                    if not getattr(function, 'regalOnly', False):
                        t = ''
                        t += 'DispatchTableGL *_next = &_context->dispatcher.front();\n'
                        t += 'RegalAssert(_next);\n'

                        t += listToString(
                            indent(stripVertical(emuCodeGen(emue, 'pre')), ''))

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

                        t += listToString(
                            indent(stripVertical(emuCodeGen(emue, 'post')),
                                   ''))

                        for i in emue:
                            if i != None and i['cond'] != None:
                                t = wrapCIf(i['cond'], indent(t))

                        c += indent(t)

                        c += listToString(
                            indent(stripVertical(emuCodeGen(emue, 'suffix')),
                                   '  '))

            else:
                c += '  %s\n' % logFunction(function, 'App')
                c += listToString(
                    indent(stripVertical(emuCodeGen(emue, 'prefix')), '  '))

                if not getattr(function, 'regalOnly', False):
                    c += '  DispatchTableGlobal *_next = &dispatcherGlobal.front();\n'
                    c += '  RegalAssert(_next);\n'

                    if not typeIsVoid(rType):
                        if rTypes in api.defaults:
                            c += '  %s ret = %s;\n' % (rTypes,
                                                       api.defaults[rTypes])
                        else:
                            if rType[-1] == '*' or typeIsVoidPointer(rType):
                                c += '  %s ret = NULL;\n' % rTypes
                            else:
                                c += '  %s ret = (%s) 0;\n' % (rTypes, rTypes)

                    c += listToString(
                        indent(stripVertical(emuCodeGen(emue, 'impl')), '  '))
                    c += '  '
                    if not typeIsVoid(rType):
                        c += 'ret = '
                    c += '_next->call(&_next->%s)(%s);\n' % (name, callParams)

                c += listToString(
                    indent(stripVertical(emuCodeGen(emue, 'init')), '  '))

                c += listToString(
                    indent(stripVertical(emuCodeGen(emue, 'suffix')), '  '))
                if not typeIsVoid(rType):
                    c += '  return ret;\n'
            c += '}\n\n'

            tmp.append((category, indent(c, '  ')))

        tmp = listToString(unfoldCategory(tmp, '  /* %s */'))

        if api.name in cond:
            tmp = wrapIf(cond[api.name], tmp)

        code += tmp

    return code
コード例 #27
0
ファイル: RegalPlugin.py プロジェクト: nigels-com/regal
def generatePluginSource(apis, args):

  code = ''
  for api in apis:

    if len(api.functions)==0:
      continue

    tmp = []
    for function in api.functions:

      if getattr(function,'regalOnly',False):
        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

      c = ''
      c += '%sREGAL_CALL plugin_%s(%s) \n{\n' % (rType, name, params)

      c += '  ::REGAL_NAMESPACE_INTERNAL::Thread::ThreadLocal &_instance = ::REGAL_NAMESPACE_INTERNAL::Thread::ThreadLocal::instance();\n'
      if function.needsContext:
        c += '  ::REGAL_NAMESPACE_INTERNAL::DispatchTableGL *_next = _instance.nextDispatchTable;\n'
      else:
        c += '  ::REGAL_NAMESPACE_INTERNAL::DispatchTableGlobal *_next = _instance.nextDispatchTableGlobal;\n'
      c += '  RegalAssert(_next);\n'
      if not typeIsVoid(rType):
        c += '  return '
      else:
        c += '  '
      c += '_next->call(&_next->%s)(%s);\n}\n' % ( name, callParams )

      tmp.append( (category, indent(c,'  ') ) )

    tmp = listToString(unfoldCategory(tmp,'  /* %s */'))

    if api.name in cond:
      tmp = wrapIf(cond[api.name], tmp)

    code += tmp

  # lookup by name

  code2 = ''
  size = {}
  for i in apis:

    if len(i.functions)==0:
      continue

    tmp = []

    names = []
    for j in i.functions:
      if getattr(j,'regalOnly',False):
        continue
      names.append(j.name)

    size[i.name] = len(names)
    tmp.extend(pointerLookupByNameCode([ (j,'plugin_%s'%j) for j in names ],("lookup_%s_Name"%i.name,"lookup_%s_Value"%i.name),valueCast = '(void *)(%s)'))

    tmp = '\n'.join(tmp)
    if i.name in cond:
      tmp = wrapIf(cond[i.name], tmp)

    code2 += '\n' + indent(tmp,'  ')

  # glGetProcAddress

  code3 = '''
  using namespace ::REGAL_NAMESPACE_INTERNAL::Lookup;
  using namespace ::REGAL_NAMESPACE_INTERNAL::Plugin;

  void * REGAL_CALL
  plugin_glGetProcAddress(const char *name)
  {
    const char **res;
'''

  for i in apis:

    if len(i.functions)==0:
      continue

    tmp =  '    res = (const char **) std::bsearch(&name, %s, %d, sizeof(const char *), NameCmp);\n'%('lookup_%s_Name'%i.name,size[i.name]-1)
    tmp += '    if (res) return const_cast<void *>(%s[(size_t) (res - %s)]);\n'%('lookup_%s_Value'%i.name,'lookup_%s_Name'%i.name)
    if i.name in cond:
      tmp = wrapIf(cond[i.name], tmp)
    code3 += '\n' + tmp

  code3 += '''
    return NULL;
  }
'''

  # Output

  substitute = {}

  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['PLUGIN_SOURCE']   = code
  substitute['PLUGIN_SOURCE2']  = code2
  substitute['PLUGIN_SOURCE3']  = code3

  outputCode( '%s/RegalPlugin.cpp' % args.srcdir, pluginHeaderTemplate.substitute(substitute))
コード例 #28
0
ファイル: Emu.py プロジェクト: florianlink/regal
def emuFindEntry(func, emuFormulae, member):

  if emuFormulae==None:
    return None

  name = func.name

  # list of function parameter names

  arglist = [ i.name.strip() for i in func.parameters ]

  # arg is a mapping from arg0 to function parameter name...

  arg = {}
  for i in range(len(arglist)):
    arg['arg%d' % i] = arglist[i]

  # ... and mappings from arg0plus to lists of function parameters

  for i in range(0,5):
    label = 'arg%dplus' % i;
    if len(arglist) > 0 :
      arg[label] = ', '.join(arglist)
      arglist.pop(0)
    else :
      arg[label] = ''

  # Iterator over the formulae
  #
  # k is the key
  # i is the formula

  for k,i in emuFormulae.iteritems():

    # Cache the compiled regular expressions, as needed

    if 'entries_re' not in i:
      i['entries_re'] = [ re.compile( '^%s$' % j ) for j in i['entries'] ]

  # A list of matches containing (match object, formula name, formula)
  # Look for matches, ideally only one

  m = [ [j.match(name),k,i] for k,i in emuFormulae.iteritems() for j in i['entries_re'] ]
  m = [ j for j in m if j[0] ]

  assert len(m)<=1, 'Ambiguous match (%s) for %s - giving up.'%(', '.join([j[1] for j in m]),name)

  if len(m):
    match   = m[0][0]
    formula = m[0][2]
    rType  = typeCode(func.ret.type)
    dummyRetVal = ''
    if not typeIsVoid(rType):
      dummyRetVal = '(( %s )0)' % rType
    emue = { 'name' : name, 'member' : member, 'dummyretval' : dummyRetVal }
    subs = deepcopy(arg)
    for l in range( len(match.groups()) + 1):
      subs['m%d' % l] = match.group( l )
    subs['name'] = name
    subs['dummyretval'] = dummyRetVal
    addSubstitution( name, formula, subs )
    substitute( emue, formula, 'impl',   subs )
    substitute( emue, formula, 'init',   subs )
    substitute( emue, formula, 'cond',   subs )
    substitute( emue, formula, 'prefix', subs )
    substitute( emue, formula, 'suffix', subs )
    substitute( emue, formula, 'pre',    subs )
    substitute( emue, formula, 'post',   subs )

    emue['cond'] = None
    if 'cond' in formula:
      emue['cond'] = formula['cond']

    # plugin is optional, default to False

    emue['plugin'] = False
    if 'plugin' in formula:
      emue['plugin'] = formula['plugin']

    return emue

  return None
コード例 #29
0
ファイル: RegalDispatchHttp.py プロジェクト: nigels-com/regal
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))
コード例 #30
0
def apiLoaderFuncDefineCode(apis, args):
  categoryPrev = None
  code = ''

  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) \n  {\n' % (rType, name, params)

      # Get a reference to the appropriate dispatch table and attempt GetProcAddress

      if function.needsContext:
        code += '    DispatchTableGL &_driver = _getDispatchGL();\n'
      else:
        code += '    DispatchTableGlobal &_driver = dispatcherGlobal.driver;\n'

      code += '    _getProcAddress(reinterpret_cast<void (**)()>(&_driver.%s),reinterpret_cast<void (*)()>(%s),"%s");\n'%(name,name,name)
      code += '    '
      if not typeIsVoid(rType):
        code += 'return '
      code += '_driver.call(&_driver.%s)(%s);\n'%(name, callParams)
      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'

  return code
コード例 #31
0
ファイル: RegalDispatchCode.py プロジェクト: sherief/regal
def generateDispatchCode(apis, args):

  code = ''

  for api in apis:
    if api.name=='gl':

      for function in api.functions:

        if not function.needsContext:
          continue

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

        f = deepcopy(function)

        name = f.name
        params = paramsDefaultCode(f.parameters, True)

        callParams = paramsNameCode(f.parameters)
        rType  = typeCode(f.ret.type)

        code += 'static %sREGAL_CALL %s%s(%s) \n{\n' % (rType, 'code_', name, params)
        code += '    RegalContext *_context = REGAL_GET_CONTEXT();\n'
        code += '    RegalAssert(_context);\n'

        code += '    DispatchTable *_next = _context->dispatcher.code._next;\n'
        code += '    RegalAssert(_next);\n'
        code += '    '
        if not typeIsVoid(rType):
          code += '%s _ret = '%(rType)
        code += '_next->call(&_next->%s)(%s);\n' % ( name, callParams )

        prefix = ''
        suffix = ''

        if not f.trace:
          prefix += '/* '
          suffix += ' */'

        header =  '    std::string indent((_context->depthBeginEnd + _context->depthPushAttrib)*2,\' \');\n'
        header += '    string_list< ::std::string > _code;\n'
        body   =  ''

        if len(f.parameters)==0:
          body += '    %s_code << indent << "%s();%s\\n";\n'%(prefix,f.name,suffix)
        if len(f.parameters)>0:
          body += '    %s_code << indent << "%s(";\n'%(prefix,f.name)

        if len(f.parameters)>0:
          delim = False
          for i in f.parameters:
            if delim:
              body += '    _code << ", "; '
            else:
              body += '                   '
#           p = cCodeParameter(f,i)
            p = logParameter(f,i)
            if p==None:
                body += '_code << "/* %s = ?? */";\n'%(i.name)
            elif p.startswith('boost::print::array'):
                type = typeStrip(i.type)
                size = i.size
                if i.maxSize != None:
                  size = i.maxSize
                if i.input:
                  if p.find('helper')==-1 and type!='GLchar' and type!='GLcharARB':
                    header += '    size_t _%sIndex = _context->codeInputNext++;\n'%(i.name)
                    header += '    _code << indent << \"const %s i\" << _%sIndex << \"[%s] = \" '%(type,i.name,size)
                    header += '<< array<%s,const char * const>(%s,%s,\"\",\"{ \",\" };\\n\",\", \");\n'%(type,i.name,size)
                    body += '_code << \"i\" << _%sIndex;\n'%(i.name)
                  else:
                    body += '_code << "/* %s = ?? */";\n'%(i.name)
                else:
                  if p.find('helper')==-1 and type!='GLchar' and type!='GLcharARB':
                    header += '    size_t _%sIndex = _context->codeOutputNext++;\n'%(i.name)
                    header += '    _code << indent << \"%s o\" << _%sIndex << \"[\" << (%s) << \"];\\n";\n'%(type,i.name,size)
                    body += '_code << \"o\" << _%sIndex;\n'%(i.name)
                  else:
                    body += '_code << "/* %s = ?? */";\n'%(i.name)

            # glTexImage2D etc

            elif i.size != None and (isinstance(i.size, str) or isinstance(i.size, unicode)) and i.size.startswith('helperGLPixelImageSize'):
              header += '    size_t _%sIndex = _context->codeInputNext++;\n'%(i.name)
              header += '    _code << indent << \"const GLubyte i\" << _%sIndex << \"[\" << helper::size::pixelImage(%s << \"] = \" '%(i.name,i.size.split('(',1)[1])
              header += '<< array<GLubyte,const char * const>(static_cast<const GLubyte *>(%s),helper::size::pixelImage(%s,\"\",\"{ \",\" }\",\",\") '%(i.name,i.size.split('(',1)[1])
              header += '<< \";\\n\";\n'
              body += '_code << \"i\" << _%sIndex;\n'%(i.name)

            elif p.startswith('boost::print::optional'):
              if i.cast != None:
                body += '_code << reinterpret_cast<%s>(%s);\n'%(i.cast,i.name)
              else:
                body += '_code << %s;\n'%(i.name)
            else:
                body += '_code << %s;\n'%(p)
            delim = True

          body += '    _code << ");%s\\n";\n'%(suffix)

        body += '    printf("%s",_code.str().c_str());\n'

        code += header + body

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

    code += '\n'

  funcInit   = apiDispatchCodeInitCode( apis, args, 'code' )

  # Output

  substitute = {}
  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['COPYRIGHT']       = args.copyright
  substitute['API_FUNC_DEFINE'] = code
  substitute['API_GLOBAL_DISPATCH_INIT'] = funcInit

  outputCode( '%s/RegalDispatchCode.cpp' % args.srcdir, dispatchCodeTemplate.substitute(substitute))
コード例 #32
0
ファイル: RegalDispatchGLX.py プロジェクト: Shalmezad/regal
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))
コード例 #33
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 not function.needsContext:
        continue
      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 )
      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'

      code += '    DispatchTable *_next = _context->dispatcher.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, "ret" )

      # 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'

  funcInit   = apiDispatchFuncInitCode( apis, args, 'log' )

  # Output

  substitute = {}
  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['COPYRIGHT']       = args.copyright
  substitute['API_FUNC_DEFINE'] = code
  substitute['API_GLOBAL_DISPATCH_INIT'] = funcInit

  outputCode( '%s/RegalDispatchLog.cpp' % args.srcdir, dispatchLogTemplate.substitute(substitute))
コード例 #34
0
def apiErrorFuncDefineCode(apis, args):
  categoryPrev = None
  code = ''

  for api in apis:

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

    for function in api.functions:
      if not function.needsContext:
        continue
      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, 'error_', name, params)
      code += '  Internal("error_%s","()");\n' % name
      code += '  RegalContext *_context = REGAL_GET_CONTEXT();\n'
      code += '  RegalAssert(_context);\n'
      code += '  DispatchTableGL *_next = _context->dispatcher.error.next();\n'
      code += '  RegalAssert(_next);\n'
      if name != 'glGetError':
        code += '  GLenum _error = GL_NO_ERROR;\n'
        code += '  if (!_context->err.inBeginEnd)\n'
        code += '    _error = _next->call(&_next->glGetError)();\n'
        code += '  RegalAssert(_error==GL_NO_ERROR);\n'
        code += '  '
        if name == 'glBegin':
          code += '_context->err.inBeginEnd = true;\n'
        if not typeIsVoid(rType):
          code += '%s ret = ' % rType
        code += '_next->call(&_next->%s)(%s);\n' % ( name, callParams )
        if name == 'glEnd':
          code += '_context->err.inBeginEnd = false;\n'
        code += '  if (!_context->err.inBeginEnd) {\n'
        code += '    _error = _next->call(&_next->glGetError)();\n'
        code += '    if (_error!=GL_NO_ERROR) {\n'
        code += '      Error("%s : ",Token::GLerrorToString(_error));\n'%(name)
        code += '      #if REGAL_BREAK\n'
        code += '      Break::ErrorCB(_error);\n'
        code += '      #endif\n'
        code += '      if (_context->err.callback)\n'
        code += '        _context->err.callback( _error );\n'
        code += '    }\n'
        code += '  }\n'
        if not typeIsVoid(rType):
          code += 'return ret;\n'
      else:
        code += '  GLenum error = _next->call(&_next->glGetError)();\n'
        code += '  return error;\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'

  return code
コード例 #35
0
def generateDispatchCode(apis, args):

    code = ''

    for api in apis:
        if api.name == 'gl':

            for function in api.functions:

                if not function.needsContext:
                    continue

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

                if function.name in exclude:
                    continue

                f = deepcopy(function)

                name = f.name
                params = paramsDefaultCode(f.parameters, True)

                callParams = paramsNameCode(f.parameters)
                rType = typeCode(f.ret.type)

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

                code += '    RegalContext *_context = REGAL_GET_CONTEXT();\n'
                code += '    RegalAssert(_context);\n'
                code += '    DispatchTableGL *_next = _context->dispatcher.code.next();\n'
                code += '    RegalAssert(_next);\n'
                code += '    '

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

                # comment-out calls to functions flagged as trace = False

                prefix = ''
                suffix = ''
                if not f.trace:
                    prefix += '/* '
                    suffix += ' */'

                h = False
                h1 = '    std::string indent((_context->depthBeginEnd + _context->depthPushAttrib + 1)*2,\' \');\n'
                h2 = ''
                body = ''

                ret = ''
                if not typeIsVoid(rType):
                    if f.name in ['glCreateShader', 'glCreateShaderObjectARB']:
                        h2 += '    size_t _retIndex = _context->codeShaderNext++;\n'
                        ret = 'const %s shader\" << _retIndex << \" = ' % typeStrip(
                            rType)
                    elif f.name in [
                            'glCreateProgram', 'glCreateProgramObjectARB'
                    ]:
                        h2 += '    size_t _retIndex = _context->codeProgramNext++;\n'
                        ret = 'const %s program\" << _retIndex << \" = ' % typeStrip(
                            rType)
                    else:
                        h2 += '    size_t _retIndex = _context->codeOutputNext++;\n'
                        ret = 'const %s o\" << _retIndex << \" = ' % typeStrip(
                            rType)

                if len(f.parameters) == 0:
                    body += '    %s_code << indent << "%s%s();%s\\n";\n' % (
                        prefix, ret, f.name, suffix)
                else:
                    body += '    %s_code << indent << "%s%s(";\n' % (
                        prefix, ret, f.name)

                    if f.name.startswith('glShaderSource'):
                        h2 += '    std::string _delim = print_string("\\\\n\\"\\n",indent,"  \\"");\n'
                        h2 += '    size_t _stringIndex = _context->codeInputNext++;\n'
                        h2 += '    _code << indent << \"const char *i\" << _stringIndex << \" =\\n\";\n'
                        h2 += '    _code << indent << "  \\\"" << string_list< ::std::string >(string_list< ::std::string >(count,string,length).str(),\'\\n\').join(_delim) << "\\";\\n";\n'
                        body += '    _code << %s << ",1,&i" <<_stringIndex << ",NULL);\\n";\n' % (
                            f.parameters[0].name)

                    else:
                        delim = False
                        for i in f.parameters:
                            if delim:
                                body += '    _code << ", "; '
                            elif len(f.parameters) > 1:
                                body += '                   '
                            else:
                                body += '    '

#             p = cCodeParameter(f,i)
                            p = logParameter(f, i)

                            # For parameters not handled yet...

                            if p == None:
                                body += '_code << "/* %s = ?? */";\n' % (
                                    i.name)

                            # Special handling for input or output arrays

                            elif p.startswith('boost::print::array'):
                                type = typeStrip(i.type)
                                size = i.size
                                if i.maxSize != None:
                                    size = i.maxSize
                                if i.input:
                                    if p.find(
                                            'helper'
                                    ) == -1 and type != 'GLchar' and type != 'GLcharARB':
                                        h2 += '    size_t _%sIndex = _context->codeInputNext++;\n' % (
                                            i.name)
                                        h2 += '    _code << indent << \"const %s i\" << _%sIndex << \"[\" << %s << \"] = \" ' % (
                                            type, i.name,
                                            expressionSimplify('(%s)' % size))
                                        h2 += '<< array<%s,const char * const>(%s,%s,\"\",\"{ \",\" };\",\", \") ' % (
                                            type, i.name, size)
                                        h2 += '<< \"\\n\";\n'
                                        body += '_code << \"i\" << _%sIndex;\n' % (
                                            i.name)
                                    else:
                                        body += '_code << "/* %s = ?? */";\n' % (
                                            i.name)
                                else:
                                    if p.find(
                                            'helper'
                                    ) == -1 and type != 'GLchar' and type != 'GLcharARB':
                                        h2 += '    size_t _%sIndex = _context->codeOutputNext++;\n' % (
                                            i.name)
                                        h2 += '    _code << indent << \"%s o\" << _%sIndex << \"[\" << %s << \"];\\n";\n' % (
                                            type, i.name,
                                            expressionSimplify('(%s)' % size))
                                        body += '_code << \"o\" << _%sIndex;\n' % (
                                            i.name)
                                    else:
                                        body += '_code << "/* %s = ?? */";\n' % (
                                            i.name)

                            # glTexImage2D etc

                            elif i.input and i.size != None and (
                                    isinstance(i.size, str)
                                    or isinstance(i.size, unicode)
                            ) and i.size.startswith('helperGLPixelImageSize'):
                                h2 += '    size_t _%sIndex = _context->codeTextureNext++;\n' % (
                                    i.name)
                                h2 += '    _header << indent << \"const GLubyte texture\" << _%sIndex << \"[\" << helper::size::pixelImage(%s << \"] = \" ' % (
                                    i.name, i.size.split('(', 1)[1])
                                h2 += '<< array<GLubyte,const char * const>(static_cast<const GLubyte *>(%s),helper::size::pixelImage(%s,\"\",\"{ \",\" }\",\",\") ' % (
                                    i.name, i.size.split('(', 1)[1])
                                h2 += '<< \";\\n\";\n'
                                h = True
                                body += '_code << \"texture\" << _%sIndex;\n' % (
                                    i.name)

                            elif p.startswith('boost::print::optional'):
                                if i.cast != None:
                                    body += '_code << reinterpret_cast<%s>(%s);\n' % (
                                        i.cast, i.name)
                                else:
                                    body += '_code << %s;\n' % (i.name)

                            # 0x prefix for hex output

                            elif p.startswith('boost::print::hex'):
                                body += '_code << \"0x\" << %s;\n' % (p)

                            elif p.startswith(
                                    'boost::print::raw'
                            ):  # Buffer data needs better handling, revisit
                                body += '_code << "NULL";\n'

                            else:
                                body += '_code << %s;\n' % (p)

                            delim = True

                        body += '    _code << ");%s\\n";\n' % (suffix)

                h1 += '    string_list< ::std::string > _code;\n'
                body += '    if (_context->codeSource)\n'
                body += '      fprintf(_context->codeSource,"%s",_code.str().c_str());\n'

                if h:
                    h1 += '    string_list< ::std::string > _header;\n'
                    body += '    if (_context->codeHeader)\n'
                    body += '      fprintf(_context->codeHeader,"%s",_header.str().c_str());\n'


#         body += '    Internal("code_%s",_code);\n'%name

                code += h1 + h2 + body

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

        code += '\n'

    funcInit = apiDispatchCodeInitCode(apis, args, 'code')

    # Output

    substitute = {}
    substitute['LICENSE'] = args.license
    substitute['AUTOGENERATED'] = args.generated
    substitute['COPYRIGHT'] = args.copyright
    substitute['API_FUNC_DEFINE'] = code
    substitute['API_GLOBAL_DISPATCH_INIT'] = funcInit

    outputCode('%s/RegalDispatchCode.cpp' % args.srcdir,
               dispatchCodeTemplate.substitute(substitute))
コード例 #36
0
def apiStatisticsFuncDefineCode(apis, args):
  categoryPrev = None
  code = ''

  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

      if not function.needsContext:
        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, 'statistics_', name, params)
      code += '  RegalContext *_context = REGAL_GET_CONTEXT();\n'
      code += '  RegalAssert(_context);\n'
      code += '\n'
      code += '  RegalAssert(_context->statistics);\n'
      code += '  Statistics &statistics = *_context->statistics;\n'
      code += '  statistics.%s++;\n'%(name)
      code += '\n'

      # Extension

      for i in api.extensions:
        if name in i.functions:
          code += '  statistics.%s++;\n'%(i.name.lower())
        code += '\n'

      # glEnable

      if name=='glEnable':
        code += '  switch (cap)\n'
        code += '  {\n'
        for i in api.enums:
          if i.name=='defines':
            for j in i.enumerantsByName:
              if getattr(j,'enableCap',False) == True:
                code += '    case %-40s %-60s break;\n'%(j.name+':','statistics.enable_%s++;'%j.name)
        code += '    default: break;\n'
        code += '  }\n\n'

      # glDisable

      if name=='glDisable':
        code += '  switch (cap)\n'
        code += '  {\n'
        for i in api.enums:
          if i.name=='defines':
            for j in i.enumerantsByName:
              if getattr(j,'enableCap',False) == True:
                code += '    case %-40s %-60s break;\n'%(j.name+':','statistics.disable_%s++;'%j.name)
        code += '    default: break;\n'
        code += '  }\n\n'

      if function.needsContext:
        code += '  DispatchTableGL *_next = _context->dispatcher.statistics.next();\n'
      else:
        code += '  DispatchTableGlobal *_next = dispatcherGlobal.statistics.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 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'

  return code
コード例 #37
0
ファイル: Emu.py プロジェクト: vvuk/regal
def emuFindEntry(func, emuFormulae, member):

    if emuFormulae == None:
        return None

    name = func.name

    # list of function parameter names

    arglist = [i.name.strip() for i in func.parameters]

    # arg is a mapping from arg0 to function parameter name...

    arg = {}
    for i in range(len(arglist)):
        arg['arg%d' % i] = arglist[i]

    # ... and mappings from arg0plus to lists of function parameters

    for i in range(0, 5):
        label = 'arg%dplus' % i
        if len(arglist) > 0:
            arg[label] = ', '.join(arglist)
            arglist.pop(0)
        else:
            arg[label] = ''

    # Iterator over the formulae
    #
    # k is the key
    # i is the formula

    for k, i in emuFormulae.iteritems():

        # Cache the compiled regular expressions, as needed

        if 'entries_re' not in i:
            i['entries_re'] = [re.compile('^%s$' % j) for j in i['entries']]

    # A list of matches containing (match object, formula name, formula)
    # Look for matches, ideally only one

    m = [[j.match(name), k, i] for k, i in emuFormulae.iteritems()
         for j in i['entries_re']]
    m = [j for j in m if j[0]]

    assert len(m) <= 1, 'Ambiguous match (%s) for %s - giving up.' % (
        ', '.join([j[1] for j in m]), name)

    if len(m):
        match = m[0][0]
        formula = m[0][2]
        rType = typeCode(func.ret.type)
        dummyRetVal = ''
        if not typeIsVoid(rType):
            dummyRetVal = '(( %s )0)' % rType
        emue = {'name': name, 'member': member, 'dummyretval': dummyRetVal}
        subs = deepcopy(arg)
        for l in range(len(match.groups()) + 1):
            subs['m%d' % l] = match.group(l)
        subs['name'] = name
        subs['dummyretval'] = dummyRetVal
        addSubstitution(name, formula, subs)
        substitute(emue, formula, 'impl', subs)
        substitute(emue, formula, 'init', subs)
        substitute(emue, formula, 'cond', subs)
        substitute(emue, formula, 'prefix', subs)
        substitute(emue, formula, 'suffix', subs)
        substitute(emue, formula, 'pre', subs)
        substitute(emue, formula, 'post', subs)

        emue['cond'] = None
        if 'cond' in formula:
            emue['cond'] = formula['cond']

        # plugin is optional, default to False

        emue['plugin'] = False
        if 'plugin' in formula:
            emue['plugin'] = formula['plugin']

        return emue

    return None
コード例 #38
0
ファイル: RegalDispatchCode.py プロジェクト: achienbsi/regal
def generateDispatchCode(apis, args):

  code = ''

  for api in apis:
    if api.name=='gl':

      for function in api.functions:

        if not function.needsContext:
          continue

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

	if function.name in exclude:
	  continue

	f = deepcopy(function)

        name = f.name
        params = paramsDefaultCode(f.parameters, True)

        callParams = paramsNameCode(f.parameters)
        rType  = typeCode(f.ret.type)

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

        code += '    RegalContext *_context = REGAL_GET_CONTEXT();\n'
        code += '    RegalAssert(_context);\n'
        code += '    DispatchTable *_next = _context->dispatcher.code._next;\n'
        code += '    RegalAssert(_next);\n'
        code += '    '

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

        # comment-out calls to functions flagged as trace = False

        prefix = ''
        suffix = ''
        if not f.trace:
          prefix += '/* '
          suffix += ' */'

        h      = False	
        h1 =  '    std::string indent((_context->depthBeginEnd + _context->depthPushAttrib + 1)*2,\' \');\n'
        h2 =  ''
        body   =  ''

	ret = ''
        if not typeIsVoid(rType):
	  if   f.name in [ 'glCreateShader','glCreateShaderObjectARB' ]:
	    h2 += '    size_t _retIndex = _context->codeShaderNext++;\n'
	    ret = 'const %s shader\" << _retIndex << \" = '%typeStrip(rType)
	  elif f.name in [ 'glCreateProgram','glCreateProgramObjectARB']:
	    h2 += '    size_t _retIndex = _context->codeProgramNext++;\n'
	    ret = 'const %s program\" << _retIndex << \" = '%typeStrip(rType)
	  else:
	    h2 += '    size_t _retIndex = _context->codeOutputNext++;\n'
	    ret = 'const %s o\" << _retIndex << \" = '%typeStrip(rType)

        if len(f.parameters)==0:
          body += '    %s_code << indent << "%s%s();%s\\n";\n'%(prefix,ret,f.name,suffix)
        else:
          body += '    %s_code << indent << "%s%s(";\n'%(prefix,ret,f.name)

          if f.name.startswith('glShaderSource'):
            h2 += '    std::string _delim = print_string("\\\\n\\"\\n",indent,"  \\"");\n'
            h2 += '    size_t _stringIndex = _context->codeInputNext++;\n'
            h2 += '    _code << indent << \"const char *i\" << _stringIndex << \" =\\n\";\n'
            h2 += '    _code << indent << "  \\\"" << string_list< ::std::string >(string_list< ::std::string >(count,string,length).str(),\'\\n\').join(_delim) << "\\";\\n";\n'
            body   += '    _code << %s << ",1,&i" <<_stringIndex << ",NULL);\\n";\n'%(f.parameters[0].name)

          else:
            delim = False
            for i in f.parameters:
              if delim:
                body += '    _code << ", "; '
              elif len(f.parameters)>1:
                body += '                   '
              else:
                body += '    '

#             p = cCodeParameter(f,i)
              p = logParameter(f,i)

              # For parameters not handled yet...

              if p==None:
                  body += '_code << "/* %s = ?? */";\n'%(i.name)

              # Special handling for input our output arrays

              elif p.startswith('boost::print::array'):
                  type = typeStrip(i.type)
                  size = i.size
                  if i.maxSize != None:
                    size = i.maxSize
                  if i.input:
                    if p.find('helper')==-1 and type!='GLchar' and type!='GLcharARB':
                      h2 += '    size_t _%sIndex = _context->codeInputNext++;\n'%(i.name)
                      h2 += '    _code << indent << \"const %s i\" << _%sIndex << \"[\" << (%s) << \"] = \" '%(type,i.name,size)
                      h2 += '<< array<%s,const char * const>(%s,%s,\"\",\"{ \",\" };\",\", \") '%(type,i.name,size)
                      h2 += '<< \"\\n\";\n'
                      body += '_code << \"i\" << _%sIndex;\n'%(i.name)
                    else:
                      body += '_code << "/* %s = ?? */";\n'%(i.name)
                  else:
                    if p.find('helper')==-1 and type!='GLchar' and type!='GLcharARB':
                      h2 += '    size_t _%sIndex = _context->codeOutputNext++;\n'%(i.name)
                      h2 += '    _code << indent << \"%s o\" << _%sIndex << \"[\" << (%s) << \"];\\n";\n'%(type,i.name,size)
                      body += '_code << \"o\" << _%sIndex;\n'%(i.name)
                    else:
                      body += '_code << "/* %s = ?? */";\n'%(i.name)

              # glTexImage2D etc

              elif i.size != None and (isinstance(i.size, str) or isinstance(i.size, unicode)) and i.size.startswith('helperGLPixelImageSize'):
                h2 += '    size_t _%sIndex = _context->codeInputNext++;\n'%(i.name)
                h2 += '    _header << indent << \"const GLubyte i\" << _%sIndex << \"[\" << helper::size::pixelImage(%s << \"] = \" '%(i.name,i.size.split('(',1)[1])
                h2 += '<< array<GLubyte,const char * const>(static_cast<const GLubyte *>(%s),helper::size::pixelImage(%s,\"\",\"{ \",\" }\",\",\") '%(i.name,i.size.split('(',1)[1])
                h2 += '<< \";\\n\";\n'
                h = True
                body += '_code << \"i\" << _%sIndex;\n'%(i.name)

              elif p.startswith('boost::print::optional'):
                if i.cast != None:
                  body += '_code << reinterpret_cast<%s>(%s);\n'%(i.cast,i.name)
                else:
                  body += '_code << %s;\n'%(i.name)

              # 0x prefix for hex output

              elif p.startswith('boost::print::hex'):
                body += '_code << \"0x\" << %s;\n'%(p)

              elif p.startswith('boost::print::raw'):   # Buffer data needs better handling, revisit
                  body += '_code << "NULL";\n'

              else:
                  body += '_code << %s;\n'%(p)

              delim = True

            body += '    _code << ");%s\\n";\n'%(suffix)

        h1 += '    string_list< ::std::string > _code;\n'
        body += '    if (_context->codeSource)\n'
        body += '      fprintf(_context->codeSource,"%s",_code.str().c_str());\n'

	if h:
          h1 += '    string_list< ::std::string > _header;\n'
	  body += '    if (_context->codeHeader)\n'
	  body += '      fprintf(_context->codeHeader,"%s",_header.str().c_str());\n'

#        body += '    Internal("code_%s",_code);\n'%name

        code += h1 + h2 + body

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

    code += '\n'

  funcInit   = apiDispatchCodeInitCode( apis, args, 'code' )

  # Output

  substitute = {}
  substitute['LICENSE']         = args.license
  substitute['AUTOGENERATED']   = args.generated
  substitute['COPYRIGHT']       = args.copyright
  substitute['API_FUNC_DEFINE'] = code
  substitute['API_GLOBAL_DISPATCH_INIT'] = funcInit

  outputCode( '%s/RegalDispatchCode.cpp' % args.srcdir, dispatchCodeTemplate.substitute(substitute))
コード例 #39
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))
コード例 #40
0
ファイル: Regal.py プロジェクト: swq0553/regal
def apiFuncDefineCode(apis, args):

  #

  code = ''
  for api in apis:

    tmp = []
    for function in api.functions:

      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

      c = ''
      c += 'REGAL_DECL %sREGAL_CALL %s(%s) \n{\n' % (rType, name, params)

      emue = [ emuFindEntry( function, i['formulae'], i['member'] ) for i in emuRegal ]

      if function.needsContext:
        c += '  RegalContext *_context = REGAL_GET_CONTEXT();\n'
        c += listToString(indent(stripVertical(emuCodeGen(emue,'prefix')),'  '))
        c += '  %s\n' % logFunction( function, 'App' )
        c += '  if (!_context) return'
        if typeIsVoid(rType):
          c += ';\n'
        else:
          if rTypes in api.defaults:
            c += ' %s;\n' % ( api.defaults[rTypes] )
          else:
            if rType[-1]=='*' or typeIsVoidPointer(rType):
              c += ' NULL;\n'
            else:
              c += ' (%s) 0;\n' % ( rTypes )

        c += listToString(indent(stripVertical(emuCodeGen(emue,'impl')),'  '))

        if getattr(function,'regalRemap',None)!=None and (isinstance(function.regalRemap, list) or isinstance(function.regalRemap, str) or isinstance(function.regalRemap, unicode)):

          # For an ES1 context, pass the call into the dispatch layers...

          if function.category in ['GL_REGAL_ES1_0_compatibility','GL_REGAL_ES1_1_compatibility']:
            c += '  #if REGAL_SYS_ES1\n'
            c += '  if (_context->isES1()) // Pass-through for ES1 only\n'
            c += '  {\n'
            c += '    DispatchTableGL *_next = &_context->dispatcher.front();\n'
            c += '    RegalAssert(_next);\n    '
            if not typeIsVoid(rType):
              c += 'return '
            c += '_next->call(&_next->%s)(%s);\n' % ( name, callParams )
            if typeIsVoid(rType):
              c += '    return;\n'
            c += '  }\n'
            c += '  #endif\n'

          # For ES2 or GL context, remap the ES1 call

          c += '  '
          if not typeIsVoid(rType):
            c += 'return '
          if isinstance(function.regalRemap, list):
            c += '\n  '.join(function.regalRemap) + '\n'
          else:
            c += '%s;\n'%(function.regalRemap)
        else:
          if not getattr(function,'regalOnly',False):
            t = ''
            t += 'DispatchTableGL *_next = &_context->dispatcher.front();\n'
            t += 'RegalAssert(_next);\n'

            t += listToString(indent(stripVertical(emuCodeGen(emue,'pre')),''))

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

            t += listToString(indent(stripVertical(emuCodeGen(emue,'post')),''))

            for i in emue:
              if i!=None and i['cond']!=None:
                t = wrapCIf(i['cond'],indent(t))

            c += indent(t)

            c += listToString(indent(stripVertical(emuCodeGen(emue,'suffix')),'  '))

      else:
        c += '  %s\n' % logFunction(function, 'App' )
        c += listToString(indent(stripVertical(emuCodeGen(emue,'prefix')),'  '))

        if not getattr(function,'regalOnly',False):
          c += '  DispatchTableGlobal *_next = &dispatcherGlobal.front();\n'
          c += '  RegalAssert(_next);\n'

          if not typeIsVoid(rType):
            if rTypes in api.defaults:
              c += '  %s ret = %s;\n' % ( rTypes, api.defaults[rTypes] )
            else:
              if rType[-1]=='*' or typeIsVoidPointer(rType):
                c += '  %s ret = NULL;\n' % rTypes
              else:
                c += '  %s ret = (%s) 0;\n' % ( rTypes, rTypes )

          c += listToString(indent(stripVertical(emuCodeGen(emue,'impl')),'  '))
          c += '  '
          if not typeIsVoid(rType):
            c += 'ret = '
          c += '_next->call(&_next->%s)(%s);\n' % ( name, callParams )

        c += listToString(indent(stripVertical(emuCodeGen(emue,'init')),'  '))

        c += listToString(indent(stripVertical(emuCodeGen(emue,'suffix')),'  '))
        if not typeIsVoid(rType):
          c += '  return ret;\n'
      c += '}\n\n'

      tmp.append( (category, indent(c,'  ') ) )

    tmp = listToString(unfoldCategory(tmp,'  /* %s */'))

    if api.name in cond:
      tmp = wrapIf(cond[api.name], tmp)

    code += tmp

  return code
コード例 #41
0
ファイル: RegalDispatchLoader.py プロジェクト: greggman/regal
def apiLoaderFuncDefineCode(apis, args):
  categoryPrev = None
  code = ''

  for api in apis:

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

    for function in api.functions:
      if not function.needsContext:
        continue
      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, 'loader_', name, params)
      code += '  RegalContext * _context = GET_REGAL_CONTEXT();\n'
      code += '  RegalAssert(_context);\n'
      code += '  DispatchTable &_driver = _context->dispatcher.driver;\n'
      code += '  GetProcAddress(_driver.%s, "%s");\n' % (name, name)
      code += '  if (_driver.%s) {\n    ' % name
      if not typeIsVoid(rType):
        code += 'return '
      code += '_driver.%s(%s);\n' % ( name, callParams )
      if typeIsVoid(rType):
        code += '    return;\n'
      code += '  }\n'
      code += '  Dispatcher::ScopedStep stepDown(_context->dispatcher);\n  '
      if not typeIsVoid(rType):
        code += 'return '
      code += '_context->dispatcher.call(&_context->dispatcher.table().%s)(%s);\n'%(name, callParams)
      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'

  return code