diff --git a/cogl/cogl-gles2-context-private.h b/cogl/cogl-gles2-context-private.h index 6a654c359..7902c9413 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 7d3f9d363..ea5e1cf45 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; }