Ejemplo n.º 1
0
class DarwinPlatform(baseplatform.BasePlatform):
    """Darwin (OSX) platform implementation"""
    DEFAULT_FUNCTION_TYPE = staticmethod(ctypes.CFUNCTYPE)
    EXTENSIONS_USE_BASE_FUNCTIONS = True

    # Get the pointers to the libraries...
    try:
        OpenGL = ctypesloader.loadLibrary(ctypes.cdll,
                                          'OpenGL',
                                          mode=ctypes.RTLD_GLOBAL)
    except OSError as err:
        raise ImportError("Unable to load OpenGL library", *err.args)
    # CGL provides the windowing environment functionality
    # but it is built into the GL libs.
    GL = GLU = CGL = OpenGL

    # glut shouldn't need to be global, but just in case a dependent library makes
    # the same assumption GLUT does...
    GLUT = ctypesloader.loadLibrary(ctypes.cdll,
                                    'GLUT',
                                    mode=ctypes.RTLD_GLOBAL)

    # GLE is handled by GLUT under OS X
    GLE = GLUT

    GetCurrentContext = CurrentContextIsValid = staticmethod(
        CGL.CGLGetCurrentContext)

    def getGLUTFontPointer(self, constant):
        """Platform specific function to retrieve a GLUT font pointer
        
        GLUTAPI void *glutBitmap9By15;
        #define GLUT_BITMAP_9_BY_15     (&glutBitmap9By15)
        
        Key here is that we want the addressof the pointer in the DLL,
        not the pointer in the DLL.  That is, our pointer is to the 
        pointer defined in the DLL, we don't want the *value* stored in
        that pointer.
        """
        name = [x.title() for x in constant.split('_')[1:]]
        internal = 'glut' + "".join([x.title() for x in name])
        pointer = ctypes.c_void_p.in_dll(self.GLUT, internal)
        return ctypes.c_void_p(ctypes.addressof(pointer))

    def safeGetError(self):
        """Provide context-not-present-safe error-checking
        
        Under OS-X an attempt to retrieve error without checking 
        context will bus-error.  This function checks for a valid
        context before running glGetError
        
        Note:
            This is a likely candidate for rewriting in C, as it
            is called for every almost function in the system!
        """
        if self.CurrentContextIsValid():
            return glGetError()
        return None
Ejemplo n.º 2
0
 def GLU(self):
     try:
         return ctypesloader.loadLibrary(ctypes.cdll,
                                         'GLU',
                                         mode=ctypes.RTLD_GLOBAL)
     except OSError:
         return None
Ejemplo n.º 3
0
 def GLU(self):
     try:
         return ctypesloader.loadLibrary(ctypes.windll,
                                         "glu32",
                                         mode=ctypes.RTLD_GLOBAL)
     except OSError:
         return None
Ejemplo n.º 4
0
 def GLES2(self):
     try:
         return ctypesloader.loadLibrary(ctypes.cdll,
                                         "GLESv2",
                                         mode=ctypes.RTLD_GLOBAL)
     except OSError:
         return None
Ejemplo n.º 5
0
 def GL(self):
     try:
         return ctypesloader.loadLibrary(ctypes.cdll,
                                         'OSMesa',
                                         mode=ctypes.RTLD_GLOBAL)
     except OSError as err:
         raise ImportError("Unable to load OpenGL library", *err.args)
Ejemplo n.º 6
0
 def GLE(self):
     try:
         return ctypesloader.loadLibrary(ctypes.cdll,
                                         'gle',
                                         mode=ctypes.RTLD_GLOBAL)
     except OSError as err:
         return None
Ejemplo n.º 7
0
class Win32Platform(baseplatform.BasePlatform):
    """Win32-specific platform implementation"""

    GLUT_GUARD_CALLBACKS = True
    GL = OpenGL = ctypesloader.loadLibrary(ctypes.windll,
                                           'opengl32',
                                           mode=ctypes.RTLD_GLOBAL)
    GLU = ctypesloader.loadLibrary(ctypes.windll,
                                   'glu32',
                                   mode=ctypes.RTLD_GLOBAL)
    try:
        GLUT = ctypesloader.loadLibrary(ctypes.windll,
                                        'glut32',
                                        mode=ctypes.RTLD_GLOBAL)
    except WindowsError, err:
        GLUT = None
Ejemplo n.º 8
0
 def GLU(self):
     try:
         return ctypesloader.loadLibrary(
             ctypes.windll, 'glu32', mode = ctypes.RTLD_GLOBAL
         )
     except OSError as err:
         return None
Ejemplo n.º 9
0
 def GL(self):
     try:
         return ctypesloader.loadLibrary(
             ctypes.windll, 'opengl32', mode = ctypes.RTLD_GLOBAL
         ) 
     except OSError as err:
         raise ImportError("Unable to load OpenGL library", *err.args)
Ejemplo n.º 10
0
 def GL(self):
     try:
         return ctypesloader.loadLibrary(ctypes.cdll,
                                         'GL',
                                         mode=ctypes.RTLD_GLOBAL)
     except OSError as err:
         return self.GLES2 or self.GLES1
Ejemplo n.º 11
0
 def getScreen( self, display ):
     from OpenGL.platform import ctypesloader
     from OpenGL.raw.GLX import _types
     import ctypes, os
     X11 = ctypesloader.loadLibrary( ctypes.cdll, 'X11' )
     XDefaultScreen = X11.XDefaultScreen
     XDefaultScreen.argtypes = [ctypes.POINTER(_types.Display)]
     return XDefaultScreen( display )
Ejemplo n.º 12
0
 def getDisplay( self ):
     from OpenGL.raw.GLX import _types
     from OpenGL.platform import ctypesloader
     import ctypes, os
     X11 = ctypesloader.loadLibrary( ctypes.cdll, 'X11' )
     XOpenDisplay = X11.XOpenDisplay 
     XOpenDisplay.restype = ctypes.POINTER(_types.Display)
     return XOpenDisplay( os.environ.get( 'DISPLAY' ))
Ejemplo n.º 13
0
class GLXPlatform(baseplatform.BasePlatform):
    """Posix (Linux, FreeBSD, etceteras) implementation for PyOpenGL"""
    # On Linux (and, I assume, most GLX platforms, we have to load
    # GL and GLU with the "global" flag to allow GLUT to resolve its
    # references to GL/GLU functions).
    GL = OpenGL = ctypesloader.loadLibrary(ctypes.cdll,
                                           'GL',
                                           mode=ctypes.RTLD_GLOBAL)
    GLU = ctypesloader.loadLibrary(ctypes.cdll, 'GLU', mode=ctypes.RTLD_GLOBAL)
    # glut shouldn't need to be global, but just in case a dependent library makes
    # the same assumption GLUT does...
    try:
        GLUT = ctypesloader.loadLibrary(ctypes.cdll,
                                        'glut',
                                        mode=ctypes.RTLD_GLOBAL)
    except OSError, err:
        GLUT = None
Ejemplo n.º 14
0
 def GLES1(self):
     try:
         return ctypesloader.loadLibrary(
             ctypes.cdll,
             'GLESv1_CM',  # ick
             mode=ctypes.RTLD_GLOBAL)
     except OSError:
         return None
Ejemplo n.º 15
0
 def getDisplay(self):
     from OpenGL.raw.GLX import _types
     from OpenGL.platform import ctypesloader
     import ctypes, os
     X11 = ctypesloader.loadLibrary(ctypes.cdll, "X11")
     XOpenDisplay = X11.XOpenDisplay 
     XOpenDisplay.restype = ctypes.POINTER(_types.Display)
     return XOpenDisplay(os.environ.get("DISPLAY"))
Ejemplo n.º 16
0
 def getScreen(self, display):
     from OpenGL.platform import ctypesloader
     from OpenGL.raw.GLX import _types
     import ctypes, os
     X11 = ctypesloader.loadLibrary(ctypes.cdll, "X11")
     XDefaultScreen = X11.XDefaultScreen
     XDefaultScreen.argtypes = [ctypes.POINTER(_types.Display)]
     return XDefaultScreen(display)
Ejemplo n.º 17
0
class OSMesaPlatform(baseplatform.BasePlatform):
    """OSMesa implementation for PyOpenGL"""
    try:
        GL = OpenGL = ctypesloader.loadLibrary(ctypes.cdll,
                                               'OSMesa',
                                               mode=ctypes.RTLD_GLOBAL)
    except OSError, err:
        raise ImportError("Unable to load OpenGL library", *err.args)
Ejemplo n.º 18
0
 def GLES1(self):
     try:
         return ctypesloader.loadLibrary(
             ctypes.cdll,
             'GLESv1_CM', # ick
             mode=ctypes.RTLD_GLOBAL 
         )
     except OSError as err:
         return None
Ejemplo n.º 19
0
 def EGL(self):
     try:
         return ctypesloader.loadLibrary(
             ctypes.cdll,
             'EGL', 
             mode=ctypes.RTLD_GLOBAL 
         )
     except OSError as err:
         raise ImportError("Unable to load EGL library", *err.args)
Ejemplo n.º 20
0
 def GL(self):
     try:
         return ctypesloader.loadLibrary(
             ctypes.cdll,
             'GL', 
             mode=ctypes.RTLD_GLOBAL 
         )
     except OSError as err:
         return self.GLES2 or self.GLES1
Ejemplo n.º 21
0
 def GLUT(self):
     for possible in ("freeglut%s.%s" % (size, vc), "glut%s.%s" % (size, vc)):
         # Prefer FreeGLUT if the user has installed it, fallback to the included
         # GLUT if it is installed
         try:
             return ctypesloader.loadLibrary(ctypes.windll, possible, mode=ctypes.RTLD_GLOBAL)
         except WindowsError:
             pass
     return None
Ejemplo n.º 22
0
 def GLUT( self ):
     try:
         return ctypesloader.loadLibrary(
             ctypes.cdll,
             'GLUT', 
             mode=ctypes.RTLD_GLOBAL 
         )
     except OSError:
         return None
Ejemplo n.º 23
0
class Win32Platform(baseplatform.BasePlatform):
    """Win32-specific platform implementation"""

    GLUT_GUARD_CALLBACKS = True
    try:
        GL = OpenGL = ctypesloader.loadLibrary(ctypes.windll,
                                               'opengl32',
                                               mode=ctypes.RTLD_GLOBAL)
    except OSError, err:
        raise ImportError("Unable to load OpenGL library", *err.args)
Ejemplo n.º 24
0
 def GLUT( self ):
     for possible in ('freeglut%s.%s'%(size,vc,), 'glut%s.%s'%(size,vc,)):
         # Prefer FreeGLUT if the user has installed it, fallback to the included 
         # GLUT if it is installed
         try:
             return ctypesloader.loadLibrary(
                 ctypes.windll, possible, mode = ctypes.RTLD_GLOBAL
             )
         except WindowsError:
             pass
     return None
Ejemplo n.º 25
0
 def GLE(self):
     for libName in ("gle%s.%s" % (size, vc), "opengle%s.%s" % (size, vc)):
         try:
             GLE = ctypesloader.loadLibrary(ctypes.cdll, libName)
             GLE.FunctionType = ctypes.CFUNCTYPE
             return GLE
         except WindowsError:
             pass
         else:
             break
     return None
Ejemplo n.º 26
0
 def GLE( self ):
     for libName in ('gle%s.%s'%(size,vc,), 'opengle%s.%s'%(size,vc,)):
         try:
             GLE = ctypesloader.loadLibrary( ctypes.cdll, libName )
             GLE.FunctionType = ctypes.CFUNCTYPE
             return GLE
         except WindowsError:
             pass
         else:
             break
     return None
Ejemplo n.º 27
0
class GLXPlatform(baseplatform.BasePlatform):
    """Posix (Linux, FreeBSD, etceteras) implementation for PyOpenGL"""
    # On Linux (and, I assume, most GLX platforms, we have to load
    # GL and GLU with the "global" flag to allow GLUT to resolve its
    # references to GL/GLU functions).
    try:
        GL = OpenGL = ctypesloader.loadLibrary(ctypes.cdll,
                                               'GL',
                                               mode=ctypes.RTLD_GLOBAL)
    except OSError, err:
        raise ImportError("Unable to load OpenGL library", *err.args)
Ejemplo n.º 28
0
 def GL(self):
     try:
         for name in ('OpenGL', 'GL'):
             lib = ctypesloader.loadLibrary(ctypes.cdll,
                                            'GL',
                                            mode=ctypes.RTLD_GLOBAL)
             if lib:
                 return lib
         raise OSError("No GL/OpenGL library available")
     except OSError:
         return self.GLES2 or self.GLES1
Ejemplo n.º 29
0
class DarwinPlatform(baseplatform.BasePlatform):
    """Darwin (OSX) platform implementation"""
    DEFAULT_FUNCTION_TYPE = staticmethod(ctypes.CFUNCTYPE)
    EXTENSIONS_USE_BASE_FUNCTIONS = True

    # Get the pointers to the libraries...
    try:
        OpenGL = ctypesloader.loadLibrary(ctypes.cdll,
                                          'OpenGL',
                                          mode=ctypes.RTLD_GLOBAL)
    except OSError, err:
        raise ImportError("Unable to load OpenGL library", *err.args)
Ejemplo n.º 30
0
class Win32Platform(baseplatform.BasePlatform):
    """Win32-specific platform implementation"""

    GLUT_GUARD_CALLBACKS = True
    GL = OpenGL = ctypesloader.loadLibrary(ctypes.windll,
                                           'opengl32',
                                           mode=ctypes.RTLD_GLOBAL)
    GLU = ctypesloader.loadLibrary(ctypes.windll,
                                   'glu32',
                                   mode=ctypes.RTLD_GLOBAL)

    GLUT = None
    for possible in ('glut32', 'freeglut32', 'freeglut'):
        # load first-up of the possible names...
        try:
            GLUT = ctypesloader.loadLibrary(ctypes.windll,
                                            possible,
                                            mode=ctypes.RTLD_GLOBAL)
        except WindowsError, err:
            GLUT = None
        else:
            break
Ejemplo n.º 31
0
 def EGL(self):
     # TODO: the raspberry pi crashes on trying to load EGL module
     # because the EGL library requires a structure from GLES2 without
     # linking to that library... Github issue is here:
     #   https://github.com/raspberrypi/firmware/issues/110
     import os
     if os.path.exists('/proc/cpuinfo'):
         info = open('/proc/cpuinfo').read()
         if 'BCM2708' in info or 'BCM2709' in info:
             assert self.GLES2
     try:
         return ctypesloader.loadLibrary(ctypes.cdll,
                                         'EGL',
                                         mode=ctypes.RTLD_GLOBAL)
     except OSError as err:
         raise ImportError("Unable to load EGL library", *err.args)
Ejemplo n.º 32
0
 def EGL(self):
     # TODO: the raspberry pi crashes on trying to load EGL module 
     # because the EGL library requires a structure from GLES2 without 
     # linking to that library... Github issue is here:
     #   https://github.com/raspberrypi/firmware/issues/110
     import os
     if os.path.exists('/proc/cpuinfo'):
         info = open('/proc/cpuinfo').read()
         if 'BCM2708' in info or 'BCM2709' in info:
             assert self.GLES2
     try:
         return ctypesloader.loadLibrary(
             ctypes.cdll,
             'EGL', 
             mode=ctypes.RTLD_GLOBAL 
         )
     except OSError as err:
         raise ImportError("Unable to load EGL library", *err.args)
Ejemplo n.º 33
0
class GLXPlatform(baseplatform.BasePlatform):
    """Posix (Linux, FreeBSD, etceteras) implementation for PyOpenGL"""
    # On Linux (and, I assume, most GLX platforms, we have to load
    # GL and GLU with the "global" flag to allow GLUT to resolve its
    # references to GL/GLU functions).
    try:
        GL = OpenGL = ctypesloader.loadLibrary(ctypes.cdll,
                                               'GL',
                                               mode=ctypes.RTLD_GLOBAL)
    except OSError as err:
        raise ImportError("Unable to load OpenGL library", *err.args)
    try:
        GLU = ctypesloader.loadLibrary(ctypes.cdll,
                                       'GLU',
                                       mode=ctypes.RTLD_GLOBAL)
    except OSError as err:
        GLU = None
    # glut shouldn't need to be global, but just in case a dependent library makes
    # the same assumption GLUT does...
    try:
        GLUT = ctypesloader.loadLibrary(ctypes.cdll,
                                        'glut',
                                        mode=ctypes.RTLD_GLOBAL)
    except OSError as err:
        GLUT = None
    # GLX doesn't seem to have its own loadable module?
    GLX = GL
    glXGetProcAddressARB = GL.glXGetProcAddressARB
    glXGetProcAddressARB.restype = ctypes.c_void_p
    getExtensionProcedure = staticmethod(glXGetProcAddressARB)
    try:
        GLE = ctypesloader.loadLibrary(ctypes.cdll,
                                       'gle',
                                       mode=ctypes.RTLD_GLOBAL)
    except OSError as err:
        GLE = None

    DEFAULT_FUNCTION_TYPE = staticmethod(ctypes.CFUNCTYPE)

    # This loads the GLX functions from the GL .so, not sure if that's
    # really kosher...
    GetCurrentContext = CurrentContextIsValid = staticmethod(
        GL.glXGetCurrentContext)

    def getGLUTFontPointer(self, constant):
        """Platform specific function to retrieve a GLUT font pointer
        
        GLUTAPI void *glutBitmap9By15;
        #define GLUT_BITMAP_9_BY_15		(&glutBitmap9By15)
        
        Key here is that we want the addressof the pointer in the DLL,
        not the pointer in the DLL.  That is, our pointer is to the 
        pointer defined in the DLL, we don't want the *value* stored in
        that pointer.
        """
        name = [x.title() for x in constant.split('_')[1:]]
        internal = 'glut' + "".join([x.title() for x in name])
        pointer = ctypes.c_void_p.in_dll(self.GLUT, internal)
        return ctypes.c_void_p(ctypes.addressof(pointer))

    safeGetError = staticmethod(OpenGL.glGetError)
Ejemplo n.º 34
0
"""Utility module for interacting with GBM to select rendering device

The base code here comes from github bug report #6 in the pyopengl
project, thanks to @abandoned-cocoon for that.
"""
import weakref, ctypes, logging, os, glob
from OpenGL.platform import ctypesloader
from OpenGL import _opaque
log = logging.getLogger(__name__)
gbm = ctypesloader.loadLibrary(ctypes.CDLL,"gbm")
__all__ = ("enumerate_devices","open_device","close_device","gbm")
_DEVICE_HANDLES = {}
GBM_BO_USE_SCANOUT = (1 << 0)
GBM_BO_USE_CURSOR = (1 << 1)
GBM_BO_USE_CURSOR_64X64 = GBM_BO_USE_CURSOR
GBM_BO_USE_RENDERING = (1 << 2)
GBM_BO_USE_WRITE = (1 << 3)
GBM_BO_USE_LINEAR = (1 << 4)

GBMDevice = _opaque.opaque_pointer_cls("GBMDevice")
GBMSurface = _opaque.opaque_pointer_cls("GBMSurface")
gbm.gbm_create_device.restype = GBMDevice
gbm.gbm_surface_create.restype = GBMSurface

def filter_bad_drivers(cards, bad_drivers=("nvidia",)):
    """Lookup the driver for each card to exclude loading nvidia devices"""
    # this is pci specific, which I suppose means we"re going to fail
    # if the GPU isn"t on the PCI bus, but we don"t seem to have
    # another way to match up the card to the driver :(
    bad_cards = set()
    for link in glob.glob("/dev/dri/by-path/pci-*-card"):
Ejemplo n.º 35
0
    GL = OpenGL = ctypesloader.loadLibrary(ctypes.windll,
                                           'opengl32',
                                           mode=ctypes.RTLD_GLOBAL)
    GLU = ctypesloader.loadLibrary(ctypes.windll,
                                   'glu32',
                                   mode=ctypes.RTLD_GLOBAL)
    try:
        GLUT = ctypesloader.loadLibrary(ctypes.windll,
                                        'glut32',
                                        mode=ctypes.RTLD_GLOBAL)
    except WindowsError, err:
        GLUT = None
    GLE = None
    for libName in ('gle32', 'opengle32'):
        try:
            GLE = ctypesloader.loadLibrary(ctypes.cdll, libName)
            GLE.FunctionType = ctypes.CFUNCTYPE
        except WindowsError, err:
            pass
        else:
            break

    DEFAULT_FUNCTION_TYPE = staticmethod(ctypes.WINFUNCTYPE)
    # Win32 GLUT uses different types for callbacks and functions...
    GLUT_CALLBACK_TYPE = staticmethod(ctypes.CFUNCTYPE)
    WGL = ctypes.windll.gdi32
    getExtensionProcedure = staticmethod(OpenGL.wglGetProcAddress)

    GLUT_FONT_CONSTANTS = {
        'GLUT_STROKE_ROMAN': ctypes.c_void_p(0),
        'GLUT_STROKE_MONO_ROMAN': ctypes.c_void_p(1),
Ejemplo n.º 36
0
        OpenGL = ctypesloader.loadLibrary(
            ctypes.cdll,
            'OpenGL', 
            mode=ctypes.RTLD_GLOBAL 
        )
    except OSError, err:
        raise ImportError("Unable to load OpenGL library", *err.args)
    # CGL provides the windowing environment functionality
    # but it is built into the GL libs.
    GL = GLU = CGL = OpenGL

    # glut shouldn't need to be global, but just in case a dependent library makes
    # the same assumption GLUT does...
    GLUT = ctypesloader.loadLibrary(
        ctypes.cdll,
        'GLUT', 
        mode=ctypes.RTLD_GLOBAL 
    )

    # GLE is handled by GLUT under OS X
    GLE = GLUT

    GetCurrentContext = CurrentContextIsValid = staticmethod( 
        CGL.CGLGetCurrentContext 
    )

    def getGLUTFontPointer( self, constant ):
        """Platform specific function to retrieve a GLUT font pointer
        
        GLUTAPI void *glutBitmap9By15;
        #define GLUT_BITMAP_9_BY_15     (&glutBitmap9By15)
Ejemplo n.º 37
0
		GLUT = ctypesloader.loadLibrary(
			ctypes.cdll,
			'glut', 
			mode=ctypes.RTLD_GLOBAL 
		)
	except OSError, err:
		GLUT = None
	# GLX doesn't seem to have its own loadable module?
	GLX = GL
	glXGetProcAddressARB = GL.glXGetProcAddressARB
	glXGetProcAddressARB.restype = ctypes.c_void_p
	getExtensionProcedure = staticmethod( glXGetProcAddressARB )
	try:
		GLE = ctypesloader.loadLibrary(
			ctypes.cdll,
			'gle', 
			mode=ctypes.RTLD_GLOBAL 
		)
	except OSError, err:
		GLE = None

	DEFAULT_FUNCTION_TYPE = staticmethod( ctypes.CFUNCTYPE )

	# This loads the GLX functions from the GL .so, not sure if that's
	# really kosher...
	GetCurrentContext = CurrentContextIsValid = staticmethod(
		GL.glXGetCurrentContext
	)


	def getGLUTFontPointer( self, constant ):
Ejemplo n.º 38
0
class Win32Platform( baseplatform.BasePlatform ):
    """Win32-specific platform implementation"""

    GLUT_GUARD_CALLBACKS = True
    try:
        GL = OpenGL = ctypesloader.loadLibrary(
            ctypes.windll, 'opengl32', mode = ctypes.RTLD_GLOBAL
        )
    except OSError as err:
        raise ImportError("Unable to load OpenGL library", *err.args)

    try:
        GLU = ctypesloader.loadLibrary(
            ctypes.windll, 'glu32', mode = ctypes.RTLD_GLOBAL
        )
    except OSError as err:
        GLU = None

    GLUT = None
    for possible in ('freeglut%s.%s'%(size,vc,), 'glut%s.%s'%(size,vc,), 'freeglut'):
        # Prefer FreeGLUT if the user has installed it, fallback to the included 
        # GLUT if it is installed
        try:
            GLUT = ctypesloader.loadLibrary(
                ctypes.windll, possible, mode = ctypes.RTLD_GLOBAL
            )
        except WindowsError as err:
            GLUT = None
        else:
            break
    try:
        del possible
    except NameError as err:
        pass

    GLE = None
    for libName in ('gle%s.%s'%(size,vc,), 'opengle%s.%s'%(size,vc,)):
        try:
            GLE = ctypesloader.loadLibrary( ctypes.cdll, libName )
            GLE.FunctionType = ctypes.CFUNCTYPE
        except WindowsError as err:
            pass
        else:
            break

    DEFAULT_FUNCTION_TYPE = staticmethod( ctypes.WINFUNCTYPE )
    # Win32 GLUT uses different types for callbacks and functions...
    GLUT_CALLBACK_TYPE = staticmethod( ctypes.CFUNCTYPE )
    WGL = ctypes.windll.gdi32
    getExtensionProcedure = staticmethod( OpenGL.wglGetProcAddress )

    GLUT_FONT_CONSTANTS = {
        'GLUT_STROKE_ROMAN': ctypes.c_void_p( 0),
        'GLUT_STROKE_MONO_ROMAN': ctypes.c_void_p( 1),
        'GLUT_BITMAP_9_BY_15': ctypes.c_void_p( 2),
        'GLUT_BITMAP_8_BY_13': ctypes.c_void_p( 3),
        'GLUT_BITMAP_TIMES_ROMAN_10': ctypes.c_void_p( 4),
        'GLUT_BITMAP_TIMES_ROMAN_24': ctypes.c_void_p( 5),
        'GLUT_BITMAP_HELVETICA_10': ctypes.c_void_p( 6),
        'GLUT_BITMAP_HELVETICA_12': ctypes.c_void_p( 7),
        'GLUT_BITMAP_HELVETICA_18': ctypes.c_void_p( 8),
    }


    def getGLUTFontPointer( self,constant ):
        """Platform specific function to retrieve a GLUT font pointer

        GLUTAPI void *glutBitmap9By15;
        #define GLUT_BITMAP_9_BY_15		(&glutBitmap9By15)

        Key here is that we want the addressof the pointer in the DLL,
        not the pointer in the DLL.  That is, our pointer is to the
        pointer defined in the DLL, we don't want the *value* stored in
        that pointer.
        """
        return self.GLUT_FONT_CONSTANTS[ constant ]

    GetCurrentContext = CurrentContextIsValid = staticmethod(
        GL.wglGetCurrentContext
    )


    def safeGetError( self ):
        """Provide context-not-present-safe error-checking

        Under OS-X an attempt to retrieve error without checking
        context will bus-error.  Likely Windows will see the same.
        This function checks for a valid context before running
        glGetError

        Note:
            This is a likely candidate for rewriting in C, as it
            is called for every almost function in the system!
        """
        if self.CurrentContextIsValid():
            return glGetError()
        return None
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or  implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""Extends OpenGL.EGL with definitions necessary for headless rendering."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import ctypes
from OpenGL.platform import ctypesloader  # pylint: disable=g-bad-import-order
try:
    # Nvidia driver seems to need libOpenGL.so (as opposed to libGL.so)
    # for multithreading to work properly. We load this in before everything else.
    ctypesloader.loadLibrary(ctypes.cdll, 'OpenGL', mode=ctypes.RTLD_GLOBAL)
except OSError:
    pass

# pylint: disable=g-import-not-at-top

from OpenGL import EGL
from OpenGL import error
from six.moves import range

# From the EGL_EXT_device_enumeration extension.
EGLDeviceEXT = ctypes.c_void_p
PFNEGLQUERYDEVICESEXTPROC = ctypes.CFUNCTYPE(EGL.EGLBoolean, EGL.EGLint,
                                             ctypes.POINTER(EGLDeviceEXT),
                                             ctypes.POINTER(EGL.EGLint))
try:
Ejemplo n.º 40
0
raise SystemExit(1)
attributes = [
    #    GLX_BIND_TO_TEXTURE_RGBA_EXT, 1,
    #    GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
    #    GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT,
    GLX_DOUBLEBUFFER,
    0,
    #    GLX_Y_INVERTED_EXT, GLX_DONT_CARE,
    GL_NONE,
]
attributes = (GLint * len(attributes))(*attributes)

import ctypes
from OpenGL.platform import ctypesloader

X11 = ctypesloader.loadLibrary(ctypes.cdll, "X11")

XDefaultScreen = X11.XDefaultScreen
XDefaultScreen.argtypes = [ctypes.POINTER(Display)]

XOpenDisplay = X11.XOpenDisplay
XOpenDisplay.restype = ctypes.POINTER(Display)

XRootWindow = X11.XRootWindow
XRootWindow.restyle = ctypes.POINTER(Window)

XCreateWindow = X11.XCreateWindow
XCreateWindow.restyle = ctypes.POINTER(Window)
XCreateWindow.argtypes = [
    ctypes.POINTER(Display),
    ctypes.POINTER(Window),
Ejemplo n.º 41
0
import os

attributes = [
#    GLX_BIND_TO_TEXTURE_RGBA_EXT, 1,
#    GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
#    GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT,
    GLX_DOUBLEBUFFER, 1,
#    GLX_Y_INVERTED_EXT, GLX_DONT_CARE,
    GL_NONE
]

#from OpenGL import platform
import ctypes
from OpenGL.platform import ctypesloader

X11 = ctypesloader.loadLibrary( ctypes.cdll, 'X11' )
XDefaultScreen = X11.XDefaultScreen
XDefaultScreen.argtypes = [ctypes.POINTER(Display)]
XOpenDisplay = X11.XOpenDisplay 
XOpenDisplay.restype = ctypes.POINTER(Display)

@pygametest()
def main():
    dsp = XOpenDisplay( os.environ.get( 'DISPLAY' ))
    screen = XDefaultScreen( dsp )
    print('X Display %s Screen %s'%( dsp, screen ))
    major,minor = GLint(),GLint()
    glXQueryVersion(dsp, major, minor)
    version = (major.value,minor.value)
    print('glX Version: %s.%s'%version)
    if version >= (1,1):
Ejemplo n.º 42
0
 """Posix (Linux, FreeBSD, etceteras) implementation for PyOpenGL"""
 # On Linux (and, I assume, most GLX platforms, we have to load 
 # GL and GLU with the "global" flag to allow GLUT to resolve its
 # references to GL/GLU functions).
 try:
     GL = OpenGL = ctypesloader.loadLibrary(
         ctypes.cdll,
         'GL', 
         mode=ctypes.RTLD_GLOBAL 
     )
 except OSError, err:
     raise ImportError("Unable to load OpenGL library", *err.args)
 try:
     GLU = ctypesloader.loadLibrary(
         ctypes.cdll,
         'GLU',
         mode=ctypes.RTLD_GLOBAL 
     )
 except OSError, err:
     GLU = None
 # glut shouldn't need to be global, but just in case a dependent library makes
 # the same assumption GLUT does...
 try:
     GLUT = ctypesloader.loadLibrary(
         ctypes.cdll,
         'glut', 
         mode=ctypes.RTLD_GLOBAL 
     )
 except OSError, err:
     GLUT = None
 # GLX doesn't seem to have its own loadable module?
Ejemplo n.º 43
0
    # glut shouldn't need to be global, but just in case a dependent library makes
    # the same assumption GLUT does...
    try:
        GLUT = ctypesloader.loadLibrary(ctypes.cdll,
                                        'glut',
                                        mode=ctypes.RTLD_GLOBAL)
    except OSError, err:
        GLUT = None
    # GLX doesn't seem to have its own loadable module?
    GLX = GL
    glXGetProcAddressARB = GL.glXGetProcAddressARB
    glXGetProcAddressARB.restype = ctypes.c_void_p
    getExtensionProcedure = staticmethod(glXGetProcAddressARB)
    try:
        GLE = ctypesloader.loadLibrary(ctypes.cdll,
                                       'gle',
                                       mode=ctypes.RTLD_GLOBAL)
    except OSError, err:
        GLE = None

    DEFAULT_FUNCTION_TYPE = staticmethod(ctypes.CFUNCTYPE)

    # This loads the GLX functions from the GL .so, not sure if that's
    # really kosher...
    GetCurrentContext = CurrentContextIsValid = staticmethod(
        GL.glXGetCurrentContext)

    def getGLUTFontPointer(self, constant):
        """Platform specific function to retrieve a GLUT font pointer
		
		GLUTAPI void *glutBitmap9By15;
Ejemplo n.º 44
0
import ctypes, ctypes.util
from OpenGL.platform import baseplatform, ctypesloader
from OpenGL.constant import Constant


class OSMesaPlatform(baseplatform.BasePlatform):
    """OSMesa implementation for PyOpenGL"""
    try:
        GL = OpenGL = ctypesloader.loadLibrary(ctypes.cdll,
                                               'OSMesa',
                                               mode=ctypes.RTLD_GLOBAL)
    except OSError, err:
        raise ImportError("Unable to load OpenGL library", *err.args)
    try:
        GLU = ctypesloader.loadLibrary(ctypes.cdll,
                                       'GLU',
                                       mode=ctypes.RTLD_GLOBAL)
    except OSError, err:
        GLU = None
    # glut shouldn't need to be global, but just in case a dependent library makes
    # the same assumption GLUT does...
    try:
        GLUT = ctypesloader.loadLibrary(ctypes.cdll,
                                        'glut',
                                        mode=ctypes.RTLD_GLOBAL)
    except OSError, err:
        GLUT = None

    try:
        GLE = ctypesloader.loadLibrary(ctypes.cdll,
                                       'gle',
Ejemplo n.º 45
0

class Win32Platform( baseplatform.BasePlatform ):
    """Win32-specific platform implementation"""

    GLUT_GUARD_CALLBACKS = True
    try:
        GL = OpenGL = ctypesloader.loadLibrary(
            ctypes.windll, 'opengl32', mode = ctypes.RTLD_GLOBAL
        )
    except OSError, err:
        raise ImportError("Unable to load OpenGL library", *err.args)

    try:
        GLU = ctypesloader.loadLibrary(
            ctypes.windll, 'glu32', mode = ctypes.RTLD_GLOBAL
        )
    except OSError, err:
        GLU = None

    GLUT = None
    for possible in ('glut32','freeglut32','freeglut'):
        # load first-up of the possible names...
        try:
            GLUT = ctypesloader.loadLibrary(
                ctypes.windll, possible, mode = ctypes.RTLD_GLOBAL
            )
        except WindowsError, err:
            GLUT = None
        else:
            break
Ejemplo n.º 46
0
class OSMesaPlatform( baseplatform.BasePlatform ):
    """OSMesa implementation for PyOpenGL"""
    try:
        GL = OpenGL = ctypesloader.loadLibrary(
            ctypes.cdll,
            'OSMesa', 
            mode=ctypes.RTLD_GLOBAL 
        )
    except OSError as err:
        raise ImportError("Unable to load OpenGL library", *err.args)
    try:
        GLU = ctypesloader.loadLibrary(
            ctypes.cdll,
            'GLU',
            mode=ctypes.RTLD_GLOBAL 
        )
    except OSError as err:
        GLU = None
    # glut shouldn't need to be global, but just in case a dependent library makes
    # the same assumption GLUT does...
    try:
        GLUT = ctypesloader.loadLibrary(
            ctypes.cdll,
            'glut', 
            mode=ctypes.RTLD_GLOBAL 
        )
    except OSError as err:
        GLUT = None

    try:
        GLE = ctypesloader.loadLibrary(
            ctypes.cdll,
            'gle', 
            mode=ctypes.RTLD_GLOBAL 
        )
    except OSError as err:
        GLE = None

    DEFAULT_FUNCTION_TYPE = staticmethod( ctypes.CFUNCTYPE )

    GLenum = ctypes.c_uint
    GLboolean = ctypes.c_ubyte
    GLsizei = ctypes.c_int
    GLint = ctypes.c_int

    baseplatform.BasePlatform.EXPORTED_NAMES += ['OSMesaCreateContext',
        'OSMesaCreateContextExt', 'OSMesaMakeCurrent', 'OSMesaGetIntegerv',
        'OSMesaGetCurrentContext', 'OSMesaDestroyContext', 'OSMesaPixelStore',
        'OSMesaGetDepthBuffer', 'OSMesaGetColorBuffer',
        'OSMESA_COLOR_INDEX', 'OSMESA_RGBA', 'OSMESA_BGRA', 'OSMESA_ARGB',
        'OSMESA_RGB', 'OSMESA_BGR', 'OSMESA_BGR', 'OSMESA_ROW_LENGTH',
        'OSMESA_Y_UP', 'OSMESA_WIDTH', 'OSMESA_HEIGHT', 'OSMESA_FORMAT',
        'OSMESA_TYPE', 'OSMESA_MAX_WIDTH', 'OSMESA_MAX_HEIGHT']

    # export OSMesa functions from osmesa.h
    class struct_osmesa_context(ctypes.Structure):
        __slots__ = [
        ]
    struct_osmesa_context._fields_ = [
        ('_opaque_struct', ctypes.c_int)
    ]
    OSMesaContext = ctypes.POINTER(struct_osmesa_context)

    # Values for the format parameter of OSMesaCreateContext()
    OSMESA_COLOR_INDEX = Constant('OSMESA_COLOR_INDEX', 6400)
    OSMESA_RGBA = Constant('OSMESA_RGBA', 6408)
    OSMESA_BGRA = Constant('OSMESA_BGRA', 0x1)
    OSMESA_ARGB = Constant('OSMESA_ARGB', 0x2)
    OSMESA_RGB = Constant('OSMESA_RGB', 6407)
    OSMESA_BGR = Constant('OSMESA_BGR',	0x4)
    OSMESA_RGB_565 = Constant('OSMESA_BGR', 0x5)

    # OSMesaPixelStore() parameters:
    OSMESA_ROW_LENGTH = Constant('OSMESA_ROW_LENGTH', 0x10)
    OSMESA_Y_UP = Constant('OSMESA_Y_UP', 0x11)

    # Accepted by OSMesaGetIntegerv:
    OSMESA_WIDTH = Constant('OSMESA_WIDTH', 0x20)
    OSMESA_HEIGHT = Constant('OSMESA_HEIGHT', 0x21)
    OSMESA_FORMAT = Constant('OSMESA_FORMAT', 0x22)
    OSMESA_TYPE = Constant('OSMESA_TYPE', 0x23)
    OSMESA_MAX_WIDTH = Constant('OSMESA_MAX_WIDTH', 0x24)
    OSMESA_MAX_HEIGHT = Constant('OSMESA_MAX_HEIGHT', 0x25)

    OSMesaCreateContext = GL.OSMesaCreateContext
    OSMesaCreateContext.argtypes = [GLenum, OSMesaContext]
    OSMesaCreateContext.restype = OSMesaContext
    
    OSMesaCreateContextExt = GL.OSMesaCreateContextExt
    OSMesaCreateContextExt.argtypes = [GLenum, GLint, GLint, GLint,
                                       OSMesaContext]
    OSMesaCreateContextExt.restype = OSMesaContext

    OSMesaDestroyContext = GL.OSMesaDestroyContext
    OSMesaDestroyContext.argtypes = [OSMesaContext]

    OSMesaMakeCurrent = GL.OSMesaMakeCurrent
    OSMesaMakeCurrent.argtypes = [OSMesaContext, ctypes.POINTER(None),
                                GLenum, GLsizei, GLsizei]
    OSMesaMakeCurrent.restype = GLboolean

    OSMesaGetCurrentContext = GL.OSMesaGetCurrentContext
    #OSMesaGetCurrentContext.restype = OSMesaContext
    GetCurrentContext = CurrentContextIsValid = OSMesaGetCurrentContext

    OSMesaPixelStore = GL.OSMesaPixelStore
    OSMesaPixelStore.argtypes = [GLint, GLint]
    OSMesaPixelStore.restype = None

    OSMesaGetProcAddress = GL.OSMesaGetProcAddress
    OSMesaGetProcAddress.restype = ctypes.c_void_p
    getExtensionProcedure = staticmethod( OSMesaGetProcAddress )

    def OSMesaGetIntegerv(self, pname):
        value = self.GLint()
        self.GL.OSMesaGetIntegerv(pname, ctypes.byref(value))
        return value.value

    def OSMesaGetDepthBuffer(self, c):
        width, height, bytesPerValue = self.GLint(), self.GLint(), self.GLint()
        buffer = ctypes.POINTER(self.GLint)()

        if self.GL.OSMesaGetDepthBuffer(c, ctypes.byref(width),
                                        ctypes.byref(height),
                                        ctypes.byref(bytesPerValue),
                                        ctypes.byref(buffer)):
            return width.value, height.value, bytesPerValue.value, buffer
        else:
            return 0, 0, 0, None

    def OSMesaGetColorBuffer(self, c):
        # TODO: make output array types which can handle the operation 
        # provide an API to convert pointers + sizes to array instances,
        # e.g. numpy.ctypeslib.as_array( ptr, bytesize ).astype( 'B' ).reshape( height,width )
        width, height, format = self.GLint(), self.GLint(), self.GLint()
        buffer = ctypes.c_void_p()

        if self.GL.OSMesaGetColorBuffer(c, ctypes.byref(width),
                                        ctypes.byref(height),
                                        ctypes.byref(format),
                                        ctypes.byref(buffer)):
            return width.value, height.value, format.value, buffer
        else:
            return 0, 0, 0, None

    def getGLUTFontPointer( self, constant ):
        """Platform specific function to retrieve a GLUT font pointer
        
        GLUTAPI void *glutBitmap9By15;
        #define GLUT_BITMAP_9_BY_15		(&glutBitmap9By15)
        
        Key here is that we want the addressof the pointer in the DLL,
        not the pointer in the DLL.  That is, our pointer is to the 
        pointer defined in the DLL, we don't want the *value* stored in
        that pointer.
        """
        name = [ x.title() for x in constant.split( '_' )[1:] ]
        internal = 'glut' + "".join( [x.title() for x in name] )
        pointer = ctypes.c_void_p.in_dll( self.GLUT, internal )
        return ctypes.c_void_p(ctypes.addressof(pointer))
    
    safeGetError = staticmethod( OpenGL.glGetError )
Ejemplo n.º 47
0
from OpenGL.platform import ctypesloader, baseplatform

class Win32Platform( baseplatform.BasePlatform ):
	"""Win32-specific platform implementation"""

	GLUT_GUARD_CALLBACKS = True
	GL = OpenGL = ctypesloader.loadLibrary( ctypes.windll, 'opengl32', mode = ctypes.RTLD_GLOBAL )
	GLU = ctypesloader.loadLibrary( ctypes.windll, 'glu32', mode = ctypes.RTLD_GLOBAL )
	try:
		GLUT = ctypesloader.loadLibrary( ctypes.windll, 'glut32', mode = ctypes.RTLD_GLOBAL )
	except WindowsError, err:
		GLUT = None
	GLE = None
	for libName in ('gle32','opengle32'):
		try:
			GLE = ctypesloader.loadLibrary( ctypes.cdll, libName )
			GLE.FunctionType = ctypes.CFUNCTYPE
		except WindowsError, err:
			pass
		else:
			break
	
	DEFAULT_FUNCTION_TYPE = staticmethod( ctypes.WINFUNCTYPE )
	# Win32 GLUT uses different types for callbacks and functions...
	GLUT_CALLBACK_TYPE = staticmethod( ctypes.CFUNCTYPE )
	WGL = ctypes.windll.gdi32
	getExtensionProcedure = staticmethod( OpenGL.wglGetProcAddress )

	GLUT_FONT_CONSTANTS = {
		'GLUT_STROKE_ROMAN': ctypes.c_void_p( 0),
		'GLUT_STROKE_MONO_ROMAN': ctypes.c_void_p( 1),