Merge "Added support for Multiple Render Targets, to Dali::FrameBuffer." into devel...
[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) 2018 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 Maximum number of color attachments supported.
76    */
77   static constexpr uint8_t MAX_COLOR_ATTACHMENTS = 8;
78
79   /**
80    * @brief Creates a new FrameBuffer, which attaches only COLOR texture.
81    *
82    * @SINCE_1_4.0
83    *
84    * @note Call GetColorTexture() to get the COLOR texture
85    *
86    * @param[in] width The width of the FrameBuffer and the color texture
87    * @param[in] height The height of the FrameBuffer and the color texture
88    * @return A handle to a newly allocated FrameBuffer
89    */
90   static FrameBuffer New( uint32_t width, uint32_t height );
91
92   /**
93    * @brief Creates a new FrameBuffer with specific attachments.
94    *
95    * @SINCE_1_4.0
96    *
97    * @param[in] width The width of the FrameBuffer and the attachments
98    * @param[in] height The height of the FrameBuffer and the attachments
99    * @param[in] attachments Enumeration of the attachments to create
100    * @return A handle to a newly allocated FrameBuffer
101    */
102   static FrameBuffer New( uint32_t width, uint32_t height, Attachment::Mask attachments );
103
104   /**
105    * @DEPRECATED_1_4.0 use New( uint32_t width, uint32_t height ) or New( uint32_t width, uint32_t height, Attachment::Mask attachments ) instead
106    * @brief Creates a new FrameBuffer object.
107    *
108    * @SINCE_1_1.43
109    *
110    * @param[in] width The width of the FrameBuffer
111    * @param[in] height The height of the FrameBuffer
112    * @param[in] attachments The attachments comprising the format of the FrameBuffer (the type is int to allow multiple bitmasks to be ORd)
113    * @return A handle to a newly allocated FrameBuffer
114    */
115   static FrameBuffer New( uint32_t width, uint32_t height, uint32_t attachments );
116
117   /**
118    * @brief Default constructor, creates an empty handle.
119    */
120   FrameBuffer();
121
122   /**
123    * @brief Destructor.
124    * @SINCE_1_1.43
125    */
126   ~FrameBuffer();
127
128   /**
129    * @brief Copy constructor, creates a new handle to the same object.
130    *
131    * @SINCE_1_1.43
132    * @param[in] handle Handle to an object
133    */
134   FrameBuffer( const FrameBuffer& handle );
135
136   /**
137    * @brief Downcasts to a FrameBuffer.
138    * If not, the returned handle is left uninitialized.
139    * @SINCE_1_1.43
140    * @param[in] handle Handle to an object
141    * @return FrameBuffer handle or an uninitialized handle
142    */
143   static FrameBuffer DownCast( BaseHandle handle );
144
145   /**
146    * @brief Assignment operator, changes this handle to point at the same object.
147    *
148    * @SINCE_1_1.43
149    * @param[in] handle Handle to an object
150    * @return Reference to the assigned object
151    */
152   FrameBuffer& operator=( const FrameBuffer& handle );
153
154   /**
155    * @brief Attach the base LOD of a 2D texture to the framebuffer for color rendering.
156    * @note This causes a color attachment to be added.
157    * @note Repeated calls to this method add textures as subsequent color attachments.
158    * @note A maximum of 8 color attachments are supported.
159    *
160    * @SINCE_1_1.43
161    * @param[in] texture The texture that will be used as output when rendering
162    * @note The texture has to have the same size than the FrameBuffer
163    * otherwise it won't be attached.
164    */
165   void AttachColorTexture( Texture& texture );
166
167   /**
168    * @brief Attach a texture to the framebuffer for color rendering.
169    * @note This causes a color attachment to be added.
170    * @note Repeated calls to this method add textures as subsequent color attachments.
171    * @note A maximum of 8 color attachments are supported.
172    *
173    * @SINCE_1_1.43
174    * @param[in] texture The texture that will be used as output when rendering
175    * @param[in] mipmapLevel The mipmap of the texture to be attached
176    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
177    * @note The specified texture mipmap has to have the same size than the FrameBuffer
178    * otherwise it won't be attached.
179    */
180   void AttachColorTexture( Texture& texture, uint32_t mipmapLevel, uint32_t layer );
181
182   /**
183    * @brief Gets the first color texture used as output in the FrameBuffer.
184    *
185    * @SINCE_1_1.43
186    * @returns A handle to the texture used as color output, or an uninitialized handle
187    */
188   Texture GetColorTexture() const;
189
190   /**
191    * @brief Gets the color texture at the given @a index used as output in the FrameBuffer.
192    * @note A maximum of 8 color attachments are supported. Passing an invalid index will return
193    * an uninitialized handle.
194    *
195    * @SINCE_1_1.43
196    * @returns A handle to the texture used as color output, or an uninitialized handle
197    */
198   Texture GetColorTexture(uint8_t index) const;
199
200 public:
201
202   /**
203    * @brief The constructor.
204    * @note  Not intended for application developers.
205    * @SINCE_1_1.43
206    * @param[in] pointer A pointer to a newly allocated FrameBuffer
207    */
208   explicit DALI_INTERNAL FrameBuffer( Internal::FrameBuffer* pointer );
209 };
210
211 /**
212  * @}
213  */
214 } //namespace Dali
215
216 #endif // DALI_FRAMEBUFFER_H