
    3j2                     R   S r SSKrSSKrSSKJrJrJr  SSKJr  \R                  " S5      r
 " S S\5      r " S S	\5      r " S
 S\5      r " S S\5      rSSKJr  Sr\R&                  (       a   SSKJrJrJr  SSKJrJrJrJr  SSKJrJr  \cc   " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S \5      r " S! S"\5      r " S# S$\5      r " S% S&\5      r!g! \ a  r\
RA                  S5        Sr SrCNSrCff = f)'z*Implementations for common converter types    N)bytesunicodeas_8_bit)NULLzOpenGL.convertersc                   ,    \ rS rSrSrSrSrS rS rSr	g)	Converter
   a  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                     [        U R                  5      nU R                   H)  nXB;   d  M
  [        XX$   5        UR                  U5        M+     [	        X15       H  u  pE[        XU5        M     g)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         K/home/wildlama/miniconda3/lib/python3.13/site-packages/OpenGL/converters.py__init__Converter.__init__"   sZ     &Az*"  H+HADU# ,    c                 x    U R                    H*  u  p#n[        X[        X5      " [        X5      5      5        M,     g)z'Look up our indices (where appropriate)N)indexLookupsr   getattr)r   wrapper	indexnameargName
methodNames        r   finaliseConverter.finalise0   s4    .2.?.?*I
!=gd>T!U /@r   N)
__name__
__module____qualname____firstlineno____doc__r   r   r   r!   __static_attributes__r
   r   r   r   r   
   s    ( HL$r   r   c                       \ rS rSrSrS rSrg)PyConverter9   zConverter sub-class for use in Wrapper.pyConverters

This class just defines the interface for a pyConverter-style
Converter object
c                 H    [        U R                  R                  < S35      e)zConvert 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__NotImplementedError	__class__r#   )r   incomingfunction	argumentss       r   __call__PyConverter.__call__@   !     "9=9P9PR
 	
r   r
   Nr#   r$   r%   r&   r'   r4   r(   r
   r   r   r*   r*   9       
r   r*   c                       \ rS rSrSrS rSrg)
CConverterO   zConverter sub-class for use in Wrapper.cConverters

This class just defines the interface for a cConverter-style
Converter object
c                 H    [        U R                  R                  < S35      e)a  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   r4   CConverter.__call__V   s!     "9=9P9PR
 	
r   r
   Nr7   r
   r   r   r:   r:   O   s    

r   r:   c                       \ rS rSrSrS rSrg)ReturnValuesc   zConverter sub-class for use as Wrapper.returnValues

This class just defines the interface for a returnValues-style
Converter object
c                 H    [        U R                  R                  < S35      e)a6  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   resultr@   r>   cArgss        r   r4   ReturnValues.__call__j   r6   r   r
   Nr7   r
   r   r   rC   rC   c   r8   r   rC   )acceleratesupport)CallFuncPyConverterDefaultCConvertergetPyArgsName)OutputSizedOutputOutputOrInputSizedOutputOrInput)returnCArgumentreturnPyArgumentzVUnable to load converters accelerators (wrapper, arraydatatype) from OpenGL_acceleratec                   $    \ rS rSrSrS rS rSrg)rK      z:PyConverter that takes a callable and calls it on incomingc                     Xl         g)zStore the functionNr2   )r   r2   s     r   r   CallFuncPyConverter.__init__   s    $Mr   c                 $    U R                  U5      $ )zCall our function on incomingrW   )r   r1   r2   arguments       r   r4   CallFuncPyConverter.__call__   s    ==**r   rW   Nr#   r$   r%   r&   r'   r   r4   r(   r
   r   r   rK   rK      s    H	%	+r   rK   c                   $    \ rS rSrSrS rS rSrg)rL      ao  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                     Xl         g)z"Just store index for future accessNr?   )r   r?   s     r   r   DefaultCConverter.__init__   s    Jr   c           	           XR                      $ ! [         a'    [        SU R                   < S[        U5      < 35      ef = f)z/Return pyArgs[self.index] or raise a ValueErrorzExpected parameter index z, but pyArgs only length )r?   
IndexError
ValueErrorlen)r   r>   r?   r   s       r   r4   DefaultCConverter.__call__   sB    jj))  zz3v;0 s	    1Ar`   Nr\   r
   r   r   rL   rL      s    			r   rL   c                   ,    \ rS rSrSrSrS/rSrS rSr	g)	rM      zCConverter returning named Python argument

Intended for use in cConverters, the function returned
retrieves the named pyArg and returns it when called.
namer?   rj   
pyArgIndexr?   rj   c                 l     XR                      $ ! [         a    [        SU R                  -  5      ef = f)Return pyArgs[ self.index ]'"Did not resolve parameter index for %r)r?   AttributeErrorRuntimeErrorrj   r=   s       r   r4   getPyArgsName.__call__   s<    jj))! "ATYYO s    #3r
   N
r#   r$   r%   r&   r'   r   r   	__slots__r4   r(   r
   r   r   rM   rM      s$    	 +
 &		r   rM   c                   8    \ rS rSrSrSrS/rSrS rS r	S r
S	rg
)rN      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.
)rj   size	arrayTypeoutIndexrj   	cArgIndex)r?   rx   ry   r{   inIndexc                 V    U R                   R                  U R                  U5      5      $ )ro   )ry   zerosgetSizer=   s       r   r4   Output.__call__   s     >>''V(<==r   c                     U R                   $ ))Retrieve the array size for this argument)rx   )r   r>   s     r   r   Output.getSize   s    99r   c                     X@R                      n U R                  U5      nUS:X  a   US   $ U$ ! [         a    Us $ f = f! [        [        4 a    Us $ f = f)Retrieve cArgs[ self.index ])   r   )r{   r   KeyErrorrc   	TypeError)r   rG   r@   r>   rH   thisSizes         r   oldStyleReturnOutput.oldStyleReturn   sq    ==)F<</ 4"!!9$   
 #I. "!M"s   / A >>AAr
   N)r#   r$   r%   r&   r'   r   r   ru   r4   r   r   r(   r
   r   r   rN   rN      s/    	 1-
 J		>		r   rN   c                   0   ^  \ rS rSrS\4rU 4S jrSrU =r$ )rP      Nc                    > U R                    H   nX   UL d  M  [        [        U ]  XU5      s  $    U R                  R                  X   5      $ N)	DO_OUTPUTsuperrP   r4   ry   asArrayr   r>   r?   r@   	do_outputr0   s        r   r4   OutputOrInput.__call__   sM    !^^	=I- >}  ,
 >>))&-88r   r
   	r#   r$   r%   r&   r   r   r4   r(   __classcell__r0   s   @r   rP   rP          4L		9 	9r   rP   c                   .    \ rS rSrSrSrSS/rSrS rSr	g	)
rO   i  zOutput 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.
)rj   	specifierlookupry   rz   )r?   r   rl   )r?   r{   r   r   ry   c                      XR                      n U R                  U5      $ ! [         a    [        SU-  5      ef = f! [         a    [	        SU R
                  -  5      ef = f)r   zUnknown specifier %srp   )r?   r   r   rq   rr   rj   )r   r>   r   s      r   r   SizedOutput.getSize  st    
M"::.	M;;y11 M"#=#KLLM " "ATYYO s   > " ;#A!r
   N)
r#   r$   r%   r&   r'   r   r   ru   r   r(   r
   r   r   rO   rO     s*    	 @-0
 N		Mr   rO   c                   0   ^  \ rS rSrS\4rU 4S jrSrU =r$ )rQ   i#  Nc                    > U R                    H   nX   UL d  M  [        [        U ]  XU5      s  $    U R                  R                  X   5      $ r   )r   r   rQ   r4   ry   r   r   s        r   r4   SizedOutputOrInput.__call__&  sN    !^^	=I- !3TC}  ,
 >>))&-88r   r
   r   r   s   @r   rQ   rQ   #  r   r   rQ   c                   ,    \ rS rSrSrSrS/rSrS rSr	g)	rR   i.  z,ReturnValues returning the named cArgs valueri   )r?   rj   r|   rm   c                     X@R                      $ )r   r`   rF   s        r   r4   returnCArgument.__call__7  s    $$r   r
   Nrt   r
   r   r   rR   rR   .  s     :*
 &		%r   rR   c                   ,    \ rS rSrSrSrS/rSrS rSr	g)	rS   i;  z-ReturnValues returning the named pyArgs valueri   rk   rm   c                     X0R                      $ )zRetrieve pyArgs[ self.index ]r`   rF   s        r   r4   returnPyArgument.__call__D  s    **%%r   r
   Nrt   r
   r   r   rS   rS   ;  s     ;+
 &		&r   rS   c                   >    \ rS rSrSrSrS/rSrS rS r	S r
S	 rSrg
)StringLengthsiI  a8  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)
ri   rk   r
   c                     SSK Jn  XR                      Vs/ s H  n[        U5      PM     nnUR                  [        U5      -  nU" U6 $ s  snf )0Get array of length integers for string contentsr   )_types)OpenGL.raw.GLr   r?   re   GLint)r   r>   r?   r@   r   xtmpa_types           r   r4   StringLengths.__call__b  sG    (%jj121!s1v12C(s| 3s   Ac                 0    [        XR                     5      $ )r   )re   r?   r=   s       r   
totalCountStringLengths.totalCountj  s    6**%&&r   c                     [        U[        [        45      (       a  U/nU Vs/ s H  n[        U5      PM     nnU$ s  snf )z/Create basic array-of-strings object from pyArg)
isinstancer   r   r   )r   argr@   r   r   r   s         r   stringArrayStringLengths.stringArrayn  s=    cE7+,,%C&)*c!c* +s   <c                     SSK Jn  [        R                  [	        U5      -  " 5       n[        U5       HE  u  pE[        R                  " UR                  R                  U5      [        R                  5      X4'   MG     U$ )z+Create a ctypes pointer to char-pointer setr   )arrays)	OpenGLr   ctypesc_char_pre   	enumeratecastGLcharARBArraydataPointer)r   stringsr   rG   iss         r   stringArrayForCStringLengths.stringArrayForCu  s]    !//CL03g&DA%%11!4FI '
 r   N)r#   r$   r%   r&   r'   r   r   ru   r4   r   r   r   r(   r
   r   r   r   r   I  s3    $ H'L I'
r   r   )"r'   r   loggingOpenGL._bytesr   r   r   OpenGL._nullr   	getLogger_logobjectr   r*   r:   rC   r   rJ   rK   ACCELERATE_AVAILABLEOpenGL_accelerate.wrapperrL   rM   OpenGL_accelerate.arraydatatyperN   rO   rP   rQ   rR   rS   ImportErrorerrwarningr   r
   r   r   <module>r      s5   0  2 2 ,-+ +^
) 
,
 
(
9 
. % ))#	
 	

	
 	
	
 	+k 	+J 2
 ,* *X	9 	9Mf M:	9[ 	9%, %&< &6J 6w  #d	
 #	#s   3D D&	D!!D&