[cogl/wip/gles2-context: 2/4] examples: update foreign framebuffer at every frame



commit 9b90b83fab6b4c5cce2e332420a93e3818bc8407
Author: Tomeu Vizoso <tomeu vizoso collabora com>
Date:   Wed Dec 14 09:54:17 2011 +0100

    examples: update foreign framebuffer at every frame

 examples/cogl-gles2-context.c |   74 ++++++++++++++++++++++++-----------------
 1 files changed, 43 insertions(+), 31 deletions(-)
---
diff --git a/examples/cogl-gles2-context.c b/examples/cogl-gles2-context.c
index b3faed3..279db1c 100644
--- a/examples/cogl-gles2-context.c
+++ b/examples/cogl-gles2-context.c
@@ -7,6 +7,47 @@ CoglColor black;
 #define OFFSCREEN_WIDTH 100
 #define OFFSCREEN_HEIGHT 100
 
+CoglTexture *
+get_offscreen_texture (CoglContext *ctx)
+{
+  GError *error = NULL;
+
+  CoglGLES2Context *gles2_ctx;
+  CoglGLES2Vtable *vtable;
+  CoglTexture *offscreen_texture = NULL;
+  CoglFramebuffer *offscreen_framebuffer;
+
+  /* Prepare offscreen framebuffer */
+  gles2_ctx = cogl_gles2_context_new (ctx, &error);
+  if (!gles2_ctx) {
+      g_error ("Failed to create GLES2 context: %s\n", error->message);
+      return NULL;
+  }
+
+  vtable = cogl_gles2_context_get_vtable (gles2_ctx);
+
+  offscreen_texture = cogl_texture_new_with_size (OFFSCREEN_WIDTH, OFFSCREEN_HEIGHT,
+                                                  COGL_TEXTURE_NO_SLICING,
+                                                  COGL_PIXEL_FORMAT_ANY);
+
+  offscreen_framebuffer = cogl_offscreen_new_to_texture (offscreen_texture);
+
+  /* Clear offscreen framebuffer with green */
+  if (!cogl_framebuffer_push_gles2_context (offscreen_framebuffer,
+                                       gles2_ctx,
+                                       &error)) {
+      g_error ("Failed to push GLES2 context: %s\n", error->message);
+      return NULL;
+  }
+
+  vtable->glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
+  vtable->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+  cogl_framebuffer_pop_gles2_context (offscreen_framebuffer);
+
+  return offscreen_texture;
+}
+
 int
 main (int argc, char **argv)
 {
@@ -20,10 +61,7 @@ main (int argc, char **argv)
         {0.7, -0.7, 0x00, 0x00, 0xff, 0xff}
     };
     CoglPrimitive *triangle;
-    CoglGLES2Context *gles2_ctx;
-    CoglGLES2Vtable *vtable;
     CoglTexture *offscreen_texture;
-    CoglFramebuffer *offscreen_framebuffer;
 
     ctx = cogl_context_new (NULL, &error);
     if (!ctx) {
@@ -42,34 +80,6 @@ main (int argc, char **argv)
 
     cogl_onscreen_show (onscreen);
 
-    /* Prepare offscreen framebuffer */
-    gles2_ctx = cogl_gles2_context_new (ctx, &error);
-    if (!gles2_ctx) {
-        fprintf (stderr, "Failed to create GLES2 context: %s\n", error->message);
-        return 1;
-    }
-
-    vtable = cogl_gles2_context_get_vtable (gles2_ctx);
-
-    offscreen_texture = cogl_texture_new_with_size (OFFSCREEN_WIDTH, OFFSCREEN_HEIGHT,
-                                                    COGL_TEXTURE_NO_SLICING,
-                                                    COGL_PIXEL_FORMAT_ANY);
-
-    offscreen_framebuffer = cogl_offscreen_new_to_texture (offscreen_texture);
-
-    /* Clear offscreen framebuffer with green */
-    if (!cogl_framebuffer_push_gles2_context (offscreen_framebuffer,
-                                         gles2_ctx,
-                                         &error)) {
-        fprintf (stderr, "Failed to push GLES2 context: %s\n", error->message);
-        return 1;
-    }
-
-    vtable->glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
-    vtable->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-    cogl_framebuffer_pop_gles2_context (offscreen_framebuffer);
-
     /* Prepare onscreen primitive */
     triangle = cogl_primitive_new_p2c4 (COGL_VERTICES_MODE_TRIANGLES,
                                         3, triangle_vertices);
@@ -78,6 +88,8 @@ main (int argc, char **argv)
         cogl_push_framebuffer (fb);
         cogl_clear (&black, COGL_BUFFER_BIT_COLOR);
 
+        offscreen_texture = get_offscreen_texture (ctx);
+
         cogl_set_source_color4f (0.0f, 0.0f, 0.0f, 1.0f);
         cogl_primitive_draw (triangle);
 



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