[Tizen] Using Depth and Stencil buffer & texture 45/231745/4
authorSeungho, Baek <sbsh.baek@samsung.com>
Tue, 17 Mar 2020 08:09:40 +0000 (17:09 +0900)
committerSeungho, Baek <sbsh.baek@samsung.com>
Fri, 24 Apr 2020 07:20:35 +0000 (16:20 +0900)
 - Add DEPTH_UNSIGNED_INT and DEPTH_FLOAT for depth
 - Add DEPTH_STENCIL for depth and stencil
 - Add AttachDepthTexture and AttachDepthStencilTexture to use Depth/Stencil buffer of FBO as a input

Change-Id: Ia7483e2e7b81de170143585eed99cabf65c89c00
Signed-off-by: Seungho, Baek <sbsh.baek@samsung.com>
19 files changed:
automated-tests/src/dali/utc-Dali-FrameBuffer.cpp
automated-tests/src/dali/utc-Dali-Pixel.cpp
dali/devel-api/file.list
dali/devel-api/rendering/frame-buffer-devel.cpp
dali/devel-api/rendering/frame-buffer-devel.h
dali/integration-api/bitmap.cpp
dali/internal/event/images/nine-patch-image-impl.cpp
dali/internal/event/rendering/frame-buffer-impl.cpp
dali/internal/event/rendering/frame-buffer-impl.h
dali/internal/render/common/render-manager.cpp
dali/internal/render/common/render-manager.h
dali/internal/render/renderers/render-texture-frame-buffer.cpp
dali/internal/render/renderers/render-texture-frame-buffer.h
dali/internal/render/renderers/render-texture.cpp
dali/internal/update/manager/update-manager.cpp
dali/internal/update/manager/update-manager.h
dali/public-api/images/pixel.cpp
dali/public-api/images/pixel.h
dali/public-api/rendering/frame-buffer.h

index 5a9a0fc..b78faf6 100644 (file)
@@ -388,6 +388,52 @@ int UtcDaliFrameBufferAttachColorTexture05(void)
   END_TEST;
 }
 
+int UtcDaliFrameBufferAttachDepthTexture01(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH_STENCIL );
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  frameBuffer.AttachColorTexture( texture );
+
+  Texture textureDepth = Texture::New( TextureType::TEXTURE_2D, Pixel::DEPTH_UNSIGNED_INT, width, height );
+  DevelFrameBuffer::AttachDepthTexture( frameBuffer, textureDepth );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliFrameBufferAttachDepthStencilTexture01(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH_STENCIL );
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  frameBuffer.AttachColorTexture( texture );
+
+  Texture textureStencil = Texture::New( TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height );
+  DevelFrameBuffer::AttachDepthStencilTexture( frameBuffer, textureStencil );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliFrameBufferGetColorTexture01(void)
 {
   TestApplication application;
@@ -465,6 +511,42 @@ int UtcDaliFrameBufferGetColorTexture04(void)
   END_TEST;
 }
 
+int UtcDaliFrameBufferGetDepthTexture01(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  frameBuffer.AttachColorTexture( texture );
+
+  Texture textureDepth = Texture::New( TextureType::TEXTURE_2D, Pixel::DEPTH_FLOAT, width, height );
+  DevelFrameBuffer::AttachDepthTexture( frameBuffer, textureDepth );
+
+  DALI_TEST_EQUALS(DevelFrameBuffer::GetDepthTexture( frameBuffer ), textureDepth, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliFrameBufferGetDepthStencilTexture01(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  frameBuffer.AttachColorTexture( texture );
+
+  Texture textureStencil = Texture::New( TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height );
+  DevelFrameBuffer::AttachDepthStencilTexture( frameBuffer, textureStencil );
+
+  DALI_TEST_EQUALS(DevelFrameBuffer::GetDepthStencilTexture( frameBuffer ), textureStencil, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliFramebufferContextLoss(void)
 {
   tet_infoline("UtcDaliFramebufferContextLoss\n");
index e86bce2..0363b3b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -50,7 +50,7 @@ int UtcDaliPixelHasAlpha(void)
 
   tet_infoline("UtcDaliPixelHasAlpha");
 
-  TestPixelEnumSize( 56 );
+  TestPixelEnumSize( 59 );
 
   DALI_TEST_CHECK( Pixel::HasAlpha( Pixel::INVALID ) == false ); // For completeness
 
@@ -114,6 +114,10 @@ int UtcDaliPixelHasAlpha(void)
   DALI_TEST_CHECK( Pixel::HasAlpha( Pixel::RGB16F ) == false );
   DALI_TEST_CHECK( Pixel::HasAlpha( Pixel::RGB32F ) == false );
 
+  DALI_TEST_CHECK( Pixel::HasAlpha( Pixel::DEPTH_UNSIGNED_INT ) == false );
+  DALI_TEST_CHECK( Pixel::HasAlpha( Pixel::DEPTH_FLOAT ) == false );
+  DALI_TEST_CHECK( Pixel::HasAlpha( Pixel::DEPTH_STENCIL ) == false );
+
   END_TEST;
 }
 
@@ -130,7 +134,7 @@ int UtcDaliPixelGetBytesPerPixel(void)
   tet_infoline("UtcDaliPixelGetBytesPerPixel");
 
   // Be sure that the number of cases tested below is correct:
-  TestPixelEnumSize( 56 );
+  TestPixelEnumSize( 59 );
 
   DALI_TEST_CHECK( Pixel::GetBytesPerPixel( Pixel::INVALID ) == 0 ); // For completeness
 
@@ -199,6 +203,10 @@ int UtcDaliPixelGetBytesPerPixel(void)
   DALI_TEST_CHECK( Pixel::GetBytesPerPixel( Pixel::RGB16F ) == 12 );
   DALI_TEST_CHECK( Pixel::GetBytesPerPixel( Pixel::RGB32F ) == 24 );
 
+  DALI_TEST_CHECK( Pixel::GetBytesPerPixel( Pixel::DEPTH_UNSIGNED_INT ) == 4 );
+  DALI_TEST_CHECK( Pixel::GetBytesPerPixel( Pixel::DEPTH_FLOAT ) == 4 );
+  DALI_TEST_CHECK( Pixel::GetBytesPerPixel( Pixel::DEPTH_STENCIL ) == 4 );
+
   END_TEST;
 }
 
@@ -218,7 +226,7 @@ int UtcDaliPixelGetAlphaOffsetAndMaskP(void)
   int bitMask = 0;
 
   // Be sure that the number of cases tested below is correct:
-  TestPixelEnumSize( 56 );
+  TestPixelEnumSize( 59 );
 
   Pixel::GetAlphaOffsetAndMask( Pixel::INVALID, byteOffset, bitMask ); // For completeness
   DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 );
@@ -339,6 +347,32 @@ int UtcDaliPixelGetAlphaOffsetAndMaskP(void)
   Pixel::GetAlphaOffsetAndMask( Pixel::RGB32F, byteOffset, bitMask );
   DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 );
 
+  Pixel::GetAlphaOffsetAndMask( Pixel::DEPTH_UNSIGNED_INT, byteOffset, bitMask );
+  DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 );
+  Pixel::GetAlphaOffsetAndMask( Pixel::DEPTH_FLOAT, byteOffset, bitMask );
+  DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 );
+  Pixel::GetAlphaOffsetAndMask( Pixel::DEPTH_STENCIL, byteOffset, bitMask );
+  DALI_TEST_CHECK( byteOffset == 0 && bitMask == 0 );
+
+  END_TEST;
+}
+
+int UtcDaliPixelConvertGlFormat(void)
+{
+  tet_infoline("UtcDaliPixelConvertGlFormat");
+
+  unsigned int pixelDataType, internalFormat;
+  Dali::Integration::ConvertToGlFormat( Pixel::Format::DEPTH_UNSIGNED_INT, pixelDataType, internalFormat );
+  DALI_TEST_CHECK( pixelDataType == GL_UNSIGNED_INT );
+  DALI_TEST_CHECK( internalFormat == GL_DEPTH_COMPONENT );
+
+  Dali::Integration::ConvertToGlFormat( Pixel::Format::DEPTH_FLOAT, pixelDataType, internalFormat );
+  DALI_TEST_CHECK( pixelDataType == GL_FLOAT );
+  DALI_TEST_CHECK( internalFormat == GL_DEPTH_COMPONENT );
+
+  Dali::Integration::ConvertToGlFormat( Pixel::Format::DEPTH_STENCIL, pixelDataType, internalFormat );
+  DALI_TEST_CHECK( pixelDataType == GL_UNSIGNED_INT_24_8 );
+  DALI_TEST_CHECK( internalFormat == GL_DEPTH_STENCIL );
   END_TEST;
 }
 
index d1c6b46..b72721a 100644 (file)
@@ -133,4 +133,4 @@ SET( DEVEL_API_HEADERS ${DEVEL_API_HEADERS}
   ${devel_api_core_scripting_header_files}
   ${devel_api_core_threading_header_files}
   ${devel_api_core_update_header_files}
-)
+)
\ No newline at end of file
index f515e70..d79ded7 100644 (file)
@@ -27,12 +27,52 @@ namespace Dali
 namespace DevelFrameBuffer
 {
 
+void AttachDepthTexture( FrameBuffer frameBuffer, Texture& texture )
+{
+  AttachDepthTexture( frameBuffer, texture, 0u );
+}
+
+void AttachDepthTexture( FrameBuffer frameBuffer, Texture& texture, uint32_t mipmapLevel )
+{
+  if( texture )
+  {
+    Internal::TexturePtr texturePtr( &GetImplementation( texture ) );
+    GetImplementation( frameBuffer ).AttachDepthTexture( texturePtr, mipmapLevel );
+  }
+}
+
+void AttachDepthStencilTexture( FrameBuffer frameBuffer, Texture& texture )
+{
+  AttachDepthStencilTexture( frameBuffer, texture, 0u );
+}
+
+void AttachDepthStencilTexture( FrameBuffer frameBuffer, Texture& texture, uint32_t mipmapLevel )
+{
+  if( texture )
+  {
+    Internal::TexturePtr texturePtr( &GetImplementation( texture ) );
+    GetImplementation( frameBuffer ).AttachDepthStencilTexture( texturePtr, mipmapLevel );
+  }
+}
+
 Texture GetColorTexture( const FrameBuffer frameBuffer, uint8_t index )
 {
   Internal::Texture* texturePtr = GetImplementation( frameBuffer ).GetColorTexture(index);
   return Dali::Texture( texturePtr );
 }
 
+Texture GetDepthTexture( FrameBuffer frameBuffer )
+{
+  Internal::Texture* texturePtr = GetImplementation(frameBuffer).GetDepthTexture();
+  return Dali::Texture( texturePtr );
+}
+
+Texture GetDepthStencilTexture( FrameBuffer frameBuffer )
+{
+  Internal::Texture* texturePtr = GetImplementation(frameBuffer).GetDepthStencilTexture();
+  return Dali::Texture( texturePtr );
+}
+
 } // namespace DevelFrameBuffer
 
 } // namespace Dali
index 455d567..8ffe17c 100644 (file)
@@ -33,6 +33,52 @@ namespace DevelFrameBuffer
 constexpr uint8_t MAX_COLOR_ATTACHMENTS = 8;
 
 /**
+ * @brief Attach the base LOD of a depth texture to the framebuffer.
+ * @note This causes a depth attachment to be added.
+ *
+ * @param[in] frameBuffer A handle to the framebuffer
+ * @param[in] texture The texture that will be used as output when rendering
+ * @note The texture has to have same size as that of FrameBuffer
+ * otherwise it won't be attached.
+ */
+void AttachDepthTexture( FrameBuffer frameBuffer, Texture& texture );
+
+/**
+ * @brief Attach a depth texture to the framebuffer.
+ * @note This causes a depth attachment to be added.
+ *
+ * @param[in] frameBuffer A handle to the framebuffer
+ * @param[in] texture The texture that will be used as output when rendering
+ * @param[in] mipmapLevel The mipmap of the texture to be attached
+ * @note The mipmapped texture has to have same size as that of FrameBuffer
+ * otherwise it won't be attached.
+ */
+void AttachDepthTexture( FrameBuffer frameBuffer, Texture& texture, uint32_t mipmapLevel );
+
+/**
+ * @brief Attach the base LOD of a stencil texture to the framebuffer.
+ * @note This causes a stencil attachment to be added.
+ *
+ * @param[in] frameBuffer A handle to the framebuffer
+ * @param[in] texture The texture that will be used as output when rendering
+ * @note The texture has to have same size as that of FrameBuffer
+ * otherwise it won't be attached.
+ */
+void AttachDepthStencilTexture( FrameBuffer frameBuffer, Texture& texture );
+
+/**
+ * @brief Attach a depth/stencil texture to the framebuffer.
+ * @note This causes a depth/stencil attachment to be added.
+ *
+ * @param[in] frameBuffer A handle to the framebuffer
+ * @param[in] texture The texture that will be used as output when rendering
+ * @param[in] mipmapLevel The mipmap of the texture to be attached
+ * @note The mipmapped texture has to have same size as that of FrameBuffer
+ * otherwise it won't be attached.
+ */
+void AttachDepthStencilTexture( FrameBuffer frameBuffer, Texture& texture, uint32_t mipmapLevel );
+
+/**
  * @brief Gets the color texture at the given @a index used as output in the FrameBuffer.
  *
  * @param[in] frameBuffer A handle to the framebuffer
@@ -45,6 +91,24 @@ constexpr uint8_t MAX_COLOR_ATTACHMENTS = 8;
  */
 Texture GetColorTexture( const FrameBuffer frameBuffer, uint8_t index );
 
+/**
+ * @brief Gets the depth texture used as output in the FrameBuffer.
+ *
+ * @param[in] frameBuffer A handle to the framebuffer
+ *
+ * @return A handle to the texture used as depth output, or an uninitialized handle
+ */
+Texture GetDepthTexture( FrameBuffer frameBuffer );
+
+/**
+ * @brief Gets the depth/stencil texture used as output in the FrameBuffer.
+ *
+ * @param[in] frameBuffer A handle to the framebuffer
+ *
+ * @return A handle to the texture used as stencil output, or an uninitialized handle
+ */
+Texture GetDepthStencilTexture( FrameBuffer frameBuffer );
+
 } // namespace DevelFrameBuffer
 
 } // namespace Dali
index 373af9c..b0f3d4e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -424,6 +424,26 @@ void ConvertToGlFormat( Format pixelformat, unsigned& pixelDataType, unsigned& i
       break;
     }
 
+    // GLES 3.0 depth and stencil formats
+    case Pixel::DEPTH_UNSIGNED_INT:
+    {
+      pixelDataType = GL_UNSIGNED_INT;
+      internalFormat = GL_DEPTH_COMPONENT;
+      break;
+    }
+    case Pixel::DEPTH_FLOAT:
+    {
+      pixelDataType = GL_FLOAT;
+      internalFormat = GL_DEPTH_COMPONENT;
+      break;
+    }
+    case Pixel::DEPTH_STENCIL:
+    {
+      pixelDataType = GL_UNSIGNED_INT_24_8;
+      internalFormat = GL_DEPTH_STENCIL;
+      break;
+    }
+
     case INVALID:
     {
       DALI_LOG_ERROR( "Invalid pixel format for bitmap\n" );
index ca96236..da05f76 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -150,6 +150,9 @@ void GetRedOffsetAndMask(Dali::Pixel::Format pixelFormat, int& byteOffset, int&
 
     case Dali::Pixel::RGB16F:
     case Dali::Pixel::RGB32F:
+    case Dali::Pixel::DEPTH_UNSIGNED_INT:
+    case Dali::Pixel::DEPTH_FLOAT:
+    case Dali::Pixel::DEPTH_STENCIL:
     {
       DALI_LOG_ERROR("Pixel format not compatible.\n");
       byteOffset=0;
index ed35d3f..d158b84 100755 (executable)
@@ -54,6 +54,8 @@ FrameBuffer::FrameBuffer( uint32_t width, uint32_t height, Mask attachments )
 : mEventThreadServices( EventThreadServices::Get() ),
   mRenderObject( NULL ),
   mColor{ nullptr },
+  mDepth( nullptr ),
+  mStencil( nullptr ),
   mWidth( width ),
   mHeight( height ),
   mAttachments( attachments ),
@@ -108,11 +110,49 @@ void FrameBuffer::AttachColorTexture( TexturePtr texture, uint32_t mipmapLevel,
   }
 }
 
+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::AttachDepthStencilTexture( TexturePtr texture, unsigned int mipmapLevel )
+{
+  if( ( texture->GetWidth() / ( 1u << mipmapLevel ) != mWidth ) ||
+      ( texture->GetHeight() / ( 1u << mipmapLevel ) != mHeight ) )
+  {
+    DALI_LOG_ERROR( "Failed to attach depth/stencil texture to FrameBuffer: Size mismatch \n" );
+  }
+  else
+  {
+    mStencil = texture;
+    AttachDepthStencilTextureToFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel );
+  }
+}
+
 Texture* FrameBuffer::GetColorTexture(uint8_t index) const
 {
   return ( mIsSurfaceBacked || index >= mColorAttachmentCount ) ? nullptr : mColor[index].Get();
 }
 
+Texture* FrameBuffer::GetDepthTexture() const
+{
+  return ( mDepth ) ? mDepth.Get() : nullptr;
+}
+
+Texture* FrameBuffer::GetDepthStencilTexture() const
+{
+  return ( mStencil ) ? mStencil.Get() : nullptr;
+}
+
 void FrameBuffer::SetSize( uint32_t width, uint32_t height )
 {
   mWidth = width;
index 86f5093..83a80b3 100755 (executable)
@@ -88,11 +88,31 @@ public:
   void AttachColorTexture( TexturePtr texture, uint32_t mipmapLevel, uint32_t layer );
 
   /**
+   * @copydoc Dali::DevelFrameBuffer::AttachDepthTexture()
+   */
+  void AttachDepthTexture( TexturePtr texture, uint32_t mipmapLevel );
+
+  /**
+   * @copydoc Dali::DevelFrameBuffer::AttachDepthStencilTexture()
+   */
+  void AttachDepthStencilTexture( TexturePtr texture, uint32_t mipmapLevel );
+
+  /**
    * @copydoc Dali::FrameBuffer::GetColorTexture()
    */
   Texture* GetColorTexture(uint8_t index) const;
 
   /**
+   * @copydoc Dali::DevelFrameBuffer::GetDepthTexture()
+   */
+  Texture* GetDepthTexture() const;
+
+  /**
+   * @copydoc Dali::DevelFrameBuffer::GetDepthStencilTexture()
+   */
+  Texture* GetDepthStencilTexture() const;
+
+  /**
    * @brief Sets the frame buffer size.
    * @param[in] width The width size
    * @param[in] height The height size
@@ -144,6 +164,8 @@ private: // data
   Internal::Render::FrameBuffer* mRenderObject;        ///< The Render::Texture associated to this texture
 
   TexturePtr mColor[ Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS ];
+  TexturePtr mDepth;
+  TexturePtr mStencil;
   uint32_t mWidth;
   uint32_t mHeight;
   Mask mAttachments;                           ///< Bit-mask of type FrameBuffer::Attachment::Mask
index dd72694..5a53673 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -410,6 +410,24 @@ void RenderManager::AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameB
   }
 }
 
+void RenderManager::AttachDepthTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel )
+{
+  if ( !frameBuffer->IsSurfaceBacked() )
+  {
+    auto textureFrameBuffer = static_cast<Render::TextureFrameBuffer*>( frameBuffer );
+    textureFrameBuffer->AttachDepthTexture( mImpl->context, texture, mipmapLevel );
+  }
+}
+
+void RenderManager::AttachDepthStencilTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel )
+{
+  if ( !frameBuffer->IsSurfaceBacked() )
+  {
+    auto textureFrameBuffer = static_cast<Render::TextureFrameBuffer*>( frameBuffer );
+    textureFrameBuffer->AttachDepthStencilTexture( mImpl->context, texture, mipmapLevel );
+  }
+}
+
 void RenderManager::AddPropertyBuffer( OwnerPointer< Render::PropertyBuffer >& propertyBuffer )
 {
   mImpl->propertyBufferContainer.PushBack( propertyBuffer.Release() );
index a5ad160..6935981 100755 (executable)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H
 
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -304,6 +304,22 @@ public:
   void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer );
 
   /**
+   * Attach a texture as depth output to an existing FrameBuffer
+   * @param[in] frameBuffer The FrameBuffer
+   * @param[in] texture The texture that will be used as output when rendering
+   * @param[in] mipmapLevel The mipmap of the texture to be attached
+   */
+  void AttachDepthTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel );
+
+  /**
+   * Attach a texture as depth/stencil output to an existing FrameBuffer
+   * @param[in] frameBuffer The FrameBuffer
+   * @param[in] texture The texture that will be used as output when rendering
+   * @param[in] mipmapLevel The mipmap of the texture to be attached
+   */
+  void AttachDepthStencilTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel );
+
+  /**
    * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
    * tracker. The lifetime of the tracker is related to the lifetime of the tracked
    * object, usually an offscreen render task.
index 24a17f4..3062c6d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -120,6 +120,32 @@ void TextureFrameBuffer::AttachColorTexture( Context& context, Render::Texture*
   context.BindFramebuffer( GL_FRAMEBUFFER, 0 );
 }
 
+void TextureFrameBuffer::AttachDepthTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel )
+{
+  context.BindFramebuffer( GL_FRAMEBUFFER, mId );
+
+  // Create a depth attachment.
+  if( texture->GetType() == TextureType::TEXTURE_2D )
+  {
+    context.FramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture->GetId(), mipmapLevel );
+  }
+
+  context.BindFramebuffer( GL_FRAMEBUFFER, 0 );
+}
+
+void TextureFrameBuffer::AttachDepthStencilTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel )
+{
+  context.BindFramebuffer( GL_FRAMEBUFFER, mId );
+
+  // Create a stencil attachment.
+  if( texture->GetType() == TextureType::TEXTURE_2D )
+  {
+    context.FramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, texture->GetId(), mipmapLevel );
+  }
+
+  context.BindFramebuffer( GL_FRAMEBUFFER, 0 );
+}
+
 void TextureFrameBuffer::Bind( Context& context )
 {
   context.BindFramebuffer( GL_FRAMEBUFFER, mId );
index 5c297d9..12e44ef 100644 (file)
@@ -94,6 +94,22 @@ public:
   void AttachColorTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer );
 
   /**
+   * @brief Attach a texture for depth rendering. Valid only for Framebuffers with DEPTH attachments.
+   * @param[in] context The GL context
+   * @param[in] texture The texture that will be used as output when rendering
+   * @param[in] mipmapLevel The mipmap of the texture to be attached
+   */
+  void AttachDepthTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel );
+
+  /**
+   * @brief Attach a texture for depth/stencil rendering. Valid only for Framebuffers with DEPTH_STENCIL attachments.
+   * @param[in] context The GL context
+   * @param[in] texture The texture that will be used as output when rendering
+   * @param[in] mipmapLevel The mipmap of the texture to be attached
+   */
+  void AttachDepthStencilTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel );
+
+  /**
    * @brief Get the number of textures bound to this frame buffer as color attachments.
    * @return The number of color attachments.
    */
index 2937453..d6783a1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -517,6 +517,28 @@ void PixelFormatToGl( Pixel::Format pixelFormat, GLenum& glFormat, GLint& glInte
       break;
     }
 
+    // GLES 3.0 depth and stencil formats
+    case Pixel::DEPTH_UNSIGNED_INT:
+    {
+      glFormat = GL_DEPTH_COMPONENT;
+      pixelDataType = GL_UNSIGNED_INT;
+      break;
+    }
+
+    case Pixel::DEPTH_FLOAT:
+    {
+      glFormat = GL_DEPTH_COMPONENT;
+      pixelDataType = GL_FLOAT;
+      break;
+    }
+
+    case Pixel::DEPTH_STENCIL:
+    {
+      glFormat = GL_DEPTH_STENCIL;
+      pixelDataType = GL_UNSIGNED_INT_24_8;
+      break;
+    }
+
     case Pixel::INVALID:
     {
       DALI_LOG_ERROR( "Invalid pixel format for bitmap\n" );
@@ -533,6 +555,16 @@ void PixelFormatToGl( Pixel::Format pixelFormat, GLenum& glFormat, GLint& glInte
       glInternalFormat = GL_R11F_G11F_B10F;
       break;
     }
+    case Pixel::DEPTH_FLOAT:
+    {
+      glInternalFormat = GL_DEPTH_COMPONENT32F;
+      break;
+    }
+    case Pixel::DEPTH_STENCIL:
+    {
+      glInternalFormat = GL_DEPTH24_STENCIL8;
+      break;
+    }
     default:
     {
       glInternalFormat = glFormat;
@@ -568,6 +600,9 @@ bool IsCompressedFormat(Pixel::Format pixelFormat)
     case Pixel::BGRA8888:
     case Pixel::RGB16F:
     case Pixel::RGB32F:
+    case Pixel::DEPTH_UNSIGNED_INT:
+    case Pixel::DEPTH_FLOAT:
+    case Pixel::DEPTH_STENCIL:
     case Pixel::INVALID:
     {
       return false;
index baa2cd1..129c88a 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -1412,6 +1412,28 @@ void UpdateManager::AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameB
   new (slot) DerivedType( &mImpl->renderManager,  &RenderManager::AttachColorTextureToFrameBuffer, frameBuffer, texture, mipmapLevel, layer );
 }
 
+void UpdateManager::AttachDepthTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel )
+{
+  typedef MessageValue3< RenderManager, Render::FrameBuffer*, Render::Texture*, uint32_t > DerivedType;
+
+  // Reserve some memory inside the render queue
+  uint32_t* slot = mImpl->renderQueue.ReserveMessageSlot( mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof( DerivedType ) );
+
+  // Construct message in the render queue memory; note that delete should not be called on the return value
+  new (slot) DerivedType( &mImpl->renderManager,  &RenderManager::AttachDepthTextureToFrameBuffer, frameBuffer, texture, mipmapLevel );
+}
+
+void UpdateManager::AttachDepthStencilTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel )
+{
+  typedef MessageValue3< RenderManager, Render::FrameBuffer*, Render::Texture*, uint32_t > DerivedType;
+
+  // Reserve some memory inside the render queue
+  uint32_t* slot = mImpl->renderQueue.ReserveMessageSlot( mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof( DerivedType ) );
+
+  // Construct message in the render queue memory; note that delete should not be called on the return value
+  new (slot) DerivedType( &mImpl->renderManager,  &RenderManager::AttachDepthStencilTextureToFrameBuffer, frameBuffer, texture, mipmapLevel );
+}
+
 } // namespace SceneGraph
 
 } // namespace Internal
index 72df33c..e13ae28 100755 (executable)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -578,6 +578,22 @@ public:
    */
   void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t face );
 
+  /**
+   * Attach a texture as depth output to an existing FrameBuffer
+   * @param[in] frameBuffer The FrameBuffer
+   * @param[in] texture The texture that will be used as output when rendering
+   * @param[in] mipmapLevel The mipmap of the texture to be attached
+   */
+  void AttachDepthTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel );
+
+  /**
+   * Attach a texture as depth/stencil output to an existing FrameBuffer
+   * @param[in] frameBuffer The FrameBuffer
+   * @param[in] texture The texture that will be used as output when rendering
+   * @param[in] mipmapLevel The mipmap of the texture to be attached
+   */
+  void AttachDepthStencilTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel );
+
 public:
 
   /**
@@ -1393,6 +1409,28 @@ inline void AttachColorTextureToFrameBuffer( UpdateManager& manager, Render::Fra
   new (slot) LocalType( &manager, &UpdateManager::AttachColorTextureToFrameBuffer, &frameBuffer, texture, mipmapLevel, layer );
 }
 
+inline void AttachDepthTextureToFrameBuffer( UpdateManager& manager, Render::FrameBuffer& frameBuffer, Render::Texture* texture, uint32_t mipmapLevel )
+{
+  typedef MessageValue3< UpdateManager, Render::FrameBuffer*, Render::Texture*, uint32_t > LocalType;
+
+  // Reserve some memory inside the message queue
+  uint32_t* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &manager, &UpdateManager::AttachDepthTextureToFrameBuffer, &frameBuffer, texture, mipmapLevel );
+}
+
+inline void AttachDepthStencilTextureToFrameBuffer( UpdateManager& manager, Render::FrameBuffer& frameBuffer, Render::Texture* texture, uint32_t mipmapLevel )
+{
+  typedef MessageValue3< UpdateManager, Render::FrameBuffer*, Render::Texture*, uint32_t > LocalType;
+
+  // Reserve some memory inside the message queue
+  uint32_t* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &manager, &UpdateManager::AttachDepthStencilTextureToFrameBuffer, &frameBuffer, texture, mipmapLevel );
+}
+
 inline void SetDepthIndicesMessage( UpdateManager& manager, OwnerPointer< NodeDepths >& nodeDepths )
 {
   typedef MessageValue1< UpdateManager, OwnerPointer< NodeDepths > > LocalType;
index b50816f..27a99b0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -91,6 +91,9 @@ bool Pixel::HasAlpha(Format pixelformat)
     case COMPRESSED_RGB_PVRTC_4BPPV1:
     case RGB16F:
     case RGB32F:
+    case DEPTH_UNSIGNED_INT:
+    case DEPTH_FLOAT:
+    case DEPTH_STENCIL:
     case INVALID:
     {
       return false;
@@ -129,6 +132,9 @@ uint32_t Pixel::GetBytesPerPixel(Format pixelFormat)
     case BGR8888:
     case RGBA8888:
     case BGRA8888:
+    case DEPTH_UNSIGNED_INT:
+    case DEPTH_FLOAT:
+    case DEPTH_STENCIL:
     {
       return 4;
     }
@@ -288,9 +294,12 @@ void Pixel::GetAlphaOffsetAndMask(Format pixelFormat, int& byteOffset, int& bitM
     case COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
     case RGB16F:
     case RGB32F:
+    case DEPTH_UNSIGNED_INT:
+    case DEPTH_FLOAT:
+    case DEPTH_STENCIL:
     case INVALID:
     {
-      DALI_LOG_ERROR("Pixel formats for compressed images are not compatible with simple masking-out of per-pixel alpha.\n");
+      DALI_LOG_ERROR("Pixel formats are not compatible with simple masking-out of per-pixel alpha.\n");
       byteOffset=0;
       bitMask=0;
       break;
index 26134b8..c03d9df 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_PIXEL_H
 
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -114,6 +114,10 @@ enum Format
   RGB16F, ///< Color depth 48-bit, 16-16-16 half floating point. @SINCE_1_2.60
   RGB32F, ///< Color depth 96-bit, 32-32-32 floating point. @SINCE_1_2.60
 
+  DEPTH_UNSIGNED_INT, ///< Unsigned int depth format 32-bit. @SINCE_1_5_9
+  DEPTH_FLOAT, ///< Float depth format 32-bit. @SINCE_1_5_9
+
+  DEPTH_STENCIL ///< Depth stencil 32-bit, 24 bit for depth, 8 bit for stencil. @SINCE_1_5_9
   ///! Update LAST_VALID_PIXEL_FORMAT below if you add an enum value here.
 };
 
@@ -129,7 +133,7 @@ const Format FIRST_VALID_PIXEL_FORMAT = A8;
  *
  * Sync it to the last value above.
  */
-const Format LAST_VALID_PIXEL_FORMAT = RGB32F;
+const Format LAST_VALID_PIXEL_FORMAT = DEPTH_STENCIL;
 
 /**
  * @brief Whether specified pixel format contains an alpha value.
index 78143a1..ea72349 100644 (file)
@@ -154,7 +154,7 @@ public:
    *
    * @SINCE_1_1.43
    * @param[in] texture The texture that will be used as output when rendering
-   * @note The texture has to have the same size than the FrameBuffer
+   * @note The texture has to have same size as that of FrameBuffer
    * otherwise it won't be attached.
    */
   void AttachColorTexture( Texture& texture );
@@ -169,7 +169,7 @@ public:
    * @param[in] texture The texture that will be used as output when rendering
    * @param[in] mipmapLevel The mipmap of the texture to be attached
    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
-   * @note The specified texture mipmap has to have the same size than the FrameBuffer
+   * @note The mipmapped texture has to have same size as that of FrameBuffer
    * otherwise it won't be attached.
    */
   void AttachColorTexture( Texture& texture, uint32_t mipmapLevel, uint32_t layer );