Add an easier to use New in FrameBuffer for the 99% of the cases where we use offscreens 58/194558/5
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Wed, 5 Dec 2018 18:17:16 +0000 (18:17 +0000)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Thu, 6 Dec 2018 14:57:28 +0000 (14:57 +0000)
- Deprecated the unsafe version which allows enum to be passed in as uint32_t

Change-Id: I9c28f06d26c25ce1d84e840e7a46056d6760208a

automated-tests/src/dali/utc-Dali-FrameBuffer.cpp
dali/internal/event/images/frame-buffer-image-impl.cpp
dali/internal/event/rendering/frame-buffer-impl.cpp
dali/internal/event/rendering/frame-buffer-impl.h
dali/internal/render/renderers/render-frame-buffer.cpp
dali/internal/render/renderers/render-frame-buffer.h
dali/public-api/rendering/frame-buffer.cpp
dali/public-api/rendering/frame-buffer.h

index 041e1bbddebb6126c38fd6ea9e7acc2bd65911b0..e19a7f8847a9ef1521acdb38b1e45934c30e459c 100644 (file)
@@ -140,6 +140,86 @@ int UtcDaliFrameBufferNew06(void)
   END_TEST;
 }
 
+int UtcDaliFrameBufferNewWithColor01(void)
+{
+  TestApplication application;
+  uint32_t width = 64;
+  uint32_t height = 64;
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height );
+  application.SendNotification();
+  application.Render();
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+  // check that texture is not empty handle
+  DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
+  END_TEST;
+}
+
+int UtcDaliFrameBufferNewWithColor02(void)
+{
+  TestApplication application;
+  uint32_t width = 64;
+  uint32_t height = 64;
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::COLOR );
+  application.SendNotification();
+  application.Render();
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+  // check that texture is not empty handle
+  DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
+  END_TEST;
+}
+
+int UtcDaliFrameBufferNewWithColor03(void)
+{
+  TestApplication application;
+  uint32_t width = 64;
+  uint32_t height = 64;
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::COLOR_DEPTH );
+  application.SendNotification();
+  application.Render();
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+  // check that texture is not empty handle
+  DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
+  END_TEST;
+}
+
+int UtcDaliFrameBufferNewWithColor04(void)
+{
+  TestApplication application;
+  uint32_t width = 64;
+  uint32_t height = 64;
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::COLOR_STENCIL );
+  application.SendNotification();
+  application.Render();
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  // check that texture is not empty handle
+  DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
+  END_TEST;
+}
+
+int UtcDaliFrameBufferNewWithColor05(void)
+{
+  TestApplication application;
+  uint32_t width = 64;
+  uint32_t height = 64;
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::COLOR_DEPTH_STENCIL );
+  application.SendNotification();
+  application.Render();
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  // check that texture is not empty handle
+  DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
+  END_TEST;
+}
+
 int UtcDaliFrameBufferCopyConstructor(void)
 {
   TestApplication application;
index def730ab433dde213508fdf580bb1ceaa068226e..b5a4439c41cdf6146a2f66c5f1c6325ed47150a3 100644 (file)
@@ -30,12 +30,11 @@ namespace Internal
 
 namespace
 {
-const int RenderBufferFormatToFrameBufferAttachments[]  = { Dali::FrameBuffer::Attachment::NONE,
-                                                            Dali::FrameBuffer::Attachment::DEPTH,
-                                                            Dali::FrameBuffer::Attachment::STENCIL,
-                                                            Dali::FrameBuffer::Attachment::DEPTH_STENCIL
-                                                          };
-
+const Dali::FrameBuffer::Attachment::Mask RenderBufferFormatToFrameBufferAttachments[]  =
+  { Dali::FrameBuffer::Attachment::NONE,
+    Dali::FrameBuffer::Attachment::DEPTH,
+    Dali::FrameBuffer::Attachment::STENCIL,
+    Dali::FrameBuffer::Attachment::DEPTH_STENCIL };
 } // unnamed namespace
 
 FrameBufferImagePtr FrameBufferImage::New( unsigned int width,
index 20d09d3ccac2cd63f1517b5aa67266c45e9a3422..ccfc8d051123d93e71385878920d10b087ce02fd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -28,7 +28,7 @@ namespace Dali
 namespace Internal
 {
 
-FrameBufferPtr FrameBuffer::New( unsigned int width, unsigned int height, unsigned int attachments  )
+FrameBufferPtr FrameBuffer::New( uint32_t width, uint32_t height, Mask attachments  )
 {
   FrameBufferPtr frameBuffer( new FrameBuffer( width, height, attachments ) );
   frameBuffer->Initialize();
@@ -41,7 +41,7 @@ Render::FrameBuffer* FrameBuffer::GetRenderObject() const
   return mRenderObject;
 }
 
-FrameBuffer::FrameBuffer( unsigned int width, unsigned int height, unsigned int attachments )
+FrameBuffer::FrameBuffer( uint32_t width, uint32_t height, Mask attachments )
 : mEventThreadServices( *Stage::GetCurrent() ),
   mRenderObject( NULL ),
   mColor( NULL ),
@@ -57,7 +57,7 @@ void FrameBuffer::Initialize()
   AddFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject );
 }
 
-void FrameBuffer::AttachColorTexture( TexturePtr texture, unsigned int mipmapLevel, unsigned int layer )
+void FrameBuffer::AttachColorTexture( TexturePtr texture, uint32_t mipmapLevel, uint32_t layer )
 {
   if( ( texture->GetWidth() / ( 1u << mipmapLevel ) == mWidth ) &&
       ( texture->GetHeight() / ( 1u << mipmapLevel ) == mHeight ) )
index 8b0f7762294f67fc973c283653258768bd453afe..938919300bd5fd446f6e0fdda13bf298c343d269 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_FRAME_BUFFER_H
 
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -42,6 +42,8 @@ class FrameBuffer : public BaseObject
 {
 public:
 
+  using Mask = Dali::FrameBuffer::Attachment::Mask;
+
   /**
    * @brief Create a new FrameBuffer
    *
@@ -50,7 +52,7 @@ public:
    * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask)
    * @return A smart-pointer to the newly allocated Texture.
    */
-  static FrameBufferPtr New( unsigned int width, unsigned int height, unsigned int attachments );
+  static FrameBufferPtr New( uint32_t width, uint32_t height, Mask attachments );
 
   /**
    * @brief Get the FrameBuffer render object
@@ -62,7 +64,7 @@ public:
   /**
    * @copydoc Dali::FrameBuffer::AttachColorTexture()
    */
-  void AttachColorTexture( TexturePtr texture, unsigned int mipmapLevel, unsigned int layer );
+  void AttachColorTexture( TexturePtr texture, uint32_t mipmapLevel, uint32_t layer );
 
   /**
    * @copydoc Dali::FrameBuffer::GetColorTexture()
@@ -77,7 +79,7 @@ private: // implementation
    * @param[in] height      The height of the FrameBuffer
    * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask)
    */
-  FrameBuffer( unsigned int width, unsigned int height, unsigned int attachments );
+  FrameBuffer( uint32_t width, uint32_t height, Mask attachments );
 
   /**
    * Second stage initialization of the Texture
@@ -92,8 +94,10 @@ protected:
   virtual ~FrameBuffer();
 
 private: // unimplemented methods
-  FrameBuffer( const FrameBuffer& );
-  FrameBuffer& operator=( const FrameBuffer& );
+
+  FrameBuffer() = delete;
+  FrameBuffer( const FrameBuffer& ) = delete;
+  FrameBuffer& operator=( const FrameBuffer& ) = delete;
 
 private: // data
 
@@ -101,9 +105,9 @@ private: // data
   Internal::Render::FrameBuffer* mRenderObject;        ///< The Render::Texture associated to this texture
 
   TexturePtr mColor;
-  unsigned int mWidth;
-  unsigned int mHeight;
-  unsigned int mAttachments;                           ///< Bit-mask of type FrameBuffer::Attachment::Mask
+  uint32_t mWidth;
+  uint32_t mHeight;
+  Mask mAttachments;                           ///< Bit-mask of type FrameBuffer::Attachment::Mask
 
 };
 
index a9d351c2f701964225cb98975d3d709f03383a3d..2ea746e41490f4e40f87e15e73b611729b1b247c 100644 (file)
@@ -27,7 +27,7 @@ namespace Internal
 namespace Render
 {
 
-FrameBuffer::FrameBuffer( uint32_t width, uint32_t height, uint32_t attachments )
+FrameBuffer::FrameBuffer( uint32_t width, uint32_t height, Mask attachments )
 :mId( 0u ),
  mDepthBuffer( attachments & Dali::FrameBuffer::Attachment::DEPTH ),
  mStencilBuffer( attachments & Dali::FrameBuffer::Attachment::STENCIL ),
index 3cf711059da9fb1fda47986ea8db2caaabbf92d6..196630dfc4d217f6abf67cb9d279925bd1299b08 100644 (file)
@@ -35,13 +35,15 @@ class FrameBuffer
 {
 public:
 
+  using Mask = Dali::FrameBuffer::Attachment::Mask;
+
   /**
    * Constructor
    * @param[in] width The width of the FrameBuffer
    * @param[in] height The height of the FrameBuffer
    * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask)
    */
-  FrameBuffer( uint32_t width, uint32_t height, uint32_t attachments );
+  FrameBuffer( uint32_t width, uint32_t height, Mask attachments );
 
   /**
    * Destructor
index 607a79bc0788861615adf6ea93cd5a23cd5b8c7f..0b86092089eda4e1c35a782ccb47d63921060fbf 100644 (file)
 #include <dali/public-api/rendering/frame-buffer.h>
 
 // INTERNAL INCLUDES
+#include <dali/integration-api/debug.h> // DALI_LOG_WARNING_NOFN
 #include <dali/internal/event/rendering/frame-buffer-impl.h> // Dali::Internal::FrameBuffer
-
+#include <dali/internal/event/rendering/texture-impl.h> // Dali::Internal::Texture
 
 namespace Dali
 {
 
-FrameBuffer FrameBuffer::New( uint32_t width, uint32_t height, uint32_t attachments )
+FrameBuffer FrameBuffer::New( uint32_t width, uint32_t height )
+{
+  return New( width, height, FrameBuffer::Attachment::COLOR );
+}
+
+FrameBuffer FrameBuffer::New( uint32_t width, uint32_t height, Attachment::Mask attachments )
 {
   Internal::FrameBufferPtr frameBuffer = Internal::FrameBuffer::New( width, height, attachments );
+  if( attachments & FrameBuffer::Attachment::COLOR )
+  {
+    Internal::TexturePtr texture = Internal::Texture::New( Dali::TextureType::TEXTURE_2D, Pixel::RGB888, width, height );
+    frameBuffer->AttachColorTexture( texture, 0u, 0u );
+  }
+  return FrameBuffer( frameBuffer.Get() );
+}
+
+FrameBuffer FrameBuffer::New( uint32_t width, uint32_t height, uint32_t attachments )
+{
+  DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: FrameBuffer::New(uint32_t,uint32_t,uint32_t) is deprecated and will be removed from next release. use New(uint32_t, uint32_t,Attachment::Mask) instead.\n" );
+  // have to static cast, which according to standard since C++11 is undefined behaviour, hence this variant is deprecated
+  Internal::FrameBufferPtr frameBuffer = Internal::FrameBuffer::New( width, height, static_cast<Attachment::Mask>( attachments ) );
   return FrameBuffer( frameBuffer.Get() );
 }
 
index 30c5e6de4d0bdc756018be285eeb8246c148c167..b80630c8ae647490d03c8e9d4459dc1c8382154e 100644 (file)
@@ -43,7 +43,7 @@ public:
 
   /**
    * @brief The initial attachments to create the FrameBuffer with.
-   * @note The color attachment is created on calling AttachColorTexture(). If a color attachment is not required, omit this call.
+   * @note The color attachment can also be created on calling AttachColorTexture().
    * @note With "NONE", no attachments are created initially. However color attachments can still be added as described above.
    *
    * @SINCE_1_1.45
@@ -51,25 +51,53 @@ public:
   struct Attachment
   {
     /**
-     * @brief Enumeration for the bit-mask value.
+     * @brief Enumeration for the attachments and/or textures to be created by default
      * @SINCE_1_1.45
      */
     enum Mask
     {
-      NONE          = 0,               ///< No attachments are created initially                            @SINCE_1_1.45
-
-      DEPTH         = 1 << 0,          ///< Depth buffer bit-mask value                                     @SINCE_1_1.45
-      STENCIL       = 1 << 1,          ///< Stencil buffer bit-mask value                                   @SINCE_1_1.45
-
-      // Preset bit-mask combinations:
-      DEPTH_STENCIL = DEPTH | STENCIL  ///< The Framebuffer will be created with depth and stencil buffer   @SINCE_1_1.45
+      NONE          = 0,                          ///< No attachments are created initially             @SINCE_1_1.45
+      DEPTH         = 1 << 0,                     ///< Depth buffer is created                          @SINCE_1_1.45
+      STENCIL       = 1 << 1,                     ///< Stencil buffer is created                        @SINCE_1_1.45
+      DEPTH_STENCIL = DEPTH | STENCIL,            ///< Depth and stencil buffer will be created         @SINCE_1_1.45
+      COLOR         = 1 << 2,                     ///< Color texture will be created                    @SINCE_1_3.54
+      COLOR_DEPTH   = COLOR | DEPTH,              ///< Color texture and depth buffer will be created   @SINCE_1_3.54
+      COLOR_STENCIL = COLOR | STENCIL,            ///< Color texture and stencil buffer will be created @SINCE_1_3.54
+      COLOR_DEPTH_STENCIL = COLOR_DEPTH | STENCIL ///< Color, depth and stencil buffer will be created  @SINCE_1_3.54
     };
   };
 
   /**
+   * @brief Creates a new FrameBuffer with only COLOR texture attached on it
+   *
+   * @SINCE_1_3.54
+   *
+   * @note Call GetColorTexture() to get the COLOR texture
+   *
+   * @param[in] width The width of the FrameBuffer and the color texture
+   * @param[in] height The height of the FrameBuffer and the color texture
+   * @return A handle to a newly allocated FrameBuffer
+   */
+  static FrameBuffer New( uint32_t width, uint32_t height );
+
+  /**
+   * @brief Creates a new FrameBuffer with the specified attachments
+   *
+   * @SINCE_1_3.54
+   *
+   * @param[in] width The width of the FrameBuffer and the attachments
+   * @param[in] height The height of the FrameBuffer and the attachments
+   * @param[in] attachments Enumeration of the attachments to create
+   * @return A handle to a newly allocated FrameBuffer
+   */
+  static FrameBuffer New( uint32_t width, uint32_t height, Attachment::Mask attachments );
+
+  /**
+   * @DEPRECATED_1_3.54 use New( uint32_t width, uint32_t height ) or New( uint32_t width, uint32_t height, Attachment::Mask attachments ) instead
    * @brief Creates a new FrameBuffer object.
    *
    * @SINCE_1_1.43
+   *
    * @param[in] width The width of the FrameBuffer
    * @param[in] height The height of the FrameBuffer
    * @param[in] attachments The attachments comprising the format of the FrameBuffer (the type is int to allow multiple bitmasks to be ORd)