Merge branch 'devel/master' into devel/graphics
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / frame-buffer-impl.cpp
index a2ac30c..9114269 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
 #include <dali/internal/event/rendering/frame-buffer-impl.h>
 
 // INTERNAL INCLUDES
-#include <dali/internal/update/manager/update-manager.h>
 #include <dali/internal/render/renderers/render-frame-buffer.h>
-#include <dali/internal/render/renderers/render-texture-frame-buffer.h>
-#include <dali/internal/render/renderers/render-surface-frame-buffer.h>
-#include <dali/integration-api/render-surface.h>
+#include <dali/internal/update/manager/update-manager.h>
 
 namespace Dali
 {
 namespace Internal
 {
-
-FrameBufferPtr FrameBuffer::New( uint32_t width, uint32_t height, Mask attachments  )
+FrameBufferPtr FrameBuffer::New(uint32_t width, uint32_t height, Mask attachments)
 {
-  FrameBufferPtr frameBuffer( new FrameBuffer( width, height, attachments ) );
+  FrameBufferPtr frameBuffer(new FrameBuffer(width, height, attachments));
   frameBuffer->Initialize();
   return frameBuffer;
 }
 
-FrameBufferPtr FrameBuffer::New( Dali::Integration::RenderSurface& renderSurface, Mask attachments )
-{
-  Dali::PositionSize positionSize = renderSurface.GetPositionSize();
-  FrameBufferPtr frameBuffer( new FrameBuffer( positionSize.width, positionSize.height, attachments ) );
-  frameBuffer->Initialize( &renderSurface );
-  return frameBuffer;
-}
-
 Render::FrameBuffer* FrameBuffer::GetRenderObject() const
 {
   return mRenderObject;
 }
 
-FrameBuffer::FrameBuffer( uint32_t width, uint32_t height, Mask attachments )
-: mEventThreadServices( EventThreadServices::Get() ),
-  mRenderObject( NULL ),
-  mColor( NULL ),
-  mWidth( width ),
-  mHeight( height ),
-  mAttachments( attachments ),
-  mIsSurfaceBacked( false )
+FrameBuffer::FrameBuffer(uint32_t width, uint32_t height, Mask attachments)
+: mEventThreadServices(EventThreadServices::Get()),
+  mRenderObject(nullptr),
+  mColor{nullptr},
+  mDepth(nullptr),
+  mStencil(nullptr),
+  mWidth(width),
+  mHeight(height),
+  mAttachments(attachments),
+  mColorAttachmentCount(0)
 {
 }
 
-void FrameBuffer::Initialize( Integration::RenderSurface* renderSurface )
+void FrameBuffer::Initialize()
 {
-  mIsSurfaceBacked = ( renderSurface != nullptr );
+  mRenderObject = new Render::FrameBuffer(mWidth, mHeight, mAttachments);
 
-  // If render surface backed, create a different scene object
-  // Make Render::FrameBuffer as a base class, and implement Render::TextureFrameBuffer & Render::WindowFrameBuffer
-  if ( mIsSurfaceBacked )
+  OwnerPointer<Render::FrameBuffer> transferOwnership(mRenderObject);
+  AddFrameBuffer(mEventThreadServices.GetUpdateManager(), transferOwnership);
+}
+
+void FrameBuffer::AttachColorTexture(TexturePtr texture, uint32_t mipmapLevel, uint32_t layer)
+{
+  if((texture->GetWidth() / (1u << mipmapLevel) != mWidth) ||
+     (texture->GetHeight() / (1u << mipmapLevel) != mHeight))
+  {
+    DALI_LOG_ERROR("Failed to attach color texture to FrameBuffer: Size mismatch \n");
+  }
+  else if(mColorAttachmentCount >= Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS)
   {
-    mRenderObject = new Render::SurfaceFrameBuffer( renderSurface );
+    DALI_LOG_ERROR("Failed to attach color texture to FrameBuffer: Exceeded maximum supported color attachments.\n");
   }
   else
   {
-    mRenderObject = new Render::TextureFrameBuffer( mWidth, mHeight, mAttachments );
+    mColor[mColorAttachmentCount] = texture;
+    ++mColorAttachmentCount;
+
+    AttachColorTextureToFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel, layer);
   }
+}
 
-  OwnerPointer< Render::FrameBuffer > transferOwnership( mRenderObject );
-  AddFrameBuffer( mEventThreadServices.GetUpdateManager(), transferOwnership );
+void FrameBuffer::AttachDepthTexture(TexturePtr texture, uint32_t mipmapLevel)
+{
+  if((texture->GetWidth() / (1u << mipmapLevel) != mWidth) ||
+     (texture->GetHeight() / (1u << mipmapLevel) != mHeight))
+  {
+    DALI_LOG_ERROR("Failed to attach depth texture to FrameBuffer: Size mismatch \n");
+  }
+  else
+  {
+    mDepth = texture;
+    AttachDepthTextureToFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel);
+  }
 }
 
-void FrameBuffer::AttachColorTexture( TexturePtr texture, uint32_t mipmapLevel, uint32_t layer )
+void FrameBuffer::AttachDepthStencilTexture(TexturePtr texture, unsigned int mipmapLevel)
 {
-  if ( mIsSurfaceBacked )
+  if((texture->GetWidth() / (1u << mipmapLevel) != mWidth) ||
+     (texture->GetHeight() / (1u << mipmapLevel) != mHeight))
   {
-    DALI_LOG_ERROR( "Attempted to attach color texture to a render surface backed FrameBuffer \n" );
+    DALI_LOG_ERROR("Failed to attach depth/stencil texture to FrameBuffer: Size mismatch \n");
   }
   else
   {
-    if( ( texture->GetWidth() / ( 1u << mipmapLevel ) == mWidth ) &&
-        ( texture->GetHeight() / ( 1u << mipmapLevel ) == mHeight ) )
-    {
-      mColor = texture;
-      AttachColorTextureToFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel, layer );
-    }
-    else
-    {
-      DALI_LOG_ERROR( "Failed to attach color texture to FrameBuffer: Size mismatch \n" );
-    }
+    mStencil = texture;
+    AttachDepthStencilTextureToFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel);
   }
 }
 
-Texture* FrameBuffer::GetColorTexture()
+Texture* FrameBuffer::GetColorTexture(uint8_t index) const
 {
-  return mIsSurfaceBacked ? nullptr : mColor.Get();
+  return (index >= mColorAttachmentCount) ? nullptr : mColor[index].Get();
 }
 
-void FrameBuffer::SetSize( uint32_t width, uint32_t height )
+Texture* FrameBuffer::GetDepthTexture() const
 {
-  mWidth = width;
-  mHeight = height;
+  return (mDepth) ? mDepth.Get() : nullptr;
+}
 
-  if( mRenderObject->IsSurfaceBacked() )
-  {
-    SetFrameBufferSizeMessage( mEventThreadServices.GetUpdateManager(), static_cast<Render::SurfaceFrameBuffer*>( mRenderObject ), width, height );
-  }
+Texture* FrameBuffer::GetDepthStencilTexture() const
+{
+  return (mStencil) ? mStencil.Get() : nullptr;
 }
 
-void FrameBuffer::MarkSurfaceAsInvalid()
+void FrameBuffer::SetSize(uint32_t width, uint32_t height)
 {
-  if ( mIsSurfaceBacked )
-  {
-    Render::SurfaceFrameBuffer* renderObject = static_cast<Render::SurfaceFrameBuffer*>( mRenderObject );
-    renderObject->MarkSurfaceAsInvalid();
-  }
+  mWidth  = width;
+  mHeight = height;
 }
 
 FrameBuffer::~FrameBuffer()
 {
-  if( EventThreadServices::IsCoreRunning() && mRenderObject )
+  if(EventThreadServices::IsCoreRunning() && mRenderObject)
   {
-    RemoveFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject );
+    RemoveFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject);
   }
 }
 
-
 } // namespace Internal
 } // namespace Dali