home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / lib / site-packages / OpenGL / platform / darwin.py < prev    next >
Encoding:
Python Source  |  2009-02-09  |  3.4 KB  |  89 lines

  1. """Darwin (MacOSX)-specific platform features
  2.  
  3. This was implemented with the help of the following links:
  4. [1] Apple's Mac OS X OpenGL interfaces: http://developer.apple.com/qa/qa2001/qa1269.html
  5. [2] As above, but updated: http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_pg_concepts/chapter_2_section_3.html
  6. [3] CGL reference: http://developer.apple.com/documentation/GraphicsImaging/Reference/CGL_OpenGL/index.html#//apple_ref/doc/uid/TP40001186
  7. [4] Intro to OpenGL on Mac OS X: http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_intro/chapter_1_section_1.html#//apple_ref/doc/uid/TP40001987-CH207-TP9
  8.  
  9. About the  CGL API, (from [1]):
  10. CGL or Core OpenGL is the lowest accessible interface API for OpenGL. 
  11. It knows nothing about windowing systems but can be used directly to 
  12. find both renderer information and as a full screen or off screen 
  13. interface. It is accessible from both Cocoa and Carbon and is what both 
  14. NSGL and AGL are built on. A complete Pbuffer interface is also provided. 
  15. Functionality is provided in via the OpenGL framework and applications 
  16. can include the OpenGL.h header to access CGL's functionality. Developers
  17. can see an example of using CGL with Carbon in the Carbon CGL code sample.
  18.  
  19. Documentation and header files are found in:
  20. /System/Library/Frameworks/OpenGL.framework
  21. /System/Library/Frameworks/GLUT.framework
  22.  
  23. """
  24. import ctypes, ctypes.util
  25. from OpenGL.platform import baseplatform, ctypesloader
  26.  
  27. class DarwinPlatform( baseplatform.BasePlatform ):
  28.     """Darwin (OSX) platform implementation"""
  29.     DEFAULT_FUNCTION_TYPE = staticmethod( ctypes.CFUNCTYPE )
  30.     EXTENSIONS_USE_BASE_FUNCTIONS = True
  31.     
  32.     # Get the pointers to the libraries...
  33.     OpenGL = ctypesloader.loadLibrary(
  34.         ctypes.cdll,
  35.         'OpenGL', 
  36.         mode=ctypes.RTLD_GLOBAL 
  37.     )
  38.     # CGL provides the windowing environment functionality
  39.     # but it is built into the GL libs.
  40.     GL = GLU = CGL = OpenGL
  41.  
  42.     # glut shouldn't need to be global, but just in case a dependent library makes
  43.     # the same assumption GLUT does...
  44.     GLUT = ctypesloader.loadLibrary(
  45.         ctypes.cdll,
  46.         'GLUT', 
  47.         mode=ctypes.RTLD_GLOBAL 
  48.     )
  49.  
  50.     # GLE is handled by GLUT under OS X
  51.     GLE = GLUT
  52.  
  53.     GetCurrentContext = CurrentContextIsValid = staticmethod( 
  54.         CGL.CGLGetCurrentContext 
  55.     )
  56.  
  57.     def getGLUTFontPointer( self, constant ):
  58.         """Platform specific function to retrieve a GLUT font pointer
  59.         
  60.         GLUTAPI void *glutBitmap9By15;
  61.         #define GLUT_BITMAP_9_BY_15     (&glutBitmap9By15)
  62.         
  63.         Key here is that we want the addressof the pointer in the DLL,
  64.         not the pointer in the DLL.  That is, our pointer is to the 
  65.         pointer defined in the DLL, we don't want the *value* stored in
  66.         that pointer.
  67.         """
  68.         name = [ x.title() for x in constant.split( '_' )[1:] ]
  69.         internal = 'glut' + "".join( [x.title() for x in name] )
  70.         pointer = ctypes.c_void_p.in_dll( self.GLUT, internal )
  71.         return ctypes.c_void_p(ctypes.addressof(pointer))
  72.  
  73.     def safeGetError( self ):
  74.         """Provide context-not-present-safe error-checking
  75.         
  76.         Under OS-X an attempt to retrieve error without checking 
  77.         context will bus-error.  This function checks for a valid
  78.         context before running glGetError
  79.         
  80.         Note:
  81.             This is a likely candidate for rewriting in C, as it
  82.             is called for every almost function in the system!
  83.         """
  84.         if self.CurrentContextIsValid():
  85.             return glGetError()
  86.         return None
  87.  
  88. glGetError = DarwinPlatform.OpenGL.glGetError
  89.