[cogl/wip/cogl-1.12: 5/9] Adds gles2-context renderer constraint
- From: Tomeu Vizoso <tomeuv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/wip/cogl-1.12: 5/9] Adds gles2-context renderer constraint
- Date: Tue, 19 Jun 2012 11:11:30 +0000 (UTC)
commit e9c6f5fb8300f98ee16dfd09e9ab666b7726a8a0
Author: Robert Bragg <robert linux intel com>
Date: Thu Apr 26 12:18:56 2012 +0100
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>
Conflicts:
cogl/cogl-renderer.c
cogl/cogl-renderer.c | 51 ++++++++++++++++++++++++++++++++----
cogl/cogl-renderer.h | 7 ++++-
cogl/cogl-types.h | 3 +-
cogl/winsys/cogl-winsys-egl.c | 3 +-
examples/cogl-gles2-context.c | 10 ++++++-
examples/cogl-gles2-gears.c | 10 ++++++-
tests/conform/test-conform-main.c | 2 +-
tests/conform/test-utils.c | 6 ++++
tests/conform/test-utils.h | 11 ++++---
9 files changed, 84 insertions(+), 19 deletions(-)
---
diff --git a/cogl/cogl-renderer.c b/cogl/cogl-renderer.c
index d07a3ca..901b52c 100644
--- a/cogl/cogl-renderer.c
+++ b/cogl/cogl-renderer.c
@@ -142,7 +142,9 @@ static void
_cogl_renderer_free (CoglRenderer *renderer)
{
const CoglWinsysVtable *winsys = _cogl_renderer_get_winsys (renderer);
- winsys->renderer_disconnect (renderer);
+
+ if (winsys)
+ winsys->renderer_disconnect (renderer);
#ifndef HAVE_DIRECTLY_LINKED_GL_LIBRARY
if (renderer->libgl_module)
@@ -239,10 +241,25 @@ _cogl_renderer_choose_driver (CoglRenderer *renderer,
{
const char *driver_name = g_getenv ("COGL_DRIVER");
const char *libgl_name;
+ gboolean support_gles2_constraint = FALSE;
+ GList *l;
if (!driver_name)
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
if (renderer->driver_override == COGL_DRIVER_GL ||
(renderer->driver_override == COGL_DRIVER_ANY &&
@@ -282,7 +299,17 @@ _cogl_renderer_choose_driver (CoglRenderer *renderer,
"No suitable driver found");
return FALSE;
- 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
@@ -310,6 +337,7 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
{
int i;
GString *error_message;
+ gboolean constraints_failed = FALSE;
if (renderer->connected)
return TRUE;
@@ -326,7 +354,7 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
const CoglWinsysVtable *winsys = _cogl_winsys_vtable_getters[i]();
GError *tmp_error = NULL;
GList *l;
- gboolean constraints_failed = FALSE;
+ gboolean skip_due_to_constraints = FALSE;
if (renderer->winsys_id_override != COGL_WINSYS_ID_ANY)
{
@@ -348,12 +376,15 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
CoglRendererConstraint constraint = GPOINTER_TO_UINT (l->data);
if (!(winsys->constraints & constraint))
{
- constraints_failed = TRUE;
+ skip_due_to_constraints = TRUE;
break;
}
}
- if (constraints_failed)
- continue;
+ if (skip_due_to_constraints)
+ {
+ constraints_failed |= TRUE;
+ continue;
+ }
/* At least temporarily we will associate this winsys with
* the renderer in-case ->renderer_connect calls API that
@@ -376,6 +407,14 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
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;
g_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_INIT,
diff --git a/cogl/cogl-renderer.h b/cogl/cogl-renderer.h
index 6332327..6ad95fb 100644
--- a/cogl/cogl-renderer.h
+++ b/cogl/cogl-renderer.h
@@ -261,6 +261,10 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error);
* @COGL_RENDERER_CONSTRAINT_USES_XLIB: Require the renderer to be X11
* based and use Xlib
* @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
* 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_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;
diff --git a/cogl/cogl-types.h b/cogl/cogl-types.h
index 92c5e9a..28e3f1e 100644
--- a/cogl/cogl-types.h
+++ b/cogl/cogl-types.h
@@ -698,7 +698,8 @@ typedef enum
typedef enum { /*< prefix=COGL_RENDERER_ERROR >*/
COGL_RENDERER_ERROR_NOT_FOUND,
- COGL_RENDERER_ERROR_XLIB_DISPLAY_OPEN
+ COGL_RENDERER_ERROR_XLIB_DISPLAY_OPEN,
+ COGL_RENDERER_ERROR_BAD_CONSTRAINT
} CoglRendererError;
/*
diff --git a/cogl/winsys/cogl-winsys-egl.c b/cogl/winsys/cogl-winsys-egl.c
index b7dbc85..6932f62 100644
--- a/cogl/winsys/cogl-winsys-egl.c
+++ b/cogl/winsys/cogl-winsys-egl.c
@@ -814,7 +814,8 @@ _cogl_winsys_restore_context (CoglContext *ctx)
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
winsys's so it does not have an ID or a name */
diff --git a/examples/cogl-gles2-context.c b/examples/cogl-gles2-context.c
index c25b73d..408852a 100644
--- a/examples/cogl-gles2-context.c
+++ b/examples/cogl-gles2-context.c
@@ -79,8 +79,14 @@ main (int argc, char **argv)
};
GSource *cogl_source;
GMainLoop *loop;
-
- data.ctx = cogl_context_new (NULL, NULL);
+ CoglRenderer *renderer;
+ CoglDisplay *display;
+
+ 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);
cogl_onscreen_show (onscreen);
diff --git a/examples/cogl-gles2-gears.c b/examples/cogl-gles2-gears.c
index f77e550..2952ca6 100644
--- a/examples/cogl-gles2-gears.c
+++ b/examples/cogl-gles2-gears.c
@@ -758,8 +758,14 @@ main (int argc, char **argv)
GError *error = NULL;
GSource *cogl_source;
GMainLoop *loop;
-
- data.ctx = cogl_context_new (NULL, NULL);
+ CoglRenderer *renderer;
+ CoglDisplay *display;
+
+ 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);
cogl_onscreen_show (onscreen);
diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c
index 5673fbc..7854001 100644
--- a/tests/conform/test-conform-main.c
+++ b/tests/conform/test-conform-main.c
@@ -97,7 +97,7 @@ main (int argc, char **argv)
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]);
diff --git a/tests/conform/test-utils.c b/tests/conform/test-utils.c
index 2259173..67deb13 100644
--- a/tests/conform/test-utils.c
+++ b/tests/conform/test-utils.c
@@ -76,6 +76,12 @@ test_utils_init (TestFlags flags)
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)
{
missing_requirement = TRUE;
diff --git a/tests/conform/test-utils.h b/tests/conform/test-utils.h
index 727aea8..857da2f 100644
--- a/tests/conform/test-utils.h
+++ b/tests/conform/test-utils.h
@@ -9,11 +9,12 @@
typedef enum _TestFlags
{
- TEST_KNOWN_FAILURE = 1<<0,
- TEST_REQUIREMENT_GL = 1<<1,
- TEST_REQUIREMENT_NPOT = 1<<2,
- TEST_REQUIREMENT_TEXTURE_3D = 1<<3,
- TEST_REQUIREMENT_POINT_SPRITE = 1<<4
+ TEST_KNOWN_FAILURE = 1<<0,
+ TEST_REQUIREMENT_GL = 1<<1,
+ TEST_REQUIREMENT_NPOT = 1<<2,
+ TEST_REQUIREMENT_TEXTURE_3D = 1<<3,
+ TEST_REQUIREMENT_POINT_SPRITE = 1<<4,
+ TEST_REQUIREMENT_GLES2_CONTEXT = 1<<5
} TestFlags;
extern CoglContext *ctx;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]