
    3j?                         S r SSKrSSKJr  SSKJr  SSKrSSKrSSKJ	r	  SSKJ
r
Jr  \R                  " \5      r " S S\5      r " S	 S
\5      r\44S jr " S S\5      r " S S\5      r " S S\5      rg)z(Base class for platform implementations
    N)ctypesloader)as_8_bit)_configflags)logsMODULE_ANNOTATIONSc                        \ rS rSrS rS rSrg)lazy_property   c                     Xl         g Nfget)selffunctions     V/home/wildlama/miniconda3/lib/python3.13/site-packages/OpenGL/platform/baseplatform.py__init__lazy_property.__init__   s    	    c                 h    U R                  U5      n[        XR                   R                  U5        U$ r   )r   setattr__name__)r   objclsvalues       r   __get__lazy_property.__get__   s(    		#YY''/r   r   N)r   
__module____qualname____firstlineno__r   r   __static_attributes__ r   r   r	   r	      s    r   r	   c                   2    \ rS rSrS rS rS rS rS rSr	g)	_CheckContext   c                     Xl         X l        g r   func	ccisvalid)r   r'   r(   s      r   r   _CheckContext.__init__   s    	"r   c                 X    US;  a  [        U R                  X5      $ X R                  U'   g )Nr&   )r   r'   __dict__)r   keyr   s      r   __setattr___CheckContext.__setattr__   s(    ++499c11!&MM#r   c                     [        U R                  SS 5      (       a  U R                  R                  $ [        U R                  5      $ )N__doc__)getattrr'   r0   reprr   s    r   __repr___CheckContext.__repr__#   s3    499i..99$$$		?"r   c                 P    US:w  a  [        U R                  U5      $ [        U5      e)Nr'   )r1   r'   AttributeError)r   r,   s     r   __getattr___CheckContext.__getattr__)   s%    &=499c**S!!r   c                     U R                  5       (       d,  SSKJn  UR                  U R                  R
                  X5      eU R                  " U0 UD6$ Nr   error)r(   OpenGLr=   	NoContextr'   r   r   argsnamedr=   s       r   __call___CheckContext.__call__.   sA    ~~$//$))"4"4dBByy$(%((r   )r(   r'   N)
r   r   r   r   r   r-   r4   r8   rC   r    r!   r   r   r#   r#      s    #'#"
)r   r#   c                    [         R                  " 5       nU(       an  SUR                  ;   a^  U (       a#  UR                  S   U ;  a  UR                  S   $ OUR                  S   $ UR                  nU(       a  SUR                  ;   a  M^  g )Nr   )sys	_getframe	f_globalsf_back)excludeframes     r   _find_modulerL   6   sr    MMOE
J%//1z*'9z22 : ??:.. J%//1 r   c            	          \ rS rSrSr/ SQrSrSrSrS r	S r
SS jrS	 rS
 rS r\R                   SSSSSSSS4	S jr\R                   SSSSSSS4S jrS r\rS r\R                   SSSSSSSS4	S jrS rS r\S 5       r\S 5       rSrg)BasePlatformC   a  Base class for per-platform implementations

Attributes of note:

    EXPORTED_NAMES -- set of names exported via the platform
        module's namespace...

    GL, GLU, GLUT, GLE, GLES1, GLES2, GLES3 -- ctypes libraries

    DEFAULT_FUNCTION_TYPE -- used as the default function
        type for functions unless overridden on a per-DLL
        basis with a "FunctionType" member

    GLUT_GUARD_CALLBACKS -- if True, the GLUT wrappers
        will provide guarding wrappers to prevent GLUT
        errors with uninitialised GLUT.

    EXTENSIONS_USE_BASE_FUNCTIONS -- if True, uses regular
        dll attribute-based lookup to retrieve extension
        function pointers.
)GetCurrentContextCurrentContextIsValidcreateBaseFunctioncreateExtensionFunctioncopyBaseFunctiongetGLUTFontPointernullFunctionGLUT_GUARD_CALLBACKSNFc                 P    U R                    H  n[        XS5      X'   M     XS'   U $ )z7Install this platform instance into the platform moduleNPLATFORM)EXPORTED_NAMESr1   )r   	namespacenames      r   installBasePlatform.installi   s-    ''D%d$7IO ( $*r   c                 T    [        US5      (       a  UR                  $ U R                  $ )z3Given a DLL, determine appropriate function type...FunctionType)hasattrr`   DEFAULT_FUNCTION_TYPE)r   dlls     r   functionTypeForBasePlatform.functionTypeForp   s'    3''###---r   c                 l    SSK Jn  U(       a&  [        R                  (       a  UR                  Ul        U$ )z1Add error checking to the function if appropriater   r<   )r>   r=   r   ERROR_CHECKINGglCheckErrorerrcheck)r   r'   rc   error_checkerr=   s        r   errorCheckingBasePlatform.errorCheckingw   s$     \88 *66DMr   c                     [         R                  (       aS  X R                  L aE  UR                  S;  a5  UR                  R	                  S5      (       d  [        XR                  5      $ U$ )z2Wrap function with context-checking if appropriate)glGetStringglGetStringiglGetIntegervglX)r   CONTEXT_CHECKINGGLr   
startswithr#   rQ   )r   r'   rc   s      r   wrapContextCheckBasePlatform.wrapContextCheck   sT     ))ww MM,,U33 'A'ABBr   c                 X    [         R                  " U[         R                  " S5      5      $ )z4Wrap function with logging operations if appropriatezOpenGL.errors)r   	logOnFailgetLog)r   r'   s     r   wrapLoggingBasePlatform.wrapLogging   s    ~~dDKK$@AAr   c                 n    U[         R                  " S5      :X  a  [        USS5      (       d  SSKJn  U$ U$ )z"Retrieve a final type for arg-typeNfinalFr   )ArrayDatatype)ctypesPOINTERr1   OpenGL.arraysr~   )r   typr~   s      r   finalArgTypeBasePlatform.finalArgType   s/    &..&&wsGU/K/K3  Jr   r!   c           
      H   U(       + =(       d    UR                  S5      S   S:H  nU(       d!  U R                  U5      (       d  [        S5      eU Vs/ s H  oR                  U5      PM     nnU
(       d  U(       dd  U R                  (       dS  U R                  [        U5      5      nU(       a  U R                  U5      " U/UQ76 " U5      nOA[        SU< SU< 35      e[        R                  " U R                  U5      " U/UQ76 UU5      nX_l
        [        U=(       d    S5      Ul        Xl        X/l        Xl        Xl        U R#                  U R%                  U R'                  XUS9U5      5      n[(        (       a  U	(       d
  [+        5       n	U	(       a  Xl        U$ s  snf )	zjCore operation to create a new base ctypes function

raises AttributeError if can't find the procedure...
_   VERSIONzExtension not availablez
Extension z( available, but no pointer for function r!   )rj   )splitcheckExtensionr7   r   EXTENSIONS_USE_BASE_FUNCTIONSgetExtensionProcedurer   rd   r   buildFunctionr0   listargNamesr   DLL	extension
deprecatedrz   ru   rk   r   rL   r   )r   functionNamerc   
resultTypeargTypesdocr   r   r   moduleforce_extensionrj   is_coretpointerr'   s                   r   constructFunctionBasePlatform.constructFunction   sq   $ !=IY__S%9!%<	%I!4!4Y!?!? !>??2:;(Q%%a((;4#E#E 00,1GHG++C0GhGP$ ,0 
  --$$S)*@x@D
 X^,$"$!!""4M"J
 %"(K <s   Fc                 v   SSK Jn  Sn [        R                  (       a-  X R                  L a  U(       a  U R                  UUUUUUUUU
S9	nOU R                  UUUUUUUU
S9n [        (       a  U	(       d
  [        5       n	U	(       a  Xl
        U$ ! [         a   nU R                  UUUUUUUU
S9n SnANPSnAff = f)zCreate a base function for given name

Normally you can just use the dll.name hook to get the object,
but we want to be able to create different bindings for the
same function, so we do the work manually here to produce a
base function from a DLL.
r   )wrapperN)rc   r   r   r   r   r   r   rj   )r   r   r   r   r   rj   )rc   r   r   r   r   r   rj   )r>   r   r   FORWARD_COMPATIBLE_ONLYrs   rV   r   r7   r   rL   r   )r   r   rc   r   r   r   r   r   r   r   rj   r   resulterrs                 r   rR   BasePlatform.createBaseFunction   s    ( 	#"	33ww:** )%%')"/ + 
 // )%%'"/ 0 	* %$*!!  
	&&%!!#+ ' 	F
	s   AB B 
B8B33B8c                 T   U(       d  gU R                  5       nU(       ai  SSKJn  UR                  SUS9nUc  0 nUR	                  SXBSS9  UR                  U5      nUc'  SSKJn  UR                  R                  U5      nXtU'   U$ U$ SSKJn  UR                  R                  U5      $ )	zACheck whether the given extension is supported by current contextTr   )contextdata
extensions)contextF)r   weak)r   )	rP   r>   r   getValuesetValuegetr   ExtensionQuerierhasExtension)r   r\   r   r   setcurrentr   r   s           r   r   BasePlatform.checkExtension  s     ((**&&|W&EC{$$\3e$TggdmG-#44AA$G"D	N)..;;DAAr   c                 :   SSK JnJn  [        U[        5      (       aq  U R                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  S9	$ [        US5      (       a  UR                   nU R#                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  UR$                  S9	$ )zCreate a new base function based on an already-created function

This is normally used to provide type-specific convenience versions of
a definition created by the automated generator.
r   )r   r=   )r   r   r   r   r   r   rj   originalFunction)r>   r   r=   
isinstance_NullFunctionPointerrV   r   r   restypeargtypesr0   r   r   r   rj   ra   r   rR   ri   )r   originalr   r=   s       r   rT   BasePlatform.copyBaseFunction<  s     	*h 455$$!!#++!**$$!**",,#..&44 % 
 
 X12200H&&LL''&&  &&((**"++ ' 

 
	
r   c                     U(       a  [         nO[        n[        UU4UUS.5      n[        (       a  U	(       d
  [	        5       n	U	(       a  Xl        U" UUUUUUUU
US9	$ )z#Construct a "null" function pointer)r0   r   )r   r   rj   r   )_DeprecatedFunctionPointerr   typer   rL   r   )r   r   rc   r   r   r   r   r   r   r   rj   r   baser   s                 r   rV   BasePlatform.nullFunction^  sp     -D'DG(
 %!''+

 
	
r   c                     [        S5      e)z/Retrieve opaque pointer for the current contextz5Platform does not define a GetCurrentContext functionNotImplementedErrorr3   s    r   rP   BasePlatform.GetCurrentContext  s    !G
 	
r   c                     [        S5      e)z.Retrieve a GLUT font pointer for this platformz7Platform does not define a GLUT font retrieval functionr   )r   constants     r   rU   BasePlatform.getGLUTFontPointer  s    !I
 	
r   c                     U R                   $ r   )rP   r3   s    r   rQ   "BasePlatform.CurrentContextIsValid  s    %%%r   c                     U R                   $ r   )rs   r3   s    r   r>   BasePlatform.OpenGL  s    wwr   r   )r   r   r   r   r0   rZ   rb   rW   r   r]   rd   rk   ru   rz   r   r   c_intr   rR   r   rS   rT   rV   rP   rU   r	   rQ   r>   r    r!   r   r   rN   rN   C   s    ,	N ! $)!.	 B <<:@ <<?BB< 1 
L <<*
X

 & &  r   rN   c                   F    \ rS rSrSr     S
S jrSrS r\rS r	S r
S	rg)r   i  z4Function-pointer-like object for undefined functionsNFc                     SSK Jn  Xl        X l        XPl        X@l        S U l        X0l        X`l        Xpl	        Xl
        Xl        Xl        g r;   )r>   r=   r   r   r   r   ri   r   r   r   r   rj   r   )r   r\   rc   r   r   r   r   r   r   rj   r   r=   s               r   r   _NullFunctionPointer.__init__  sB     	!  !"$*.r   c                     U R                   (       d2  U R                  (       d  U R                  (       a  U R                  5         U R                   $ )z"Make this object appear to be NULL)resolvedr   r   loadr3   s    r   __nonzero__ _NullFunctionPointer.__nonzero__  s*    DNNd6J6JIIK}}r   c                     SSK Jn   UR
                  R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S9	n[!        UR"                  5      U R$                  l        SU l        U$ ! [         a#    [        (       a  [        R	                  S5         gf = f! [(         a
  n SnAgSnAff = f)zGAttempt to load the function again, presumably with a context this timer   )platformz/Platform import failed (likely during shutdown)N)r   r   r   r   r   rj   r   T)r>   r   ImportErrorloginforY   r   r   r   r   r   r   r   r   rj   r   staticmethodrC   	__class__r   r7   )r   r   r'   r   s       r   r   _NullFunctionPointer.load  s    	'
	$$66<<HH.."00 $ 4 4 7 
D '34==&ADNN# DMK-  	sJK	   		s#   B1 A;C! 1*CC!
C50C5c                     U R                  5       (       a  U " U0 UD6$  SSKJn  UR                  SU R                  < SU R                  < S35      e! [
         a
  n S nAg S nAff = f)Nr   r<   z&Attempt to call an undefined function z, check for bool(z) before calling)r   r>   r=   NullFunctionErrorr   r   )r   rA   rB   r=   r   s        r   rC   _NullFunctionPointer.__call__  sd    99;;'''(
 --  	  s   A 
A'"A')r   r   r   r   r   r   ri   rj   r   r   r   r   )NNFNN)r   r   r   r   r0   r   r   r   __bool__r   rC   r    r!   r   r   r   r     s8    > /6 H H:r   r   c                       \ rS rSrSrS rSrg)r   i  Tc                 N    SSK Jn  UR                  SU R                  < S35      e)Nr   r<   z&Attempt to call a deprecated function zv while OpenGL in FORWARD_COMPATIBLE_ONLY mode.  Set OpenGL.FORWARD_COMPATIBLE_ONLY to False to use legacy entry points)r>   r=   r   r   r@   s       r   rC   #_DeprecatedFunctionPointer.__call__  s$     %%}}
 	
r   r!   N)r   r   r   r   r   rC   r    r!   r   r   r   r     s    J
r   r   )r0   r   OpenGL.platformr   OpenGL._bytesr   rF   loggingr>   r   r   r   	getLoggerr   r   objectr	   r#   rL   rN   r   r   r!   r   r   <module>r      s}     ( "   +!F )F )< # 
Z6 Zz
U6 Up	
!5 	
r   