[Cogl] [PATCH 1/8] cogl-gles2-context: Fix the default viewport and scissor size

Robert Bragg robert at sixbynine.org
Thu Aug 9 10:25:05 PDT 2012


This looks good to land to me:

Reviewed-by: Robert Bragg <robert at linux.intel.com>

thanks,
- Robert

On Thu, Aug 9, 2012 at 5:08 PM, Neil Roberts <neil at linux.intel.com> wrote:
> 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.
> ---
>  cogl/cogl-gles2-context-private.h |  5 +++++
>  cogl/cogl-gles2-context.c         | 21 +++++++++++++++++++++
>  2 files changed, 26 insertions(+)
>
> 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;
>  }
>
> --
> 1.7.11.3.g3c3efa5
>
> _______________________________________________
> Cogl mailing list
> Cogl at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/cogl


More information about the Cogl mailing list