
    _e)                        d Z dZddlZddlmZ  ej
                  e      Z	 ddlZddlZesJ 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j0                  r	 ddlmZ eD ej6                  g dd      Z eed      rd Znd Z	 [ e e      Z G d dejB                        Z	  ej6                  dgd       dZ"d Z% e%d      ejL                   e%d      ejN                   e%d      ejP                   e%d      ejR                   e%e"      ejT                   e%e$      ejV                   e%d      ejX                   e%d      ejX                   e%d      ejZ                   e%d       ej\                  ddiZ/i ejL                   e%d      ejN                   e%d      ejP                   e%d      ejR                   e%d      ejZ                   e%d      ejT                   e%e"      ej\                   e%d       ejX                   e%d      ejV                   e%e$      ej`                   e%d!      ddd e%d      d e%d      d e%d      d e%d      d  e%d       d e%d       e%d       e%d       e%d       e%d      d"Z1y# e	$ rZ
 e	de
z        dZ
[
ww xY w# e	$ rZ
ej5                  d       Y dZ
[
edZ
[
ww xY w# e$ rZ
Y dZ
[
OdZ
[
ww xY w# e#$ rZ
dZ"dZ$Y dZ
[
2dZ
[
ww xY w)#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                    	 t        |j                  d   d         S # t        $ rZ | j                  |      }	 t        |j                  d   d         cY S # t        $ r t        |j                  d   d      cY cY S w xY ww xY w)8Convert given instance to a data-pointer value (integer)datar   )r   r   AttributeErrorasArray__array_data__clsinstances     ;/usr/lib/python3/dist-packages/OpenGL/arrays/numpymodule.pydataPointerr   (   s    >H88@CDD! >;;2> < <V DQ GHH% > 7 7 :1==>	>s,    B AB "A<7B ;A<<B c                    	 t        |j                  d   d      S # t        $ rZ | j                  |      }	 t        |j                  d   d         cY S # t        $ r t        |j                  d   d      cY cY S w xY ww xY w)r   r   r   )r   r   r   r   r   r   s     r   r   r   3   s    >H33A6q99! >;;2> < <V DQ GHH% > 7 7 :1==>	>s,    A>AA>"A:5A>9A::A>c                   F   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j0                  ej2                  ej4                  fZ eed      reej:                  fz  Z eed      reej<                  fz  ZeZdZ e!jD                  Z"e#d        Z$e#d        Z%e#dd       Z&e#dd	       Z'e#dd
       Z(e#dd       Z)e#dd       Z*e#dd       Z+e#dd       Z,y)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                 j    t        j                  |d      }t        j                  |t        |         S )z)Return Numpy array of zeros in given sizer   dtype)r   arrayzerosGL_TYPE_TO_ARRAY_MAPPING)r   dimstypeCodes      r   r&   zNumpyHandler.zerosn   s+     ;;C0D;;&>x&HII    c           	          |j                   }t        j                  |      }|/t        d|dt	        t        j                               d|      |S )z=Given a value, guess OpenGL type of the corresponding pointerz%Don't know GL type for array of type z, known types: z
value:)r$   ARRAY_TO_GL_TYPE_MAPPINGget	TypeErrorlistkeys)r   valuer)   constants       r   arrayToGLTypezNumpyHandler.arrayToGLTypes   sR     {{H/33X?H $'?'D'D'F"G 
 Or*   Nc                     |j                   S )z6Given a data-value, calculate dimensions for the array)sizer   r1   r)   s      r   	arraySizezNumpyHandler.arraySize   s     ::r*   c                     	 |j                   S # t        $ rL | j                  rt        j                  dt        |            | j                  ||      }|j                   cY S w xY w)zCGiven a data-value, calculate number of bytes required to representz2Non-numpy array passed to numpy arrayByteCount: %s)nbytesr   ERROR_ON_COPYr	   	CopyErrortyper   r6   s      r   arrayByteCountzNumpyHandler.arrayByteCount   s`    	$||#! $$$//PU  UH6||#$s    AA#"A#c                 .    ||S | j                  ||      S )z7Convert given value to an array value of given typeCode)
contiguousr6   s      r   r   zNumpyHandler.asArray   s     }~~uh88r*   c                    t         |   }	 |j                  j                  }|r|||j                  j                  k(  r|S |r:| j
                  r.ddlm}  |j                  d|j                  j                  |      | j
                  rddlm}  |j                  d|      ||j                  j                  }t        j                  ||      S # t        $ r2 |rt        j                  ||      cY S t        j                  |      cY S w xY w)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.
            r   r   2Array of type %r passed, required array of type %rzNon-contiguous array passed)r'   flagsr?   r$   charr:   OpenGLr	   r;   r   ascontiguousarrayr   )r   sourcer)   r?   r	   s        r   r?   zNumpyHandler.contiguous   s      0;HG#\\44
 8#3xARAR7R!M S%6%6,)%//P))8  ((0-eoo="   '#)<<#4#4 22FHFF9 " = 22FHFF 22F<<	=s   C !D
2D
	D
c                      |j                   d   S )z-Determine unit size of an array (if possible)shaper6   s      r   unitSizezNumpyHandler.unitSize   s     ;;r?"r*   c                     |j                   S )z<Determine dimensions of the passed array value (if possible)rI   r6   s      r   
dimensionszNumpyHandler.dimensions   s     ;;r*   c                 :   	 | j                  |      }|rA|j                  t        |   k7  r+t        j                  d|j                  j
                  |      t        |      S # t        $ r0 | j                  ||      }| j                  |      }|f|_	        |cY S w xY w)NrA   )
r   r$   r'   r	   r;   rC   c_void_pr.   r   _temporary_array_)r   r   r)   pointerr%   pps         r   
from_paramzNumpyHandler.from_param   s    +//85 2JH2V V//P ++X   **  Xx9__e-(-x$		s   A! !6BB)N)-__name__
__module____qualname____doc__r   ndarraybool_intcuintcint8uint8int16uint16int32uint32int64uint64float16float32float64	complex64
complex128bytes_str_void
datetime64timedelta64HANDLED_TYPEShasattrr    r!   r   isOutputr   r:   classmethodr&   r3   r7   r=   r   r?   rK   rM   rS    r*   r   r   r   D   s   	 MMKKJJKKJJKKKKLLKKLLKKLLKKLLMMMMMMOOLLJJJJ1
4 5$enn..M5&e..00M!$22		J 
	J 

	 

	 
	 
	 
	$ 
	$ 
	9 
	9 
.	G 
.	G^ 
	# 
	# 
	 
	 
	+ 
	+r*   r   r   shHc                 D    t        j                  d|       j                  S )N)r   r#   )r   r&   r$   )rC   s    r   lookupDtyperw      s    ;;D*000r*   dfeBcbIP)ru   r}   r{   rs   )2rW   REGISTRY_NAMEloggingrD   r   	getLoggerrT   _logr   ImportErrorerrctypesOpenGL._bytesr   OpenGL.raw.GLr   OpenGL.raw.GL.VERSIONr   r	   OpenGL.arraysr
   rO   r   r   ACCELERATE_AVAILABLE%OpenGL_accelerate.numpy_formathandlerwarningr%   	testArrayro   r   	NameErrorrq   FormatHandler
SHORT_TYPEr.   USHORT_TYPErw   	GL_DOUBLEGL_FLOATGL_HALF_FLOATGL_INTGL_SHORTGL_UNSIGNED_SHORTGL_UNSIGNED_BYTEGL_BYTEGL_UNSIGNED_INTr,   	GL_VOID_Pr'   rr   r*   r   <module>r      s     w($@ v     (  '?? $))
F
 Ys,I y./		>		> {,K\+33 \+|EKK!cJ
1 f&&foof**fmm
V__f66f--f--fnnf,,$ 
k#&
OOK$ +c* MM;s#	
 NNK$ OO[, K, [- k+6 k#& 	$ S	 S	 S	 S	  S	!" S	#$ 
S		S		S		S	+ [  @
8#>
??@   
S	
 	

D  L  JKsY   J( 1K  K$ >K7 (J=-J88J= K!KK!$K4/K47L<LL