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/devel-api/common/owner-container.h>
24 #include <dali/internal/render/common/render-item.h>
29 typedef Rect<int> ClippingBox;
46 typedef OwnerContainer< RenderItem* > RenderItemContainer;
49 typedef OwnerContainer< RenderList* > RenderListContainer;
52 * The RenderList structure provides the renderer with a list of renderers and
53 * a set of flags to tell it what depth buffering is required.
60 * The RenderFlags describe how the objects are rendered using the depth and stencil buffer.
62 * The flags which relate to GL_DEPTH_TEST and GL_STENCIL_TEST are called
63 * DEPTH_BUFFER_ENABLED and STENCIL_BUFFER_ENABLED to avoid any confusion.
64 * E.g. if GL_DEPTH_TEST is not enabled you can't write to the depth buffer, which can cause confusion.
69 DEPTH_BUFFER_ENABLED = 1 << 0, ///< If depth buffer should be used for writing / test operations
70 DEPTH_WRITE = 1 << 1, ///< If the depth buffer is writable
71 DEPTH_CLEAR = 1 << 2, ///< If the depth buffer should first be cleared
72 STENCIL_BUFFER_ENABLED = 1 << 3, ///< If stencil buffer should be used for writing / test operation
73 STENCIL_WRITE = 1 << 4, ///< If the stencil buffer is writable
74 STENCIL_CLEAR = 1 << 5, ///< If the stencil buffer should first be cleared
86 mHasColorRenderItems( false )
95 // pointer container deletes the render items
100 * Clear the render flags
108 * Set particular render flags
109 * @param[in] flags The set of flags to bitwise or with existing flags
111 void SetFlags( unsigned int flags )
113 mRenderFlags |= flags;
117 * Retrieve the render flags.
118 * @return the render flags.
120 unsigned int GetFlags() const
126 * Reset the render list for next frame
130 // we dont want to delete and re-create the render items every frame
139 * Reserve space in the render list
140 * @param size to reserve
142 void Reserve( RenderItemContainer::SizeType size )
145 mItems.Reserve( size );
149 * @return the capacity of the render list
151 RenderItemContainer::SizeType Capacity()
153 return mItems.Capacity();
157 * Get next free render item
158 * @return reference to the next available RenderItem
160 RenderItem& GetNextFreeItem()
162 // check if we have enough items, we can only be one behind at worst
163 if( mItems.Count() <= mNextFree )
165 mItems.PushBack( new RenderItem ); // Push a new empty render item
167 // get the item mNextFree points to and increase by one
168 RenderItem& item = *mItems[ mNextFree++ ];
174 * Get item at a given position in the list
176 RenderItem& GetItem( RenderItemContainer::SizeType index ) const
178 DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
179 return *mItems[ index ];
183 * Get renderer from an item in the list
185 const Render::Renderer& GetRenderer( RenderItemContainer::SizeType index ) const
187 DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
188 return mItems[ index ]->GetRenderer();
192 * Get the number of real items
193 * Because of caching, the actual size may be bit more
194 * @return The number of items
196 RenderItemContainer::SizeType Count() const
202 * @return the number of items cached by the list
204 RenderItemContainer::SizeType GetCachedItemCount() const
206 return mItems.Count();
210 * Tells the render list to reuse the items from the cache
212 void ReuseCachedItems()
214 mNextFree = mItems.Count();
218 * Predicate to inform if the list is empty
222 return (mNextFree == 0);
227 * @param clipping on/off
228 * @param box for clipping
230 void SetClipping( bool clipping, const ClippingBox& box )
234 ClippingBox* newBox = new ClippingBox( box );
236 mClippingBox = newBox;
241 * @return true if clipping is on
243 bool IsClipping() const
245 return (NULL != mClippingBox);
249 * @return the clipping box
251 const ClippingBox& GetClippingBox() const
253 return *mClippingBox;
257 * @return the container (for sorting)
259 RenderItemContainer& GetContainer()
265 * Do some housekeeping to keep memory consumption low
267 void ReleaseUnusedItems()
269 // release any non-used RenderItems
270 if( mItems.Count() > mNextFree )
272 mItems.Resize( mNextFree );
277 * @return the source layer these renderitems originate from
279 Layer* GetSourceLayer()
285 * @param layer these renderitems originate from
287 void SetSourceLayer( Layer* layer )
289 mSourceLayer = layer;
293 * Set if the RenderList contains color RenderItems
294 * @param[in] hasColorRenderItems True if it contains color RenderItems, false otherwise
296 void SetHasColorRenderItems( bool hasColorRenderItems )
298 mHasColorRenderItems = hasColorRenderItems;
302 * Check if the RenderList contains color RenderItems
303 * @return true if the RenderList contains color RenderItems, false otherwise
305 bool HasColorRenderItems() const
307 return mHasColorRenderItems;
313 * Copy constructor and assignment operator not defined
315 RenderList( const RenderList& rhs );
316 const RenderList& operator=( const RenderList& rhs );
318 RenderItemContainer mItems; ///< Each item is a renderer and matrix pair
319 RenderItemContainer::SizeType mNextFree; ///< index for the next free item to use
321 unsigned int mRenderFlags; ///< The render flags
323 ClippingBox* mClippingBox; ///< The clipping box, in window coordinates, when clipping is enabled
324 Layer* mSourceLayer; ///< The originating layer where the renderers are from
325 bool mHasColorRenderItems : 1; ///< True if list contains color render items
328 } // namespace SceneGraph
330 } // namespace Internal
334 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H__