Add move semantics to commonly used classes in dali-core
[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   /**
49    * @brief The initial attachments to create the FrameBuffer with.
50    * @note The color attachment can also be created on calling AttachColorTexture().
51    * @note With "NONE", no attachments are created initially. However color attachments can still be added as described above.
52    *
53    * @SINCE_1_1.45
54    */
55   struct Attachment
56   {
57     /**
58      * @brief Enumeration for the attachments and/or textures to be created by default
59      * @SINCE_1_1.45
60      */
61     enum Mask
62     {
63       NONE          = 0,                          ///< No attachments are created initially.         @SINCE_1_1.45
64       DEPTH         = 1 << 0,                     ///< Depth buffer is created.                      @SINCE_1_1.45
65       STENCIL       = 1 << 1,                     ///< Stencil buffer is created.                    @SINCE_1_1.45
66       DEPTH_STENCIL = DEPTH | STENCIL,            ///< Depth and stencil buffer are created.         @SINCE_1_1.45
67       COLOR         = 1 << 2,                     ///< Color texture is created.                     @SINCE_1_4.0
68       COLOR_DEPTH   = COLOR | DEPTH,              ///< Color texture and depth buffer are created.   @SINCE_1_4.0
69       COLOR_STENCIL = COLOR | STENCIL,            ///< Color texture and stencil buffer are created. @SINCE_1_4.0
70       COLOR_DEPTH_STENCIL = COLOR_DEPTH | STENCIL ///< Color, depth and stencil buffer are created.  @SINCE_1_4.0
71     };
72   };
73
74   /**
75    * @brief Creates a new FrameBuffer, which attaches only COLOR texture.
76    *
77    * @SINCE_1_4.0
78    *
79    * @note Call GetColorTexture() to get the COLOR texture
80    *
81    * @param[in] width The width of the FrameBuffer and the color texture
82    * @param[in] height The height of the FrameBuffer and the color texture
83    * @return A handle to a newly allocated FrameBuffer
84    */
85   static FrameBuffer New( uint32_t width, uint32_t height );
86
87   /**
88    * @brief Creates a new FrameBuffer with specific attachments.
89    *
90    * @SINCE_1_4.0
91    *
92    * @param[in] width The width of the FrameBuffer and the attachments
93    * @param[in] height The height of the FrameBuffer and the attachments
94    * @param[in] attachments Enumeration of the attachments to create
95    * @return A handle to a newly allocated FrameBuffer
96    */
97   static FrameBuffer New( uint32_t width, uint32_t height, Attachment::Mask attachments );
98
99   /**
100    * @brief Default constructor, creates an empty handle.
101    */
102   FrameBuffer();
103
104   /**
105    * @brief Destructor.
106    * @SINCE_1_1.43
107    */
108   ~FrameBuffer();
109
110   /**
111    * @brief Copy constructor, creates a new handle to the same object.
112    *
113    * @SINCE_1_1.43
114    * @param[in] handle Handle to an object
115    */
116   FrameBuffer( const FrameBuffer& handle );
117
118   /**
119    * @brief Downcasts to a FrameBuffer.
120    * If not, the returned handle is left uninitialized.
121    * @SINCE_1_1.43
122    * @param[in] handle Handle to an object
123    * @return FrameBuffer handle or an uninitialized handle
124    */
125   static FrameBuffer DownCast( BaseHandle handle );
126
127   /**
128    * @brief Assignment operator, changes this handle to point at the same object.
129    *
130    * @SINCE_1_1.43
131    * @param[in] handle Handle to an object
132    * @return Reference to the assigned object
133    */
134   FrameBuffer& operator=( const FrameBuffer& handle );
135
136   /**
137    * @brief Move constructor.
138    *
139    * @SINCE_1_9.22
140    * @param[in] rhs A reference to the moved handle
141    */
142   FrameBuffer( FrameBuffer&& rhs );
143
144   /**
145    * @brief Move assignment operator.
146    *
147    * @SINCE_1_9.22
148    * @param[in] rhs A reference to the moved handle
149    * @return A reference to this handle
150    */
151   FrameBuffer& operator=( FrameBuffer&& rhs );
152
153   /**
154    * @brief Attach the base LOD of a 2D texture to the framebuffer for color rendering.
155    * @note This causes a color attachment to be added.
156    * @note Repeated calls to this method add textures as subsequent color attachments.
157    * @note A maximum of 8 color attachments are supported.
158    *
159    * @SINCE_1_1.43
160    * @param[in] texture The texture that will be used as output when rendering
161    * @note The texture has to have same size as that of FrameBuffer
162    * otherwise it won't be attached.
163    */
164   void AttachColorTexture( Texture& texture );
165
166   /**
167    * @brief Attach a texture to the framebuffer for color rendering.
168    * @note This causes a color attachment to be added.
169    * @note Repeated calls to this method add textures as subsequent color attachments.
170    * @note A maximum of 8 color attachments are supported.
171    *
172    * @SINCE_1_1.43
173    * @param[in] texture The texture that will be used as output when rendering
174    * @param[in] mipmapLevel The mipmap of the texture to be attached
175    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
176    * @note The mipmapped texture has to have same size as that of FrameBuffer
177    * otherwise it won't be attached.
178    */
179   void AttachColorTexture( Texture& texture, uint32_t mipmapLevel, uint32_t layer );
180
181   /**
182    * @brief Gets the first color texture used as output in the FrameBuffer.
183    *
184    * @SINCE_1_1.43
185    * @returns A handle to the texture used as color output, or an uninitialized handle
186    */
187   Texture GetColorTexture();
188
189 public:
190
191   /**
192    * @brief The constructor.
193    * @note  Not intended for application developers.
194    * @SINCE_1_1.43
195    * @param[in] pointer A pointer to a newly allocated FrameBuffer
196    */
197   explicit DALI_INTERNAL FrameBuffer( Internal::FrameBuffer* pointer );
198 };
199
200 /**
201  * @}
202  */
203 } //namespace Dali
204
205 #endif // DALI_FRAMEBUFFER_H