1.1 --- a/src/drivers/video_egl.c Tue Mar 20 08:29:38 2012 +1000
1.2 +++ b/src/drivers/video_egl.c Fri May 29 18:47:05 2015 +1000
1.4 EGL_RENDERABLE_TYPE,EGL_OPENGL_ES2_BIT,
1.5 EGL_NONE, EGL_NONE };
1.7 +static const EGLint alt_attributes[] = {
1.8 + EGL_DEPTH_SIZE, 16,
1.9 + EGL_STENCIL_SIZE, 8,
1.10 + EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
1.11 + EGL_RENDERABLE_TYPE,EGL_OPENGL_ES2_BIT,
1.12 + EGL_NONE, EGL_NONE };
1.14 static const EGLint context_attributes[] = {
1.15 EGL_CONTEXT_CLIENT_VERSION, 2,
1.16 EGL_NONE, EGL_NONE };
1.18 static EGLSurface surface = EGL_NO_SURFACE;
1.19 static gboolean fbo_created = FALSE;
1.21 -gboolean video_egl_set_window(EGLNativeWindowType window, int width, int height, int format)
1.22 +static void video_egl_swap_buffers();
1.23 +static int video_egl_major = 0, video_egl_minor = 0;
1.25 +gboolean video_egl_init()
1.28 - EGLint num_config, major = 0, minor = 0;
1.29 - const EGLint *attribute_list;
1.31 display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
1.32 - if( eglInitialize(display, &major, &minor) != EGL_TRUE ) {
1.33 + if( eglInitialize(display, &video_egl_major, &video_egl_minor) != EGL_TRUE ) {
1.34 logEGLError( "Unable to initialise EGL display" );
1.40 +gboolean video_egl_init_context( EGLNativeWindowType window, int format )
1.43 + EGLint num_config;
1.44 + const EGLint *attribute_list;
1.46 if( format == COLFMT_RGB565 || format == COLFMT_BGRA1555 ) {
1.47 attribute_list = RGB565_attributes;
1.49 attribute_list = RGB888_attributes;
1.51 + eglChooseConfig(display, attribute_list, &config, 1, &num_config);
1.53 + surface = eglCreateWindowSurface(display, config, window, NULL);
1.54 + if( surface == EGL_NO_SURFACE ) {
1.55 + /* Try alternate config in case of failure. This provides a workaround for
1.56 + * the Nokia N900 where eglCreateWindowSurface fails when color attributes
1.57 + * are specified. (bug report: https://bugs.maemo.org/show_bug.cgi?id=9335)
1.59 + eglChooseConfig(display, alt_attributes, &config, 1, &num_config);
1.60 + surface = eglCreateWindowSurface(display, config, window, NULL);
1.62 - eglChooseConfig(display, attribute_list, &config, 1, &num_config);
1.63 + if( surface == EGL_NO_SURFACE ) {
1.64 + logEGLError( "Unable to create EGL surface" );
1.65 + video_egl_shutdown();
1.70 context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attributes);
1.71 if( context == EGL_NO_CONTEXT ) {
1.72 logEGLError( "Unable to create EGL context" );
1.73 - video_egl_clear_window();
1.74 + video_egl_shutdown();
1.78 - surface = eglCreateWindowSurface(display, config, window, NULL);
1.79 - if( surface == EGL_NO_SURFACE ) {
1.80 - logEGLError( "Unable to create EGL surface" );
1.81 - video_egl_clear_window();
1.84 + if( eglMakeCurrent( display, surface, surface, context ) == EGL_FALSE ) {
1.85 + logEGLError( "Unable to make EGL context current" );
1.86 + video_egl_shutdown();
1.90 - if( eglMakeCurrent( display, surface, surface, context ) == EGL_FALSE ) {
1.91 - logEGLError( "Unable to make EGL context current" );
1.92 - video_egl_clear_window();
1.98 - display_egl_driver.capabilities.depth_bits = 16; /* TODO: get from config info */
1.99 - if( !gl_init_driver(&display_egl_driver, TRUE) ) {
1.100 - video_egl_clear_window();
1.101 +gboolean video_egl_init_driver( display_driver_t driver )
1.103 + driver->swap_buffers = video_egl_swap_buffers;
1.104 + driver->capabilities.depth_bits = 16; /* TODO: get from config info */
1.105 + if( !gl_init_driver(driver, TRUE) ) {
1.106 + video_egl_shutdown();
1.109 fbo_created = TRUE;
1.110 - gl_set_video_size(width, height, 0);
1.111 - pvr2_setup_gl_context();
1.112 - INFO( "Initialised EGL %d.%d", major, minor );
1.116 -void video_egl_clear_window()
1.117 +void video_egl_shutdown()
1.119 if( fbo_created ) {
1.120 pvr2_shutdown_gl_context();
1.121 @@ -154,6 +180,24 @@
1.122 eglTerminate(display);
1.123 display = EGL_NO_DISPLAY;
1.127 +gboolean video_egl_set_window(EGLNativeWindowType window, int width, int height, int format)
1.129 + if( ! video_egl_init() ||
1.130 + ! video_egl_init_context( window, format ) ||
1.131 + ! video_egl_init_driver( &display_egl_driver ) ) {
1.134 + gl_set_video_size(width, height, 0);
1.135 + pvr2_setup_gl_context();
1.136 + INFO( "Initialised EGL %d.%d", video_egl_major, video_egl_minor );
1.140 +void video_egl_clear_window()
1.142 + video_egl_shutdown();
1.143 INFO( "Terminated EGL" );