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/>.
24 #ifndef __COGL_CLIP_STACK_H
25 #define __COGL_CLIP_STACK_H
27 #include "cogl2-path.h"
28 #include "cogl-matrix.h"
29 #include "cogl-primitive.h"
30 #include "cogl-framebuffer.h"
32 /* The clip stack works like a GSList where only a pointer to the top
33 of the stack is stored. The empty clip stack is represented simply
34 by the NULL pointer. When an entry is added to or removed from the
35 stack the new top of the stack is returned. When an entry is pushed
36 a new clip stack entry is created which effectively takes ownership
37 of the reference on the old entry. Therefore unrefing the top entry
38 effectively loses ownership of all entries in the stack */
40 typedef struct _CoglClipStack CoglClipStack;
41 typedef struct _CoglClipStackRect CoglClipStackRect;
42 typedef struct _CoglClipStackWindowRect CoglClipStackWindowRect;
43 typedef struct _CoglClipStackPath CoglClipStackPath;
44 typedef struct _CoglClipStackPrimitive CoglClipStackPrimitive;
49 COGL_CLIP_STACK_WINDOW_RECT,
51 COGL_CLIP_STACK_PRIMITIVE
54 /* A clip stack consists a list of entries. Each entry has a reference
55 * count and a link to its parent node. The child takes a reference on
56 * the parent and the CoglClipStack holds a reference to the top of
57 * the stack. There are no links back from the parent to the
58 * children. This allows stacks that have common ancestry to share the
61 * For example, the following sequence of operations would generate
64 * CoglClipStack *stack_a = NULL;
65 * stack_a = _cogl_clip_stack_push_rectangle (stack_a, ...);
66 * stack_a = _cogl_clip_stack_push_rectangle (stack_a, ...);
67 * stack_a = _cogl_clip_stack_push_from_path (stack_a, ...);
68 * CoglClipStack *stack_b = NULL;
69 * stack_b = cogl_clip_stack_push_window_rectangle (stack_b, ...);
78 * +-----------+ +-----------+
79 * both tops hold | rect node | | rect node |
80 * a ref to the |ref count 2|--|ref count 1|
81 * same rect node +-----------+ +-----------+
94 CoglClipStackType type;
96 /* This will be null if there is no parent. If it is not null then
97 this node must be holding a reference to the parent */
98 CoglClipStack *parent;
100 /* All clip entries have a window-space bounding box which we can
101 use to calculate a scissor. The scissor limits the clip so that
102 we don't need to do a full stencil clear if the stencil buffer is
103 needed. This is stored in Cogl's coordinate space (ie, 0,0 is the
110 unsigned int ref_count;
113 struct _CoglClipStackRect
115 CoglClipStack _parent_data;
117 /* The rectangle for this clip */
123 /* If this is true then the clip for this rectangle is entirely
124 described by the scissor bounds. This implies that the rectangle
125 is screen aligned and we don't need to use the stencil buffer to
126 set the clip. We keep the entry as a rect entry rather than a
127 window rect entry so that it will be easier to detect if the
128 modelview matrix is that same as when a rectangle is added to the
129 journal. In that case we can use the original clip coordinates
130 and modify the rectangle instead. */
131 gboolean can_be_scissor;
133 /* The matrix that was current when the clip was set */
137 struct _CoglClipStackWindowRect
139 CoglClipStack _parent_data;
141 /* The window rect clip doesn't need any specific data because it
142 just adds to the scissor clip */
145 struct _CoglClipStackPath
147 CoglClipStack _parent_data;
149 /* The matrix that was current when the clip was set */
155 struct _CoglClipStackPrimitive
157 CoglClipStack _parent_data;
159 /* The matrix that was current when the clip was set */
162 CoglPrimitive *primitive;
171 _cogl_clip_stack_push_window_rectangle (CoglClipStack *stack,
178 _cogl_clip_stack_push_rectangle (CoglClipStack *stack,
183 const CoglMatrix *modelview_matrix);
186 _cogl_clip_stack_push_from_path (CoglClipStack *stack,
188 const CoglMatrix *modelview_matrix);
191 _cogl_clip_stack_push_primitive (CoglClipStack *stack,
192 CoglPrimitive *primitive,
197 const CoglMatrix *modelview_matrix);
200 _cogl_clip_stack_pop (CoglClipStack *stack);
203 _cogl_clip_stack_get_bounds (CoglClipStack *stack,
210 _cogl_clip_stack_flush (CoglClipStack *stack,
211 CoglFramebuffer *framebuffer);
214 _cogl_clip_stack_ref (CoglClipStack *stack);
217 _cogl_clip_stack_unref (CoglClipStack *stack);
219 #endif /* __COGL_CLIP_STACK_H */