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
81 mHasColorRenderItems( false )
90 // pointer container deletes the render items
95 * Clear the render flags
103 * Set particular render flags
104 * @param[in] flags The set of flags to bitwise or with existing flags
106 void SetFlags( unsigned int flags )
108 mRenderFlags |= flags;
112 * Retrieve the render flags.
113 * @return the render flags.
115 unsigned int GetFlags() const
121 * Reset the render list for next frame
125 // we dont want to delete and re-create the render items every frame
134 * Reserve space in the render list
135 * @param size to reserve
137 void Reserve( RenderItemContainer::SizeType size )
140 mItems.Reserve( size );
144 * @return the capacity of the render list
146 RenderItemContainer::SizeType Capacity()
148 return mItems.Capacity();
152 * Get next free render item
153 * @return reference to the next available RenderItem
155 RenderItem& GetNextFreeItem()
157 // check if we have enough items, we can only be one behind at worst
158 if( mItems.Count() <= mNextFree )
160 mItems.PushBack( new RenderItem ); // Push a new empty render item
162 // get the item mNextFree points to and increase by one
163 RenderItem& item = *mItems[ mNextFree++ ];
169 * Get item at a given position in the list
171 RenderItem& GetItem( RenderItemContainer::SizeType index ) const
173 DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
174 return *mItems[ index ];
178 * Get renderer from an item in the list
180 const Renderer* GetRenderer( RenderItemContainer::SizeType index ) const
182 DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
183 return mItems[ index ]->GetRenderer();
187 * Get the number of real items
188 * Because of caching, the actual size may be bit more
189 * @return The number of items
191 RenderItemContainer::SizeType Count() const
197 * @return the number of items cached by the list
199 RenderItemContainer::SizeType GetCachedItemCount() const
201 return mItems.Count();
205 * Tells the render list to reuse the items from the cache
207 void ReuseCachedItems()
209 mNextFree = mItems.Count();
213 * Predicate to inform if the list is empty
217 return (mNextFree == 0);
222 * @param clipping on/off
223 * @param box for clipping
225 void SetClipping( bool clipping, const ClippingBox& box )
229 ClippingBox* newBox = new ClippingBox( box );
231 mClippingBox = newBox;
236 * @return true if clipping is on
238 bool IsClipping() const
240 return (NULL != mClippingBox);
244 * @return the clipping box
246 const ClippingBox& GetClippingBox() const
248 return *mClippingBox;
252 * @return the container (for sorting)
254 RenderItemContainer& GetContainer()
260 * Do some housekeeping to keep memory consumption low
262 void ReleaseUnusedItems()
264 // release any non-used RenderItems
265 if( mItems.Count() > mNextFree )
267 mItems.Resize( mNextFree );
272 * @return the source layer these renderitems originate from
274 Layer* GetSourceLayer()
280 * @param layer these renderitems originate from
282 void SetSourceLayer( Layer* layer )
284 mSourceLayer = layer;
288 * Set if the RenderList contains color RenderItems
289 * @param[in] hasColorRenderItems True if it contains color RenderItems, false otherwise
291 void SetHasColorRenderItems( bool hasColorRenderItems )
293 mHasColorRenderItems = hasColorRenderItems;
297 * Check if the RenderList contains color RenderItems
298 * @return true if the RenderList contains color RenderItems, false otherwise
300 bool HasColorRenderItems() const
302 return mHasColorRenderItems;
308 * Copy constructor and assignment operator not defined
310 RenderList( const RenderList& rhs );
311 const RenderList& operator=( const RenderList& rhs );
313 RenderItemContainer mItems; ///< Each item is a renderer and matrix pair
314 RenderItemContainer::SizeType mNextFree; ///< index for the next free item to use
316 unsigned int mRenderFlags; ///< The render flags
318 ClippingBox* mClippingBox; ///< The clipping box, in window coordinates, when clipping is enabled
319 Layer* mSourceLayer; ///< The originating layer where the renderers are from
320 bool mHasColorRenderItems : 1; ///< True if list contains color render items
323 } // namespace SceneGraph
325 } // namespace Internal
329 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H__