[cogl/wip/combined-driver-build: 2/5] Use all core GL functions through indirect pointers



commit b47eb123275305738b82dd7c10171bf245ba67f6
Author: Neil Roberts <neil linux intel com>
Date:   Wed Jul 6 21:51:00 2011 +0100

    Use all core GL functions through indirect pointers
    
    cogl-ext-functions.h now contains definitions for all of the core GL
    and GLES functions that we would normally link to directly. All of the
    code has changed to access them through the cogl context pointer. The
    GE macro now takes an extra parameter to specify the context because
    the macro itself needs to make GL calls but various points in the Cogl
    source use different names for the context variable.

 cogl/cogl-attribute.c                       |  125 +++++++---------
 cogl/cogl-buffer.c                          |   58 +++----
 cogl/cogl-clip-stack.c                      |   58 ++++----
 cogl/cogl-context.c                         |    7 +-
 cogl/cogl-ext-functions.h                   |  212 +++++++++++++++++++++++++++
 cogl/cogl-framebuffer.c                     |  144 ++++++++----------
 cogl/cogl-internal.h                        |   16 +-
 cogl/cogl-matrix-stack.c                    |    8 +-
 cogl/cogl-pipeline-fragend-arbfp.c          |   41 ++----
 cogl/cogl-pipeline-fragend-fixed.c          |   94 ++++++------
 cogl/cogl-pipeline-fragend-glsl.c           |   25 +---
 cogl/cogl-pipeline-opengl.c                 |  129 ++++++++---------
 cogl/cogl-pipeline-progend-glsl.c           |  125 ++++++++--------
 cogl/cogl-pipeline-vertend-fixed.c          |    2 +-
 cogl/cogl-pipeline-vertend-glsl.c           |   27 +---
 cogl/cogl-pixel-buffer.c                    |    9 -
 cogl/cogl-primitives.c                      |    5 -
 cogl/cogl-program.c                         |   57 ++-----
 cogl/cogl-shader.c                          |   64 +++-----
 cogl/cogl-texture-2d.c                      |   74 ++++++----
 cogl/cogl-texture-3d.c                      |   61 +++++----
 cogl/cogl-texture-rectangle.c               |   72 +++++----
 cogl/cogl-texture.c                         |   28 ++--
 cogl/cogl.c                                 |   24 ++--
 cogl/cogl2-path.c                           |   36 +++---
 cogl/driver/gl/cogl-gl.c                    |   31 +++-
 cogl/driver/gl/cogl-texture-driver-gl.c     |  128 +++++++++-------
 cogl/driver/gles/cogl-gles.c                |   21 ++-
 cogl/driver/gles/cogl-texture-driver-gles.c |  115 ++++++++-------
 cogl/winsys/cogl-winsys-glx.c               |   12 +-
 cogl/winsys/cogl-winsys-wgl.c               |    2 +-
 31 files changed, 982 insertions(+), 828 deletions(-)
---
diff --git a/cogl/cogl-attribute.c b/cogl/cogl-attribute.c
index 0e5e106..5970b79 100644
--- a/cogl/cogl-attribute.c
+++ b/cogl/cogl-attribute.c
@@ -47,30 +47,7 @@
 #include <string.h>
 #include <stdio.h>
 
-#if defined (HAVE_COGL_GL)
-
-#define glGenBuffers ctx->glGenBuffers
-#define glBindBuffer ctx->glBindBuffer
-#define glBufferData ctx->glBufferData
-#define glBufferSubData ctx->glBufferSubData
-#define glGetBufferSubData ctx->glGetBufferSubData
-#define glDeleteBuffers ctx->glDeleteBuffers
-#define glMapBuffer ctx->glMapBuffer
-#define glUnmapBuffer ctx->glUnmapBuffer
-#define glClientActiveTexture ctx->glClientActiveTexture
-#ifndef GL_ARRAY_BUFFER
-#define GL_ARRAY_BUFFER GL_ARRAY_BUFFER_ARB
-#endif
-
-#define glVertexAttribPointer ctx->glVertexAttribPointer
-#define glEnableVertexAttribArray ctx->glEnableVertexAttribArray
-#define glDisableVertexAttribArray ctx->glDisableVertexAttribArray
-#define MAY_HAVE_PROGRAMABLE_GL
-
-#define glDrawRangeElements(mode, start, end, count, type, indices) \
-  ctx->glDrawRangeElements (mode, start, end, count, type, indices)
-
-#else /* GLES 1/2 */
+#if ! defined (HAVE_COGL_GL)
 
 /* GLES doesn't have glDrawRangeElements, so we simply pretend it does
  * but that it makes no use of the start, end constraints: */
@@ -433,23 +410,23 @@ toggle_enabled_cb (int bit_num, void *user_data)
   const CoglBitmask *new_values = user_data;
   gboolean enabled = _cogl_bitmask_get (new_values, bit_num);
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
 #ifdef HAVE_COGL_GLES2
 
   if (enabled)
-    GE( glEnableVertexAttribArray (bit_num) );
+    GE( ctx, glEnableVertexAttribArray (bit_num) );
   else
-    GE( glDisableVertexAttribArray (bit_num) );
+    GE( ctx, glDisableVertexAttribArray (bit_num) );
 
 #else /* HAVE_COGL_GLES2 */
 
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
-  GE( glClientActiveTexture (GL_TEXTURE0 + bit_num) );
+  GE( ctx, glClientActiveTexture (GL_TEXTURE0 + bit_num) );
 
   if (enabled)
-    GE( glEnableClientState (GL_TEXTURE_COORD_ARRAY) );
+    GE( ctx, glEnableClientState (GL_TEXTURE_COORD_ARRAY) );
   else
-    GE( glDisableClientState (GL_TEXTURE_COORD_ARRAY) );
+    GE( ctx, glDisableClientState (GL_TEXTURE_COORD_ARRAY) );
 
 #endif /* HAVE_COGL_GLES2 */
 }
@@ -619,7 +596,8 @@ enable_gl_state (CoglDrawFlags flags,
             _cogl_pipeline_progend_glsl_get_color_attribute (source);
           if (attrib_location != -1)
             {
-              GE( glVertexAttribPointer (attrib_location,
+              GE( ctx,
+                  glVertexAttribPointer (attrib_location,
                                          attribute->n_components,
                                          attribute->type,
                                          TRUE, /* normalize */
@@ -632,11 +610,11 @@ enable_gl_state (CoglDrawFlags flags,
 #else
 
           enable_flags |= COGL_ENABLE_COLOR_ARRAY;
-          /* GE (glEnableClientState (GL_COLOR_ARRAY)); */
-          GE (glColorPointer (attribute->n_components,
-                              attribute->type,
-                              attribute->stride,
-                              base + attribute->offset));
+          /* GE (ctx, glEnableClientState (GL_COLOR_ARRAY)); */
+          GE (ctx, glColorPointer (attribute->n_components,
+                                   attribute->type,
+                                   attribute->stride,
+                                   base + attribute->offset));
 
 #endif
 
@@ -648,7 +626,8 @@ enable_gl_state (CoglDrawFlags flags,
             _cogl_pipeline_progend_glsl_get_normal_attribute (source);
           if (attrib_location != -1)
             {
-              GE( glVertexAttribPointer (attrib_location,
+              GE( ctx,
+                  glVertexAttribPointer (attrib_location,
                                          attribute->n_components,
                                          attribute->type,
                                          TRUE, /* normalize */
@@ -660,10 +639,10 @@ enable_gl_state (CoglDrawFlags flags,
 #else
 
           /* FIXME: go through cogl cache to enable normal array */
-          GE (glEnableClientState (GL_NORMAL_ARRAY));
-          GE (glNormalPointer (attribute->type,
-                               attribute->stride,
-                               base + attribute->offset));
+          GE (ctx, glEnableClientState (GL_NORMAL_ARRAY));
+          GE (ctx, glNormalPointer (attribute->type,
+                                    attribute->stride,
+                                    base + attribute->offset));
 
 #endif
 
@@ -675,7 +654,8 @@ enable_gl_state (CoglDrawFlags flags,
                                              (source, attribute->texture_unit);
           if (attrib_location != -1)
             {
-              GE( glVertexAttribPointer (attrib_location,
+              GE( ctx,
+                  glVertexAttribPointer (attrib_location,
                                          attribute->n_components,
                                          attribute->type,
                                          FALSE, /* normalize */
@@ -685,12 +665,12 @@ enable_gl_state (CoglDrawFlags flags,
             }
 #else
 
-          GE (glClientActiveTexture (GL_TEXTURE0 +
-                                     attribute->texture_unit));
-          GE (glTexCoordPointer (attribute->n_components,
-                                 attribute->type,
-                                 attribute->stride,
-                                 base + attribute->offset));
+          GE (ctx, glClientActiveTexture (GL_TEXTURE0 +
+                                          attribute->texture_unit));
+          GE (ctx, glTexCoordPointer (attribute->n_components,
+                                      attribute->type,
+                                      attribute->stride,
+                                      base + attribute->offset));
           _cogl_bitmask_set (&ctx->temp_bitmask,
                              attribute->texture_unit, TRUE);
 
@@ -703,7 +683,8 @@ enable_gl_state (CoglDrawFlags flags,
             _cogl_pipeline_progend_glsl_get_position_attribute (source);
           if (attrib_location != -1)
             {
-              GE( glVertexAttribPointer (attrib_location,
+              GE( ctx,
+                  glVertexAttribPointer (attrib_location,
                                          attribute->n_components,
                                          attribute->type,
                                          FALSE, /* normalize */
@@ -715,11 +696,11 @@ enable_gl_state (CoglDrawFlags flags,
 #else
 
           enable_flags |= COGL_ENABLE_VERTEX_ARRAY;
-          /* GE (glEnableClientState (GL_VERTEX_ARRAY)); */
-          GE (glVertexPointer (attribute->n_components,
-                               attribute->type,
-                               attribute->stride,
-                               base + attribute->offset));
+          /* GE (ctx, glEnableClientState (GL_VERTEX_ARRAY)); */
+          GE (ctx, glVertexPointer (attribute->n_components,
+                                    attribute->type,
+                                    attribute->stride,
+                                    base + attribute->offset));
 
 #endif
           break;
@@ -729,13 +710,13 @@ enable_gl_state (CoglDrawFlags flags,
             /* FIXME: go through cogl cache to enable generic array. */
             /* FIXME: this is going to end up just using the builtins
                on GLES 2 */
-            GE (glEnableVertexAttribArray (generic_index++));
-            GE (glVertexAttribPointer (generic_index,
-                                       attribute->n_components,
-                                       attribute->type,
-                                       attribute->normalized,
-                                       attribute->stride,
-                                       base + attribute->offset));
+            GE (ctx, glEnableVertexAttribArray (generic_index++));
+            GE (ctx, glVertexAttribPointer (generic_index,
+                                            attribute->n_components,
+                                            attribute->type,
+                                            attribute->normalized,
+                                            attribute->stride,
+                                            base + attribute->offset));
 #endif
           }
           break;
@@ -788,12 +769,12 @@ disable_gl_state (CoglAttribute **attributes,
       switch (attribute->name_id)
         {
         case COGL_ATTRIBUTE_NAME_ID_COLOR_ARRAY:
-          /* GE (glDisableClientState (GL_COLOR_ARRAY)); */
+          /* GE (ctx, glDisableClientState (GL_COLOR_ARRAY)); */
           break;
         case COGL_ATTRIBUTE_NAME_ID_NORMAL_ARRAY:
           /* FIXME: go through cogl cache to enable normal array */
 #ifndef HAVE_COGL_GLES2
-          GE (glDisableClientState (GL_NORMAL_ARRAY));
+          GE (ctx, glDisableClientState (GL_NORMAL_ARRAY));
 #endif
           break;
         case COGL_ATTRIBUTE_NAME_ID_TEXTURE_COORD_ARRAY:
@@ -804,12 +785,12 @@ disable_gl_state (CoglAttribute **attributes,
              required */
           break;
         case COGL_ATTRIBUTE_NAME_ID_POSITION_ARRAY:
-          /* GE (glDisableClientState (GL_VERTEX_ARRAY)); */
+          /* GE (ctx, glDisableClientState (GL_VERTEX_ARRAY)); */
           break;
         case COGL_ATTRIBUTE_NAME_ID_CUSTOM_ARRAY:
 #ifdef MAY_HAVE_PROGRAMABLE_GL
           /* FIXME: go through cogl cache to enable generic array */
-          GE (glDisableVertexAttribArray (generic_index++));
+          GE (ctx, glDisableVertexAttribArray (generic_index++));
 #endif
           break;
         default:
@@ -1109,11 +1090,13 @@ _cogl_draw_attributes (CoglVerticesMode mode,
   ValidateLayerState state;
   CoglPipeline *source;
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   flush_state (flags, &state);
 
   source = enable_gl_state (flags, attributes, n_attributes, &state);
 
-  GE (glDrawArrays ((GLenum)mode, first_vertex, n_vertices));
+  GE (ctx, glDrawArrays ((GLenum)mode, first_vertex, n_vertices));
 
   /* FIXME: we shouldn't be disabling state after drawing we should
    * just disable the things not needed after enabling state. */
@@ -1223,10 +1206,10 @@ _cogl_draw_indexed_attributes (CoglVerticesMode mode,
       break;
     }
 
-  GE (glDrawElements ((GLenum)mode,
-                      n_vertices,
-                      indices_gl_type,
-                      base + buffer_offset + index_size * first_vertex));
+  GE (ctx, glDrawElements ((GLenum)mode,
+                           n_vertices,
+                           indices_gl_type,
+                           base + buffer_offset + index_size * first_vertex));
 
   _cogl_buffer_unbind (buffer);
 
diff --git a/cogl/cogl-buffer.c b/cogl/cogl-buffer.c
index eae7e0c..207b170 100644
--- a/cogl/cogl-buffer.c
+++ b/cogl/cogl-buffer.c
@@ -49,21 +49,6 @@
  * GL/GLES compatibility defines for the buffer API:
  */
 
-#if defined (HAVE_COGL_GL)
-
-#define glGenBuffers ctx->glGenBuffers
-#define glBindBuffer ctx->glBindBuffer
-#define glBufferData ctx->glBufferData
-#define glBufferSubData ctx->glBufferSubData
-#define glGetBufferSubData ctx->glGetBufferSubData
-#define glDeleteBuffers ctx->glDeleteBuffers
-
-#endif
-
-/* These two are always accessed through an extension, even on GLES */
-#define glMapBuffer ctx->glMapBuffer
-#define glUnmapBuffer ctx->glUnmapBuffer
-
 #ifndef GL_PIXEL_PACK_BUFFER
 #define GL_PIXEL_PACK_BUFFER 0x88EB
 #endif
@@ -165,16 +150,21 @@ bo_map (CoglBuffer       *buffer,
    * store is created. */
   if (!buffer->store_created || (hints & COGL_BUFFER_MAP_HINT_DISCARD))
     {
-      GE( glBufferData (gl_target,
-                        buffer->size,
-                        NULL,
-                        _cogl_buffer_hints_to_gl_enum (buffer->usage_hint,
-                                                       buffer->update_hint)) );
+      GLenum gl_enum;
+
+      gl_enum = _cogl_buffer_hints_to_gl_enum (buffer->usage_hint,
+                                               buffer->update_hint);
+
+
+      GE( ctx, glBufferData (gl_target,
+                             buffer->size,
+                             NULL,
+                             gl_enum) );
       buffer->store_created = TRUE;
     }
 
-  GE_RET( data, glMapBuffer (gl_target,
-                             _cogl_buffer_access_to_gl_enum (access)) );
+  GE_RET( data, ctx, glMapBuffer (gl_target,
+                                  _cogl_buffer_access_to_gl_enum (access)) );
   if (data)
     buffer->flags |= COGL_BUFFER_FLAG_MAPPED;
 
@@ -190,7 +180,8 @@ bo_unmap (CoglBuffer *buffer)
 
   _cogl_buffer_bind (buffer, buffer->last_target);
 
-  GE( glUnmapBuffer (convert_bind_target_to_gl_target (buffer->last_target)) );
+  GE( ctx, glUnmapBuffer (convert_bind_target_to_gl_target
+                          (buffer->last_target)) );
   buffer->flags &= ~COGL_BUFFER_FLAG_MAPPED;
 
   _cogl_buffer_unbind (buffer);
@@ -217,15 +208,16 @@ bo_set_data (CoglBuffer   *buffer,
    * store is created. */
   if (!buffer->store_created)
     {
-      GE( glBufferData (gl_target,
-                        buffer->size,
-                        NULL,
-                        _cogl_buffer_hints_to_gl_enum (buffer->usage_hint,
-                                                       buffer->update_hint)) );
+      GLenum gl_enum = _cogl_buffer_hints_to_gl_enum (buffer->usage_hint,
+                                                      buffer->update_hint);
+      GE( ctx, glBufferData (gl_target,
+                             buffer->size,
+                             NULL,
+                             gl_enum) );
       buffer->store_created = TRUE;
     }
 
-  GE( glBufferSubData (gl_target, offset, size, data) );
+  GE( ctx, glBufferSubData (gl_target, offset, size, data) );
 
   _cogl_buffer_unbind (buffer);
 
@@ -294,7 +286,7 @@ _cogl_buffer_initialize (CoglBuffer           *buffer,
       buffer->vtable.unmap = bo_unmap;
       buffer->vtable.set_data = bo_set_data;
 
-      GE( glGenBuffers (1, &buffer->gl_handle) );
+      GE( ctx, glGenBuffers (1, &buffer->gl_handle) );
       buffer->flags |= COGL_BUFFER_FLAG_BUFFER_OBJECT;
     }
 }
@@ -308,7 +300,7 @@ _cogl_buffer_fini (CoglBuffer *buffer)
   g_return_if_fail (buffer->immutable_ref == 0);
 
   if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
-    GE( glDeleteBuffers (1, &buffer->gl_handle) );
+    GE( ctx, glDeleteBuffers (1, &buffer->gl_handle) );
   else
     g_free (buffer->data);
 }
@@ -372,7 +364,7 @@ _cogl_buffer_bind (CoglBuffer *buffer, CoglBufferBindTarget target)
   if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
     {
       GLenum gl_target = convert_bind_target_to_gl_target (buffer->last_target);
-      GE( glBindBuffer (gl_target, buffer->gl_handle) );
+      GE( ctx, glBindBuffer (gl_target, buffer->gl_handle) );
       return NULL;
     }
   else
@@ -392,7 +384,7 @@ _cogl_buffer_unbind (CoglBuffer *buffer)
   if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
     {
       GLenum gl_target = convert_bind_target_to_gl_target (buffer->last_target);
-      GE( glBindBuffer (gl_target, 0) );
+      GE( ctx, glBindBuffer (gl_target, 0) );
     }
 
   ctx->current_buffer[buffer->last_target] = NULL;
diff --git a/cogl/cogl-clip-stack.c b/cogl/cogl-clip-stack.c
index 5f21810..c599cfd 100644
--- a/cogl/cogl-clip-stack.c
+++ b/cogl/cogl-clip-stack.c
@@ -117,9 +117,9 @@ set_clip_plane (GLint plane_num,
 #if defined (HAVE_COGL_GLES2)
   g_assert_not_reached ();
 #elif defined (HAVE_COGL_GLES)
-  GE( glClipPlanef (plane_num, plane) );
+  GE( ctx, glClipPlanef (plane_num, plane) );
 #else
-  GE( glClipPlane (plane_num, plane) );
+  GE( ctx, glClipPlane (plane_num, plane) );
 #endif
 
   _cogl_matrix_stack_pop (modelview_stack);
@@ -213,15 +213,15 @@ add_stencil_clip_rectangle (float x_1,
 
   if (first)
     {
-      GE( glEnable (GL_STENCIL_TEST) );
+      GE( ctx, glEnable (GL_STENCIL_TEST) );
 
       /* Initially disallow everything */
-      GE( glClearStencil (0) );
-      GE( glClear (GL_STENCIL_BUFFER_BIT) );
+      GE( ctx, glClearStencil (0) );
+      GE( ctx, glClear (GL_STENCIL_BUFFER_BIT) );
 
       /* Punch out a hole to allow the rectangle */
-      GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
-      GE( glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) );
+      GE( ctx, glStencilFunc (GL_NEVER, 0x1, 0x1) );
+      GE( ctx, glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) );
 
       _cogl_rectangle_immediate (x_1, y_1, x_2, y_2);
     }
@@ -229,14 +229,14 @@ add_stencil_clip_rectangle (float x_1,
     {
       /* Add one to every pixel of the stencil buffer in the
 	 rectangle */
-      GE( glStencilFunc (GL_NEVER, 0x1, 0x3) );
-      GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
+      GE( ctx, glStencilFunc (GL_NEVER, 0x1, 0x3) );
+      GE( ctx, glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
       _cogl_rectangle_immediate (x_1, y_1, x_2, y_2);
 
       /* Subtract one from all pixels in the stencil buffer so that
 	 only pixels where both the original stencil buffer and the
 	 rectangle are set will be valid */
-      GE( glStencilOp (GL_DECR, GL_DECR, GL_DECR) );
+      GE( ctx, glStencilOp (GL_DECR, GL_DECR, GL_DECR) );
 
       _cogl_matrix_stack_push (projection_stack);
       _cogl_matrix_stack_load_identity (projection_stack);
@@ -256,8 +256,8 @@ add_stencil_clip_rectangle (float x_1,
     }
 
   /* Restore the stencil mode */
-  GE( glStencilFunc (GL_EQUAL, 0x1, 0x1) );
-  GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) );
+  GE( ctx, glStencilFunc (GL_EQUAL, 0x1, 0x1) );
+  GE( ctx, glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) );
 
   /* restore the original source pipeline */
   cogl_pop_source ();
@@ -266,25 +266,31 @@ add_stencil_clip_rectangle (float x_1,
 static void
 disable_stencil_buffer (void)
 {
-  GE( glDisable (GL_STENCIL_TEST) );
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
+  GE( ctx, glDisable (GL_STENCIL_TEST) );
 }
 
 static void
 enable_clip_planes (void)
 {
-  GE( glEnable (GL_CLIP_PLANE0) );
-  GE( glEnable (GL_CLIP_PLANE1) );
-  GE( glEnable (GL_CLIP_PLANE2) );
-  GE( glEnable (GL_CLIP_PLANE3) );
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
+  GE( ctx, glEnable (GL_CLIP_PLANE0) );
+  GE( ctx, glEnable (GL_CLIP_PLANE1) );
+  GE( ctx, glEnable (GL_CLIP_PLANE2) );
+  GE( ctx, glEnable (GL_CLIP_PLANE3) );
 }
 
 static void
 disable_clip_planes (void)
 {
-  GE( glDisable (GL_CLIP_PLANE3) );
-  GE( glDisable (GL_CLIP_PLANE2) );
-  GE( glDisable (GL_CLIP_PLANE1) );
-  GE( glDisable (GL_CLIP_PLANE0) );
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
+  GE( ctx, glDisable (GL_CLIP_PLANE3) );
+  GE( ctx, glDisable (GL_CLIP_PLANE2) );
+  GE( ctx, glDisable (GL_CLIP_PLANE1) );
+  GE( ctx, glDisable (GL_CLIP_PLANE0) );
 }
 
 static gpointer
@@ -612,7 +618,7 @@ _cogl_clip_stack_flush (CoglClipStack *stack)
       COGL_NOTE (CLIPPING, "Flushed empty clip stack");
 
       ctx->current_clip_stack_uses_stencil = FALSE;
-      GE (glDisable (GL_SCISSOR_TEST));
+      GE (ctx, glDisable (GL_SCISSOR_TEST));
       return;
     }
 
@@ -654,10 +660,10 @@ _cogl_clip_stack_flush (CoglClipStack *stack)
              scissor_x0, scissor_y0,
              scissor_x1, scissor_y1);
 
-  GE (glEnable (GL_SCISSOR_TEST));
-  GE (glScissor (scissor_x0, scissor_y_start,
-                 scissor_x1 - scissor_x0,
-                 scissor_y1 - scissor_y0));
+  GE (ctx, glEnable (GL_SCISSOR_TEST));
+  GE (ctx, glScissor (scissor_x0, scissor_y_start,
+                      scissor_x1 - scissor_x0,
+                      scissor_y1 - scissor_y0));
 
   /* Add all of the entries. This will end up adding them in the
      reverse order that they were specified but as all of the clips
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c
index 884ec4a..13c9142 100644
--- a/cogl/cogl-context.c
+++ b/cogl/cogl-context.c
@@ -47,7 +47,6 @@
 
 #ifdef HAVE_COGL_GL
 #include "cogl-pipeline-fragend-arbfp-private.h"
-#define glActiveTexture _context->glActiveTexture
 #endif
 
 /* This isn't defined in the GLES headers */
@@ -199,7 +198,7 @@ cogl_context_new (CoglDisplay *display,
   /* See cogl-pipeline.c for more details about why we leave texture unit 1
    * active by default... */
   context->active_texture_unit = 1;
-  GE (glActiveTexture (GL_TEXTURE1));
+  GE (context, glActiveTexture (GL_TEXTURE1));
 
   context->legacy_fog_state.enabled = FALSE;
 
@@ -307,7 +306,7 @@ cogl_context_new (CoglDisplay *display,
    * makes things a bit simpler for us. Under GLES2 the alpha test is
    * implemented in the fragment shader so there is no enable for it
    */
-  GE (glEnable (GL_ALPHA_TEST));
+  GE (context, glEnable (GL_ALPHA_TEST));
 #endif
 
 #ifdef HAVE_COGL_GLES2
@@ -355,7 +354,7 @@ cogl_context_new (CoglDisplay *display,
      sprites are handled using a builtin varying in the shader. */
 #ifndef HAVE_COGL_GLES2
   if (cogl_features_available (COGL_FEATURE_POINT_SPRITE))
-    GE (glEnable (GL_POINT_SPRITE));
+    GE (context, glEnable (GL_POINT_SPRITE));
 #endif
 
   return _cogl_context_object_new (context);
diff --git a/cogl/cogl-ext-functions.h b/cogl/cogl-ext-functions.h
index e73e4dc..ac2e1a4 100644
--- a/cogl/cogl-ext-functions.h
+++ b/cogl/cogl-ext-functions.h
@@ -48,6 +48,212 @@
  * @extension_names: A list of extension names to try. If any of these
  * extensions match then it will be used.
  */
+
+/* These are the core GL functions which we assume will always be
+   available */
+COGL_EXT_BEGIN (core,
+                0, 0,
+                COGL_EXT_IN_GLES | COGL_EXT_IN_GLES2,
+                "\0",
+                "\0")
+COGL_EXT_FUNCTION (void, glBindTexture,
+                   (GLenum target, GLuint texture))
+COGL_EXT_FUNCTION (void, glBlendFunc,
+                   (GLenum sfactor, GLenum dfactor))
+COGL_EXT_FUNCTION (void, glClear,
+                   (GLbitfield mask))
+COGL_EXT_FUNCTION (void, glClearColor,
+                   (GLclampf red,
+                    GLclampf green,
+                    GLclampf blue,
+                    GLclampf alpha))
+COGL_EXT_FUNCTION (void, glClearStencil,
+                   (GLint s))
+COGL_EXT_FUNCTION (void, glColorMask,
+                   (GLboolean red,
+                    GLboolean green,
+                    GLboolean blue,
+                    GLboolean alpha))
+COGL_EXT_FUNCTION (void, glCopyTexSubImage2D,
+                   (GLenum target,
+                    GLint level,
+                    GLint xoffset,
+                    GLint yoffset,
+                    GLint x,
+                    GLint y,
+                    GLsizei width,
+                    GLsizei height))
+COGL_EXT_FUNCTION (void, glDeleteTextures,
+                   (GLsizei n, const GLuint* textures))
+COGL_EXT_FUNCTION (void, glDepthFunc,
+                   (GLenum func))
+COGL_EXT_FUNCTION (void, glDepthMask,
+                   (GLboolean flag))
+COGL_EXT_FUNCTION (void, glDisable,
+                   (GLenum cap))
+COGL_EXT_FUNCTION (void, glDrawArrays,
+                   (GLenum mode, GLint first, GLsizei count))
+COGL_EXT_FUNCTION (void, glDrawElements,
+                   (GLenum mode,
+                    GLsizei count,
+                    GLenum type,
+                    const GLvoid* indices))
+COGL_EXT_FUNCTION (void, glEnable,
+                   (GLenum cap))
+COGL_EXT_FUNCTION (void, glFinish,
+                   (void))
+COGL_EXT_FUNCTION (void, glFlush,
+                   (void))
+COGL_EXT_FUNCTION (void, glFrontFace,
+                   (GLenum mode))
+COGL_EXT_FUNCTION (void, glGenTextures,
+                   (GLsizei n, GLuint* textures))
+COGL_EXT_FUNCTION (GLenum, glGetError,
+                   (void))
+COGL_EXT_FUNCTION (void, glGetIntegerv,
+                   (GLenum pname, GLint* params))
+COGL_EXT_FUNCTION (const GLubyte*, glGetString,
+                   (GLenum name))
+COGL_EXT_FUNCTION (void, glHint,
+                   (GLenum target, GLenum mode))
+COGL_EXT_FUNCTION (GLboolean, glIsTexture,
+                   (GLuint texture))
+COGL_EXT_FUNCTION (void, glPixelStorei,
+                   (GLenum pname, GLint param))
+COGL_EXT_FUNCTION (void, glReadPixels,
+                   (GLint x,
+                    GLint y,
+                    GLsizei width,
+                    GLsizei height,
+                    GLenum format,
+                    GLenum type,
+                    GLvoid* pixels))
+COGL_EXT_FUNCTION (void, glScissor,
+                   (GLint x, GLint y, GLsizei width, GLsizei height))
+COGL_EXT_FUNCTION (void, glStencilFunc,
+                   (GLenum func, GLint ref, GLuint mask))
+COGL_EXT_FUNCTION (void, glStencilMask,
+                   (GLuint mask))
+COGL_EXT_FUNCTION (void, glStencilOp,
+                   (GLenum fail, GLenum zfail, GLenum zpass))
+COGL_EXT_FUNCTION (void, glTexImage2D,
+                   (GLenum target,
+                    GLint level,
+                    GLint internalformat,
+                    GLsizei width,
+                    GLsizei height,
+                    GLint border,
+                    GLenum format,
+                    GLenum type,
+                    const GLvoid* pixels))
+COGL_EXT_FUNCTION (void, glTexParameterfv,
+                   (GLenum target, GLenum pname, const GLfloat* params))
+COGL_EXT_FUNCTION (void, glTexParameteri,
+                   (GLenum target, GLenum pname, GLint param))
+COGL_EXT_FUNCTION (void, glTexSubImage2D,
+                   (GLenum target,
+                    GLint level,
+                    GLint xoffset,
+                    GLint yoffset,
+                    GLsizei width,
+                    GLsizei height,
+                    GLenum format,
+                    GLenum type,
+                    const GLvoid* pixels))
+COGL_EXT_FUNCTION (void, glViewport,
+                   (GLint x, GLint y, GLsizei width, GLsizei height))
+COGL_EXT_END ()
+
+/* These are the core GL functions which are available when the API
+   supports fixed-function (ie, GL and GLES1.1) */
+COGL_EXT_BEGIN (fixed_function_core,
+                0, 0,
+                COGL_EXT_IN_GLES,
+                "\0",
+                "\0")
+COGL_EXT_FUNCTION (void, glAlphaFunc,
+                   (GLenum func, GLclampf ref))
+COGL_EXT_FUNCTION (void, glFogf,
+                   (GLenum pname, GLfloat param))
+COGL_EXT_FUNCTION (void, glFogfv,
+                   (GLenum pname, const GLfloat *params))
+COGL_EXT_FUNCTION (void, glLoadMatrixf,
+                   (const GLfloat *m))
+COGL_EXT_FUNCTION (void, glMaterialfv,
+                   (GLenum face, GLenum pname, const GLfloat *params))
+COGL_EXT_FUNCTION (void, glPointSize,
+                   (GLfloat size))
+COGL_EXT_FUNCTION (void, glTexEnvfv,
+                   (GLenum target, GLenum pname, const GLfloat *params))
+COGL_EXT_FUNCTION (void, glColor4ub,
+                   (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha))
+COGL_EXT_FUNCTION (void, glColorPointer,
+                   (GLint size,
+                    GLenum type,
+                    GLsizei stride,
+                    const GLvoid *pointer))
+COGL_EXT_FUNCTION (void, glDisableClientState,
+                   (GLenum array))
+COGL_EXT_FUNCTION (void, glEnableClientState,
+                   (GLenum array))
+COGL_EXT_FUNCTION (void, glLoadIdentity,
+                   (void))
+COGL_EXT_FUNCTION (void, glMatrixMode,
+                   (GLenum mode))
+COGL_EXT_FUNCTION (void, glNormalPointer,
+                   (GLenum type, GLsizei stride, const GLvoid *pointer))
+COGL_EXT_FUNCTION (void, glTexCoordPointer,
+                   (GLint size,
+                    GLenum type,
+                    GLsizei stride,
+                    const GLvoid *pointer))
+COGL_EXT_FUNCTION (void, glTexEnvi,
+                   (GLenum target,
+                    GLenum pname,
+                    GLint param))
+COGL_EXT_FUNCTION (void, glVertexPointer,
+                   (GLint size,
+                    GLenum type,
+                    GLsizei stride,
+                    const GLvoid *pointer))
+COGL_EXT_END ()
+
+/* These are the core GL functions which are only available in big
+   GL */
+COGL_EXT_BEGIN (only_in_big_gl,
+                0, 0,
+                0, /* not in GLES */
+                "\0",
+                "\0")
+COGL_EXT_FUNCTION (void, glGetTexLevelParameteriv,
+                   (GLenum target, GLint level,
+                    GLenum pname, GLint *params))
+COGL_EXT_FUNCTION (void, glGetTexImage,
+                   (GLenum target, GLint level,
+                    GLenum format, GLenum type,
+                    GLvoid *pixels))
+COGL_EXT_FUNCTION (void, glClipPlane,
+                   (GLenum plane, const double *equation))
+COGL_EXT_FUNCTION (void, glDepthRange,
+                   (double near_val, double far_val))
+COGL_EXT_FUNCTION (void, glDrawBuffer,
+                   (GLenum mode))
+COGL_EXT_END ()
+
+/* These functions are only available in GLES 1.1 and are used as
+   replacements for some GL equivalents that only accept double
+   arguments */
+COGL_EXT_BEGIN (only_in_gles1,
+                255, 255,
+                COGL_EXT_IN_GLES,
+                "\0",
+                "\0")
+COGL_EXT_FUNCTION (void, glClipPlanef,
+                   (GLenum plane, const GLfloat *equation))
+COGL_EXT_FUNCTION (void, glDepthRangef,
+                   (GLfloat near_val, GLfloat far_val))
+COGL_EXT_END ()
+
 COGL_EXT_BEGIN (offscreen,
                 255, 255,
                 COGL_EXT_IN_GLES2,
@@ -303,6 +509,12 @@ COGL_EXT_FUNCTION (void, glGetProgramInfoLog,
                     GLsizei              *length,
                     GLchar               *infoLog))
 
+COGL_EXT_FUNCTION (void, glVertexAttrib4f,
+                   (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w))
+
+COGL_EXT_FUNCTION (GLint, glGetAttribLocation,
+                   (GLuint program, const GLchar *name))
+
 COGL_EXT_END ()
 
 COGL_EXT_BEGIN (vbos, 1, 5,
diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c
index e96f1f6..d5b4ad4 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -40,25 +40,6 @@
 #include "cogl-journal-private.h"
 #include "cogl-winsys-private.h"
 
-#ifndef HAVE_COGL_GLES2
-
-#define glGenRenderbuffers                ctx->glGenRenderbuffers
-#define glDeleteRenderbuffers             ctx->glDeleteRenderbuffers
-#define glBindRenderbuffer                ctx->glBindRenderbuffer
-#define glRenderbufferStorage             ctx->glRenderbufferStorage
-#define glGenFramebuffers                 ctx->glGenFramebuffers
-#define glBindFramebuffer                 ctx->glBindFramebuffer
-#define glFramebufferTexture2D            ctx->glFramebufferTexture2D
-#define glFramebufferRenderbuffer         ctx->glFramebufferRenderbuffer
-#define glCheckFramebufferStatus          ctx->glCheckFramebufferStatus
-#define glDeleteFramebuffers              ctx->glDeleteFramebuffers
-#define glGetFramebufferAttachmentParameteriv \
-                                          ctx->glGetFramebufferAttachmentParameteriv
-
-#endif
-
-#define glBlitFramebuffer                 ctx->glBlitFramebuffer
-
 #ifndef GL_FRAMEBUFFER
 #define GL_FRAMEBUFFER		0x8D40
 #endif
@@ -252,9 +233,11 @@ _cogl_clear4f (unsigned long buffers,
 {
   GLbitfield gl_buffers = 0;
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   if (buffers & COGL_BUFFER_BIT_COLOR)
     {
-      GE( glClearColor (red, green, blue, alpha) );
+      GE( ctx, glClearColor (red, green, blue, alpha) );
       gl_buffers |= GL_COLOR_BUFFER_BIT;
     }
 
@@ -277,7 +260,7 @@ _cogl_clear4f (unsigned long buffers,
       return;
     }
 
-  GE (glClear (gl_buffers));
+  GE (ctx, glClear (gl_buffers));
 }
 
 void
@@ -626,9 +609,7 @@ _cogl_framebuffer_flush_dependency_journals (CoglFramebuffer *framebuffer)
 static inline void
 _cogl_framebuffer_init_bits (CoglFramebuffer *framebuffer)
 {
-#ifdef HAVE_COGL_GL
   CoglContext *ctx = framebuffer->context;
-#endif
 
   if (G_LIKELY (!framebuffer->dirty_bitmasks))
     return;
@@ -642,36 +623,39 @@ _cogl_framebuffer_init_bits (CoglFramebuffer *framebuffer)
       attachment = GL_COLOR_ATTACHMENT0;
 
       pname = GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE;
-      GE( glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
-                                                 attachment,
-                                                 pname,
-                                                 &framebuffer->red_bits) );
+      GE( ctx, glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
+                                                      attachment,
+                                                      pname,
+                                                      &framebuffer->red_bits) );
 
       pname = GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE;
-      GE( glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
-                                                 attachment,
-                                                 pname,
-                                                 &framebuffer->green_bits) );
+      GE( ctx, glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
+                                                      attachment,
+                                                      pname,
+                                                      &framebuffer->green_bits)
+          );
 
       pname = GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE;
-      GE( glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
-                                                 attachment,
-                                                 pname,
-                                                 &framebuffer->blue_bits) );
+      GE( ctx, glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
+                                                      attachment,
+                                                      pname,
+                                                      &framebuffer->blue_bits)
+          );
 
       pname = GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE;
-      GE( glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
-                                                 attachment,
-                                                 pname,
-                                                 &framebuffer->alpha_bits) );
+      GE( ctx, glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
+                                                      attachment,
+                                                      pname,
+                                                      &framebuffer->alpha_bits)
+          );
     }
   else
 #endif /* HAVE_COGL_GL */
     {
-      GE( glGetIntegerv (GL_RED_BITS,   &framebuffer->red_bits)   );
-      GE( glGetIntegerv (GL_GREEN_BITS, &framebuffer->green_bits) );
-      GE( glGetIntegerv (GL_BLUE_BITS,  &framebuffer->blue_bits)  );
-      GE( glGetIntegerv (GL_ALPHA_BITS, &framebuffer->alpha_bits) );
+      GE( ctx, glGetIntegerv (GL_RED_BITS,   &framebuffer->red_bits)   );
+      GE( ctx, glGetIntegerv (GL_GREEN_BITS, &framebuffer->green_bits) );
+      GE( ctx, glGetIntegerv (GL_BLUE_BITS,  &framebuffer->blue_bits)  );
+      GE( ctx, glGetIntegerv (GL_ALPHA_BITS, &framebuffer->alpha_bits) );
     }
 
 
@@ -729,28 +713,30 @@ try_creating_fbo (CoglOffscreen *offscreen,
   ctx->dirty_bound_framebuffer = 1;
 
   /* Generate framebuffer */
-  glGenFramebuffers (1, &fbo_gl_handle);
-  GE (glBindFramebuffer (GL_FRAMEBUFFER, fbo_gl_handle));
+  ctx->glGenFramebuffers (1, &fbo_gl_handle);
+  GE (ctx, glBindFramebuffer (GL_FRAMEBUFFER, fbo_gl_handle));
   offscreen->fbo_handle = fbo_gl_handle;
 
-  GE (glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
-                              tex_gl_target, tex_gl_handle, data->level));
+  GE (ctx, glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+                                   tex_gl_target, tex_gl_handle, data->level));
 
   if (flags & _TRY_DEPTH_STENCIL)
     {
       /* Create a renderbuffer for depth and stenciling */
-      GE (glGenRenderbuffers (1, &gl_depth_stencil_handle));
-      GE (glBindRenderbuffer (GL_RENDERBUFFER, gl_depth_stencil_handle));
-      GE (glRenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_STENCIL,
-                                 data->level_width,
-                                 data->level_height));
-      GE (glBindRenderbuffer (GL_RENDERBUFFER, 0));
-      GE (glFramebufferRenderbuffer (GL_FRAMEBUFFER,
-                                     GL_STENCIL_ATTACHMENT,
-                                     GL_RENDERBUFFER, gl_depth_stencil_handle));
-      GE (glFramebufferRenderbuffer (GL_FRAMEBUFFER,
-                                     GL_DEPTH_ATTACHMENT,
-                                     GL_RENDERBUFFER, gl_depth_stencil_handle));
+      GE (ctx, glGenRenderbuffers (1, &gl_depth_stencil_handle));
+      GE (ctx, glBindRenderbuffer (GL_RENDERBUFFER, gl_depth_stencil_handle));
+      GE (ctx, glRenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_STENCIL,
+                                      data->level_width,
+                                      data->level_height));
+      GE (ctx, glBindRenderbuffer (GL_RENDERBUFFER, 0));
+      GE (ctx, glFramebufferRenderbuffer (GL_FRAMEBUFFER,
+                                          GL_STENCIL_ATTACHMENT,
+                                          GL_RENDERBUFFER,
+                                          gl_depth_stencil_handle));
+      GE (ctx, glFramebufferRenderbuffer (GL_FRAMEBUFFER,
+                                          GL_DEPTH_ATTACHMENT,
+                                          GL_RENDERBUFFER,
+                                          gl_depth_stencil_handle));
       offscreen->renderbuffers =
         g_slist_prepend (offscreen->renderbuffers,
                          GUINT_TO_POINTER (gl_depth_stencil_handle));
@@ -758,15 +744,15 @@ try_creating_fbo (CoglOffscreen *offscreen,
 
   if (flags & _TRY_DEPTH)
     {
-      GE (glGenRenderbuffers (1, &gl_depth_handle));
-      GE (glBindRenderbuffer (GL_RENDERBUFFER, gl_depth_handle));
+      GE (ctx, glGenRenderbuffers (1, &gl_depth_handle));
+      GE (ctx, glBindRenderbuffer (GL_RENDERBUFFER, gl_depth_handle));
       /* For now we just ask for GL_DEPTH_COMPONENT16 since this is all that's
        * available under GLES */
-      GE (glRenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT16,
+      GE (ctx, glRenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT16,
                                  data->level_width,
                                  data->level_height));
-      GE (glBindRenderbuffer (GL_RENDERBUFFER, 0));
-      GE (glFramebufferRenderbuffer (GL_FRAMEBUFFER,
+      GE (ctx, glBindRenderbuffer (GL_RENDERBUFFER, 0));
+      GE (ctx, glFramebufferRenderbuffer (GL_FRAMEBUFFER,
                                      GL_DEPTH_ATTACHMENT,
                                      GL_RENDERBUFFER, gl_depth_handle));
       offscreen->renderbuffers =
@@ -776,13 +762,13 @@ try_creating_fbo (CoglOffscreen *offscreen,
 
   if (flags & _TRY_STENCIL)
     {
-      GE (glGenRenderbuffers (1, &gl_stencil_handle));
-      GE (glBindRenderbuffer (GL_RENDERBUFFER, gl_stencil_handle));
-      GE (glRenderbufferStorage (GL_RENDERBUFFER, GL_STENCIL_INDEX8,
+      GE (ctx, glGenRenderbuffers (1, &gl_stencil_handle));
+      GE (ctx, glBindRenderbuffer (GL_RENDERBUFFER, gl_stencil_handle));
+      GE (ctx, glRenderbufferStorage (GL_RENDERBUFFER, GL_STENCIL_INDEX8,
                                  data->level_width,
                                  data->level_height));
-      GE (glBindRenderbuffer (GL_RENDERBUFFER, 0));
-      GE (glFramebufferRenderbuffer (GL_FRAMEBUFFER,
+      GE (ctx, glBindRenderbuffer (GL_RENDERBUFFER, 0));
+      GE (ctx, glFramebufferRenderbuffer (GL_FRAMEBUFFER,
                                      GL_STENCIL_ATTACHMENT,
                                      GL_RENDERBUFFER, gl_stencil_handle));
       offscreen->renderbuffers =
@@ -791,18 +777,18 @@ try_creating_fbo (CoglOffscreen *offscreen,
     }
 
   /* Make sure it's complete */
-  status = glCheckFramebufferStatus (GL_FRAMEBUFFER);
+  status = ctx->glCheckFramebufferStatus (GL_FRAMEBUFFER);
 
   if (status != GL_FRAMEBUFFER_COMPLETE)
     {
       GSList *l;
 
-      GE (glDeleteFramebuffers (1, &fbo_gl_handle));
+      GE (ctx, glDeleteFramebuffers (1, &fbo_gl_handle));
 
       for (l = offscreen->renderbuffers; l; l = l->next)
         {
           GLuint renderbuffer = GPOINTER_TO_UINT (l->data);
-          GE (glDeleteRenderbuffers (1, &renderbuffer));
+          GE (ctx, glDeleteRenderbuffers (1, &renderbuffer));
         }
 
       g_slist_free (offscreen->renderbuffers);
@@ -941,9 +927,7 @@ static void
 _cogl_offscreen_free (CoglOffscreen *offscreen)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (offscreen);
-#ifndef HAVE_COGL_GLES2
   CoglContext *ctx = framebuffer->context;
-#endif
   GSList *l;
 
   /* Chain up to parent */
@@ -952,11 +936,11 @@ _cogl_offscreen_free (CoglOffscreen *offscreen)
   for (l = offscreen->renderbuffers; l; l = l->next)
     {
       GLuint renderbuffer = GPOINTER_TO_UINT (l->data);
-      GE (glDeleteRenderbuffers (1, &renderbuffer));
+      GE (ctx, glDeleteRenderbuffers (1, &renderbuffer));
     }
   g_slist_free (offscreen->renderbuffers);
 
-  GE (glDeleteFramebuffers (1, &offscreen->fbo_handle));
+  GE (ctx, glDeleteFramebuffers (1, &offscreen->fbo_handle));
 
   if (offscreen->texture != COGL_INVALID_HANDLE)
     cogl_handle_unref (offscreen->texture);
@@ -1368,7 +1352,7 @@ bind_gl_framebuffer (CoglContext *ctx,
                      CoglFramebuffer *framebuffer)
 {
   if (framebuffer->type == COGL_FRAMEBUFFER_TYPE_OFFSCREEN)
-    GE (glBindFramebuffer (target,
+    GE (ctx, glBindFramebuffer (target,
                            COGL_OFFSCREEN (framebuffer)->fbo_handle));
   else
     {
@@ -1377,7 +1361,7 @@ bind_gl_framebuffer (CoglContext *ctx,
       winsys->onscreen_bind (COGL_ONSCREEN (framebuffer));
       /* glBindFramebuffer is an an extension with OpenGL ES 1.1 */
       if (cogl_features_available (COGL_FEATURE_OFFSCREEN))
-        GE (glBindFramebuffer (target, 0));
+        GE (ctx, glBindFramebuffer (target, 0));
     }
 }
 
@@ -1435,7 +1419,7 @@ _cogl_framebuffer_flush_state (CoglFramebuffer *draw_buffer,
                  draw_buffer->viewport_width,
                  draw_buffer->viewport_height);
 
-      GE (glViewport (draw_buffer->viewport_x,
+      GE (ctx, glViewport (draw_buffer->viewport_x,
                       gl_viewport_y,
                       draw_buffer->viewport_width,
                       draw_buffer->viewport_height));
@@ -1596,7 +1580,7 @@ _cogl_blit_framebuffer (unsigned int src_x,
      the scissor */
   _cogl_clip_stack_flush (NULL);
 
-  glBlitFramebuffer (src_x, src_y,
+  ctx->glBlitFramebuffer (src_x, src_y,
                      src_x + width, src_y + height,
                      dst_x, dst_y,
                      dst_x + width, dst_y + height,
diff --git a/cogl/cogl-internal.h b/cogl/cogl-internal.h
index b695abd..71e5766 100644
--- a/cogl/cogl-internal.h
+++ b/cogl/cogl-internal.h
@@ -66,10 +66,10 @@ typedef struct _CoglBoxedValue
 const char *
 cogl_gl_error_to_string (GLenum error_code);
 
-#define GE(x)                           G_STMT_START {  \
+#define GE(ctx, x)                      G_STMT_START {  \
   GLenum __err;                                         \
-  (x);                                                  \
-  while ((__err = glGetError ()) != GL_NO_ERROR)        \
+  (ctx)->x;                                             \
+  while ((__err = (ctx)->glGetError ()) != GL_NO_ERROR) \
     {                                                   \
       g_warning ("%s: GL error (%d): %s\n",             \
                  G_STRLOC,                              \
@@ -77,10 +77,10 @@ cogl_gl_error_to_string (GLenum error_code);
                  cogl_gl_error_to_string (__err));      \
     }                                   } G_STMT_END
 
-#define GE_RET(ret, x)                  G_STMT_START {  \
+#define GE_RET(ret, ctx, x)             G_STMT_START {  \
   GLenum __err;                                         \
-  ret = (x);                                            \
-  while ((__err = glGetError ()) != GL_NO_ERROR)        \
+  ret = (ctx)->x;                                       \
+  while ((__err = (ctx)->glGetError ()) != GL_NO_ERROR) \
     {                                                   \
       g_warning ("%s: GL error (%d): %s\n",             \
                  G_STRLOC,                              \
@@ -90,8 +90,8 @@ cogl_gl_error_to_string (GLenum error_code);
 
 #else /* !COGL_GL_DEBUG */
 
-#define GE(x) (x)
-#define GE_RET(ret, x)  (ret = (x))
+#define GE(ctx, x) ((ctx)->x)
+#define GE_RET(ret, ctx, x) (ret = ((ctx)->x))
 
 #endif /* COGL_GL_DEBUG */
 
diff --git a/cogl/cogl-matrix-stack.c b/cogl/cogl-matrix-stack.c
index d844c7b..d761b53 100644
--- a/cogl/cogl-matrix-stack.c
+++ b/cogl/cogl-matrix-stack.c
@@ -402,15 +402,17 @@ flush_to_fixed_api_gl (gboolean is_identity,
 {
   CoglMatrixStack *stack = user_data;
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   if (is_identity)
     {
       if (!stack->flushed_identity)
-        GE (glLoadIdentity ());
+        GE (ctx, glLoadIdentity ());
       stack->flushed_identity = TRUE;
     }
   else
     {
-      GE (glLoadMatrixf (cogl_matrix_get_array (matrix)) );
+      GE (ctx, glLoadMatrixf (cogl_matrix_get_array (matrix)) );
       stack->flushed_identity = FALSE;
     }
 }
@@ -516,7 +518,7 @@ _cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack,
           break;
         }
 
-      GE (glMatrixMode (gl_mode));
+      GE (ctx, glMatrixMode (gl_mode));
       ctx->flushed_matrix_mode = mode;
     }
 
diff --git a/cogl/cogl-pipeline-fragend-arbfp.c b/cogl/cogl-pipeline-fragend-arbfp.c
index 3f4c4a3..ef07357 100644
--- a/cogl/cogl-pipeline-fragend-arbfp.c
+++ b/cogl/cogl-pipeline-fragend-arbfp.c
@@ -50,19 +50,6 @@
 #include <glib/gprintf.h>
 #include <string.h>
 
-/*
- * GL/GLES compatability defines for pipeline thingies:
- */
-
-#ifdef HAVE_COGL_GL
-#define glProgramString ctx->glProgramString
-#define glBindProgram ctx->glBindProgram
-#define glDeletePrograms ctx->glDeletePrograms
-#define glGenPrograms ctx->glGenPrograms
-#define glProgramLocalParameter4fv ctx->glProgramLocalParameter4fv
-#define glUseProgram ctx->glUseProgram
-#endif
-
 /* This might not be defined on GLES */
 #ifndef GL_TEXTURE_3D
 #define GL_TEXTURE_3D                           0x806F
@@ -135,7 +122,7 @@ arbfp_program_state_unref (ArbfpProgramState *state)
     {
       if (state->gl_program)
         {
-          GE (glDeletePrograms (1, &state->gl_program));
+          GE (ctx, glDeletePrograms (1, &state->gl_program));
           state->gl_program = 0;
         }
 
@@ -866,9 +853,9 @@ update_constants_cb (CoglPipeline *pipeline,
       _cogl_pipeline_get_layer_combine_constant (pipeline,
                                                  layer_index,
                                                  constant);
-      GE (glProgramLocalParameter4fv (GL_FRAGMENT_PROGRAM_ARB,
-                                      unit_state->constant_id,
-                                      constant));
+      GE (ctx, glProgramLocalParameter4fv (GL_FRAGMENT_PROGRAM_ARB,
+                                           unit_state->constant_id,
+                                           constant));
       unit_state->dirty_combine_constant = FALSE;
     }
   return TRUE;
@@ -901,22 +888,22 @@ _cogl_pipeline_fragend_arbfp_end (CoglPipeline *pipeline,
       if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_SHOW_SOURCE)))
         g_message ("pipeline program:\n%s", arbfp_program_state->source->str);
 
-      GE (glGenPrograms (1, &arbfp_program_state->gl_program));
+      GE (ctx, glGenPrograms (1, &arbfp_program_state->gl_program));
 
-      GE (glBindProgram (GL_FRAGMENT_PROGRAM_ARB,
+      GE (ctx, glBindProgram (GL_FRAGMENT_PROGRAM_ARB,
                          arbfp_program_state->gl_program));
 
-      while ((gl_error = glGetError ()) != GL_NO_ERROR)
+      while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
         ;
-      glProgramString (GL_FRAGMENT_PROGRAM_ARB,
-                       GL_PROGRAM_FORMAT_ASCII_ARB,
-                       arbfp_program_state->source->len,
-                       arbfp_program_state->source->str);
-      if (glGetError () != GL_NO_ERROR)
+      ctx->glProgramString (GL_FRAGMENT_PROGRAM_ARB,
+                            GL_PROGRAM_FORMAT_ASCII_ARB,
+                            arbfp_program_state->source->len,
+                            arbfp_program_state->source->str);
+      if (ctx->glGetError () != GL_NO_ERROR)
         {
           g_warning ("\n%s\n%s",
                      arbfp_program_state->source->str,
-                     glGetString (GL_PROGRAM_ERROR_STRING_ARB));
+                     ctx->glGetString (GL_PROGRAM_ERROR_STRING_ARB));
         }
 
       arbfp_program_state->source = NULL;
@@ -979,7 +966,7 @@ _cogl_pipeline_fragend_arbfp_end (CoglPipeline *pipeline,
   else
     gl_program = arbfp_program_state->gl_program;
 
-  GE (glBindProgram (GL_FRAGMENT_PROGRAM_ARB, gl_program));
+  GE (ctx, glBindProgram (GL_FRAGMENT_PROGRAM_ARB, gl_program));
   _cogl_use_fragment_program (0, COGL_PIPELINE_PROGRAM_TYPE_ARBFP);
 
   if (arbfp_program_state->user_program == COGL_INVALID_HANDLE)
diff --git a/cogl/cogl-pipeline-fragend-fixed.c b/cogl/cogl-pipeline-fragend-fixed.c
index ee80b5e..ebd2ec8 100644
--- a/cogl/cogl-pipeline-fragend-fixed.c
+++ b/cogl/cogl-pipeline-fragend-fixed.c
@@ -62,7 +62,7 @@ _cogl_disable_texture_unit (int unit_index)
   if (unit->enabled_gl_target)
     {
       _cogl_set_active_texture_unit (unit_index);
-      GE (glDisable (unit->enabled_gl_target));
+      GE (ctx, glDisable (unit->enabled_gl_target));
       unit->enabled_gl_target = 0;
     }
 }
@@ -77,8 +77,8 @@ get_max_texture_units (void)
   if (ctx->max_texture_units == -1)
     {
       ctx->max_texture_units = 1;
-      GE (glGetIntegerv (GL_MAX_TEXTURE_UNITS,
-                         &ctx->max_texture_units));
+      GE (ctx, glGetIntegerv (GL_MAX_TEXTURE_UNITS,
+                              &ctx->max_texture_units));
     }
 
   return ctx->max_texture_units;
@@ -162,12 +162,12 @@ _cogl_pipeline_fragend_fixed_add_layer (CoglPipeline *pipeline,
         {
           /* Disable the previous target if it's still enabled */
           if (unit->enabled_gl_target)
-            GE (glDisable (unit->enabled_gl_target));
+            GE (ctx, glDisable (unit->enabled_gl_target));
 
           /* Enable the new target */
           if (!G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_TEXTURING)))
             {
-              GE (glEnable (gl_target));
+              GE (ctx, glEnable (gl_target));
               unit->enabled_gl_target = gl_target;
             }
         }
@@ -183,7 +183,7 @@ _cogl_pipeline_fragend_fixed_add_layer (CoglPipeline *pipeline,
           unit->enabled_gl_target == 0)
         {
           _cogl_set_active_texture_unit (unit_index);
-          GE (glEnable (unit->gl_target));
+          GE (ctx, glEnable (unit->gl_target));
           unit->enabled_gl_target = unit->gl_target;
         }
     }
@@ -195,15 +195,15 @@ _cogl_pipeline_fragend_fixed_add_layer (CoglPipeline *pipeline,
                                             COGL_PIPELINE_LAYER_STATE_COMBINE);
       CoglPipelineLayerBigState *big_state = authority->big_state;
 
-      GE (glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE));
+      GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE));
 
       /* Set the combiner functions... */
-      GE (glTexEnvi (GL_TEXTURE_ENV,
-                     GL_COMBINE_RGB,
-                     big_state->texture_combine_rgb_func));
-      GE (glTexEnvi (GL_TEXTURE_ENV,
-                     GL_COMBINE_ALPHA,
-                     big_state->texture_combine_alpha_func));
+      GE (ctx, glTexEnvi (GL_TEXTURE_ENV,
+                          GL_COMBINE_RGB,
+                          big_state->texture_combine_rgb_func));
+      GE (ctx, glTexEnvi (GL_TEXTURE_ENV,
+                          GL_COMBINE_ALPHA,
+                          big_state->texture_combine_alpha_func));
 
       /*
        * Setup the function arguments...
@@ -213,46 +213,46 @@ _cogl_pipeline_fragend_fixed_add_layer (CoglPipeline *pipeline,
       n_rgb_func_args =
         _cogl_get_n_args_for_combine_func (big_state->texture_combine_rgb_func);
 
-      GE (glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB,
-                     big_state->texture_combine_rgb_src[0]));
-      GE (glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB,
-                     big_state->texture_combine_rgb_op[0]));
+      GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB,
+                          big_state->texture_combine_rgb_src[0]));
+      GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB,
+                          big_state->texture_combine_rgb_op[0]));
       if (n_rgb_func_args > 1)
         {
-          GE (glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB,
-                         big_state->texture_combine_rgb_src[1]));
-          GE (glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB,
-                         big_state->texture_combine_rgb_op[1]));
+          GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB,
+                              big_state->texture_combine_rgb_src[1]));
+          GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB,
+                              big_state->texture_combine_rgb_op[1]));
         }
       if (n_rgb_func_args > 2)
         {
-          GE (glTexEnvi (GL_TEXTURE_ENV, GL_SRC2_RGB,
-                         big_state->texture_combine_rgb_src[2]));
-          GE (glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_RGB,
-                         big_state->texture_combine_rgb_op[2]));
+          GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC2_RGB,
+                              big_state->texture_combine_rgb_src[2]));
+          GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_RGB,
+                              big_state->texture_combine_rgb_op[2]));
         }
 
       /* For the Alpha component */
       n_alpha_func_args =
         _cogl_get_n_args_for_combine_func (big_state->texture_combine_alpha_func);
 
-      GE (glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA,
-                     big_state->texture_combine_alpha_src[0]));
-      GE (glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA,
-                     big_state->texture_combine_alpha_op[0]));
+      GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA,
+                          big_state->texture_combine_alpha_src[0]));
+      GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA,
+                          big_state->texture_combine_alpha_op[0]));
       if (n_alpha_func_args > 1)
         {
-          GE (glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_ALPHA,
-                         big_state->texture_combine_alpha_src[1]));
-          GE (glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA,
-                         big_state->texture_combine_alpha_op[1]));
+          GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_ALPHA,
+                              big_state->texture_combine_alpha_src[1]));
+          GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA,
+                              big_state->texture_combine_alpha_op[1]));
         }
       if (n_alpha_func_args > 2)
         {
-          GE (glTexEnvi (GL_TEXTURE_ENV, GL_SRC2_ALPHA,
-                         big_state->texture_combine_alpha_src[2]));
-          GE (glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA,
-                         big_state->texture_combine_alpha_op[2]));
+          GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_SRC2_ALPHA,
+                              big_state->texture_combine_alpha_src[2]));
+          GE (ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA,
+                              big_state->texture_combine_alpha_op[2]));
         }
     }
 
@@ -263,8 +263,8 @@ _cogl_pipeline_fragend_fixed_add_layer (CoglPipeline *pipeline,
         (layer, COGL_PIPELINE_LAYER_STATE_COMBINE_CONSTANT);
       CoglPipelineLayerBigState *big_state = authority->big_state;
 
-      GE (glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,
-                      big_state->texture_combine_constant));
+      GE (ctx, glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,
+                           big_state->texture_combine_constant));
     }
 
   return TRUE;
@@ -315,9 +315,9 @@ _cogl_pipeline_fragend_fixed_end (CoglPipeline *pipeline,
           fogColor[2] = cogl_color_get_blue_float (&fog_state->color);
           fogColor[3] = cogl_color_get_alpha_float (&fog_state->color);
 
-          GE (glEnable (GL_FOG));
+          GE (ctx, glEnable (GL_FOG));
 
-          GE (glFogfv (GL_FOG_COLOR, fogColor));
+          GE (ctx, glFogfv (GL_FOG_COLOR, fogColor));
 
 #if HAVE_COGL_GLES
           switch (fog_state->mode)
@@ -336,15 +336,15 @@ _cogl_pipeline_fragend_fixed_end (CoglPipeline *pipeline,
           /* TODO: support other modes for GLES2 */
 
           /* NB: GLES doesn't have glFogi */
-          GE (glFogf (GL_FOG_MODE, gl_mode));
-          GE (glHint (GL_FOG_HINT, GL_NICEST));
+          GE (ctx, glFogf (GL_FOG_MODE, gl_mode));
+          GE (ctx, glHint (GL_FOG_HINT, GL_NICEST));
 
-          GE (glFogf (GL_FOG_DENSITY, fog_state->density));
-          GE (glFogf (GL_FOG_START, fog_state->z_near));
-          GE (glFogf (GL_FOG_END, fog_state->z_far));
+          GE (ctx, glFogf (GL_FOG_DENSITY, fog_state->density));
+          GE (ctx, glFogf (GL_FOG_START, fog_state->z_near));
+          GE (ctx, glFogf (GL_FOG_END, fog_state->z_far));
         }
       else
-        GE (glDisable (GL_FOG));
+        GE (ctx, glDisable (GL_FOG));
     }
 
   return TRUE;
diff --git a/cogl/cogl-pipeline-fragend-glsl.c b/cogl/cogl-pipeline-fragend-glsl.c
index 6f6fb3a..a0787c4 100644
--- a/cogl/cogl-pipeline-fragend-glsl.c
+++ b/cogl/cogl-pipeline-fragend-glsl.c
@@ -45,17 +45,6 @@
 #include "cogl-shader-private.h"
 #include "cogl-program-private.h"
 
-#ifndef HAVE_COGL_GLES2
-
-#define glCreateShader       ctx->glCreateShader
-#define glGetShaderiv        ctx->glGetShaderiv
-#define glGetShaderInfoLog   ctx->glGetShaderInfoLog
-#define glCompileShader      ctx->glCompileShader
-#define glShaderSource       ctx->glShaderSource
-#define glDeleteShader       ctx->glDeleteShader
-
-#endif /* HAVE_COGL_GLES2 */
-
 #include <glib.h>
 
 /*
@@ -124,7 +113,7 @@ glsl_shader_state_unref (GlslShaderState *state)
   if (state->ref_count == 0)
     {
       if (state->gl_shader)
-        GE( glDeleteShader (state->gl_shader) );
+        GE( ctx, glDeleteShader (state->gl_shader) );
 
       g_free (state->unit_state);
 
@@ -277,7 +266,7 @@ _cogl_pipeline_fragend_glsl_start (CoglPipeline *pipeline,
         return TRUE;
 
       /* We need to recreate the shader so destroy the existing one */
-      GE( glDeleteShader (priv->glsl_shader_state->gl_shader) );
+      GE( ctx, glDeleteShader (priv->glsl_shader_state->gl_shader) );
       priv->glsl_shader_state->gl_shader = 0;
     }
 
@@ -798,7 +787,7 @@ _cogl_pipeline_fragend_glsl_end (CoglPipeline *pipeline,
 
       g_string_append (glsl_shader_state->source, "}\n");
 
-      GE_RET( shader, glCreateShader (GL_FRAGMENT_SHADER) );
+      GE_RET( shader, ctx, glCreateShader (GL_FRAGMENT_SHADER) );
 
       lengths[0] = glsl_shader_state->header->len;
       source_strings[0] = glsl_shader_state->header->str;
@@ -817,17 +806,17 @@ _cogl_pipeline_fragend_glsl_end (CoglPipeline *pipeline,
                                                 2, /* count */
                                                 source_strings, lengths);
 
-      GE( glCompileShader (shader) );
-      GE( glGetShaderiv (shader, GL_COMPILE_STATUS, &compile_status) );
+      GE( ctx, glCompileShader (shader) );
+      GE( ctx, glGetShaderiv (shader, GL_COMPILE_STATUS, &compile_status) );
 
       if (!compile_status)
         {
           GLint len = 0;
           char *shader_log;
 
-          GE( glGetShaderiv (shader, GL_INFO_LOG_LENGTH, &len) );
+          GE( ctx, glGetShaderiv (shader, GL_INFO_LOG_LENGTH, &len) );
           shader_log = g_alloca (len);
-          GE( glGetShaderInfoLog (shader, len, &len, shader_log) );
+          GE( ctx, glGetShaderInfoLog (shader, len, &len, shader_log) );
           g_warning ("Shader compilation failed:\n%s", shader_log);
         }
 
diff --git a/cogl/cogl-pipeline-opengl.c b/cogl/cogl-pipeline-opengl.c
index 51ac2f6..836a801 100644
--- a/cogl/cogl-pipeline-opengl.c
+++ b/cogl/cogl-pipeline-opengl.c
@@ -49,20 +49,6 @@
  * GL/GLES compatability defines for pipeline thingies:
  */
 
-#ifdef HAVE_COGL_GL
-#define glActiveTexture ctx->glActiveTexture
-#define glClientActiveTexture ctx->glClientActiveTexture
-#define glBlendEquation ctx->glBlendEquation
-#define glBlendColor ctx->glBlendColor
-
-#define glProgramString ctx->glProgramString
-#define glBindProgram ctx->glBindProgram
-#define glDeletePrograms ctx->glDeletePrograms
-#define glGenPrograms ctx->glGenPrograms
-#define glProgramLocalParameter4fv ctx->glProgramLocalParameter4fv
-#define glUseProgram ctx->glUseProgram
-#endif
-
 /* These aren't defined in the GLES headers */
 #ifndef GL_POINT_SPRITE
 #define GL_POINT_SPRITE 0x8861
@@ -144,7 +130,7 @@ _cogl_set_active_texture_unit (int unit_index)
 
   if (ctx->active_texture_unit != unit_index)
     {
-      GE (glActiveTexture (GL_TEXTURE0 + unit_index));
+      GE (ctx, glActiveTexture (GL_TEXTURE0 + unit_index));
       ctx->active_texture_unit = unit_index;
     }
 }
@@ -196,7 +182,7 @@ _cogl_bind_gl_texture_transient (GLenum gl_target,
       !unit->is_foreign)
     return;
 
-  GE (glBindTexture (gl_target, gl_texture));
+  GE (ctx, glBindTexture (gl_target, gl_texture));
 
   unit->dirty_gl_texture = TRUE;
   unit->is_foreign = is_foreign;
@@ -222,7 +208,7 @@ _cogl_delete_gl_texture (GLuint gl_texture)
         }
     }
 
-  GE (glDeleteTextures (1, &gl_texture));
+  GE (ctx, glDeleteTextures (1, &gl_texture));
 }
 
 /* Whenever the underlying GL texture storage of a CoglTexture is
@@ -266,14 +252,14 @@ set_glsl_program (GLuint gl_program)
     {
       GLenum gl_error;
 
-      while ((gl_error = glGetError ()) != GL_NO_ERROR)
+      while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
         ;
-      glUseProgram (gl_program);
-      if (glGetError () == GL_NO_ERROR)
+      ctx->glUseProgram (gl_program);
+      if (ctx->glGetError () == GL_NO_ERROR)
         ctx->current_gl_program = gl_program;
       else
         {
-          GE( glUseProgram (0) );
+          GE( ctx, glUseProgram (0) );
           ctx->current_gl_program = 0;
         }
     }
@@ -302,7 +288,7 @@ _cogl_use_fragment_program (GLuint gl_program, CoglPipelineProgramType type)
 
         case COGL_PIPELINE_PROGRAM_TYPE_ARBFP:
 #ifdef HAVE_COGL_GL
-          GE( glDisable (GL_FRAGMENT_PROGRAM_ARB) );
+          GE( ctx, glDisable (GL_FRAGMENT_PROGRAM_ARB) );
 #endif
           break;
 
@@ -316,7 +302,7 @@ _cogl_use_fragment_program (GLuint gl_program, CoglPipelineProgramType type)
         {
         case COGL_PIPELINE_PROGRAM_TYPE_ARBFP:
 #ifdef HAVE_COGL_GL
-          GE( glEnable (GL_FRAGMENT_PROGRAM_ARB) );
+          GE( ctx, glEnable (GL_FRAGMENT_PROGRAM_ARB) );
 #endif
           break;
 
@@ -421,8 +407,8 @@ _cogl_get_max_texture_image_units (void)
   if (G_UNLIKELY (ctx->max_texture_image_units == -1))
     {
       ctx->max_texture_image_units = 1;
-      GE (glGetIntegerv (GL_MAX_TEXTURE_IMAGE_UNITS,
-                         &ctx->max_texture_image_units));
+      GE (ctx, glGetIntegerv (GL_MAX_TEXTURE_IMAGE_UNITS,
+                              &ctx->max_texture_image_units));
     }
 
   return ctx->max_texture_image_units;
@@ -449,14 +435,14 @@ flush_depth_state (CoglDepthState *depth_state)
 
   if (ctx->depth_test_function_cache != depth_state->test_function)
     {
-      GE (glDepthFunc (depth_state->test_function));
+      GE (ctx, glDepthFunc (depth_state->test_function));
       ctx->depth_test_function_cache = depth_state->test_function;
     }
 
   if (ctx->depth_writing_enabled_cache != depth_state->write_enabled)
     {
-      GE (glDepthMask (depth_state->write_enabled ?
-                       GL_TRUE : GL_FALSE));
+      GE (ctx, glDepthMask (depth_state->write_enabled ?
+                            GL_TRUE : GL_FALSE));
       ctx->depth_writing_enabled_cache = depth_state->write_enabled;
     }
 
@@ -465,11 +451,11 @@ flush_depth_state (CoglDepthState *depth_state)
       ctx->depth_range_far_cache != depth_state->range_far)
     {
 #ifdef COGL_HAS_GLES2
-      GE (glDepthRangef (depth_state->range_near,
-                         depth_state->range_far));
+      GE (ctx, glDepthRangef (depth_state->range_near,
+                              depth_state->range_far));
 #else
-      GE (glDepthRange (depth_state->range_near,
-                        depth_state->range_far));
+      GE (ctx, glDepthRange (depth_state->range_near,
+                             depth_state->range_far));
 #endif
       ctx->depth_range_near_cache = depth_state->range_near;
       ctx->depth_range_far_cache = depth_state->range_far;
@@ -496,10 +482,10 @@ _cogl_pipeline_flush_color_blend_alpha_depth_state (
         {
           CoglPipeline *authority =
             _cogl_pipeline_get_authority (pipeline, COGL_PIPELINE_STATE_COLOR);
-          GE (glColor4ub (cogl_color_get_red_byte (&authority->color),
-                          cogl_color_get_green_byte (&authority->color),
-                          cogl_color_get_blue_byte (&authority->color),
-                          cogl_color_get_alpha_byte (&authority->color)));
+          GE (ctx, glColor4ub (cogl_color_get_red_byte (&authority->color),
+                               cogl_color_get_green_byte (&authority->color),
+                               cogl_color_get_blue_byte (&authority->color),
+                               cogl_color_get_alpha_byte (&authority->color)));
         }
     }
 #endif
@@ -539,28 +525,28 @@ _cogl_pipeline_flush_color_blend_alpha_depth_state (
             cogl_color_get_alpha_float (&blend_state->blend_constant);
 
 
-          GE (glBlendColor (red, green, blue, alpha));
+          GE (ctx, glBlendColor (red, green, blue, alpha));
         }
 
       if (have_blend_equation_seperate &&
           blend_state->blend_equation_rgb != blend_state->blend_equation_alpha)
-        GE (ctx->glBlendEquationSeparate (blend_state->blend_equation_rgb,
+        GE (ctx, glBlendEquationSeparate (blend_state->blend_equation_rgb,
                                           blend_state->blend_equation_alpha));
       else
-        GE (glBlendEquation (blend_state->blend_equation_rgb));
+        GE (ctx, glBlendEquation (blend_state->blend_equation_rgb));
 
       if (have_blend_func_separate &&
           (blend_state->blend_src_factor_rgb != blend_state->blend_src_factor_alpha ||
            (blend_state->blend_src_factor_rgb !=
             blend_state->blend_src_factor_alpha)))
-        GE (ctx->glBlendFuncSeparate (blend_state->blend_src_factor_rgb,
+        GE (ctx, glBlendFuncSeparate (blend_state->blend_src_factor_rgb,
                                       blend_state->blend_dst_factor_rgb,
                                       blend_state->blend_src_factor_alpha,
                                       blend_state->blend_dst_factor_alpha));
       else
 #endif
-        GE (glBlendFunc (blend_state->blend_src_factor_rgb,
-                         blend_state->blend_dst_factor_rgb));
+        GE (ctx, glBlendFunc (blend_state->blend_src_factor_rgb,
+                              blend_state->blend_dst_factor_rgb));
     }
 
 #ifndef HAVE_COGL_GLES2
@@ -576,8 +562,8 @@ _cogl_pipeline_flush_color_blend_alpha_depth_state (
         &authority->big_state->alpha_state;
 
       /* NB: Currently the Cogl defines are compatible with the GL ones: */
-      GE (glAlphaFunc (alpha_state->alpha_func,
-                       alpha_state->alpha_func_reference));
+      GE (ctx, glAlphaFunc (alpha_state->alpha_func,
+                            alpha_state->alpha_func_reference));
     }
 
   /* Under GLES2 the lighting parameters are implemented as uniforms
@@ -589,16 +575,16 @@ _cogl_pipeline_flush_color_blend_alpha_depth_state (
       CoglPipelineLightingState *lighting_state =
         &authority->big_state->lighting_state;
 
-      GE (glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT,
-                        lighting_state->ambient));
-      GE (glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE,
-                        lighting_state->diffuse));
-      GE (glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,
-                        lighting_state->specular));
-      GE (glMaterialfv (GL_FRONT_AND_BACK, GL_EMISSION,
-                        lighting_state->emission));
-      GE (glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS,
-                        &lighting_state->shininess));
+      GE (ctx, glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT,
+                             lighting_state->ambient));
+      GE (ctx, glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE,
+                             lighting_state->diffuse));
+      GE (ctx, glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,
+                             lighting_state->specular));
+      GE (ctx, glMaterialfv (GL_FRONT_AND_BACK, GL_EMISSION,
+                             lighting_state->emission));
+      GE (ctx, glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS,
+                             &lighting_state->shininess));
     }
 
 #endif /* HAVE_COGL_GLES2 */
@@ -613,14 +599,14 @@ _cogl_pipeline_flush_color_blend_alpha_depth_state (
         {
           if (ctx->depth_test_enabled_cache != TRUE)
             {
-              GE (glEnable (GL_DEPTH_TEST));
+              GE (ctx, glEnable (GL_DEPTH_TEST));
               ctx->depth_test_enabled_cache = depth_state->test_enabled;
             }
           flush_depth_state (depth_state);
         }
       else if (ctx->depth_test_enabled_cache != FALSE)
         {
-          GE (glDisable (GL_DEPTH_TEST));
+          GE (ctx, glDisable (GL_DEPTH_TEST));
           ctx->depth_test_enabled_cache = depth_state->test_enabled;
         }
     }
@@ -628,9 +614,9 @@ _cogl_pipeline_flush_color_blend_alpha_depth_state (
   if (pipeline->real_blend_enable != ctx->gl_blend_enable_cache)
     {
       if (pipeline->real_blend_enable)
-        GE (glEnable (GL_BLEND));
+        GE (ctx, glEnable (GL_BLEND));
       else
-        GE (glDisable (GL_BLEND));
+        GE (ctx, glDisable (GL_BLEND));
       /* XXX: we shouldn't update any other blend state if blending
        * is disabled! */
       ctx->gl_blend_enable_cache = pipeline->real_blend_enable;
@@ -658,24 +644,24 @@ get_max_activateable_texture_units (void)
         /* Previously this code subtracted the value by one but there
            was no explanation for why it did this and it doesn't seem
            to make sense so it has been removed */
-        GE (glGetIntegerv (GL_MAX_TEXTURE_COORDS, values + n_values++));
+        GE (ctx, glGetIntegerv (GL_MAX_TEXTURE_COORDS, values + n_values++));
 
       /* GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS is defined for GLSL but
          not ARBfp */
       if (cogl_features_available (COGL_FEATURE_SHADERS_GLSL))
-        GE (glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
-                           values + n_values++));
+        GE (ctx, glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
+                                values + n_values++));
 #endif /* HAVE_COGL_GL */
 
 #ifdef HAVE_COGL_GLES2
 
-      GE (glGetIntegerv (GL_MAX_VERTEX_ATTRIBS, values + n_values));
+      GE (ctx, glGetIntegerv (GL_MAX_VERTEX_ATTRIBS, values + n_values));
       /* Two of the vertex attribs need to be used for the position
          and color */
       values[n_values++] -= 2;
 
-      GE (glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
-                         values + n_values++));
+      GE (ctx, glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
+                              values + n_values++));
 
 #else /* HAVE_COGL_GLES2 */
 
@@ -684,8 +670,8 @@ get_max_activateable_texture_units (void)
          available in GLES2. These are also tied to the number of
          texture coordinates that can be uploaded so it should be less
          than that available from the shader extensions */
-      GE (glGetIntegerv (GL_MAX_TEXTURE_UNITS,
-                         values + n_values++));
+      GE (ctx, glGetIntegerv (GL_MAX_TEXTURE_UNITS,
+                              values + n_values++));
 
 #endif /* HAVE_COGL_GLES2 */
 
@@ -784,7 +770,7 @@ flush_layers_common_gl_state_cb (CoglPipelineLayer *layer, void *user_data)
           if (unit_index == 1)
             unit->dirty_gl_texture = TRUE;
           else
-            GE (glBindTexture (gl_target, gl_texture));
+            GE (ctx, glBindTexture (gl_target, gl_texture));
           unit->gl_texture = gl_texture;
           unit->gl_target = gl_target;
         }
@@ -810,8 +796,8 @@ flush_layers_common_gl_state_cb (CoglPipelineLayer *layer, void *user_data)
 
       _cogl_set_active_texture_unit (unit_index);
 
-      GE (glTexEnvi (GL_POINT_SPRITE, GL_COORD_REPLACE,
-                     big_state->point_sprite_coords));
+      GE (ctx, glTexEnvi (GL_POINT_SPRITE, GL_COORD_REPLACE,
+                          big_state->point_sprite_coords));
     }
 #endif /* HAVE_COGL_GLES2 */
 
@@ -1321,7 +1307,8 @@ done:
 
       attribute = _cogl_pipeline_progend_glsl_get_color_attribute (pipeline);
       if (attribute != -1)
-        GE (glVertexAttrib4f (attribute,
+        GE (ctx,
+            glVertexAttrib4f (attribute,
                               cogl_color_get_red_float (&authority->color),
                               cogl_color_get_green_float (&authority->color),
                               cogl_color_get_blue_float (&authority->color),
@@ -1352,7 +1339,7 @@ done:
   if (cogl_pipeline_get_n_layers (pipeline) > 1 && unit1->dirty_gl_texture)
     {
       _cogl_set_active_texture_unit (1);
-      GE (glBindTexture (unit1->gl_target, unit1->gl_texture));
+      GE (ctx, glBindTexture (unit1->gl_target, unit1->gl_texture));
       unit1->dirty_gl_texture = FALSE;
     }
 
diff --git a/cogl/cogl-pipeline-progend-glsl.c b/cogl/cogl-pipeline-progend-glsl.c
index 7efbe25..51be8d1 100644
--- a/cogl/cogl-pipeline-progend-glsl.c
+++ b/cogl/cogl-pipeline-progend-glsl.c
@@ -42,21 +42,7 @@
 #include "cogl-pipeline-fragend-glsl-private.h"
 #include "cogl-pipeline-vertend-glsl-private.h"
 
-#ifndef HAVE_COGL_GLES2
-
-#define glCreateProgram      ctx->glCreateProgram
-#define glAttachShader       ctx->glAttachShader
-#define glUseProgram         ctx->glUseProgram
-#define glLinkProgram        ctx->glLinkProgram
-#define glDeleteProgram      ctx->glDeleteProgram
-#define glGetProgramInfoLog  ctx->glGetProgramInfoLog
-#define glGetProgramiv       ctx->glGetProgramiv
-#define glGetUniformLocation ctx->glGetUniformLocation
-#define glUniform1i          ctx->glUniform1i
-#define glUniform1f          ctx->glUniform1f
-#define glUniform4fv         ctx->glUniform4fv
-
-#else
+#ifdef HAVE_COGL_GLES2
 
 /* These are used to generalise updating some uniforms that are
    required when building for GLES2 */
@@ -178,12 +164,14 @@ _cogl_pipeline_progend_glsl_get_position_attribute (CoglPipeline *pipeline)
 {
   CoglPipelineProgendPrivate *priv = get_glsl_priv (pipeline);
 
+  _COGL_GET_CONTEXT (ctx, -1);
+
   g_return_val_if_fail (priv != NULL, -1);
   g_return_val_if_fail (priv->program != 0, -1);
 
   if (priv->position_attribute_location == ATTRIBUTE_LOCATION_UNKNOWN)
     GE_RET( priv->position_attribute_location,
-            glGetAttribLocation (priv->program, "cogl_position_in") );
+            ctx, glGetAttribLocation (priv->program, "cogl_position_in") );
 
   return priv->position_attribute_location;
 }
@@ -193,12 +181,14 @@ _cogl_pipeline_progend_glsl_get_color_attribute (CoglPipeline *pipeline)
 {
   CoglPipelineProgendPrivate *priv = get_glsl_priv (pipeline);
 
+  _COGL_GET_CONTEXT (ctx, -1);
+
   g_return_val_if_fail (priv != NULL, -1);
   g_return_val_if_fail (priv->program != 0, -1);
 
   if (priv->color_attribute_location == ATTRIBUTE_LOCATION_UNKNOWN)
     GE_RET( priv->color_attribute_location,
-            glGetAttribLocation (priv->program, "cogl_color_in") );
+            ctx, glGetAttribLocation (priv->program, "cogl_color_in") );
 
   return priv->color_attribute_location;
 }
@@ -208,12 +198,14 @@ _cogl_pipeline_progend_glsl_get_normal_attribute (CoglPipeline *pipeline)
 {
   CoglPipelineProgendPrivate *priv = get_glsl_priv (pipeline);
 
+  _COGL_GET_CONTEXT (ctx, -1);
+
   g_return_val_if_fail (priv != NULL, -1);
   g_return_val_if_fail (priv->program != 0, -1);
 
   if (priv->normal_attribute_location == ATTRIBUTE_LOCATION_UNKNOWN)
     GE_RET( priv->normal_attribute_location,
-            glGetAttribLocation (priv->program, "cogl_normal_in") );
+            ctx, glGetAttribLocation (priv->program, "cogl_normal_in") );
 
   return priv->normal_attribute_location;
 }
@@ -224,6 +216,8 @@ _cogl_pipeline_progend_glsl_get_tex_coord_attribute (CoglPipeline *pipeline,
 {
   CoglPipelineProgendPrivate *priv = get_glsl_priv (pipeline);
 
+  _COGL_GET_CONTEXT (ctx, -1);
+
   g_return_val_if_fail (priv != NULL, -1);
   g_return_val_if_fail (priv->program != 0, -1);
 
@@ -231,7 +225,8 @@ _cogl_pipeline_progend_glsl_get_tex_coord_attribute (CoglPipeline *pipeline,
     {
       if (priv->tex_coord0_attribute_location == ATTRIBUTE_LOCATION_UNKNOWN)
         GE_RET( priv->tex_coord0_attribute_location,
-                glGetAttribLocation (priv->program, "cogl_tex_coord0_in") );
+                ctx, glGetAttribLocation (priv->program,
+                                          "cogl_tex_coord0_in") );
 
       return priv->tex_coord0_attribute_location;
     }
@@ -256,7 +251,7 @@ _cogl_pipeline_progend_glsl_get_tex_coord_attribute (CoglPipeline *pipeline,
 
       if (locations[unit - 1] == ATTRIBUTE_LOCATION_UNKNOWN)
         GE_RET( locations[unit - 1],
-                glGetAttribLocation (priv->program, name) );
+                ctx, glGetAttribLocation (priv->program, name) );
 
       g_free (name);
 
@@ -311,7 +306,7 @@ destroy_glsl_priv (void *user_data)
 #endif
 
       if (priv->program)
-        GE( glDeleteProgram (priv->program) );
+        GE( ctx, glDeleteProgram (priv->program) );
 
       g_free (priv->unit_state);
 
@@ -344,9 +339,9 @@ link_program (GLint gl_program)
 
   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
 
-  GE( glLinkProgram (gl_program) );
+  GE( ctx, glLinkProgram (gl_program) );
 
-  GE( glGetProgramiv (gl_program, GL_LINK_STATUS, &link_status) );
+  GE( ctx, glGetProgramiv (gl_program, GL_LINK_STATUS, &link_status) );
 
   if (!link_status)
     {
@@ -354,12 +349,12 @@ link_program (GLint gl_program)
       GLsizei out_log_length;
       char *log;
 
-      GE( glGetProgramiv (gl_program, GL_INFO_LOG_LENGTH, &log_length) );
+      GE( ctx, glGetProgramiv (gl_program, GL_INFO_LOG_LENGTH, &log_length) );
 
       log = g_malloc (log_length);
 
-      GE( glGetProgramInfoLog (gl_program, log_length,
-                               &out_log_length, log) );
+      GE( ctx, glGetProgramInfoLog (gl_program, log_length,
+                                    &out_log_length, log) );
 
       g_warning ("Failed to link GLSL program:\n%.*s\n",
                  log_length, log);
@@ -395,23 +390,23 @@ get_uniform_cb (CoglPipeline *pipeline,
                           "_cogl_sampler_%i", state->unit);
 
   GE_RET( uniform_location,
-          glGetUniformLocation (state->gl_program,
-                                ctx->codegen_source_buffer->str) );
+          ctx, glGetUniformLocation (state->gl_program,
+                                     ctx->codegen_source_buffer->str) );
 
   /* We can set the uniform immediately because the samplers are the
      unit index not the texture object number so it will never
      change. Unfortunately GL won't let us use a constant instead of a
      uniform */
   if (uniform_location != -1)
-    GE( glUniform1i (uniform_location, state->unit) );
+    GE( ctx, glUniform1i (uniform_location, state->unit) );
 
   g_string_set_size (ctx->codegen_source_buffer, 0);
   g_string_append_printf (ctx->codegen_source_buffer,
                           "_cogl_layer_constant_%i", state->unit);
 
   GE_RET( uniform_location,
-          glGetUniformLocation (state->gl_program,
-                                ctx->codegen_source_buffer->str) );
+          ctx, glGetUniformLocation (state->gl_program,
+                                     ctx->codegen_source_buffer->str) );
 
   unit_state->combine_constant_uniform = uniform_location;
 
@@ -422,8 +417,8 @@ get_uniform_cb (CoglPipeline *pipeline,
                           "cogl_texture_matrix[%i]", state->unit);
 
   GE_RET( uniform_location,
-          glGetUniformLocation (state->gl_program,
-                                ctx->codegen_source_buffer->str) );
+          ctx, glGetUniformLocation (state->gl_program,
+                                     ctx->codegen_source_buffer->str) );
 
   unit_state->texture_matrix_uniform = uniform_location;
 
@@ -452,8 +447,8 @@ update_constants_cb (CoglPipeline *pipeline,
       _cogl_pipeline_get_layer_combine_constant (pipeline,
                                                  layer_index,
                                                  constant);
-      GE (glUniform4fv (unit_state->combine_constant_uniform,
-                        1, constant));
+      GE (ctx, glUniform4fv (unit_state->combine_constant_uniform,
+                             1, constant));
       unit_state->dirty_combine_constant = FALSE;
     }
 
@@ -467,8 +462,8 @@ update_constants_cb (CoglPipeline *pipeline,
 
       matrix = _cogl_pipeline_get_layer_matrix (pipeline, layer_index);
       array = cogl_matrix_get_array (matrix);
-      GE (glUniformMatrix4fv (unit_state->texture_matrix_uniform,
-                              1, FALSE, array));
+      GE (ctx, glUniformMatrix4fv (unit_state->texture_matrix_uniform,
+                                   1, FALSE, array));
       unit_state->dirty_texture_matrix = FALSE;
     }
 
@@ -575,7 +570,7 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
       (user_program->age != priv->user_program_age ||
        n_tex_coord_attribs > priv->n_tex_coord_attribs))
     {
-      GE( glDeleteProgram (priv->program) );
+      GE( ctx, glDeleteProgram (priv->program) );
       priv->program = 0;
     }
 
@@ -584,7 +579,7 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
       GLuint backend_shader;
       GSList *l;
 
-      GE_RET( priv->program, glCreateProgram () );
+      GE_RET( priv->program, ctx, glCreateProgram () );
 
       /* Attach all of the shader from the user program */
       if (user_program)
@@ -613,8 +608,8 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
 
               g_assert (shader->language == COGL_SHADER_LANGUAGE_GLSL);
 
-              GE( glAttachShader (priv->program,
-                                  shader->gl_handle) );
+              GE( ctx, glAttachShader (priv->program,
+                                       shader->gl_handle) );
             }
 
           priv->user_program_age = user_program->age;
@@ -623,10 +618,10 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
       /* Attach any shaders from the GLSL backends */
       if (pipeline->fragend == COGL_PIPELINE_FRAGEND_GLSL &&
           (backend_shader = _cogl_pipeline_fragend_glsl_get_shader (pipeline)))
-        GE( glAttachShader (priv->program, backend_shader) );
+        GE( ctx, glAttachShader (priv->program, backend_shader) );
       if (pipeline->vertend == COGL_PIPELINE_VERTEND_GLSL &&
           (backend_shader = _cogl_pipeline_vertend_glsl_get_shader (pipeline)))
-        GE( glAttachShader (priv->program, backend_shader) );
+        GE( ctx, glAttachShader (priv->program, backend_shader) );
 
       link_program (priv->program);
 
@@ -669,20 +664,20 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
 
       for (i = 0; i < G_N_ELEMENTS (builtin_uniforms); i++)
         GE_RET( priv->builtin_uniform_locations[i],
-                glGetUniformLocation (gl_program,
-                                      builtin_uniforms[i].uniform_name) );
+                ctx, glGetUniformLocation (gl_program,
+                                           builtin_uniforms[i].uniform_name) );
 
       GE_RET( priv->modelview_uniform,
-              glGetUniformLocation (gl_program,
-                                    "cogl_modelview_matrix") );
+              ctx, glGetUniformLocation (gl_program,
+                                         "cogl_modelview_matrix") );
 
       GE_RET( priv->projection_uniform,
-              glGetUniformLocation (gl_program,
-                                    "cogl_projection_matrix") );
+              ctx, glGetUniformLocation (gl_program,
+                                         "cogl_projection_matrix") );
 
       GE_RET( priv->mvp_uniform,
-              glGetUniformLocation (gl_program,
-                                    "cogl_modelview_projection_matrix") );
+              ctx, glGetUniformLocation (gl_program,
+                                         "cogl_modelview_projection_matrix") );
     }
   if (program_changed ||
       priv->last_used_for_pipeline != pipeline)
@@ -775,8 +770,10 @@ flush_modelview_cb (gboolean is_identity,
 {
   CoglPipelineProgendPrivate *priv = user_data;
 
-  GE( glUniformMatrix4fv (priv->modelview_uniform, 1, FALSE,
-                          cogl_matrix_get_array (matrix)) );
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
+  GE( ctx, glUniformMatrix4fv (priv->modelview_uniform, 1, FALSE,
+                               cogl_matrix_get_array (matrix)) );
 }
 
 static void
@@ -786,8 +783,10 @@ flush_projection_cb (gboolean is_identity,
 {
   CoglPipelineProgendPrivate *priv = user_data;
 
-  GE( glUniformMatrix4fv (priv->projection_uniform, 1, FALSE,
-                          cogl_matrix_get_array (matrix)) );
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
+  GE( ctx, glUniformMatrix4fv (priv->projection_uniform, 1, FALSE,
+                               cogl_matrix_get_array (matrix)) );
 }
 
 typedef struct
@@ -804,19 +803,23 @@ flush_combined_step_two_cb (gboolean is_identity,
   FlushCombinedData *data = user_data;
   CoglMatrix mvp_matrix;
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   /* If the modelview is the identity then we can bypass the matrix
      multiplication */
   if (is_identity)
-    GE( glUniformMatrix4fv (data->priv->mvp_uniform, 1, FALSE,
-                            cogl_matrix_get_array (data->projection_matrix)) );
+    {
+      const float *array = cogl_matrix_get_array (data->projection_matrix);
+      GE( ctx, glUniformMatrix4fv (data->priv->mvp_uniform, 1, FALSE, array ) );
+    }
   else
     {
       cogl_matrix_multiply (&mvp_matrix,
                             data->projection_matrix,
                             matrix);
 
-      GE( glUniformMatrix4fv (data->priv->mvp_uniform, 1, FALSE,
-                              cogl_matrix_get_array (&mvp_matrix)) );
+      GE( ctx, glUniformMatrix4fv (data->priv->mvp_uniform, 1, FALSE,
+                                   cogl_matrix_get_array (&mvp_matrix)) );
     }
 }
 
@@ -927,8 +930,10 @@ update_float_uniform (CoglPipeline *pipeline,
   float (* float_getter_func) (CoglPipeline *) = getter_func;
   float value;
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   value = float_getter_func (pipeline);
-  GE( glUniform1f (uniform_location, value) );
+  GE( ctx, glUniform1f (uniform_location, value) );
 }
 
 #endif
diff --git a/cogl/cogl-pipeline-vertend-fixed.c b/cogl/cogl-pipeline-vertend-fixed.c
index dc2008a..d6baf98 100644
--- a/cogl/cogl-pipeline-vertend-fixed.c
+++ b/cogl/cogl-pipeline-vertend-fixed.c
@@ -104,7 +104,7 @@ _cogl_pipeline_vertend_fixed_end (CoglPipeline *pipeline,
 
       if (ctx->point_size_cache != authority->big_state->point_size)
         {
-          GE( glPointSize (authority->big_state->point_size) );
+          GE( ctx, glPointSize (authority->big_state->point_size) );
           ctx->point_size_cache = authority->big_state->point_size;
         }
     }
diff --git a/cogl/cogl-pipeline-vertend-glsl.c b/cogl/cogl-pipeline-vertend-glsl.c
index 44a747b..ac98c87 100644
--- a/cogl/cogl-pipeline-vertend-glsl.c
+++ b/cogl/cogl-pipeline-vertend-glsl.c
@@ -41,17 +41,6 @@
 #include "cogl-program-private.h"
 #include "cogl-pipeline-vertend-glsl-private.h"
 
-#ifndef HAVE_COGL_GLES2
-
-#define glCreateShader       ctx->glCreateShader
-#define glGetShaderiv        ctx->glGetShaderiv
-#define glGetShaderInfoLog   ctx->glGetShaderInfoLog
-#define glCompileShader      ctx->glCompileShader
-#define glShaderSource       ctx->glShaderSource
-#define glDeleteShader       ctx->glDeleteShader
-
-#endif /* HAVE_COGL_GLES2 */
-
 const CoglPipelineVertend _cogl_pipeline_glsl_vertend;
 
 typedef struct
@@ -86,7 +75,7 @@ destroy_glsl_priv (void *user_data)
   if (--priv->ref_count == 0)
     {
       if (priv->gl_shader)
-        GE( glDeleteShader (priv->gl_shader) );
+        GE( ctx, glDeleteShader (priv->gl_shader) );
 
       g_slice_free (CoglPipelineVertendPrivate, priv);
     }
@@ -185,7 +174,7 @@ _cogl_pipeline_vertend_glsl_start (CoglPipeline *pipeline,
         return TRUE;
 
       /* We need to recreate the shader so destroy the existing one */
-      GE( glDeleteShader (priv->gl_shader) );
+      GE( ctx, glDeleteShader (priv->gl_shader) );
       priv->gl_shader = 0;
     }
 
@@ -234,7 +223,7 @@ _cogl_pipeline_vertend_glsl_start (CoglPipeline *pipeline,
 
       if (ctx->point_size_cache != authority->big_state->point_size)
         {
-          GE( glPointSize (authority->big_state->point_size) );
+          GE( ctx, glPointSize (authority->big_state->point_size) );
           ctx->point_size_cache = authority->big_state->point_size;
         }
     }
@@ -332,7 +321,7 @@ _cogl_pipeline_vertend_glsl_end (CoglPipeline *pipeline,
                        "  cogl_color_out = cogl_color_in;\n"
                        "}\n");
 
-      GE_RET( shader, glCreateShader (GL_VERTEX_SHADER) );
+      GE_RET( shader, ctx, glCreateShader (GL_VERTEX_SHADER) );
 
       lengths[0] = priv->header->len;
       source_strings[0] = priv->header->str;
@@ -346,17 +335,17 @@ _cogl_pipeline_vertend_glsl_end (CoglPipeline *pipeline,
                                                 2, /* count */
                                                 source_strings, lengths);
 
-      GE( glCompileShader (shader) );
-      GE( glGetShaderiv (shader, GL_COMPILE_STATUS, &compile_status) );
+      GE( ctx, glCompileShader (shader) );
+      GE( ctx, glGetShaderiv (shader, GL_COMPILE_STATUS, &compile_status) );
 
       if (!compile_status)
         {
           GLint len = 0;
           char *shader_log;
 
-          GE( glGetShaderiv (shader, GL_INFO_LOG_LENGTH, &len) );
+          GE( ctx, glGetShaderiv (shader, GL_INFO_LOG_LENGTH, &len) );
           shader_log = g_alloca (len);
-          GE( glGetShaderInfoLog (shader, len, &len, shader_log) );
+          GE( ctx, glGetShaderInfoLog (shader, len, &len, shader_log) );
           g_warning ("Shader compilation failed:\n%s", shader_log);
         }
 
diff --git a/cogl/cogl-pixel-buffer.c b/cogl/cogl-pixel-buffer.c
index ea92553..e8a1b06 100644
--- a/cogl/cogl-pixel-buffer.c
+++ b/cogl/cogl-pixel-buffer.c
@@ -52,15 +52,6 @@
 
 #if defined (HAVE_COGL_GL)
 
-#define glGenBuffers ctx->drv.pf_glGenBuffers
-#define glBindBuffer ctx->drv.pf_glBindBuffer
-#define glBufferData ctx->drv.pf_glBufferData
-#define glBufferSubData ctx->drv.pf_glBufferSubData
-#define glGetBufferSubData ctx->drv.pf_glGetBufferSubData
-#define glDeleteBuffers ctx->drv.pf_glDeleteBuffers
-#define glMapBuffer ctx->drv.pf_glMapBuffer
-#define glUnmapBuffer ctx->drv.pf_glUnmapBuffer
-
 #ifndef GL_PIXEL_UNPACK_BUFFER
 #define GL_PIXEL_UNPACK_BUFFER GL_PIXEL_UNPACK_BUFFER_ARB
 #endif
diff --git a/cogl/cogl-primitives.c b/cogl/cogl-primitives.c
index fd83813..69cb71e 100644
--- a/cogl/cogl-primitives.c
+++ b/cogl/cogl-primitives.c
@@ -42,11 +42,6 @@
 
 #define _COGL_MAX_BEZ_RECURSE_DEPTH 16
 
-#ifdef HAVE_COGL_GL
-#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
-#endif
-
-
 typedef struct _TextureSlicedQuadState
 {
   CoglPipeline *pipeline;
diff --git a/cogl/cogl-program.c b/cogl/cogl-program.c
index 24a938d..8f00ead 100644
--- a/cogl/cogl-program.c
+++ b/cogl/cogl-program.c
@@ -48,32 +48,6 @@ COGL_OBJECT_DEFINE_DEPRECATED_REF_COUNTING (program);
    an array and then flushed whenever the material backend requests
    it. */
 
-#ifndef HAVE_COGL_GLES2
-
-#define glGetUniformLocation       ctx->glGetUniformLocation
-#define glUniform1f                ctx->glUniform1f
-#define glUniform2f                ctx->glUniform2f
-#define glUniform3f                ctx->glUniform3f
-#define glUniform4f                ctx->glUniform4f
-#define glUniform1fv               ctx->glUniform1fv
-#define glUniform2fv               ctx->glUniform2fv
-#define glUniform3fv               ctx->glUniform3fv
-#define glUniform4fv               ctx->glUniform4fv
-#define glUniform1i                ctx->glUniform1i
-#define glUniform2i                ctx->glUniform2i
-#define glUniform3i                ctx->glUniform3i
-#define glUniform4i                ctx->glUniform4i
-#define glUniform1iv               ctx->glUniform1iv
-#define glUniform2iv               ctx->glUniform2iv
-#define glUniform3iv               ctx->glUniform3iv
-#define glUniform4iv               ctx->glUniform4iv
-#define glUniformMatrix2fv         ctx->glUniformMatrix2fv
-#define glUniformMatrix3fv         ctx->glUniformMatrix3fv
-#define glUniformMatrix4fv         ctx->glUniformMatrix4fv
-#define glProgramLocalParameter4fv ctx->glProgramLocalParameter4fv
-
-#endif /* HAVE_COGL_GLES2 */
-
 static void
 _cogl_program_free (CoglProgram *program)
 {
@@ -448,10 +422,10 @@ _cogl_program_flush_uniform_glsl (GLint location,
 
         switch (value->size)
           {
-          case 1: glUniform1iv (location, value->count, ptr); break;
-          case 2: glUniform2iv (location, value->count, ptr); break;
-          case 3: glUniform3iv (location, value->count, ptr); break;
-          case 4: glUniform4iv (location, value->count, ptr); break;
+          case 1: ctx->glUniform1iv (location, value->count, ptr); break;
+          case 2: ctx->glUniform2iv (location, value->count, ptr); break;
+          case 3: ctx->glUniform3iv (location, value->count, ptr); break;
+          case 4: ctx->glUniform4iv (location, value->count, ptr); break;
           }
       }
       break;
@@ -467,10 +441,10 @@ _cogl_program_flush_uniform_glsl (GLint location,
 
         switch (value->size)
           {
-          case 1: glUniform1fv (location, value->count, ptr); break;
-          case 2: glUniform2fv (location, value->count, ptr); break;
-          case 3: glUniform3fv (location, value->count, ptr); break;
-          case 4: glUniform4fv (location, value->count, ptr); break;
+          case 1: ctx->glUniform1fv (location, value->count, ptr); break;
+          case 2: ctx->glUniform2fv (location, value->count, ptr); break;
+          case 3: ctx->glUniform3fv (location, value->count, ptr); break;
+          case 4: ctx->glUniform4fv (location, value->count, ptr); break;
           }
       }
       break;
@@ -487,13 +461,16 @@ _cogl_program_flush_uniform_glsl (GLint location,
         switch (value->size)
           {
           case 2:
-            glUniformMatrix2fv (location, value->count, value->transpose, ptr);
+            ctx->glUniformMatrix2fv (location, value->count,
+                                     value->transpose, ptr);
             break;
           case 3:
-            glUniformMatrix3fv (location, value->count, value->transpose, ptr);
+            ctx->glUniformMatrix3fv (location, value->count,
+                                     value->transpose, ptr);
             break;
           case 4:
-            glUniformMatrix4fv (location, value->count, value->transpose, ptr);
+            ctx->glUniformMatrix4fv (location, value->count,
+                                     value->transpose, ptr);
             break;
           }
       }
@@ -517,8 +494,8 @@ _cogl_program_flush_uniform_arbfp (GLint location,
       g_return_if_fail (value->size == 4);
       g_return_if_fail (value->count == 1);
 
-      GE( glProgramLocalParameter4fv (GL_FRAGMENT_PROGRAM_ARB, location,
-                                      value->v.float_value) );
+      GE( ctx, glProgramLocalParameter4fv (GL_FRAGMENT_PROGRAM_ARB, location,
+                                           value->v.float_value) );
     }
 }
 
@@ -552,7 +529,7 @@ _cogl_program_flush_uniforms (CoglProgram *program,
               if (_cogl_program_get_language (program) ==
                   COGL_SHADER_LANGUAGE_GLSL)
                 uniform->location =
-                  glGetUniformLocation (gl_program, uniform->name);
+                  ctx->glGetUniformLocation (gl_program, uniform->name);
               else
                 uniform->location =
                   get_local_param_index (uniform->name);
diff --git a/cogl/cogl-shader.c b/cogl/cogl-shader.c
index 7b474bf..996676b 100644
--- a/cogl/cogl-shader.c
+++ b/cogl/cogl-shader.c
@@ -36,22 +36,6 @@
 
 #include <string.h>
 
-#ifdef HAVE_COGL_GL
-#define glCreateShader             ctx->glCreateShader
-#define glGetShaderiv              ctx->glGetShaderiv
-#define glGetShaderInfoLog         ctx->glGetShaderInfoLog
-#define glCompileShader            ctx->glCompileShader
-#define glShaderSource             ctx->glShaderSource
-#define glDeleteShader             ctx->glDeleteShader
-#define glProgramString            ctx->glProgramString
-#define glBindProgram              ctx->glBindProgram
-#define glDeletePrograms           ctx->glDeletePrograms
-#define glGenPrograms              ctx->glGenPrograms
-#define GET_CONTEXT         _COGL_GET_CONTEXT
-#else
-#define GET_CONTEXT(CTXVAR,RETVAL) G_STMT_START { } G_STMT_END
-#endif
-
 static void _cogl_shader_free (CoglShader *shader);
 
 COGL_HANDLE_DEFINE (Shader, shader);
@@ -70,12 +54,12 @@ _cogl_shader_free (CoglShader *shader)
   if (shader->language == COGL_SHADER_LANGUAGE_ARBFP)
     {
       if (shader->gl_handle)
-        GE (glDeletePrograms (1, &shader->gl_handle));
+        GE (ctx, glDeletePrograms (1, &shader->gl_handle));
     }
   else
 #endif
     if (shader->gl_handle)
-      GE (glDeleteShader (shader->gl_handle));
+      GE (ctx, glDeleteShader (shader->gl_handle));
 
 #endif /* HAVE_COGL_GLES */
 
@@ -87,7 +71,7 @@ cogl_create_shader (CoglShaderType type)
 {
   CoglShader *shader;
 
-  GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
+  _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
 
   switch (type)
     {
@@ -122,13 +106,13 @@ delete_shader (CoglShader *shader)
   if (shader->language == COGL_SHADER_LANGUAGE_ARBFP)
     {
       if (shader->gl_handle)
-        GE (glDeletePrograms (1, &shader->gl_handle));
+        GE (ctx, glDeletePrograms (1, &shader->gl_handle));
     }
   else
 #endif
     {
       if (shader->gl_handle)
-        GE (glDeleteShader (shader->gl_handle));
+        GE (ctx, glDeleteShader (shader->gl_handle));
     }
 
   shader->gl_handle = 0;
@@ -211,7 +195,7 @@ _cogl_shader_set_source_with_boilerplate (GLuint shader_gl_handle,
   char *tex_coord_declarations = NULL;
 #endif
 
-  GET_CONTEXT (ctx, NO_RETVAL);
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
 
 #ifdef HAVE_COGL_GLES2
   if (cogl_features_available (COGL_FEATURE_TEXTURE_3D))
@@ -295,8 +279,8 @@ _cogl_shader_set_source_with_boilerplate (GLuint shader_gl_handle,
       g_string_free (buf, TRUE);
     }
 
-  GE( glShaderSource (shader_gl_handle, count,
-                      (const char **) strings, lengths) );
+  GE( ctx, glShaderSource (shader_gl_handle, count,
+                           (const char **) strings, lengths) );
 
 #ifdef HAVE_COGL_GLES2
   g_free (tex_coord_declarations);
@@ -325,30 +309,30 @@ _cogl_shader_compile_real (CoglHandle handle,
       if (shader->gl_handle)
         return;
 
-      GE (glGenPrograms (1, &shader->gl_handle));
+      GE (ctx, glGenPrograms (1, &shader->gl_handle));
 
-      GE (glBindProgram (GL_FRAGMENT_PROGRAM_ARB, shader->gl_handle));
+      GE (ctx, glBindProgram (GL_FRAGMENT_PROGRAM_ARB, shader->gl_handle));
 
       if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_SHOW_SOURCE)))
         g_message ("user ARBfp program:\n%s", shader->source);
 
 #ifdef COGL_GL_DEBUG
-      while ((gl_error = glGetError ()) != GL_NO_ERROR)
+      while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
         ;
 #endif
-      glProgramString (GL_FRAGMENT_PROGRAM_ARB,
-                       GL_PROGRAM_FORMAT_ASCII_ARB,
-                       strlen (shader->source),
-                       shader->source);
+      ctx->glProgramString (GL_FRAGMENT_PROGRAM_ARB,
+                            GL_PROGRAM_FORMAT_ASCII_ARB,
+                            strlen (shader->source),
+                            shader->source);
 #ifdef COGL_GL_DEBUG
-      gl_error = glGetError ();
+      gl_error = ctx->glGetError ();
       if (gl_error != GL_NO_ERROR)
         {
           g_warning ("%s: GL error (%d): Failed to compile ARBfp:\n%s\n%s",
                      G_STRLOC,
                      gl_error,
                      shader->source,
-                     glGetString (GL_PROGRAM_ERROR_STRING_ARB));
+                     ctx->glGetString (GL_PROGRAM_ERROR_STRING_ARB));
         }
 #endif
     }
@@ -380,7 +364,7 @@ _cogl_shader_compile_real (CoglHandle handle,
           break;
         }
 
-      shader->gl_handle = glCreateShader (gl_type);
+      shader->gl_handle = ctx->glCreateShader (gl_type);
 
       _cogl_shader_set_source_with_boilerplate (shader->gl_handle,
                                                 gl_type,
@@ -389,7 +373,7 @@ _cogl_shader_compile_real (CoglHandle handle,
                                                 (const char **) &shader->source,
                                                 NULL);
 
-      GE (glCompileShader (shader->gl_handle));
+      GE (ctx, glCompileShader (shader->gl_handle));
 
 #ifdef HAVE_COGL_GLES2
       shader->n_tex_coord_attribs = n_tex_coord_attribs;
@@ -420,7 +404,7 @@ cogl_shader_get_info_log (CoglHandle handle)
 
   CoglShader *shader;
 
-  GET_CONTEXT (ctx, NULL);
+  _COGL_GET_CONTEXT (ctx, NULL);
 
   if (!cogl_is_shader (handle))
     return NULL;
@@ -455,7 +439,7 @@ cogl_shader_get_info_log (CoglHandle handle)
       if (!shader->gl_handle)
         _cogl_shader_compile_real (handle, 4);
 
-      glGetShaderInfoLog (shader->gl_handle, 511, &len, buffer);
+      ctx->glGetShaderInfoLog (shader->gl_handle, 511, &len, buffer);
       buffer[len] = '\0';
       return g_strdup (buffer);
     }
@@ -468,7 +452,7 @@ cogl_shader_get_type (CoglHandle  handle)
 {
   CoglShader *shader;
 
-  GET_CONTEXT (ctx, COGL_SHADER_TYPE_VERTEX);
+  _COGL_GET_CONTEXT (ctx, COGL_SHADER_TYPE_VERTEX);
 
   if (!cogl_is_shader (handle))
     {
@@ -492,7 +476,7 @@ cogl_shader_is_compiled (CoglHandle handle)
   GLint status;
   CoglShader *shader;
 
-  GET_CONTEXT (ctx, FALSE);
+  _COGL_GET_CONTEXT (ctx, FALSE);
 
   if (!cogl_is_shader (handle))
     return FALSE;
@@ -523,7 +507,7 @@ cogl_shader_is_compiled (CoglHandle handle)
       if (!shader->gl_handle)
         _cogl_shader_compile_real (handle, 4);
 
-      GE (glGetShaderiv (shader->gl_handle, GL_COMPILE_STATUS, &status));
+      GE (ctx, glGetShaderiv (shader->gl_handle, GL_COMPILE_STATUS, &status));
       if (status == GL_TRUE)
         return TRUE;
       else
diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c
index 86ccae1..267ed9a 100644
--- a/cogl/cogl-texture-2d.c
+++ b/cogl/cogl-texture-2d.c
@@ -136,6 +136,8 @@ _cogl_texture_2d_set_wrap_mode_parameters (CoglTexture *tex,
 {
   CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   /* Only set the wrap mode if it's different from the current value
      to avoid too many GL calls. Texture 2D doesn't make use of the r
      coordinate so we can ignore its wrap mode */
@@ -145,8 +147,12 @@ _cogl_texture_2d_set_wrap_mode_parameters (CoglTexture *tex,
       _cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
                                        tex_2d->gl_texture,
                                        tex_2d->is_foreign);
-      GE( glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode_s) );
-      GE( glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_mode_t) );
+      GE( ctx, glTexParameteri (GL_TEXTURE_2D,
+                                GL_TEXTURE_WRAP_S,
+                                wrap_mode_s) );
+      GE( ctx, glTexParameteri (GL_TEXTURE_2D,
+                                GL_TEXTURE_WRAP_T,
+                                wrap_mode_t) );
 
       tex_2d->wrap_mode_s = wrap_mode_s;
       tex_2d->wrap_mode_t = wrap_mode_t;
@@ -262,8 +268,8 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,
   _cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
                                    tex_2d->gl_texture,
                                    tex_2d->is_foreign);
-  GE( glTexImage2D (GL_TEXTURE_2D, 0, gl_intformat,
-                    width, height, 0, gl_format, gl_type, NULL) );
+  GE( ctx, glTexImage2D (GL_TEXTURE_2D, 0, gl_intformat,
+                         width, height, 0, gl_format, gl_type, NULL) );
 
   return _cogl_texture_2d_handle_new (tex_2d);
 }
@@ -405,15 +411,15 @@ cogl_texture_2d_new_from_foreign (CoglContext *ctx,
     return COGL_INVALID_HANDLE;
 
   /* Make sure it is a valid GL texture object */
-  if (!glIsTexture (gl_handle))
+  if (!ctx->glIsTexture (gl_handle))
     return COGL_INVALID_HANDLE;
 
   /* Make sure binding succeeds */
-  while ((gl_error = glGetError ()) != GL_NO_ERROR)
+  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
     ;
 
   _cogl_bind_gl_texture_transient (GL_TEXTURE_2D, gl_handle, TRUE);
-  if (glGetError () != GL_NO_ERROR)
+  if (ctx->glGetError () != GL_NO_ERROR)
     return COGL_INVALID_HANDLE;
 
   /* Obtain texture parameters
@@ -421,16 +427,16 @@ cogl_texture_2d_new_from_foreign (CoglContext *ctx,
 
 #if HAVE_COGL_GL
 
-  GE( glGetTexLevelParameteriv (GL_TEXTURE_2D, 0,
-                                GL_TEXTURE_COMPRESSED,
-                                &gl_compressed) );
+  GE( ctx, glGetTexLevelParameteriv (GL_TEXTURE_2D, 0,
+                                     GL_TEXTURE_COMPRESSED,
+                                     &gl_compressed) );
 
   {
     GLint val;
 
-    GE( glGetTexLevelParameteriv (GL_TEXTURE_2D, 0,
-                                  GL_TEXTURE_INTERNAL_FORMAT,
-                                  &val) );
+    GE( ctx, glGetTexLevelParameteriv (GL_TEXTURE_2D, 0,
+                                       GL_TEXTURE_INTERNAL_FORMAT,
+                                       &val) );
 
     gl_int_format = val;
   }
@@ -529,10 +535,10 @@ _cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
                                    tex_2d->gl_texture,
                                    FALSE);
 
-  while ((gl_error = glGetError ()) != GL_NO_ERROR)
+  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
     ;
   ctx->glEGLImageTargetTexture2D (GL_TEXTURE_2D, image);
-  if (glGetError () != GL_NO_ERROR)
+  if (ctx->glGetError () != GL_NO_ERROR)
     {
       g_set_error (error,
                    COGL_TEXTURE_ERROR,
@@ -630,6 +636,8 @@ _cogl_texture_2d_copy_from_framebuffer (CoglHandle handle,
 {
   CoglTexture2D *tex_2d;
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   g_return_if_fail (cogl_is_texture_2d (handle));
 
   tex_2d = COGL_TEXTURE_2D (handle);
@@ -644,11 +652,11 @@ _cogl_texture_2d_copy_from_framebuffer (CoglHandle handle,
                                    tex_2d->gl_texture,
                                    tex_2d->is_foreign);
 
-  glCopyTexSubImage2D (GL_TEXTURE_2D,
-                       0, /* level */
-                       dst_x, dst_y,
-                       src_x, src_y,
-                       width, height);
+  ctx->glCopyTexSubImage2D (GL_TEXTURE_2D,
+                            0, /* level */
+                            dst_x, dst_y,
+                            src_x, src_y,
+                            width, height);
 
   tex_2d->mipmaps_dirty = TRUE;
 }
@@ -721,6 +729,8 @@ _cogl_texture_2d_set_filters (CoglTexture *tex,
 {
   CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   if (min_filter == tex_2d->min_filter
       && mag_filter == tex_2d->mag_filter)
     return;
@@ -733,8 +743,8 @@ _cogl_texture_2d_set_filters (CoglTexture *tex,
   _cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
                                    tex_2d->gl_texture,
                                    tex_2d->is_foreign);
-  GE( glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter) );
-  GE( glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter) );
+  GE( ctx, glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter) );
+  GE( ctx, glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter) );
 }
 
 static void
@@ -760,16 +770,16 @@ _cogl_texture_2d_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
 #ifndef HAVE_COGL_GLES2
       else
         {
-          GE( glTexParameteri (GL_TEXTURE_2D,
-                               GL_GENERATE_MIPMAP,
-                               GL_TRUE) );
-          GE( glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 1, 1,
-                               tex_2d->first_pixel.gl_format,
-                               tex_2d->first_pixel.gl_type,
-                               tex_2d->first_pixel.data) );
-          GE( glTexParameteri (GL_TEXTURE_2D,
-                               GL_GENERATE_MIPMAP,
-                               GL_FALSE) );
+          GE( ctx, glTexParameteri (GL_TEXTURE_2D,
+                                    GL_GENERATE_MIPMAP,
+                                    GL_TRUE) );
+          GE( ctx, glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 1, 1,
+                                    tex_2d->first_pixel.gl_format,
+                                    tex_2d->first_pixel.gl_type,
+                                    tex_2d->first_pixel.data) );
+          GE( ctx, glTexParameteri (GL_TEXTURE_2D,
+                                    GL_GENERATE_MIPMAP,
+                                    GL_FALSE) );
         }
 #endif
 
diff --git a/cogl/cogl-texture-3d.c b/cogl/cogl-texture-3d.c
index 3803c2d..7c11172 100644
--- a/cogl/cogl-texture-3d.c
+++ b/cogl/cogl-texture-3d.c
@@ -49,9 +49,6 @@
 #define GL_TEXTURE_WRAP_R                       0x8072
 #endif
 
-#define glTexImage3D ctx->glTexImage3D
-#define glTexSubImage3D ctx->glTexSubImage3D
-
 static void _cogl_texture_3d_free (CoglTexture3D *tex_3d);
 
 COGL_TEXTURE_DEFINE (Texture3D, texture_3d);
@@ -140,6 +137,8 @@ _cogl_texture_3d_set_wrap_mode_parameters (CoglTexture *tex,
 {
   CoglTexture3D *tex_3d = COGL_TEXTURE_3D (tex);
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   /* Only set the wrap mode if it's different from the current value
      to avoid too many GL calls. */
   if (tex_3d->wrap_mode_s != wrap_mode_s ||
@@ -149,9 +148,15 @@ _cogl_texture_3d_set_wrap_mode_parameters (CoglTexture *tex,
       _cogl_bind_gl_texture_transient (GL_TEXTURE_3D,
                                        tex_3d->gl_texture,
                                        FALSE);
-      GE( glTexParameteri (GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, wrap_mode_s) );
-      GE( glTexParameteri (GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, wrap_mode_t) );
-      GE( glTexParameteri (GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, wrap_mode_p) );
+      GE( ctx, glTexParameteri (GL_TEXTURE_3D,
+                                GL_TEXTURE_WRAP_S,
+                                wrap_mode_s) );
+      GE( ctx, glTexParameteri (GL_TEXTURE_3D,
+                                GL_TEXTURE_WRAP_T,
+                                wrap_mode_t) );
+      GE( ctx, glTexParameteri (GL_TEXTURE_3D,
+                                GL_TEXTURE_WRAP_R,
+                                wrap_mode_p) );
 
       tex_3d->wrap_mode_s = wrap_mode_s;
       tex_3d->wrap_mode_t = wrap_mode_t;
@@ -295,8 +300,8 @@ cogl_texture_3d_new_with_size (unsigned int     width,
   _cogl_bind_gl_texture_transient (GL_TEXTURE_3D,
                                    tex_3d->gl_texture,
                                    FALSE);
-  GE( glTexImage3D (GL_TEXTURE_3D, 0, gl_intformat,
-                    width, height, depth, 0, gl_format, gl_type, NULL) );
+  GE( ctx, glTexImage3D (GL_TEXTURE_3D, 0, gl_intformat,
+                         width, height, depth, 0, gl_format, gl_type, NULL) );
 
   return _cogl_texture_3d_handle_new (tex_3d);
 }
@@ -536,6 +541,8 @@ _cogl_texture_3d_set_filters (CoglTexture *tex,
 {
   CoglTexture3D *tex_3d = COGL_TEXTURE_3D (tex);
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   if (min_filter == tex_3d->min_filter
       && mag_filter == tex_3d->mag_filter)
     return;
@@ -548,8 +555,8 @@ _cogl_texture_3d_set_filters (CoglTexture *tex,
   _cogl_bind_gl_texture_transient (GL_TEXTURE_3D,
                                    tex_3d->gl_texture,
                                    FALSE);
-  GE( glTexParameteri (GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, mag_filter) );
-  GE( glTexParameteri (GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, min_filter) );
+  GE( ctx, glTexParameteri (GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, mag_filter) );
+  GE( ctx, glTexParameteri (GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, min_filter) );
 }
 
 static void
@@ -574,23 +581,23 @@ _cogl_texture_3d_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
 #ifndef HAVE_COGL_GLES2
       else
         {
-          GE( glTexParameteri (GL_TEXTURE_3D,
-                               GL_GENERATE_MIPMAP,
-                               GL_TRUE) );
-          GE( glTexSubImage3D (GL_TEXTURE_3D,
-                               0, /* level */
-                               0, /* xoffset */
-                               0, /* yoffset */
-                               0, /* zoffset */
-                               1, /* width */
-                               1, /* height */
-                               1, /* depth */
-                               tex_3d->first_pixel.gl_format,
-                               tex_3d->first_pixel.gl_type,
-                               tex_3d->first_pixel.data) );
-          GE( glTexParameteri (GL_TEXTURE_3D,
-                               GL_GENERATE_MIPMAP,
-                               GL_FALSE) );
+          GE( ctx, glTexParameteri (GL_TEXTURE_3D,
+                                    GL_GENERATE_MIPMAP,
+                                    GL_TRUE) );
+          GE( ctx, glTexSubImage3D (GL_TEXTURE_3D,
+                                    0, /* level */
+                                    0, /* xoffset */
+                                    0, /* yoffset */
+                                    0, /* zoffset */
+                                    1, /* width */
+                                    1, /* height */
+                                    1, /* depth */
+                                    tex_3d->first_pixel.gl_format,
+                                    tex_3d->first_pixel.gl_type,
+                                    tex_3d->first_pixel.data) );
+          GE( ctx, glTexParameteri (GL_TEXTURE_3D,
+                                    GL_GENERATE_MIPMAP,
+                                    GL_FALSE) );
         }
 #endif
 
diff --git a/cogl/cogl-texture-rectangle.c b/cogl/cogl-texture-rectangle.c
index 37bc93d..dc8bb77 100644
--- a/cogl/cogl-texture-rectangle.c
+++ b/cogl/cogl-texture-rectangle.c
@@ -154,6 +154,8 @@ _cogl_texture_rectangle_set_wrap_mode_parameters (CoglTexture *tex,
 {
   CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   /* Only set the wrap mode if it's different from the current value
      to avoid too many GL calls. Texture rectangle doesn't make use of
      the r coordinate so we can ignore its wrap mode */
@@ -163,13 +165,13 @@ _cogl_texture_rectangle_set_wrap_mode_parameters (CoglTexture *tex,
       g_assert (can_use_wrap_mode (wrap_mode_s));
       g_assert (can_use_wrap_mode (wrap_mode_t));
 
-      GE( _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
-                                           tex_rect->gl_texture,
-                                           tex_rect->is_foreign) );
-      GE( glTexParameteri (GL_TEXTURE_RECTANGLE_ARB,
-                           GL_TEXTURE_WRAP_S, wrap_mode_s) );
-      GE( glTexParameteri (GL_TEXTURE_RECTANGLE_ARB,
-                           GL_TEXTURE_WRAP_T, wrap_mode_t) );
+      _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
+                                       tex_rect->gl_texture,
+                                       tex_rect->is_foreign);
+      GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB,
+                                GL_TEXTURE_WRAP_S, wrap_mode_s) );
+      GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB,
+                                GL_TEXTURE_WRAP_T, wrap_mode_t) );
 
       tex_rect->wrap_mode_s = wrap_mode_s;
       tex_rect->wrap_mode_t = wrap_mode_t;
@@ -251,6 +253,8 @@ _cogl_texture_rectangle_new_with_size (unsigned int     width,
   GLenum                gl_format;
   GLenum                gl_type;
 
+  _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
+
   /* Since no data, we need some internal format */
   if (internal_format == COGL_PIXEL_FORMAT_ANY)
     internal_format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
@@ -267,11 +271,11 @@ _cogl_texture_rectangle_new_with_size (unsigned int     width,
                                                   internal_format);
 
   _cogl_texture_driver_gen (GL_TEXTURE_RECTANGLE_ARB, 1, &tex_rect->gl_texture);
-  GE( _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
-                                       tex_rect->gl_texture,
-                                       tex_rect->is_foreign) );
-  GE( glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, gl_intformat,
-                    width, height, 0, gl_format, gl_type, NULL) );
+  _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
+                                   tex_rect->gl_texture,
+                                   tex_rect->is_foreign);
+  GE( ctx, glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, gl_intformat,
+                         width, height, 0, gl_format, gl_type, NULL) );
 
   return _cogl_texture_rectangle_handle_new (tex_rect);
 }
@@ -344,35 +348,37 @@ _cogl_texture_rectangle_new_from_foreign (GLuint gl_handle,
   GLenum                gl_int_format = 0;
   CoglTextureRectangle *tex_rect;
 
+  _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
+
   if (!_cogl_texture_driver_allows_foreign_gl_target (GL_TEXTURE_RECTANGLE_ARB))
     return COGL_INVALID_HANDLE;
 
   /* Make sure it is a valid GL texture object */
-  if (!glIsTexture (gl_handle))
+  if (!ctx->glIsTexture (gl_handle))
     return COGL_INVALID_HANDLE;
 
   /* Make sure binding succeeds */
-  while ((gl_error = glGetError ()) != GL_NO_ERROR)
+  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
     ;
 
   _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB, gl_handle, TRUE);
-  if (glGetError () != GL_NO_ERROR)
+  if (ctx->glGetError () != GL_NO_ERROR)
     return COGL_INVALID_HANDLE;
 
   /* Obtain texture parameters */
 
 #if HAVE_COGL_GL
 
-  GE( glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE_ARB, 0,
-                                GL_TEXTURE_COMPRESSED,
-                                &gl_compressed) );
+  GE( ctx, glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE_ARB, 0,
+                                     GL_TEXTURE_COMPRESSED,
+                                     &gl_compressed) );
 
   {
     GLint val;
 
-    GE( glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE_ARB, 0,
-                                  GL_TEXTURE_INTERNAL_FORMAT,
-                                  &val) );
+    GE( ctx, glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE_ARB, 0,
+                                       GL_TEXTURE_INTERNAL_FORMAT,
+                                       &val) );
 
     gl_int_format = val;
   }
@@ -499,6 +505,8 @@ _cogl_texture_rectangle_set_filters (CoglTexture *tex,
 {
   CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   if (min_filter == tex_rect->min_filter
       && mag_filter == tex_rect->mag_filter)
     return;
@@ -511,13 +519,13 @@ _cogl_texture_rectangle_set_filters (CoglTexture *tex,
   tex_rect->mag_filter = mag_filter;
 
   /* Apply new filters to the texture */
-  GE( _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
-                                       tex_rect->gl_texture,
-                                       tex_rect->is_foreign) );
-  GE( glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
-                       mag_filter) );
-  GE( glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
-                       min_filter) );
+  _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
+                                   tex_rect->gl_texture,
+                                   tex_rect->is_foreign);
+  GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
+                            mag_filter) );
+  GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
+                            min_filter) );
 }
 
 static void
@@ -580,6 +588,8 @@ _cogl_texture_rectangle_get_data (CoglTexture     *tex,
   GLenum                gl_format;
   GLenum                gl_type;
 
+  _COGL_GET_CONTEXT (ctx, FALSE);
+
   bpp = _cogl_get_format_bpp (format);
 
   _cogl_pixel_format_to_gl (format,
@@ -589,9 +599,9 @@ _cogl_texture_rectangle_get_data (CoglTexture     *tex,
 
   _cogl_texture_driver_prep_gl_for_pixels_download (rowstride, bpp);
 
-  GE( _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
-                                       tex_rect->gl_texture,
-                                       tex_rect->is_foreign) );
+  _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
+                                   tex_rect->gl_texture,
+                                   tex_rect->is_foreign);
   return _cogl_texture_driver_gl_get_tex_image (GL_TEXTURE_RECTANGLE_ARB,
                                                 gl_format,
                                                 gl_type,
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index f1ff63d..f2f0a3b 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -250,27 +250,31 @@ _cogl_texture_prepare_for_upload (CoglBitmap      *src_bmp,
 void
 _cogl_texture_prep_gl_alignment_for_pixels_upload (int pixels_rowstride)
 {
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   if (!(pixels_rowstride & 0x7))
-    GE( glPixelStorei (GL_UNPACK_ALIGNMENT, 8) );
+    GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT, 8) );
   else if (!(pixels_rowstride & 0x3))
-    GE( glPixelStorei (GL_UNPACK_ALIGNMENT, 4) );
+    GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT, 4) );
   else if (!(pixels_rowstride & 0x1))
-    GE( glPixelStorei (GL_UNPACK_ALIGNMENT, 2) );
+    GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT, 2) );
   else
-    GE( glPixelStorei (GL_UNPACK_ALIGNMENT, 1) );
+    GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT, 1) );
 }
 
 void
 _cogl_texture_prep_gl_alignment_for_pixels_download (int pixels_rowstride)
 {
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   if (!(pixels_rowstride & 0x7))
-    GE( glPixelStorei (GL_PACK_ALIGNMENT, 8) );
+    GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, 8) );
   else if (!(pixels_rowstride & 0x3))
-    GE( glPixelStorei (GL_PACK_ALIGNMENT, 4) );
+    GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, 4) );
   else if (!(pixels_rowstride & 0x1))
-    GE( glPixelStorei (GL_PACK_ALIGNMENT, 2) );
+    GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, 2) );
   else
-    GE( glPixelStorei (GL_PACK_ALIGNMENT, 1) );
+    GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, 1) );
 }
 
 /* FIXME: wrap modes should be set on pipelines not textures */
@@ -1119,10 +1123,10 @@ _cogl_texture_draw_and_read (CoglHandle   handle,
      still doesn't seem to have an alpha buffer. This might be just
      a PowerVR issue.
   GLint r_bits, g_bits, b_bits, a_bits;
-  GE( glGetIntegerv (GL_ALPHA_BITS, &a_bits) );
-  GE( glGetIntegerv (GL_RED_BITS, &r_bits) );
-  GE( glGetIntegerv (GL_GREEN_BITS, &g_bits) );
-  GE( glGetIntegerv (GL_BLUE_BITS, &b_bits) );
+  GE( ctx, glGetIntegerv (GL_ALPHA_BITS, &a_bits) );
+  GE( ctx, glGetIntegerv (GL_RED_BITS, &r_bits) );
+  GE( ctx, glGetIntegerv (GL_GREEN_BITS, &g_bits) );
+  GE( ctx, glGetIntegerv (GL_BLUE_BITS, &b_bits) );
   printf ("R bits: %d\n", r_bits);
   printf ("G bits: %d\n", g_bits);
   printf ("B bits: %d\n", b_bits);
diff --git a/cogl/cogl.c b/cogl/cogl.c
index 67f1ed1..ea4d7c8 100644
--- a/cogl/cogl.c
+++ b/cogl/cogl.c
@@ -47,10 +47,6 @@
 #include "cogl-attribute-private.h"
 #include "cogl-framebuffer-private.h"
 
-#ifdef HAVE_COGL_GL
-#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
-#endif
-
 #ifdef COGL_GL_DEBUG
 /* GL error to string conversion */
 static const struct {
@@ -154,14 +150,14 @@ toggle_flag (CoglContext *ctx,
     {
       if (!(ctx->enable_flags & flag))
 	{
-	  GE( glEnable (gl_flag) );
+	  GE( ctx, glEnable (gl_flag) );
 	  ctx->enable_flags |= flag;
 	  return TRUE;
 	}
     }
   else if (ctx->enable_flags & flag)
     {
-      GE( glDisable (gl_flag) );
+      GE( ctx, glDisable (gl_flag) );
       ctx->enable_flags &= ~flag;
     }
 
@@ -191,14 +187,14 @@ toggle_client_flag (CoglContext *ctx,
     {
       if (!(ctx->enable_flags & flag))
 	{
-	  GE( glEnableClientState (gl_flag) );
+	  GE( ctx, glEnableClientState (gl_flag) );
 	  ctx->enable_flags |= flag;
 	  return TRUE;
 	}
     }
   else if (ctx->enable_flags & flag)
     {
-      GE( glDisableClientState (gl_flag) );
+      GE( ctx, glDisableClientState (gl_flag) );
       ctx->enable_flags &= ~flag;
     }
 
@@ -307,9 +303,9 @@ _cogl_flush_face_winding (void)
     {
 
       if (winding == COGL_FRONT_WINDING_CLOCKWISE)
-        GE (glFrontFace (GL_CW));
+        GE (ctx, glFrontFace (GL_CW));
       else
-        GE (glFrontFace (GL_CCW));
+        GE (ctx, glFrontFace (GL_CCW));
       ctx->flushed_front_winding = winding;
     }
 }
@@ -574,9 +570,9 @@ _cogl_read_pixels_with_rowstride (int x,
 
       _cogl_texture_driver_prep_gl_for_pixels_download (4 * width, 4);
 
-      GE( glReadPixels (x, y, width, height,
-                        GL_RGBA, GL_UNSIGNED_BYTE,
-                        tmp_data) );
+      GE( ctx, glReadPixels (x, y, width, height,
+                             GL_RGBA, GL_UNSIGNED_BYTE,
+                             tmp_data) );
 
       /* CoglBitmap doesn't currently have a way to convert without
          allocating its own buffer so we have to copy the data
@@ -604,7 +600,7 @@ _cogl_read_pixels_with_rowstride (int x,
     {
       _cogl_texture_driver_prep_gl_for_pixels_download (rowstride, bpp);
 
-      GE( glReadPixels (x, y, width, height, gl_format, gl_type, pixels) );
+      GE( ctx, glReadPixels (x, y, width, height, gl_format, gl_type, pixels) );
 
       /* Convert to the premult format specified by the caller
          in-place. This will do nothing if the premult status is already
diff --git a/cogl/cogl2-path.c b/cogl/cogl2-path.c
index 043ac37..521bd1f 100644
--- a/cogl/cogl2-path.c
+++ b/cogl/cogl2-path.c
@@ -381,15 +381,15 @@ _cogl_add_path_to_stencil_buffer (CoglPath *path,
 
   _cogl_pipeline_flush_gl_state (ctx->stencil_pipeline, FALSE, 0);
 
-  GE( glEnable (GL_STENCIL_TEST) );
+  GE( ctx, glEnable (GL_STENCIL_TEST) );
 
-  GE( glColorMask (FALSE, FALSE, FALSE, FALSE) );
-  GE( glDepthMask (FALSE) );
+  GE( ctx, glColorMask (FALSE, FALSE, FALSE, FALSE) );
+  GE( ctx, glDepthMask (FALSE) );
 
   if (merge)
     {
-      GE (glStencilMask (2));
-      GE (glStencilFunc (GL_LEQUAL, 0x2, 0x6));
+      GE (ctx, glStencilMask (2));
+      GE (ctx, glStencilFunc (GL_LEQUAL, 0x2, 0x6));
     }
   else
     {
@@ -407,18 +407,18 @@ _cogl_add_path_to_stencil_buffer (CoglPath *path,
       else
         {
           /* Just clear the bounding box */
-          GE( glStencilMask (~(GLuint) 0) );
-          GE( glStencilOp (GL_ZERO, GL_ZERO, GL_ZERO) );
+          GE( ctx, glStencilMask (~(GLuint) 0) );
+          GE( ctx, glStencilOp (GL_ZERO, GL_ZERO, GL_ZERO) );
           _cogl_rectangle_immediate (data->path_nodes_min.x,
                                      data->path_nodes_min.y,
                                      data->path_nodes_max.x,
                                      data->path_nodes_max.y);
         }
-      GE (glStencilMask (1));
-      GE (glStencilFunc (GL_LEQUAL, 0x1, 0x3));
+      GE (ctx, glStencilMask (1));
+      GE (ctx, glStencilFunc (GL_LEQUAL, 0x1, 0x3));
     }
 
-  GE (glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT));
+  GE (ctx, glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT));
 
   if (path->data->path_nodes->len >= 3)
     _cogl_path_fill_nodes (path);
@@ -427,9 +427,9 @@ _cogl_add_path_to_stencil_buffer (CoglPath *path,
     {
       /* Now we have the new stencil buffer in bit 1 and the old
          stencil buffer in bit 0 so we need to intersect them */
-      GE (glStencilMask (3));
-      GE (glStencilFunc (GL_NEVER, 0x2, 0x3));
-      GE (glStencilOp (GL_DECR, GL_DECR, GL_DECR));
+      GE (ctx, glStencilMask (3));
+      GE (ctx, glStencilFunc (GL_NEVER, 0x2, 0x3));
+      GE (ctx, glStencilOp (GL_DECR, GL_DECR, GL_DECR));
       /* Decrement all of the bits twice so that only pixels where the
          value is 3 will remain */
 
@@ -450,12 +450,12 @@ _cogl_add_path_to_stencil_buffer (CoglPath *path,
       _cogl_matrix_stack_pop (projection_stack);
     }
 
-  GE (glStencilMask (~(GLuint) 0));
-  GE (glDepthMask (TRUE));
-  GE (glColorMask (TRUE, TRUE, TRUE, TRUE));
+  GE (ctx, glStencilMask (~(GLuint) 0));
+  GE (ctx, glDepthMask (TRUE));
+  GE (ctx, glColorMask (TRUE, TRUE, TRUE, TRUE));
 
-  GE (glStencilFunc (GL_EQUAL, 0x1, 0x1));
-  GE (glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP));
+  GE (ctx, glStencilFunc (GL_EQUAL, 0x1, 0x1));
+  GE (ctx, glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP));
 
   /* restore the original pipeline */
   cogl_pop_source ();
diff --git a/cogl/driver/gl/cogl-gl.c b/cogl/driver/gl/cogl-gl.c
index 906d7da..a701cb7 100644
--- a/cogl/driver/gl/cogl-gl.c
+++ b/cogl/driver/gl/cogl-gl.c
@@ -40,8 +40,10 @@ _cogl_get_gl_version (int *major_out, int *minor_out)
   const char *version_string, *major_end, *minor_end;
   int major = 0, minor = 0;
 
+  _COGL_GET_CONTEXT (ctx, FALSE);
+
   /* Get the OpenGL version number */
-  if ((version_string = (const char *) glGetString (GL_VERSION)) == NULL)
+  if ((version_string = (const char *) ctx->glGetString (GL_VERSION)) == NULL)
     return FALSE;
 
   /* Extract the major number */
@@ -75,6 +77,8 @@ _cogl_gl_check_version (GError **error)
   int major, minor;
   const char *gl_extensions;
 
+  _COGL_GET_CONTEXT (ctx, FALSE);
+
   if (!_cogl_get_gl_version (&major, &minor))
     {
       g_set_error (error,
@@ -88,7 +92,7 @@ _cogl_gl_check_version (GError **error)
   if (COGL_CHECK_GL_VERSION (major, minor, 1, 3))
     return TRUE;
 
-  gl_extensions = (const char*) glGetString (GL_EXTENSIONS);
+  gl_extensions = (const char*) ctx->glGetString (GL_EXTENSIONS);
 
   /* OpenGL 1.2 is only supported if we have the multitexturing
      extension */
@@ -131,16 +135,25 @@ _cogl_gl_update_features (CoglContext *context)
   int num_stencil_bits = 0;
   int gl_major = 0, gl_minor = 0;
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
+  /* We have to special case getting the pointer to the glGetString
+     function because we need to use it to determine what functions we
+     can expect */
+  context->glGetString =
+    (void *) _cogl_get_proc_address (_cogl_context_get_winsys (context),
+                                     "glGetString");
+
   COGL_NOTE (WINSYS,
              "Checking features\n"
              "  GL_VENDOR: %s\n"
              "  GL_RENDERER: %s\n"
              "  GL_VERSION: %s\n"
              "  GL_EXTENSIONS: %s",
-             glGetString (GL_VENDOR),
-             glGetString (GL_RENDERER),
-             glGetString (GL_VERSION),
-             glGetString (GL_EXTENSIONS));
+             ctx->glGetString (GL_VENDOR),
+             ctx->glGetString (GL_RENDERER),
+             ctx->glGetString (GL_VERSION),
+             ctx->glGetString (GL_EXTENSIONS));
 
   _cogl_get_gl_version (&gl_major, &gl_minor);
 
@@ -148,7 +161,7 @@ _cogl_gl_update_features (CoglContext *context)
            | COGL_FEATURE_UNSIGNED_INT_INDICES
            | COGL_FEATURE_DEPTH_RANGE);
 
-  gl_extensions = (const char *)glGetString (GL_EXTENSIONS);
+  gl_extensions = (const char *)ctx->glGetString (GL_EXTENSIONS);
 
   _cogl_feature_check_ext_functions (context,
                                      gl_major,
@@ -172,12 +185,12 @@ _cogl_gl_update_features (CoglContext *context)
     }
 #endif
 
-  GE( glGetIntegerv (GL_STENCIL_BITS, &num_stencil_bits) );
+  GE( ctx, glGetIntegerv (GL_STENCIL_BITS, &num_stencil_bits) );
   /* We need at least three stencil bits to combine clips */
   if (num_stencil_bits > 2)
     flags |= COGL_FEATURE_STENCIL_BUFFER;
 
-  GE( glGetIntegerv (GL_MAX_CLIP_PLANES, &max_clip_planes) );
+  GE( ctx, glGetIntegerv (GL_MAX_CLIP_PLANES, &max_clip_planes) );
   if (max_clip_planes >= 4)
     flags |= COGL_FEATURE_FOUR_CLIP_PLANES;
 
diff --git a/cogl/driver/gl/cogl-texture-driver-gl.c b/cogl/driver/gl/cogl-texture-driver-gl.c
index d5e7126..fdb938e 100644
--- a/cogl/driver/gl/cogl-texture-driver-gl.c
+++ b/cogl/driver/gl/cogl-texture-driver-gl.c
@@ -46,9 +46,6 @@
 #include <stdlib.h>
 #include <math.h>
 
-#define glGenerateMipmap ctx->glGenerateMipmap
-#define glTexImage3D ctx->glTexImage3D
-
 void
 _cogl_texture_driver_gen (GLenum   gl_target,
                           GLsizei  n,
@@ -56,7 +53,9 @@ _cogl_texture_driver_gen (GLenum   gl_target,
 {
   unsigned int i;
 
-  GE (glGenTextures (n, textures));
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
+  GE (ctx, glGenTextures (n, textures));
 
   for (i = 0; i < n; i++)
     {
@@ -69,9 +68,9 @@ _cogl_texture_driver_gen (GLenum   gl_target,
         case GL_TEXTURE_2D:
         case GL_TEXTURE_3D:
           /* GL_TEXTURE_MAG_FILTER defaults to GL_LINEAR, no need to set it */
-          GE( glTexParameteri (gl_target,
-                               GL_TEXTURE_MIN_FILTER,
-                               GL_LINEAR) );
+          GE( ctx, glTexParameteri (gl_target,
+                                    GL_TEXTURE_MIN_FILTER,
+                                    GL_LINEAR) );
           break;
 
         case GL_TEXTURE_RECTANGLE_ARB:
@@ -94,13 +93,16 @@ prep_gl_for_pixels_upload_full (int pixels_rowstride,
                                 int pixels_src_y,
                                 int pixels_bpp)
 {
-  GE( glPixelStorei (GL_UNPACK_ROW_LENGTH, pixels_rowstride / pixels_bpp) );
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
+  GE( ctx, glPixelStorei (GL_UNPACK_ROW_LENGTH,
+                          pixels_rowstride / pixels_bpp) );
 
-  GE( glPixelStorei (GL_UNPACK_SKIP_PIXELS, pixels_src_x) );
-  GE( glPixelStorei (GL_UNPACK_SKIP_ROWS, pixels_src_y) );
+  GE( ctx, glPixelStorei (GL_UNPACK_SKIP_PIXELS, pixels_src_x) );
+  GE( ctx, glPixelStorei (GL_UNPACK_SKIP_ROWS, pixels_src_y) );
 
   if (cogl_features_available (COGL_FEATURE_TEXTURE_3D))
-    GE( glPixelStorei (GL_UNPACK_IMAGE_HEIGHT, image_height) );
+    GE( ctx, glPixelStorei (GL_UNPACK_IMAGE_HEIGHT, image_height) );
 
   _cogl_texture_prep_gl_alignment_for_pixels_upload (pixels_rowstride);
 }
@@ -121,13 +123,15 @@ prep_gl_for_pixels_download_full (int pixels_rowstride,
                                   int pixels_src_y,
                                   int pixels_bpp)
 {
-  GE( glPixelStorei (GL_PACK_ROW_LENGTH, pixels_rowstride / pixels_bpp) );
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
+  GE( ctx, glPixelStorei (GL_PACK_ROW_LENGTH, pixels_rowstride / pixels_bpp) );
 
-  GE( glPixelStorei (GL_PACK_SKIP_PIXELS, pixels_src_x) );
-  GE( glPixelStorei (GL_PACK_SKIP_ROWS, pixels_src_y) );
+  GE( ctx, glPixelStorei (GL_PACK_SKIP_PIXELS, pixels_src_x) );
+  GE( ctx, glPixelStorei (GL_PACK_SKIP_ROWS, pixels_src_y) );
 
   if (cogl_features_available (COGL_FEATURE_TEXTURE_3D))
-    GE( glPixelStorei (GL_PACK_IMAGE_HEIGHT, image_height) );
+    GE( ctx, glPixelStorei (GL_PACK_IMAGE_HEIGHT, image_height) );
 
   _cogl_texture_prep_gl_alignment_for_pixels_download (pixels_rowstride);
 }
@@ -156,6 +160,8 @@ _cogl_texture_driver_upload_subregion_to_gl (GLenum       gl_target,
   guint8 *data;
   int bpp = _cogl_get_format_bpp (_cogl_bitmap_get_format (source_bmp));
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   data = _cogl_bitmap_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0);
 
   /* Setup gl alignment to match rowstride and top-left corner */
@@ -167,12 +173,12 @@ _cogl_texture_driver_upload_subregion_to_gl (GLenum       gl_target,
 
   _cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
 
-  GE( glTexSubImage2D (gl_target, 0,
-                       dst_x, dst_y,
-                       width, height,
-                       source_gl_format,
-                       source_gl_type,
-                       data) );
+  GE( ctx, glTexSubImage2D (gl_target, 0,
+                            dst_x, dst_y,
+                            width, height,
+                            source_gl_format,
+                            source_gl_type,
+                            data) );
 
   _cogl_bitmap_unbind (source_bmp);
 }
@@ -189,6 +195,8 @@ _cogl_texture_driver_upload_to_gl (GLenum       gl_target,
   guint8 *data;
   int bpp = _cogl_get_format_bpp (_cogl_bitmap_get_format (source_bmp));
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   data = _cogl_bitmap_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0);
 
   /* Setup gl alignment to match rowstride and top-left corner */
@@ -197,14 +205,14 @@ _cogl_texture_driver_upload_to_gl (GLenum       gl_target,
 
   _cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
 
-  GE( glTexImage2D (gl_target, 0,
-                    internal_gl_format,
-                    _cogl_bitmap_get_width (source_bmp),
-                    _cogl_bitmap_get_height (source_bmp),
-                    0,
-                    source_gl_format,
-                    source_gl_type,
-                    data) );
+  GE( ctx, glTexImage2D (gl_target, 0,
+                         internal_gl_format,
+                         _cogl_bitmap_get_width (source_bmp),
+                         _cogl_bitmap_get_height (source_bmp),
+                         0,
+                         source_gl_format,
+                         source_gl_type,
+                         data) );
 
   _cogl_bitmap_unbind (source_bmp);
 }
@@ -235,16 +243,16 @@ _cogl_texture_driver_upload_to_gl_3d (GLenum       gl_target,
 
   _cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
 
-  GE( glTexImage3D (gl_target,
-                    0, /* level */
-                    internal_gl_format,
-                    _cogl_bitmap_get_width (source_bmp),
-                    height,
-                    depth,
-                    0,
-                    source_gl_format,
-                    source_gl_type,
-                    data) );
+  GE( ctx, glTexImage3D (gl_target,
+                         0, /* level */
+                         internal_gl_format,
+                         _cogl_bitmap_get_width (source_bmp),
+                         height,
+                         depth,
+                         0,
+                         source_gl_format,
+                         source_gl_type,
+                         data) );
 
   _cogl_bitmap_unbind (source_bmp);
 }
@@ -255,11 +263,13 @@ _cogl_texture_driver_gl_get_tex_image (GLenum  gl_target,
                                        GLenum  dest_gl_type,
                                        guint8 *dest)
 {
-  GE (glGetTexImage (gl_target,
-                     0, /* level */
-                     dest_gl_format,
-                     dest_gl_type,
-                     (GLvoid *)dest));
+  _COGL_GET_CONTEXT (ctx, FALSE);
+
+  GE (ctx, glGetTexImage (gl_target,
+                          0, /* level */
+                          dest_gl_format,
+                          dest_gl_type,
+                          (GLvoid *)dest));
   return TRUE;
 }
 
@@ -283,12 +293,12 @@ _cogl_texture_driver_size_supported_3d (GLenum gl_target,
     return FALSE;
 
   /* Proxy texture allows for a quick check for supported size */
-  GE( glTexImage3D (proxy_target, 0, GL_RGBA,
-                    width, height, depth, 0 /* border */,
-                    gl_format, gl_type, NULL) );
+  GE( ctx, glTexImage3D (proxy_target, 0, GL_RGBA,
+                         width, height, depth, 0 /* border */,
+                         gl_format, gl_type, NULL) );
 
-  GE( glGetTexLevelParameteriv (proxy_target, 0,
-                                GL_TEXTURE_WIDTH, &new_width) );
+  GE( ctx, glGetTexLevelParameteriv (proxy_target, 0,
+                                     GL_TEXTURE_WIDTH, &new_width) );
 
   return new_width != 0;
 }
@@ -303,6 +313,8 @@ _cogl_texture_driver_size_supported (GLenum gl_target,
   GLenum proxy_target;
   GLint new_width = 0;
 
+  _COGL_GET_CONTEXT (ctx, FALSE);
+
   if (gl_target == GL_TEXTURE_2D)
     proxy_target = GL_PROXY_TEXTURE_2D;
 #if HAVE_COGL_GL
@@ -314,12 +326,12 @@ _cogl_texture_driver_size_supported (GLenum gl_target,
     return FALSE;
 
   /* Proxy texture allows for a quick check for supported size */
-  GE( glTexImage2D (proxy_target, 0, GL_RGBA,
-                    width, height, 0 /* border */,
-                    gl_format, gl_type, NULL) );
+  GE( ctx, glTexImage2D (proxy_target, 0, GL_RGBA,
+                         width, height, 0 /* border */,
+                         gl_format, gl_type, NULL) );
 
-  GE( glGetTexLevelParameteriv (proxy_target, 0,
-                                GL_TEXTURE_WIDTH, &new_width) );
+  GE( ctx, glGetTexLevelParameteriv (proxy_target, 0,
+                                     GL_TEXTURE_WIDTH, &new_width) );
 
   return new_width != 0;
 }
@@ -329,11 +341,13 @@ _cogl_texture_driver_try_setting_gl_border_color (
                                               GLuint   gl_target,
                                               const GLfloat *transparent_color)
 {
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   /* Use a transparent border color so that we can leave the
      color buffer alone when using texture co-ordinates
      outside of the texture */
-  GE( glTexParameterfv (gl_target, GL_TEXTURE_BORDER_COLOR,
-                        transparent_color) );
+  GE( ctx, glTexParameterfv (gl_target, GL_TEXTURE_BORDER_COLOR,
+                             transparent_color) );
 }
 
 gboolean
@@ -504,7 +518,7 @@ _cogl_texture_driver_gl_generate_mipmaps (GLenum gl_target)
 {
   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
 
-  GE( glGenerateMipmap (gl_target) );
+  GE( ctx, glGenerateMipmap (gl_target) );
 }
 
 CoglPixelFormat
diff --git a/cogl/driver/gles/cogl-gles.c b/cogl/driver/gles/cogl-gles.c
index bf11194..0d97d2b 100644
--- a/cogl/driver/gles/cogl-gles.c
+++ b/cogl/driver/gles/cogl-gles.c
@@ -54,18 +54,25 @@ _cogl_gl_update_features (CoglContext *context)
 #endif
   int num_stencil_bits = 0;
 
+  /* We have to special case getting the pointer to the glGetString
+     function because we need to use it to determine what functions we
+     can expect */
+  context->glGetString =
+    (void *) _cogl_get_proc_address (_cogl_context_get_winsys (context),
+                                     "glGetString");
+
   COGL_NOTE (WINSYS,
              "Checking features\n"
              "  GL_VENDOR: %s\n"
              "  GL_RENDERER: %s\n"
              "  GL_VERSION: %s\n"
              "  GL_EXTENSIONS: %s",
-             glGetString (GL_VENDOR),
-             glGetString (GL_RENDERER),
-             glGetString (GL_VERSION),
-             glGetString (GL_EXTENSIONS));
+             context->glGetString (GL_VENDOR),
+             context->glGetString (GL_RENDERER),
+             context->glGetString (GL_VERSION),
+             context->glGetString (GL_EXTENSIONS));
 
-  gl_extensions = (const char*) glGetString (GL_EXTENSIONS);
+  gl_extensions = (const char*) context->glGetString (GL_EXTENSIONS);
 
   _cogl_feature_check_ext_functions (context,
                                      -1 /* GL major version */,
@@ -78,13 +85,13 @@ _cogl_gl_update_features (CoglContext *context)
 #endif
                                      );
 
-  GE( glGetIntegerv (GL_STENCIL_BITS, &num_stencil_bits) );
+  GE( context, glGetIntegerv (GL_STENCIL_BITS, &num_stencil_bits) );
   /* We need at least three stencil bits to combine clips */
   if (num_stencil_bits > 2)
     flags |= COGL_FEATURE_STENCIL_BUFFER;
 
 #ifndef HAVE_COGL_GLES2
-  GE( glGetIntegerv (GL_MAX_CLIP_PLANES, &max_clip_planes) );
+  GE( context, glGetIntegerv (GL_MAX_CLIP_PLANES, &max_clip_planes) );
   if (max_clip_planes >= 4)
     flags |= COGL_FEATURE_FOUR_CLIP_PLANES;
 #endif
diff --git a/cogl/driver/gles/cogl-texture-driver-gles.c b/cogl/driver/gles/cogl-texture-driver-gles.c
index a8fecbd..9a3f61b 100644
--- a/cogl/driver/gles/cogl-texture-driver-gles.c
+++ b/cogl/driver/gles/cogl-texture-driver-gles.c
@@ -46,9 +46,6 @@
 #include <stdlib.h>
 #include <math.h>
 
-#define glTexImage3D ctx->glTexImage3D
-#define glTexSubImage3D ctx->glTexSubImage3D
-
 #ifndef GL_TEXTURE_3D
 #define GL_TEXTURE_3D 0x806F
 #endif
@@ -63,7 +60,9 @@ _cogl_texture_driver_gen (GLenum   gl_target,
 {
   unsigned int i;
 
-  GE (glGenTextures (n, textures));
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
+  GE (ctx, glGenTextures (n, textures));
 
   for (i = 0; i < n; i++)
     {
@@ -74,7 +73,9 @@ _cogl_texture_driver_gen (GLenum   gl_target,
         case GL_TEXTURE_2D:
         case GL_TEXTURE_3D:
           /* GL_TEXTURE_MAG_FILTER defaults to GL_LINEAR, no need to set it */
-          GE( glTexParameteri (gl_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR) );
+          GE( ctx, glTexParameteri (gl_target,
+                                    GL_TEXTURE_MIN_FILTER,
+                                    GL_LINEAR) );
           break;
 
         default:
@@ -143,6 +144,8 @@ _cogl_texture_driver_upload_subregion_to_gl (GLenum       gl_target,
   CoglBitmap *slice_bmp;
   int rowstride;
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   /* If we are copying a sub region of the source bitmap then we need
      to copy it because GLES does not support GL_UNPACK_ROW_LENGTH */
   if (src_x != 0 || src_y != 0 ||
@@ -177,12 +180,12 @@ _cogl_texture_driver_upload_subregion_to_gl (GLenum       gl_target,
 
   _cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
 
-  GE( glTexSubImage2D (gl_target, 0,
-                       dst_x, dst_y,
-                       width, height,
-                       source_gl_format,
-                       source_gl_type,
-                       data) );
+  GE( ctx, glTexSubImage2D (gl_target, 0,
+                            dst_x, dst_y,
+                            width, height,
+                            source_gl_format,
+                            source_gl_type,
+                            data) );
 
   _cogl_bitmap_unbind (slice_bmp);
 
@@ -205,6 +208,8 @@ _cogl_texture_driver_upload_to_gl (GLenum       gl_target,
   CoglBitmap *bmp;
   guint8 *data;
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   bmp = prepare_bitmap_alignment_for_upload (source_bmp);
   rowstride = _cogl_bitmap_get_rowstride (bmp);
 
@@ -215,13 +220,13 @@ _cogl_texture_driver_upload_to_gl (GLenum       gl_target,
 
   data = _cogl_bitmap_bind (bmp, COGL_BUFFER_ACCESS_READ, 0);
 
-  GE( glTexImage2D (gl_target, 0,
-                    internal_gl_format,
-                    bmp_width, bmp_height,
-                    0,
-                    source_gl_format,
-                    source_gl_type,
-                    data) );
+  GE( ctx, glTexImage2D (gl_target, 0,
+                         internal_gl_format,
+                         bmp_width, bmp_height,
+                         0,
+                         source_gl_format,
+                         source_gl_type,
+                         data) );
 
   _cogl_bitmap_unbind (bmp);
 
@@ -264,16 +269,16 @@ _cogl_texture_driver_upload_to_gl_3d (GLenum       gl_target,
       /* Initialize the texture with empty data and then upload each
          image with a sub-region update */
 
-      GE( glTexImage3D (gl_target,
-                        0, /* level */
-                        internal_gl_format,
-                        bmp_width,
-                        height,
-                        depth,
-                        0,
-                        source_gl_format,
-                        source_gl_type,
-                        NULL) );
+      GE( ctx, glTexImage3D (gl_target,
+                             0, /* level */
+                             internal_gl_format,
+                             bmp_width,
+                             height,
+                             depth,
+                             0,
+                             source_gl_format,
+                             source_gl_type,
+                             NULL) );
 
       bmp = _cogl_bitmap_new_from_data (g_malloc (bpp * bmp_width * height),
                                         _cogl_bitmap_get_format (source_bmp),
@@ -295,17 +300,17 @@ _cogl_texture_driver_upload_to_gl_3d (GLenum       gl_target,
           data = _cogl_bitmap_bind (bmp,
                                     COGL_BUFFER_ACCESS_READ, 0);
 
-          GE( glTexSubImage3D (gl_target,
-                               0, /* level */
-                               0, /* xoffset */
-                               0, /* yoffset */
-                               i, /* zoffset */
-                               bmp_width, /* width */
-                               height, /* height */
-                               1, /* depth */
-                               source_gl_format,
-                               source_gl_type,
-                               data) );
+          GE( ctx, glTexSubImage3D (gl_target,
+                                    0, /* level */
+                                    0, /* xoffset */
+                                    0, /* yoffset */
+                                    i, /* zoffset */
+                                    bmp_width, /* width */
+                                    height, /* height */
+                                    1, /* depth */
+                                    source_gl_format,
+                                    source_gl_type,
+                                    data) );
 
           _cogl_bitmap_unbind (bmp);
         }
@@ -318,16 +323,16 @@ _cogl_texture_driver_upload_to_gl_3d (GLenum       gl_target,
 
       _cogl_texture_driver_prep_gl_for_pixels_upload (rowstride, bpp);
 
-      GE( glTexImage3D (gl_target,
-                        0, /* level */
-                        internal_gl_format,
-                        bmp_width,
-                        height,
-                        depth,
-                        0,
-                        source_gl_format,
-                        source_gl_type,
-                        data) );
+      GE( ctx, glTexImage3D (gl_target,
+                             0, /* level */
+                             internal_gl_format,
+                             bmp_width,
+                             height,
+                             depth,
+                             0,
+                             source_gl_format,
+                             source_gl_type,
+                             data) );
 
       _cogl_bitmap_unbind (source_bmp);
     }
@@ -355,10 +360,12 @@ _cogl_texture_driver_size_supported_3d (GLenum gl_target,
 {
   GLint max_size;
 
+  _COGL_GET_CONTEXT (ctx, FALSE);
+
   /* GLES doesn't support a proxy texture target so let's at least
      check whether the size is greater than
      GL_MAX_3D_TEXTURE_SIZE_OES */
-  GE( glGetIntegerv (GL_MAX_3D_TEXTURE_SIZE_OES, &max_size) );
+  GE( ctx, glGetIntegerv (GL_MAX_3D_TEXTURE_SIZE_OES, &max_size) );
 
   return width <= max_size && height <= max_size && depth <= max_size;
 }
@@ -372,9 +379,11 @@ _cogl_texture_driver_size_supported (GLenum gl_target,
 {
   GLint max_size;
 
+  _COGL_GET_CONTEXT (ctx, FALSE);
+
   /* GLES doesn't support a proxy texture target so let's at least
      check whether the size is greater than GL_MAX_TEXTURE_SIZE */
-  GE( glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_size) );
+  GE( ctx, glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_size) );
 
   return width <= max_size && height <= max_size;
 }
@@ -491,7 +500,9 @@ void
 _cogl_texture_driver_gl_generate_mipmaps (GLenum gl_target)
 {
 #ifdef HAVE_COGL_GLES2
-  GE( glGenerateMipmap (gl_target) );
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
+  GE( ctx, glGenerateMipmap (gl_target) );
 #endif
 }
 
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index 1b41fde..80c3767 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -1116,7 +1116,7 @@ _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
    *   additional extension so we can report the limited region of
    *   the window damage to X/compositors.
    */
-  glFinish ();
+  context->glFinish ();
 
   if (have_counter && can_wait)
     {
@@ -1148,7 +1148,7 @@ _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
       int i;
       /* XXX: checkout how this state interacts with the code to use
        * glBlitFramebuffer in Neil's texture atlasing branch */
-      glDrawBuffer (GL_FRONT);
+      context->glDrawBuffer (GL_FRONT);
       for (i = 0; i < n_rectangles; i++)
         {
           int *rect = &rectangles[4 * i];
@@ -1158,7 +1158,7 @@ _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
                                       rect[0], rect[1], x2, y2,
                                       GL_COLOR_BUFFER_BIT, GL_NEAREST);
         }
-      glDrawBuffer (GL_BACK);
+      context->glDrawBuffer (GL_BACK);
     }
 
   /* NB: unlike glXSwapBuffers, glXCopySubBuffer and
@@ -1166,7 +1166,7 @@ _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
    * have to flush ourselves if we want the request to complete in
    * a finite amount of time since otherwise the driver can batch
    * the command indefinitely. */
-  glFlush ();
+  context->glFlush ();
 
   /* NB: It's important we save the counter we read before acting on
    * the swap request since if we are mixing and matching different
@@ -1237,7 +1237,7 @@ _cogl_winsys_onscreen_swap_buffers (CoglOnscreen *onscreen)
            * obviously does not happen when we use _GLX_SWAP and let
            * the driver do the right thing
            */
-          glFinish ();
+          context->glFinish ();
 
           if (have_counter && can_wait)
             {
@@ -1844,7 +1844,7 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
 
       COGL_NOTE (TEXTURE_PIXMAP, "Rebinding GLXPixmap for %p", tex_pixmap);
 
-      GE( _cogl_bind_gl_texture_transient (gl_target, gl_handle, FALSE) );
+      _cogl_bind_gl_texture_transient (gl_target, gl_handle, FALSE);
 
       if (glx_tex_pixmap->pixmap_bound)
         glx_renderer->pf_glXReleaseTexImage (xlib_renderer->xdpy,
diff --git a/cogl/winsys/cogl-winsys-wgl.c b/cogl/winsys/cogl-winsys-wgl.c
index acee20d..fef7313 100644
--- a/cogl/winsys/cogl-winsys-wgl.c
+++ b/cogl/winsys/cogl-winsys-wgl.c
@@ -534,7 +534,7 @@ get_wgl_extensions_string (HDC dc)
      extensions isn't supported then we can at least fake it to
      support the swap control extension */
   if (_cogl_check_extension ("WGL_EXT_swap_control",
-                             (char *) glGetString (GL_EXTENSIONS)))
+                             (char *) ctx->glGetString (GL_EXTENSIONS)))
     return "WGL_EXT_swap_control";
 
   return NULL;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]