diff --git a/gfx/gfx_context.c b/gfx/gfx_context.c index 494e75ccda..f5763beab7 100644 --- a/gfx/gfx_context.c +++ b/gfx/gfx_context.c @@ -85,24 +85,45 @@ const gfx_ctx_driver_t *gfx_ctx_find_driver(const char *ident) return NULL; } -const gfx_ctx_driver_t *gfx_ctx_init_first(void *data, +static const gfx_ctx_driver_t *ctx_init(void *data, + const gfx_ctx_driver_t *ctx, + const char *driver, enum gfx_ctx_api api, unsigned major, unsigned minor, bool hw_render_ctx) { - unsigned i; - for (i = 0; gfx_ctx_drivers[i]; i++) - { - if (gfx_ctx_drivers[i]->bind_api(data, api, major, minor)) - { - if (gfx_ctx_drivers[i]->bind_hw_render) - { - gfx_ctx_drivers[i]->bind_hw_render(data, - g_settings.video.shared_context && hw_render_ctx); - } + const gfx_ctx_driver_t *tmp = gfx_ctx_find_driver(driver); - if (gfx_ctx_drivers[i]->init(data)) - return gfx_ctx_drivers[i]; - } + if (tmp) + ctx = (const gfx_ctx_driver_t*)tmp; + + if (ctx->bind_api(data, api, major, minor)) + { + if (ctx->bind_hw_render) + ctx->bind_hw_render(data, + g_settings.video.shared_context && hw_render_ctx); + + if (ctx->init(data)) + return ctx; + } + + return NULL; +} + +const gfx_ctx_driver_t *gfx_ctx_init_first(void *data, + const char *driver, + enum gfx_ctx_api api, unsigned major, + unsigned minor, bool hw_render_ctx) +{ + unsigned i; + const gfx_ctx_driver_t *ctx = NULL; + + for (i = 0; gfx_ctx_drivers[i]; i++) + { + ctx = ctx_init(data, gfx_ctx_drivers[i], driver, + api, major, minor, hw_render_ctx); + + if (ctx) + return ctx; } return NULL; diff --git a/gfx/gfx_context.h b/gfx/gfx_context.h index d7920b526d..f9f62c68b5 100644 --- a/gfx/gfx_context.h +++ b/gfx/gfx_context.h @@ -150,8 +150,8 @@ extern const gfx_ctx_driver_t gfx_ctx_null; const gfx_ctx_driver_t *gfx_ctx_find_driver(const char *ident); /* Finds first suitable driver and initializes. */ -const gfx_ctx_driver_t *gfx_ctx_init_first(void *data, enum gfx_ctx_api api, - unsigned major, unsigned minor, bool hw_render_ctx); +const gfx_ctx_driver_t *gfx_ctx_init_first(void *data, const char *driver, + enum gfx_ctx_api api, unsigned major, unsigned minor, bool hw_render_ctx); #ifdef __cplusplus } diff --git a/gfx/gl.c b/gfx/gl.c index 28c0a67397..4ad0f52121 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -2017,39 +2017,8 @@ static const gfx_ctx_driver_t *gl_get_context(gl_t *gl) gl->shared_context_use = g_settings.video.shared_context && cb->context_type != RETRO_HW_CONTEXT_NONE; - if (*g_settings.video.context_driver) - { - const gfx_ctx_driver_t *ctx = gfx_ctx_find_driver( - g_settings.video.context_driver); - - if (ctx) - { - if (!ctx->bind_api(gl, api, major, minor)) - { - RARCH_ERR("Failed to bind API %s to context %s.\n", api_name, g_settings.video.context_driver); - return NULL; - } - - /* Enables or disables offscreen HW context. */ - if (ctx->bind_hw_render) - ctx->bind_hw_render(gl, gl->shared_context_use); - - if (!ctx->init(gl)) - { - RARCH_ERR("Failed to init GL context: %s.\n", ctx->ident); - return NULL; - } - } - else - { - RARCH_ERR("Didn't find GL context: %s.\n", g_settings.video.context_driver); - return NULL; - } - - return ctx; - } - - return gfx_ctx_init_first(gl, api, major, minor, gl->shared_context_use); + return gfx_ctx_init_first(gl, g_settings.video.context_driver, + api, major, minor, gl->shared_context_use); } #ifdef GL_DEBUG