
    ^jG*                    .   d Z ddlmZ ddlZddlmZmZmZmZm	Z	m
Z
 ddlmZmZmZmZ ddlmZmZmZmZ ddlmZmZ ddlmZmZmZ dd	lmZmZmZ dd
lmZmZ ddlmZmZ ddlmZm Z  ddl!m"Z" e"rddl#m$Z$ ddZ% G d d          Z& G d d          Z'dS )a  OpenGL Framebuffer abstractions.

This module provides classes for working with Framebuffers & Renderbuffers
and their attachments. Attachments can be pyglet Texture objects, which allows
easily accessing their data, saving to disk, etc. Renderbuffers can be used
if you don't need to access their data at a later time. For example::

    # Create two objects to use as attachments for our Framebuffer.
    color_buffer = pyglet.image.Texture.create(width, height, min_filter=GL_NEAREST, mag_filter=GL_NEAREST)
    depth_buffer = pyglet.image.buffer.Renderbuffer(width, height, GL_DEPTH_COMPONENT)

    # Create a framebuffer object, and attach the two buffers:
    framebuffer = pyglet.image.Framebuffer()
    framebuffer.attach_texture(color_buffer, attachment=GL_COLOR_ATTACHMENT0)
    framebuffer.attach_renderbuffer(depth_buffer, attachment=GL_DEPTH_ATTACHMENT)

    # Bind the Framebuffer, which sets it as the active render target:
    framebuffer.bind()

See the OpenGL documentation for more information on valid attachment types and targets.
    )annotationsN)GLintGLuintglBindFramebufferglBindRenderbufferglCheckFramebufferStatusglClear)glDeleteFramebuffersglDeleteRenderbuffersglFramebufferRenderbufferglFramebufferTexture)glFramebufferTextureLayerglGenFramebuffersglGenRenderbuffersglGetIntegerv)glRenderbufferStorage glRenderbufferStorageMultisample)GL_COLOR_ATTACHMENT0GL_MAX_COLOR_ATTACHMENTSGL_RENDERBUFFER)GL_FRAMEBUFFERGL_FRAMEBUFFER_COMPLETE$GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT)(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT%GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER)%GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT,GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)%GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFERGL_FRAMEBUFFER_UNSUPPORTED)TYPE_CHECKING)Texturereturnintc                 V    t                      } t          t          |            | j        S )z4Get the maximum allow Framebuffer Color attachments.)r   r   r   value)numbers    N/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/image/buffer.pyget_max_color_attachmentsr(   *   s$    WWF*F333<    c                      e Zd ZdZddd
Zedd            Zedd            Zedd            ZddZ	e
dd            ZddZddZddZdS )RenderbufferzOpenGL Renderbuffer Object.   widthr#   heightinternal_formatsamplesr"   Nonec                v   t           j        j        | _        t	                      | _        || _        || _        || _        t          d| j                   t          t          | j                   |dk    rt          t          ||||           nt          t          |||           t          t          d           dS )zCreate a RenderBuffer instance.r,   r   N)pygletglcurrent_context_contextr   _id_width_height_internal_formatr   r   r   r   r   )selfr-   r.   r/   r0   s        r'   __init__zRenderbuffer.__init__4   s    	188 /1dh'''?DH555Q;;,_gX]_effff!/?E6RRR?A.....r)   c                    | j         j        S Nr7   r%   r;   s    r'   idzRenderbuffer.idF   s    x~r)   c                    | j         S r>   r8   r@   s    r'   r-   zRenderbuffer.widthJ   s
    {r)   c                    | j         S r>   r9   r@   s    r'   r.   zRenderbuffer.heightN   s
    |r)   c                :    t          t          | j                   d S r>   )r   r   r7   r@   s    r'   bindzRenderbuffer.bindR   s    ?DH55555r)   c                 0    t          t          d           d S )Nr   )r   r    r)   r'   unbindzRenderbuffer.unbindU   s    ?A.....r)   c                >    t          d| j                   d | _        d S )Nr,   )r   r7   r@   s    r'   deletezRenderbuffer.deleteY   s    a***r)   c                    | j         F	 | j                            | j         j                   d | _         d S # t          t
          f$ r Y d S w xY wd S r>   )r7   r6   delete_renderbufferr%   AttributeErrorImportErrorr@   s    r'   __del__zRenderbuffer.__del__]   sc    811$(.AAA"K0   	     +6 A
Astrc                :    | j         j         d| j        j         dS Nz(id=)	__class____name__r7   r%   r@   s    r'   __repr__zRenderbuffer.__repr__e   "    .)@@tx~@@@@r)   N)r,   )
r-   r#   r.   r#   r/   r#   r0   r#   r"   r1   r"   r#   r"   r1   r"   rS   )rY   
__module____qualname____doc__r<   propertyrA   r-   r.   rG   staticmethodrJ   rL   rQ   rZ   rI   r)   r'   r+   r+   1   s	       %%/ / / / /$    X    X    X6 6 6 6 / / / \/      A A A A A Ar)   r+   c                      e Zd ZdZefddZe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ed"d            Zed#d            Zeefd$dZeefd%dZeefd&dZd#dZdS )'Framebufferz:OpenGL Framebuffer Object.

    .. versionadded:: 2.0
    targetr#   r"   r1   c                    t           j        j        | _        t	                      | _        t          d| j                   d| _        d| _        d| _	        || _
        dS )zCreate a Framebuffer Instance.r,   r   N)r3   r4   r5   r6   r   r7   r   _attachment_typesr8   r9   rf   )r;   rf   s     r'   r<   zFramebuffer.__init__n   sL    	188!TX&&&!"r)   c                    | j         j        S )zThe Framebuffer id.r?   r@   s    r'   rA   zFramebuffer.idx   s     x~r)   c                    | j         S )z#The width of the widest attachment.rC   r@   s    r'   r-   zFramebuffer.width}   s     {r)   c                    | j         S )z%The height of the tallest attachment.rE   r@   s    r'   r.   zFramebuffer.height   s     |r)   c                :    t          | j        | j                   dS )zWBind the Framebuffer.

        This ctivates it as the current drawing target.
        N)r   rf   r7   r@   s    r'   rG   zFramebuffer.bind   s    
 	$+tx00000r)   c                0    t          | j        d           dS )zUnbind the Framebuffer.

        Unbind should be called to prevent further rendering
        to the framebuffer, or if you wish to access data
        from its Texture attachments.
        r   N)r   rf   r@   s    r'   rJ   zFramebuffer.unbind   s     	$+q)))))r)   c                    | j         r>|                                  t          | j                    |                                  dS dS )zClear the attachments.N)rh   rG   r	   rJ   r@   s    r'   clearzFramebuffer.clear   sF    ! 	IIKKKD*+++KKMMMMM	 	r)   c                >    t          d| j                   d| _        dS )z"Explicitly delete the Framebuffer.r,   N)r
   r7   r@   s    r'   rL   zFramebuffer.delete   s    Q)))r)   c                    | j         F	 | j                            | j         j                   d | _         d S # t          t
          f$ r Y d S w xY wd S r>   )r7   r6   delete_framebufferr%   rO   rP   r@   s    r'   rQ   zFramebuffer.__del__   sc    800@@@"K0   	  rR   boolc                <    t          t                    t          k    S )z2True if the framebuffer is 'complete', else False.)r   r   r   r@   s    r'   is_completezFramebuffer.is_complete   s     (77;RRRr)   rS   c                     t           dt          dt          dt          dt          dt
          dt          dt          di} t          t                    }| 
                    |d	          S )
zGet the current Framebuffer status, as a string.

        If ``Framebuffer.is_complete`` is ``False``, this method
        can be used for more information. It will return a
        string with the OpenGL reported status.
        z,Framebuffer unsupported. Try another format.z"Framebuffer incomplete attachment.zFramebuffer missing attachment.z"Framebuffer unsupported dimension.zFramebuffer incomplete formats.z#Framebuffer incomplete draw buffer.z#Framebuffer incomplete read buffer.zFramebuffer is complete.zUnknown error)r   r   r   r   r   r   r   r   r   r   get)states	gl_statuss     r'   
get_statuszFramebuffer.get_status   s_     -.\68\>@a:<`79Z79^79^)+EG -^<<	zz)_555r)   texturer!   
attachmentc                *   |                                   t          |||j        |j                   | xj        |z  c_        t          |j        | j                  | _        t          |j        | j	                  | _	        | 
                                 dS )a  Attach a Texture to the Framebuffer.

        Args:
            texture:
                Specifies the texture object to attach to the framebuffer attachment
                point named by attachment.
            target:
                Specifies the framebuffer target. target must be GL_DRAW_FRAMEBUFFER,
                GL_READ_FRAMEBUFFER, or GL_FRAMEBUFFER. GL_FRAMEBUFFER is equivalent
                to GL_DRAW_FRAMEBUFFER.
            attachment:
                Specifies the attachment point of the framebuffer. attachment must be
                GL_COLOR_ATTACHMENTi, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT or
                GL_DEPTH_STENCIL_ATTACHMENT.
        N)rG   r   rA   levelrh   maxr-   r8   r.   r9   rJ   )r;   r{   rf   r|   s       r'   attach_texturezFramebuffer.attach_texture   sx    " 			VZW]KKK*,'-557>4<88r)   layerr~   c                "   |                                   t          |||j        ||           | xj        |z  c_        t	          |j        | j                  | _        t	          |j        | j                  | _        | 	                                 dS )aN  Attach a Texture layer to the Framebuffer.

        Args:
            texture:
                Specifies the texture object to attach to the framebuffer attachment
                point named by attachment.
            layer:
                Specifies the layer of texture to attach.
            level:
                Specifies the mipmap level of texture to attach.
            target:
                Specifies the framebuffer target. target must be GL_DRAW_FRAMEBUFFER,
                GL_READ_FRAMEBUFFER, or GL_FRAMEBUFFER. GL_FRAMEBUFFER is equivalent
                to GL_DRAW_FRAMEBUFFER.
            attachment:
                Specifies the attachment point of the framebuffer. attachment must be
                GL_COLOR_ATTACHMENTi, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT or
                GL_DEPTH_STENCIL_ATTACHMENT.
        N)
rG   r   rA   rh   r   r-   r8   r.   r9   rJ   )r;   r{   r   r~   rf   r|   s         r'   attach_texture_layerz Framebuffer.attach_texture_layer   sx    * 			!&*gj%OOO*,'-557>4<88r)   renderbufferr+   c                *   |                                   t          ||t          |j                   | xj        |z  c_        t          |j        | j                  | _        t          |j        | j	                  | _	        | 
                                 dS )a  Attach a Renderbuffer to the Framebuffer.

        Args:
            renderbuffer:
                Specifies the Renderbuffer to attach to the framebuffer attachment
                point named by attachment.
            target:
                Specifies the framebuffer target. target must be GL_DRAW_FRAMEBUFFER,
                GL_READ_FRAMEBUFFER, or GL_FRAMEBUFFER. GL_FRAMEBUFFER is equivalent
                to GL_DRAW_FRAMEBUFFER.
            attachment:
                Specifies the attachment point of the framebuffer. attachment must be
                GL_COLOR_ATTACHMENTi, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT or
                GL_DEPTH_STENCIL_ATTACHMENT.
        N)rG   r   r   rA   rh   r   r-   r8   r.   r9   rJ   )r;   r   rf   r|   s       r'   attach_renderbufferzFramebuffer.attach_renderbuffer   sx    " 			!&*o|WWW*,,,dk::<.==r)   c                :    | j         j         d| j        j         dS rU   rW   r@   s    r'   rZ   zFramebuffer.__repr__  r[   r)   N)rf   r#   r"   r1   r\   r]   )r"   rs   r^   )r{   r!   rf   r#   r|   r#   r"   r1   )r{   r!   r   r#   r~   r#   rf   r#   r|   r#   r"   r1   )r   r+   rf   r#   r|   r#   r"   r1   )rY   r_   r`   ra   r   r<   rb   rA   r-   r.   rG   rJ   ro   rL   rQ   ru   rc   rz   r   r   r   r   rZ   rI   r)   r'   re   re   i   s         &4         X    X    X1 1 1 1* * * *      
    S S S XS 6 6 6 \6* &4G[    2 ,:Ma    : +9L`    0A A A A A Ar)   re   r\   )(ra   
__future__r   r3   	pyglet.glr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr    pyglet.imager!   r(   r+   re   rI   r)   r'   <module>r      s   * # " " " " "  m m m m m m m m m m m m m m m m r r r r r r r r r r r r e e e e e e e e e e e e M M M M M M M M U U U U U U U U U U c c c c c c c c c c e e e e e e e e i i i i i i i i W W W W W W W W             %$$$$$$   5A 5A 5A 5A 5A 5A 5A 5ApiA iA iA iA iA iA iA iA iA iAr)   