Exemplo n.º 1
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)
      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
Exemplo n.º 2
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 = 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
Exemplo n.º 3
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)
            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
Exemplo n.º 4
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)
            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
Exemplo n.º 5
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