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 buffer.
59 DEPTH_TEST = 0x01, ///< If depth testing should be used
60 DEPTH_WRITE = 0x02, ///< If the depth buffer is writable
61 DEPTH_CLEAR = 0x04, ///< If the depth buffer should first be cleared
62 STENCIL_TEST = 0x08, ///< If stencil testing should be used
63 STENCIL_WRITE = 0x10, ///< If the stencil buffer is writable
64 STENCIL_CLEAR = 0x20 ///< If the stencil buffer should first be cleared
83 // pointer container deletes the render items
88 * Clear the render flags
96 * Set particular render flags
97 * @param[in] flags The set of flags to bitwise or with existing flags
99 void SetFlags( unsigned int flags )
101 mRenderFlags |= flags;
105 * Retrieve the render flags.
106 * @return the render flags.
108 unsigned int GetFlags() const
114 * Reset the render list for next frame
118 // we dont want to delete and re-create the render items every frame
127 * Reserve space in the render list
128 * @param size to reserve
130 void Reserve( RenderItemContainer::SizeType size )
133 mItems.Reserve( size );
137 * @return the capacity of the render list
139 RenderItemContainer::SizeType Capacity()
141 return mItems.Capacity();
145 * Get next free render item
146 * @return reference to the next available RenderItem
148 RenderItem& GetNextFreeItem()
150 // check if we have enough items, we can only be one behind at worst
151 if( mItems.Count() <= mNextFree )
153 mItems.PushBack( new RenderItem ); // Push a new empty render item
155 // get the item mNextFree points to and increase by one
156 RenderItem& item = *mItems[ mNextFree++ ];
162 * Get item at a given position in the list
164 RenderItem& GetItem( RenderItemContainer::SizeType index ) const
166 DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
167 return *mItems[ index ];
171 * Get renderer from an item in the list
173 const Renderer* GetRenderer( RenderItemContainer::SizeType index ) const
175 DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
176 return mItems[ index ]->GetRenderer();
180 * Get the number of real items
181 * Because of caching, the actual size may be bit more
182 * @return The number of items
184 RenderItemContainer::SizeType Count() const
190 * @return the number of items cached by the list
192 RenderItemContainer::SizeType GetCachedItemCount() const
194 return mItems.Count();
198 * Tells the render list to reuse the items from the cache
200 void ReuseCachedItems()
202 mNextFree = mItems.Count();
206 * Predicate to inform if the list is empty
210 return (mNextFree == 0);
215 * @param clipping on/off
216 * @param box for clipping
218 void SetClipping( bool clipping, const ClippingBox& box )
222 ClippingBox* newBox = new ClippingBox( box );
224 mClippingBox = newBox;
229 * @return true if clipping is on
231 bool IsClipping() const
233 return (NULL != mClippingBox);
237 * @return the clipping box
239 const ClippingBox& GetClippingBox() const
241 return *mClippingBox;
245 * @return the container (for sorting)
247 RenderItemContainer& GetContainer()
253 * Do some housekeeping to keep memory consumption low
255 void ReleaseUnusedItems()
257 // release any non-used RenderItems
258 if( mItems.Count() > mNextFree )
260 mItems.Resize( mNextFree );
265 * @return the source layer these renderitems originate from
267 Layer* GetSourceLayer()
273 * @param layer these renderitems originate from
275 void SetSourceLayer( Layer* layer )
277 mSourceLayer = layer;
283 * Copy constructor and assignment operator not defined
285 RenderList( const RenderList& rhs );
286 const RenderList& operator=( const RenderList& rhs );
288 RenderItemContainer mItems; ///< Each item is a renderer and matrix pair
289 RenderItemContainer::SizeType mNextFree; ///< index for the next free item to use
291 unsigned int mRenderFlags; ///< The render flags
293 ClippingBox* mClippingBox; ///< The clipping box, in window coordinates, when clipping is enabled
294 Layer* mSourceLayer; ///< The originating layer where the renderers are from
298 } // namespace SceneGraph
300 } // namespace Internal
304 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H__