<s> import sys as _sys <EOL> from pyglet import gl <EOL> from pyglet . gl import gl_info <EOL> from pyglet . gl import glu_info <EOL> class Config ( object ) : <EOL> '''<STR_LIT>''' <EOL> _attribute_names = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> major_version = None <EOL> minor_version = None <EOL> forward_compatible = None <EOL> debug = None <EOL> def __init__ ( self , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> for name in self . _attribute_names : <EOL> if name in kwargs : <EOL> setattr ( self , name , kwargs [ name ] ) <EOL> else : <EOL> setattr ( self , name , None ) <EOL> def _requires_gl_3 ( self ) : <EOL> if self . major_version is not None and self . major_version >= <NUM_LIT:3> : <EOL> return True <EOL> if self . forward_compatible or self . debug : <EOL> return True <EOL> return False <EOL> def get_gl_attributes ( self ) : <EOL> '''<STR_LIT>''' <EOL> return [ ( name , getattr ( self , name ) ) for name in self . _attribute_names ] <EOL> def match ( self , canvas ) : <EOL> '''<STR_LIT>''' <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def create_context ( self , share ) : <EOL> '''<STR_LIT>''' <EOL> raise gl . ConfigException ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def is_complete ( self ) : <EOL> '''<STR_LIT>''' <EOL> return isinstance ( self , CanvasConfig ) <EOL> def __repr__ ( self ) : <EOL> import pprint <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , <EOL> pprint . pformat ( self . get_gl_attributes ( ) ) ) <EOL> class CanvasConfig ( Config ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , canvas , base_config ) : <EOL> self . canvas = canvas <EOL> self . major_version = base_config . major_version <EOL> self . minor_version = base_config . minor_version <EOL> self . forward_compatible = base_config . forward_compatible <EOL> self . debug = base_config . debug <EOL> def compatible ( self , canvas ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def create_context ( self , share ) : <EOL> '''<STR_LIT>''' <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def is_complete ( self ) : <EOL> return True <EOL> class ObjectSpace ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _doomed_textures = [ ] <EOL> self . _doomed_buffers = [ ] <EOL> class Context ( object ) : <EOL> '''<STR_LIT>''' <EOL> CONTEXT_SHARE_NONE = None <EOL> CONTEXT_SHARE_EXISTING = <NUM_LIT:1> <EOL> _gl_begin = False <EOL> _info = None <EOL> _workaround_checks = [ <EOL> ( '<STR_LIT>' , <EOL> lambda info : info . get_renderer ( ) == '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <EOL> lambda info : ( info . get_renderer ( ) . startswith ( '<STR_LIT>' ) <EOL> or info . get_renderer ( ) == <EOL> '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , <EOL> lambda info : ( '<STR_LIT>' in info . get_renderer ( ) and <EOL> info . have_version ( <NUM_LIT:1> , <NUM_LIT:5> ) and <EOL> _sys . platform == '<STR_LIT>' ) ) , <EOL> ] <EOL> def __init__ ( self , config , context_share = None ) : <EOL> self . config = config <EOL> self . context_share = context_share <EOL> self . canvas = None <EOL> if context_share : <EOL> self . object_space = context_share . object_space <EOL> else : <EOL> self . object_space = ObjectSpace ( ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . __class__ . __name__ <EOL> def attach ( self , canvas ) : <EOL> if self . canvas is not None : <EOL> self . detach ( ) <EOL> if not self . config . compatible ( canvas ) : <EOL> raise RuntimeError ( '<STR_LIT>' % ( canvas , self ) ) <EOL> self . canvas = canvas <EOL> def detach ( self ) : <EOL> self . canvas = None <EOL> def set_current ( self ) : <EOL> if not self . canvas : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> gl . current_context = self <EOL> gl_info . set_active_context ( ) <EOL> glu_info . set_active_context ( ) <EOL> if not self . _info : <EOL> self . _info = gl_info . GLInfo ( ) <EOL> self . _info . set_active_context ( ) <EOL> for attr , check in self . _workaround_checks : <EOL> setattr ( self , attr , check ( self . _info ) ) <EOL> if self . object_space . _doomed_textures : <EOL> textures = self . object_space . _doomed_textures <EOL> textures = ( gl . GLuint * len ( textures ) ) ( * textures ) <EOL> gl . glDeleteTextures ( len ( textures ) , textures ) <EOL> self . object_space . _doomed_textures = [ ] <EOL> if self . object_space . _doomed_buffers : <EOL> buffers = self . object_space . _doomed_buffers <EOL> buffers = ( gl . GLuint * len ( buffers ) ) ( * buffers ) <EOL> gl . glDeleteBuffers ( len ( buffers ) , buffers ) <EOL> self . object_space . _doomed_buffers = [ ] <EOL> def destroy ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . detach ( ) <EOL> if gl . current_context is self : <EOL> gl . current_context = None <EOL> gl_info . remove_active_context ( ) <EOL> if gl . _shadow_window is not None : <EOL> gl . _shadow_window . switch_to ( ) <EOL> def delete_texture ( self , texture_id ) : <EOL> '''<STR_LIT>''' <EOL> if self . object_space is gl . current_context . object_space : <EOL> id = gl . GLuint ( texture_id ) <EOL> gl . glDeleteTextures ( <NUM_LIT:1> , id ) <EOL> else : <EOL> self . object_space . _doomed_textures . append ( texture_id ) <EOL> def delete_buffer ( self , buffer_id ) : <EOL> '''<STR_LIT>''' <EOL> if self . object_space is gl . current_context . object_space and False : <EOL> id = gl . GLuint ( buffer_id ) <EOL> gl . glDeleteBuffers ( <NUM_LIT:1> , id ) <EOL> else : <EOL> self . object_space . _doomed_buffers . append ( buffer_id ) <EOL> def get_info ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _info </s>
