<s> import ctypes <EOL> from egl_constants import * <EOL> verbose = False <EOL> EGL_DEFAULT_DISPLAY = <NUM_LIT:0> <EOL> EGL_NO_CONTEXT = <NUM_LIT:0> <EOL> EGL_NO_DISPLAY = <NUM_LIT:0> <EOL> EGL_NO_SURFACE = <NUM_LIT:0> <EOL> DISPMANX_PROTECTION_NONE = <NUM_LIT:0> <EOL> bcm = ctypes . CDLL ( '<STR_LIT>' ) <EOL> opengles = ctypes . CDLL ( '<STR_LIT>' ) <EOL> openegl = ctypes . CDLL ( '<STR_LIT>' ) <EOL> eglint = ctypes . c_int <EOL> def eglints ( L ) : <EOL> """<STR_LIT>""" <EOL> return ( eglint * len ( L ) ) ( * L ) <EOL> class EGL ( object ) : <EOL> def __init__ ( self , depthbuffer = False ) : <EOL> """<STR_LIT>""" <EOL> b = bcm . bcm_host_init ( ) <EOL> assert b == <NUM_LIT:0> <EOL> self . display = openegl . eglGetDisplay ( EGL_DEFAULT_DISPLAY ) <EOL> assert self . display <EOL> r = openegl . eglInitialize ( self . display , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> assert r <EOL> if depthbuffer : <EOL> attribute_list = eglints ( ( EGL_RED_SIZE , <NUM_LIT:8> , <EOL> EGL_GREEN_SIZE , <NUM_LIT:8> , <EOL> EGL_BLUE_SIZE , <NUM_LIT:8> , <EOL> EGL_ALPHA_SIZE , <NUM_LIT:8> , <EOL> EGL_SURFACE_TYPE , EGL_WINDOW_BIT , <EOL> EGL_DEPTH_SIZE , <NUM_LIT:16> , <EOL> EGL_NONE ) ) <EOL> else : <EOL> attribute_list = eglints ( ( EGL_RED_SIZE , <NUM_LIT:8> , <EOL> EGL_GREEN_SIZE , <NUM_LIT:8> , <EOL> EGL_BLUE_SIZE , <NUM_LIT:8> , <EOL> EGL_ALPHA_SIZE , <NUM_LIT:8> , <EOL> EGL_SURFACE_TYPE , EGL_WINDOW_BIT , <EOL> EGL_NONE ) ) <EOL> numconfig = eglint ( ) <EOL> config = ctypes . c_void_p ( ) <EOL> r = openegl . eglChooseConfig ( self . display , <EOL> ctypes . byref ( attribute_list ) , <EOL> ctypes . byref ( config ) , <NUM_LIT:1> , <EOL> ctypes . byref ( numconfig ) ) <EOL> assert r <EOL> r = openegl . eglBindAPI ( EGL_OPENGL_ES_API ) <EOL> assert r <EOL> if verbose : <EOL> print '<STR_LIT>' , numconfig <EOL> context_attribs = eglints ( ( EGL_CONTEXT_CLIENT_VERSION , <NUM_LIT:2> , EGL_NONE ) ) <EOL> self . context = openegl . eglCreateContext ( self . display , config , <EOL> EGL_NO_CONTEXT , <EOL> ctypes . byref ( context_attribs ) ) <EOL> assert self . context != EGL_NO_CONTEXT <EOL> width = eglint ( ) <EOL> height = eglint ( ) <EOL> s = bcm . graphics_get_display_size ( <NUM_LIT:0> , ctypes . byref ( width ) , ctypes . byref ( height ) ) <EOL> self . width = width . value <EOL> self . height = height . value <EOL> assert s >= <NUM_LIT:0> <EOL> dispman_display = bcm . vc_dispmanx_display_open ( <NUM_LIT:0> ) <EOL> dispman_update = bcm . vc_dispmanx_update_start ( <NUM_LIT:0> ) <EOL> dst_rect = eglints ( ( <NUM_LIT:0> , <NUM_LIT:0> , width . value , height . value ) ) <EOL> src_rect = eglints ( ( <NUM_LIT:0> , <NUM_LIT:0> , width . value << <NUM_LIT:16> , height . value << <NUM_LIT:16> ) ) <EOL> assert dispman_update <EOL> assert dispman_display <EOL> dispman_element = bcm . vc_dispmanx_element_add ( dispman_update , dispman_display , <EOL> <NUM_LIT:0> , ctypes . byref ( dst_rect ) , <NUM_LIT:0> , <EOL> ctypes . byref ( src_rect ) , <EOL> DISPMANX_PROTECTION_NONE , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> bcm . vc_dispmanx_update_submit_sync ( dispman_update ) <EOL> nativewindow = eglints ( ( dispman_element , width , height ) ) <EOL> nw_p = ctypes . pointer ( nativewindow ) <EOL> self . nw_p = nw_p <EOL> self . surface = openegl . eglCreateWindowSurface ( self . display , config , nw_p , <NUM_LIT:0> ) <EOL> assert self . surface != EGL_NO_SURFACE <EOL> r = openegl . eglMakeCurrent ( self . display , self . surface , self . surface , self . context ) <EOL> assert r <EOL> def swap_buffers ( self ) : <EOL> openegl . eglSwapBuffers ( self . display , self . surface ) </s>
