
    _eU                     X   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j                  d      ZddlmZ dZej"                  r	 dd	lmZ dd
lmZ ddlmZmZmZ eCd Z G d dej8                        Z G d dej8                        Z G d dej:                        Zn ed      Zej<                  sddZnddZej@                  seZ!nereZ!nd Z!ej<                  sd Z"nd Z" G d de#      Z$ddZ%d Z&y# e$ rZej5                  d       Y dZ[dZ[ww xY w)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                     |d   S )zReturn the converted object as result of function
        
        Note: this is a hack that always returns pyArgs[0]!
        r    )resultbaseOperationpyArgscArgss       </usr/lib/python3/dist-packages/OpenGL/arrays/arrayhelpers.pyreturnPointerr      s    
 ay    c                   &    e Zd ZdZdZdZddZd Zy)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   c                      || _         || _        y Nr   )selfr   r   s      r   __init__zAsArrayOfType.__init__.   s    &DN$DMr   c                 h    || j                      }t        j                  |   }|j                  |      S z/Get the arg as an array of the appropriate type)r    r   GL_CONSTANT_TO_ARRAY_TYPEasArray)r#   argwrappedOperationargstype	arrayTypes         r   __call__zAsArrayOfType.__call__1   s1    )D%??GI$$c++r   N)pointerr,   __name__
__module____qualname____doc__argNamesindexLookupsr$   r.   r   r   r   r   r   "   s    	 .
	%	,r   r   c                   &    e Zd ZdZdZdZddZd Zy)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   Nc                      || _         || _        y r"   r8   r#   r   r-   s      r   r$   zAsArrayTyped.__init__A       &DN&DNr   c                 8    | j                   j                  |      S r&   )r-   r(   )r#   r)   r*   r+   s       r   r.   zAsArrayTyped.__call__D   s    >>))300r   r/   Nr0   r   r   r   r   r   6   s    	 /
	'	1r   r   c                   &    e Zd ZdZdZdZddZd Zy)r   zCGiven arrayName and arrayType, determine size of arrayName
        r8   r9   Nc                      || _         || _        y r"   r8   r;   s      r   r$   zAsArrayTypedSize.__init__N   r<   r   c                 R    | j                   j                  || j                           S r&   )r-   	arraySizer   )r#   r   indexr*   s       r   r.   zAsArrayTypedSize.__call__Q   s     >>++VDOO-EGGr   r>   r0   r   r   r   r   r   G   s    	.
	'	Hr   r   c                 @    t        j                  | j                        S )z9Create PyConverter to get first argument as array of type)r   CallFuncPyConverterr(   typsizes     r   asArrayTyperI   X   s    --s{{<<r   c                      y)zNo converter requiredNr   rF   s     r   rI   rI   \       r   c                       j                   } j                   j                  }t        j                   j
                        |z   fd}|S )zCreate PyConverter function to get array as type and check size
            
            Produces a raw function, not a PyConverter instance
            c                     j                  |       }|j                  |       }|j                  |      }|k7  rt        dd|d|       |S )Nz	Expected z byte array, got z byte array)
getHandlerr(   arrayByteCount
ValueError)	incomingfunctionr+   handlerr   byteSizedataTypeexpectedBytesrG   s	         r   asArraySizez$asArrayTypeSize.<locals>.asArraySizeo   s]    ..(4 (H>"116;},$)$ !  r   )r(   typeConstantrB   ctypessizeofbaseType)rG   rH   r(   rB   rW   rU   rV   s   `    @@r   asArrayTypeSizer\   f   sF    
 kkG''HI"MM3<<9D@M r   c                  L    ddl m}  t        j                  | j                        S )z=Create PyConverter returning incoming as an array of any typer   ArrayDatatype)OpenGL.arraysr_   r   rE   r(   r^   s    r   asVoidArrayra      s    /--}/D/DFFr   c                       y)z9If there's no copying allowed, we can use default passingNr   r   r   r   ra   ra      rK   r   c                   "    e Zd ZdZd Zd Zd Zy)storePointerTypeas  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                      || _         || _        y r"   )pointerNameconstant)r#   rf   rg   s      r   r$   zstorePointerType.__init__   s    & r   c                 D    |j                  | j                        | _        y r"   )r   rf   pointerIndex)r#   wrappers     r   finalisezstorePointerType.finalise   s    #..0@0@Br   c                 ^    t        j                  | j                  || j                            y r"   )r   setValuerg   ri   )r#   r   r   r   r   s        r   r.   zstorePointerType.__call__   s!    dmmVD4E4E-FHr   N)r1   r2   r3   r4   r$   rk   r.   r   r   r   rd   rd      s    
!CIr   rd   c                 P    ddl m} |j                  |       j                  ||      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   )rj   )OpenGLrj   setInputArraySize)r   rH   r,   argNamerj   s        r   setInputArraySizeTyperr      s#     ??M+==wNNr   c                 .    | j                   fd}|S )Nc                 &    | d   }|S  |      S )z+Return the array size of the first argumentr   r   )r   rC   r   arraydefaultunitSizes       r   arraySizeOfFirstz.arraySizeOfFirstType.<locals>.arraySizeOfFirst   s!    q	=NU$$r   )rw   )rG   rv   rx   rw   s    ` @r   arraySizeOfFirstTypery      s    ||H% r   r"   )r   )'r4   ro   rY   r   r   r   r   r`   r   OpenGL._bytesr   r	   logging	getLogger_logr
   r   ACCELERATE_AVAILABLEOpenGL_accelerate.arraydatatypeOpenGL_accelerate.wrapperr   r   r   r   ImportErrorerrwarningr   PyConverter
CConverterERROR_ON_COPYrI   ARRAY_SIZE_CHECKINGr\   ra   objectrd   rr   ry   r   r   r   <module>r      s5  
    1 1 ' ' w68 $ ))	
KC	
 	
 ",// ,(1
.. 1"HJ11 H *1.M!!= ''!O1	4 !!G
I I*O	m  
L	
 	

s   D	 	D)D$$D)