
    _e%                        d Z ddlZ ej                  d      ZddlmZmZ ddlmZ d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ej&                  r)ddlmZ dZej,                  r	 ddlmZ e G d de      ZndZeZeZeZy# e$ rZej5                  d       Y dZ[2dZ[ww xY w)a  Implementation of OpenGL errors/exceptions

Note that OpenGL-ctypes will also throw standard errors,
such as TypeError or ValueError when appropriate.

ErrorChecker is an _ErrorChecker instance that allows you
to register a new error-checking function for use 
throughout the system.
    NzOpenGL.error)platform_configflags)ArgumentError)ErrorGLErrorGLUError	GLUTErrorGLerrorGLUerror	GLUTerrorr   c                       e Zd ZdZy)r   z6Base class for all PyOpenGL-specific exception classesN__name__
__module____qualname____doc__     ./usr/lib/python3/dist-packages/OpenGL/error.pyr   r      s    @r   r   c                       e Zd ZdZy)	NoContextaS  Raised to indicate that there is no currently active context
    
    Technically almost *any* OpenGL call can segfault if there is 
    no active context.  The OpenGL.CHECK_CONTEXT flag, if enabled 
    will cause this error to be raised whenever a GL or GLU call is 
    issued (via PyOpenGL) if there is no currently valid context.
    Nr   r   r   r   r   r      s    r   r   c                       e Zd ZdZy)	CopyErrorzRaised to indicate that operation requires data-copying
    
    if you set:
        OpenGL.ERROR_ON_COPY = True 
    
    before importing OpenGL.GL, this error will be raised when 
    a passed argument would require a copy to be made.
    Nr   r   r   r   r   r      s    r   r   c                       e Zd ZdZy)NullFunctionErrorz1Error raised when an undefined function is calledNr   r   r   r   r   r   '   s    ;r   r   c                   J    e Zd ZdZ	 	 	 	 	 	 	 d
dZdZd Zd Zd ZddZ	d	 Z
y)r   a  OpenGL core error implementation class
    
    Primary purpose of this error class is to allow for 
    annotating an error with more details about the calling 
    environment so that it's easier to debug errors in the
    wrapping process.
    
    Attributes:
    
        err -- the OpenGL error code for the error 
        result -- the OpenGL result code for the operation
        baseOperation -- the "function" being called
        pyArgs -- the translated set of Python arguments
        cArgs -- the Python objects matching 1:1 the C arguments
        cArguments -- ctypes-level arguments to the operation,
            often raw integers for pointers and the like
        description -- OpenGL description of the error (textual)
    Nc                 l    |||||||f\  | _         | _        | _        | _        | _        | _        | _        y)z:Initialise the GLError, storing metadata for later displayN)errresult
cArgumentsbaseOperationpyArgscArgsdescription)selfr   r   r    r!   r"   r#   r$   s           r   __init__zGLError.__init__=   s@      65
		
Hdk4?TZr   )r   r$   r!   r"   r#   r    r   c                    g }| j                   D ]p  }t        | |d      }||dk(  sd|z  }t        | |      r#|j                   t        | |      ||             L|j                  |d| j	                  |             r | j
                  j                  ddj                  |D cg c]  }|s|	 c}      dS c c}w )z4Create a fully formatted representation of the errorNr$   z	format_%s = z(
	z,
	z
))DISPLAY_ORDERgetattrhasattrappend	shortRepr	__class__r   join)r%   argspropertyvalueformatFunctionxs         r   __str__zGLError.__str__Z   s    ** 
	HT8T3E Hm$;!,h!7D.2KK!=n!=x!PQKK /" 
	  $~~66"1Q"9
  	"s   (B>0B>c           
         | j                   j                  ddj                  d| j                  z  | j	                  d| j
                        xs d| j                  d| j                        xs dfD cg c]  }|r| c}      dS c c}w )z7Produce a much shorter version of the error as a stringz( z, zerr=%sr$    r!   z ))r.   r   r/   r   format_descriptionr$   format_baseOperationr!   )r%   r4   s     r   __repr__zGLError.__repr__k   s     NN##II$((#''8H8HJPb))?D<N<NPVTV# Q 	   
 	
s   3Bc                     |,| j                    	 ddlm}  || j                         x| _        }|y|d| j                  |      S # t        $ r
}Y d}~yd}~ww xY w)z-Format description using GLU's gluErrorStringNr   )gluErrorStringr(   )r   
OpenGL.GLUr<   r$   	Exceptionr-   )r%   r1   r2   r<   r   s        r   r8   zGLError.format_descriptionu   sf    =TXX15+9488+EE 5 =NNE#
 	
	  s   A 	AAc           
      >   t        |t        t        f      r`|r^t        t	        |            dk\  rGt        |t              rd}nd}|dj                  |D cg c]  }| j                  |d       c}      z  S t	        |      }t        |      dk  r|S |dd d	z   S c c}w )
z0Retrieve short representation of the given value(   z	[
		%s
	]z
(
		%s,
	)z,
		Fx   Nu   z...)
isinstancelisttuplelenreprr/   r-   )r%   r2   
firstLeveltemplater4   rs         r   r-   zGLError.shortRepr   s    utEl,3tE{;KR;O5$(+,inn5:01DNN1U+  
 %Mq6C<HTc7U?"s   B
c                 J    t        |d      r|d|j                  S |d|S )z,Format a baseOperation reference for displayr   r(   )r+   r   )r%   r1   r2   s      r   r9   zGLError.format_baseOperation   s&    E:''99'00r   )NNNNNNN)T)r   r   r   r   r&   r)   r5   r:   r8   r-   r9   r   r   r   r   r   *   sC    ( 
(M"	

#"1r   r   c                       e Zd ZdZy)r   zGLU error implementation classNr   r   r   r   r   r          (r   r   c                       e Zd ZdZy)r	   zGLUT error implementation classNr   r   r   r   r	   r	      s    )r   r	   c                       e Zd ZdZy)EGLErrorzEGL error implementation classNr   r   r   r   rP   rP      rM   r   rP   )acceleratesupport)_ErrorCheckerzYOpenGL_accelerate seems to be installed, but unable to import error checking entry point!c                   L    e Zd ZdZdZddefdZd Zd Zd Z		 	 ddZ
d	 Zd
 Zy)rR   a  Per-API error-checking object
            
            Attributes:
                _registeredChecker -- the checking function enabled when 
                    not doing onBegin/onEnd processing
                _currentChecker -- currently active checking function
            Nr   c                    |j                   | _        || _        || _        || _        | j                  r4t
        j                  r| j                  | _        n#| j                  | _        n| j                  | _        | j                  | _
        y)z+Initialize from a platform module/referenceN)CurrentContextIsValid_isValid
_getErrors_noErrorResult_errorClassr   CONTEXT_CHECKINGsafeGetError_registeredCheckernullGetError_currentChecker)r%   r   r!   noErrorResult
errorClasss        r   r&   z_ErrorChecker.__init__   sl     ( > >"/&3##- ??#44262C2C/26///.2.?.?D+'+'>'>$r   c                 6    | j                   | j                  u ryy)z(We are "true" if we actually do anythingFT)r\   r]   r%   s    r   __bool__z_ErrorChecker.__bool__   s    **d.?.?? r   c                 D    | j                         r| j                         S y)z5Check for error, testing for context before operationN)rV   rW   rb   s    r   r[   z_ErrorChecker.safeGetError   s    ==???,,r   c                     | j                   S )z;Used as error-checker when no error checking should be done)rX   rb   s    r   r]   z_ErrorChecker.nullGetError   s    ***r   c                 n    | j                         }|| j                  k7  r| j                  ||||      |S )a  Base GL Error checker compatible with new ctypes errcheck protocol
                
                This function will raise a GLError with just the calling information
                available at the C-calling level, i.e. the error code, cArguments,
                baseOperation and result.  Higher-level code is responsible for any 
                extra annotations.
                
                Note:
                    glCheckError relies on glBegin/glEnd interactions to 
                    prevent glGetError being called during a glBegin/glEnd 
                    sequence.  If you are calling glBegin/glEnd in C you 
                    should call onBegin and onEnd appropriately.
                )r    r!   )r^   rX   rY   )r%   r   r!   r    r0   r   s         r   glCheckErrorz_ErrorChecker.glCheckError   sK    ( **,$---**%/(5	 +   r   c                 &    | j                   | _        y)z?Called by glBegin to record the fact that glGetError won't workN)r]   r^   rb   s    r   onBeginz_ErrorChecker.onBegin   s    '+'8'8$r   c                 &    | j                   | _        y)z<Called by glEnd to record the fact that glGetError will workN)r\   r^   rb   s    r   onEndz_ErrorChecker.onEnd   s    '+'>'>$r   )NN)r   r   r   r   rW   r   r&   rc   r[   r]   rg   ri   rk   r   r   r   rR   rR      sA     J8<AZa ?

+ #	:9?r   rR   )r   logging	getLogger_logOpenGLr   r   ctypesr   __all__r>   r   r   r   r   r   r   r	   rP   ERROR_CHECKINGrQ   rR   ACCELERATE_AVAILABLEOpenGL_accelerate.errorcheckerImportErrorr   warningobjectr   r
   r   r   r   r   <module>rx      s
   w.* )  
AY A  < <o1u o1b) )* *) ) (M--	|D F	?V F	?P M
	_  	|LLy{{	|s   "B? ?CCC