From f910ce2ee55b45d069febab9f78abe45bdb84872 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Sat, 31 Oct 2009 00:00:33 +0000 Subject: [PATCH] [cogl-draw-buffer] fix Cogl -> GL viewport coord conversion Before we call glViewport we need to convert Cogl viewport coordinates (where the origin is defined to be top left) to OpenGL coordinates (where the origin is defined to be bottom left) We weren't considering that offscreen rendering is always upside down and in this case Cogl coordinates == OpenGL coordinates. --- cogl/cogl-draw-buffer.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cogl/cogl-draw-buffer.c b/cogl/cogl-draw-buffer.c index 83ad3e313..2a7b75784 100644 --- a/cogl/cogl-draw-buffer.c +++ b/cogl/cogl-draw-buffer.c @@ -567,11 +567,18 @@ _cogl_draw_buffer_flush_state (CoglHandle handle, if (ctx->dirty_gl_viewport) { + int gl_viewport_y; + /* Convert the Cogl viewport y offset to an OpenGL viewport y offset - * (NB: OpenGL defines its window and viewport origins to be bottom - * left, while Cogl defines them to be top left.) */ - int gl_viewport_y = draw_buffer->height - - (draw_buffer->viewport_y + draw_buffer->viewport_height); + * NB: OpenGL defines its window and viewport origins to be bottom + * left, while Cogl defines them to be top left. + * NB: We render upside down to offscreen draw buffers so we don't + * need to convert the y offset in this case. */ + if (cogl_is_offscreen (draw_buffer)) + gl_viewport_y = draw_buffer->viewport_y; + else + gl_viewport_y = draw_buffer->height - + (draw_buffer->viewport_y + draw_buffer->viewport_height); GE (glViewport (draw_buffer->viewport_x, gl_viewport_y,