Ë
    _ð£eÁ  ã                   óT   — d Z ddlmZ ddlZi Zi ZeegZd	d„Zd
d„Zd	d„Z	d	d„Z
d	d„Zy)a…  Storage of per-context values of various types

Because OpenGL needs persistent references to the
objects we're constructing to shadow Python objects,
we have to store references to the objects somewhere

For any given Python GUI library, we can use a weakref
to the library's representation of the GL context to 
call the cleanup function.  That means some per-GUI 
library code in OpenGL (or the library), but it gives 
us very natural operations within OpenGL.

Note: you can entirely disable use of this module by 
setting:

    OpenGL.ERROR_ON_COPY = True 
    OpenGL.STORE_POINTERS = False 
        
before importing OpenGL functionality.
é    )ÚplatformNc                 ój   — | €0t        j                  «       } | dk(  rddlm} |j	                  d«      ‚| S )znGet the context (if passed, just return)
    
    context -- the context ID, if None, the current context
    r   )Úerrorz1Attempt to retrieve context when no valid context)r   ÚGetCurrentContextÚOpenGLr   ÚError)Úcontextr   s     ú4/usr/lib/python3/dist-packages/OpenGL/contextdata.pyÚ
getContextr      s<   € ð
 €Ü×,Ñ,Ó.ˆØaŠ<Ý$Ø—+‘+ØGóð ð €Nó    c                 ó@  — t        |dd«      ryt        |«      }|rt        }t        j                  }nt
        }t        }|j                  |«      }|€ |«       x||<   }|j                  | «      }|€	 || = |S ||| <   |S # t        t        t        f$ r}Y d}~|S d}~ww xY w)a7  Set a stored value for the given context
    
    constant -- Normally a GL constant value, but can be any hashable value 
    value -- the value to be stored.  If weak is true must be 
        weak-reference-able.  If None, then the value will be deleted from 
        the storage 
    context -- the context identifier for which we're storing the value
    weak -- if true, value will be stored with a weakref
        Note: you should always pass the same value for "weak" for a given 
        constant, otherwise you will create two storages for the constant.
    Ú
_no_cache_FN)Úgetattrr   ÚstoredWeakPointersÚweakrefÚWeakValueDictionaryÚstoredPointersÚdictÚgetÚKeyErrorÚ	TypeErrorÚ
ValueError)	ÚconstantÚvaluer	   ÚweakÚstorageÚclsÚcurrentÚpreviousÚerrs	            r
   ÚsetValuer!   ,   s¹   € ô | UÔ,ØÜ˜'Ó#€GÙÜ$ˆÜ×)Ñ)‰ä ˆÜˆØk‰k˜7Ó$€GØ€Ù%(£UÐ*ˆÑ˜7Ø{‰{˜HÓ&€HØ€}ð	Ø˜Ð#ð €Oð $ˆÑØ€Oøô œ¤:Ð.ò 	Ûð
 €Oûð	ús   Á2A> Á>BÂBc                 ó–   — t        |«      }d}t        D ]  }|j                  |«      }|sŒ	 || = d}Œ |S # t        $ r
}Y d}~Œ/d}~ww xY w)zÏDelete the specified value for the given context
    
    constant -- Normally a GL constant value, but can be any hashable value 
    context -- the context identifier for which we're storing the value
    FTN)r   ÚSTORAGESr   r   )r   r	   Úfoundr   ÚcontextStorager    s         r
   ÚdelValuer&   O   sa   € ô ˜'Ó#€GØ€EÜò ˆØ Ÿ™ gÓ0ˆÚðØ" HÐ.Ø‘ðð €Løô ò Üûðús   ¬5µ	AÁAc                 ó†   — t        |«      }t        D ]-  }|j                  |«      }|sŒ|j                  | «      }|€Œ+|c S  y)z®Get a stored value for the given constant
    
    constant -- unique ID for the type of data being retrieved
    context -- the context ID, if None, the current context
    N)r   r#   r   )r   r	   r   r%   r   s        r
   ÚgetValuer(   a   sN   € ô ˜'Ó#€GÜò ˆØ Ÿ™ gÓ0ˆÚØ#×'Ñ'¨Ó3ˆEØÑ Ø’ðð r   c                 ó†   — | €t        j                  «       } t        D ]  }	 t        | =  y y# t        $ r}Y d}~ yd}~ww xY w)aÜ  Cleanup all held pointer objects for the given context
    
    Warning: this is dangerous, as if you call it before a context 
    is destroyed you may release memory held by the context and cause
    a protection fault when the GL goes to render the scene!
    
    Normally you will want to get the context ID explicitly and then 
    register cleanupContext as a weakref callback to your GUI library 
    Context object with the (now invalid) context ID as parameter.
    NTF)r   r   r#   r   r   )r	   r   r    s      r
   ÚcleanupContextr*   p   sM   € ð €Ü×,Ñ,Ó.ˆÜò ˆð	Ü Ð)ñ ñøô ò 	Ýûð	ús   ¡,¬	A »A )N)NF)Ú__doc__r   r   r   r   r   r#   r   r!   r&   r(   r*   © r   r
   ú<module>r-      sH   ðñõ( Û ð€ðÐ ð Ð/Ð1€óó"óFó$ôr   