diff mbox

[02/21] gl: Store the GL flavor (Desktop or ES) in the device struct

Message ID 1311602208-5973-2-git-send-email-alexandros.frantzis@linaro.org
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org July 25, 2011, 1:56 p.m. UTC
From: Alexandros Frantzis <alexandros.frantzis@linaro.org>

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 src/cairo-gl-device.c  |    1 +
 src/cairo-gl-info.c    |   16 ++++++++++++++++
 src/cairo-gl-private.h |   11 +++++++++++
 3 files changed, 28 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/src/cairo-gl-device.c b/src/cairo-gl-device.c
index d206da8..35339aa 100644
--- a/src/cairo-gl-device.c
+++ b/src/cairo-gl-device.c
@@ -183,6 +183,7 @@  _cairo_gl_context_init (cairo_gl_context_t *ctx)
 	_cairo_gl_has_extension ("GL_MESA_pack_invert");
 
     ctx->current_operator = -1;
+    ctx->gl_flavor = _cairo_gl_get_flavor ();
 
     status = _cairo_gl_context_init_shaders (ctx);
     if (unlikely (status))
diff --git a/src/cairo-gl-info.c b/src/cairo-gl-info.c
index 168d194..12a618d 100644
--- a/src/cairo-gl-info.c
+++ b/src/cairo-gl-info.c
@@ -55,6 +55,22 @@  _cairo_gl_get_version (void)
     return CAIRO_GL_VERSION_ENCODE (major, minor);
 }
 
+cairo_gl_flavor_t
+_cairo_gl_get_flavor (void)
+{
+    const char *version = (const char *) glGetString (GL_VERSION);
+    cairo_gl_flavor_t flavor;
+
+    if (version == NULL)
+	flavor = CAIRO_GL_FLAVOR_NONE;
+    else if (strstr (version, "OpenGL ES") != NULL)
+	flavor = CAIRO_GL_FLAVOR_ES;
+    else
+	flavor = CAIRO_GL_FLAVOR_DESKTOP;
+
+    return flavor;
+}
+
 cairo_bool_t
 _cairo_gl_has_extension (const char *ext)
 {
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index 73818b1..602550f 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -86,6 +86,13 @@ 
 /* VBO size that we allocate, smaller size means we gotta flush more often */
 #define CAIRO_GL_VBO_SIZE 16384
 
+/* GL flavor */
+typedef enum cairo_gl_flavor {
+    CAIRO_GL_FLAVOR_NONE = 0,
+    CAIRO_GL_FLAVOR_DESKTOP = 1,
+    CAIRO_GL_FLAVOR_ES = 2
+} cairo_gl_flavor_t;
+
 /* Indices for vertex attributes used by BindAttribLocation etc */
 enum {
     CAIRO_GL_VERTEX_ATTRIB_INDEX = 0,
@@ -279,6 +286,7 @@  struct _cairo_gl_context {
     cairo_bool_t has_mesa_pack_invert;
     cairo_gl_dispatch_t dispatch;
     GLfloat modelviewprojection_matrix[16];
+    cairo_gl_flavor_t gl_flavor;
 
     void (*acquire) (void *ctx);
     void (*release) (void *ctx);
@@ -557,6 +565,9 @@  _cairo_gl_shader_fini (cairo_gl_context_t *ctx, cairo_gl_shader_t *shader);
 cairo_private int
 _cairo_gl_get_version (void);
 
+cairo_private cairo_gl_flavor_t
+_cairo_gl_get_flavor (void);
+
 cairo_private cairo_bool_t
 _cairo_gl_has_extension (const char *ext);