a
    ij                     @   sR   d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	 G dd dej
ZdS )zOSMesa-specific features

To request an OSMesa context, you need to run your script with:

    PYOPENGL_PLATFORM=osmesa

defined in your shell/execution environment.
    N)baseplatformctypesloader)Constant)_typesc                   @   s   e Zd ZdZejjdd dg 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ejdd Zejdd Zdd ZdS )OSMesaPlatformz"OSMesa implementation for PyOpenGLNOSMesac              
   C   sR   zt jtjdtjdW S  tyL } ztdg|jR  W Y d }~n
d }~0 0 d S )Nr   modezUnable to load OpenGL library)r   loadLibraryctypescdllRTLD_GLOBALOSErrorImportErrorargsselferr r   T/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/OpenGL/platform/osmesa.pyGL   s    zOSMesaPlatform.GLc              
   C   sB   zt jtjdtjdW S  ty< } zW Y d }~d S d }~0 0 d S )NGLUr   r   r
   r   r   r   r   r   r   r   r   r      s    zOSMesaPlatform.GLUc              
   C   sB   zt jtjdtjdW S  ty< } zW Y d }~d S d }~0 0 d S )Nglutr   r   r   r   r   r   GLUT'   s    zOSMesaPlatform.GLUTc              
   C   sB   zt jtjdtjdW S  ty< } zW Y d }~d S d }~0 0 d S )NZgler   r   r   r   r   r   GLE1   s    zOSMesaPlatform.GLEc                 C   s   | j S N)r   r   r   r   r   r   ;   s    zOSMesaPlatform.OSMesac                 C   s   | j j}tj|_|S r   )r   ZOSMesaGetCurrentContextr   ZOSMesaContextrestyper   functionr   r   r   GetCurrentContext@   s    z OSMesaPlatform.GetCurrentContextc                 C   s   | j S r   )r!   r   r   r   r   CurrentContextIsValidE   s    z$OSMesaPlatform.CurrentContextIsValidc                 C   s   | j j}tj|_|S r   )r   ZOSMesaGetProcAddressr   c_void_pr   r   r   r   r   getExtensionProcedureH   s    z$OSMesaPlatform.getExtensionProcedurec                 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>Y       z5OSMesaPlatform.getGLUTFontPointer.<locals>.<listcomp>_   Nr    c                 S   s   g | ]}|  qS r   r%   r'   r   r   r   r*   Z   r+   )splitjoinr   r#   Zin_dllr   Z	addressof)r   ZconstantnameZinternalZpointerr   r   r   getGLUTFontPointerN   s    z!OSMesaPlatform.getGLUTFontPointer)__name__
__module____qualname____doc__r   BasePlatformZEXPORTED_NAMESZlazy_propertyr   r   r   r   r   staticmethodr   Z	CFUNCTYPEZDEFAULT_FUNCTION_TYPEr!   r"   r$   r2   r   r   r   r   r      s,   
	
	
	
	




r   )r6   r   Zctypes.utilZOpenGL.platformr   r   ZOpenGL.constantr   ZOpenGL.raw.osmesar   r7   r   r   r   r   r   <module>   s
   