<s> """<STR_LIT>""" <EOL> from contextlib import contextmanager <EOL> import numpy <EOL> from OpenGL import GL <EOL> from pyrr . utils import all_parameters_as_numpy_arrays , parameters_as_numpy_arrays <EOL> def _generate_enum_map ( enum_names ) : <EOL> """<STR_LIT>""" <EOL> map = { } <EOL> for ( key , value ) in enum_names . items ( ) : <EOL> try : <EOL> map [ getattr ( GL , key ) ] = value <EOL> except AttributeError : <EOL> pass <EOL> return map <EOL> def _extract_version ( version ) : <EOL> """<STR_LIT>""" <EOL> import re <EOL> versions = re . split ( r'<STR_LIT>' , version ) <EOL> return int ( versions [ <NUM_LIT:0> ] ) , int ( versions [ <NUM_LIT:1> ] ) <EOL> def gl_version ( ) : <EOL> """<STR_LIT>""" <EOL> return GL . glGetString ( GL . GL_VERSION ) <EOL> def gl_version_tuple ( ) : <EOL> return _extract_version ( gl_version ( ) ) <EOL> def gl_profile ( ) : <EOL> """<STR_LIT>""" <EOL> major , minor = gl_version_tuple ( ) <EOL> if major <= <NUM_LIT:2> : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> def glsl_version ( ) : <EOL> """<STR_LIT>""" <EOL> return GL . glGetString ( GL . GL_SHADING_LANGUAGE_VERSION ) <EOL> def glsl_version_tuple ( ) : <EOL> """<STR_LIT>""" <EOL> return _extract_version ( glsl_version ( ) ) <EOL> def is_legacy ( ) : <EOL> """<STR_LIT>""" <EOL> return gl_version_tuple ( ) [ <NUM_LIT:0> ] <= <NUM_LIT:2> <EOL> def is_core ( ) : <EOL> """<STR_LIT>""" <EOL> return gl_version_tuple ( ) [ <NUM_LIT:0> ] >= <NUM_LIT:3> <EOL> def print_gl_info ( ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" <EOL> for prop in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> type = getattr ( GL , prop ) <EOL> value = GL . glGetString ( type ) <EOL> print "<STR_LIT>" % ( prop , value ) <EOL> def string_to_type ( type ) : <EOL> """<STR_LIT>""" <EOL> return getattr ( GL , type ) <EOL> def type_to_string ( glType ) : <EOL> """<STR_LIT>""" <EOL> return { <EOL> GL . GLbyte : "<STR_LIT>" , <EOL> GL . GLubyte : "<STR_LIT>" , <EOL> GL . GLshort : "<STR_LIT>" , <EOL> GL . GLushort : "<STR_LIT>" , <EOL> GL . GLint : "<STR_LIT>" , <EOL> GL . GLuint : "<STR_LIT>" , <EOL> GL . GLfloat : "<STR_LIT>" , <EOL> GL . GLdouble : "<STR_LIT>" , <EOL> } [ glType ] <EOL> def enum_to_type ( glEnum ) : <EOL> return { <EOL> GL . constants . GL_CHAR : GL . constants . GLchar , <EOL> GL . constants . GL_UNSIGNED_BYTE : GL . constants . GLubyte , <EOL> GL . constants . GL_BYTE : GL . constants . GLbyte , <EOL> GL . constants . GL_UNSIGNED_SHORT : GL . constants . GLushort , <EOL> GL . constants . GL_SHORT : GL . constants . GLshort , <EOL> GL . constants . GL_UNSIGNED_INT : GL . constants . GLuint , <EOL> GL . constants . GL_INT : GL . constants . GLint , <EOL> GL . constants . GL_FLOAT : GL . constants . GLfloat , <EOL> GL . constants . GL_DOUBLE : GL . constants . GLdouble , <EOL> } [ glEnum ] <EOL> @ contextmanager <EOL> def attributes ( attribs ) : <EOL> """<STR_LIT>""" <EOL> GL . glPushAttrib ( attribs ) <EOL> try : <EOL> yield <EOL> finally : <EOL> GL . glPopAttrib ( ) <EOL> @ contextmanager <EOL> def begin ( mode ) : <EOL> """<STR_LIT>""" <EOL> GL . glBegin ( mode ) <EOL> try : <EOL> yield <EOL> finally : <EOL> GL . glEnd ( ) <EOL> @ contextmanager <EOL> def matrix_mode ( mode ) : <EOL> """<STR_LIT>""" <EOL> GL . glPushAttrib ( GL . GL_TRANSFORM_BIT ) <EOL> GL . glMatrixMode ( mode ) <EOL> try : <EOL> yield <EOL> finally : <EOL> GL . glPopAttrib ( ) <EOL> @ contextmanager <EOL> @ all_parameters_as_numpy_arrays <EOL> def load_matrix ( mat ) : <EOL> """<STR_LIT>""" <EOL> GL . glPushMatrix ( ) <EOL> GL . glLoadMatrixf ( mat . astype ( '<STR_LIT>' ) ) <EOL> try : <EOL> yield <EOL> finally : <EOL> GL . glPopMatrix ( ) <EOL> @ contextmanager <EOL> @ all_parameters_as_numpy_arrays <EOL> def multiply_matrix ( mat ) : <EOL> """<STR_LIT>""" <EOL> GL . glPushMatrix ( ) <EOL> GL . glMultMatrixf ( mat . astype ( '<STR_LIT>' ) ) <EOL> try : <EOL> yield <EOL> finally : <EOL> GL . glPopMatrix ( ) <EOL> @ contextmanager <EOL> @ parameters_as_numpy_arrays ( '<STR_LIT>' ) <EOL> def mode_and_matrix ( mode , mat ) : <EOL> """<STR_LIT>""" <EOL> GL . glPushAttrib ( GL . GL_TRANSFORM_BIT ) <EOL> GL . glMatrixMode ( mode ) <EOL> GL . glPushMatrix ( ) <EOL> GL . glMultMatrixf ( mat . astype ( '<STR_LIT>' ) ) <EOL> try : <EOL> yield <EOL> finally : <EOL> GL . glPopMatrix ( ) <EOL> GL . glPopAttrib ( ) </s>
