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;
44 typedef OwnerContainer< RenderItem* > RenderItemContainer;
47 typedef OwnerContainer< RenderList* > RenderListContainer;
50 * The RenderList structure provides the renderer with a list of renderers and
51 * a set of flags to tell it what depth buffering is required.
58 * The RenderFlags describe how the objects are rendered using the depth and stencil buffer.
60 * The flags which relate to GL_DEPTH_TEST and GL_STENCIL_TEST are called
61 * DEPTH_BUFFER_ENABLED and STENCIL_BUFFER_ENABLED to avoid any confusion.
62 * E.g. if GL_DEPTH_TEST is not enabled you can't write to the depth buffer, which can cause confusion.
67 DEPTH_BUFFER_ENABLED = 1 << 0, ///< If depth buffer should be used for writing / test operations
68 DEPTH_WRITE = 1 << 1, ///< If the depth buffer is writable
69 DEPTH_CLEAR = 1 << 2, ///< If the depth buffer should first be cleared
70 STENCIL_BUFFER_ENABLED = 1 << 3, ///< If stencil buffer should be used for writing / test operation
71 STENCIL_WRITE = 1 << 4, ///< If the stencil buffer is writable
72 STENCIL_CLEAR = 1 << 5, ///< If the stencil buffer should first be cleared
84 mHasColorRenderItems( false )
93 // pointer container deletes the render items
98 * Clear the render flags
106 * Set particular render flags
107 * @param[in] flags The set of flags to bitwise or with existing flags
109 void SetFlags( unsigned int flags )
111 mRenderFlags |= flags;
115 * Retrieve the render flags.
116 * @return the render flags.
118 unsigned int GetFlags() const
124 * Reset the render list for next frame
128 // we dont want to delete and re-create the render items every frame
137 * Reserve space in the render list
138 * @param size to reserve
140 void Reserve( RenderItemContainer::SizeType size )
143 mItems.Reserve( size );
147 * @return the capacity of the render list
149 RenderItemContainer::SizeType Capacity()
151 return mItems.Capacity();
155 * Get next free render item
156 * @return reference to the next available RenderItem
158 RenderItem& GetNextFreeItem()
160 // check if we have enough items, we can only be one behind at worst
161 if( mItems.Count() <= mNextFree )
163 mItems.PushBack( RenderItem::New() ); // Push a new empty render item
165 // get the item mNextFree points to and increase by one
166 RenderItem& item = *mItems[ mNextFree++ ];
171 * Get item at a given position in the list
173 RenderItem& GetItem( RenderItemContainer::SizeType index ) const
175 DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
176 return *mItems[ index ];
180 * Get renderer from an item in the list
182 const Render::Renderer& GetRenderer( RenderItemContainer::SizeType index ) const
184 DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
185 return *mItems[ index ]->mRenderer;
189 * Get the number of real items
190 * Because of caching, the actual size may be bit more
191 * @return The number of items
193 RenderItemContainer::SizeType Count() const
199 * @return the number of items cached by the list
201 RenderItemContainer::SizeType GetCachedItemCount() const
203 return mItems.Count();
207 * Tells the render list to reuse the items from the cache
209 void ReuseCachedItems()
211 mNextFree = mItems.Count();
215 * Predicate to inform if the list is empty
219 return (mNextFree == 0);
224 * @param clipping on/off
225 * @param box for clipping
227 void SetClipping( bool clipping, const ClippingBox& box )
231 ClippingBox* newBox = new ClippingBox( box );
233 mClippingBox = newBox;
238 * @return true if clipping is on
240 bool IsClipping() const
242 return (NULL != mClippingBox);
246 * @return the clipping box
248 const ClippingBox& GetClippingBox() const
250 return *mClippingBox;
254 * @return the container (for sorting)
256 RenderItemContainer& GetContainer()
262 * Do some housekeeping to keep memory consumption low
264 void ReleaseUnusedItems()
266 // release any non-used RenderItems
267 if( mItems.Count() > mNextFree )
269 mItems.Resize( mNextFree );
274 * @return the source layer these renderitems originate from
276 Layer* GetSourceLayer()
282 * @param layer these renderitems originate from
284 void SetSourceLayer( Layer* layer )
286 mSourceLayer = layer;
290 * Set if the RenderList contains color RenderItems
291 * @param[in] hasColorRenderItems True if it contains color RenderItems, false otherwise
293 void SetHasColorRenderItems( bool hasColorRenderItems )
295 mHasColorRenderItems = hasColorRenderItems;
299 * Check if the RenderList contains color RenderItems
300 * @return true if the RenderList contains color RenderItems, false otherwise
302 bool HasColorRenderItems() const
304 return mHasColorRenderItems;
310 * Copy constructor and assignment operator not defined
312 RenderList( const RenderList& rhs );
313 const RenderList& operator=( const RenderList& rhs );
315 RenderItemContainer mItems; ///< Each item is a renderer and matrix pair
316 RenderItemContainer::SizeType mNextFree; ///< index for the next free item to use
318 unsigned int mRenderFlags; ///< The render flags
320 ClippingBox* mClippingBox; ///< The clipping box, in window coordinates, when clipping is enabled
321 Layer* mSourceLayer; ///< The originating layer where the renderers are from
322 bool mHasColorRenderItems : 1; ///< True if list contains color render items
325 } // namespace SceneGraph
327 } // namespace Internal
331 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_LIST_H__