diff --git a/cogl/cogl-internal.h b/cogl/cogl-internal.h index 0cc2f9bec..5c9a0979b 100644 --- a/cogl/cogl-internal.h +++ b/cogl/cogl-internal.h @@ -90,13 +90,6 @@ typedef enum { /*< prefix=COGL_DRIVER_ERROR >*/ COGL_DRIVER_ERROR_FAILED_TO_LOAD_LIBRARY } CoglDriverError; -typedef enum -{ - COGL_DRIVER_GL, - COGL_DRIVER_GLES1, - COGL_DRIVER_GLES2 -} CoglDriver; - typedef enum { COGL_PRIVATE_FEATURE_TEXTURE_2D_FROM_EGL_IMAGE = 1L<<0, diff --git a/cogl/cogl-renderer-private.h b/cogl/cogl-renderer-private.h index bdc505da6..11dc0bb07 100644 --- a/cogl/cogl-renderer-private.h +++ b/cogl/cogl-renderer-private.h @@ -42,6 +42,7 @@ struct _CoglRenderer { CoglObject _parent; gboolean connected; + CoglDriver driver_override; const CoglWinsysVtable *winsys_vtable; CoglWinsysID winsys_id_override; GList *constraints; diff --git a/cogl/cogl-renderer.c b/cogl/cogl-renderer.c index 2af1f74b4..1c6a28b84 100644 --- a/cogl/cogl-renderer.c +++ b/cogl/cogl-renderer.c @@ -245,7 +245,9 @@ _cogl_renderer_choose_driver (CoglRenderer *renderer, driver_name = _cogl_config_driver; #ifdef HAVE_COGL_GL - if (driver_name == NULL || !g_ascii_strcasecmp (driver_name, "gl")) + if (renderer->driver_override == COGL_DRIVER_GL || + (renderer->driver_override == COGL_DRIVER_ANY && + (driver_name == NULL || !g_ascii_strcasecmp (driver_name, "gl")))) { renderer->driver = COGL_DRIVER_GL; libgl_name = COGL_GL_LIBNAME; @@ -254,7 +256,9 @@ _cogl_renderer_choose_driver (CoglRenderer *renderer, #endif #ifdef HAVE_COGL_GLES2 - if (driver_name == NULL || !g_ascii_strcasecmp (driver_name, "gles2")) + if (renderer->driver_override == COGL_DRIVER_GLES2 || + (renderer->driver_override == COGL_DRIVER_ANY && + (driver_name == NULL || !g_ascii_strcasecmp (driver_name, "gles2")))) { renderer->driver = COGL_DRIVER_GLES2; libgl_name = COGL_GLES2_LIBNAME; @@ -263,7 +267,9 @@ _cogl_renderer_choose_driver (CoglRenderer *renderer, #endif #ifdef HAVE_COGL_GLES - if (driver_name == NULL || !g_ascii_strcasecmp (driver_name, "gles1")) + if (renderer->driver_override == COGL_DRIVER_GLES1 || + (renderer->driver_override == COGL_DRIVER_ANY && + (driver_name == NULL || !g_ascii_strcasecmp (driver_name, "gles1")))) { renderer->driver = COGL_DRIVER_GLES1; libgl_name = COGL_GLES1_LIBNAME; @@ -505,3 +511,18 @@ cogl_renderer_remove_constraint (CoglRenderer *renderer, GUINT_TO_POINTER (constraint)); } +void +cogl_renderer_set_driver (CoglRenderer *renderer, + CoglDriver driver) +{ + _COGL_RETURN_IF_FAIL (!renderer->connected); + renderer->driver_override = driver; +} + +CoglDriver +cogl_renderer_get_driver (CoglRenderer *renderer) +{ + _COGL_RETURN_VAL_IF_FAIL (renderer->connected, 0); + + return renderer->driver; +} diff --git a/cogl/cogl-renderer.h b/cogl/cogl-renderer.h index 06b0f5c19..63323279c 100644 --- a/cogl/cogl-renderer.h +++ b/cogl/cogl-renderer.h @@ -319,6 +319,62 @@ void cogl_renderer_remove_constraint (CoglRenderer *renderer, CoglRendererConstraint constraint); +/** + * CoglDriver: + * @COGL_DRIVER_ANY: Implies no preference for which driver is used + * @COGL_DRIVER_GL: An OpenGL driver. + * @COGL_DRIVER_GLES1: An OpenGL ES 1.1 driver. + * @COGL_DRIVER_GLES2: An OpenGL ES 2.0 driver. + * + * Identifiers for underlying hardware drivers that may be used by + * Cogl for rendering. + * + * Since: 1.10 + * Stability: unstable + */ +typedef enum +{ + COGL_DRIVER_ANY, + COGL_DRIVER_GL, + COGL_DRIVER_GLES1, + COGL_DRIVER_GLES2 +} CoglDriver; + +/** + * cogl_renderer_set_driver: + * @renderer: An unconnected #CoglRenderer + * + * Requests that Cogl should try to use a specific underlying driver + * for rendering. + * + * If you select an unsupported driver then cogl_renderer_connect() + * will fail and report an error. Most applications should not + * explicitly select a driver and should rely on Cogl automatically + * choosing the driver. + * + * This may only be called on an un-connected #CoglRenderer. + * + * Since: 1.10 + * Stability: unstable + */ +void +cogl_renderer_set_driver (CoglRenderer *renderer, + CoglDriver driver); + +/** + * cogl_renderer_get_driver: + * @renderer: A connected #CoglRenderer + * + * Queries what underlying driver is being used by Cogl. + * + * This may only be called on a connected #CoglRenderer. + * + * Since: 1.10 + * Stability: unstable + */ +CoglDriver +cogl_renderer_get_driver (CoglRenderer *renderer); + G_END_DECLS #endif /* __COGL_RENDERER_H__ */ diff --git a/cogl/winsys/cogl-winsys-egl-kms.c b/cogl/winsys/cogl-winsys-egl-kms.c index 7864bd24c..1f42fe589 100644 --- a/cogl/winsys/cogl-winsys-egl-kms.c +++ b/cogl/winsys/cogl-winsys-egl-kms.c @@ -178,6 +178,8 @@ _cogl_winsys_egl_display_setup (CoglDisplay *display, surfaceless_feature = COGL_EGL_WINSYS_FEATURE_SURFACELESS_GLES2; surfaceless_feature_name = "gles2"; break; + case COGL_DRIVER_ANY: + g_return_val_if_reached (FALSE); } if (!(egl_renderer->private_features & surfaceless_feature))