+ context.Scissor( x, y, useScissorBox.width, useScissorBox.height );
+ }
+ }
+ }
+}
+
+inline void RenderAlgorithms::SetupClipping( const RenderItem& item,
+ Context& context,
+ bool& usedStencilBuffer,
+ uint32_t& lastClippingDepth,
+ uint32_t& lastClippingId,
+ Integration::StencilBufferAvailable stencilBufferAvailable,
+ int orientation )
+{
+ RenderMode::Type renderMode = RenderMode::AUTO;
+ const Renderer *renderer = item.mRenderer;
+ if( renderer )
+ {
+ renderMode = renderer->GetRenderMode();
+ }
+
+ // Setup the stencil using either the automatic clipping feature, or, the manual per-renderer stencil API.
+ // Note: This switch is in order of most likely value first.
+ switch( renderMode )
+ {
+ case RenderMode::AUTO:
+ {
+ // Turn the color buffer on as we always want to render this renderer, regardless of clipping hierarchy.
+ context.ColorMask( true );
+
+ // The automatic clipping feature will manage the scissor and stencil functions, only if stencil buffer is available for the latter.
+ // As both scissor and stencil clips can be nested, we may be simultaneously traversing up the scissor tree, requiring a scissor to be un-done. Whilst simultaneously adding a new stencil clip.
+ // We process both based on our current and old clipping depths for each mode.
+ // Both methods with return rapidly if there is nothing to be done for that type of clipping.
+ SetupScissorClipping( item, context, orientation );
+
+ if( stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE )
+ {
+ SetupStencilClipping( item, context, lastClippingDepth, lastClippingId );
+ }
+ break;
+ }
+
+ case RenderMode::NONE:
+ case RenderMode::COLOR:
+ {
+ // No clipping is performed for these modes.
+ // Note: We do not turn off scissor clipping as it may be used for the whole layer.
+ // The stencil buffer will not be used at all, but we only need to disable it if it's available.
+ if( stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE )
+ {
+ context.EnableStencilBuffer( false );