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