1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
"""Abstraction for the platform-specific code in PyOpenGL
Each supported platform has a module which provides the
specific functionality required to support the base OpenGL
functionality on that platform. These modules are
registered using plugins in the:
OpenGL.plugin.PlatformPlugin
objects. To support a new platform you'll need to create
a new PlatformPlugin instance *before* you import
OpenGL.platform . Once you have a working platform
module, please consider contributing it back to the project.
See baseplatform.BasePlatform for the core functionality
of a platform implementation. See the various platform
specific modules for examples to use when porting.
"""
import os, sys
from OpenGL.plugins import PlatformPlugin
def _load( ):
"""Load the os.name plugin for the platform functionality"""
key = (os.environ.get( 'PYOPENGL_PLATFORM'), sys.platform,os.name)
plugin = PlatformPlugin.match( key )
plugin_class = plugin.load()
plugin.loaded = True
# create instance of this platform implementation
plugin = plugin_class()
# install into the platform module's namespace now
plugin.install(globals())
return plugin
_load()
def types(resultType,*argTypes):
"""Decorator to add returnType, argTypes and argNames to a function"""
def add_types( function ):
"""Adds the given metadata to the function, introspects var names from declaration"""
function.resultType = resultType
function.argTypes = argTypes
if hasattr( function, 'func_code' ): # python 2.x
function.argNames = function.func_code.co_varnames
else:
function.argNames = function.__code__.co_varnames
return function
return add_types
def unpack_constants( constants, namespace ):
"""Create constants and add to the namespace"""
from OpenGL.constant import Constant
for line in constants.splitlines():
if line and line.split():
name,value = line.split()
namespace[name] = Constant( name, int(value,16) )
def createFunction( function, dll,extension,deprecated=False, error_checker=None ):
"""Allows the more compact declaration format to use the old-style constructor"""
return nullFunction(
function.__name__,
dll or PLATFORM.GL,
resultType = function.resultType,
argTypes = function.argTypes,
doc = None, argNames = function.argNames,
extension = extension,
deprecated = deprecated,
module = function.__module__,
error_checker = error_checker,
)
|