
    3j;                         S r SSKr\R                  " 5         \R                  " \5      rSSK7  SSKJrJ	r	J
r
  SS/r " S S\5      rS	 rS
 rg)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)*)bytesunicodeas_8_bitcompileProgramcompileShaderc                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)ShaderProgram   z0Integer sub-class with context-manager operationc                     [        U 5        g)zStart use of the programNglUseProgram)selfs    N/home/wildlama/miniconda3/lib/python3.13/site-packages/OpenGL/GLES2/shaders.py	__enter__ShaderProgram.__enter__   s
    d    c                     [        S5        g)zStop use of the programr   Nr   )r   typvaltbs       r   __exit__ShaderProgram.__exit__   s
    ar   c                     [        U 5        [        U [        5      nU[        :X  a  [	        SU< S[        U 5      < 35      eU $ )zsCheck that the program validates

Validation has to occur *after* linking/loading

raises RuntimeError on failures
zValidation failure (): )glValidateProgramglGetProgramivGL_VALIDATE_STATUSGL_FALSERuntimeErrorglGetProgramInfoLog)r   
validations     r   check_validateShaderProgram.check_validate   sE     	4!#T+=?
!#T+ 
 r   c                 r    [        U [        5      nU[        :X  a  [        SU< S[	        U 5      < 35      eU $ )zDCheck link status for this program

raises RuntimeError on failures
zLink failure (r   )r   GL_LINK_STATUSr   r    r!   )r   link_statuss     r   check_linkedShaderProgram.check_linked0   s<    
 %dN<("#T+ 
 r   c                    SSK JnJn  SSKJn  U" 5       n[        U [        R                  U5        UR                  UR                  45      nU" 5       nU" 5       n[        R                  XR                  XgU5        UR                  U4$ )a  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._typesr+   r,   OpenGL.arraysr-   r   get_program_binaryGL_PROGRAM_BINARY_LENGTHzerosvalueglGetProgramBinary)r   r+   r,   r-   sizeresultsize2formats           r   retrieveShaderProgram.retrieve>   sn     	6-w0II4Q""TZZM2--tZZPVX||V##r   c                     [         R                  XU[        U5      5        U R                  5         U R	                  5         U $ )zOAttempt to load binary-format for a pre-compiled shader

See notes in retrieve
)r0   glProgramBinarylenr#   r(   )r   r8   binarys      r   loadShaderProgram.loadP   s7    
 	**D&#f+Nr    N)__name__
__module____qualname____firstlineno____doc__r   r   r#   r(   r9   r?   __static_attributes__rA   r   r   r
   r
      s#    :"$$r   r
   c                     [        5       nUR                  S5      (       a  [        U[        R                  [
        5        UR                  S5      (       a  [        U[        R                  [
        5        U  H  n[        X#5        M     [        U5      n[        U5        UR                  5         UR                  5         U  H  n[        U5        M     U$ )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)

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 when a link/validation failure occurs
	separableretrievable)glCreateProgramgetglProgramParameteriseparate_shader_objectsGL_PROGRAM_SEPARABLEGL_TRUEr0   "GL_PROGRAM_BINARY_RETRIEVABLE_HINTglAttachShaderr
   glLinkProgramr#   r(   glDeleteShader)shadersnamedprogramshaders       r   r   r   Z   s    B GyyW&=&R&RT[]yyW&8&[&[]dfw' W&G'v Nr   c                 4   [        U [        [        45      (       a  U /n U  Vs/ s H  n[        U5      PM     n n[	        U5      n[        X05        [        U5        [        U[        5      nU[        :X  a  [        SU< S[        U5      < 3U U5      eU$ s  snf )zCompile 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glCompileShaderglGetShaderivGL_COMPILE_STATUSr   r    glGetShaderInfoLog)source
shaderTypesrX   r6   s        r   r   r      s     6E'?++$*,Fqx{FF,J'FF$VF$57F "F, 
 	
 M! -s   B)rF   loggingbasicConfig	getLoggerrB   logOpenGL.GLES2OpenGL._bytesr   r   r   __all__intr
   r   r   rA   r   r   <module>rl      s]   	     #  0 0 
BS BH.^r   