Making DALi public API typesafe using guaranteed types; uint8_t, uint32_t
[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 is created on calling AttachColorTexture(). If a color attachment is not required, omit this call.
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 bit-mask value.
55      * @SINCE_1_1.45
56      */
57     enum Mask
58     {
59       NONE          = 0,               ///< No attachments are created initially                            @SINCE_1_1.45
60
61       DEPTH         = 1 << 0,          ///< Depth buffer bit-mask value                                     @SINCE_1_1.45
62       STENCIL       = 1 << 1,          ///< Stencil buffer bit-mask value                                   @SINCE_1_1.45
63
64       // Preset bit-mask combinations:
65       DEPTH_STENCIL = DEPTH | STENCIL  ///< The Framebuffer will be created with depth and stencil buffer   @SINCE_1_1.45
66     };
67   };
68
69   /**
70    * @brief Creates a new FrameBuffer object.
71    *
72    * @SINCE_1_1.43
73    * @param[in] width The width of the FrameBuffer
74    * @param[in] height The height of the FrameBuffer
75    * @param[in] attachments The attachments comprising the format of the FrameBuffer (the type is int to allow multiple bitmasks to be ORd)
76    * @return A handle to a newly allocated FrameBuffer
77    */
78   static FrameBuffer New( uint32_t width, uint32_t height, uint32_t attachments );
79
80   /**
81    * @brief Default constructor, creates an empty handle.
82    */
83   FrameBuffer();
84
85   /**
86    * @brief Destructor.
87    * @SINCE_1_1.43
88    */
89   ~FrameBuffer();
90
91   /**
92    * @brief Copy constructor, creates a new handle to the same object.
93    *
94    * @SINCE_1_1.43
95    * @param[in] handle Handle to an object
96    */
97   FrameBuffer( const FrameBuffer& handle );
98
99   /**
100    * @brief Downcasts to a FrameBuffer.
101    * If not, the returned handle is left uninitialized.
102    * @SINCE_1_1.43
103    * @param[in] handle Handle to an object
104    * @return FrameBuffer handle or an uninitialized handle
105    */
106   static FrameBuffer DownCast( BaseHandle handle );
107
108   /**
109    * @brief Assignment operator, changes this handle to point at the same object.
110    *
111    * @SINCE_1_1.43
112    * @param[in] handle Handle to an object
113    * @return Reference to the assigned object
114    */
115   FrameBuffer& operator=( const FrameBuffer& handle );
116
117   /**
118    * @brief Attach the base LOD of a 2D texture to the framebuffer for color rendering.
119    * @note This causes a color attachment to be added.
120    *
121    * @SINCE_1_1.43
122    * @param[in] texture The texture that will be used as output when rendering
123    * @note The texture has to have the same size than the FrameBuffer
124    * otherwise it won't be attached.
125    */
126   void AttachColorTexture( Texture& texture );
127
128   /**
129    * @brief Attach a texture to the framebuffer for color rendering.
130    * @note This causes a color attachment to be added.
131    *
132    * @SINCE_1_1.43
133    * @param[in] texture The texture that will be used as output when rendering
134    * @param[in] mipmapLevel The mipmap of the texture to be attached
135    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
136    * @note The specified texture mipmap has to have the same size than the FrameBuffer
137    * otherwise it won't be attached.
138    */
139   void AttachColorTexture( Texture& texture, uint32_t mipmapLevel, uint32_t layer );
140
141   /**
142    * @brief Gets the color texture used as output in the FrameBuffer.
143    *
144    * @SINCE_1_1.43
145    * @returns A handle to the texture used as color output, or an uninitialized handle
146    */
147   Texture GetColorTexture();
148
149 public:
150
151   /**
152    * @brief The constructor.
153    * @note  Not intended for application developers.
154    * @SINCE_1_1.43
155    * @param[in] pointer A pointer to a newly allocated FrameBuffer
156    */
157   explicit DALI_INTERNAL FrameBuffer( Internal::FrameBuffer* pointer );
158 };
159
160 } //namespace Dali
161
162 #endif // DALI_FRAMEBUFFER_H