[cogl/wip/rib/cogl-1.12: 126/139] cogl-gles2-context: Fix the default viewport and scissor size



commit 0cd88bd6765843cdcef806bf8ea6f3f8619e93a2
Author: Neil Roberts <neil linux intel com>
Date:   Tue Aug 7 16:15:55 2012 +0100

    cogl-gles2-context: Fix the default viewport and scissor size
    
    In GL, the default viewport and scissor should be set to the size of
    the first surface that the context is bound to. If a CoglGLES2Context
    is first used with an offscreen framebuffer then this surface will
    actually be the dummy 1x1 window which will mess up the defaults. To
    fix that, this patch makes it just always override the viewport and
    scissor the first time the context is bound to something.
    
    Reviewed-by: Robert Bragg <robert linux intel com>
    
    (cherry picked from commit 02567b3e6b64e6849b9f7c6aa2137401be7ece8d)

 cogl/cogl-gles2-context-private.h |    5 +++++
 cogl/cogl-gles2-context.c         |   21 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/cogl/cogl-gles2-context-private.h b/cogl/cogl-gles2-context-private.h
index 6a654c3..7902c94 100644
--- a/cogl/cogl-gles2-context-private.h
+++ b/cogl/cogl-gles2-context-private.h
@@ -52,6 +52,11 @@ struct _CoglGLES2Context
 
   CoglContext *context;
 
+  /* This is set to FALSE until the first time the GLES2 context is
+   * bound to something. We need to keep track of this so we can set
+   * the viewport and scissor the first time it is bound. */
+  CoglBool has_been_bound;
+
   CoglFramebuffer *read_buffer;
   CoglGLES2Offscreen *gles2_read_buffer;
   CoglFramebuffer *write_buffer;
diff --git a/cogl/cogl-gles2-context.c b/cogl/cogl-gles2-context.c
index 7d3f9d3..ea5e1cf 100644
--- a/cogl/cogl-gles2-context.c
+++ b/cogl/cogl-gles2-context.c
@@ -483,6 +483,27 @@ cogl_push_gles2_context (CoglContext *ctx,
     }
 
   current_gles2_context = gles2_ctx;
+
+  /* If this is the first time this gles2 context has been used then
+   * we'll force the viewport and scissor to the right size. GL has
+   * the semantics that the viewport and scissor default to the size
+   * of the first surface the context is used with. If the first
+   * CoglFramebuffer that this context is used with is an offscreen,
+   * then the surface from GL's point of view will be the 1x1 dummy
+   * surface so the viewport will be wrong. Therefore we just override
+   * the default viewport and scissor here */
+  if (!gles2_ctx->has_been_bound)
+    {
+      int fb_width = cogl_framebuffer_get_width (write_buffer);
+      int fb_height = cogl_framebuffer_get_height (write_buffer);
+
+      gles2_ctx->vtable->glViewport (0, 0, /* x/y */
+                                     fb_width, fb_height);
+      gles2_ctx->vtable->glScissor (0, 0, /* x/y */
+                                    fb_width, fb_height);
+      gles2_ctx->has_been_bound = TRUE;
+    }
+
   return TRUE;
 }
 



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