
    ^jHG                    ,   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
Z
d dl
mZ d dlmZ erd dlmZ d dlmZ d d	lmZ d d
lmZ  G d de          Z G d d          Z G d deej                  Z G d d          Z G d d          ZdS )    )annotationsN)Enum)TYPE_CHECKINGCallable)gl)gl_info)Array)Canvas)GLInfo)ShaderProgramc                      e Zd ZdZdZdZdS )	OpenGLAPIzThe OpenGL API backend to use.      N)__name__
__module____qualname____doc__OPENGL	OPENGL_ES     I/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/gl/base.pyr   r      s        ((FIIIr   r   c                  >   e Zd ZU dZded<   ded<   ded<   ded<   ded<   ded	<   ded
<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   dZded<   ded<   ded<   ded<   ded<   ded<   d.d Zd/d"Zej	        d0d&            Z
d1d*Zd2d+Zd3d,Zd-S )4Configa  Graphics configuration.

    A Config stores the preferences for OpenGL attributes such as the
    number of auxiliary 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.
    booldouble_bufferstereoint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)r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   major_versionminor_versionforward_compatible
opengl_apidebugtransparent_framebufferr.   r/   r0   strr1   r2   r3   kwargsfloatreturnNonec                    | j         D ]/}||v rt          | |||                    t          | |d           0| j        pd| _        dS )zCreate a template config with the given attributes.

        Specify attributes as keyword arguments, for example::

            template = Config(double_buffer=True)

        Nr   )_attribute_namessetattrr1   )selfr5   names      r   __init__zConfig.__init__l   s_     ) 	* 	*Dv~~dF4L1111dD))))/1Tr   "list[tuple[str, bool | int | str]]c                *      fd j         D             S )zReturn a list of attributes set on this config.

        The attributes are returned as a list of tuples, containing
        the name and values. Any unset attributes will have a value
        of ``None``.
        c                4    g | ]}|t          |          fS r   )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   canvasr
   list[DisplayConfig]c                    dS )z@Return a list of matching complete configs for the given canvas.Nr   r<   rG   s     r   matchzConfig.match         r   shareContext | NoneContextc                .    d}t          j        |          )zCreate a GL context that satisfies this configuration.

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

        :deprecated: Use `DisplayConfig.create_context`.
        zZThis config cannot be used to create contexts. Use Config.match to created a DisplayConfig)r   ConfigException)r<   rM   msgs      r   create_contextzConfig.create_context   s    : 	  %%%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, DisplayConfig)``.
        )
isinstanceDisplayConfigrE   s    r   is_completezConfig.is_complete   s     $...r   c                J    | j         j         d|                                  dS )N())	__class__r   rF   rE   s    r   __repr__zConfig.__repr__   s*    .)GGD,B,B,D,DGGGGr   N)r5   r6   r7   r8   )r7   r?   )rG   r
   r7   rH   )rM   rN   r7   rO   r7   r   r7   r4   )r   r   r   r   __annotations__r:   r>   rF   abcabstractmethodrK   rS   rW   r\   r   r   r   r   r      s          LLLLLLMMMOOONNNOOOOOO4 OOOKKK!!!!2 2 2 2 O O O O 	O O O O& & & &
/ 
/ 
/ 
/H H H H H Hr   r   c                  r    e Zd ZU dZded<   ddZej        dd
            Zej        dd            Z	ddZ
dS )rV   zAn OpenGL configuration for a particular display.

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

    .. versionadded:: 1.2
    r
   rG   base_configr   r7   r8   c                    || _         |j        | _        |j        | _        |j        | _        |j        p| j        | _        |j        | _        |j        | _        d S N)rG   r.   r/   r0   r1   r2   r3   )r<   rG   rc   s      r   r>   zDisplayConfig.__init__   sV    $(6(6"-"@%0CDO &
'2'J$$$r   r   c                    dS )z(Determine compatibility with the canvas.Nr   rJ   s     r   
compatiblezDisplayConfig.compatible   rL   r   rM   rO   c                    dS )zCreate a GL context that satisfies this configuration.

        Args:
            share:
                If not ``None``, a Context with which to share objects with.
        Nr   )r<   rM   s     r   rS   zDisplayConfig.create_context   rL   r   c                    dS )NTr   rE   s    r   rW   zDisplayConfig.is_complete   s    tr   N)rG   r
   rc   r   r7   r8   )rG   r
   r7   r   )rM   rO   r7   rO   r]   )r   r   r   r   r_   r>   r`   ra   rg   rS   rW   r   r   r   rV   rV      s           NNN	K 	K 	K 	K 	7 7 7 7 	        r   rV   c                      e Zd ZdZddZdS )ObjectSpacez;A container to store shared objects that are to be removed.r7   r8   c                L    g | _         g | _        g | _        g | _        g | _        dS )z$Initialize the context object space.N)doomed_texturesdoomed_buffersdoomed_shader_programsdoomed_shadersdoomed_renderbuffersrE   s    r   r>   zObjectSpace.__init__   s2      " &(# $&!!!r   Nr7   r8   )r   r   r   r   r>   r   r   r   rk   rk      s.        EE' ' ' ' ' 'r   rk   c                  
   e Zd ZU dZdZded<   ded<   ded<   d	ed
<   d7d8dZd9dZd:dZd:dZ	d;dZ
d:dZd:dZed<d            Zed=d            Zd:dZd>d Zd>d!Zd?d%Zd@d(ZdAd*ZdBd,ZdCd.ZdDd0ZdEd2ZdFd4ZdGd6ZdS )HrO   zfA base OpenGL context for drawing.

    Use ``DisplayConfig.create_context`` to create a context.
    NzGLInfo | None_infork   object_spacerV   configrN   context_sharer7   r8   c                    || _         || _        d| _        g | _        g | _        |r|j        | _        nt                      | _        t          j                    | _	        dS )a=  Initialize a context.

        This should only be created through the ``DisplayConfig.create_context`` method.

        Args:
            config:
                An operating system specific config.
            context_share:
                A context to share objects with. Use ``None`` to disable sharing.
        N)
rv   rw   rG   doomed_vaosdoomed_framebuffersru   rk   weakrefWeakValueDictionary_cached_programs)r<   rv   rw   s      r   r>   zContext.__init__   sc     *#%  	. - :D +D ' ; = =r   r4   c                P    | j         j         dt          |            d| j         dS )Nz(id=z, share=rZ   )r[   r   idrw   rE   s    r   r\   zContext.__repr__   s/    .)VVr$xxVVASVVVVr   c                .    |                                   d S re   )set_currentrE   s    r   	__enter__zContext.__enter__  s    r   c                    d S re   r   )r<   _argss     r   __exit__zContext.__exit__  s    r   rG   r
   c                    | j         |                                  | j                            |          sd| d|  }t	          |          || _         d S )NzCannot attach z to )rG   detachrv   rg   RuntimeError)r<   rG   rR   s      r   attachzContext.attach	  s]    ;"KKMMM{%%f-- 	$5655t55Cs###r   c                    d | _         d S re   )rG   rE   s    r   r   zContext.detach  s    r   c                   | j         sd}t          |          | t          _        t	          j                     | j        s1t	          j                    | _        | j                                         | j        j	        r*| 
                    | j        j	        t          j                   | j        j        r*| 
                    | j        j        t          j                   | j        j        r*|                     | j        j        t          j                   | j        j        r*|                     | j        j        t          j                   | j        j        r*| 
                    | j        j        t          j                   | j        r%| 
                    | j        t          j                   | j        r'| 
                    | j        t          j                   dS dS )a"  Make this the active Context.

        Setting the Context current will also delete any OpenGL
        objects that have been queued for deletion. IE: any objects
        that were created in this Context, but have been called for
        deletion while another Context was active.
        zCanvas has not been attachedN)rG   r   r   current_contextr   set_active_contextrt   r   ru   rm   _delete_objectsglDeleteTexturesrn   glDeleteBuffersro   _delete_objects_one_by_oneglDeleteProgramrp   glDeleteShaderrq   glDeleteRenderbuffersry   glDeleteVertexArraysrz   glDeleteFramebuffers)r<   rR   s     r   r   zContext.set_current  s    { 	$0Cs### " 	"$$$z 	, ))DJJ))+++, 	Y  !2!BBDWXXX+ 	W  !2!A2CUVVV3 	@++D,=,T,.,>@ @ @+ 	a++D,=,LbN_```1 	c  !2!GIabbb 	L  !123JKKK# 	T  !92;RSSSSS	T 	Tr   list_listdeletion_func'Callable[[int, Array[gl.GLuint]], None]c                x    t          |           }| d|         }| d|=  ||t          j        |z  |            dS )zRelease all OpenGL objects in the given list.

        Uses the supplied deletion function with the signature ``(GLuint count, GLuint *names)``.
        Nlenr   GLuint)r   r   count	to_deletes       r   r   zContext._delete_objects@  sK     E

&5&M	&5&Mebi%/)<=====r   Callable[[gl.GLuint], None]c                    t          |           }| d|         }| d|= |D ]} |t          j        |                      dS )zRelease all OpenGL objects in the given list.

        Similar to ``_delete_objects``, but assumes the deletion function's signature to be ``(GLuint name)``.

        The function is called for each object.
        Nr   )r   r   r   r   r=   s        r   r   z"Context._delete_objects_one_by_oneL  s[     E

&5&M	&5&M 	+ 	+DM")D//****	+ 	+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 usable 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)r   r   r   r   remove_active_context_shadow_window	switch_torE   s    r   destroyzContext.destroy[  sl     	%%!%B)+++  ,!++----- &%
 -,r   r   c                ~    | j         t          j        j         u o%t          j                    t          j                    u S )a  Check if it's safe to interact with this context's object space.

        This is considered to be the case if the currently active context's
        object space is the same as this context's object space and this
        method is called from the main thread.
        )ru   r   r   	threadingcurrent_threadmain_threadrE   s    r    _safe_to_operate_on_object_spacez(Context._safe_to_operate_on_object_spacem  s;     !R%7%DD F(**i.C.E.EE	Gr   c                j    t           j        | u o%t          j                    t          j                    u S )zCheck whether it is safe to interact with this context.

        This is considered to be the case if it's the current context and this
        method is called from the main thread.
        )r   r   r   r   r   rE   s    r   _safe_to_operate_onzContext._safe_to_operate_onw  s.     !T)ci.F.H.HILaLcLc.ccr   sourcestuple[str, str]r   c                    | j                             t          |                    x}r|S d |D             }t          j        j        j        | }|| j         t          |          <   |S )a'  Create a ShaderProgram from OpenGL GLSL source.

        This is a convenience method that takes one or more tuples of
        (source_string, shader_type), and returns a
        :py:class:`~pyglet.graphics.shader.ShaderProgram` instance.

        ``source_string`` is OpenGL GLSL source code as a str, and ``shader_type``
        is the OpenGL shader type, such as "vertex" or "fragment". See
        :py:class:`~pyglet.graphics.shader.Shader` for more information.

        .. note:: This method is cached. Given the same shader sources, the
                  same ShaderProgram instance will be returned. For more
                  control over the ShaderProgram lifecycle, it is recommended
                  to manually create Shaders and link ShaderPrograms.

        .. versionadded:: 2.0.10
        c              3  f   K   | ],\  }}t           j        j                            ||          V  -d S re   )pygletgraphicsshaderShader)rC   srcsrctypes      r   	<genexpr>z)Context.create_program.<locals>.<genexpr>  s;      ]]>C6?)00g>>]]]]]]r   )r}   getr4   r   r   r   r   )r<   r   programshaderss       r   create_programzContext.create_program  sk    $ +//G===7 	N]]U\]]]/(6@.5c'll+r   
texture_idr   c                    |                                  r)t          j        dt          j        |                     dS | j        j                            |           dS )a  Safely delete a Texture belonging to this context's object space.

        This method will delete the texture immediately via
        ``glDeleteTextures`` if the current context's object space is the same
        as this context's object space, and it is called from the main thread.

        Otherwise, the texture will only be marked for deletion, postponing
        it until any context with the same object space becomes active again.

        This makes it safe to call from anywhere, including other threads.
        r   N)r   r   r   r   ru   rm   append)r<   r   s     r   delete_texturezContext.delete_texture  s\     0022 	A29Z#8#899999-44Z@@@@@r   	buffer_idc                    |                                  r)t          j        dt          j        |                     dS | j        j                            |           dS )zSafely delete a Buffer belonging to this context's object space.

        This method behaves similarly to ``delete_texture``, though for
        ``glDeleteBuffers`` instead of ``glDeleteTextures``.
        r   N)r   r   r   r   ru   rn   r   )r<   r   s     r   delete_bufferzContext.delete_buffer  s[     0022 	?q")I"6"677777,33I>>>>>r   
program_idc                    |                                  r(t          j        t          j        |                     dS | j        j                            |           dS )zSafely delete a ShaderProgram belonging to this context's object space.

        This method behaves similarly to ``delete_texture``, though for
        ``glDeleteProgram`` instead of ``glDeleteTextures``.
        N)r   r   r   r   ru   ro   r   )r<   r   s     r   delete_shader_programzContext.delete_shader_program  sZ     0022 	Hry44555554;;JGGGGGr   	shader_idc                    |                                  r(t          j        t          j        |                     dS | j        j                            |           dS )zSafely delete a Shader belonging to this context's object space.

        This method behaves similarly to ``delete_texture``, though for
        ``glDeleteShader`` instead of ``glDeleteTextures``.
        N)r   r   r   r   ru   rp   r   )r<   r   s     r   delete_shaderzContext.delete_shader  sY     0022 	?bi	2233333,33I>>>>>r   rbo_idc                    |                                  r)t          j        dt          j        |                     dS | j        j                            |           dS )zSafely delete a Renderbuffer belonging to this context's object space.

        This method behaves similarly to ``delete_texture``, though for
        ``glDeleteRenderbuffers`` instead of ``glDeleteTextures``.
        r   N)r   r   r   r   ru   rq   r   )r<   r   s     r   delete_renderbufferzContext.delete_renderbuffer  s\     0022 	B$Q	&(9(9:::::299&AAAAAr   vao_idc                    |                                  r)t          j        dt          j        |                     dS | j                            |           dS )aq  Safely delete a Vertex Array Object belonging to this context.

        If this context is not the current context or this method is not
        called from the main thread, its deletion will be postponed until
        this context is next made active again.

        Otherwise, this method will immediately delete the VAO via
        ``glDeleteVertexArrays``.
        r   N)r   r   r   r   ry   r   )r<   r   s     r   
delete_vaozContext.delete_vao  sX     ##%% 	,#Ary'8'899999##F+++++r   fbo_idc                    |                                  r)t          j        dt          j        |                     dS | j                            |           dS )zSafely delete a Framebuffer Object belonging to this context.

        This method behaves similarly to ``delete_vao``, though for
        ``glDeleteFramebuffers`` instead of ``glDeleteVertexArrays``.
        r   N)r   r   r   r   rz   r   )r<   r   s     r   delete_framebufferzContext.delete_framebuffer  sX     ##%% 	4#Ary'8'899999$++F33333r   r   c                    | j         S )z6Get the :py:class:`~GLInfo` instance for this context.)rt   rE   s    r   get_infozContext.get_info  s
    zr   re   )rv   rV   rw   rN   r7   r8   r^   rr   )rG   r
   r7   r8   )r   r   r   r   r7   r8   )r   r   r   r   r7   r8   r]   )r   r   r7   r   )r   r   r7   r8   )r   r   r7   r8   )r   r   r7   r8   )r   r   r7   r8   )r   r   r7   r8   )r   r   r7   r8   )r   r   r7   r8   )r7   r   )r   r   r   r   rt   r_   r>   r\   r   r   r   r   r   staticmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rO   rO      s7         
  E !!!!> > > > >2W W W W            %T %T %T %TX 	> 	> 	> \	> + + + \+. . . .$G G G Gd d d d   6A A A A"	? 	? 	? 	?	H 	H 	H 	H	? 	? 	? 	?	B 	B 	B 	B, , , ,	4 	4 	4 	4     r   rO   )
__future__r   r`   r   r{   enumr   typingr   r   r   r   	pyglet.glr   _ctypesr	   pyglet.display.baser
   pyglet.gl.gl_infor   pyglet.graphics.shaderr   r   r   ABCrV   rk   rO   r   r   r   <module>r      s   " " " " " " 



            * * * * * * * *              5******((((((444444       KH KH KH KH KH KH KH KH\" " " " "FCG " " "J
' 
' 
' 
' 
' 
' 
' 
'Y Y Y Y Y Y Y Y Y Yr   