a
    ij*                  
   @   s  d Z ddlmZmZmZ ddlmZmZ ddlZddlm	Z	m
Z
 ddlT ddlmZ dd	 Zeed
dddZeeddZeeddZeeddZeeddZeeddZeeddZeeddZeeddZeeddZeeddZeeddZeejde
jdddZeejde
jdddZeejddd dddjd
dddZee jddddjddd dddZ ee!jd
dddjddd dddjddddjddddZ!ee"jd
dddjdd d dddZ"ddlZdd!l#m$Z$m%Z%m&Z& dd"lm'Z' dd#l(m)Z* dd$lm+Z+m,Z, e-d%d&Z.ej/d'ej0j1de	j2e	j3e4ej5ej6fd(d)ed*Ze+j7dd+Z8ee9d9d
9de8j:;de8j<=d
e8=de8j>Zz[8W n& e?y Z@ zW Y dZ@[@n
dZ@[@0 0 d,d- ZAejBr:eAeCeD_EejBrLeAeFeG_Ee*ed.d/ Ze*e d0d1 Z e*e"d2d3 Z"e*e!d8d4d5Z!e*eHd6d7 ZHdS )9ad  OpenGL extension ARB.shader_objects

This module customises the behaviour of the 
OpenGL.raw.GL.ARB.shader_objects to provide a more 
Python-friendly API

Overview (from the spec)
	
	This extension adds API calls that are necessary to manage shader
	objects and program objects as defined in the OpenGL 2.0 white papers by
	3Dlabs.
	
	The generation of an executable that runs on one of OpenGL's
	programmable units is modeled to that of developing a typical C/C++
	application. There are one or more source files, each of which are
	stored by OpenGL in a shader object. Each shader object (source file)
	needs to be compiled and attached to a program object. Once all shader
	objects are compiled successfully, the program object needs to be linked
	to produce an executable. This executable is part of the program object,
	and can now be loaded onto the programmable units to make it part of the
	current OpenGL state. Both the compile and link stages generate a text
	string that can be queried to get more information. This information
	could be, but is not limited to, compile errors, link errors,
	optimization hints, etc. Values for uniform variables, declared in a
	shader, can be set by the application and used to control a shader's
	behavior.
	
	This extension defines functions for creating shader objects and program
	objects, for compiling shader objects, for linking program objects, for
	attaching shader objects to program objects, and for using a program
	object as part of current state. Functions to load uniform values are
	also defined. Some house keeping functions, like deleting an object and
	querying object state, are also provided.
	
	Although this extension defines the API for creating shader objects, it
	does not define any specific types of shader objects. It is assumed that
	this extension will be implemented along with at least one such
	additional extension for creating a specific type of OpenGL 2.0 shader
	(e.g., the ARB_fragment_shader extension or the ARB_vertex_shader
	extension).

The official definition of this extension is available here:
http://www.opengl.org/registry/specs/ARB/shader_objects.txt
    )platformconstantarrays)
extensionswrapperN)_types_glgets)*)_EXTENSION_NAMEc                  C   s   ddl m}  | tS )z=Return boolean indicating whether this extension is availabler   r   )OpenGLr   ZhasGLExtensionr
   r    r   Z/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/OpenGL/GL/ARB/shader_objects.pyglInitShaderObjectsARB4   s    r   lengthstringvalueparamsZpnameT)sizeZpnameArgorPassInZinfoLogc                 C   s   | fS Nr   xr   r   r   <lambda>s       r   Z	maxLength)   )r   r   countobjc                 C   s   | fS r   r   r   r   r   r   r   z   r   ZmaxCountnamec                 C   s   | fS r   r   r   r   r   r   r      r   r   typesourcec                 C   s   | fS r   r   r   r   r   r   r      r   )bytes_NULL_8_BYTEas_8_bit)_errors)lazy)
converterserrorGL_INFO_LOG_LENGTH_ARBi  glShaderSourceARBzHglShaderSourceARB( GLhandleARB(shaderObj), [bytes(string),...] ) -> None)Z	shaderObjr   r   r   )ZdllZ
resultTypeZargTypesdocZargNames	extension)r   c                    s   d fdd	}|S )z>Generate an error-checking function for compilation operationsNc                    sH   t jj| ||g|R  } t|d  }|sDtj| ||t|d d| S )Nr   )resultbaseOperation
cArgumentsdescription)r$   Z_error_checkerZglCheckErrorglGetObjectParameterivARBr'   ZGLErrorglGetInfoLogARB)r,   r-   r.   argsstatuskeyr   r   GLSLCheckError   s    
z#_afterCheck.<locals>.GLSLCheckError)NNr   )r5   r6   r   r4   r   _afterCheck   s    r7   c                 C   s>   t t|t}|dkr:t|}| ||d| |jtS dS )zrRetrieve the program/shader's error messages as a Python string

    returns string which is '' if no message
    r   N )intr0   r(   ctypescreate_string_bufferr   stripr"   )r-   r   r   logr   r   r   r1      s    
r1   c                 C   s>   t |t}|dkr2tj|f}| ||d| |S tjdS )zBRetrieve the attached objects as an array of GLhandleARB instancesr   N)r   )r0   ZGL_OBJECT_ATTACHED_OBJECTS_ARBr   ZGLuintArrayZzeros)r-   r   r   Zstorager   r   r   glGetAttachedObjectsARB   s    
r>   c                 C   s>   t t|t}|dkr:t|}| ||d| |jtS dS )zsRetrieve the program/shader's source code as a Python string

    returns string which is '' if no source code
    r   Nr8   )r9   r0   Z"GL_OBJECT_SHADER_SOURCE_LENGTH_ARBr:   r;   r   r<   r"   )r-   r   r   r    r   r   r   glGetShaderSourceARB   s    
r?   c           	      C   s   t t|t}|du r$t t|t}||k r|dkr| |||\}}}}t|drb| d}n*t|dr|| d}nt|dr|j}|||fS t	d||d f dS )	zKRetrieve the name, size and type of the uniform of the index in the programNr   tobytes    tostringr   zIndex %s out of range 0 to %ir   )
r9   r0   ZGL_OBJECT_ACTIVE_UNIFORMS_ARBZ'GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARBhasattrr@   rstriprB   r   
IndexError)	r-   programindexZbufSizeZ	max_indexr   r   r   r   r   r   r   glGetActiveUniformARB	  s*    



rH   c                 C   s2   |st dt|}|d tkr(|t }| ||S )z=Check that name is a string with a null byte at the end of itzNon-null name required)
ValueErrorr#   r"   )r-   rF   r   r   r   r   glGetUniformLocationARB#  s    rK   )N)I__doc__r   r   r   r   r   r   r:   ZOpenGL.raw.GLr   r   Z OpenGL.raw.GL.ARB.shader_objectsr
   r   r)   ZsetInputArraySizeZglUniform1fvARBZglUniform2fvARBZglUniform3fvARBZglUniform4fvARBZglUniform1ivARBZglUniform2ivARBZglUniform3ivARBZglUniform4ivARBZglUniformMatrix2fvARBZglUniformMatrix3fvARBZglUniformMatrix4fvARBZglGetObjectParameterfvARBZ	setOutputZ_glget_size_mappingr0   r1   r>   rH   r?   ZOpenGL._bytesr!   r"   r#   r$   ZOpenGL.lazywrapperr%   Z_lazyr&   r'   Constantr(   ZcreateExtensionFunctionZPLATFORMZGLZGLhandleARBZGLsizeiZPOINTERc_char_pZ
GLintArrayZStringLengthsconvZsetPyConverterZstringArrayZsetCResolverZstringArrayForCZsetCConverterZ
totalCount	NameErrorerrr7   ZERROR_CHECKINGZGL_OBJECT_COMPILE_STATUS_ARBZglCompileShaderARBZerrcheckZGL_OBJECT_LINK_STATUS_ARBZglLinkProgramARBrK   r   r   r   r   <module>   s  ,





















	





