
    \
j<:                         d dl mZmZ d dlmZ d dlmZ  G d d          Z G d de          Z G d d	          Z G d
 d          Z	dS )    )glcompat_platform)gl_info)glu_infoc                   T    e Zd ZdZg dZdZdZdZdZd Z	d Z
d Zd Zd Zd	 Zd
 ZdS )Configa  Graphics configuration.

    A Config stores the preferences for OpenGL attributes such as the
    number of auxilliary buffers, size of the colour and depth buffers,
    double buffering, stencilling, multi- and super-sampling, and so on.

    Different platforms support a different set of attributes, so these
    are set with a string key and a value which is integer or boolean.

    :Ivariables:
        `double_buffer` : bool
            Specify the presence of a back-buffer for every color buffer.
        `stereo` : bool
            Specify the presence of separate left and right buffer sets.
        `buffer_size` : int
            Total bits per sample per color buffer.
        `aux_buffers` : int
            The number of auxilliary color buffers.
        `sample_buffers` : int
            The number of multisample buffers.
        `samples` : int
            The number of samples per pixel, or 0 if there are no multisample
            buffers.
        `red_size` : int
            Bits per sample per buffer devoted to the red component.
        `green_size` : int
            Bits per sample per buffer devoted to the green component.
        `blue_size` : int
            Bits per sample per buffer devoted to the blue component.
        `alpha_size` : int
            Bits per sample per buffer devoted to the alpha component.
        `depth_size` : int
            Bits per sample in the depth buffer.
        `stencil_size` : int
            Bits per sample in the stencil buffer.
        `accum_red_size` : int
            Bits per pixel devoted to the red component in the accumulation
            buffer.
        `accum_green_size` : int
            Bits per pixel devoted to the green component in the accumulation
            buffer.
        `accum_blue_size` : int
            Bits per pixel devoted to the blue component in the accumulation
            buffer.
        `accum_alpha_size` : int
            Bits per pixel devoted to the alpha component in the accumulation
            buffer.
    )double_bufferstereobuffer_sizeaux_bufferssample_bufferssamplesred_size
green_size	blue_size
alpha_size
depth_sizestencil_sizeaccum_red_sizeaccum_green_sizeaccum_blue_sizeaccum_alpha_sizemajor_versionminor_versionforward_compatibledebugNc                 t    | j         D ]/}||v rt          | |||                    t          | |d           0dS )zCreate a template config with the given attributes.

        Specify attributes as keyword arguments, for example::

            template = Config(double_buffer=True)

        N)_attribute_namessetattr)selfkwargsnames      H/DATA/AppData/hermes/venv/lib/python3.11/site-packages/pyglet/gl/base.py__init__zConfig.__init__w   sW     ) 	* 	*Dv~~dF4L1111dD))))		* 	*    c                 N    | j         | j         dk    rdS | j        s| j        rdS dS )N   TF)r   r   r   r    s    r#   requires_gl_3zConfig.requires_gl_3   s;    )d.@A.E.E4" 	dj 	4ur%   c                 *      fd j         D             S )zReturn a list of attributes set on this config.

        :rtype: list of tuple ``(name, value)``
        :return: All attributes, with unset attributes having a value of
            ``None``.
        c                 4    g | ]}|t          |          fS  )getattr).0r"   r    s     r#   
<listcomp>z,Config.get_gl_attributes.<locals>.<listcomp>   s(    NNNwtT**+NNNr%   )r   r(   s   `r#   get_gl_attributeszConfig.get_gl_attributes   s#     ONNN8MNNNNr%   c                      t          d          )a  Return a list of matching complete configs for the given canvas.

        .. versionadded:: 1.2

        :Parameters:
            `canvas` : `Canvas`
                Display to host contexts created from the config.

        :rtype: list of `CanvasConfig`
        abstractNotImplementedErrorr    canvass     r#   matchzConfig.match   s     "*---r%   c                 *    t          j        d          )a5  Create a GL context that satisifies this configuration.

        :deprecated: Use `CanvasConfig.create_context`.

        :Parameters:
            `share` : `Context`
                If not None, a context with which to share objects with.

        :rtype: `Context`
        :return: The new context.
        zZThis config cannot be used to create contexts.  Use Config.match to created a CanvasConfig)r   ConfigExceptionr    shares     r#   create_contextzConfig.create_context   s"       "N O O 	Or%   c                 ,    t          | t                    S )a  Determine if this config is complete and able to create a context.

        Configs created directly are not complete, they can only serve
        as templates for retrieving a supported config from the system.
        For example, `pyglet.window.Screen.get_matching_configs` returns
        complete configs.

        :deprecated: Use ``isinstance(config, CanvasConfig)``.

        :rtype: bool
        :return: True if the config is complete and can create a context.
        )
isinstanceCanvasConfigr(   s    r#   is_completezConfig.is_complete   s     $---r%   c                 x    dd l }| j        j        d|                    |                                           dS )Nr   ())pprint	__class____name__pformatr0   )r    rD   s     r#   __repr__zConfig.__repr__   s?    >222FNN4CYCYC[C[4\4\4\4\]]r%   )rF   
__module____qualname____doc__r   r   r   r   r   r$   r)   r0   r7   r<   r@   rH   r,   r%   r#   r   r   )   s        / /b  . MME* * *  O O O. . .O O O. . .^ ^ ^ ^ ^r%   r   c                   *    e Zd ZdZd Zd Zd Zd ZdS )r?   zOpenGL configuration for a particular canvas.

    Use `Config.match` to obtain an instance of this class.

    .. versionadded:: 1.2

    :Ivariables:
        `canvas` : `Canvas`
            The canvas this config is valid on.

    c                 t    || _         |j        | _        |j        | _        |j        | _        |j        | _        d S N)r6   r   r   r   r   )r    r6   base_configs      r#   r$   zCanvasConfig.__init__   s8    (6(6"-"@ &


r%   c                      t          d          )Nr2   r3   r5   s     r#   
compatiblezCanvasConfig.compatible   s    !*---r%   c                      t          d          )zCreate a GL context that satisifies this configuration.

        :Parameters:
            `share` : `Context`
                If not None, a context with which to share objects with.

        :rtype: `Context`
        :return: The new context.
        r2   r3   r:   s     r#   r<   zCanvasConfig.create_context   s     "*---r%   c                     dS )NTr,   r(   s    r#   r@   zCanvasConfig.is_complete   s    tr%   N)rF   rI   rJ   rK   r$   rQ   r<   r@   r,   r%   r#   r?   r?      sZ        
 
' ' '. . .
. 
. 
.    r%   r?   c                       e Zd Zd ZdS )ObjectSpacec                 "    g | _         g | _        d S rN   )_doomed_textures_doomed_buffersr(   s    r#   r$   zObjectSpace.__init__   s     !#!r%   N)rF   rI   rJ   r$   r,   r%   r#   rU   rU      s#        " " " " "r%   rU   c                   v    e Zd ZdZdZdZdZdZdd fdd fd	d
 fgZddZ	d Z
d Zd Zd Zd Zd Zd Zd ZdS )ContextzOpenGL context for drawing.

    Use `CanvasConfig.create_context` to create a context.

    :Ivariables:
        `object_space` : `ObjectSpace`
            An object which is shared between all contexts that share
            GL objects.

    N   F_workaround_unpack_row_lengthc                 2    |                                  dk    S )NzGDI Generic)get_rendererinfos    r#   <lambda>zContext.<lambda>  s    d''))]: r%   _workaround_vboc                     |                                                      d          p>|                                                      d          p|                                  dk    S )NzATI Radeon XzRADEON XPRESS 200Mz(Intel 965/963 Graphics Media Accelerator)r^   
startswithr_   s    r#   ra   zContext.<lambda>!  se    t((**55nEE B++--889MNNB++--AB r%   _workaround_vbo_finishc                 p    d|                                  v o |                     dd          o
t          dk    S )NATIr[      darwin)r^   have_versionr   r_   s    r#   ra   zContext.<lambda>*  s?    u 1 1 3 33 3((A..3&(2 r%   c                 v    || _         || _        d | _        |r|j        | _        d S t	                      | _        d S rN   )configcontext_sharer6   object_spacerU   )r    rl   rm   s      r#   r$   zContext.__init__/  sC    * 	. - :D +Dr%   c                      d| j         j        z  S )Nz%s())rE   rF   r(   s    r#   rH   zContext.__repr__9  s    ///r%   c                     | j         |                                  | j                            |          st	          d|d|           || _         d S )NzCannot attach z to )r6   detachrl   rQ   RuntimeErrorr5   s     r#   attachzContext.attach<  sV    ;"KKMMM{%%f-- 	J,66644HIIIr%   c                     d | _         d S rN   )r6   r(   s    r#   rq   zContext.detachC  s    r%   c                 Z   | j         st          d          | t          _        t	          j                     t          j                     | j        s]t	          j                    | _        | j                                         | j	        D ]$\  }}t          | | || j                             %| j        j        rr| j        j        d d          }t          j        t          |          z  | }t          j        t          |          |           g | j        j        dt          |          <   | j        j        rt| j        j        d d          }t          j        t          |          z  | }t          j        t          |          |           g | j        j        dt          |          <   d S d S )NzCanvas has not been attachedr   )r6   rr   r   current_contextr   set_active_contextr   _infoGLInfo_workaround_checksr   rn   rW   GLuintlenglDeleteTexturesrX   glDeleteBuffers)r    attrchecktexturesbufferss        r#   set_currentzContext.set_currentF  s   { 	?=>>> " 	"$$$#%%% z 	7 ))DJJ))+++#6 7 7edEE$*$5$56666 - 	E(9!!!<H	CMM1H=HHx888BDD.qX?, 	C'7:Gy3w<</':Gs7||W555@BD-aGn===		C 	Cr%   c                     |                                   t          j        | u rKdt          _        t          j                     t          j        "t          j                                         dS dS dS )a  Release the context.

        The context will not be useable after being destroyed.  Each platform
        has its own convention for releasing the context and the buffer(s)
        that depend on it in the correct order; this should never be called
        by an application.
        N)rq   r   rv   r   remove_active_context_shadow_window	switch_tor(   s    r#   destroyzContext.destroyg  sl     	%%!%B)+++  ,!++----- &%
 -,r%   c                     | j         t          j        j         u r+t          j        |          }t          j        d|           dS | j         j                            |           dS )a  Safely delete a texture belonging to this context.

        Usually, the texture is released immediately using
        ``glDeleteTextures``, however if another context that does not share
        this context's object space is currently active, the deletion will
        be deferred until an appropriate context is activated.

        :Parameters:
            `texture_id` : int
                The OpenGL name of the texture to delete.

        r[   N)rn   r   rv   r{   r}   rW   append)r    
texture_idids      r#   delete_texturezContext.delete_texturey  s`      2 ???:&&B2&&&&&.55jAAAAAr%   c                 v    | j         t          j        j         u r	 | j         j                            |           dS )a  Safely delete a buffer object belonging to this context.

        This method behaves similarly to :py:func:`~pyglet.text.document.AbstractDocument.delete_texture`, though for
        ``glDeleteBuffers`` instead of ``glDeleteTextures``.

        :Parameters:
            `buffer_id` : int
                The OpenGL name of the buffer to delete.

        .. versionadded:: 1.1
        Fr[   N)rn   r   rv   r{   r~   rX   r   )r    	buffer_idr   s      r#   delete_bufferzContext.delete_buffer  s=      2 ???? -44Y?????r%   c                     | j         S )znGet the OpenGL information for this context.

        .. versionadded:: 1.2

        :rtype: `GLInfo`
        )rx   r(   s    r#   get_infozContext.get_info  s     zr%   rN   )rF   rI   rJ   rK   CONTEXT_SHARE_NONECONTEXT_SHARE_EXISTING	_gl_beginrx   rz   r$   rH   rs   rq   r   r   r   r   r   r,   r%   r#   rZ   rZ      s       	 	   I E 
)	:	:	< 

C 
C	D 
"
4 
4	5-8. . . .0 0 0    C C CB. . .$B B B&@ @ @$    r%   rZ   N)
pygletr   r   	pyglet.glr   r   r   r?   rU   rZ   r,   r%   r#   <module>r      s  H ' & & & & & & &            Y^ Y^ Y^ Y^ Y^ Y^ Y^ Y^x% % % % %6 % % %P" " " " " " " "p p p p p p p p p pr%   