[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.
This commit is contained in:
Robert Bragg 2009-10-30 23:57:56 +00:00
parent 0369a1b84d
commit 149e3e168a

View File

@ -114,6 +114,13 @@ struct _CoglClipStackEntryPath
CoglPathNode path[1]; 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 void
cogl_clip_push_window_rect (float x_offset, cogl_clip_push_window_rect (float x_offset,
float y_offset, float y_offset,
@ -123,8 +130,8 @@ cogl_clip_push_window_rect (float x_offset,
CoglHandle draw_buffer; CoglHandle draw_buffer;
CoglClipStackState *clip_state; CoglClipStackState *clip_state;
CoglClipStack *stack; CoglClipStack *stack;
int draw_buffer_height;
CoglClipStackEntryWindowRect *entry; CoglClipStackEntryWindowRect *entry;
float viewport_height;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -137,17 +144,30 @@ cogl_clip_push_window_rect (float x_offset,
stack = clip_state->stacks->data; 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); entry = g_slice_new (CoglClipStackEntryWindowRect);
/* We convert from coords with (0,0) at top left to coords /* We store the entry coordinates in OpenGL window coordinate space and so
* with (0,0) at bottom left. */ * 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->type = COGL_CLIP_STACK_WINDOW_RECT;
entry->x0 = x_offset; entry->x0 = x_offset;
entry->y0 = viewport_height - y_offset - height;
entry->x1 = x_offset + width; 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 */ /* Store it in the stack */
stack->stack_top = g_list_prepend (stack->stack_top, entry); stack->stack_top = g_list_prepend (stack->stack_top, entry);