
    _e#                     0   d Z ddlZ ej                  e      ZddlmZ ddlmZm	Z	m
Z
mZmZmZmZ ddlmZ ddlmZmZmZ g dZd Zd	gZee	e
eefD ]l  Z ee      D ]_  ZdZd
D ]4  Zej;                  e      sdZed ee        Zeevs( eee      s2dZ n edu sCejA                  dej                  e       a n  eejB                  ejD                        Z! eejF                  ejH                        Z# eejJ                  ejL                        Z% eejN                  ejP                        Z' eejR                  ejT                        Z) eejV                  ejT                        Z+ eejX                  ejZ                        Z, eej\                  ejZ                        Z.ej^                  Z/ej`                  Z0ejb                  Z1ejd                  Z2ejf                  Z3 G d de4      Z5d Z6d Z7 G d de8      Z9 G d de8      Z: G d de8      Z;y)ay  Convenience module providing common shader entry points

The point of this module is to allow client code to use
OpenGL Core names to reference shader-related operations
even if the local hardware only supports ARB extension-based
shader rendering.

There are also two utility methods compileProgram and compileShader
which make it easy to create demos which are shader-using.
    N)GL)shader_objectsfragment_shadervertex_shadervertex_programgeometry_shader4separate_shader_objectsget_program_binary)	alternate)bytesunicodeas_8_bit)glAttachShaderglDeleteShaderglGetProgramInfoLogglGetShaderInfoLogglGetProgramivglGetShaderivcompileProgramcompileShaderGL_VALIDATE_STATUSGL_LINK_STATUSShaderCompilationErrorShaderValidationErrorShaderLinkErrorc                 4   t        t        |       rt        t        |       }t        |d      rIt        t        t        |       t        t        |            t               | <   t        j                  |        y|t               | <   t        j                  |        yy)N__call__TF)hasattrr   getattrr   moduleglobals__all__append)basenameroots      3/usr/lib/python3/dist-packages/OpenGL/GL/shaders.py_altr(   &   sx    DD"4
#'4 t$GIdO NND"  #GIdONND"    r   )	ObjectARB_ARBARBFTzFound no alternate for: %s.%sc                   :    e Zd ZdZdZd Zd Zd Zd Zd Z	d
dZ
y	)ShaderProgramz0Integer sub-class with context-manager operationFc                     t        |        y)zStart use of the programNglUseProgram)selfs    r'   	__enter__zShaderProgram.__enter__\   s
    dr)   c                     t        d       y)zStop use of the programr   Nr0   )r2   typvaltbs       r'   __exit__zShaderProgram.__exit___   s
    ar)   c                     t        |        t        | t              }|t        k(  rt	        d|dt        |             d| _        | S )zCheck that the program validates
        
        Validation has to occur *after* linking/loading
        
        raises ShaderValidationError on failures
        zValidation failure (): T)glValidateProgramr   r   GL_FALSEr   r   	validated)r2   
validations     r'   check_validatezShaderProgram.check_validatec   sL     	4!#T+=?
!'#T+ 
 r)   c                 l    t        | t              }|t        k(  rt        d|dt	        |             | S )z_Check link status for this program
        
        raises ShaderLinkError on failures
        zLink failure (r:   )r   r   r<   r   r   )r2   link_statuss     r'   check_linkedzShaderProgram.check_linkedu   s<    
 %dN<("!#T+ 
 r)   c                    ddl m}m} ddlm}  |       }t        | t        j                  |       |j                  |j                  f      } |       } |       }t        j                  | |j                  |||       |j                  |fS )aN  Attempt to retrieve binary for this compiled shader
        
        Note that binaries for a program are *not* generally portable,
        they should be used solely for caching compiled programs for 
        local use; i.e. to reduce compilation overhead.
        
        returns (format,binaryData) for the shader program
        r   )GLintGLenum)GLbyteArray)OpenGL.raw.GL._typesrD   rE   OpenGL.arraysrF   r   r
   GL_PROGRAM_BINARY_LENGTHzerosvalueglGetProgramBinary)r2   rD   rE   rF   sizeresultsize2formats           r'   retrievezShaderProgram.retrieve   sr     	6-w0II4Q""TZZM2--tTZZPVX||V##r)   c                     t        j                  | ||t        |             |r| j                          | j	                          | S )zgAttempt to load binary-format for a pre-compiled shader
        
        See notes in retrieve
        )r
   glProgramBinarylenr?   rB   )r2   rP   binaryvalidates       r'   loadzShaderProgram.load   s<    
 	**D&&#f+N!r)   N)T)__name__
__module____qualname____doc__r=   r3   r8   r?   rB   rQ   rW    r)   r'   r.   r.   Y   s(    :I$$$	r)   r.   c                     t               }|j                  d      rt        |t        j                  t
               |j                  d      rt        |t        j                  t
               | D ]  }t        ||        t        |      }t        |       |j                  dd      r|j                          |j                          | D ]  }t        |        |S )a_  Create a new program, attach shaders and validate

    shaders -- arbitrary number of shaders to attach to the
        generated program.
    separable (keyword only) -- set the separable flag to allow 
        for partial installation of shader into the pipeline (see 
        glUseProgramStages)
    retrievable (keyword only) -- set the retrievable flag to 
        allow retrieval of the program binary representation, (see 
        glProgramBinary, glGetProgramBinary)
    validate (keyword only) -- if False, suppress automatic 
        validation against current GL state. In advanced usage 
        the validation can produce spurious errors. Note: this 
        function is *not* really intended for advanced usage,
        if you're finding yourself specifying this flag you 
        likely should be using your own shader management code.

    This convenience function is *not* standard OpenGL,
    but it does wind up being fairly useful for demos
    and the like.  You may wish to copy it to your code
    base to guard against PyOpenGL changes.

    Usage:

        shader = compileProgram(
            compileShader( source, GL_VERTEX_SHADER ),
            compileShader( source2, GL_FRAGMENT_SHADER ),
        )
        glUseProgram( shader )

    Note:
        If (and only if) validation of the linked program
        *passes* then the passed-in shader objects will be
        deleted from the GL.

    returns ShaderProgram() (GLuint) program reference
    raises RuntimeError subclasses {
        ShaderCompilationError, ShaderValidationError, ShaderLinkError,
    } when a link/validation failure occurs
    	separableretrievablerV   T)glCreateProgramgetglProgramParameterir	   GL_PROGRAM_SEPARABLEGL_TRUEr
   "GL_PROGRAM_BINARY_RETRIEVABLE_HINTr   r.   glLinkProgramr?   rB   r   )shadersnamedprogramshaders       r'   r   r      s    R GyyW&=&R&RT[]yyW&8&[&[]df (w'(W&G'yyT"  vNr)   c                    t        | t        t        f      r| g} | D cg c]  }t        |       } }t	        |      }t        ||        t        |       t        |t              }|st        d|dt        |      | |      |S c c}w )a  Compile shader source of given type

    source -- GLSL source-code for the shader
    shaderType -- GLenum GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, etc,

    returns GLuint compiled shader reference
    raises RuntimeError when a compilation failure occurs
    zShader compile failure (r:   )
isinstancer   r   r   glCreateShaderglShaderSourceglCompileShaderr   GL_COMPILE_STATUSr   r   )source
shaderTypesrj   rN   s        r'   r   r      s     6E'?+$*,qx{,F,J'FFF$VF$57F %"F, 
 	
 M! -s   Bc                       e Zd ZdZy)r   z&Raised when a shader compilation failsNrX   rY   rZ   r[   r\   r)   r'   r   r      s    0r)   r   c                       e Zd ZdZy)r   z'Raised when a program fails to validateNru   r\   r)   r'   r   r      s    1r)   r   c                       e Zd ZdZy)r   zRaised when a shader link failsNru   r\   r)   r'   r   r      s    )r)   r   )<r[   logging	getLoggerrX   logOpenGLr   OpenGL.GL.ARBr   r   r   r   r   r	   r
   OpenGL.extensionsr   OpenGL._bytesr   r   r   r"   r(   	_excludesr    dirr%   foundsuffixendswithrT   r$   debugr   glAttachObjectARBglDetachShaderglDetachObjectARBr   glDeleteObjectARBglGetAttachedShadersglGetAttachedObjectsARBr   glGetInfoLogARBr   r   glGetObjectParameterivARBr   r   rp   r   r<   rd   intr.   r   r   RuntimeErrorr   r   r   r\   r)   r'   <module>r      s0  	 g#    ( 0 0" 	?= F F 0 	F}}f&Os6{^,y(T4) $	 E>II:	& B--n.N.NPB--n.N.NPB--n.N.NP ""9"9>;a;ac !7!79W9WY  5 5~7U7UW 2++^-U-UWB--~/W/WY** (( "";;
**ES EN7p:1\ 12L 2*l *r)   