
    \
jC                     *   d Z ddlZddlZddlT ddlmZ eej        eej	        e
ej        eej        eej        eej        eej        eej        iZeee
eeeeedZ ej        dej                  Zi Zd Zd Zd	 Zd
 Z G d d          Z  G d de           Z! G d de           Z" G d de           Z# G d de           Z$ G d de           Z% G d de           Z& G d de           Z' G d de           Z( G d de           Z)e!e"e#e$e%e&e(dZ*dS ) a
  Access byte arrays as arrays of vertex attributes.

Use :py:func:`create_attribute` to create an attribute accessor given a
simple format string.  Alternatively, the classes may be constructed directly.

Attribute format strings
========================

An attribute format string specifies the format of a vertex attribute.  Format
strings are accepted by the :py:func:`create_attribute` function as well as most
methods in the :py:mod:`pyglet.graphics` module.

Format strings have the following (BNF) syntax::

    attribute ::= ( name | index 'g' 'n'? | texture 't' ) count type

``name`` describes the vertex attribute, and is one of the following
constants for the predefined attributes:

``c``
    Vertex color
``e``
    Edge flag
``f``
    Fog coordinate
``n``
    Normal vector
``s``
    Secondary color
``t``
    Texture coordinate
``v``
    Vertex coordinate

You can alternatively create a generic indexed vertex attribute by
specifying its index in decimal followed by the constant ``g``.  For
example, ``0g`` specifies the generic vertex attribute with index 0.
If the optional constant ``n`` is present after the ``g``, the
attribute is normalised to the range ``[0, 1]`` or ``[-1, 1]`` within
the range of the data type.

Texture coordinates for multiple texture units can be specified with the 
texture number before the constant 't'.  For example, ``1t`` gives the
texture coordinate attribute for texture unit 1.

``count`` gives the number of data components in the attribute.  For
example, a 3D vertex position has a count of 3.  Some attributes
constrain the possible counts that can be used; for example, a normal
vector must have a count of 3.

``type`` gives the data type of each component of the attribute.  The
following types can be used:

``b``
    ``GLbyte``
``B``
    ``GLubyte``
``s``
    ``GLshort``
``S``
    ``GLushort``
``i``
    ``GLint``
``I``
    ``GLuint``
``f``
    ``GLfloat``
``d``
    ``GLdouble``

Some attributes constrain the possible data types; for example,
normal vectors must use one of the signed data types.  The use of
some data types, while not illegal, may have severe performance
concerns.  For example, the use of ``GLdouble`` is discouraged,
and colours should be specified with ``GLubyte``.

Whitespace is prohibited within the format string.

Some examples follow:

``v3f``
    3-float vertex position
``c4b``
    4-byte colour
``1eb``
    Edge flag
``0g3f``
    3-float generic vertex attribute 0
``1gn1i``
    Integer generic vertex attribute 1, normalized to [-1, 1]
``2gn4B``
    4-byte generic vertex attribute 2, normalized to [0, 1] (because
    the type is unsigned)
``3t2f``
    2-float texture coordinate for texture unit 3.

    N)*)vertexbuffer)bBsSiIfdz
    (?P<name>
       [cefnstv] | 
       (?P<generic_index>[0-9]+) g (?P<generic_normalized>n?) |
       (?P<texcoord_texture>[0-9]+) t)
    (?P<count>[1234])
    (?P<type>[bBsSiIfd])
c                      | dz
  |dz
   z  |z   S )N    )valigns     Y/DATA/AppData/hermes/venv/lib/python3.11/site-packages/pyglet/graphics/vertexattribute.py_alignr      s    U	l"e++    c                     d}d}| D ]=}t          ||j                  }||_        ||j        z  }t	          ||j                  }>t          ||          }| D ]	}||_        
dS )a   Interleave attribute offsets.

    Adjusts the offsets and strides of the given attributes so that
    they are interleaved.  Alignment constraints are respected.

    :Parameters:
        `attributes` : sequence of `AbstractAttribute`
            Attributes to interleave in-place.

    r   N)r   r   offsetsizemaxstride)
attributesr   max_size	attributes       r   interleave_attributesr      s     FH 1 1		00!	). x00FH%%F " "	!	" "r   c                 f    d}|D ]+}t          ||j                  }||_        || |j        z  z  },dS )aQ  Serialize attribute offsets.
    
    Adjust the offsets of the given attributes so that they are
    packed serially against each other for `count` vertices.

    :Parameters:
        `count` : int
            Number of vertices.
        `attributes` : sequence of `AbstractAttribute`
            Attributes to serialize in-place.

    r   N)r   r   r   r   )countr   r   r   s       r   serialize_attributesr       sO     F + +		00!	%)***+ +r   c                    	 t           |          \  }} || S # t          $ r Y nw xY wt                              |           }|sJ d| z              t	          |                    d                    }t          |                    d                   }|                    d          }|                    d          }|r0|                    d          }t          }	t	          |          |||f}nl|rt          }	t	          |          ||f}nP|                    d          }
t          |
         }	|	j
        r#||	j
        k    sJ d|
|	j
        fz              |f}n||f}|	|ft           | <    |	| S )	a  Create a vertex attribute description from a format string.
    
    The initial stride and offset of the attribute will be 0.

    :Parameters:
        `format` : str
            Attribute format string.  See the module summary for details.

    :rtype: `AbstractAttribute`
    zInvalid attribute format %rr   typegeneric_indextexcoord_texturegeneric_normalizednamez+Attributes named "%s" must have count of %d)_attribute_cacheKeyError_attribute_format_rematchintgroup	_gl_typesGenericAttributeMultiTexCoordAttribute_attribute_classes_fixed_count)formatclsargsr*   r   gl_typer#   r$   
normalized
attr_classr&   s              r   create_attributer8      s   $V,	TsDz    !&&v..E88/&8885G$$%%EF++,GKK00M{{#566 $[[!566
%
=!!:ug=	 $+
#$$eW4{{6""'-
" 	$J3333=*1A3 3 433 :DD7#D)4/V:ts    
$$c                   4    e Zd ZdZdZd Zd Zd Zd Zd Z	dS )AbstractAttributez;Abstract accessor for an attribute in a mapped buffer.
    Nc                     |dv s
J d            || _         t          |         | _        || _        t	          j        | j                  | _        || j        z  | _        | j        | _        d| _	        dS )zCreate the attribute accessor.

        :Parameters:
            `count` : int
                Number of components in the attribute.
            `gl_type` : int
                OpenGL type enumerant; for example, ``GL_FLOAT``

        )r            zComponent count out of ranger   N)
r5   _c_typesc_typer   ctypessizeofr   r   r   r   )selfr   r5   s      r   __init__zAbstractAttribute.__init__  sm     $$$&D$$$w'
]4;//
DJ&	ir   c                      t          d          )z3Enable the attribute using ``glEnableClientState``.abstractNotImplementedErrorrC   s    r   enablezAbstractAttribute.enable#  s    !*---r   c                      t          d          )aP  Setup this attribute to point to the currently bound buffer at
        the given offset.

        ``offset`` should be based on the currently bound buffer's ``ptr``
        member.

        :Parameters:
            `offset` : int
                Pointer offset to the currently bound buffer for this
                attribute.

        rF   rG   )rC   r   s     r   set_pointerzAbstractAttribute.set_pointer'  s     "*---r   c                    | j         |z  }| j         |z  }| j        |z  }| j         | j        k    s|s3t          j        | j        |z            }|                    |||          S || j        z  }|| j        z  }| j         t          j        | j                  z  }| j        t          j        | j                  z  }	t          j        | j        ||z  |	z
  z            }|                    |||          }
t          j
        |
|| j        |          S )a  Map a buffer region using this attribute as an accessor.

        The returned region can be modified as if the buffer was a contiguous
        array of this attribute (though it may actually be interleaved or
        otherwise non-contiguous).

        The returned region consists of a contiguous array of component
        data elements.  For example, if this attribute uses 3 floats per
        vertex, and the `count` parameter is 4, the number of floats mapped
        will be ``3 * 4 = 12``.

        :Parameters:
            `buffer` : `AbstractMappable`
                The buffer to map.
            `start` : int
                Offset of the first vertex to map.
            `count` : int
                Number of vertices to map

        :rtype: `AbstractBufferRegion`
        )r   r   r   rA   POINTERr@   
get_regionr   rB   r   IndirectArrayRegion)rC   bufferstartr   
byte_start	byte_sizearray_countptr_typeelem_strideelem_offsetregions              r   rO   zAbstractAttribute.get_region6  s   , [5(
K%'	j5(;$)##;#~dkK&?@@H$$ZHEEE $+%J$I+t{)C)CCK+t{)C)CCK~u{2[@AC CH&&z9hGGF3TZ> > >r   c                     | j         | j        k    rD| j         |z  }| j         |z  }| j        |z  } | j        |z  | }|                    |||           dS |                     |||          }||dd<   dS )au  Set the data over a region of the buffer.

        :Parameters:
            `buffer` : AbstractMappable`
                The buffer to modify.
            `start` : int
                Offset of the first vertex to set.
            `count` : int
                Number of vertices to set.
            `data` : sequence
                Sequence of data components.

        N)r   r   r   r@   set_data_regionrO   )	rC   rQ   rR   r   datarS   rT   rU   rY   s	            r   
set_regionzAbstractAttribute.set_region_  s     ;$)##u,Je+I*u,K-DK+-5D""4Y????? __VUE::FF111IIIr   )
__name__
__module____qualname____doc__r1   rD   rJ   rL   rO   r]   r   r   r   r:   r:   
  sq          L  &. . .. . .'> '> '>R    r   r:   c                   2     e Zd ZdZdZ fdZd Zd Z xZS )ColorAttributezColor vertex attribute.colorsc                 v    |dv s
J d            t          t          |                               ||           d S )N)r=   r>   z*Color attributes must have count of 3 or 4)superrc   rD   rC   r   r5   	__class__s      r   rD   zColorAttribute.__init__  s=     Lnd##,,UG<<<<<r   c                 .    t          t                     d S N)glEnableClientStateGL_COLOR_ARRAYrI   s    r   rJ   zColorAttribute.enable  s    N+++++r   c                 X    t          | j        | j        | j        | j        |z              d S rj   )glColorPointerr   r5   r   r   rC   pointers     r   rL   zColorAttribute.set_pointer  s4    tz4<{W,	. 	. 	. 	. 	.r   	r^   r_   r`   ra   pluralrD   rJ   rL   __classcell__rh   s   @r   rc   rc   z  sa        !!F= = = = =, , ,. . . . . . .r   rc   c                   6     e Zd ZdZdZdZ fdZd Zd Z xZ	S )EdgeFlagAttributezEdge flag attribute.
edge_flagsr   c                     |t           t          t          fv s
J d            t          t          |                               d|           d S )Nz*Edge flag attribute must have boolean typer   )GL_BYTEGL_UNSIGNED_BYTEGL_BOOLrf   rv   rD   rC   r5   rh   s     r   rD   zEdgeFlagAttribute.__init__  sN    7$4g>>>>8 ?>>&&//7;;;;;r   c                 .    t          t                     d S rj   )rk   GL_EDGE_FLAG_ARRAYrI   s    r   rJ   zEdgeFlagAttribute.enable      ./////r   c                 @    t          | j        | j        |z              d S rj   )glEdgeFlagPointerr   r   ro   s     r   rL   zEdgeFlagAttribute.set_pointer  s!    $+t{W'<=====r   
r^   r_   r`   ra   rr   r1   rD   rJ   rL   rs   rt   s   @r   rv   rv     sf        FL< < < < <
0 0 0> > > > > > >r   rv   c                   2     e Zd ZdZdZ fdZd Zd Z xZS )FogCoordAttributezFog coordinate attribute.
fog_coordsc                 Z    t          t          |                               ||           d S rj   )rf   r   rD   rg   s      r   rD   zFogCoordAttribute.__init__  s*    &&//w?????r   c                 .    t          t                     d S rj   )rk   GL_FOG_COORD_ARRAYrI   s    r   rJ   zFogCoordAttribute.enable  r   r   c                 X    t          | j        | j        | j        | j        |z              d S rj   )glFogCoordPointerr   r5   r   r   ro   s     r   rL   zFogCoordAttribute.set_pointer  4    $*dlDK+/	1 	1 	1 	1 	1r   rq   rt   s   @r   r   r     sf        ##F@ @ @ @ @0 0 01 1 1 1 1 1 1r   r   c                   6     e Zd ZdZdZdZ fdZd Zd Z xZ	S )NormalAttributezNormal vector attribute.normalsr=   c                     |t           t          t          t          t          fv s
J d            t          t          |                               d|           d S )Nz&Normal attribute must have signed typer=   )ry   GL_SHORTGL_INTGL_FLOAT	GL_DOUBLErf   r   rD   r|   s     r   rD   zNormalAttribute.__init__  sQ    7Hfh	JJJJ4 KJJot$$--a99999r   c                 .    t          t                     d S rj   )rk   GL_NORMAL_ARRAYrI   s    r   rJ   zNormalAttribute.enable      O,,,,,r   c                 L    t          | j        | j        | j        |z              d S rj   )glNormalPointerr5   r   r   ro   s     r   rL   zNormalAttribute.set_pointer  s%    dk4;3HIIIIIr   r   rt   s   @r   r   r     sm        ""FL: : : : :
- - -J J J J J J Jr   r   c                   6     e Zd ZdZdZdZ fdZd Zd Z xZ	S )SecondaryColorAttributezSecondary color attribute.secondary_colorsr=   c                 Z    t          t          |                               d|           d S Nr=   )rf   r   rD   r|   s     r   rD   z SecondaryColorAttribute.__init__  s*    %t,,55aAAAAAr   c                 .    t          t                     d S rj   )rk   GL_SECONDARY_COLOR_ARRAYrI   s    r   rJ   zSecondaryColorAttribute.enable  s    455555r   c                 N    t          d| j        | j        | j        |z              d S r   )glSecondaryColorPointerr5   r   r   ro   s     r   rL   z#SecondaryColorAttribute.set_pointer  s2    4< $g 5	7 	7 	7 	7 	7r   r   rt   s   @r   r   r     sk        $$FLB B B B B6 6 67 7 7 7 7 7 7r   r   c                   8     e Zd ZdZdZ fdZd Zd Zd Z xZ	S )TexCoordAttributeTexture coordinate attribute.
tex_coordsc                     |t           t          t          t          t          fv s
J d            t	          t
          |                               ||           d S Nz6Texture coord attribute must have non-byte signed type)r   r   r   r   rf   r   rD   rg   s      r   rD   zTexCoordAttribute.__init__  sR    8VVXyIIIID JII&&//w?????r   c                 .    t          t                     d S rj   )rk   GL_TEXTURE_COORD_ARRAYrI   s    r   rJ   zTexCoordAttribute.enable  s    233333r   c                 X    t          | j        | j        | j        | j        |z              d S rj   glTexCoordPointerr   r5   r   r   ro   s     r   rL   zTexCoordAttribute.set_pointer  r   r   c                 ,    t           | _        d| _        dS )zHChanges the class of the attribute to `MultiTexCoordAttribute`.
        r   N)r/   rh   texturerI   s    r   $convert_to_multi_tex_coord_attributez6TexCoordAttribute.convert_to_multi_tex_coord_attribute  s     0r   )
r^   r_   r`   ra   rr   rD   rJ   rL   r   rs   rt   s   @r   r   r     su        ''F@ @ @ @ @
4 4 41 1 1      r   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )r/   r   c                     |t           t          t          t          t          fv s
J d            || _        t          t          |                               ||           d S r   )r   r   r   r   r   rf   r/   rD   )rC   r   r   r5   rh   s       r   rD   zMultiTexCoordAttribute.__init__  sY    8VVXyIIIID JII$d++44UGDDDDDr   c                 f    t          t          | j        z              t          t                     d S rj   )glClientActiveTextureGL_TEXTURE0r   rk   r   rI   s    r   rJ   zMultiTexCoordAttribute.enable  s,    kDL8999233333r   c                 X    t          | j        | j        | j        | j        |z              d S rj   r   ro   s     r   rL   z"MultiTexCoordAttribute.set_pointer  r   r   r^   r_   r`   ra   rD   rJ   rL   rs   rt   s   @r   r/   r/     sa        ''E E E E E4 4 41 1 1 1 1 1 1r   r/   c                   2     e Zd ZdZdZ fdZd Zd Z xZS )VertexAttributezVertex coordinate attribute.verticesc                     |dk    s
J d            |t           t          t          t          t          fv s
J d            t	          t
          |                               ||           d S )Nr   z-Vertex attribute must have count of 2, 3 or 4z7Vertex attribute must have signed type larger than byte)r   r   r   r   rf   r   rD   rg   s      r   rD   zVertexAttribute.__init__  sh    qyyy; yy8VVXyIIIIE JIIot$$--eW=====r   c                 .    t          t                     d S rj   )rk   GL_VERTEX_ARRAYrI   s    r   rJ   zVertexAttribute.enable  r   r   c                 X    t          | j        | j        | j        | j        |z              d S rj   )glVertexPointerr   r5   r   r   ro   s     r   rL   zVertexAttribute.set_pointer	  s4    
DL$+g-	/ 	/ 	/ 	/ 	/r   rq   rt   s   @r   r   r     sa        &&F> > > > >- - -/ / / / / / /r   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )r.   z2Generic vertex attribute, used by shader programs.c                     t          |          | _        || _        t          t          |                               ||           d S rj   )boolr6   indexrf   r.   rD   )rC   r   r6   r   r5   rh   s        r   rD   zGenericAttribute.__init__  s@    z**
%%..ug>>>>>r   c                 .    t          | j                   d S rj   )glEnableVertexAttribArrayr   rI   s    r   rJ   zGenericAttribute.enable  s    !$*-----r   c           	      p    t          | j        | j        | j        | j        | j        | j        |z              d S rj   )glVertexAttribPointerr   r   r5   r6   r   r   ro   s     r   rL   zGenericAttribute.set_pointer  s=    dj$*dl"ot{"kG3	5 	5 	5 	5 	5r   r   rt   s   @r   r.   r.     s\        <<? ? ? ? ?
. . .5 5 5 5 5 5 5r   r.   )cer   nr   tr   )+ra   rerA   	pyglet.glpyglet.graphicsr   ry   c_byterz   c_ubyter   c_shortGL_UNSIGNED_SHORTc_ushortr   c_intGL_UNSIGNED_INTc_uintr   c_floatr   c_doubler?   r-   compileVERBOSEr)   r'   r   r   r    r8   r:   rc   rv   r   r   r   r   r/   r   r.   r0   r   r   r   <module>r      s  H` `D 
			      ( ( ( ( ( ( V]fnfnv
FLV]fnv	 
								 		 "rz # Z    , , ," " ".+ + +(* * *Zm m m m m m m m`. . . . .& . . ."> > > > >) > > >$1 1 1 1 1) 1 1 1 J J J J J' J J J$7 7 7 7 7/ 7 7 7"    )   01 1 1 1 1. 1 1 1$/ / / / /' / / /(5 5 5 5 5( 5 5 5$ 
				 		    r   