
    _e1                     D   d Z ddlZddlZddlmZmZmZ ddlmZ  ej                  d      Z
 G d de      Z G d d	e      Z G d
 de      Z G d de      ZddlmZ dZej&                  r	 ddlmZmZmZ ddlmZmZmZmZ ddlmZmZ ec 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 G d% d&e      Z!y# e$ rZe
jA                  d       dZY dZ[dZ[ww xY w)'z*Implementations for common converter types    N)bytesunicodeas_8_bit)NULLzOpenGL.convertersc                   $    e Zd ZdZdZdZd Zd Zy)	Convertera  Base class for Converter types

    Converter objects are callable objects used with the
    OpenGL.wrapper.Wrapper class to simplify the wrapping
    of functions by collecting commonly used functionality
    into a reusable function.

    Each Converter has two (class) attributes:

        argNames -- list of argument names for initialisation
        indexLookups -- set of (indexname, argName,methodName) values
            to lookup on wrapper.  These allow us to use argument-name
            references to refer to which arguments to use when
            processing (prevents the need to revise pointers when
            we change the API for a function).

    Converters can be any of the Wrapper API helper functions,
    so the callable interface can vary among Converter classes.
     c                     t        | j                        }| j                  D ](  }||v st        | |||          |j                  |       * t	        ||      D ]  \  }}t        | ||        y)zStore arguments in attributes

        *args -- mapped to self.argNames in order to set attributes
        **named -- mapped to self.argNames by name to set attributes
        N)listargNamessetattrremovezip)selfargsnamedr   avalues         3/usr/lib/python3/dist-packages/OpenGL/converters.py__init__zConverter.__init__   sp     & 	%AEzq%(,$	% Hd, 	&GAeT1e%	&    c                 |    | j                   D ]-  \  }}}t        | | t        ||      t        | |                   / y)z'Look up our indices (where appropriate)N)indexLookupsr   getattr)r   wrapper	indexnameargName
methodNames        r   finalisezConverter.finalise*   sC    ,0,=,= 	(Igji+
+GT7,DE	r   N)__name__
__module____qualname____doc__r   r   r   r   r	   r   r   r   r      s    & HL&r   r   c                       e Zd ZdZd Zy)PyConverterzConverter sub-class for use in Wrapper.pyConverters

    This class just defines the interface for a pyConverter-style
    Converter object
    c                 F    t        | j                  j                  d      )a  Convert incoming argument into compatable data-types

        incoming -- the Python argument for this parameter
        function -- the wrapper.Wrapper class we are supporting
        arguments -- the complete set of arguments passed to the
            function


        ! class doesn't implement __call__NotImplemented	__class__r    )r   incomingfunction	argumentss       r   __call__zPyConverter.__call__9   #     NN##
  	r   Nr    r!   r"   r#   r.   r	   r   r   r%   r%   3       
r   r%   c                       e Zd ZdZd Zy)
CConverterzConverter sub-class for use in Wrapper.cConverters

    This class just defines the interface for a cConverter-style
    Converter object
    c                 F    t        | j                  j                  d      )a3  Calculate C-compatible Python object from Python arguments

        pyArgs -- set of Python argument objects converted by
            pyConverters from the incoming arguments
        index -- our index in baseOperation.cConverters
        baseOperation -- the Wrapper object which we are supporting
        r'   r(   r   pyArgsindexbaseOperations       r   r.   zCConverter.__call__M   s#     NN##
  	r   Nr0   r	   r   r   r3   r3   G   s    

r   r3   c                       e Zd ZdZd Zy)ReturnValueszConverter sub-class for use as Wrapper.returnValues

    This class just defines the interface for a returnValues-style
    Converter object
    c                 F    t        | j                  j                  d      )af  Return a final value to the caller

        result -- the raw ctypes result value
        baseOperation -- the Wrapper object which we are supporting
        pyArgs -- the set of Python arguments produced by pyConverters
        cArgs -- the set of C-compatible arguments produced by CConverter

        return the Python object for the final result
        r'   r(   r   resultr8   r6   cArgss        r   r.   zReturnValues.__call__^   r/   r   Nr0   r	   r   r   r:   r:   X   r1   r   r:   )acceleratesupport)CallFuncPyConverterDefaultCConvertergetPyArgsName)OutputSizedOutputOutputOrInputSizedOutputOrInput)returnCArgumentreturnPyArgumentzVUnable to load converters accelerators (wrapper, arraydatatype) from OpenGL_acceleratec                       e Zd ZdZd Zd Zy)r@   z:PyConverter that takes a callable and calls it on incomingc                     || _         y)zStore the functionNr,   )r   r,   s     r   r   zCallFuncPyConverter.__init__   s	    $DMr   c                 $    | j                  |      S )zCall our function on incomingrK   )r   r+   r,   arguments       r   r.   zCallFuncPyConverter.__call__   s    ==(,,r   Nr    r!   r"   r#   r   r.   r	   r   r   r@   r@      s    H	%	-r   r@   c                       e Zd ZdZd Zd Zy)rA   a  NULL or Default CConverter, returns same-named Python argument

        Used primarily to allow for specifying a converter that explicitly
        says "use the default behaviour".  This is *not* a finalise-ing
        converter, it is passed in the index explicitly and just retrieves
        that index from pyArgs when called.

        Raises informative errors if the index cannot be resolved in pyArgs
        c                     || _         y)z"Just store index for future accessNr7   )r   r7   s     r   r   zDefaultCConverter.__init__   s	    DJr   c           	          	 || j                      S # t        $ r% t        d| j                   dt        |            w xY w)z/Return pyArgs[self.index] or raise a ValueErrorzExpected parameter index z, but pyArgs only length )r7   
IndexError
ValueErrorlen)r   r6   r7   r   s       r   r.   zDefaultCConverter.__call__   sE    tzz++  JJL s    .?NrN   r	   r   r   rA   rA      s    				r   rA   c                   $    e Zd ZdZdZdgZdZd Zy)rB   zCConverter returning named Python argument

        Intended for use in cConverters, the function returned
        retrieves the named pyArg and returns it when called.
        namer7   rX   
pyArgIndexr7   rX   c                 l    	 || j                      S # t        $ r t        d| j                  z        w xY w)Return pyArgs[ self.index ]'"Did not resolve parameter index for %r)r7   AttributeErrorRuntimeErrorrX   r5   s       r   r.   zgetPyArgsName.__call__   s@    _tzz++! _"$QSWS\S\$]^^_s    "3Nr    r!   r"   r#   r   r   	__slots__r.   r	   r   r   rB   rB      s!    	
 8;&		_r   rB   c                   0    e Zd ZdZdZdgZdZd Zd Zd Z	y)	rC   a  CConverter generating static-size typed output arrays

        Produces an output array of given type (arrayType) and
        size using self.lookup() to determine the size of the
        array to be produced, where the lookup function is passed
        as an initialisation argument.

        Provides also:

            oldStyleReturn( ... ) for use in the default case of
                PyOpenGL compatability mode, where result arrays of
                size (1,) are returned as scalar values.
        )rX   size	arrayTypeoutIndexrX   	cArgIndex)r7   rd   re   rg   inIndexc                 V    | j                   j                  | j                  |            S )r]   )re   zerosgetSizer5   s       r   r.   zOutput.__call__   s     >>''f)=??r   c                     | j                   S ))Retrieve the array size for this argument)rd   )r   r6   s     r   rl   zOutput.getSize   s    99r   c                     || j                      }	 | j                  |      }|dk(  r	 |d   S |S # t        $ r |cY S w xY w# t        t        f$ r |cY S w xY w)Retrieve cArgs[ self.index ])   r   )rg   rl   KeyErrorrS   	TypeError)r   r=   r8   r6   r>   thisSizes         r   oldStyleReturnzOutput.oldStyleReturn   ss    DMM+F<</ 4"!!9$   
 #9- "!M"s   / A  == AAN)
r    r!   r"   r#   r   r   rb   r.   rl   ru   r	   r   r   rC   rC      s0    	 0-
 F		@		r   rC   c                   &     e Zd ZdefZ fdZ xZS )rE   Nc                     | j                   D ]   }||   |u st        t        |   |||      c S  | j                  j                  ||         S N)	DO_OUTPUTsuperrE   r.   re   asArrayr   r6   r7   r8   	do_outputr*   s        r   r.   zOutputOrInput.__call__   sV    !^^ `	%=I- -?P]__` >>))6%=::r   r    r!   r"   r   ry   r.   __classcell__r*   s   @r   rE   rE          $K		; 	;r   rE   c                   &    e Zd ZdZdZddgZdZd Zy)rD   a  Output generating dynamically-sized typed output arrays

        Takes an extra parameter "specifier", which is the name of
        a Python argument to be passed to the lookup function in order
        to determine the appropriate size for the output array.
        )rX   	specifierlookupre   rf   )r7   r   rZ   )r7   rg   r   r   re   c                     	 || j                      }	 | j                  |      S # t        $ r t        d|z        w xY w# t        $ r t	        d| j
                  z        w xY w)rn   zUnknown specifier %sr^   )r7   r   rr   r_   r`   rX   )r   r6   r   s      r   rl   zSizedOutput.getSize   sw    N"DJJ0	N;;	33 N"$>$LMMN " _"$QSWS\S\$]^^_s   > # ;"A N)r    r!   r"   r#   r   r   rb   rl   r	   r   r   rD   rD      s)    	 >-0
 J	
	Nr   rD   c                   &     e Zd ZdefZ fdZ xZS )rF   Nc                     | j                   D ]   }||   |u st        t        |   |||      c S  | j                  j                  ||         S rx   )ry   rz   rF   r.   re   r{   r|   s        r   r.   zSizedOutputOrInput.__call__   sW    !^^ e	%=I- "4TDfeUbdde >>))6%=::r   r~   r   s   @r   rF   rF      r   r   rF   c                   $    e Zd ZdZdZdgZdZd Zy)rG   z,ReturnValues returning the named cArgs valuerW   )r7   rX   rh   r[   c                      || j                      S )rp   rQ   r<   s        r   r.   zreturnCArgument.__call__  s    $$r   Nra   r	   r   r   rG   rG      s    :7:'		%r   rG   c                   $    e Zd ZdZdZdgZdZd Zy)rH   z-ReturnValues returning the named pyArgs valuerW   rY   r[   c                      || j                      S )zRetrieve pyArgs[ self.index ]rQ   r<   s        r   r.   zreturnPyArgument.__call__  s    $**%%r   Nra   r	   r   r   rH   rH     s    ;8;'		&r   rH   c                   6    e Zd ZdZdZdgZdZd Zd Zd Z	d Z
y	)
StringLengthsad  CConverter for processing array-of-pointers-to-strings data-type

    Converter is a CConverter for the array-of-lengths for a
    array-of-pointers-to-strings data-type used to pass a set
    of code fragments to the GLSL compiler.

    Provides also:

        stringArray -- PyConverter callable ensuring list-of-strings
            format for the python argument

        stringArrayForC -- CResolver converting the array to
            POINTER(c_char_p) format for passing to C

        totalCount -- CConverter callable giving count of string
            pointers (that is, length of the pointer array)
    rW   rY   r	   c                     ddl m} || j                     D cg c]  }t        |       }}|j                  t        |      z  } || S c c}w )0Get array of length integers for string contentsr   )_types)OpenGL.raw.GLr   r7   rU   GLint)r   r6   r7   r8   r   xtmpa_types           r   r.   zStringLengths.__call__$  sF    (%djj12!s1v22C(~ 3s   A	c                 2    t        || j                           S )r   )rU   r7   r5   s       r   
totalCountzStringLengths.totalCount*  s    6$**%&&r   c                 r    t        |t        t        f      r|g}|D cg c]  }t        |       }}|S c c}w )z/Create basic array-of-strings object from pyArg)
isinstancer   r   r   )r   argr8   r   r   r   s         r   stringArrayzStringLengths.stringArray-  s8    sU7O-%C&)*!** +s   4c                     ddl m} t        j                  t	        |      z         }t        |      D ]E  \  }}t        j                  |j                  j                  |      t        j                        ||<   G |S )z+Create a ctypes pointer to char-pointer setr   )arrays)	OpenGLr   ctypesc_char_prU   	enumeratecastGLcharARBArraydataPointer)r   stringsr   r=   iss         r   stringArrayForCzStringLengths.stringArrayForC3  sf    !//CL03W% 	CAa%%11!4F1I	
 r   N)r    r!   r"   r#   r   r   rb   r.   r   r   r   r	   r   r   r   r     s/    " H47LI'	r   r   )"r#   r   loggingOpenGL._bytesr   r   r   OpenGL._nullr   	getLogger_logobjectr   r%   r3   r:   r   r?   r@   ACCELERATE_AVAILABLEOpenGL_accelerate.wrapperrA   rB   OpenGL_accelerate.arraydatatyperC   rD   rE   rF   rG   rH   ImportErrorerrwarningr   r	   r   r   <module>r      s9   0  2 2 w-/) )X9 () "I * % ))#	
 	
	
 	
	
 -{ -Z ._ _ &* &N; ;Nv N0;k ;%< %&L &-Z -k  #d	
 #	#s   .C= =DDD