1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/math/rect.h>
23 #include <dali/internal/render/common/render-item.h>
24 #include <dali/internal/common/owner-container.h>
29 typedef Rect<int> ClippingBox;
41 typedef OwnerContainer< RenderItem* > RenderItemContainer;
44 typedef OwnerContainer< RenderList* > RenderListContainer;
47 * The RenderList structure provides the renderer with a list of renderers and
48 * a set of flags to tell it what depth buffering is required.
55 * The RenderFlags describe how the objects are rendered using the depth and stencil buffer.
57 * The flags which relate to GL_DEPTH_TEST and GL_STENCIL_TEST are called
58 * DEPTH_BUFFER_ENABLED and STENCIL_BUFFER_ENABLED to avoid any confusion.
59 * E.g. if GL_DEPTH_TEST is not enabled you can't write to the depth buffer, which can cause confusion.
64 DEPTH_BUFFER_ENABLED = 1 << 0, ///< If depth buffer should be used for writing / test operations
65 DEPTH_WRITE = 1 << 1, ///< If the depth buffer is writable
66 DEPTH_CLEAR = 1 << 2, ///< If the depth buffer should first be cleared
67 STENCIL_BUFFER_ENABLED = 1 << 3, ///< If stencil buffer should be used for writing / test operation
68 STENCIL_WRITE = 1 << 4, ///< If the stencil buffer is writable
69 STENCIL_CLEAR = 1 << 5, ///< If the stencil buffer should first be cleared
89 // pointer container deletes the render items
94 * Clear the render flags
102 * Set particular render flags
103 * @param[in] flags The set of flags to bitwise or with existing flags
105 void SetFlags( unsigned int flags )
107 mRenderFlags |= flags;
111 * Retrieve the render flags.
112 * @return the render flags.
114 unsigned int GetFlags() const
120 * Reset the render list for next frame
124 // we dont want to delete and re-create the render items every frame
133 * Reserve space in the render list
134 * @param size to reserve
136 void Reserve( RenderItemContainer::SizeType size )
139 mItems.Reserve( size );
143 * @return the capacity of the render list
145 RenderItemContainer::SizeType Capacity()
147 return mItems.Capacity();
151 * Get next free render item
152 * @return reference to the next available RenderItem
154 RenderItem& GetNextFreeItem()
156 // check if we have enough items, we can only be one behind at worst
157 if( mItems.Count() <= mNextFree )
159 mItems.PushBack( new RenderItem ); // Push a new empty render item
161 // get the item mNextFree points to and increase by one
162 RenderItem& item = *mItems[ mNextFree++ ];
168 * Get item at a given position in the list
170 RenderItem& GetItem( RenderItemContainer::SizeType index ) const
172 DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
173 return *mItems[ index ];
177 * Get renderer from an item in the list
179 const Renderer* GetRenderer( RenderItemContainer::SizeType index ) const
181 DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
182 return mItems[ index ]->GetRenderer();
186 * Get the number of real items
187 * Because of caching, the actual size may be bit more
188 * @return The number of items
190 RenderItemContainer::SizeType Count() const
196 * @return the number of items cached by the list
198 RenderItemContainer::SizeType GetCachedItemCount() const
200 return mItems.Count();
204 * Tells the render list to reuse the items from the cache
206 void ReuseCachedItems()
208 mNextFree = mItems.Count();
212 * Predicate to inform if the list is empty
216 return (mNextFree == 0);
221 * @param clipping on/off
222 * @param box for clipping
224 void SetClipping( bool clipping, const ClippingBox& box )
228 ClippingBox* newBox = new ClippingBox( box );
230 mClippingBox = newBox;
235 * @return true if clipping is on
237 bool IsClipping() const
239 return (NULL != mClippingBox);
243 * @return the clipping box
245 const ClippingBox& GetClippingBox() const
247 return *mClippingBox;
251 * @return the container (for sorting)
253 RenderItemContainer& GetContainer()
259 * Do some housekeeping to keep memory consumption low
261 void ReleaseUnusedItems()
263 // release any non-used RenderItems
264 if( mItems.Count() > mNextFree )
266 mItems.Resize( mNextFree );
271 * @return the source layer these renderitems originate from
273 Layer* GetSourceLayer()
279 * @param layer these renderitems originate from
281 void SetSourceLayer( Layer* layer )
283 mSourceLayer = layer;
289 * Copy constructor and assignment operator not defined
291 RenderList( const RenderList& rhs );
292 const RenderList& operator=( const RenderList& rhs );
294 RenderItemContainer mItems; ///< Each item is a renderer and matrix pair
295 RenderItemContainer::SizeType mNextFree; ///< index for the next free item to use
297 unsigned int mRenderFlags; ///< The render flags
299 ClippingBox* mClippingBox; ///< The clipping box, in window coordinates, when clipping is enabled
300 Layer* mSourceLayer; ///< The originating layer where the renderers are from
304 } // namespace SceneGraph
306 } // namespace Internal
310 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H__