Added support for Multiple Render Targets, to Dali::FrameBuffer.
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-manager.cpp
index a3e6db9..35167ed 100644 (file)
@@ -80,7 +80,6 @@ struct RenderManager::Impl
     renderQueue(),
     instructions(),
     renderAlgorithms(),
-    backgroundColor( Dali::Stage::DEFAULT_BACKGROUND_COLOR ),
     frameCount( 0u ),
     renderBufferIndex( SceneGraphBuffers::INITIAL_UPDATE_BUFFER_INDEX ),
     defaultSurfaceRect(),
@@ -148,8 +147,6 @@ struct RenderManager::Impl
   RenderInstructionContainer                instructions;
   Render::RenderAlgorithms                  renderAlgorithms;        ///< The RenderAlgorithms object is used to action the renders required by a RenderInstruction
 
-  Vector4                                   backgroundColor;         ///< The glClear color used at the beginning of each frame.
-
   uint32_t                                  frameCount;              ///< The current frame count
   BufferIndex                               renderBufferIndex;       ///< The index of the buffer to read from; this is opposite of the "update" buffer
 
@@ -249,11 +246,6 @@ RenderInstructionContainer& RenderManager::GetRenderInstructionContainer()
   return mImpl->instructions;
 }
 
-void RenderManager::SetBackgroundColor( const Vector4& color )
-{
-  mImpl->backgroundColor = color;
-}
-
 void RenderManager::SetDefaultSurfaceRect(const Rect<int32_t>& rect)
 {
   mImpl->defaultSurfaceRect = rect;
@@ -605,7 +597,6 @@ void RenderManager::DoRender( RenderInstruction& instruction )
   }
 
   Rect<int32_t> surfaceRect = mImpl->defaultSurfaceRect;
-  Vector4 backgroundColor = mImpl->backgroundColor;
   Integration::DepthBufferAvailable depthBufferAvailable = mImpl->depthBufferAvailable;
   Integration::StencilBufferAvailable stencilBufferAvailable = mImpl->stencilBufferAvailable;
 
@@ -637,7 +628,6 @@ void RenderManager::DoRender( RenderInstruction& instruction )
       }
 
       surfaceRect = Rect<int32_t>( 0, 0, static_cast<int32_t>( surfaceFrameBuffer->GetWidth() ), static_cast<int32_t>( surfaceFrameBuffer->GetHeight() ) );
-      backgroundColor = surfaceFrameBuffer->GetBackgroundColor();
     }
     else
     {
@@ -665,7 +655,10 @@ void RenderManager::DoRender( RenderInstruction& instruction )
     {
       // For each offscreen buffer, update the dependency list with the new texture id used by this frame buffer.
       Render::TextureFrameBuffer* textureFrameBuffer = static_cast<Render::TextureFrameBuffer*>( instruction.mFrameBuffer );
-      mImpl->textureDependencyList.PushBack( textureFrameBuffer->GetTextureId() );
+      for (unsigned int i0 = 0, i1 = textureFrameBuffer->GetColorAttachmentCount(); i0 < i1; ++i0)
+      {
+        mImpl->textureDependencyList.PushBack( textureFrameBuffer->GetTextureId(i0) );
+      }
     }
   }
   else
@@ -679,20 +672,12 @@ void RenderManager::DoRender( RenderInstruction& instruction )
                               surfaceRect.y,
                               surfaceRect.width,
                               surfaceRect.height );
-
-    mImpl->currentContext->ClearColor( backgroundColor.r,
-                                backgroundColor.g,
-                                backgroundColor.b,
-                                backgroundColor.a );
   }
 
   // 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->currentContext->SetScissorTest( false );
-
   GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
 
   mImpl->currentContext->ColorMask( true );
@@ -710,8 +695,6 @@ void RenderManager::DoRender( RenderInstruction& instruction )
     clearMask |= GL_STENCIL_BUFFER_BIT;
   }
 
-  mImpl->currentContext->Clear( clearMask, Context::FORCE_CLEAR );
-
   if( !instruction.mIgnoreRenderToFbo && ( instruction.mFrameBuffer != 0 ) )
   {
     if ( instruction.mFrameBuffer->IsSurfaceBacked() ) // Surface rendering
@@ -764,21 +747,34 @@ void RenderManager::DoRender( RenderInstruction& instruction )
     }
   }
 
+  bool clearFullFrameRect = true;
+  if( instruction.mFrameBuffer != 0 )
+  {
+    Viewport frameRect( 0, 0, instruction.mFrameBuffer->GetWidth(), instruction.mFrameBuffer->GetHeight() );
+    clearFullFrameRect = ( frameRect == viewportRect );
+  }
+  else
+  {
+    clearFullFrameRect = ( surfaceRect == viewportRect );
+  }
+
   mImpl->currentContext->Viewport(viewportRect.x, viewportRect.y, viewportRect.width, viewportRect.height);
+  mImpl->currentContext->ClearColor( clearColor.r,
+                                     clearColor.g,
+                                     clearColor.b,
+                                     clearColor.a );
 
-  if ( instruction.mIsClearColorSet )
+  if( instruction.mIsClearColorSet && !clearFullFrameRect )
   {
-    mImpl->currentContext->ClearColor( clearColor.r,
-                                       clearColor.g,
-                                       clearColor.b,
-                                       clearColor.a );
-
-    // Clear the viewport area only
     mImpl->currentContext->SetScissorTest( true );
     mImpl->currentContext->Scissor( viewportRect.x, viewportRect.y, viewportRect.width, viewportRect.height );
-    mImpl->currentContext->ColorMask( true );
-    mImpl->currentContext->Clear( GL_COLOR_BUFFER_BIT , Context::CHECK_CACHED_VALUES );
+    mImpl->currentContext->Clear( clearMask, Context::FORCE_CLEAR );
+    mImpl->currentContext->SetScissorTest( false );
+  }
+  else
+  {
     mImpl->currentContext->SetScissorTest( false );
+    mImpl->currentContext->Clear( clearMask, Context::FORCE_CLEAR );
   }
 
   // Clear the list of bound textures