
    ^j                    h   d Z ddlmZ ddlZddlmZmZmZmZm	Z	 ddl
mZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z  ddl!m"Z"m#Z#m$Z$ ddl%m&Z&m'Z' e	e         Z(eZ)erdd	l*m+Z+ dd
l,m-Z- ddl.m/Z/ d%dZ0eej1        eej2        eej3        eej4        eej5        eej6        eej7        eej8        iZ9eeeeeeeedZ:d&dZ; G d d          Z< G d de<          Z= G d d          Z> G d d          Z?d&dZ@d&dZA G d d e?          ZB G d! d"e?          ZC G d# d$eCeB          ZDdS )'aF  Manage related vertex attributes within a single vertex domain.

A vertex "domain" consists of a set of attribute descriptions that together
describe the layout of one or more vertex buffers which are used together to
specify the vertices in a primitive.  Additionally, the domain manages the
buffers used to store the data and will resize them as necessary to accommodate
new vertices.

Domains can optionally be indexed, in which case they also manage a buffer
containing vertex indices.  This buffer is grown separately and has no size
relation to the attribute buffers.

Applications can create vertices (and optionally, indices) within a domain
with the :py:meth:`VertexDomain.create` method.  This returns a
:py:class:`VertexList` representing the list of vertices created.  The vertex
attribute data within the group can be modified, and the changes will be made
to the underlying buffers automatically.

The entire domain can be efficiently drawn in one step with the
:py:meth:`VertexDomain.draw` method, assuming all the vertices comprise
primitives of the same OpenGL primitive mode.
    )annotationsN)TYPE_CHECKINGAnyNoReturnSequenceType)Array_Pointer_SimpleCData)GL_BYTE	GL_DOUBLEGL_FLOATGL_INTGL_SHORTGL_UNSIGNED_BYTEGL_UNSIGNED_INTGL_UNSIGNED_SHORTGLintGLintptrGLsizeiGLvoidglDrawArraysglDrawArraysInstancedglDrawElementsglDrawElementsInstancedglMultiDrawArraysglMultiDrawElements)
allocationshadervertexarray)AttributeBufferObjectIndexedBufferObject)	Allocator)	Attribute)VertexArrayvintreturnc                f    | dz  } | | dz	  z  } | | dz	  z  } | | dz	  z  } | | dz	  z  } | | dz	  z  } | dz   S )N                )r&   s    W/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/graphics/vertexdomain.py_nearest_pow2r1   >   sW     FAaKAaKAaKAaKAbLAq5L    )bBhHiIfdnamestrpropertyc                <     d
 fd}d fd	}t          ||          S )Nself
VertexListr(   Array[float | int]c                    | j         j                 }|                    | j        | j                  }|                    | j        | j                   |S N)domainattrib_name_buffers
get_regionstartcountinvalidate_regionr?   bufferregionr;   s      r0   _attribute_getterz3_make_attribute_property.<locals>._attribute_getterb   sJ    06""4:tz::  TZ888r2   datar   Nonec                n    | j         j                 }|                    | j        | j        |           d S rC   )rD   rE   
set_regionrG   rH   r?   rN   rK   r;   s      r0   _attribute_setterz3_make_attribute_property.<locals>._attribute_setterh   s4    06$*dj$77777r2   )r?   r@   r(   rA   )r?   r@   rN   r   r(   rO   r=   r;   rM   rS   s   `  r0   _make_attribute_propertyrV   a   sS         8 8 8 8 8 8 %'8999r2   c                      e Zd ZU dZded<   ded<   ded<   dZded	<   dZded
<   ded<   d'dZd(dZd)d*dZ	d+dZ
d,dZd-dZd.d!Zd/d$Zd0d&ZdS )1r@   zzA list of vertices within a :py:class:`VertexDomain`.

    Use :py:meth:`VertexDomain.create` to construct this list.
    r'   rH   rG   $VertexDomain | InstancedVertexDomainrD   Fboolindexed	instanceddictinitial_attribsVertexDomainr(   rO   c                H    || _         || _        || _        |j        | _        d S rC   )rD   rG   rH   attribute_metar]   )r?   rD   rG   rH   s       r0   __init__zVertexList.__init__{   s(    

%4r2   modec                <    | j                             ||            dS )zDraw this vertex list in the given OpenGL mode.

        Args:
            mode:
                OpenGL drawing mode, e.g. ``GL_POINTS``, ``GL_LINES``, etc.
        N)rD   draw_subset)r?   rb   s     r0   drawzVertexList.draw   s"     	d+++++r2   Nindex_count
int | Nonec                >   | j                             | j        | j        |          }|| j        k    r]| j         j                                        D ]>}|                    | j        | j                  }|                    || j        |           ?|| _        || _        dS )zResize this group.

        Args:
            count:
                New number of vertices in the list.
            index_count:
                Ignored for non indexed VertexDomains

        N)rD   safe_reallocrG   rH   rE   valuesrF   rQ   )r?   rH   rf   	new_startrK   old_datas         r0   resizezVertexList.resize   s     K,,TZUKK	
""+9@@BB C C!,,TZDD!!)TZBBBB



r2   c                Z    | j         j                            | j        | j                   dS zDelete this group.N)rD   	allocatordeallocrG   rH   r?   s    r0   deletezVertexList.delete   s'    %%dj$*=====r2   InstancedVertexDomaininstance_attributesSequence[str]c                   | j         du s
J d            t          |j                                                  t          | j        j                                                  k    s
J d            |                    | j                  }| j        j                                        D ]s\  }}|j        |         }|	                    | j
        | j                  }||v r|j        |         }d}	|d |j                 }n| j        }	|                    ||	|           t| j        j                            | j
        | j                   || _        || _
        d| _         d S )NFz#Vertex list is already an instance.Domain attributes must match.r*   T)r[   listattribute_nameskeysrD   
safe_allocrH   rE   itemsrF   rG   rQ   rp   rq   )
r?   rD   ru   rk   keycurrent_buffer
new_bufferrl   attribrH   s
             r0   set_instance_sourcezVertexList.set_instance_source   sW   ~&&&(M&&&F*//1122d4;;V;[;[;];]6^6^^^^+ _^^ %%dj11	#';#B#H#H#J#J 		> 		>C3C8J%00TZHHH)))/4#MV\M2
!!)UH====%%dj$*===
r2   c                >   t          |j                                                  t          | j        j                                                  k    s
J d            |                    | j                  }| j        j                                        D ]N\  }}|j        |         }|                    | j	        | j                  }|
                    || j        |           O| j        j                            | j	        | j                   || _        || _	        dS )a  Move this group from its current domain and add to the specified one.

        Attributes on domains must match.
        (In practice, used to change parent state of some vertices).

        Args:
            domain:
                Domain to migrate this vertex list to.

        rx   N)ry   rz   r{   rD   r|   rH   rE   r}   rF   rG   rQ   rp   rq   )r?   rD   rk   r;   
old_bufferr   rl   s          r0   migratezVertexList.migrate   s    F*//1122d4;;V;[;[;];]6^6^^^^+ _^^ %%dj11	 $ ? E E G G 	C 	CD*3D9J!,,TZDDH!!)TZBBBB%%dj$*===


r2   r;   r<   rN   r   c           	     4   | j         j        |         }| j        }|j        | j        z  }|j        |z  |z   }	 ||j        ||<   |                    | j        |           d S # t          $ r- d| d||z
   dt          |           d}t          |          d w xY w)NzInvalid data size for 'z'. Expected z, got .)rD   rE   rH   rG   rN   rI   
ValueErrorlen)r?   r;   rN   rK   rH   array_start	array_endmsgs           r0   set_attribute_datazVertexList.set_attribute_data   s    06
lTZ/L5(;6		,15FKI-.$$TZ77777 	, 	, 	,iDiii+>Uii]`ae]f]fiiiCS//t+	,s   'A   7BkwargsVertexInstancec                t   | j         sJ | j        xj        dz  c_        | j        j        }| j                            d          }| j        j        D ]L\  }}|j        r@|j        |v sJ |j         d            |                    |dz
  d||j                            M| j                            | ||          S )Nr*      zA is defined as an instance attribute, keyword argument not found.)	r[   rD   
_instancessafe_alloc_instancebuffer_attributesinstancer;   rQ   _vertexinstance_class)r?   r   instance_idrG   rK   	attributes         r0   add_instancezVertexList.add_instance   s    ~~!#k,//22!%!> 	N 	NFI! N ~///Y^ 3Q 3Q 3Q///!!+/1fY^6LMMM{00{EJJJr2   r   c                    | j         sJ |j        | j        j        k    rd}t	          |          | j        xj        dz  c_        | j        j                            |j        d           d S )Nz,Only the last instance added can be removed.r*   r   )r[   idrD   r   	Exceptioninstance_allocatorrq   rG   )r?   r   r   s      r0   delete_instancezVertexList.delete_instance   sk    ~~;$+000@CC.. !#&..x~qAAAAAr2   )rD   r^   rG   r'   rH   r'   r(   rO   rb   r'   r(   rO   rC   )rH   r'   rf   rg   r(   rO   r(   rO   )rD   rt   ru   rv   r(   rO   )rD   rX   r(   rO   )r;   r<   rN   r   r(   rO   )r   r   r(   r   )r   r   r(   rO   )__name__
__module____qualname____doc____annotations__rZ   r[   ra   re   rm   rs   r   r   r   r   r   r/   r2   r0   r@   r@   o   s1          JJJJJJ0000GI5 5 5 5, , , ,    &> > > >   ,   0, , , ,K K K K B B B B B Br2   r@   c                       e Zd ZU dZded<   dZded<   ded<   ded	<   d fdZd fdZd fdZd fdZ	e
dd            Zej        dd            Z xZS ) IndexedVertexListzA list of vertices within an :py:class:`IndexedVertexDomain` that are indexed.

    Use :py:meth:`IndexedVertexDomain.create` to construct this list.
    2IndexedVertexDomain | InstancedIndexedVertexDomainrD   TrY   rZ   r'   rf   index_startIndexedVertexDomainrG   rH   r(   rO   c                j    t                                          |||           || _        || _        d S rC   )superra   r   rf   )r?   rD   rG   rH   r   rf   	__class__s         r0   ra   zIndexedVertexList.__init__  s5    ...&&r2   c                    t                                                       | j        j                            | j        | j                   dS ro   )r   rs   rD   index_allocatorrq   r   rf   )r?   r   s    r0   rs   zIndexedVertexList.delete  s>    #++D,<d>NOOOOOr2   c                l   | j         }| j        }t                                          |           || j         k    ra| j         |z
  |j                            | j        | j                  }|j                            | j        | j        fd|D                        |j                            | j        | j                  }|j	        
                    | j        | j                   | j                            | j                  }| j        j                            || j        |           || _        dS )a)  Move this group from its current indexed domain and add to the specified one.

        Attributes on domains must match.  (In practice, used
        to change parent state of some vertices).

        Args:
            domain:
                Indexed domain to migrate this vertex list to.
        c                    g | ]}|z   S r/   r/   .0r7   diffs     r0   
<listcomp>z-IndexedVertexList.migrate.<locals>.<listcomp>   !    SrSrSrabTUX\T\SrSrSrr2   N)rG   rD   r   r   index_bufferrF   r   rf   rQ   r   rq   safe_index_alloc)	r?   rD   	old_start
old_domainold_indices	old_arrayrk   r   r   s	          @r0   r   zIndexedVertexList.migrate  s!    J	[
 
"":	)D$1<<T=MtO_``K#..t/?AQSrSrSrSrfqSrSrSrsss +66t7GIYZZ	 	"**4+;T=MNNNK001ABB	 ++It7GSSS$r2   ru   rv   c                N   | j         du s
J d            | j        }| j        }t                                          ||           t          |j                                                  t          | j        j                                                  k    s
J d            || j        k    ra| j        |z
  |j        	                    | j
        | j                  }|j                            | j
        | j        fd|D                        |j        	                    | j
        | j                  }|j                            | j
        | j                   | j                            | j                  }| j        j                            || j        |           || _
        d S )NFz)IndexedVertexList is already an instance.rx   c                    g | ]}|z   S r/   r/   r   s     r0   r   z9IndexedVertexList.set_instance_source.<locals>.<listcomp><  r   r2   )r[   rG   rD   r   r   ry   rz   r{   r   rF   r   rf   rQ   r   rq   r   )
r?   rD   ru   r   r   r   r   rk   r   r   s
           @r0   r   z%IndexedVertexList.set_instance_source-  s   ~&&&(S&&&J	[
##F,?@@@F*//1122d4;;V;[;[;];]6^6^^^^+ _^^
 
"":	)D$1<<T=MtO_``K#..t/?AQSrSrSrSrfqSrSrSrsss +66t7GIYZZ	 	"**4+;T=MNNNK001ABB	 ++It7GSSS$r2   	list[int]c                ~    | j         fd| j        j                            | j        | j                  D             S )zArray of index data.c                    g | ]}|z
  S r/   r/   r   r7   rG   s     r0   r   z-IndexedVertexList.indices.<locals>.<listcomp>M  s    kkkaE	kkkr2   )rG   rD   r   rF   r   rf   )r?   rG   s    @r0   indiceszIndexedVertexList.indicesI  sB     
kkkk4;#;#F#FtGWY]Yi#j#jkkkkr2   rN   Sequence[int]c                    | j         | j        j                            | j        | j        t          fd|D                                  d S )Nc              3  "   K   | ]	}|z   V  
d S rC   r/   r   s     r0   	<genexpr>z,IndexedVertexList.indices.<locals>.<genexpr>T  s+      UnUndeVWZ_V_UnUnUnUnUnUnr2   )rG   rD   r   rQ   r   rf   tuple)r?   rN   rG   s     @r0   r   zIndexedVertexList.indicesO  sT    
 	 ++D,<d>NPUUnUnUnUnimUnUnUnPnPnooooor2   )rD   r   rG   r'   rH   r'   r   r'   rf   r'   r(   rO   r   )rD   r   r(   rO   )rD   r   ru   rv   r(   rO   )r(   r   )rN   r   r(   rO   )r   r   r   r   r   rZ   ra   rs   r   r   r=   r   setter__classcell__r   s   @r0   r   r      s/          ?>>>G' ' ' ' ' 'P P P P P P
% % % % % %@% % % % % %8 l l l Xl
 ^p p p ^p p p p pr2   r   c                  V    e Zd ZU ded<   ded<   ded<   dd
Zedd            ZddZdS )r   r'   r   rG   VertexList | IndexedVertexList_vertex_listvertex_listr   r(   rO   c                0    || _         || _        || _        d S rC   )r   rG   r   )r?   r   r   rG   s       r0   ra   zVertexInstance.__init__\  s    
'r2   4InstancedVertexDomain | InstancedIndexedVertexDomainc                    | j         j        S rC   )r   rD   rr   s    r0   rD   zVertexInstance.domaina  s     ''r2   c                H    | j                             |            d | _         d S rC   )r   r   rr   s    r0   rs   zVertexInstance.deletee  s'    ))$/// r2   N)r   r   r   r'   rG   r'   r(   rO   )r(   r   r   )r   r   r   r   ra   r=   rD   rs   r/   r2   r0   r   r   W  s|         GGGJJJ0000( ( ( (
 ( ( ( X(! ! ! ! ! !r2   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Zded<   eZded<   d,dZd-dZ	d.dZ
d/d0d#Zd1d%Zd2d'Zed3d)            Zd4d+ZdS )5r^   zManagement of a set of vertex lists.

    Construction of a vertex domain is usually done with the
    :py:func:`create_domain` function.
    dict[str, dict[str, Any]]r`   r#   rp   z-list[tuple[AttributeBufferObject, Attribute]]r   r%   vaozdict[str, Attribute]rz   z dict[str, AttributeBufferObject]rE   dict[str, property]_property_dicttype_vertexlist_classr.   r'   _initial_countztype[VertexList]_vertex_classr(   rO   c           	     V   || _         t          j        | j                  | _        t          j                    | _        i | _        g | _	        i | _
        i | _        |                                D ]\  }}|d         d         t          v sJ d|d          d| d            |d         }|d         }t          |d         d                  }d|d         v }|d	         }t          j        ||||||          x| j        |<   }	t!          |	j        | j        j        z  |	          x| j
        |<   }
| j	                            |
|	f           t)          |          | j        |	j        <   t-          | j        j        | j        f| j                  | _        | j                                         | j	        D ]b\  }
}	|
                                 |	                                 |	                    |
j                   |	j        r|	                                 c| j                                          d S )
Nformatr   'z'' is not a valid attribute format for 'z'.locationrH   nr   )!r`   r   r#   r   rp   r    r%   r   rz   r   rE   r   r}   	_gl_typesr   r$   r!   stridecapacityappendrV   r;   r   r   r   r   bindenableset_pointerptrr   set_divisorunbind)r?   r`   r;   metar   rH   gl_type	normalizer[   r   rK   s              r0   ra   zVertexDomain.__init__~  sG   ,#-d.ABB*,,!!##%  (..00 	Q 	QJD$>!$	1113vtH~3v3vnr3v3v3v111J'HMEXq 12GtH~-IZ(I5;5EdHV[]dfoFO6Q 6Q QD & 7LIL\_c_m_vLvLU7W 7W WD$T*V
 "))69*=>>> 3K42P2PD	// "&d&8&ADDVCXZ^Zm!n!n!%!7 	( 	(FIKKMMM!!&*---! (%%'''r2   rH   c                T   	 | j                             |          S # t          j        $ r|}t	          |j                  }| j        D ]"\  }}|                    ||j        z             #| j         	                    |           | j                             |          cY d}~S d}~ww xY wz5Allocate vertices, resizing the buffers if necessary.N
rp   allocr   AllocatorMemoryExceptionr1   requested_capacityr   rm   r   set_capacityr?   rH   er   rK   _s         r0   r|   zVertexDomain.safe_alloc      	/>''...2 	/ 	/ 	/$Q%9::H!3 8 8	h67777N''111>''........	/    B'A1B"B'"B'rG   	new_countc                \   	 | j                             |||          S # t          j        $ r~}t	          |j                  }| j        D ]"\  }}|                    ||j        z             #| j         	                    |           | j                             |||          cY d}~S d}~ww xY wz7Reallocate vertices, resizing the buffers if necessary.N
rp   reallocr   r   r1   r   r   rm   r   r   r?   rG   rH   r   r   r   rK   r   s           r0   ri   zVertexDomain.safe_realloc      	C>))%	BBB2 	C 	C 	C$Q%9::H!3 8 8	h67777N''111>))%	BBBBBBBB	C    B+A3B& B+&B+Nrf   rg   r@   c                Z    |                      |          }|                     | ||          S )zCreate a :py:class:`VertexList` in this domain.

        Args:
            count:
                Number of vertices to create.
            index_count:
                Ignored for non indexed VertexDomains
        )r|   r   )r?   rH   rf   rG   s       r0   createzVertexDomain.create  s-     &&%%dE5999r2   rb   c                ~   | j                                          | j        D ]\  }}|                                 | j                                        \  }}t          |          }|dk    rdS |dk    rt          ||d         |d                    dS t          |z  | }t          |z  | }t          ||||           dS )  Draw all vertices in the domain.

        All vertices in the domain are drawn at once. This is the
        most efficient way to render primitives.

        Args:
            mode:
                OpenGL drawing mode, e.g. ``GL_POINTS``, ``GL_LINES``, etc.

        r   r*   N)r   r   r   commitrp   get_allocated_regionsr   r   r   r   r   r?   rb   rK   r   startssizes	primcounts          r0   re   zVertexDomain.draw  s     	/ 	 	IFAMMOOOO<<>>KK	>>D!^^vay%(33333i'&1Fy(51EdFE9=====r2   r   c                    | j                                          | j        D ]\  }}|                                 t	          ||j        |j                   dS )ac  Draw a specific VertexList in the domain.

        The `vertex_list` parameter specifies a :py:class:`VertexList`
        to draw. Only primitives in that list will be drawn.

        Args:
            mode:
                OpenGL drawing mode, e.g. ``GL_POINTS``, ``GL_LINES``, etc.
            vertex_list:
                Vertex list to draw.

        N)r   r   r   r  r   rG   rH   r?   rb   r   rK   r   s        r0   rd   zVertexDomain.draw_subset  sV     	/ 	 	IFAMMOOOOT;,k.?@@@@@r2   rY   c                    | j         j         S rC   rp   r
  rr   s    r0   is_emptyzVertexDomain.is_empty      >(((r2   r<   c                T    d| j         j         dt          |           dd| j         dS )N<@x >)r   r   r   rp   rr   s    r0   __repr__zVertexDomain.__repr__  s3    K4>*KKRXXKKK$.KKKKr2   r`   r   r(   rO   rH   r'   r(   r'   rG   r'   rH   r'   r   r'   r(   r'   rC   )rH   r'   rf   rg   r(   r@   r   rb   r'   r   r@   r(   rO   r(   rY   )r(   r<   )r   r   r   r   r   r   r@   r   ra   r|   ri   r  re   rd   r=   r  r  r/   r2   r0   r^   r^   j  sd          .---DDDD))))9999''''N&0M0000+ + + +Z	/ 	/ 	/ 	/	C 	C 	C 	C
: 
: 
: 
: 
:> > > >6A A A A& ) ) ) X)L L L L L Lr2   r^   c                <     d
 fd}d fd	}t          ||          S )Nr?   r   r(   Array[CTypesDataType]c                    | j         j                 }|                    | j        dz
  d          }|                    | j        dz
  d           |S Nr*   )rD   rE   rF   r   rI   rJ   s      r0   rM   z<_make_instance_attribute_property.<locals>._attribute_getter  sN    06""47Q;22  1a000r2   rN   r   rO   c                j    | j         j                 }|                    | j        dz
  d|           d S r"  )rD   rE   rQ   r   rR   s      r0   rS   z<_make_instance_attribute_property.<locals>._attribute_setter
  s6    06$'A+q$/////r2   r?   r   r(   r   )r?   r   rN   r   r(   rO   rT   rU   s   `  r0   !_make_instance_attribute_propertyr%    sS         0 0 0 0 0 0 %'8999r2   c                <     d fd}d fd
}t          ||          S )Nr?   r   r(   r   c                d    | j         j                 }|                    | j        dz
  d          S r"  )rD   rE   rF   r   )r?   rK   r;   s     r0   rM   zG_make_restricted_instance_attribute_property.<locals>._attribute_getter  s.    06  1a000r2   _self_datar   r   c                .    d d}t          |          )NzAttribute 'z ' is not an instanced attribute.)r   )r(  r)  r   r;   s      r0   rS   zG_make_restricted_instance_attribute_property.<locals>._attribute_setter  s    BDBBBnnr2   r$  )r(  r   r)  r   r(   r   rT   rU   s   `  r0   ,_make_restricted_instance_attribute_propertyr+    sS    1 1 1 1 1 1      %'8999r2   c                       e Zd ZU ded<   ded<   ded<   ded<   d fdZddZddZddZddZddZ	e
d d            Z xZS )!rt   r#   r   r'   r   r   _instance_propertiesr   r   r`   r   r(   rO   c                   t                                          |           d| _        t          j        | j                  | _        i | _        | j        	                                D ];\  }}|j
        rt          |          | j        |<   $t          |          | j        |<   <t          dt          f| j                  | _        d S )Nr*   r   )r   ra   r   r   r#   r   r   r-  rz   r}   r   r%  r+  r   r   r   )r?   r`   r;   r   r   s       r0   ra   zInstancedVertexDomain.__init__#  s    (((","6t7J"K"K$&!#399;; 	e 	eOD)! e2STX2Y2Y)$//2^_c2d2d)$//%)*:^<MtOh%i%i"""r2   rH   c                b   	 | j                             |          S # t          j        $ r}t	          |j                  }| j        D ])\  }}|j        r|                    ||j	        z             *| j         
                    |           | j                             |          cY d }~S d }~ww xY wrC   )r   r   r   r   r1   r   r   r   rm   r   r   )r?   rH   r   r   rK   r   s         r0   r   z)InstancedVertexDomain.safe_alloc_instance1  s    	8*007772 	8 	8 	8$Q%9::H%)%; < <!	% <MM(V]":;;;#00:::*0077777777	8s    B.A8B)#B.)B.c                T   	 | j                             |          S # t          j        $ r|}t	          |j                  }| j        D ]"\  }}|                    ||j        z             #| j         	                    |           | j                             |          cY d}~S d}~ww xY wr   r   r   s         r0   r|   z InstancedVertexDomain.safe_alloc<  r   r   rG   r   c                \   	 | j                             |||          S # t          j        $ r~}t	          |j                  }| j        D ]"\  }}|                    ||j        z             #| j         	                    |           | j                             |||          cY d}~S d}~ww xY wr   r   r   s           r0   ri   z"InstancedVertexDomain.safe_reallocG  r  r  rb   c                    | j                                          | j        D ]\  }}|                                 | j                                        \  }}t          ||d         |d         | j                   dS r  r   N)r   r   r   r  rp   r  r   r   r?   rb   rK   r   r
  r  s         r0   re   zInstancedVertexDomain.drawR  ss     	/ 	 	IFAMMOOOO<<>>dF1IuQxIIIIIr2   r   r@   c                    | j                                          | j        D ]\  }}|                                 t	          ||j        |j        | j                   dS )ab  Draw a specific VertexList in the domain.

        The `vertex_list` parameter specifies a :py:class:`VertexList`
        to draw. Only primitives in that list will be drawn.

        Args:
            mode:
                OpenGL drawing mode, e.g. ``GL_POINTS``, ``GL_LINES``, etc.
            vertex_list:
                Vertex list to draw.
        N)r   r   r   r  r   rG   rH   r   r  s        r0   rd   z!InstancedVertexDomain.draw_subsetd  sZ     	/ 	 	IFAMMOOOOdK$5{7H$/ZZZZZr2   rY   c                    | j         j         S rC   r  rr   s    r0   r  zInstancedVertexDomain.is_emptyv  r  r2   r  r  r  r   r  r  )r   r   r   r   ra   r   r|   ri   re   rd   r=   r  r   r   s   @r0   rt   rt     s        !!!!OOO----j j j j j j	8 	8 	8 	8	/ 	/ 	/ 	/	C 	C 	C 	CJ J J J$[ [ [ [$ ) ) ) X) ) ) ) )r2   rt   c                       e Zd ZU dZded<   ded<   ded<   ded<   d	ed
<   dZeZefd fdZ	ddZ
ddZd dZd!dZd"dZ xZS )#r   Management of a set of indexed vertex lists.

    Construction of an indexed vertex domain is usually done with the
    :py:func:`create_domain` function.
    r#   r   r'   index_gl_typeCTypesDataTypeindex_c_typeindex_element_sizer"   r   r.   r`   r   r(   rO   c                f   t                                          |           t          j        | j                  | _        || _        t          j        |         | _	        t          j        | j	                  | _        t          | j        j        | j        z  t          j        |         | j        d          | _        | j                                         | j                                         | j                                         t)          | j        j        | j        f| j                  | _        d S r"  )r   ra   r   r#   _initial_index_countr   r9  r   _c_typesr;  ctypessizeofr<  r"   r   r   r   r   bind_to_index_bufferr   r   r   r   r   r   r?   r`   r9  r   s      r0   ra   zIndexedVertexDomain.__init__  s    ((()3D4MNN*"OM:"(-0A"B"B/0D0MPTPg0g060N040G013 3
 	..000 "&d&8&ADDVCX&*&9"; ";r2   rH   c                D   	 | j                             |          S # t          j        $ rt}t	          |j                  }| j                            || j        z             | j         	                    |           | j                             |          cY d}~S d}~ww xY w)z4Allocate indices, resizing the buffers if necessary.N
r   r   r   r   r1   r   r   rm   r<  r   r?   rH   r   r   s       r0   r   z$IndexedVertexDomain.safe_index_alloc  s    	5'--e4442 	5 	5 	5$Q%9::H$$X0G%GHHH --h777'--e44444444		5    BA)BBBrG   r   c                L   	 | j                             |||          S # t          j        $ rv}t	          |j                  }| j                            || j        z             | j         	                    |           | j                             |||          cY d}~S d}~ww xY wz6Reallocate indices, resizing the buffers if necessary.N
r   r   r   r   r1   r   r   rm   r<  r   r?   rG   rH   r   r   r   s         r0   safe_index_reallocz&IndexedVertexDomain.safe_index_realloc      	I'//uiHHH2 	I 	I 	I$Q%9::H$$X0G%GHHH --h777'//uiHHHHHHHH		I    B#A+BB#B#rf   r   c                    |                      |          }|                     |          }|                     | ||||          S zCreate an :py:class:`IndexedVertexList` in this domain.

        Args:
            count:
                Number of vertices to create
            index_count:
                Number of indices to create

        r|   r   r   r?   rH   rf   rG   r   s        r0   r  zIndexedVertexDomain.create  D     &&++K88%%dE5+{SSSr2   rb   c                J     j                                           j        D ]\  }}|                                  j                                          j                                        \  }}t          |          }|dk    rdS |dk    r:t          ||d          j	         j        j
        |d          j        z  z              dS  fd|D             } t          j        t                    |z  t          |z  |  }t!          |z  | }t#          || j	        ||           dS )r  r   r*   c                >    g | ]}|j         z  j        j        z   S r/   )r<  r   r   )r   sr?   s     r0   r   z,IndexedVertexDomain.draw.<locals>.<listcomp>  s,    ZZZaa$11D4E4IIZZZr2   N)r   r   r   r  r   r   r  r   r   r9  r   r<  r@  POINTERr   r   r   r   r	  s   `      r0   re   zIndexedVertexDomain.draw  sA    	/ 	 	IFAMMOOOO  """,BBDDKK	>>D!^^4q4+=,06!9t?V3VVX X X X X [ZZZSYZZZF8fnV,,y8Hy<PSY;Z[Fy(51EeT-?SSSSSr2   r   c                   | j                                          | j        D ]\  }}|                                 | j                                         t          ||j        | j        | j        j        |j	        | j
        z  z              dS )ap  Draw a specific IndexedVertexList in the domain.

        The `vertex_list` parameter specifies a :py:class:`IndexedVertexList`
        to draw. Only primitives in that list will be drawn.

        Args:
            mode:
                OpenGL drawing mode, e.g. ``GL_POINTS``, ``GL_LINES``, etc.
            vertex_list:
                Vertex list to draw.
        N)r   r   r   r  r   r   rf   r9  r   r   r<  r  s        r0   rd   zIndexedVertexDomain.draw_subset  s     	/ 	 	IFAMMOOOO  """t[4d6H(,".1HHI	J 	J 	J 	J 	Jr2   r`   r   r9  r'   r(   rO   r  r  rH   r'   rf   r'   r(   r   r   rb   r'   r   r   r(   rO   )r   r   r   r   r   r>  r   r   r   ra   r   rL  r  re   rd   r   r   s   @r0   r   r   {  s         
     %%%%%M '6; ; ; ; ; ; ;,5 5 5 5I I I IT T T TT T T T>J J J J J J J Jr2   r   c                  `     e Zd ZU dZdZded<   efd fd
ZddZddZ	ddZ
ddZddZ xZS )InstancedIndexedVertexDomainr8  r.   r'   r>  r`   r   r9  r(   rO   c                L    t                                          ||           d S rC   )r   ra   rC  s      r0   ra   z%InstancedIndexedVertexDomain.__init__  s#    77777r2   rH   c                D   	 | j                             |          S # t          j        $ rt}t	          |j                  }| j                            || j        z             | j         	                    |           | j                             |          cY d}~S d}~ww xY w)zAllocate indices, resizing the buffers if necessary.

        Returns:
            The starting index of the allocated region.
        NrE  rF  s       r0   r   z-InstancedIndexedVertexDomain.safe_index_alloc  s    	5'--e4442 	5 	5 	5$Q%9::H$$X0G%GHHH --h777'--e44444444		5rG  rG   r   c                L   	 | j                             |||          S # t          j        $ rv}t	          |j                  }| j                            || j        z             | j         	                    |           | j                             |||          cY d}~S d}~ww xY wrI  rJ  rK  s         r0   rL  z/InstancedIndexedVertexDomain.safe_index_realloc  rM  rN  rf   r   c                    |                      |          }|                     |          }|                     | ||||          S rP  rQ  rR  s        r0   r  z#InstancedIndexedVertexDomain.create  rS  r2   rb   c                .   | j                                          | j        D ]\  }}|                                 | j                                        \  }}t          ||d         | j        | j        j	        |d         | j
        z  z   | j                   dS r3  )r   r   r   r  r   r  r   r9  r   r   r<  r   r4  s         r0   re   z!InstancedIndexedVertexDomain.draw)  s     	/ 	 	IFAMMOOOO,BBDDeAh0B $ 1 5q	DD[8[ []a]l	n 	n 	n 	n 	nr2   r   c                    | j                                          | j        D ]\  }}|                                 t	          ||j        | j        | j        j        |j	        | j
        z  z   | j                   dS )as  Draw a specific IndexedVertexList in the domain.

        The ``vertex_list`` parameter specifies a :py:class:`IndexedVertexList`
        to draw. Only primitives in that list will be drawn.

        Args:
            mode:
                OpenGL drawing mode, e.g. ``GL_POINTS``, ``GL_LINES``, etc.
            vertex_list:
                Vertex list to draw.

        N)r   r   r   r  r   rf   r9  r   r   r   r<  r   r  s        r0   rd   z(InstancedIndexedVertexDomain.draw_subset<  s     	/ 	 	IFAMMOOOOk&=t?Q $ 1 5 + 7$:Q Q!RSWSb	d 	d 	d 	d 	dr2   rY  r  r  rZ  r   r[  )r   r   r   r   r>  r   r   ra   r   rL  r  re   rd   r   r   s   @r0   r]  r]    s          
 !#"""" '68 8 8 8 8 8 85 5 5 5I I I IT T T Tn n n n&d d d d d d d dr2   r]  )r&   r'   r(   r'   )r;   r<   r(   r=   )Er   
__future__r   r@  typingr   r   r   r   r   _ctypesr	   r
   r   pyglet.gl.glr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   pyglet.graphicsr   r   r    pyglet.graphics.vertexbufferr!   r"   r:  CTypesPointerpyglet.graphics.allocationr#   pyglet.graphics.shaderr$   pyglet.graphics.vertexarrayr%   r1   c_bytec_ubytec_shortc_ushortc_intc_uintc_floatc_doubler?  r   rV   r@   r   r   r^   r%  r+  rt   r   r]  r/   r2   r0   <module>rv     s   , # " " " " "  ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1 1 1 1 1 1 1 1 1 1                                       ( < ; ; ; ; ; ; ; ; ; S S S S S S S Sl# 8444444000000777777	 	 	 	 V]fnfnv
FLV]fnv	 
								 		: : : :EB EB EB EB EB EB EB EBP]p ]p ]p ]p ]p
 ]p ]p ]p@! ! ! ! ! ! ! !&VL VL VL VL VL VL VL VLr: : : :	: 	: 	: 	:[) [) [) [) [)L [) [) [)|yJ yJ yJ yJ yJ, yJ yJ yJxXd Xd Xd Xd Xd#68M Xd Xd Xd Xd Xdr2   