This looks nice to me, thanks.<div><br></div><div>Reviewed-by: Robert Bragg &lt;<a href="mailto:robert@linux.intel.com">robert@linux.intel.com</a>&gt;<br><br><div class="gmail_quote">On Thu, Mar 22, 2012 at 5:32 PM, Neil Roberts <span dir="ltr">&lt;<a href="mailto:neil@linux.intel.com">neil@linux.intel.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Cogl already had a vtable for the texture driver. This ended up being<br>
used for some things that are not strictly related to texturing such<br>
as converting between pixel formats and GL enums. Some other functions<br>
that are driver dependent such as updating the features were not<br>
indirected through a vtable but instead switched directly by looking<br>
at the ctx-&gt;driver enum value. This patch normalises to the two uses<br>
by adding a separate vtable for driver functions not related to<br>
texturing and moves the pixel format conversion functions to it from<br>
the texture driver vtable. It also adds a context parameter to all of<br>
the functions in the new driver vtable so that they won&#39;t have to rely<br>
on the global context.<br>
---<br>
 cogl/Makefile.am                            |    1 +<br>
 cogl/cogl-atlas.c                           |   18 +-<br>
 cogl/cogl-context-private.h                 |    4 +-<br>
 cogl/cogl-context.c                         |   31 ++--<br>
 cogl/cogl-driver.h                          |   51 ++++++<br>
 cogl/cogl-framebuffer.c                     |    9 +-<br>
 cogl/cogl-private.h                         |    8 -<br>
 cogl/cogl-texture-2d-sliced.c               |    9 +-<br>
 cogl/cogl-texture-2d.c                      |   41 +++--<br>
 cogl/cogl-texture-3d.c                      |   18 +-<br>
 cogl/cogl-texture-driver.h                  |   19 +--<br>
 cogl/cogl-texture-rectangle.c               |   41 +++--<br>
 cogl/cogl-texture.c                         |   30 ++--<br>
 cogl/driver/gl/cogl-gl.c                    |  240 ++++++++++++++++++++++++---<br>
 cogl/driver/gl/cogl-texture-driver-gl.c     |  205 +----------------------<br>
 cogl/driver/gles/cogl-gles.c                |  124 ++++++++++++++-<br>
 cogl/driver/gles/cogl-texture-driver-gles.c |  119 +-------------<br>
 17 files changed, 515 insertions(+), 453 deletions(-)<br>
 create mode 100644 cogl/cogl-driver.h<br>
<br>
diff --git a/cogl/Makefile.am b/cogl/Makefile.am<br>
index 538fbf3..69cb5df 100644<br>
--- a/cogl/Makefile.am<br>
+++ b/cogl/Makefile.am<br>
@@ -196,6 +196,7 @@ cogl_sources_c = \<br>
        $(srcdir)/cogl-display.h                        \<br>
        $(srcdir)/cogl-display.c                        \<br>
        $(srcdir)/cogl-internal.h                       \<br>
+       $(srcdir)/cogl-driver.h                         \<br>
        $(srcdir)/cogl.c                                \<br>
        $(srcdir)/cogl-object-private.h                 \<br>
        $(srcdir)/cogl-object.h                         \<br>
diff --git a/cogl/cogl-atlas.c b/cogl/cogl-atlas.c<br>
index bfa76dc..68f48c0 100644<br>
--- a/cogl/cogl-atlas.c<br>
+++ b/cogl/cogl-atlas.c<br>
@@ -177,10 +177,11 @@ _cogl_atlas_get_initial_size (CoglPixelFormat format,<br>
<br>
   _COGL_GET_CONTEXT (ctx, NO_RETVAL);<br>
<br>
-  ctx-&gt;texture_driver-&gt;pixel_format_to_gl (format,<br>
-                                           &amp;gl_intformat,<br>
-                                           NULL, /* gl_format */<br>
-                                           &amp;gl_type);<br>
+  ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                          format,<br>
+                                          &amp;gl_intformat,<br>
+                                          NULL, /* gl_format */<br>
+                                          &amp;gl_type);<br>
<br>
   /* At least on Intel hardware, the texture size will be rounded up<br>
      to at least 1MB so we might as well try to aim for that as an<br>
@@ -217,10 +218,11 @@ _cogl_atlas_create_map (CoglPixelFormat          format,<br>
<br>
   _COGL_GET_CONTEXT (ctx, NULL);<br>
<br>
-  ctx-&gt;texture_driver-&gt;pixel_format_to_gl (format,<br>
-                                           &amp;gl_intformat,<br>
-                                           NULL, /* gl_format */<br>
-                                           &amp;gl_type);<br>
+  ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                          format,<br>
+                                          &amp;gl_intformat,<br>
+                                          NULL, /* gl_format */<br>
+                                          &amp;gl_type);<br>
<br>
   /* Keep trying increasingly larger atlases until we can fit all of<br>
      the textures */<br>
diff --git a/cogl/cogl-context-private.h b/cogl/cogl-context-private.h<br>
index 6d92faf..a79672f 100644<br>
--- a/cogl/cogl-context-private.h<br>
+++ b/cogl/cogl-context-private.h<br>
@@ -41,6 +41,7 @@<br>
 #include &quot;cogl-buffer-private.h&quot;<br>
 #include &quot;cogl-bitmask.h&quot;<br>
 #include &quot;cogl-atlas.h&quot;<br>
+#include &quot;cogl-driver.h&quot;<br>
 #include &quot;cogl-texture-driver.h&quot;<br>
 #include &quot;cogl-pipeline-cache.h&quot;<br>
 #include &quot;cogl-texture-2d.h&quot;<br>
@@ -62,7 +63,8 @@ struct _CoglContext<br>
<br>
   CoglDriver driver;<br>
<br>
-  /* vtable for the texture driver functions */<br>
+  /* vtables for the driver functions */<br>
+  const CoglDriverVtable *driver_vtable;<br>
   const CoglTextureDriver *texture_driver;<br>
<br>
   /* Features cache */<br>
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c<br>
index 8b1ea2b..8ed3103 100644<br>
--- a/cogl/cogl-context.c<br>
+++ b/cogl/cogl-context.c<br>
@@ -61,9 +61,11 @@<br>
<br>
 #ifdef HAVE_COGL_GL<br>
 extern const CoglTextureDriver _cogl_texture_driver_gl;<br>
+extern const CoglDriverVtable _cogl_driver_gl;<br>
 #endif<br>
 #if defined (HAVE_COGL_GLES) || defined (HAVE_COGL_GLES2)<br>
 extern const CoglTextureDriver _cogl_texture_driver_gles;<br>
+extern const CoglDriverVtable _cogl_driver_gles;<br>
 #endif<br>
<br>
 static void _cogl_context_free (CoglContext *context);<br>
@@ -203,18 +205,11 @@ cogl_context_new (CoglDisplay *display,<br>
      lot throughout Cogl */<br>
   context-&gt;driver = display-&gt;renderer-&gt;driver;<br>
<br>
-  winsys = _cogl_context_get_winsys (context);<br>
-  if (!winsys-&gt;context_init (context, error))<br>
-    {<br>
-      cogl_object_unref (display);<br>
-      g_free (context);<br>
-      return NULL;<br>
-    }<br>
-<br>
   switch (context-&gt;driver)<br>
     {<br>
 #ifdef HAVE_COGL_GL<br>
     case COGL_DRIVER_GL:<br>
+      context-&gt;driver_vtable = &amp;_cogl_driver_gl;<br>
       context-&gt;texture_driver = &amp;_cogl_texture_driver_gl;<br>
       break;<br>
 #endif<br>
@@ -222,6 +217,7 @@ cogl_context_new (CoglDisplay *display,<br>
 #if defined (HAVE_COGL_GLES) || defined (HAVE_COGL_GLES2)<br>
     case COGL_DRIVER_GLES1:<br>
     case COGL_DRIVER_GLES2:<br>
+      context-&gt;driver_vtable = &amp;_cogl_driver_gles;<br>
       context-&gt;texture_driver = &amp;_cogl_texture_driver_gles;<br>
       break;<br>
 #endif<br>
@@ -230,6 +226,14 @@ cogl_context_new (CoglDisplay *display,<br>
       g_assert_not_reached ();<br>
     }<br>
<br>
+  winsys = _cogl_context_get_winsys (context);<br>
+  if (!winsys-&gt;context_init (context, error))<br>
+    {<br>
+      cogl_object_unref (display);<br>
+      g_free (context);<br>
+      return NULL;<br>
+    }<br>
+<br>
   context-&gt;attribute_name_states_hash =<br>
     g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);<br>
   context-&gt;attribute_name_index_map = NULL;<br>
@@ -578,16 +582,7 @@ gboolean<br>
 _cogl_context_update_features (CoglContext *context,<br>
                                GError **error)<br>
 {<br>
-#ifdef HAVE_COGL_GL<br>
-  if (context-&gt;driver == COGL_DRIVER_GL)<br>
-    return _cogl_gl_update_features (context, error);<br>
-#endif<br>
-<br>
-#if defined(HAVE_COGL_GLES) || defined(HAVE_COGL_GLES2)<br>
-  return _cogl_gles_update_features (context, error);<br>
-#endif<br>
-<br>
-  g_assert_not_reached ();<br>
+  return context-&gt;driver_vtable-&gt;update_features (context, error);<br>
 }<br>
<br>
 void<br>
diff --git a/cogl/cogl-driver.h b/cogl/cogl-driver.h<br>
new file mode 100644<br>
index 0000000..b68e37a<br>
--- /dev/null<br>
+++ b/cogl/cogl-driver.h<br>
@@ -0,0 +1,51 @@<br>
+/*<br>
+ * Cogl<br>
+ *<br>
+ * An object oriented GL/GLES Abstraction/Utility Layer<br>
+ *<br>
+ * Copyright (C) 2012 Intel Corporation.<br>
+ *<br>
+ * This library is free software; you can redistribute it and/or<br>
+ * modify it under the terms of the GNU Lesser General Public<br>
+ * License as published by the Free Software Foundation; either<br>
+ * version 2 of the License, or (at your option) any later version.<br>
+ *<br>
+ * This library is distributed in the hope that it will be useful,<br>
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br>
+ * Lesser General Public License for more details.<br>
+ *<br>
+ * You should have received a copy of the GNU Lesser General Public<br>
+ * License along with this library. If not, see &lt;<a href="http://www.gnu.org/licenses/" target="_blank">http://www.gnu.org/licenses/</a>&gt;.<br>
+ *<br>
+ *<br>
+ */<br>
+<br>
+#ifndef __COGL_DRIVER_H<br>
+#define __COGL_DRIVER_H<br>
+<br>
+#include &quot;cogl-context.h&quot;<br>
+<br>
+typedef struct _CoglDriverVtable CoglDriverVtable;<br>
+<br>
+struct _CoglDriverVtable<br>
+{<br>
+  gboolean<br>
+  (* pixel_format_from_gl_internal) (CoglContext *context,<br>
+                                     GLenum gl_int_format,<br>
+                                     CoglPixelFormat *out_format);<br>
+<br>
+  CoglPixelFormat<br>
+  (* pixel_format_to_gl) (CoglContext *context,<br>
+                          CoglPixelFormat format,<br>
+                          GLenum *out_glintformat,<br>
+                          GLenum *out_glformat,<br>
+                          GLenum *out_gltype);<br>
+<br>
+  gboolean<br>
+  (* update_features) (CoglContext *context,<br>
+                       GError **error);<br>
+};<br>
+<br>
+#endif /* __COGL_DRIVER_H */<br>
+<br>
diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c<br>
index 74d595f..647b61d 100644<br>
--- a/cogl/cogl-framebuffer.c<br>
+++ b/cogl/cogl-framebuffer.c<br>
@@ -2005,10 +2005,11 @@ cogl_framebuffer_read_pixels_into_bitmap (CoglFramebuffer *framebuffer,<br>
<br>
   format = cogl_bitmap_get_format (bitmap);<br>
<br>
-  required_format = ctx-&gt;texture_driver-&gt;pixel_format_to_gl (format,<br>
-                                                             &amp;gl_intformat,<br>
-                                                             &amp;gl_format,<br>
-                                                             &amp;gl_type);<br>
+  required_format = ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                                            format,<br>
+                                                            &amp;gl_intformat,<br>
+                                                            &amp;gl_format,<br>
+                                                            &amp;gl_type);<br>
<br>
   /* NB: All offscreen rendering is done upside down so there is no need<br>
    * to flip in this case... */<br>
diff --git a/cogl/cogl-private.h b/cogl/cogl-private.h<br>
index 6130c11..0985ec8 100644<br>
--- a/cogl/cogl-private.h<br>
+++ b/cogl/cogl-private.h<br>
@@ -31,14 +31,6 @@<br>
 G_BEGIN_DECLS<br>
<br>
 gboolean<br>
-_cogl_gl_update_features (CoglContext *context,<br>
-                          GError **error);<br>
-<br>
-gboolean<br>
-_cogl_gles_update_features (CoglContext *context,<br>
-                            GError **error);<br>
-<br>
-gboolean<br>
 _cogl_check_extension (const char *name, const char *ext);<br>
<br>
 void<br>
diff --git a/cogl/cogl-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c<br>
index 836caaf..7150d2b 100644<br>
--- a/cogl/cogl-texture-2d-sliced.c<br>
+++ b/cogl/cogl-texture-2d-sliced.c<br>
@@ -639,10 +639,11 @@ _cogl_texture_2d_sliced_slices_create (CoglContext *ctx,<br>
       slices_for_size = _cogl_pot_slices_for_size;<br>
     }<br>
<br>
-  ctx-&gt;texture_driver-&gt;pixel_format_to_gl (format,<br>
-                                           &amp;gl_intformat,<br>
-                                           NULL,<br>
-                                           &amp;gl_type);<br>
+  ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                          format,<br>
+                                          &amp;gl_intformat,<br>
+                                          NULL,<br>
+                                          &amp;gl_type);<br>
<br>
   /* Negative number means no slicing forced by the user */<br>
   if (tex_2ds-&gt;max_waste &lt;= -1)<br>
diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c<br>
index dad1eac..cd0d522 100644<br>
--- a/cogl/cogl-texture-2d.c<br>
+++ b/cogl/cogl-texture-2d.c<br>
@@ -120,10 +120,11 @@ _cogl_texture_2d_can_create (unsigned int width,<br>
        !_cogl_util_is_pot (height)))<br>
     return FALSE;<br>
<br>
-  ctx-&gt;texture_driver-&gt;pixel_format_to_gl (internal_format,<br>
-                                           &amp;gl_intformat,<br>
-                                           NULL,<br>
-                                           &amp;gl_type);<br>
+  ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                          internal_format,<br>
+                                          &amp;gl_intformat,<br>
+                                          NULL,<br>
+                                          &amp;gl_type);<br>
<br>
   /* Check that the driver can create a texture with that size */<br>
   if (!ctx-&gt;texture_driver-&gt;size_supported (GL_TEXTURE_2D,<br>
@@ -192,10 +193,11 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,<br>
       return NULL;<br>
     }<br>
<br>
-  internal_format = ctx-&gt;texture_driver-&gt;pixel_format_to_gl (internal_format,<br>
-                                                             &amp;gl_intformat,<br>
-                                                             &amp;gl_format,<br>
-                                                             &amp;gl_type);<br>
+  internal_format = ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                                            internal_format,<br>
+                                                            &amp;gl_intformat,<br>
+                                                            &amp;gl_format,<br>
+                                                            &amp;gl_type);<br>
<br>
   tex_2d = _cogl_texture_2d_create_base (width, height, COGL_TEXTURE_NONE,<br>
                                          internal_format);<br>
@@ -382,8 +384,9 @@ cogl_texture_2d_new_from_foreign (CoglContext *ctx,<br>
<br>
       /* If we can query GL for the actual pixel format then we&#39;ll ignore<br>
          the passed in format and use that. */<br>
-      if (!ctx-&gt;texture_driver-&gt;pixel_format_from_gl_internal (gl_int_format,<br>
-                                                               &amp;format))<br>
+      if (!ctx-&gt;driver_vtable-&gt;pixel_format_from_gl_internal (ctx,<br>
+                                                              gl_int_format,<br>
+                                                              &amp;format))<br>
         return COGL_INVALID_HANDLE;<br>
     }<br>
   else<br>
@@ -391,10 +394,11 @@ cogl_texture_2d_new_from_foreign (CoglContext *ctx,<br>
     {<br>
       /* Otherwise we&#39;ll assume we can derive the GL format from the<br>
          passed in format */<br>
-      ctx-&gt;texture_driver-&gt;pixel_format_to_gl (format,<br>
-                                               &amp;gl_int_format,<br>
-                                               NULL,<br>
-                                               NULL);<br>
+      ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                              format,<br>
+                                              &amp;gl_int_format,<br>
+                                              NULL,<br>
+                                              NULL);<br>
     }<br>
<br>
   /* Note: We always trust the given width and height without querying<br>
@@ -812,10 +816,11 @@ _cogl_texture_2d_get_data (CoglTexture     *tex,<br>
<br>
   bpp = _cogl_pixel_format_get_bytes_per_pixel (format);<br>
<br>
-  ctx-&gt;texture_driver-&gt;pixel_format_to_gl (format,<br>
-                                           NULL, /* internal format */<br>
-                                           &amp;gl_format,<br>
-                                           &amp;gl_type);<br>
+  ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                          format,<br>
+                                          NULL, /* internal format */<br>
+                                          &amp;gl_format,<br>
+                                          &amp;gl_type);<br>
<br>
   ctx-&gt;texture_driver-&gt;prep_gl_for_pixels_download (rowstride, bpp);<br>
<br>
diff --git a/cogl/cogl-texture-3d.c b/cogl/cogl-texture-3d.c<br>
index 8662d5a..e33c248 100644<br>
--- a/cogl/cogl-texture-3d.c<br>
+++ b/cogl/cogl-texture-3d.c<br>
@@ -167,10 +167,11 @@ _cogl_texture_3d_can_create (CoglContext *ctx,<br>
       return FALSE;<br>
     }<br>
<br>
-  ctx-&gt;texture_driver-&gt;pixel_format_to_gl (internal_format,<br>
-                                           &amp;gl_intformat,<br>
-                                           NULL,<br>
-                                           &amp;gl_type);<br>
+  ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                          internal_format,<br>
+                                          &amp;gl_intformat,<br>
+                                          NULL,<br>
+                                          &amp;gl_type);<br>
<br>
   /* Check that the driver can create a texture with that size */<br>
   if (!ctx-&gt;texture_driver-&gt;size_supported_3d (GL_TEXTURE_3D,<br>
@@ -213,10 +214,11 @@ cogl_texture_3d_new_with_size (CoglContext *ctx,<br>
                                     error))<br>
     return NULL;<br>
<br>
-  internal_format = ctx-&gt;texture_driver-&gt;pixel_format_to_gl (internal_format,<br>
-                                                             &amp;gl_intformat,<br>
-                                                             &amp;gl_format,<br>
-                                                             &amp;gl_type);<br>
+  internal_format = ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                                            internal_format,<br>
+                                                            &amp;gl_intformat,<br>
+                                                            &amp;gl_format,<br>
+                                                            &amp;gl_type);<br>
<br>
   tex_3d = _cogl_texture_3d_create_base (ctx,<br>
                                          width, height, depth,<br>
diff --git a/cogl/cogl-texture-driver.h b/cogl/cogl-texture-driver.h<br>
index 6cbc3af..07ccdf8 100644<br>
--- a/cogl/cogl-texture-driver.h<br>
+++ b/cogl/cogl-texture-driver.h<br>
@@ -161,22 +161,6 @@ struct _CoglTextureDriver<br>
                                    const GLfloat *transparent_color);<br>
<br>
   /*<br>
-   * XXX: this should live in cogl/{gl,gles}/cogl.c<br>
-   */<br>
-  gboolean<br>
-  (* pixel_format_from_gl_internal) (GLenum            gl_int_format,<br>
-                                     CoglPixelFormat  *out_format);<br>
-<br>
-  /*<br>
-   * XXX: this should live in cogl/{gl,gles}/cogl.c<br>
-   */<br>
-  CoglPixelFormat<br>
-  (* pixel_format_to_gl) (CoglPixelFormat  format,<br>
-                          GLenum          *out_glintformat,<br>
-                          GLenum          *out_glformat,<br>
-                          GLenum          *out_gltype);<br>
-<br>
-  /*<br>
    * It may depend on the driver as to what texture targets may be used when<br>
    * creating a foreign texture. E.g. OpenGL supports ARB_texture_rectangle<br>
    * but GLES doesn&#39;t<br>
@@ -199,7 +183,8 @@ struct _CoglTextureDriver<br>
    * destination has another format.<br>
    */<br>
   CoglPixelFormat<br>
-  (* find_best_gl_get_data_format) (CoglPixelFormat  format,<br>
+  (* find_best_gl_get_data_format) (CoglContext     *context,<br>
+                                    CoglPixelFormat  format,<br>
                                     GLenum          *closest_gl_format,<br>
                                     GLenum          *closest_gl_type);<br>
 };<br>
diff --git a/cogl/cogl-texture-rectangle.c b/cogl/cogl-texture-rectangle.c<br>
index b906f58..a7c4ae2 100644<br>
--- a/cogl/cogl-texture-rectangle.c<br>
+++ b/cogl/cogl-texture-rectangle.c<br>
@@ -128,10 +128,11 @@ _cogl_texture_rectangle_can_create (unsigned int width,<br>
       return FALSE;<br>
     }<br>
<br>
-  ctx-&gt;texture_driver-&gt;pixel_format_to_gl (internal_format,<br>
-                                           &amp;gl_intformat,<br>
-                                           NULL,<br>
-                                           &amp;gl_type);<br>
+  ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                          internal_format,<br>
+                                          &amp;gl_intformat,<br>
+                                          NULL,<br>
+                                          &amp;gl_type);<br>
<br>
   /* Check that the driver can create a texture with that size */<br>
   if (!ctx-&gt;texture_driver-&gt;size_supported (GL_TEXTURE_RECTANGLE_ARB,<br>
@@ -196,10 +197,11 @@ cogl_texture_rectangle_new_with_size (CoglContext *ctx,<br>
                                            internal_format, error))<br>
     return NULL;<br>
<br>
-  internal_format = ctx-&gt;texture_driver-&gt;pixel_format_to_gl (internal_format,<br>
-                                                             &amp;gl_intformat,<br>
-                                                             &amp;gl_format,<br>
-                                                             &amp;gl_type);<br>
+  internal_format = ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                                            internal_format,<br>
+                                                            &amp;gl_intformat,<br>
+                                                            &amp;gl_format,<br>
+                                                            &amp;gl_type);<br>
<br>
   tex_rect = _cogl_texture_rectangle_create_base (width, height,<br>
                                                   internal_format);<br>
@@ -320,8 +322,9 @@ _cogl_texture_rectangle_new_from_foreign (GLuint gl_handle,<br>
<br>
       /* If we can query GL for the actual pixel format then we&#39;ll ignore<br>
          the passed in format and use that. */<br>
-      if (!ctx-&gt;texture_driver-&gt;pixel_format_from_gl_internal (gl_int_format,<br>
-                                                               &amp;format))<br>
+      if (!ctx-&gt;driver_vtable-&gt;pixel_format_from_gl_internal (ctx,<br>
+                                                              gl_int_format,<br>
+                                                              &amp;format))<br>
         return NULL;<br>
     }<br>
   else<br>
@@ -329,10 +332,11 @@ _cogl_texture_rectangle_new_from_foreign (GLuint gl_handle,<br>
     {<br>
       /* Otherwise we&#39;ll assume we can derive the GL format from the<br>
          passed in format */<br>
-      ctx-&gt;texture_driver-&gt;pixel_format_to_gl (format,<br>
-                                               &amp;gl_int_format,<br>
-                                               NULL,<br>
-                                               NULL);<br>
+      ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                              format,<br>
+                                              &amp;gl_int_format,<br>
+                                              NULL,<br>
+                                              NULL);<br>
     }<br>
<br>
   /* Note: We always trust the given width and height without querying<br>
@@ -532,10 +536,11 @@ _cogl_texture_rectangle_get_data (CoglTexture     *tex,<br>
<br>
   bpp = _cogl_pixel_format_get_bytes_per_pixel (format);<br>
<br>
-  ctx-&gt;texture_driver-&gt;pixel_format_to_gl (format,<br>
-                                           NULL, /* internal format */<br>
-                                           &amp;gl_format,<br>
-                                           &amp;gl_type);<br>
+  ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                          format,<br>
+                                          NULL, /* internal format */<br>
+                                          &amp;gl_format,<br>
+                                          &amp;gl_type);<br>
<br>
   ctx-&gt;texture_driver-&gt;prep_gl_for_pixels_download (rowstride, bpp);<br>
<br>
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c<br>
index 6b08ec5..27cbb64 100644<br>
--- a/cogl/cogl-texture.c<br>
+++ b/cogl/cogl-texture.c<br>
@@ -212,24 +212,27 @@ _cogl_texture_prepare_for_upload (CoglBitmap      *src_bmp,<br>
       /* Use the source format from the src bitmap type and the internal<br>
          format from the dst format type so that GL can do the<br>
          conversion */<br>
-      ctx-&gt;texture_driver-&gt;pixel_format_to_gl (src_format,<br>
-                                               NULL, /* internal format */<br>
-                                               out_glformat,<br>
-                                               out_gltype);<br>
-      ctx-&gt;texture_driver-&gt;pixel_format_to_gl (dst_format,<br>
-                                               out_glintformat,<br>
-                                               NULL,<br>
-                                               NULL);<br>
+      ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                              src_format,<br>
+                                              NULL, /* internal format */<br>
+                                              out_glformat,<br>
+                                              out_gltype);<br>
+      ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                              dst_format,<br>
+                                              out_glintformat,<br>
+                                              NULL,<br>
+                                              NULL);<br>
<br>
     }<br>
   else<br>
     {<br>
       CoglPixelFormat closest_format;<br>
<br>
-      closest_format = ctx-&gt;texture_driver-&gt;pixel_format_to_gl (dst_format,<br>
-                                                                out_glintformat,<br>
-                                                                out_glformat,<br>
-                                                                out_gltype);<br>
+      closest_format = ctx-&gt;driver_vtable-&gt;pixel_format_to_gl (ctx,<br>
+                                                               dst_format,<br>
+                                                               out_glintformat,<br>
+                                                               out_glformat,<br>
+                                                               out_gltype);<br>
<br>
       if (closest_format != src_format)<br>
         dst_bmp = _cogl_bitmap_convert (src_bmp, closest_format);<br>
@@ -1148,7 +1151,8 @@ cogl_texture_get_data (CoglTexture     *texture,<br>
     return byte_size;<br>
<br>
   closest_format =<br>
-    ctx-&gt;texture_driver-&gt;find_best_gl_get_data_format (format,<br>
+    ctx-&gt;texture_driver-&gt;find_best_gl_get_data_format (ctx,<br>
+                                                       format,<br>
                                                        &amp;closest_gl_format,<br>
                                                        &amp;closest_gl_type);<br>
<br>
diff --git a/cogl/driver/gl/cogl-gl.c b/cogl/driver/gl/cogl-gl.c<br>
index b35ddbe..6d39033 100644<br>
--- a/cogl/driver/gl/cogl-gl.c<br>
+++ b/cogl/driver/gl/cogl-gl.c<br>
@@ -34,13 +34,199 @@<br>
 #include &quot;cogl-renderer-private.h&quot;<br>
<br>
 static gboolean<br>
-_cogl_get_gl_version (int *major_out, int *minor_out)<br>
+_cogl_driver_pixel_format_from_gl_internal (CoglContext *context,<br>
+                                            GLenum gl_int_format,<br>
+                                            CoglPixelFormat *out_format)<br>
+{<br>
+  /* It doesn&#39;t really matter we convert to exact same<br>
+     format (some have no cogl match anyway) since format<br>
+     is re-matched against cogl when getting or setting<br>
+     texture image data.<br>
+  */<br>
+<br>
+  switch (gl_int_format)<br>
+    {<br>
+    case GL_ALPHA: case GL_ALPHA4: case GL_ALPHA8:<br>
+    case GL_ALPHA12: case GL_ALPHA16:<br>
+<br>
+      *out_format = COGL_PIXEL_FORMAT_A_8;<br>
+      return TRUE;<br>
+<br>
+    case GL_LUMINANCE: case GL_LUMINANCE4: case GL_LUMINANCE8:<br>
+    case GL_LUMINANCE12: case GL_LUMINANCE16:<br>
+<br>
+      *out_format = COGL_PIXEL_FORMAT_G_8;<br>
+      return TRUE;<br>
+<br>
+    case GL_RGB: case GL_RGB4: case GL_RGB5: case GL_RGB8:<br>
+    case GL_RGB10: case GL_RGB12: case GL_RGB16: case GL_R3_G3_B2:<br>
+<br>
+      *out_format = COGL_PIXEL_FORMAT_RGB_888;<br>
+      return TRUE;<br>
+<br>
+    case GL_RGBA: case GL_RGBA2: case GL_RGBA4: case GL_RGB5_A1:<br>
+    case GL_RGBA8: case GL_RGB10_A2: case GL_RGBA12: case GL_RGBA16:<br>
+<br>
+      *out_format = COGL_PIXEL_FORMAT_RGBA_8888;<br>
+      return TRUE;<br>
+    }<br>
+<br>
+  return FALSE;<br>
+}<br>
+<br>
+static CoglPixelFormat<br>
+_cogl_driver_pixel_format_to_gl (CoglContext *context,<br>
+                                 CoglPixelFormat  format,<br>
+                                 GLenum *out_glintformat,<br>
+                                 GLenum *out_glformat,<br>
+                                 GLenum *out_gltype)<br>
+{<br>
+  CoglPixelFormat required_format;<br>
+  GLenum glintformat;<br>
+  GLenum glformat = 0;<br>
+  GLenum gltype;<br>
+<br>
+  required_format = format;<br>
+<br>
+  /* Find GL equivalents */<br>
+  switch (format)<br>
+    {<br>
+    case COGL_PIXEL_FORMAT_A_8:<br>
+      glintformat = GL_ALPHA;<br>
+      glformat = GL_ALPHA;<br>
+      gltype = GL_UNSIGNED_BYTE;<br>
+      break;<br>
+    case COGL_PIXEL_FORMAT_G_8:<br>
+      glintformat = GL_LUMINANCE;<br>
+      glformat = GL_LUMINANCE;<br>
+      gltype = GL_UNSIGNED_BYTE;<br>
+      break;<br>
+<br>
+    case COGL_PIXEL_FORMAT_RGB_888:<br>
+      glintformat = GL_RGB;<br>
+      glformat = GL_RGB;<br>
+      gltype = GL_UNSIGNED_BYTE;<br>
+      break;<br>
+    case COGL_PIXEL_FORMAT_BGR_888:<br>
+      glintformat = GL_RGB;<br>
+      glformat = GL_BGR;<br>
+      gltype = GL_UNSIGNED_BYTE;<br>
+      break;<br>
+    case COGL_PIXEL_FORMAT_RGBA_8888:<br>
+    case COGL_PIXEL_FORMAT_RGBA_8888_PRE:<br>
+      glintformat = GL_RGBA;<br>
+      glformat = GL_RGBA;<br>
+      gltype = GL_UNSIGNED_BYTE;<br>
+      break;<br>
+    case COGL_PIXEL_FORMAT_BGRA_8888:<br>
+    case COGL_PIXEL_FORMAT_BGRA_8888_PRE:<br>
+      glintformat = GL_RGBA;<br>
+      glformat = GL_BGRA;<br>
+      gltype = GL_UNSIGNED_BYTE;<br>
+      break;<br>
+<br>
+      /* The following two types of channel ordering<br>
+       * have no GL equivalent unless defined using<br>
+       * system word byte ordering */<br>
+    case COGL_PIXEL_FORMAT_ARGB_8888:<br>
+    case COGL_PIXEL_FORMAT_ARGB_8888_PRE:<br>
+      glintformat = GL_RGBA;<br>
+      glformat = GL_BGRA;<br>
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN<br>
+      gltype = GL_UNSIGNED_INT_8_8_8_8;<br>
+#else<br>
+      gltype = GL_UNSIGNED_INT_8_8_8_8_REV;<br>
+#endif<br>
+      break;<br>
+<br>
+    case COGL_PIXEL_FORMAT_ABGR_8888:<br>
+    case COGL_PIXEL_FORMAT_ABGR_8888_PRE:<br>
+      glintformat = GL_RGBA;<br>
+      glformat = GL_RGBA;<br>
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN<br>
+      gltype = GL_UNSIGNED_INT_8_8_8_8;<br>
+#else<br>
+      gltype = GL_UNSIGNED_INT_8_8_8_8_REV;<br>
+#endif<br>
+      break;<br>
+<br>
+    case COGL_PIXEL_FORMAT_RGBA_1010102:<br>
+    case COGL_PIXEL_FORMAT_RGBA_1010102_PRE:<br>
+      glintformat = GL_RGBA;<br>
+      glformat = GL_RGBA;<br>
+      gltype = GL_UNSIGNED_INT_10_10_10_2;<br>
+      break;<br>
+<br>
+    case COGL_PIXEL_FORMAT_BGRA_1010102:<br>
+    case COGL_PIXEL_FORMAT_BGRA_1010102_PRE:<br>
+      glintformat = GL_RGBA;<br>
+      glformat = GL_BGRA;<br>
+      gltype = GL_UNSIGNED_INT_10_10_10_2;<br>
+      break;<br>
+<br>
+    case COGL_PIXEL_FORMAT_ABGR_2101010:<br>
+    case COGL_PIXEL_FORMAT_ABGR_2101010_PRE:<br>
+      glintformat = GL_RGBA;<br>
+      glformat = GL_RGBA;<br>
+      gltype = GL_UNSIGNED_INT_2_10_10_10_REV;<br>
+      break;<br>
+<br>
+    case COGL_PIXEL_FORMAT_ARGB_2101010:<br>
+    case COGL_PIXEL_FORMAT_ARGB_2101010_PRE:<br>
+      glintformat = GL_RGBA;<br>
+      glformat = GL_BGRA;<br>
+      gltype = GL_UNSIGNED_INT_2_10_10_10_REV;<br>
+      break;<br>
+<br>
+      /* The following three types of channel ordering<br>
+       * are always defined using system word byte<br>
+       * ordering (even according to GLES spec) */<br>
+    case COGL_PIXEL_FORMAT_RGB_565:<br>
+      glintformat = GL_RGB;<br>
+      glformat = GL_RGB;<br>
+      gltype = GL_UNSIGNED_SHORT_5_6_5;<br>
+      break;<br>
+    case COGL_PIXEL_FORMAT_RGBA_4444:<br>
+    case COGL_PIXEL_FORMAT_RGBA_4444_PRE:<br>
+      glintformat = GL_RGBA;<br>
+      glformat = GL_RGBA;<br>
+      gltype = GL_UNSIGNED_SHORT_4_4_4_4;<br>
+      break;<br>
+    case COGL_PIXEL_FORMAT_RGBA_5551:<br>
+    case COGL_PIXEL_FORMAT_RGBA_5551_PRE:<br>
+      glintformat = GL_RGBA;<br>
+      glformat = GL_RGBA;<br>
+      gltype = GL_UNSIGNED_SHORT_5_5_5_1;<br>
+      break;<br>
+<br>
+    case COGL_PIXEL_FORMAT_ANY:<br>
+    case COGL_PIXEL_FORMAT_YUV:<br>
+      g_assert_not_reached ();<br>
+      break;<br>
+    }<br>
+<br>
+  /* All of the pixel formats are handled above so if this hits then<br>
+     we&#39;ve been given an invalid pixel format */<br>
+  g_assert (glformat != 0);<br>
+<br>
+  if (out_glintformat != NULL)<br>
+    *out_glintformat = glintformat;<br>
+  if (out_glformat != NULL)<br>
+    *out_glformat = glformat;<br>
+  if (out_gltype != NULL)<br>
+    *out_gltype = gltype;<br>
+<br>
+  return required_format;<br>
+}<br>
+<br>
+static gboolean<br>
+_cogl_get_gl_version (CoglContext *ctx,<br>
+                      int *major_out,<br>
+                      int *minor_out)<br>
 {<br>
   const char *version_string, *major_end, *minor_end;<br>
   int major = 0, minor = 0;<br>
<br>
-  _COGL_GET_CONTEXT (ctx, FALSE);<br>
-<br>
   /* Get the OpenGL version number */<br>
   if ((version_string = (const char *) ctx-&gt;glGetString (GL_VERSION)) == NULL)<br>
     return FALSE;<br>
@@ -77,7 +263,7 @@ check_gl_version (CoglContext *ctx,<br>
   int major, minor;<br>
   const char *gl_extensions;<br>
<br>
-  if (!_cogl_get_gl_version (&amp;major, &amp;minor))<br>
+  if (!_cogl_get_gl_version (ctx, &amp;major, &amp;minor))<br>
     {<br>
       g_set_error (error,<br>
                    COGL_DRIVER_ERROR,<br>
@@ -119,9 +305,9 @@ check_gl_version (CoglContext *ctx,<br>
   return TRUE;<br>
 }<br>
<br>
-gboolean<br>
-_cogl_gl_update_features (CoglContext *context,<br>
-                          GError **error)<br>
+static gboolean<br>
+_cogl_driver_update_features (CoglContext *ctx,<br>
+                              GError **error)<br>
 {<br>
   CoglPrivateFeatureFlags private_flags = 0;<br>
   CoglFeatureFlags flags = 0;<br>
@@ -130,16 +316,14 @@ _cogl_gl_update_features (CoglContext *context,<br>
   int num_stencil_bits = 0;<br>
   int gl_major = 0, gl_minor = 0;<br>
<br>
-  _COGL_GET_CONTEXT (ctx, FALSE);<br>
-<br>
   /* We have to special case getting the pointer to the glGetString<br>
      function because we need to use it to determine what functions we<br>
      can expect */<br>
-  context-&gt;glGetString =<br>
-    (void *) _cogl_renderer_get_proc_address (context-&gt;display-&gt;renderer,<br>
+  ctx-&gt;glGetString =<br>
+    (void *) _cogl_renderer_get_proc_address (ctx-&gt;display-&gt;renderer,<br>
                                               &quot;glGetString&quot;);<br>
<br>
-  if (!check_gl_version (context, error))<br>
+  if (!check_gl_version (ctx, error))<br>
     return FALSE;<br>
<br>
   COGL_NOTE (WINSYS,<br>
@@ -153,7 +337,7 @@ _cogl_gl_update_features (CoglContext *context,<br>
              ctx-&gt;glGetString (GL_VERSION),<br>
              ctx-&gt;glGetString (GL_EXTENSIONS));<br>
<br>
-  _cogl_get_gl_version (&amp;gl_major, &amp;gl_minor);<br>
+  _cogl_get_gl_version (ctx, &amp;gl_major, &amp;gl_minor);<br>
<br>
   flags = (COGL_FEATURE_TEXTURE_READ_PIXELS<br>
            | COGL_FEATURE_UNSIGNED_INT_INDICES<br>
@@ -167,7 +351,7 @@ _cogl_gl_update_features (CoglContext *context,<br>
<br>
   gl_extensions = (const char *)ctx-&gt;glGetString (GL_EXTENSIONS);<br>
<br>
-  _cogl_feature_check_ext_functions (context,<br>
+  _cogl_feature_check_ext_functions (ctx,<br>
                                      gl_major,<br>
                                      gl_minor,<br>
                                      gl_extensions);<br>
@@ -200,16 +384,16 @@ _cogl_gl_update_features (CoglContext *context,<br>
   if (max_clip_planes &gt;= 4)<br>
     private_flags |= COGL_PRIVATE_FEATURE_FOUR_CLIP_PLANES;<br>
<br>
-  if (context-&gt;glGenRenderbuffers)<br>
+  if (ctx-&gt;glGenRenderbuffers)<br>
     {<br>
       flags |= COGL_FEATURE_OFFSCREEN;<br>
       COGL_FLAGS_SET (ctx-&gt;features, COGL_FEATURE_ID_OFFSCREEN, TRUE);<br>
     }<br>
<br>
-  if (context-&gt;glBlitFramebuffer)<br>
+  if (ctx-&gt;glBlitFramebuffer)<br>
     private_flags |= COGL_PRIVATE_FEATURE_OFFSCREEN_BLIT;<br>
<br>
-  if (context-&gt;glRenderbufferStorageMultisampleIMG)<br>
+  if (ctx-&gt;glRenderbufferStorageMultisampleIMG)<br>
     {<br>
       flags |= COGL_FEATURE_OFFSCREEN_MULTISAMPLE;<br>
       COGL_FLAGS_SET (ctx-&gt;features,<br>
@@ -227,19 +411,19 @@ _cogl_gl_update_features (CoglContext *context,<br>
       COGL_FLAGS_SET (ctx-&gt;features, COGL_FEATURE_ID_POINT_SPRITE, TRUE);<br>
     }<br>
<br>
-  if (context-&gt;glGenPrograms)<br>
+  if (ctx-&gt;glGenPrograms)<br>
     {<br>
       flags |= COGL_FEATURE_SHADERS_ARBFP;<br>
       COGL_FLAGS_SET (ctx-&gt;features, COGL_FEATURE_ID_ARBFP, TRUE);<br>
     }<br>
<br>
-  if (context-&gt;glCreateProgram)<br>
+  if (ctx-&gt;glCreateProgram)<br>
     {<br>
       flags |= COGL_FEATURE_SHADERS_GLSL;<br>
       COGL_FLAGS_SET (ctx-&gt;features, COGL_FEATURE_ID_GLSL, TRUE);<br>
     }<br>
<br>
-  if (context-&gt;glGenBuffers)<br>
+  if (ctx-&gt;glGenBuffers)<br>
     {<br>
       private_flags |= COGL_PRIVATE_FEATURE_VBOS;<br>
       flags |= (COGL_FEATURE_MAP_BUFFER_FOR_READ |<br>
@@ -257,21 +441,29 @@ _cogl_gl_update_features (CoglContext *context,<br>
                       COGL_FEATURE_ID_TEXTURE_RECTANGLE, TRUE);<br>
     }<br>
<br>
-  if (context-&gt;glTexImage3D)<br>
+  if (ctx-&gt;glTexImage3D)<br>
     {<br>
       flags |= COGL_FEATURE_TEXTURE_3D;<br>
       COGL_FLAGS_SET (ctx-&gt;features, COGL_FEATURE_ID_TEXTURE_3D, TRUE);<br>
     }<br>
<br>
-  if (context-&gt;glEGLImageTargetTexture2D)<br>
+  if (ctx-&gt;glEGLImageTargetTexture2D)<br>
     private_flags |= COGL_PRIVATE_FEATURE_TEXTURE_2D_FROM_EGL_IMAGE;<br>
<br>
   if (_cogl_check_extension (&quot;GL_EXT_packed_depth_stencil&quot;, gl_extensions))<br>
     private_flags |= COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL;<br>
<br>
   /* Cache features */<br>
-  context-&gt;private_feature_flags |= private_flags;<br>
-  context-&gt;feature_flags |= flags;<br>
+  ctx-&gt;private_feature_flags |= private_flags;<br>
+  ctx-&gt;feature_flags |= flags;<br>
<br>
   return TRUE;<br>
 }<br>
+<br>
+const CoglDriverVtable<br>
+_cogl_driver_gl =<br>
+  {<br>
+    _cogl_driver_pixel_format_from_gl_internal,<br>
+    _cogl_driver_pixel_format_to_gl,<br>
+    _cogl_driver_update_features<br>
+  };<br>
diff --git a/cogl/driver/gl/cogl-texture-driver-gl.c b/cogl/driver/gl/cogl-texture-driver-gl.c<br>
index 83d47ae..373fade 100644<br>
--- a/cogl/driver/gl/cogl-texture-driver-gl.c<br>
+++ b/cogl/driver/gl/cogl-texture-driver-gl.c<br>
@@ -353,190 +353,6 @@ _cogl_texture_driver_try_setting_gl_border_color (<br>
 }<br>
<br>
 static gboolean<br>
-_cogl_texture_driver_pixel_format_from_gl_internal (GLenum gl_int_format,<br>
-                                                    CoglPixelFormat  *out_format)<br>
-{<br>
-  /* It doesn&#39;t really matter we convert to exact same<br>
-     format (some have no cogl match anyway) since format<br>
-     is re-matched against cogl when getting or setting<br>
-     texture image data.<br>
-  */<br>
-<br>
-  switch (gl_int_format)<br>
-    {<br>
-    case GL_ALPHA: case GL_ALPHA4: case GL_ALPHA8:<br>
-    case GL_ALPHA12: case GL_ALPHA16:<br>
-<br>
-      *out_format = COGL_PIXEL_FORMAT_A_8;<br>
-      return TRUE;<br>
-<br>
-    case GL_LUMINANCE: case GL_LUMINANCE4: case GL_LUMINANCE8:<br>
-    case GL_LUMINANCE12: case GL_LUMINANCE16:<br>
-<br>
-      *out_format = COGL_PIXEL_FORMAT_G_8;<br>
-      return TRUE;<br>
-<br>
-    case GL_RGB: case GL_RGB4: case GL_RGB5: case GL_RGB8:<br>
-    case GL_RGB10: case GL_RGB12: case GL_RGB16: case GL_R3_G3_B2:<br>
-<br>
-      *out_format = COGL_PIXEL_FORMAT_RGB_888;<br>
-      return TRUE;<br>
-<br>
-    case GL_RGBA: case GL_RGBA2: case GL_RGBA4: case GL_RGB5_A1:<br>
-    case GL_RGBA8: case GL_RGB10_A2: case GL_RGBA12: case GL_RGBA16:<br>
-<br>
-      *out_format = COGL_PIXEL_FORMAT_RGBA_8888;<br>
-      return TRUE;<br>
-    }<br>
-<br>
-  return FALSE;<br>
-}<br>
-<br>
-static CoglPixelFormat<br>
-_cogl_texture_driver_pixel_format_to_gl (CoglPixelFormat  format,<br>
-                                         GLenum          *out_glintformat,<br>
-                                         GLenum          *out_glformat,<br>
-                                         GLenum          *out_gltype)<br>
-{<br>
-  CoglPixelFormat required_format;<br>
-  GLenum glintformat;<br>
-  GLenum glformat = 0;<br>
-  GLenum gltype;<br>
-<br>
-  required_format = format;<br>
-<br>
-  /* Find GL equivalents */<br>
-  switch (format)<br>
-    {<br>
-    case COGL_PIXEL_FORMAT_A_8:<br>
-      glintformat = GL_ALPHA;<br>
-      glformat = GL_ALPHA;<br>
-      gltype = GL_UNSIGNED_BYTE;<br>
-      break;<br>
-    case COGL_PIXEL_FORMAT_G_8:<br>
-      glintformat = GL_LUMINANCE;<br>
-      glformat = GL_LUMINANCE;<br>
-      gltype = GL_UNSIGNED_BYTE;<br>
-      break;<br>
-<br>
-    case COGL_PIXEL_FORMAT_RGB_888:<br>
-      glintformat = GL_RGB;<br>
-      glformat = GL_RGB;<br>
-      gltype = GL_UNSIGNED_BYTE;<br>
-      break;<br>
-    case COGL_PIXEL_FORMAT_BGR_888:<br>
-      glintformat = GL_RGB;<br>
-      glformat = GL_BGR;<br>
-      gltype = GL_UNSIGNED_BYTE;<br>
-      break;<br>
-    case COGL_PIXEL_FORMAT_RGBA_8888:<br>
-    case COGL_PIXEL_FORMAT_RGBA_8888_PRE:<br>
-      glintformat = GL_RGBA;<br>
-      glformat = GL_RGBA;<br>
-      gltype = GL_UNSIGNED_BYTE;<br>
-      break;<br>
-    case COGL_PIXEL_FORMAT_BGRA_8888:<br>
-    case COGL_PIXEL_FORMAT_BGRA_8888_PRE:<br>
-      glintformat = GL_RGBA;<br>
-      glformat = GL_BGRA;<br>
-      gltype = GL_UNSIGNED_BYTE;<br>
-      break;<br>
-<br>
-      /* The following two types of channel ordering<br>
-       * have no GL equivalent unless defined using<br>
-       * system word byte ordering */<br>
-    case COGL_PIXEL_FORMAT_ARGB_8888:<br>
-    case COGL_PIXEL_FORMAT_ARGB_8888_PRE:<br>
-      glintformat = GL_RGBA;<br>
-      glformat = GL_BGRA;<br>
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN<br>
-      gltype = GL_UNSIGNED_INT_8_8_8_8;<br>
-#else<br>
-      gltype = GL_UNSIGNED_INT_8_8_8_8_REV;<br>
-#endif<br>
-      break;<br>
-<br>
-    case COGL_PIXEL_FORMAT_ABGR_8888:<br>
-    case COGL_PIXEL_FORMAT_ABGR_8888_PRE:<br>
-      glintformat = GL_RGBA;<br>
-      glformat = GL_RGBA;<br>
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN<br>
-      gltype = GL_UNSIGNED_INT_8_8_8_8;<br>
-#else<br>
-      gltype = GL_UNSIGNED_INT_8_8_8_8_REV;<br>
-#endif<br>
-      break;<br>
-<br>
-    case COGL_PIXEL_FORMAT_RGBA_1010102:<br>
-    case COGL_PIXEL_FORMAT_RGBA_1010102_PRE:<br>
-      glintformat = GL_RGBA;<br>
-      glformat = GL_RGBA;<br>
-      gltype = GL_UNSIGNED_INT_10_10_10_2;<br>
-      break;<br>
-<br>
-    case COGL_PIXEL_FORMAT_BGRA_1010102:<br>
-    case COGL_PIXEL_FORMAT_BGRA_1010102_PRE:<br>
-      glintformat = GL_RGBA;<br>
-      glformat = GL_BGRA;<br>
-      gltype = GL_UNSIGNED_INT_10_10_10_2;<br>
-      break;<br>
-<br>
-    case COGL_PIXEL_FORMAT_ABGR_2101010:<br>
-    case COGL_PIXEL_FORMAT_ABGR_2101010_PRE:<br>
-      glintformat = GL_RGBA;<br>
-      glformat = GL_RGBA;<br>
-      gltype = GL_UNSIGNED_INT_2_10_10_10_REV;<br>
-      break;<br>
-<br>
-    case COGL_PIXEL_FORMAT_ARGB_2101010:<br>
-    case COGL_PIXEL_FORMAT_ARGB_2101010_PRE:<br>
-      glintformat = GL_RGBA;<br>
-      glformat = GL_BGRA;<br>
-      gltype = GL_UNSIGNED_INT_2_10_10_10_REV;<br>
-      break;<br>
-<br>
-      /* The following three types of channel ordering<br>
-       * are always defined using system word byte<br>
-       * ordering (even according to GLES spec) */<br>
-    case COGL_PIXEL_FORMAT_RGB_565:<br>
-      glintformat = GL_RGB;<br>
-      glformat = GL_RGB;<br>
-      gltype = GL_UNSIGNED_SHORT_5_6_5;<br>
-      break;<br>
-    case COGL_PIXEL_FORMAT_RGBA_4444:<br>
-    case COGL_PIXEL_FORMAT_RGBA_4444_PRE:<br>
-      glintformat = GL_RGBA;<br>
-      glformat = GL_RGBA;<br>
-      gltype = GL_UNSIGNED_SHORT_4_4_4_4;<br>
-      break;<br>
-    case COGL_PIXEL_FORMAT_RGBA_5551:<br>
-    case COGL_PIXEL_FORMAT_RGBA_5551_PRE:<br>
-      glintformat = GL_RGBA;<br>
-      glformat = GL_RGBA;<br>
-      gltype = GL_UNSIGNED_SHORT_5_5_5_1;<br>
-      break;<br>
-<br>
-    case COGL_PIXEL_FORMAT_ANY:<br>
-    case COGL_PIXEL_FORMAT_YUV:<br>
-      g_assert_not_reached ();<br>
-      break;<br>
-    }<br>
-<br>
-  /* All of the pixel formats are handled above so if this hits then<br>
-     we&#39;ve been given an invalid pixel format */<br>
-  g_assert (glformat != 0);<br>
-<br>
-  if (out_glintformat != NULL)<br>
-    *out_glintformat = glintformat;<br>
-  if (out_glformat != NULL)<br>
-    *out_glformat = glformat;<br>
-  if (out_gltype != NULL)<br>
-    *out_gltype = gltype;<br>
-<br>
-  return required_format;<br>
-}<br>
-<br>
-static gboolean<br>
 _cogl_texture_driver_allows_foreign_gl_target (GLenum gl_target)<br>
 {<br>
   /* GL_ARB_texture_rectangle textures are supported if they are<br>
@@ -561,16 +377,17 @@ _cogl_texture_driver_gl_generate_mipmaps (GLenum gl_target)<br>
 }<br>
<br>
 static CoglPixelFormat<br>
-_cogl_texture_driver_find_best_gl_get_data_format (<br>
-                                             CoglPixelFormat  format,<br>
-                                             GLenum          *closest_gl_format,<br>
-                                             GLenum          *closest_gl_type)<br>
+_cogl_texture_driver_find_best_gl_get_data_format<br>
+                                            (CoglContext *context,<br>
+                                             CoglPixelFormat format,<br>
+                                             GLenum *closest_gl_format,<br>
+                                             GLenum *closest_gl_type)<br>
 {<br>
-  /* Find closest format that&#39;s supported by GL */<br>
-  return _cogl_texture_driver_pixel_format_to_gl (format,<br>
-                                                  NULL, /* don&#39;t need */<br>
-                                                  closest_gl_format,<br>
-                                                  closest_gl_type);<br>
+  return context-&gt;driver_vtable-&gt;pixel_format_to_gl (context,<br>
+                                                     format,<br>
+                                                     NULL, /* don&#39;t need */<br>
+                                                     closest_gl_format,<br>
+                                                     closest_gl_type);<br>
 }<br>
<br>
 const CoglTextureDriver<br>
@@ -586,8 +403,6 @@ _cogl_texture_driver_gl =<br>
     _cogl_texture_driver_size_supported,<br>
     _cogl_texture_driver_size_supported_3d,<br>
     _cogl_texture_driver_try_setting_gl_border_color,<br>
-    _cogl_texture_driver_pixel_format_from_gl_internal,<br>
-    _cogl_texture_driver_pixel_format_to_gl,<br>
     _cogl_texture_driver_allows_foreign_gl_target,<br>
     _cogl_texture_driver_gl_generate_mipmaps,<br>
     _cogl_texture_driver_find_best_gl_get_data_format<br>
diff --git a/cogl/driver/gles/cogl-gles.c b/cogl/driver/gles/cogl-gles.c<br>
index 8087ae0..d4c5968 100644<br>
--- a/cogl/driver/gles/cogl-gles.c<br>
+++ b/cogl/driver/gles/cogl-gles.c<br>
@@ -33,9 +33,119 @@<br>
 #include &quot;cogl-renderer-private.h&quot;<br>
 #include &quot;cogl-private.h&quot;<br>
<br>
-gboolean<br>
-_cogl_gles_update_features (CoglContext *context,<br>
-                            GError **error)<br>
+static gboolean<br>
+_cogl_driver_pixel_format_from_gl_internal (CoglContext *context,<br>
+                                            GLenum gl_int_format,<br>
+                                            CoglPixelFormat *out_format)<br>
+{<br>
+  return TRUE;<br>
+}<br>
+<br>
+static CoglPixelFormat<br>
+_cogl_driver_pixel_format_to_gl (CoglContext *context,<br>
+                                 CoglPixelFormat  format,<br>
+                                 GLenum *out_glintformat,<br>
+                                 GLenum *out_glformat,<br>
+                                 GLenum *out_gltype)<br>
+{<br>
+  CoglPixelFormat required_format;<br>
+  GLenum glintformat;<br>
+  GLenum glformat = 0;<br>
+  GLenum gltype;<br>
+<br>
+  required_format = format;<br>
+<br>
+  /* Find GL equivalents */<br>
+  switch (format)<br>
+    {<br>
+    case COGL_PIXEL_FORMAT_A_8:<br>
+      glintformat = GL_ALPHA;<br>
+      glformat = GL_ALPHA;<br>
+      gltype = GL_UNSIGNED_BYTE;<br>
+      break;<br>
+    case COGL_PIXEL_FORMAT_G_8:<br>
+      glintformat = GL_LUMINANCE;<br>
+      glformat = GL_LUMINANCE;<br>
+      gltype = GL_UNSIGNED_BYTE;<br>
+      break;<br>
+<br>
+      /* Just one 24-bit ordering supported */<br>
+    case COGL_PIXEL_FORMAT_RGB_888:<br>
+    case COGL_PIXEL_FORMAT_BGR_888:<br>
+      glintformat = GL_RGB;<br>
+      glformat = GL_RGB;<br>
+      gltype = GL_UNSIGNED_BYTE;<br>
+      required_format = COGL_PIXEL_FORMAT_RGB_888;<br>
+      break;<br>
+<br>
+      /* Just one 32-bit ordering supported */<br>
+    case COGL_PIXEL_FORMAT_RGBA_8888:<br>
+    case COGL_PIXEL_FORMAT_RGBA_8888_PRE:<br>
+    case COGL_PIXEL_FORMAT_BGRA_8888:<br>
+    case COGL_PIXEL_FORMAT_BGRA_8888_PRE:<br>
+    case COGL_PIXEL_FORMAT_ARGB_8888:<br>
+    case COGL_PIXEL_FORMAT_ARGB_8888_PRE:<br>
+    case COGL_PIXEL_FORMAT_ABGR_8888:<br>
+    case COGL_PIXEL_FORMAT_ABGR_8888_PRE:<br>
+    case COGL_PIXEL_FORMAT_RGBA_1010102:<br>
+    case COGL_PIXEL_FORMAT_RGBA_1010102_PRE:<br>
+    case COGL_PIXEL_FORMAT_BGRA_1010102:<br>
+    case COGL_PIXEL_FORMAT_BGRA_1010102_PRE:<br>
+    case COGL_PIXEL_FORMAT_ABGR_2101010:<br>
+    case COGL_PIXEL_FORMAT_ABGR_2101010_PRE:<br>
+    case COGL_PIXEL_FORMAT_ARGB_2101010:<br>
+    case COGL_PIXEL_FORMAT_ARGB_2101010_PRE:<br>
+      glintformat = GL_RGBA;<br>
+      glformat = GL_RGBA;<br>
+      gltype = GL_UNSIGNED_BYTE;<br>
+      required_format = COGL_PIXEL_FORMAT_RGBA_8888;<br>
+      required_format |= (format &amp; COGL_PREMULT_BIT);<br>
+      break;<br>
+<br>
+      /* The following three types of channel ordering<br>
+       * are always defined using system word byte<br>
+       * ordering (even according to GLES spec) */<br>
+    case COGL_PIXEL_FORMAT_RGB_565:<br>
+      glintformat = GL_RGB;<br>
+      glformat = GL_RGB;<br>
+      gltype = GL_UNSIGNED_SHORT_5_6_5;<br>
+      break;<br>
+    case COGL_PIXEL_FORMAT_RGBA_4444:<br>
+    case COGL_PIXEL_FORMAT_RGBA_4444_PRE:<br>
+      glintformat = GL_RGBA;<br>
+      glformat = GL_RGBA;<br>
+      gltype = GL_UNSIGNED_SHORT_4_4_4_4;<br>
+      break;<br>
+    case COGL_PIXEL_FORMAT_RGBA_5551:<br>
+    case COGL_PIXEL_FORMAT_RGBA_5551_PRE:<br>
+      glintformat = GL_RGBA;<br>
+      glformat = GL_RGBA;<br>
+      gltype = GL_UNSIGNED_SHORT_5_5_5_1;<br>
+      break;<br>
+<br>
+    case COGL_PIXEL_FORMAT_ANY:<br>
+    case COGL_PIXEL_FORMAT_YUV:<br>
+      g_assert_not_reached ();<br>
+      break;<br>
+    }<br>
+<br>
+  /* All of the pixel formats are handled above so if this hits then<br>
+     we&#39;ve been given an invalid pixel format */<br>
+  g_assert (glformat != 0);<br>
+<br>
+  if (out_glintformat != NULL)<br>
+    *out_glintformat = glintformat;<br>
+  if (out_glformat != NULL)<br>
+    *out_glformat = glformat;<br>
+  if (out_gltype != NULL)<br>
+    *out_gltype = gltype;<br>
+<br>
+  return required_format;<br>
+}<br>
+<br>
+static gboolean<br>
+_cogl_driver_update_features (CoglContext *context,<br>
+                              GError **error)<br>
 {<br>
   CoglPrivateFeatureFlags private_flags = 0;<br>
   CoglFeatureFlags flags = 0;<br>
@@ -172,3 +282,11 @@ _cogl_gles_update_features (CoglContext *context,<br>
<br>
   return TRUE;<br>
 }<br>
+<br>
+const CoglDriverVtable<br>
+_cogl_driver_gles =<br>
+  {<br>
+    _cogl_driver_pixel_format_from_gl_internal,<br>
+    _cogl_driver_pixel_format_to_gl,<br>
+    _cogl_driver_update_features<br>
+  };<br>
diff --git a/cogl/driver/gles/cogl-texture-driver-gles.c b/cogl/driver/gles/cogl-texture-driver-gles.c<br>
index 2bc596b..ad1c248 100644<br>
--- a/cogl/driver/gles/cogl-texture-driver-gles.c<br>
+++ b/cogl/driver/gles/cogl-texture-driver-gles.c<br>
@@ -390,114 +390,6 @@ _cogl_texture_driver_try_setting_gl_border_color (<br>
 }<br>
<br>
 static gboolean<br>
-_cogl_texture_driver_pixel_format_from_gl_internal (GLenum gl_int_format,<br>
-                                                    CoglPixelFormat *out_format)<br>
-{<br>
-  return TRUE;<br>
-}<br>
-<br>
-static CoglPixelFormat<br>
-_cogl_texture_driver_pixel_format_to_gl (CoglPixelFormat  format,<br>
-                                         GLenum          *out_glintformat,<br>
-                                         GLenum          *out_glformat,<br>
-                                         GLenum          *out_gltype)<br>
-{<br>
-  CoglPixelFormat required_format;<br>
-  GLenum glintformat;<br>
-  GLenum glformat = 0;<br>
-  GLenum gltype;<br>
-<br>
-  required_format = format;<br>
-<br>
-  /* Find GL equivalents */<br>
-  switch (format)<br>
-    {<br>
-    case COGL_PIXEL_FORMAT_A_8:<br>
-      glintformat = GL_ALPHA;<br>
-      glformat = GL_ALPHA;<br>
-      gltype = GL_UNSIGNED_BYTE;<br>
-      break;<br>
-    case COGL_PIXEL_FORMAT_G_8:<br>
-      glintformat = GL_LUMINANCE;<br>
-      glformat = GL_LUMINANCE;<br>
-      gltype = GL_UNSIGNED_BYTE;<br>
-      break;<br>
-<br>
-      /* Just one 24-bit ordering supported */<br>
-    case COGL_PIXEL_FORMAT_RGB_888:<br>
-    case COGL_PIXEL_FORMAT_BGR_888:<br>
-      glintformat = GL_RGB;<br>
-      glformat = GL_RGB;<br>
-      gltype = GL_UNSIGNED_BYTE;<br>
-      required_format = COGL_PIXEL_FORMAT_RGB_888;<br>
-      break;<br>
-<br>
-      /* Just one 32-bit ordering supported */<br>
-    case COGL_PIXEL_FORMAT_RGBA_8888:<br>
-    case COGL_PIXEL_FORMAT_RGBA_8888_PRE:<br>
-    case COGL_PIXEL_FORMAT_BGRA_8888:<br>
-    case COGL_PIXEL_FORMAT_BGRA_8888_PRE:<br>
-    case COGL_PIXEL_FORMAT_ARGB_8888:<br>
-    case COGL_PIXEL_FORMAT_ARGB_8888_PRE:<br>
-    case COGL_PIXEL_FORMAT_ABGR_8888:<br>
-    case COGL_PIXEL_FORMAT_ABGR_8888_PRE:<br>
-    case COGL_PIXEL_FORMAT_RGBA_1010102:<br>
-    case COGL_PIXEL_FORMAT_RGBA_1010102_PRE:<br>
-    case COGL_PIXEL_FORMAT_BGRA_1010102:<br>
-    case COGL_PIXEL_FORMAT_BGRA_1010102_PRE:<br>
-    case COGL_PIXEL_FORMAT_ABGR_2101010:<br>
-    case COGL_PIXEL_FORMAT_ABGR_2101010_PRE:<br>
-    case COGL_PIXEL_FORMAT_ARGB_2101010:<br>
-    case COGL_PIXEL_FORMAT_ARGB_2101010_PRE:<br>
-      glintformat = GL_RGBA;<br>
-      glformat = GL_RGBA;<br>
-      gltype = GL_UNSIGNED_BYTE;<br>
-      required_format = COGL_PIXEL_FORMAT_RGBA_8888;<br>
-      required_format |= (format &amp; COGL_PREMULT_BIT);<br>
-      break;<br>
-<br>
-      /* The following three types of channel ordering<br>
-       * are always defined using system word byte<br>
-       * ordering (even according to GLES spec) */<br>
-    case COGL_PIXEL_FORMAT_RGB_565:<br>
-      glintformat = GL_RGB;<br>
-      glformat = GL_RGB;<br>
-      gltype = GL_UNSIGNED_SHORT_5_6_5;<br>
-      break;<br>
-    case COGL_PIXEL_FORMAT_RGBA_4444:<br>
-    case COGL_PIXEL_FORMAT_RGBA_4444_PRE:<br>
-      glintformat = GL_RGBA;<br>
-      glformat = GL_RGBA;<br>
-      gltype = GL_UNSIGNED_SHORT_4_4_4_4;<br>
-      break;<br>
-    case COGL_PIXEL_FORMAT_RGBA_5551:<br>
-    case COGL_PIXEL_FORMAT_RGBA_5551_PRE:<br>
-      glintformat = GL_RGBA;<br>
-      glformat = GL_RGBA;<br>
-      gltype = GL_UNSIGNED_SHORT_5_5_5_1;<br>
-      break;<br>
-<br>
-    case COGL_PIXEL_FORMAT_ANY:<br>
-    case COGL_PIXEL_FORMAT_YUV:<br>
-      g_assert_not_reached ();<br>
-      break;<br>
-    }<br>
-<br>
-  /* All of the pixel formats are handled above so if this hits then<br>
-     we&#39;ve been given an invalid pixel format */<br>
-  g_assert (glformat != 0);<br>
-<br>
-  if (out_glintformat != NULL)<br>
-    *out_glintformat = glintformat;<br>
-  if (out_glformat != NULL)<br>
-    *out_glformat = glformat;<br>
-  if (out_gltype != NULL)<br>
-    *out_gltype = gltype;<br>
-<br>
-  return required_format;<br>
-}<br>
-<br>
-static gboolean<br>
 _cogl_texture_driver_allows_foreign_gl_target (GLenum gl_target)<br>
 {<br>
   /* Allow 2-dimensional textures only */<br>
@@ -516,10 +408,11 @@ _cogl_texture_driver_gl_generate_mipmaps (GLenum gl_target)<br>
 }<br>
<br>
 static CoglPixelFormat<br>
-_cogl_texture_driver_find_best_gl_get_data_format (<br>
-                                             CoglPixelFormat  format,<br>
-                                             GLenum          *closest_gl_format,<br>
-                                             GLenum          *closest_gl_type)<br>
+_cogl_texture_driver_find_best_gl_get_data_format<br>
+                                            (CoglContext *context,<br>
+                                             CoglPixelFormat format,<br>
+                                             GLenum *closest_gl_format,<br>
+                                             GLenum *closest_gl_type)<br>
 {<br>
   /* Find closest format that&#39;s supported by GL<br>
      (Can&#39;t use _cogl_pixel_format_to_gl since available formats<br>
@@ -542,8 +435,6 @@ _cogl_texture_driver_gles =<br>
     _cogl_texture_driver_size_supported,<br>
     _cogl_texture_driver_size_supported_3d,<br>
     _cogl_texture_driver_try_setting_gl_border_color,<br>
-    _cogl_texture_driver_pixel_format_from_gl_internal,<br>
-    _cogl_texture_driver_pixel_format_to_gl,<br>
     _cogl_texture_driver_allows_foreign_gl_target,<br>
     _cogl_texture_driver_gl_generate_mipmaps,<br>
     _cogl_texture_driver_find_best_gl_get_data_format<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.3.16.g9464b<br>
<br>
_______________________________________________<br>
Cogl mailing list<br>
<a href="mailto:Cogl@lists.freedesktop.org">Cogl@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/cogl" target="_blank">http://lists.freedesktop.org/mailman/listinfo/cogl</a><br>
</font></span></blockquote></div><br></div>