Disable certain GL calls when depth and/or stencil buffers are not available 60/159560/3
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 9 Nov 2017 14:51:01 +0000 (14:51 +0000)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 17 Nov 2017 16:04:33 +0000 (16:04 +0000)
Change-Id: Ibe949280e963e3ffbbe46d99499b4415c4b86ec0

12 files changed:
automated-tests/src/dali/dali-test-suite-utils/test-application.cpp
dali/integration-api/CMakeLists.txt
dali/integration-api/core-enumerations.h [new file with mode: 0644]
dali/integration-api/core.cpp
dali/integration-api/core.h
dali/integration-api/file.list
dali/internal/common/core-impl.cpp
dali/internal/common/core-impl.h
dali/internal/render/common/render-algorithms.cpp
dali/internal/render/common/render-algorithms.h
dali/internal/render/common/render-manager.cpp
dali/internal/render/common/render-manager.h

index 54a69bb..a247f7d 100644 (file)
@@ -68,7 +68,9 @@ void TestApplication::Initialize()
                                         mGlSyncAbstraction,
                                         mGestureManager,
                                         mDataRetentionPolicy,
-                                        false );
+                                        Integration::RenderToFrameBuffer::FALSE,
+                                        Integration::DepthBufferAvailable::TRUE,
+                                        Integration::StencilBufferAvailable::TRUE );
 
   mCore->ContextCreated();
   mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
index 07ae15d..8beedf4 100644 (file)
@@ -25,6 +25,7 @@ SET(SOURCES ${SOURCES}
 
 SET(INTEGRATION_API_HEADERS
   ${CMAKE_CURRENT_SOURCE_DIR}/core.h
+  ${CMAKE_CURRENT_SOURCE_DIR}/core-enumerations.h
   ${CMAKE_CURRENT_SOURCE_DIR}/context-notifier.h
   ${CMAKE_CURRENT_SOURCE_DIR}/debug.h
   ${CMAKE_CURRENT_SOURCE_DIR}/profiling.h
diff --git a/dali/integration-api/core-enumerations.h b/dali/integration-api/core-enumerations.h
new file mode 100644 (file)
index 0000000..684be03
--- /dev/null
@@ -0,0 +1,64 @@
+#ifndef DALI_INTEGRATION_CORE_ENUMERATIONS_H
+#define DALI_INTEGRATION_CORE_ENUMERATIONS_H
+
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/common/view-mode.h>
+#include <dali/integration-api/context-notifier.h>
+#include <dali/integration-api/resource-policies.h>
+
+namespace Dali
+{
+
+namespace Integration
+{
+
+/**
+ * @brief Enumerations to specify whether we should render to the frame-buffer.
+ */
+enum class RenderToFrameBuffer
+{
+  FALSE = 0,
+  TRUE
+};
+
+/**
+ * @brief Enumerations to specify whether the depth buffer is available.
+ */
+enum class DepthBufferAvailable
+{
+  FALSE = 0,
+  TRUE
+};
+
+/**
+ * @brief Enumerations to specify whether the stencil buffer is available.
+ */
+enum class StencilBufferAvailable
+{
+  FALSE = 0,
+  TRUE
+};
+
+} // namespace Integration
+
+} // namespace Dali
+
+#endif // DALI_INTEGRATION_CORE_ENUMERATIONS_H
index dbe71ec..41dfa0d 100644 (file)
@@ -36,7 +36,9 @@ Core* Core::New( RenderController& renderController,
                  GlSyncAbstraction& glSyncAbstraction,
                  GestureManager& gestureManager,
                  ResourcePolicy::DataRetention policy,
-                 bool renderToFboEnabled )
+                 RenderToFrameBuffer renderToFboEnabled,
+                 DepthBufferAvailable depthBufferAvailable,
+                 StencilBufferAvailable stencilBufferAvailable )
 {
   Core* instance = new Core;
   instance->mImpl = new Internal::Core( renderController,
@@ -45,7 +47,9 @@ Core* Core::New( RenderController& renderController,
                                         glSyncAbstraction,
                                         gestureManager,
                                         policy,
-                                        renderToFboEnabled );
+                                        renderToFboEnabled,
+                                        depthBufferAvailable,
+                                        stencilBufferAvailable );
 
   return instance;
 }
index 6d44715..7db841a 100644 (file)
  *
  */
 
-// EXTERNAL INCLUDES
+// INTERNAL INCLUDES
 #include <dali/public-api/common/dali-common.h>
 #include <dali/public-api/common/view-mode.h>
 #include <dali/integration-api/context-notifier.h>
+#include <dali/integration-api/core-enumerations.h>
 #include <dali/integration-api/resource-policies.h>
 
 namespace Dali
@@ -217,6 +218,8 @@ public:
    * and platform support. Dali should honour this policy when deciding to discard
    * intermediate resource data.
    * @param[in] renderToFboEnabled Whether rendering into the Frame Buffer Object is enabled.
+   * @param[in] depthBufferAvailable Whether the depth buffer is available
+   * @param[in] stencilBufferAvailable Whether the stencil buffer is available
    * @return A newly allocated Core.
    */
   static Core* New( RenderController& renderController,
@@ -225,7 +228,9 @@ public:
                     GlSyncAbstraction& glSyncAbstraction,
                     GestureManager& gestureManager,
                     ResourcePolicy::DataRetention policy,
-                    bool renderToFboEnabled );
+                    RenderToFrameBuffer renderToFboEnabled,
+                    DepthBufferAvailable depthBufferAvailable,
+                    StencilBufferAvailable stencilBufferAvailable );
 
   /**
    * Non-virtual destructor. Core is not intended as a base class.
index afcc494..3337f92 100644 (file)
@@ -24,6 +24,7 @@ platform_abstraction_src_files = \
 
 platform_abstraction_header_files = \
    $(platform_abstraction_src_dir)/core.h \
+   $(platform_abstraction_src_dir)/core-enumerations.h \
    $(platform_abstraction_src_dir)/context-notifier.h \
    $(platform_abstraction_src_dir)/debug.h \
    $(platform_abstraction_src_dir)/profiling.h \
index 873dbf5..7637a27 100644 (file)
@@ -84,7 +84,9 @@ Core::Core( RenderController& renderController,
             GlSyncAbstraction& glSyncAbstraction,
             GestureManager& gestureManager,
             ResourcePolicy::DataRetention dataRetentionPolicy,
-            bool renderToFboEnabled )
+            Integration::RenderToFrameBuffer renderToFboEnabled,
+            Integration::DepthBufferAvailable depthBufferAvailable,
+            Integration::StencilBufferAvailable stencilBufferAvailable )
 : mRenderController( renderController ),
   mPlatform(platform),
   mProcessingEvent(false)
@@ -103,7 +105,7 @@ Core::Core( RenderController& renderController,
 
   mRenderTaskProcessor = new SceneGraph::RenderTaskProcessor();
 
-  mRenderManager = RenderManager::New( glAbstraction, glSyncAbstraction );
+  mRenderManager = RenderManager::New( glAbstraction, glSyncAbstraction, depthBufferAvailable, stencilBufferAvailable );
 
   RenderQueue& renderQueue = mRenderManager->GetRenderQueue();
 
@@ -125,7 +127,7 @@ Core::Core( RenderController& renderController,
   // This must be called after stage is created but before stage initialization
   mRelayoutController = IntrusivePtr< RelayoutController >( new RelayoutController( mRenderController ) );
 
-  mStage->Initialize( renderToFboEnabled );
+  mStage->Initialize( renderToFboEnabled == Integration::RenderToFrameBuffer::TRUE );
 
   mGestureEventProcessor = new GestureEventProcessor( *mStage, *mUpdateManager, gestureManager, mRenderController );
   mEventProcessor = new EventProcessor( *mStage, *mNotificationManager, *mGestureEventProcessor );
index 2a73f5a..0e745d7 100644 (file)
@@ -21,6 +21,7 @@
 // INTERNAL INCLUDES
 #include <dali/public-api/object/ref-object.h>
 #include <dali/integration-api/context-notifier.h>
+#include <dali/integration-api/core-enumerations.h>
 #include <dali/internal/common/owner-pointer.h>
 #include <dali/internal/event/animation/animation-playlist-declarations.h>
 #include <dali/internal/event/common/stage-def.h>
@@ -80,7 +81,9 @@ public:
         Integration::GlSyncAbstraction& glSyncAbstraction,
         Integration::GestureManager& gestureManager,
         ResourcePolicy::DataRetention dataRetentionPolicy,
-        bool renderToFboEnabled );
+        Integration::RenderToFrameBuffer renderToFboEnabled,
+        Integration::DepthBufferAvailable depthBufferAvailable,
+        Integration::StencilBufferAvailable stencilBufferAvailable );
 
   /**
    * Destructor
index 7c5063f..d262224 100644 (file)
@@ -296,7 +296,12 @@ inline void RenderAlgorithms::SetupScissorClipping( const RenderItem& item, Cont
   }
 }
 
-inline void RenderAlgorithms::SetupClipping( const RenderItem& item, Context& context, bool& usedStencilBuffer, uint32_t& lastClippingDepth, uint32_t& lastClippingId )
+inline void RenderAlgorithms::SetupClipping( const RenderItem& item,
+                                             Context& context,
+                                             bool& usedStencilBuffer,
+                                             uint32_t& lastClippingDepth,
+                                             uint32_t& lastClippingId,
+                                             Integration::StencilBufferAvailable stencilBufferAvailable )
 {
   RenderMode::Type renderMode = RenderMode::AUTO;
   const Renderer *renderer = item.mRenderer;
@@ -314,12 +319,16 @@ inline void RenderAlgorithms::SetupClipping( const RenderItem& item, Context& co
       // 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.
+      // 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 );
-      SetupStencilClipping( item, context, lastClippingDepth, lastClippingId );
+
+      if( stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE )
+      {
+        SetupStencilClipping( item, context, lastClippingDepth, lastClippingId );
+      }
       break;
     }
 
@@ -328,8 +337,11 @@ inline void RenderAlgorithms::SetupClipping( const RenderItem& item, Context& co
     {
       // 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.
-      context.EnableStencilBuffer( false );
+      // 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 );
+      }
 
       // Setup the color buffer based on the RenderMode.
       context.ColorMask( renderMode == RenderMode::COLOR );
@@ -339,29 +351,32 @@ inline void RenderAlgorithms::SetupClipping( const RenderItem& item, Context& co
     case RenderMode::STENCIL:
     case RenderMode::COLOR_STENCIL:
     {
-      // We are using the low-level Renderer Stencil API.
-      // The stencil buffer must be enabled for every renderer with stencil mode on, as renderers in between can disable it.
-      // Note: As the command state is cached, it is only sent when needed.
-      context.EnableStencilBuffer( true );
-
-      // Setup the color buffer based on the RenderMode.
-      context.ColorMask( renderMode == RenderMode::COLOR_STENCIL );
-
-      // If this is the first use of the stencil buffer within this RenderList, clear it (this avoids unnecessary clears).
-      if( !usedStencilBuffer )
+      if( stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE )
       {
-        context.Clear( GL_STENCIL_BUFFER_BIT, Context::CHECK_CACHED_VALUES );
-        usedStencilBuffer = true;
+        // We are using the low-level Renderer Stencil API.
+        // The stencil buffer must be enabled for every renderer with stencil mode on, as renderers in between can disable it.
+        // Note: As the command state is cached, it is only sent when needed.
+        context.EnableStencilBuffer( true );
+
+        // Setup the color buffer based on the RenderMode.
+        context.ColorMask( renderMode == RenderMode::COLOR_STENCIL );
+
+        // If this is the first use of the stencil buffer within this RenderList, clear it (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() );
       }
-
-      // 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() );
       break;
     }
   }
@@ -371,13 +386,17 @@ inline void RenderAlgorithms::ProcessRenderList( const RenderList& renderList,
                                                  Context& context,
                                                  BufferIndex bufferIndex,
                                                  const Matrix& viewMatrix,
-                                                 const Matrix& projectionMatrix )
+                                                 const Matrix& projectionMatrix,
+                                                 Integration::DepthBufferAvailable depthBufferAvailable,
+                                                 Integration::StencilBufferAvailable stencilBufferAvailable )
 {
   DALI_PRINT_RENDER_LIST( renderList );
 
   // Note: The depth buffer is enabled or disabled on a per-renderer basis.
   // Here we pre-calculate the value to use if these modes are set to AUTO.
-  const bool autoDepthTestMode( !( renderList.GetSourceLayer()->IsDepthTestDisabled() ) && renderList.HasColorRenderItems() );
+  const bool autoDepthTestMode(  ( depthBufferAvailable == Integration::DepthBufferAvailable::TRUE ) &&
+                                !( renderList.GetSourceLayer()->IsDepthTestDisabled() ) &&
+                                 renderList.HasColorRenderItems() );
   const std::size_t count = renderList.Count();
   uint32_t lastClippingDepth( 0u );
   uint32_t lastClippingId( 0u );
@@ -411,16 +430,19 @@ inline void RenderAlgorithms::ProcessRenderList( const RenderList& renderList,
 
     // Set up clipping based on both the Renderer and Actor APIs.
     // The Renderer API will be used if specified. If AUTO, the Actors automatic clipping feature will be used.
-    SetupClipping( item, context, usedStencilBuffer, lastClippingDepth, lastClippingId );
+    SetupClipping( item, context, usedStencilBuffer, lastClippingDepth, lastClippingId, stencilBufferAvailable );
 
     if( DALI_LIKELY( item.mRenderer ) )
     {
-      // Set up the depth buffer based on per-renderer flags.
+      // Set up the depth buffer based on per-renderer flags if depth buffer is available
       // If the per renderer flags are set to "ON" or "OFF", they will always override any Layer depth mode or
       // draw-mode state, such as Overlays.
       // If the flags are set to "AUTO", the behavior then depends on the type of renderer. Overlay Renderers will always
       // disable depth testing and writing. Color Renderers will enable them if the Layer does.
-      SetupDepthBuffer( item, context, autoDepthTestMode, firstDepthBufferUse );
+      if( depthBufferAvailable == Integration::DepthBufferAvailable::TRUE )
+      {
+        SetupDepthBuffer( item, context, autoDepthTestMode, firstDepthBufferUse );
+      }
 
       // Render the item.
       item.mRenderer->Render( context, bufferIndex, *item.mNode, item.mModelMatrix, item.mModelViewMatrix,
@@ -435,7 +457,11 @@ RenderAlgorithms::RenderAlgorithms()
 {
 }
 
-void RenderAlgorithms::ProcessRenderInstruction( const RenderInstruction& instruction, Context& context, BufferIndex bufferIndex )
+void RenderAlgorithms::ProcessRenderInstruction( const RenderInstruction& instruction,
+                                                 Context& context,
+                                                 BufferIndex bufferIndex,
+                                                 Integration::DepthBufferAvailable depthBufferAvailable,
+                                                 Integration::StencilBufferAvailable stencilBufferAvailable )
 {
   DALI_PRINT_RENDER_INSTRUCTION( instruction, bufferIndex );
 
@@ -457,7 +483,13 @@ void RenderAlgorithms::ProcessRenderInstruction( const RenderInstruction& instru
 
       if( renderList && !renderList->IsEmpty() )
       {
-        ProcessRenderList( *renderList, context, bufferIndex, *viewMatrix, *projectionMatrix );
+        ProcessRenderList( *renderList,
+                            context,
+                            bufferIndex,
+                           *viewMatrix,
+                           *projectionMatrix,
+                            depthBufferAvailable,
+                            stencilBufferAvailable );
       }
     }
   }
index 5d4e44f..523cc14 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 // INTERNAL INCLUDES
+#include <dali/integration-api/core-enumerations.h>
 #include <dali/internal/common/buffer-index.h>
 #include <dali/internal/render/common/render-list.h>
 
@@ -52,11 +53,17 @@ class RenderAlgorithms
 
     /**
      * Process a render-instruction.
-     * @param[in] instruction The render-instruction to process.
-     * @param[in] context     The GL context.
-     * @param[in] bufferIndex The current render buffer index (previous update buffer)
+     * @param[in] instruction            The render-instruction to process.
+     * @param[in] context                The GL context.
+     * @param[in] bufferIndex            The current render buffer index (previous update buffer)
+     * @param[in] depthBufferAvailable   Whether the depth buffer is available
+     * @param[in] stencilBufferAvailable Whether the stencil buffer is available
      */
-    void ProcessRenderInstruction( const SceneGraph::RenderInstruction& instruction, Context& context, BufferIndex bufferIndex );
+    void ProcessRenderInstruction( const SceneGraph::RenderInstruction& instruction,
+                                   Context& context,
+                                   BufferIndex bufferIndex,
+                                   Integration::DepthBufferAvailable depthBufferAvailable,
+                                   Integration::StencilBufferAvailable stencilBufferAvailable );
 
   private:
 
@@ -88,18 +95,32 @@ class RenderAlgorithms
      * @param[in/out] usedStencilBuffer        True if the stencil buffer has been used so far within this RenderList. Used by StencilMode::ON.
      * @param[in/out] lastClippingDepth        The stencil depth of the last renderer drawn. Used by the clipping feature.
      * @param[in/out] lastClippingId           The clipping ID of the last renderer drawn.   Used by the clipping feature.
+     * @param[in]     stencilBufferAvailable   Whether the stencil buffer is available
      */
-    inline void SetupClipping( const Dali::Internal::SceneGraph::RenderItem& item, Context& context, bool& usedStencilBuffer, uint32_t& lastClippingDepth, uint32_t& lastClippingId );
+    inline void SetupClipping( const Dali::Internal::SceneGraph::RenderItem& item,
+                               Context& context,
+                               bool& usedStencilBuffer,
+                               uint32_t& lastClippingDepth,
+                               uint32_t& lastClippingId,
+                               Integration::StencilBufferAvailable stencilBufferAvailable );
 
     /**
      * @brief Process a render-list.
-     * @param[in] renderList       The render-list to process.
-     * @param[in] context          The GL context.
-     * @param[in] buffer           The current render buffer index (previous update buffer)
-     * @param[in] viewMatrix       The view matrix from the appropriate camera.
-     * @param[in] projectionMatrix The projection matrix from the appropriate camera.
+     * @param[in] renderList             The render-list to process.
+     * @param[in] context                The GL context.
+     * @param[in] buffer                 The current render buffer index (previous update buffer)
+     * @param[in] viewMatrix             The view matrix from the appropriate camera.
+     * @param[in] projectionMatrix       The projection matrix from the appropriate camera.
+     * @param[in] depthBufferAvailable   Whether the depth buffer is available
+     * @param[in] stencilBufferAvailable Whether the stencil buffer is available
      */
-    inline void ProcessRenderList( const Dali::Internal::SceneGraph::RenderList& renderList, Context& context, BufferIndex bufferIndex, const Matrix& viewMatrix, const Matrix& projectionMatrix );
+    inline void ProcessRenderList( const Dali::Internal::SceneGraph::RenderList& renderList,
+                                   Context& context,
+                                   BufferIndex bufferIndex,
+                                   const Matrix& viewMatrix,
+                                   const Matrix& projectionMatrix,
+                                   Integration::DepthBufferAvailable depthBufferAvailable,
+                                   Integration::StencilBufferAvailable stencilBufferAvailable );
 
     // Prevent copying:
     RenderAlgorithms( RenderAlgorithms& rhs );
index a4ddb84..9261a6d 100644 (file)
@@ -54,7 +54,9 @@ namespace SceneGraph
 struct RenderManager::Impl
 {
   Impl( Integration::GlAbstraction& glAbstraction,
-        Integration::GlSyncAbstraction& glSyncAbstraction )
+        Integration::GlSyncAbstraction& glSyncAbstraction,
+        Integration::DepthBufferAvailable depthBufferAvailableParam,
+        Integration::StencilBufferAvailable stencilBufferAvailableParam )
   : context( glAbstraction ),
     glSyncAbstraction( glSyncAbstraction ),
     renderQueue(),
@@ -69,7 +71,9 @@ struct RenderManager::Impl
     textureContainer(),
     frameBufferContainer(),
     lastFrameWasRendered( false ),
-    programController( glAbstraction )
+    programController( glAbstraction ),
+    depthBufferAvailable( depthBufferAvailableParam ),
+    stencilBufferAvailable( stencilBufferAvailableParam )
   {
   }
 
@@ -127,14 +131,21 @@ struct RenderManager::Impl
 
   ProgramController                         programController;        ///< Owner of the GL programs
 
+  Integration::DepthBufferAvailable         depthBufferAvailable;     ///< Whether the depth buffer is available
+  Integration::StencilBufferAvailable       stencilBufferAvailable;   ///< Whether the stencil buffer is available
+
 };
 
 RenderManager* RenderManager::New( Integration::GlAbstraction& glAbstraction,
-                                   Integration::GlSyncAbstraction& glSyncAbstraction )
+                                   Integration::GlSyncAbstraction& glSyncAbstraction,
+                                   Integration::DepthBufferAvailable depthBufferAvailable,
+                                   Integration::StencilBufferAvailable stencilBufferAvailable )
 {
   RenderManager* manager = new RenderManager;
   manager->mImpl = new Impl( glAbstraction,
-                             glSyncAbstraction );
+                             glSyncAbstraction,
+                             depthBufferAvailable,
+                             stencilBufferAvailable );
   return manager;
 }
 
@@ -421,17 +432,31 @@ void RenderManager::Render( Integration::RenderStatus& status )
                                mImpl->backgroundColor.b,
                                mImpl->backgroundColor.a );
 
-    mImpl->context.ClearStencil( 0 );
-
-    // Clear the entire color, depth and stencil buffers for the default framebuffer.
-    // It is important to clear all 3 buffers, for performance on deferred renderers like Mali
+    // Clear the entire color, depth and stencil buffers for the default framebuffer, if required.
+    // It is important to clear all 3 buffers when they are being used, for performance on deferred renderers
     // e.g. previously when the depth & stencil buffers were NOT cleared, it caused the DDK to exceed a "vertex count limit",
     // and then stall. That problem is only noticeable when rendering a large number of vertices per frame.
+
     mImpl->context.SetScissorTest( false );
+
+    GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
+
     mImpl->context.ColorMask( true );
-    mImpl->context.DepthMask( true );
-    mImpl->context.StencilMask( 0xFF ); // 8 bit stencil mask, all 1's
-    mImpl->context.Clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, Context::FORCE_CLEAR );
+
+    if( mImpl->depthBufferAvailable == Integration::DepthBufferAvailable::TRUE )
+    {
+      mImpl->context.DepthMask( true );
+      clearMask |= GL_DEPTH_BUFFER_BIT;
+    }
+
+    if( mImpl->stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE)
+    {
+      mImpl->context.ClearStencil( 0 );
+      mImpl->context.StencilMask( 0xFF ); // 8 bit stencil mask, all 1's
+      clearMask |= GL_STENCIL_BUFFER_BIT;
+    }
+
+    mImpl->context.Clear( clearMask, Context::FORCE_CLEAR );
 
     // reset the program matrices for all programs once per frame
     // this ensures we will set view and projection matrix once per program per camera
@@ -532,7 +557,12 @@ void RenderManager::DoRender( RenderInstruction& instruction )
     mImpl->context.SetScissorTest( false );
   }
 
-  mImpl->renderAlgorithms.ProcessRenderInstruction( instruction, mImpl->context, mImpl->renderBufferIndex );
+  mImpl->renderAlgorithms.ProcessRenderInstruction(
+      instruction,
+      mImpl->context,
+      mImpl->renderBufferIndex,
+      mImpl->depthBufferAvailable,
+      mImpl->stencilBufferAvailable );
 
   if( instruction.mRenderTracker && ( instruction.mFrameBuffer != NULL ) )
   {
index 400d138..5e48692 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
 
 // INTERNAL INCLUDES
 #include <dali/public-api/math/rect.h>
+#include <dali/integration-api/core-enumerations.h>
 #include <dali/internal/common/shader-saver.h>
 #include <dali/internal/render/gl-resources/gpu-buffer.h>
 #include <dali/internal/render/renderers/render-property-buffer.h>
@@ -71,12 +72,15 @@ public:
 
   /**
    * Construct a new RenderManager.
-   * @param[in]  glAbstraction The GL abstraction used for rendering.
-   * @param[in]  glSyncAbstraction The GL sync abstraction used fence sync creation/deletion.
-   * @param[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.*
+   * @param[in]  glAbstraction           The GL abstraction used for rendering.
+   * @param[in]  glSyncAbstraction       The GL sync abstraction used fence sync creation/deletion.
+   * @param[in]  depthBufferAvailable    Whether the depth buffer is available
+   * @param[in]  stencilBufferAvailable  Whether the stencil buffer is available
    */
   static RenderManager* New( Integration::GlAbstraction& glAbstraction,
-                             Integration::GlSyncAbstraction& glSyncAbstraction );
+                             Integration::GlSyncAbstraction& glSyncAbstraction,
+                             Integration::DepthBufferAvailable depthBufferAvailable,
+                             Integration::StencilBufferAvailable stencilBufferAvailable );
 
   /**
    * Non-virtual destructor; not intended as a base class