diff --git a/cogl/cogl/cogl-framebuffer-private.h b/cogl/cogl/cogl-framebuffer-private.h index 0c9af2d92..f4edadd89 100644 --- a/cogl/cogl/cogl-framebuffer-private.h +++ b/cogl/cogl/cogl-framebuffer-private.h @@ -310,4 +310,14 @@ cogl_framebuffer_get_journal (CoglFramebuffer *framebuffer); CoglFramebufferDriver * cogl_framebuffer_get_driver (CoglFramebuffer *framebuffer); +/** + * cogl_framebuffer_is_y_flipped: + * @framebuffer: a #CoglFramebuffer + * + * Returns %TRUE if the Y coordinate 0 means the bottom of the framebuffer, and + * %FALSE if the Y coordinate means the top. + */ +gboolean +cogl_framebuffer_is_y_flipped (CoglFramebuffer *framebuffer); + #endif /* __COGL_FRAMEBUFFER_PRIVATE_H */ diff --git a/cogl/cogl/cogl-framebuffer.c b/cogl/cogl/cogl-framebuffer.c index 41194829c..16324a0ad 100644 --- a/cogl/cogl/cogl-framebuffer.c +++ b/cogl/cogl/cogl-framebuffer.c @@ -1577,7 +1577,7 @@ cogl_framebuffer_read_pixels (CoglFramebuffer *framebuffer, return ret; } -static gboolean +gboolean cogl_framebuffer_is_y_flipped (CoglFramebuffer *framebuffer) { return COGL_FRAMEBUFFER_GET_CLASS (framebuffer)->is_y_flipped (framebuffer); diff --git a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c index 6e807fa71..de5ed30d9 100644 --- a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c +++ b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c @@ -77,9 +77,8 @@ cogl_gl_framebuffer_flush_viewport_state (CoglGlFramebuffer *gl_framebuffer) /* 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. - * NB: We render upside down to offscreen framebuffers so we don't - * need to convert the y offset in this case. */ - if (COGL_IS_OFFSCREEN (framebuffer)) + */ + if (cogl_framebuffer_is_y_flipped (framebuffer)) gl_viewport_y = viewport_y; else gl_viewport_y = @@ -441,12 +440,9 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver, COGL_FRAMEBUFFER_STATE_BIND); /* The y coordinate should be given in OpenGL's coordinate system - * so 0 is the bottom row - * - * NB: all offscreen rendering is done upside down so no conversion - * is necissary in this case. + * so 0 is the bottom row. */ - if (!COGL_IS_OFFSCREEN (framebuffer)) + if (!cogl_framebuffer_is_y_flipped (framebuffer)) y = framebuffer_height - y - height; required_format = ctx->driver_vtable->pixel_format_to_gl (ctx, @@ -455,11 +451,9 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver, &gl_format, &gl_type); - /* NB: All offscreen rendering is done upside down so there is no need - * to flip in this case... */ if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_MESA_PACK_INVERT) && (source & COGL_READ_PIXELS_NO_FLIP) == 0 && - !COGL_IS_OFFSCREEN (framebuffer)) + !cogl_framebuffer_is_y_flipped (framebuffer)) { if (ctx->driver == COGL_DRIVER_GLES2) gl_pack_enum = GL_PACK_REVERSE_ROW_ORDER_ANGLE; @@ -614,9 +608,7 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver, goto EXIT; } - /* NB: All offscreen rendering is done upside down so there is no need - * to flip in this case... */ - if (!COGL_IS_OFFSCREEN (framebuffer) && + if (!cogl_framebuffer_is_y_flipped (framebuffer) && (source & COGL_READ_PIXELS_NO_FLIP) == 0 && !pack_invert_set) {