return 0;
}
-int gl_init(void *display, void *window, int *quirks, int w, int h)
+int gl_init(void *display, int *quirks)
+{
+ int retval = -1;
+ int ret;
+
+ ret = gl_platform_init(&display, quirks);
+ if (ret != 0) {
+ fprintf(stderr, "gl_platform_init failed with %d\n", ret);
+ return retval;
+ }
+
+ edpy = eglGetDisplay((EGLNativeDisplayType)display);
+ if (edpy == EGL_NO_DISPLAY) {
+ fprintf(stderr, "Failed to get EGL display\n");
+ goto out;
+ }
+
+ if (!eglInitialize(edpy, NULL, NULL)) {
+ fprintf(stderr, "Failed to initialize EGL\n");
+ goto out;
+ }
+ retval = 0;
+
+out:
+ if (retval && edpy != EGL_NO_DISPLAY)
+ gl_shutdown();
+ return retval;
+}
+
+int gl_create(void *window, int *quirks, int w, int h)
{
EGLConfig ecfg = NULL;
EGLint num_config;
EGL_NONE
};
- ret = gl_platform_init(&display, &window, quirks);
+ ret = gl_platform_create(&window, quirks);
if (ret != 0) {
fprintf(stderr, "gl_platform_init failed with %d\n", ret);
return retval;
}
memset(tex_mem, 0, tex_w * tex_h * 2);
- edpy = eglGetDisplay((EGLNativeDisplayType)display);
- if (edpy == EGL_NO_DISPLAY) {
- fprintf(stderr, "Failed to get EGL display\n");
- goto out;
- }
-
- if (!eglInitialize(edpy, NULL, NULL)) {
- fprintf(stderr, "Failed to initialize EGL\n");
- goto out;
- }
-
if (!eglChooseConfig(edpy, config_attr, &ecfg, 1, &num_config)) {
fprintf(stderr, "Failed to choose config (%x)\n", eglGetError());
goto out;
retval = 0;
out:
if (retval && edpy != EGL_NO_DISPLAY)
- gl_finish();
+ gl_destroy();
return retval;
}
gl_have_error("glClear");
}
-void gl_finish(void)
+void gl_destroy(void)
{
if (edpy == EGL_NO_DISPLAY)
return; // nothing to do
eglDestroySurface(edpy, esfc);
esfc = EGL_NO_SURFACE;
}
+
+ gl_es_surface = (void *)esfc;
+
+ if (tex_mem) free(tex_mem);
+ tex_mem = NULL;
+
+ gl_platform_destroy();
+}
+
+void gl_shutdown(void)
+{
if (edpy != EGL_NO_DISPLAY) {
eglTerminate(edpy);
edpy = EGL_NO_DISPLAY;
}
gl_es_display = (void *)edpy;
- gl_es_surface = (void *)esfc;
-
- if (tex_mem) free(tex_mem);
- tex_mem = NULL;
- gl_platform_finish();
+ gl_platform_shutdown();
}
#ifdef HAVE_GLES
-int gl_init(void *display, void *window, int *quirks, int w, int h);
+int gl_init(void *display, int *quirks);
+int gl_create(void *window, int *quirks, int w, int h);
void gl_announce(void);
int gl_flip_v(const void *fb, int w, int h, const float *vertices);
int gl_flip(const void *fb, int w, int h);
void gl_clear(void);
-void gl_finish(void);
+void gl_destroy(void);
+void gl_shutdown(void);
/* for external flips */
extern void *gl_es_display;
#else
-static __inline int gl_init(void *display, void *window, int *quirks, int w, int h)
+static __inline int gl_init(void *display, int *quirks)
+{
+ return -1;
+}
+
+static __inline int gl_create(void *window, int *quirks, int w, int h)
{
return -1;
}
return -1;
}
static __inline void gl_clear(void) {}
-static __inline void gl_finish(void) {}
+static __inline void gl_destroy(void) {}
+static __inline void gl_shutdown(void) {}
#define gl_es_display (void *)0
#define gl_es_surface (void *)0
vc_dispmanx_update_submit_sync(m_dispmanUpdate);
}
-int gl_platform_init(void **display, void **window, int *quirks)
+int gl_platform_init(void **display, int *quirks)
{
x11display = NULL;
- x11window = 0;
x11lib = dlopen("libX11.so.6", RTLD_LAZY);
if (x11lib != NULL) {
&& pXTranslateCoordinates != NULL)
{
x11display = *display;
- x11window = (Window)*window;
}
}
bcm_host_init();
- submit_rect();
*display = EGL_DEFAULT_DISPLAY;
+
+ return gl_load();
+}
+
+int gl_platform_create(void **window, int *quirks)
+{
+ x11window = 0;
+
+ if (x11lib != NULL) {
+ x11window = (Window)*window;
+ }
+
+ submit_rect();
+
*window = &m_nativeWindow;
*quirks |= GL_QUIRK_ACTIVATE_RECREATE;
- return gl_load();
+ return !x11lib;
}
-void gl_platform_finish(void)
+void gl_platform_destroy(void)
+{
+ vc_dispmanx_display_close(m_dispmanDisplay);
+
+ x11window = 0;
+}
+
+void gl_platform_shutdown(void)
{
gl_unload();
- vc_dispmanx_display_close(m_dispmanDisplay);
bcm_host_deinit();
if (x11lib) {
}
x11display = NULL;
- x11window = 0;
}
#else
-int gl_platform_init(void **display, void **window, int *quirks)
+int gl_platform_init(void **display, int *quirks)
{
return gl_load();
}
-void gl_platform_finish(void)
+int gl_platform_create(void **window, int *quirks)
+{
+ return 0;
+}
+
+void gl_platform_destroy(void)
+{
+}
+
+void gl_platform_shutdown(void)
{
gl_unload();
}
-int gl_platform_init(void **display, void **window, int *quirks);
-void gl_platform_finish(void);
+int gl_platform_init(void **display, int *quirks);
+int gl_platform_create(void **window, int *quirks);
+void gl_platform_destroy(void);
+void gl_platform_shutdown(void);
plat_sdl_overlay = NULL;
}
if (plat_sdl_gl_active) {
- gl_finish();
+ gl_destroy();
plat_sdl_gl_active = 0;
}
}
else if (plat_target.vout_method == vout_mode_gl) {
int sw = plat_sdl_screen->w, sh = plat_sdl_screen->h;
- plat_sdl_gl_active = (gl_init(display, window, &gl_quirks, sw, sh) == 0);
+ plat_sdl_gl_active = (gl_create(window, &gl_quirks, sw, sh) == 0);
if (!plat_sdl_gl_active) {
fprintf(stderr, "warning: could not init GL.\n");
plat_target.vout_method = 0;
else if (plat_sdl_gl_active) {
if (gl_quirks & GL_QUIRK_ACTIVATE_RECREATE) {
int sw = plat_sdl_screen->w, sh = plat_sdl_screen->h;
- gl_finish();
- plat_sdl_gl_active = (gl_init(display, window, &gl_quirks, sw, sh) == 0);
+ gl_destroy();
+ plat_sdl_gl_active = (gl_create(window, &gl_quirks, sw, sh) == 0);
}
gl_flip(NULL, 0, 0);
}
if (env)
try_gl = atoi(env);
if (try_gl) {
- update_wm_display_window();
- ret = gl_init(display, window, &gl_quirks, g_menuscreen_w, g_menuscreen_h);
+ ret = gl_init(display, &gl_quirks);
+ if (ret == 0) {
+ update_wm_display_window();
+ ret = gl_create(window, &gl_quirks, g_menuscreen_w, g_menuscreen_h);
+ }
}
if (ret == 0) {
gl_announce();
gl_works = 1;
- gl_finish();
+ gl_destroy();
}
i = 0;
plat_sdl_overlay = NULL;
}
if (plat_sdl_gl_active) {
- gl_finish();
+ gl_destroy();
plat_sdl_gl_active = 0;
}
+ gl_shutdown();
+
// restore back to initial resolution
// resolves black screen issue on R-Pi
if (strcmp(vid_drv_name, "x11") != 0)