Ensure BaseHandle class move noexcept (core public-api)
[platform/core/uifw/dali-core.git] / dali / public-api / rendering / frame-buffer.h
1 #ifndef DALI_FRAMEBUFFER_H
2 #define DALI_FRAMEBUFFER_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <cstdint> // uint32_t
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/base-handle.h>
26 #include <dali/public-api/rendering/texture.h>
27
28 namespace Dali
29 {
30 /**
31  * @addtogroup dali_core_rendering_effects
32  * @{
33  */
34
35 namespace Internal DALI_INTERNAL
36 {
37 class FrameBuffer;
38 }
39
40 /**
41  * @brief FrameBuffer is a collection of textures that can be used as the destination for rendering.
42  * @SINCE_1_1.43
43  */
44 class DALI_CORE_API FrameBuffer : public BaseHandle
45 {
46 public:
47   /**
48    * @brief The initial attachments to create the FrameBuffer with.
49    * @note The color attachment can also be created on calling AttachColorTexture().
50    * @note With "NONE", no attachments are created initially. However color attachments can still be added as described above.
51    *
52    * @SINCE_1_1.45
53    */
54   struct Attachment
55   {
56     /**
57      * @brief Enumeration for the attachments and/or textures to be created by default
58      * @SINCE_1_1.45
59      */
60     enum Mask
61     {
62       NONE                = 0,                    ///< No attachments are created initially.         @SINCE_1_1.45
63       DEPTH               = 1 << 0,               ///< Depth buffer is created.                      @SINCE_1_1.45
64       STENCIL             = 1 << 1,               ///< Stencil buffer is created.                    @SINCE_1_1.45
65       DEPTH_STENCIL       = DEPTH | STENCIL,      ///< Depth and stencil buffer are created.         @SINCE_1_1.45
66       COLOR               = 1 << 2,               ///< Color texture is created.                     @SINCE_1_4.0
67       COLOR_DEPTH         = COLOR | DEPTH,        ///< Color texture and depth buffer are created.   @SINCE_1_4.0
68       COLOR_STENCIL       = COLOR | STENCIL,      ///< Color texture and stencil buffer are created. @SINCE_1_4.0
69       COLOR_DEPTH_STENCIL = COLOR_DEPTH | STENCIL ///< Color, depth and stencil buffer are created.  @SINCE_1_4.0
70     };
71   };
72
73   /**
74    * @brief Creates a new FrameBuffer, which attaches only COLOR texture.
75    *
76    * @SINCE_1_4.0
77    *
78    * @note Call GetColorTexture() to get the COLOR texture
79    *
80    * @param[in] width The width of the FrameBuffer and the color texture
81    * @param[in] height The height of the FrameBuffer and the color texture
82    * @return A handle to a newly allocated FrameBuffer
83    */
84   static FrameBuffer New(uint32_t width, uint32_t height);
85
86   /**
87    * @brief Creates a new FrameBuffer with specific attachments.
88    *
89    * @SINCE_1_4.0
90    *
91    * @param[in] width The width of the FrameBuffer and the attachments
92    * @param[in] height The height of the FrameBuffer and the attachments
93    * @param[in] attachments Enumeration of the attachments to create
94    * @return A handle to a newly allocated FrameBuffer
95    */
96   static FrameBuffer New(uint32_t width, uint32_t height, Attachment::Mask attachments);
97
98   /**
99    * @brief Default constructor, creates an empty handle.
100    */
101   FrameBuffer();
102
103   /**
104    * @brief Destructor.
105    * @SINCE_1_1.43
106    */
107   ~FrameBuffer();
108
109   /**
110    * @brief Copy constructor, creates a new handle to the same object.
111    *
112    * @SINCE_1_1.43
113    * @param[in] handle Handle to an object
114    */
115   FrameBuffer(const FrameBuffer& handle);
116
117   /**
118    * @brief Downcasts to a FrameBuffer.
119    * If not, the returned handle is left uninitialized.
120    * @SINCE_1_1.43
121    * @param[in] handle Handle to an object
122    * @return FrameBuffer handle or an uninitialized handle
123    */
124   static FrameBuffer DownCast(BaseHandle handle);
125
126   /**
127    * @brief Assignment operator, changes this handle to point at the same object.
128    *
129    * @SINCE_1_1.43
130    * @param[in] handle Handle to an object
131    * @return Reference to the assigned object
132    */
133   FrameBuffer& operator=(const FrameBuffer& handle);
134
135   /**
136    * @brief Move constructor.
137    *
138    * @SINCE_1_9.22
139    * @param[in] rhs A reference to the moved handle
140    */
141   FrameBuffer(FrameBuffer&& rhs) noexcept;
142
143   /**
144    * @brief Move assignment operator.
145    *
146    * @SINCE_1_9.22
147    * @param[in] rhs A reference to the moved handle
148    * @return A reference to this handle
149    */
150   FrameBuffer& operator=(FrameBuffer&& rhs) noexcept;
151
152   /**
153    * @brief Attach the base LOD of a 2D texture to the framebuffer for color rendering.
154    * @note This causes a color attachment to be added.
155    * @note Repeated calls to this method add textures as subsequent color attachments.
156    * @note A maximum of 8 color attachments are supported.
157    *
158    * @SINCE_1_1.43
159    * @param[in] texture The texture that will be used as output when rendering
160    * @note The texture has to have same size as that of FrameBuffer
161    * otherwise it won't be attached.
162    */
163   void AttachColorTexture(Texture& texture);
164
165   /**
166    * @brief Attach a texture to the framebuffer for color rendering.
167    * @note This causes a color attachment to be added.
168    * @note Repeated calls to this method add textures as subsequent color attachments.
169    * @note A maximum of 8 color attachments are supported.
170    *
171    * @SINCE_1_1.43
172    * @param[in] texture The texture that will be used as output when rendering
173    * @param[in] mipmapLevel The mipmap of the texture to be attached
174    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
175    * @note The mipmapped texture has to have same size as that of FrameBuffer
176    * otherwise it won't be attached.
177    */
178   void AttachColorTexture(Texture& texture, uint32_t mipmapLevel, uint32_t layer);
179
180   /**
181    * @brief Gets the first color texture used as output in the FrameBuffer.
182    *
183    * @SINCE_1_1.43
184    * @returns A handle to the texture used as color output, or an uninitialized handle
185    */
186   Texture GetColorTexture();
187
188 public:
189   /**
190    * @brief The constructor.
191    * @note  Not intended for application developers.
192    * @SINCE_1_1.43
193    * @param[in] pointer A pointer to a newly allocated FrameBuffer
194    */
195   explicit DALI_INTERNAL FrameBuffer(Internal::FrameBuffer* pointer);
196 };
197
198 /**
199  * @}
200  */
201 } //namespace Dali
202
203 #endif // DALI_FRAMEBUFFER_H