4 * An object oriented GL/GLES Abstraction/Utility Layer
6 * Copyright (C) 2007,2008,2009,2010 Intel Corporation.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
33 #include "cogl-clip-stack.h"
34 #include "cogl-clip-state-private.h"
35 #include "cogl-context-private.h"
36 #include "cogl-internal.h"
37 #include "cogl-framebuffer-private.h"
38 #include "cogl-journal-private.h"
39 #include "cogl-util.h"
40 #include "cogl-matrix-private.h"
41 #include "cogl-clip-state.h"
42 #include "cogl1-context.h"
45 cogl_clip_push_window_rectangle (int x_offset,
50 cogl_framebuffer_push_scissor_clip (cogl_get_draw_framebuffer (),
51 x_offset, y_offset, width, height);
54 /* XXX: This is deprecated API */
56 cogl_clip_push_window_rect (float x_offset,
61 cogl_clip_push_window_rectangle (x_offset, y_offset, width, height);
65 cogl_clip_push_rectangle (float x_1,
70 cogl_framebuffer_push_rectangle_clip (cogl_get_draw_framebuffer (),
74 /* XXX: Deprecated API */
76 cogl_clip_push (float x_offset,
81 cogl_clip_push_rectangle (x_offset,
88 cogl_clip_push_from_path_preserve (void)
90 _COGL_GET_CONTEXT (ctx, NO_RETVAL);
91 cogl_framebuffer_push_path_clip (cogl_get_draw_framebuffer (),
95 #undef cogl_clip_push_from_path
97 cogl_clip_push_from_path (void)
99 _COGL_GET_CONTEXT (ctx, NO_RETVAL);
101 cogl_clip_push_from_path_preserve ();
103 cogl_object_unref (ctx->current_path);
104 ctx->current_path = cogl2_path_new ();
108 cogl_clip_push_primitive (CoglPrimitive *primitive,
114 cogl_framebuffer_push_primitive_clip (cogl_get_draw_framebuffer (),
125 cogl_framebuffer_pop_clip (cogl_get_draw_framebuffer ());
129 cogl_clip_stack_save (void)
131 _cogl_framebuffer_save_clip_stack (cogl_get_draw_framebuffer ());
135 cogl_clip_stack_restore (void)
137 _cogl_framebuffer_restore_clip_stack (cogl_get_draw_framebuffer ());
140 /* XXX: This should never have been made public API! */
142 cogl_clip_ensure (void)
146 * This API shouldn't be used by anyone and the documented semantics
147 * are basically vague enough that we can get away with doing
153 _cogl_clip_state_init (CoglClipState *clip_state)
155 _COGL_GET_CONTEXT (ctx, NO_RETVAL);
157 clip_state->stacks = NULL;
159 /* Add an intial stack */
160 _cogl_clip_state_save_clip_stack (clip_state);
164 _cogl_clip_state_destroy (CoglClipState *clip_state)
166 /* Destroy all of the stacks */
167 while (clip_state->stacks)
168 _cogl_clip_state_restore_clip_stack (clip_state);
172 _cogl_clip_state_get_stack (CoglClipState *clip_state)
174 return clip_state->stacks->data;
178 _cogl_clip_state_set_stack (CoglClipState *clip_state,
179 CoglClipStack *stack)
181 /* Replace the top of the stack of stacks */
182 _cogl_clip_stack_ref (stack);
183 _cogl_clip_stack_unref (clip_state->stacks->data);
184 clip_state->stacks->data = stack;
188 _cogl_clip_state_save_clip_stack (CoglClipState *clip_state)
190 clip_state->stacks = g_slist_prepend (clip_state->stacks, NULL);
194 _cogl_clip_state_restore_clip_stack (CoglClipState *clip_state)
198 _COGL_RETURN_IF_FAIL (clip_state->stacks != NULL);
200 stack = clip_state->stacks->data;
202 _cogl_clip_stack_unref (stack);
204 /* Revert to an old stack */
205 clip_state->stacks = g_slist_delete_link (clip_state->stacks,