a
    ij                     @   s   d Z ddlZddlZddlZejdZes8dejd< ne dkrLedddl	m
Z ddlmZ dd	 Zdaejd
ejd
ejd
ejd
ejdejd
ejejejejejejejfZG dd dZdS )HAn EGL context for headless accelerated OpenGL rendering on GPU devices.    NPYOPENGL_PLATFORMZeglzCannot use EGL rendering platform. The PYOPENGL_PLATFORM environment variable is set to {!r} (should be either unset or 'egl').)egl_ext)errorc               	   C   s   t  } tjdd}|du r$| }nPt|}d|  krDt| k sdn tdt| d  d| d| ||d  }|D ]t}t t j	|d}|t j
krxt  t jkrxzt |dd}W n tjy   Y qx0 |t jkrxt  t jkrx|  S qxt j
S )z8Creates an initialized EGL display directly on a device.ZMUJOCO_EGL_DEVICE_IDNr   zOThe MUJOCO_EGL_DEVICE_ID environment variable must be an integer between 0 and    z (inclusive), got .)EGLZeglQueryDevicesEXTosenvirongetintlenRuntimeErrorZeglGetPlatformDisplayEXTZEGL_PLATFORM_DEVICE_EXTEGL_NO_DISPLAYZeglGetErrorZEGL_SUCCESSZeglInitializer   ZGLErrorZEGL_TRUE)Zall_devicesZselected_device
candidatesZ
device_idxZdevicedisplayZinitialized r   S/home/ghrups/robot-bench/.venv/lib64/python3.9/site-packages/mujoco/egl/__init__.py%create_initialized_egl_device_display#   s4    

r         c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )	GLContextr   c                 C   s   ~~t  }d}tj|  }t  td u rRt attjkrDtdt	
tjt ttt||| |jdk r|tdtttj tt|d tjd | _| jstdd S )Nr   zCannot initialize a EGL device display. This likely means that your EGL driver does not support the PLATFORM_DEVICE extension, which is required for creating a headless rendering context.zVEGL failed to find a framebuffer configuration that matches the desired attributes: {}r   zCannot create an EGL context.)ctypesZc_longr   Z	EGLConfigeglReleaseThreadEGL_DISPLAYr   r   ImportErroratexitregisterZeglTerminateZeglChooseConfigEGL_ATTRIBUTESvaluer   formatZ
eglBindAPIZEGL_OPENGL_APIZeglCreateContextEGL_NO_CONTEXT_context)self	max_width
max_heightZnum_configsZconfig_sizeZconfigsr   r   r   __init__U   s>    

zGLContext.__init__c                 C   s"   t tt jt j| jstdd S )Nz'Failed to make the EGL context current.)r   eglMakeCurrentr   EGL_NO_SURFACEr"   r   r#   r   r   r   make_currentw   s    zGLContext.make_currentc                 C   sV   | j rLt }|r6| j j|jkr6tttjtjtj tt| j  t	  d| _ dS )z-Frees resources associated with this context.N)
r"   r   ZeglGetCurrentContextaddressr'   r   r(   r!   ZeglDestroyContextr   )r#   Zcurrent_contextr   r   r   free}   s    
zGLContext.freec                 C   s   |    d S )N)r,   r)   r   r   r   __del__   s    zGLContext.__del__N)__name__
__module____qualname____doc__r&   r*   r,   r-   r   r   r   r   r   R   s
   "r   )r1   r   r   r	   r
   r   r   lowerr   Z
mujoco.eglr   r   ZOpenGLr   r   r   ZEGL_RED_SIZEZEGL_GREEN_SIZEZEGL_BLUE_SIZEZEGL_ALPHA_SIZEZEGL_DEPTH_SIZEZEGL_STENCIL_SIZEZEGL_COLOR_BUFFER_TYPEZEGL_RGB_BUFFERZEGL_SURFACE_TYPEZEGL_PBUFFER_BITZEGL_RENDERABLE_TYPEZEGL_OPENGL_BITZEGL_NONEr   r   r   r   r   r   <module>   s4   