+ * @brief This method sets up the stencil and color buffer based on the current Renderers flags.
+ * @param[in] item The current RenderItem about to be rendered
+ * @param[in] context The context
+ * @param[in/out] usedStencilBuffer True if the stencil buffer has been used so far within this RenderList
+ * @param[in] stencilManagedByDrawMode True if the stencil and color buffer is being managed by DrawMode::STENCIL
+ */
+inline void SetupPerRendererFlags( const RenderItem& item, Context& context, bool& usedStencilBuffer, bool stencilManagedByDrawMode )
+{
+ // DrawMode::STENCIL is deprecated, however to support it we must not set
+ // flags based on the renderer properties if it is in use.
+ if( stencilManagedByDrawMode )
+ {
+ return;
+ }
+
+ // Setup the color buffer based on the renderers properties.
+ Renderer *renderer = item.mRenderer;
+ RenderMode::Type renderMode = renderer->GetRenderMode();
+ const bool writeToColorBuffer = ( renderMode == RenderMode::AUTO ) || ( renderMode == RenderMode::COLOR ) || ( renderMode == RenderMode::COLOR_STENCIL );
+ context.ColorMask( writeToColorBuffer );
+
+ // If the stencil buffer is disabled for this renderer, exit now to save unnecessary value setting.
+ if( ( renderMode != RenderMode::STENCIL ) && ( renderMode != RenderMode::COLOR_STENCIL ) )
+ {
+ // No per-renderer stencil setup, exit.
+ context.EnableStencilBuffer( false );
+ return;
+ }
+
+ // At this point, the stencil buffer is enabled.
+ context.EnableStencilBuffer( true );
+
+ // If this is the first use of the stencil buffer within this RenderList, clear it now.
+ // This avoids unnecessary clears.
+ if( !usedStencilBuffer )
+ {
+ context.Clear( GL_STENCIL_BUFFER_BIT, Context::CHECK_CACHED_VALUES );
+ usedStencilBuffer = true;
+ }
+
+ // Setup the stencil buffer based on the renderers properties.
+ context.StencilFunc( DaliStencilFunctionToGL[ renderer->GetStencilFunction() ],
+ renderer->GetStencilFunctionReference(),
+ renderer->GetStencilFunctionMask() );
+ context.StencilOp( DaliStencilOperationToGL[ renderer->GetStencilOperationOnFail() ],
+ DaliStencilOperationToGL[ renderer->GetStencilOperationOnZFail() ],
+ DaliStencilOperationToGL[ renderer->GetStencilOperationOnZPass() ] );
+ context.StencilMask( renderer->GetStencilMask() );
+}
+
+/**