a
    ij3                     @   s:   d Z ddlZddlZddlmZmZ G dd dejZdS )z%EGL (cross-platform) platform library    N)baseplatformctypesloaderc                       s   e Zd ZdZejdd Zejdd Zejdd Zejdd	 Z	ejd
d Z
ejdd Zejdd Zejdd Zejdd Zejdd ZeejZejdd Zdd Z fddZ  ZS )EGLPlatformz)EGL platform for opengl-es only platformsc                 C   s0   zt jtjdtjdW S  ty*   Y d S 0 d S )NZ	GLESv1_CMmoder   loadLibraryctypescdllRTLD_GLOBALOSErrorself r   Q/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/OpenGL/platform/egl.pyGLES1   s    zEGLPlatform.GLES1c                 C   s0   zt jtjdtjdW S  ty*   Y d S 0 d S )NZGLESv2r   r   r   r   r   r   GLES2   s    zEGLPlatform.GLES2c                 C   s   | j S N)r   r   r   r   r   GLES3   s    zEGLPlatform.GLES3c                 C   s\   z8dD ]&}t jtj|tjd}|r|  W S qtdW n tyV   | jpP| j Y S 0 d S )N)OpenGLGLr   zNo GL/OpenGL library available)r   r   r	   r
   r   r   r   r   )r   namelibr   r   r   r      s    zEGLPlatform.GLc                 C   s0   zt jtjdtjdW S  ty*   Y d S 0 d S )NGLUr   r   r   r   r   r   r   -   s    zEGLPlatform.GLUc                 C   s0   zt jtjdtjdW S  ty*   Y d S 0 d S )Nglutr   r   r   r   r   r   GLUT7   s    zEGLPlatform.GLUTc                 C   s   | j S r   )r   r   r   r   r   r   A   s    zEGLPlatform.OpenGLc              
   C   s   dd l }|jdr`tdd}| }W d    n1 s<0    Y  d|v sVd|v r`| js`J ztjtj	dtj
dW S  ty } ztdg|jR  W Y d }~n
d }~0 0 d S )	Nr   z/proc/cpuinforZBCM2708ZBCM2709EGLr   zUnable to load EGL library)ospathexistsopenreadr   r   r   r	   r
   r   r   ImportErrorargs)r   r   finfoerrr   r   r   r   D   s    &
zEGLPlatform.EGLc                 C   s   | j j}tj|_|S r   )r   eglGetProcAddressr	   c_void_prestype)r   r(   r   r   r   getExtensionProcedureX   s    z!EGLPlatform.getExtensionProcedurec                 C   s0   zt jtjdtjdW S  ty*   Y d S 0 d S )NZgler   r   r   r   r   r   GLE]   s    zEGLPlatform.GLEc                 C   s   | j j}tj|_|S r   )r   eglGetCurrentContextr	   r)   r*   )r   r-   r   r   r   GetCurrentContexti   s    zEGLPlatform.GetCurrentContextc                 C   sT   dd | ddd D }dddd |D  }tj| j|}tt|S )	a  Platform specific function to retrieve a GLUT font pointer

        GLUTAPI void *glutBitmap9By15;
        #define GLUT_BITMAP_9_BY_15		(&glutBitmap9By15)

        Key here is that we want the addressof the pointer in the DLL,
        not the pointer in the DLL.  That is, our pointer is to the
        pointer defined in the DLL, we don't want the *value* stored in
        that pointer.
        c                 S   s   g | ]}|  qS r   title.0xr   r   r   
<listcomp>z       z2EGLPlatform.getGLUTFontPointer.<locals>.<listcomp>_   Nr    c                 S   s   g | ]}|  qS r   r/   r1   r   r   r   r4   {   r5   )splitjoinr	   r)   Zin_dllr   Z	addressof)r   Zconstantr   ZinternalZpointerr   r   r   getGLUTFontPointero   s    zEGLPlatform.getGLUTFontPointerc                    sB   t t| |}ddl}|jddkr>|jds>d|jd< |S )z>Work around SDL not recognising wayland as platform by defaultr   NZXDG_SESSION_TYPEZwaylandZSDL_VIDEODRIVER)superr   installr   environget)r   	namespaceresultr   	__class__r   r   r=      s    
zEGLPlatform.install)__name__
__module____qualname____doc__r   Zlazy_propertyr   r   r   r   r   r   r   r   r+   r,   staticmethodr	   Z	CFUNCTYPEZDEFAULT_FUNCTION_TYPEr.   r;   r=   __classcell__r   r   rB   r   r      s4   
	
	


	
	






r   )rG   r	   Zctypes.utilZOpenGL.platformr   r   ZBasePlatformr   r   r   r   r   <module>   s   