a
    ij)                  +   @   s  d Z dZddlZddlmZ eeZzddlZW n0 e	yb Z
 ze	de
 W Y dZ
[
n
dZ
[
0 0 ddlZestJ ddlZddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ejZddlmZ dZejrzddlmZ W n0 e	y Z
 zed W Y dZ
[
n
dZ
[
0 0 edu reg ddZeedrHdd Zndd Zz[W n& ey| Z
 zW Y dZ
[
n
dZ
[
0 0 e eZG dd dej!Zzedgd dZ"W n. e#y Z
 zdZ"dZ$W Y dZ
[
n
dZ
[
0 0 dd Z%e%dej&e%dej'e%dej(e%dej)e%e"ej*e%e$ej+e%dej,e%d ej,e%d!ej-e%d"ej.ddiZ/ej&e%dej'e%dej(e%dej)e%dej-e%d!ej*e%e"ej.e%d"ej,e%dej+e%e$ej0e%d#d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iZ1dS )$zNumpy (new version) module implementation of the OpenGL-ctypes array interfaces

XXX Need to register handlers for all of the scalar types that numpy returns,
would like to have all return values be int/float if they are of  compatible
type as well.
numpy    N)_configflagszNo numpy module present: %s)long)_types)GL_1_1error)formathandler)acceleratesupport)NumpyHandlerzEUnable to load numpy_formathandler accelerator from OpenGL_accelerate)            i__array_interface__c                 C   sv   zt |jd d W S  typ   | |}zt |jd d W  Y S  tyj   t |jd d Y  Y S 0 Y n0 dS )8Convert given instance to a data-pointer value (integer)datar   N)r   r   AttributeErrorasArray__array_data__clsinstance r   W/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/OpenGL/arrays/numpymodule.pydataPointer(   s    
r   c                 C   st   zt |jd dW S  tyn   | |}zt |jd d W  Y S  tyh   t |jd d Y  Y S 0 Y n0 dS )r   r   r   N)r   r   r   r   r   r   r   r   r   r   3   s    
c                   @   s(  e Zd ZdZejejejejej	ej
ejejejejejejejejejejejejejejejejejejfZeedreejf7 Zeedreejf7 ZeZdZ e!j"Z"e#dd Z$e#dd Z%e#dd
dZ&e#dddZ'e#dddZ(e#dddZ)e#dddZ*e#dddZ+e#dddZ,d	S )r   a  Numpy-specific data-type handler for OpenGL

        Attributes:

            ERROR_ON_COPY -- if True, will raise errors
                if we have to copy an array object in order to produce
                a contiguous array of the correct type.
        float128
complex256Tc                 C   s   t j|dd}t |t| S )z)Return Numpy array of zeros in given sizer   dtype)r   arrayzerosGL_TYPE_TO_ARRAY_MAPPING)r   dimstypeCoder   r   r   r"   n   s    zNumpyHandler.zerosc                 C   s6   |j }t|}|du r2td|tt |f |S )z=Given a value, guess OpenGL type of the corresponding pointerNzADon't know GL type for array of type %r, known types: %s
value:%s)r    ARRAY_TO_GL_TYPE_MAPPINGget	TypeErrorlistkeys)r   valuer%   Zconstantr   r   r   arrayToGLTypes   s    
zNumpyHandler.arrayToGLTypeNc                 C   s   |j S )z6Given a data-value, calculate dimensions for the array)sizer   r+   r%   r   r   r   	arraySize   s    zNumpyHandler.arraySizec                 C   sH   z|j W S  tyB   | jr,tdt|| ||}|j  Y S 0 dS )zCGiven a data-value, calculate number of bytes required to representz2Non-numpy array passed to numpy arrayByteCount: %sN)nbytesr   ERROR_ON_COPYr   	CopyErrortyper   r.   r   r   r   arrayByteCount   s    zNumpyHandler.arrayByteCountc                 C   s   |du r|S |  ||S dS )z7Convert given value to an array value of given typeCodeN)
contiguousr.   r   r   r   r      s    zNumpyHandler.asArrayc                 C   s   t | }z|jj}W n4 tyH   |r6t|| Y S t| Y S Y n0 |rf|du sb||jjkrf|S |r| jrddl	m
} |d|jj|n:| jrddl	m
} |d||du r|jj}t||S dS )a  Get contiguous array from source

            source -- numpy Python array (or compatible object)
                for use as the data source.  If this is not a contiguous
                array of the given typeCode, a copy will be made,
                otherwise will just be returned unchanged.
            typeCode -- optional 1-character typeCode specifier for
                the numpy.array function.

            All gl*Pointer calls should use contiguous arrays, as non-
            contiguous arrays will be re-copied on every rendering pass.
            Although this doesn't raise an error, it does tend to slow
            down rendering.
            Nr   r   2Array of type %r passed, required array of type %rzNon-contiguous array passed)r#   flagsr5   r   r   Zascontiguousarrayr    charr1   OpenGLr   r2   )r   sourcer%   r5   r   r   r   r   r5      s0    

zNumpyHandler.contiguousc                 C   s
   |j d S )z-Determine unit size of an array (if possible)shaper.   r   r   r   unitSize   s    zNumpyHandler.unitSizec                 C   s   |j S )z<Determine dimensions of the passed array value (if possible)r<   r.   r   r   r   
dimensions   s    zNumpyHandler.dimensionsc                 C   st   z|  |}W n4 tyB   | ||}|  |}|f|_| Y S 0 |rh|jt| krhtd|jj|t	|S d S )Nr6   )
r   r(   r   Z_temporary_array_r    r#   r   r2   r8   c_void_p)r   r   r%   Zpointerr!   ppr   r   r   
from_param   s    

zNumpyHandler.from_param)N)N)N)N)N)N)N)-__name__
__module____qualname____doc__r   ZndarrayZbool_ZintcZuintcZint8Zuint8Zint16Zuint16Zint32Zuint32Zint64Zuint64Zfloat16Zfloat32Zfloat64Z	complex64Z
complex128bytes_Zstr_voidZ
datetime64Ztimedelta64ZHANDLED_TYPEShasattrr   r   r   ZisOutputr   r1   classmethodr"   r,   r/   r4   r   r5   r>   r?   rB   r   r   r   r   r   D   sf   	



/r   r   shHc                 C   s   t jd| djS )N)r   r   )r   r"   r    )r8   r   r   r   lookupDtype   s    rN   dfeBcbIP)2rF   ZREGISTRY_NAMEloggingr9   r   	getLoggerrC   _logr   ImportErrorerrctypesZOpenGL._bytesr   ZOpenGL.raw.GLr   ZOpenGL.raw.GL.VERSIONr   r   ZOpenGL.arraysr	   r@   r
   r   ZACCELERATE_AVAILABLEZ%OpenGL_accelerate.numpy_formathandlerwarningr!   Z	testArrayrI   r   	NameErrorrJ   ZFormatHandlerZ
SHORT_TYPEr(   ZUSHORT_TYPErN   Z	GL_DOUBLEZGL_FLOATZGL_HALF_FLOATZGL_INTZGL_SHORTZGL_UNSIGNED_SHORTZGL_UNSIGNED_BYTEZGL_BYTEZGL_UNSIGNED_INTr&   Z	GL_VOID_Pr#   r   r   r   r   <module>   s   
"


 



















