mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 10:00:45 -05:00
Adds gles2-context renderer constraint
This adds a new renderer constraint enum: COGL_RENDERER_CONSTRAINT_SUPPORTS_GLES2_CONTEXT that can be used by applications to ensure the renderer they connect to has support for creating a GLES2 context via cogl_gles2_context_new(). The cogl-gles2-context and cogl-gles2-gears examples and the conformance tests have been updated to use this constraint. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit ed61463d7194354b26624e8014859f0fbfc06a12)
This commit is contained in:
parent
8d0b771cd3
commit
498937083e
@ -241,10 +241,25 @@ _cogl_renderer_choose_driver (CoglRenderer *renderer,
|
|||||||
{
|
{
|
||||||
const char *driver_name = g_getenv ("COGL_DRIVER");
|
const char *driver_name = g_getenv ("COGL_DRIVER");
|
||||||
const char *libgl_name;
|
const char *libgl_name;
|
||||||
|
CoglBool support_gles2_constraint = FALSE;
|
||||||
|
GList *l;
|
||||||
|
|
||||||
if (!driver_name)
|
if (!driver_name)
|
||||||
driver_name = _cogl_config_driver;
|
driver_name = _cogl_config_driver;
|
||||||
|
|
||||||
|
for (l = renderer->constraints; l; l = l->next)
|
||||||
|
{
|
||||||
|
CoglRendererConstraint constraint = GPOINTER_TO_UINT (l->data);
|
||||||
|
if (constraint == COGL_RENDERER_CONSTRAINT_SUPPORTS_COGL_GLES2)
|
||||||
|
{
|
||||||
|
support_gles2_constraint = TRUE;
|
||||||
|
|
||||||
|
if (!driver_name && renderer->driver_override == COGL_DRIVER_ANY)
|
||||||
|
renderer->driver_override = COGL_DRIVER_GLES2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_COGL_GL
|
#ifdef HAVE_COGL_GL
|
||||||
if (renderer->driver_override == COGL_DRIVER_GL ||
|
if (renderer->driver_override == COGL_DRIVER_GL ||
|
||||||
(renderer->driver_override == COGL_DRIVER_ANY &&
|
(renderer->driver_override == COGL_DRIVER_ANY &&
|
||||||
@ -286,6 +301,16 @@ _cogl_renderer_choose_driver (CoglRenderer *renderer,
|
|||||||
|
|
||||||
found:
|
found:
|
||||||
|
|
||||||
|
if (support_gles2_constraint &&
|
||||||
|
renderer->driver != COGL_DRIVER_GLES2)
|
||||||
|
{
|
||||||
|
g_set_error (error,
|
||||||
|
COGL_RENDERER_ERROR,
|
||||||
|
COGL_RENDERER_ERROR_BAD_CONSTRAINT,
|
||||||
|
"No suitable driver found");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef HAVE_DIRECTLY_LINKED_GL_LIBRARY
|
#ifndef HAVE_DIRECTLY_LINKED_GL_LIBRARY
|
||||||
|
|
||||||
renderer->libgl_module = g_module_open (libgl_name,
|
renderer->libgl_module = g_module_open (libgl_name,
|
||||||
@ -312,6 +337,7 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
GString *error_message;
|
GString *error_message;
|
||||||
|
CoglBool constraints_failed = FALSE;
|
||||||
|
|
||||||
if (renderer->connected)
|
if (renderer->connected)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -328,7 +354,7 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
|
|||||||
const CoglWinsysVtable *winsys = _cogl_winsys_vtable_getters[i]();
|
const CoglWinsysVtable *winsys = _cogl_winsys_vtable_getters[i]();
|
||||||
GError *tmp_error = NULL;
|
GError *tmp_error = NULL;
|
||||||
GList *l;
|
GList *l;
|
||||||
CoglBool constraints_failed = FALSE;
|
CoglBool skip_due_to_constraints = FALSE;
|
||||||
|
|
||||||
if (renderer->winsys_id_override != COGL_WINSYS_ID_ANY)
|
if (renderer->winsys_id_override != COGL_WINSYS_ID_ANY)
|
||||||
{
|
{
|
||||||
@ -350,12 +376,15 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
|
|||||||
CoglRendererConstraint constraint = GPOINTER_TO_UINT (l->data);
|
CoglRendererConstraint constraint = GPOINTER_TO_UINT (l->data);
|
||||||
if (!(winsys->constraints & constraint))
|
if (!(winsys->constraints & constraint))
|
||||||
{
|
{
|
||||||
constraints_failed = TRUE;
|
skip_due_to_constraints = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (constraints_failed)
|
if (skip_due_to_constraints)
|
||||||
|
{
|
||||||
|
constraints_failed |= TRUE;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* At least temporarily we will associate this winsys with
|
/* At least temporarily we will associate this winsys with
|
||||||
* the renderer in-case ->renderer_connect calls API that
|
* the renderer in-case ->renderer_connect calls API that
|
||||||
@ -378,6 +407,14 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
|
|||||||
|
|
||||||
if (!renderer->connected)
|
if (!renderer->connected)
|
||||||
{
|
{
|
||||||
|
if (constraints_failed)
|
||||||
|
{
|
||||||
|
g_set_error (error, COGL_RENDERER_ERROR,
|
||||||
|
COGL_RENDERER_ERROR_BAD_CONSTRAINT,
|
||||||
|
"Failed to connected to any renderer due to constraints");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
renderer->winsys_vtable = NULL;
|
renderer->winsys_vtable = NULL;
|
||||||
g_set_error (error, COGL_WINSYS_ERROR,
|
g_set_error (error, COGL_WINSYS_ERROR,
|
||||||
COGL_WINSYS_ERROR_INIT,
|
COGL_WINSYS_ERROR_INIT,
|
||||||
|
@ -261,6 +261,10 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error);
|
|||||||
* @COGL_RENDERER_CONSTRAINT_USES_XLIB: Require the renderer to be X11
|
* @COGL_RENDERER_CONSTRAINT_USES_XLIB: Require the renderer to be X11
|
||||||
* based and use Xlib
|
* based and use Xlib
|
||||||
* @COGL_RENDERER_CONSTRAINT_USES_EGL: Require the renderer to be EGL based
|
* @COGL_RENDERER_CONSTRAINT_USES_EGL: Require the renderer to be EGL based
|
||||||
|
* @COGL_RENDERER_CONSTRAINT_SUPPORTS_COGL_GLES2: Require that the
|
||||||
|
* renderer supports creating a #CoglGLES2Context via
|
||||||
|
* cogl_gles2_context_new(). This can be used to integrate GLES 2.0
|
||||||
|
* code into Cogl based applications.
|
||||||
*
|
*
|
||||||
* These constraint flags are hard-coded features of the different renderer
|
* These constraint flags are hard-coded features of the different renderer
|
||||||
* backends. Sometimes a platform may support multiple rendering options which
|
* backends. Sometimes a platform may support multiple rendering options which
|
||||||
@ -281,7 +285,8 @@ typedef enum
|
|||||||
{
|
{
|
||||||
COGL_RENDERER_CONSTRAINT_USES_X11 = (1 << 0),
|
COGL_RENDERER_CONSTRAINT_USES_X11 = (1 << 0),
|
||||||
COGL_RENDERER_CONSTRAINT_USES_XLIB = (1 << 1),
|
COGL_RENDERER_CONSTRAINT_USES_XLIB = (1 << 1),
|
||||||
COGL_RENDERER_CONSTRAINT_USES_EGL = (1 << 2)
|
COGL_RENDERER_CONSTRAINT_USES_EGL = (1 << 2),
|
||||||
|
COGL_RENDERER_CONSTRAINT_SUPPORTS_COGL_GLES2 = (1 << 3)
|
||||||
} CoglRendererConstraint;
|
} CoglRendererConstraint;
|
||||||
|
|
||||||
|
|
||||||
|
@ -737,7 +737,8 @@ typedef enum
|
|||||||
|
|
||||||
typedef enum { /*< prefix=COGL_RENDERER_ERROR >*/
|
typedef enum { /*< prefix=COGL_RENDERER_ERROR >*/
|
||||||
COGL_RENDERER_ERROR_NOT_FOUND,
|
COGL_RENDERER_ERROR_NOT_FOUND,
|
||||||
COGL_RENDERER_ERROR_XLIB_DISPLAY_OPEN
|
COGL_RENDERER_ERROR_XLIB_DISPLAY_OPEN,
|
||||||
|
COGL_RENDERER_ERROR_BAD_CONSTRAINT
|
||||||
} CoglRendererError;
|
} CoglRendererError;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -809,7 +809,8 @@ _cogl_winsys_restore_context (CoglContext *ctx)
|
|||||||
|
|
||||||
static CoglWinsysVtable _cogl_winsys_vtable =
|
static CoglWinsysVtable _cogl_winsys_vtable =
|
||||||
{
|
{
|
||||||
.constraints = COGL_RENDERER_CONSTRAINT_USES_EGL,
|
.constraints = COGL_RENDERER_CONSTRAINT_USES_EGL |
|
||||||
|
COGL_RENDERER_CONSTRAINT_SUPPORTS_COGL_GLES2,
|
||||||
|
|
||||||
/* This winsys is only used as a base for the EGL-platform
|
/* This winsys is only used as a base for the EGL-platform
|
||||||
winsys's so it does not have an ID or a name */
|
winsys's so it does not have an ID or a name */
|
||||||
|
@ -79,8 +79,14 @@ main (int argc, char **argv)
|
|||||||
};
|
};
|
||||||
GSource *cogl_source;
|
GSource *cogl_source;
|
||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
|
CoglRenderer *renderer;
|
||||||
|
CoglDisplay *display;
|
||||||
|
|
||||||
data.ctx = cogl_context_new (NULL, NULL);
|
renderer = cogl_renderer_new ();
|
||||||
|
cogl_renderer_add_constraint (renderer,
|
||||||
|
COGL_RENDERER_CONSTRAINT_SUPPORTS_COGL_GLES2);
|
||||||
|
display = cogl_display_new (renderer, NULL);
|
||||||
|
data.ctx = cogl_context_new (display, NULL);
|
||||||
|
|
||||||
onscreen = cogl_onscreen_new (data.ctx, 640, 480);
|
onscreen = cogl_onscreen_new (data.ctx, 640, 480);
|
||||||
cogl_onscreen_show (onscreen);
|
cogl_onscreen_show (onscreen);
|
||||||
|
@ -758,8 +758,14 @@ main (int argc, char **argv)
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GSource *cogl_source;
|
GSource *cogl_source;
|
||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
|
CoglRenderer *renderer;
|
||||||
|
CoglDisplay *display;
|
||||||
|
|
||||||
data.ctx = cogl_context_new (NULL, NULL);
|
renderer = cogl_renderer_new ();
|
||||||
|
cogl_renderer_add_constraint (renderer,
|
||||||
|
COGL_RENDERER_CONSTRAINT_SUPPORTS_COGL_GLES2);
|
||||||
|
display = cogl_display_new (renderer, NULL);
|
||||||
|
data.ctx = cogl_context_new (display, NULL);
|
||||||
|
|
||||||
onscreen = cogl_onscreen_new (data.ctx, 300, 300);
|
onscreen = cogl_onscreen_new (data.ctx, 300, 300);
|
||||||
cogl_onscreen_show (onscreen);
|
cogl_onscreen_show (onscreen);
|
||||||
|
@ -99,7 +99,7 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
UNPORTED_TEST (test_viewport);
|
UNPORTED_TEST (test_viewport);
|
||||||
|
|
||||||
ADD_TEST (test_gles2_context, 0);
|
ADD_TEST (test_gles2_context, TEST_REQUIREMENT_GLES2_CONTEXT);
|
||||||
|
|
||||||
g_printerr ("Unknown test name \"%s\"\n", argv[1]);
|
g_printerr ("Unknown test name \"%s\"\n", argv[1]);
|
||||||
|
|
||||||
|
@ -76,6 +76,12 @@ test_utils_init (TestFlags flags)
|
|||||||
missing_requirement = TRUE;
|
missing_requirement = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags & TEST_REQUIREMENT_GLES2_CONTEXT &&
|
||||||
|
!cogl_has_feature (ctx, COGL_FEATURE_ID_GLES2_CONTEXT))
|
||||||
|
{
|
||||||
|
missing_requirement = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (flags & TEST_KNOWN_FAILURE)
|
if (flags & TEST_KNOWN_FAILURE)
|
||||||
{
|
{
|
||||||
missing_requirement = TRUE;
|
missing_requirement = TRUE;
|
||||||
|
@ -13,7 +13,8 @@ typedef enum _TestFlags
|
|||||||
TEST_REQUIREMENT_GL = 1<<1,
|
TEST_REQUIREMENT_GL = 1<<1,
|
||||||
TEST_REQUIREMENT_NPOT = 1<<2,
|
TEST_REQUIREMENT_NPOT = 1<<2,
|
||||||
TEST_REQUIREMENT_TEXTURE_3D = 1<<3,
|
TEST_REQUIREMENT_TEXTURE_3D = 1<<3,
|
||||||
TEST_REQUIREMENT_POINT_SPRITE = 1<<4
|
TEST_REQUIREMENT_POINT_SPRITE = 1<<4,
|
||||||
|
TEST_REQUIREMENT_GLES2_CONTEXT = 1<<5
|
||||||
} TestFlags;
|
} TestFlags;
|
||||||
|
|
||||||
extern CoglContext *ctx;
|
extern CoglContext *ctx;
|
||||||
|
Loading…
Reference in New Issue
Block a user