a
    ij                  
   @   s  d Z ddlZddlZddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
mZ ddlZedZddlmZ dZejrz0dd	lmZ dd
lmZ ddlmZmZmZ W n. ey Z zed W Y dZ[n
dZ[0 0 edu r"dd ZG dd dejZG dd dejZG dd dejZnedZejs>d#ddZn
d$ddZej sVeZ!nerbeZ!ndd Z!ejs|dd Z"ndd Z"G dd de#Z$d%dd Z%d!d" Z&dS )&zHelper functions for wrapping array-using operations

These are functions intended to be used in wrapping
GL functions that deal with OpenGL array data-types.
    N)_configflags)contextdataerror
converters)arraydatatype)bytesunicodezOpenGL.arrays.arrayhelpers)acceleratesupport)AsArrayTypedSizeChecked)returnPyArgumentIndex)AsArrayOfTypeAsArrayTypedAsArrayTypedSizez>Unable to load arrayhelpers accelerator from OpenGL_acceleratec                 C   s   |d S )zwReturn the converted object as result of function

        Note: this is a hack that always returns pyArgs[0]!
        r    )resultbaseOperationpyArgscArgsr   r   X/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/OpenGL/arrays/arrayhelpers.pyreturnPointer    s    
r   c                   @   s*   e Zd ZdZdZdZdddZdd	 Zd
S )r   zGiven arrayName and typeName coerce arrayName to array of type typeName

        TODO: It should be possible to drop this if ERROR_ON_COPY,
        as array inputs always have to be the final objects in that
        case.
        	arrayNametypeName)
arrayIndexr   
pyArgIndex)	typeIndexr   r   pointertypec                 C   s   || _ || _d S Nr   )selfr   r   r   r   r   __init__:   s    zAsArrayOfType.__init__c                 C   s   || j  }tj| }||S z/Get the arg as an array of the appropriate type)r   r   ZGL_CONSTANT_TO_ARRAY_TYPEasArray)r    argwrappedOperationargsr   	arrayTyper   r   r   __call__>   s    

zAsArrayOfType.__call__N)r   r   __name__
__module____qualname____doc__ZargNamesZindexLookupsr!   r(   r   r   r   r   r   ,   s
   
r   c                   @   s*   e Zd ZdZdZdZd
ddZdd	 ZdS )r   zGiven arrayName and arrayType, convert arrayName to array of type

        TODO: It should be possible to drop this if ERROR_ON_COPY,
        as array inputs always have to be the final objects in that
        case.
        r   r'   r   r   Nc                 C   s   || _ || _d S r   r.   r    r   r'   r   r   r   r!   O   s    zAsArrayTyped.__init__c                 C   s   | j |S r"   )r'   r#   )r    r$   r%   r&   r   r   r   r(   S   s    zAsArrayTyped.__call__)r   Nr)   r   r   r   r   r   D   s
   
r   c                   @   s*   e Zd ZdZdZdZd
ddZdd	 ZdS )r   z:Given arrayName and arrayType, determine size of arrayNamer.   r/   r   Nc                 C   s   || _ || _d S r   r.   r0   r   r   r   r!   ]   s    zAsArrayTypedSize.__init__c                 C   s   | j || j S r"   )r'   Z	arraySizer   )r    r   indexr%   r   r   r   r(   a   s    zAsArrayTypedSize.__call__)r   Nr)   r   r   r   r   r   W   s
   
r   c                 C   s   t | jS )z9Create PyConverter to get first argument as array of type)r   CallFuncPyConverterr#   typsizer   r   r   asArrayTypej   s    r6   c                 C   s   dS )zNo converter requiredNr   r3   r   r   r   r6   p   s    c                    s*   j  tj|  fdd}|S )zCreate PyConverter function to get array as type and check size

            Produces a raw function, not a PyConverter instance
            c                    s>    | }||  }||}|kr:td|f | |S )Nz)Expected %r byte array, got %r byte array)Z
getHandlerr#   ZarrayByteCount
ValueError)incomingfunctionr&   handlerr   ZbyteSizeZdataTypeZexpectedBytesr4   r   r   asArraySize   s    

z$asArrayTypeSize.<locals>.asArraySize)ZtypeConstantctypesZsizeofZbaseType)r4   r5   r<   r   r;   r   asArrayTypeSize|   s    r>   c                  C   s   ddl m}  t| jS )z=Create PyConverter returning incoming as an array of any typer   ArrayDatatype)OpenGL.arraysr@   r   r2   r#   r?   r   r   r   asVoidArray   s    rB   c                   C   s   dS )z9If there's no copying allowed, we can use default passingNr   r   r   r   r   rB      s    c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	storePointerTypeaf  Store named pointer value in context indexed by constant

    pointerName -- named pointer argument
    constant -- constant used to index in the context storage

    Note: OpenGL.STORE_POINTERS can be set with ERROR_ON_COPY
    to ignore this storage operation.

    Stores the pyArgs (i.e. result of pyConverters) for the named
    pointer argument...
    c                 C   s   || _ || _d S r   )pointerNameconstant)r    rD   rE   r   r   r   r!      s    zstorePointerType.__init__c                 C   s   | | j| _d S r   )r   rD   pointerIndex)r    wrapperr   r   r   finalise   s    zstorePointerType.finalisec                 C   s   t | j|| j  d S r   )r   ZsetValuerE   rF   )r    r   r   r   r   r   r   r   r(      s    zstorePointerType.__call__N)r*   r+   r,   r-   r!   rH   r(   r   r   r   r   rC      s   rC   c                 C   s   ddl m} || ||S )a  Decorate function with vector-handling code for a single argument

    if OpenGL.ERROR_ON_COPY is False, then we return the
    named argument, converting to the passed array type,
    optionally checking that the array matches size.

    if OpenGL.ERROR_ON_COPY is True, then we will dramatically
    simplify this function, only wrapping if size is True, i.e.
    only wrapping if we intend to do a size check on the array.
    r   )rG   )OpenGLrG   ZsetInputArraySize)r   r5   r   ZargNamerG   r   r   r   setInputArraySizeType   s    rJ   c                    s   | j  fdd}|S )Nc                    s    | d }|du r S |S dS )z+Return the array size of the first argumentr   Nr   )r   r1   r   arraydefaultunitSizer   r   arraySizeOfFirst   s    z.arraySizeOfFirstType.<locals>.arraySizeOfFirst)rN   )r4   rM   rO   r   rL   r   arraySizeOfFirstType   s    rP   )N)N)r   )'r-   rI   r=   r   r   r   r   rA   r   ZOpenGL._bytesr   r   logging	getLogger_logr	   r
   ZACCELERATE_AVAILABLEZOpenGL_accelerate.arraydatatypeZOpenGL_accelerate.wrapperr   r   r   r   ImportErrorerrwarningr   ZPyConverterZ
CConverterZERROR_ON_COPYr6   ZARRAY_SIZE_CHECKINGr>   rB   objectrC   rJ   rP   r   r   r   r   <module>   sJ   
 



