From 57bd250a71742ca9ab704fb0a5466f4b210a6db8 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Fri, 30 Oct 2009 23:57:56 +0000 Subject: [PATCH] [cogl_clip_push_window_rect] fix Cogl -> GL coordinate conversion Firstly this now uses the draw buffer height not the viewport height when we need to perform a y = height - y conversion, since (as the name suggests) we are dealing with window coordinates not viewport coordinates. Secondly this skips any conversion when the current draw buffer is an offscreen draw buffer since offscreen rendering is always forced to be upside down and in this case Cogl window coordinates == GL window coordinates. --- cogl/cogl-clip-stack.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/cogl/cogl-clip-stack.c b/cogl/cogl-clip-stack.c index cac156fa6..93900338e 100644 --- a/cogl/cogl-clip-stack.c +++ b/cogl/cogl-clip-stack.c @@ -114,6 +114,13 @@ struct _CoglClipStackEntryPath CoglPathNode path[1]; }; +/* FIXME: deprecate and replace with: + * void + * cogl_clip_push_window_rectangle (int x_offset, + * int y_offset, + * int width, + * int height); + */ void cogl_clip_push_window_rect (float x_offset, float y_offset, @@ -123,8 +130,8 @@ cogl_clip_push_window_rect (float x_offset, CoglHandle draw_buffer; CoglClipStackState *clip_state; CoglClipStack *stack; + int draw_buffer_height; CoglClipStackEntryWindowRect *entry; - float viewport_height; _COGL_GET_CONTEXT (ctx, NO_RETVAL); @@ -137,17 +144,30 @@ cogl_clip_push_window_rect (float x_offset, stack = clip_state->stacks->data; - viewport_height = _cogl_draw_buffer_get_viewport_height (draw_buffer); + draw_buffer_height = _cogl_draw_buffer_get_height (draw_buffer); entry = g_slice_new (CoglClipStackEntryWindowRect); - /* We convert from coords with (0,0) at top left to coords - * with (0,0) at bottom left. */ + /* We store the entry coordinates in OpenGL window coordinate space and so + * because Cogl defines the window origin to be top left but OpenGL defines + * it as bottom left we may need to convert the incoming coordinates. + * + * NB: Cogl forces all offscreen rendering to be done upside down so in this + * case no conversion is needed. + */ entry->type = COGL_CLIP_STACK_WINDOW_RECT; entry->x0 = x_offset; - entry->y0 = viewport_height - y_offset - height; entry->x1 = x_offset + width; - entry->y1 = viewport_height - y_offset; + if (cogl_is_offscreen (draw_buffer)) + { + entry->y0 = y_offset; + entry->y1 = y_offset + height; + } + else + { + entry->y0 = draw_buffer_height - y_offset - height; + entry->y1 = draw_buffer_height - y_offset; + } /* Store it in the stack */ stack->stack_top = g_list_prepend (stack->stack_top, entry);