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 / constants.py < prev    next >
Encoding:
Python Source  |  2008-12-20  |  2.4 KB  |  83 lines

  1. """OpenGL-wide constant types (not OpenGL.GL-specific"""
  2. import ctypes
  3. from OpenGL.constant import Constant
  4.  
  5. GL_FALSE = Constant( 'GL_FALSE', 0x0 )
  6. GL_TRUE = Constant( 'GL_TRUE', 0x1 )
  7. GL_BYTE = Constant( 'GL_BYTE', 0x1400 )
  8. GL_UNSIGNED_BYTE = Constant( 'GL_UNSIGNED_BYTE', 0x1401 )
  9. GL_SHORT = Constant( 'GL_SHORT', 0x1402 )
  10. GL_UNSIGNED_SHORT = Constant( 'GL_UNSIGNED_SHORT', 0x1403 )
  11. GL_INT = Constant( 'GL_INT', 0x1404 )
  12. GL_UNSIGNED_INT = Constant( 'GL_UNSIGNED_INT', 0x1405 )
  13. GL_FLOAT = Constant( 'GL_FLOAT', 0x1406 )
  14. GL_DOUBLE = Constant( 'GL_DOUBLE', 0x140a )
  15. GL_CHAR = str
  16. GL_HALF_NV = Constant( 'GL_HALF_NV', 0x1401 )
  17.  
  18. # Basic OpenGL data-types as ctypes declarations...
  19. def _defineType( name, baseType, convertFunc = long ):
  20.     import OpenGL 
  21.     if OpenGL.ALLOW_NUMPY_SCALARS:
  22.         original = baseType.from_param
  23.         def from_param( x, typeCode=None ):
  24.             try:
  25.                 return original( x )
  26.             except TypeError, err:
  27.                 try:
  28.                     return original( convertFunc(x) )
  29.                 except TypeError, err2:
  30.                     raise err
  31.         setattr( baseType, 'from_param', staticmethod( from_param ) )
  32.         return baseType
  33.     else:
  34.         return baseType
  35.  
  36. GLvoid = None
  37. GLboolean = _defineType( 'GLboolean', ctypes.c_ubyte, bool )
  38. GLenum = _defineType( 'GLenum', ctypes.c_uint )
  39.  
  40. GLfloat = _defineType( 'GLfloat', ctypes.c_float, float )
  41. GLdouble = _defineType( 'GLdouble', ctypes.c_double, float )
  42.  
  43. GLbyte = ctypes.c_byte
  44. GLshort = _defineType( 'GLshort', ctypes.c_short, int )
  45. GLint = _defineType( 'GLint', ctypes.c_int, int )
  46. GLuint = _defineType( 'GLuint', ctypes.c_uint )
  47.  
  48. GLsizei = _defineType( 'GLsizei', ctypes.c_int, int )
  49.  
  50. GLubyte = ctypes.c_ubyte
  51. GLushort = _defineType( 'GLushort', ctypes.c_ushort, int )
  52. GLhandleARB = _defineType( 'GLhandleARB', ctypes.c_uint )
  53. GLhandle = _defineType( 'GLhandle', ctypes.c_uint )
  54.  
  55. GLchar = GLcharARB = ctypes.c_char
  56.  
  57. GLbitfield = _defineType( 'GLbitfield', ctypes.c_uint )
  58.  
  59. GLclampd = _defineType( 'GLclampd', ctypes.c_double, float )
  60. GLclampf = _defineType( 'GLclampf', ctypes.c_float, float )
  61.  
  62. # ptrdiff_t, actually...
  63. GLsizeiptrARB = GLsizeiptr = GLsizei
  64. GLintptrARB = GLintptr = GLint
  65. size_t = ctypes.c_ulong
  66.  
  67. GLhalfNV = GLhalfARB = ctypes.c_ushort
  68.  
  69.  
  70. ARRAY_TYPE_TO_CONSTANT = [
  71.     ('GLclampd', GL_DOUBLE),
  72.     ('GLclampf', GL_FLOAT),
  73.     ('GLfloat', GL_FLOAT),
  74.     ('GLdouble', GL_DOUBLE),
  75.     ('GLbyte', GL_BYTE),
  76.     ('GLshort', GL_SHORT),
  77.     ('GLint', GL_INT),
  78.     ('GLubyte', GL_UNSIGNED_BYTE),
  79.     ('GLushort', GL_UNSIGNED_SHORT),
  80.     ('GLuint', GL_UNSIGNED_INT),
  81.     ('GLenum', GL_UNSIGNED_INT),
  82. ]
  83.