[dali_1.1.2] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / images / frame-buffer-image.h
1 #ifndef __DALI_FRAME_BUFFER_IMAGE_H__
2 #define __DALI_FRAME_BUFFER_IMAGE_H__
3
4 /*
5  * Copyright (c) 2015 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 // INTERNAL INCLUDES
22 #include <dali/public-api/images/image.h>
23 #include <dali/public-api/images/native-image-interface.h>
24 #include <dali/public-api/images/pixel.h>
25
26 namespace Dali
27 {
28 /**
29  * @addtogroup dali-core-images
30  * @{
31  */
32
33 namespace Internal DALI_INTERNAL
34 {
35 class FrameBufferImage;
36 }
37
38 namespace RenderBuffer
39 {
40 /**
41  * @brief Render Buffer formats
42  * The default format for framebuffer creation is COLOR, so If a depth buffer for 3D rendering is required use
43  * COLOR_DEPTH instead
44  */
45 enum Format ///< Framebuffer format, default color depth is RGBA 32 bit with alpha
46 {
47   COLOR,                ///< Framebuffer will be created with color buffer.
48   COLOR_DEPTH,          ///< Framebuffer will be created with color and depth buffer
49   COLOR_STENCIL,        ///< Framebuffer will be created with color and stencil buffer
50   COLOR_DEPTH_STENCIL   ///< Framebuffer will be created with color, depth and stencil buffer. NOTE: May be not supported in all devices
51 };
52 }
53
54 /**
55  * @brief FrameBufferImage represents a GLES Frame Buffer Object and contains the result
56  * of an 'off screen' render pass of a RenderTask.
57  * The FrameBufferImage can then be used with an ImageActor (with optional shader
58  * effects) and rendered to the screen.
59  */
60 class DALI_IMPORT_API FrameBufferImage : public Image
61 {
62 public:
63   /**
64    * @brief Constructor which creates an uninitialized FrameBufferImage object.
65    *
66    * Use Image::New(...) to create an initialised object.
67    */
68   FrameBufferImage();
69
70   /**
71    * @brief Create a new FrameBufferImage.
72    *
73    * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
74    * The ReleasePolicy defaults to Dali::Image::Never.
75    * @param [in] width       The width in pixels. Setting to zero will use the width of the stage.
76    * @param [in] height      The height in pixels. Setting to zero will use the height of the stage.
77    * @param [in] pixelFormat The pixel format (rgba 32 bit by default)
78    * @param [in] bufferFormat The format of the buffers that are going to be created for the FBO, (COLOR and DEPTH buffer as default)
79    * @post When the FrameBufferImage is first used as a render target, an exception may be thrown if pixelFormat is not supported on the hardware platform.
80    * @return A handle to a new instance of a FrameBufferImage.
81    */
82   static FrameBufferImage New(unsigned int width = 0, unsigned int height = 0, Pixel::Format pixelFormat = Pixel::RGBA8888,
83                               RenderBuffer::Format bufferFormat = RenderBuffer::COLOR);
84
85   /**
86    * @brief Create a new FrameBufferImage.
87    *
88    * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
89    * @param [in] width       The width in pixels. Setting to zero will use the width of the stage.
90    * @param [in] height      The height in pixels. Setting to zero will use the height of the stage.
91    * @param [in] pixelFormat The pixel format.
92    * @param [in] releasePolicy The ReleasePolicy to apply to the FrameBufferImage.
93    * @param [in] bufferFormat The format of the buffers that are going to be created for the FBO, (COLOR and DEPTH buffer as default)
94    *
95    * Note that there is no need for a LoadPolicy - by definition it is always OnDemand, since there is no point in the FrameBufferImage existing unless someone is rendering to
96    * it, or it is being used as an input (e.g. ShaderEffect / ImageActor).
97    *
98    * @post When the FrameBufferImage is first used as a render target, an exception may be thrown if pixelFormat is not supported on the hardware platform.
99    * @return A handle to a new instance of a FrameBufferImage.
100    */
101   static FrameBufferImage New(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy,
102                               RenderBuffer::Format bufferFormat = RenderBuffer::COLOR);
103
104   /**
105    * @brief Create a new FrameBufferImage.
106    *
107    * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
108    * @param [in] image       The native image.
109    *
110    * Note that there is no need for a LoadPolicy - by definition it is always OnDemand, since there is no point in the FrameBufferImage existing unless someone is rendering to
111    * it, or it is being used as an input (e.g. ShaderEffect / ImageActor).
112    *
113    * @post When the FrameBufferImage is first used as a render target, an exception may be thrown if the NativeImage cannot be mapped to a texture.
114    * @return A handle to a new instance of a FrameBufferImage.
115    */
116   static FrameBufferImage New(NativeImageInterface& image);
117
118   /**
119    * @brief Create a new FrameBufferImage.
120    *
121    * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
122    * @param [in] image       The native image.
123    * @param [in] releasePolicy The ReleasePolicy to apply to the FrameBufferImage.
124    *
125    * Note that there is no need for a LoadPolicy - by definition it is always OnDemand, since there is no point in the FrameBufferImage existing unless someone is rendering to
126    * it, or it is being used as an input (e.g. ShaderEffect / ImageActor).
127    *
128    * @post When the FrameBufferImage is first used as a render target, an exception may be thrown if the NativeImage cannot be mapped to a texture.
129    * @return A handle to a new instance of a FrameBufferImage.
130    */
131   static FrameBufferImage New(NativeImageInterface& image, ReleasePolicy releasePolicy);
132
133   /**
134    * @brief Downcast an Object handle to FrameBufferImage handle.
135    *
136    * If handle points to a FrameBufferImage object the
137    * downcast produces valid handle. If not the returned handle is left uninitialized.
138    * @param[in] handle to An object
139    * @return handle to a FrameBufferImage object or an uninitialized handle
140    */
141   static FrameBufferImage DownCast( BaseHandle handle );
142
143   /**
144    * @brief Destructor
145    *
146    * This is non-virtual since derived Handle types must not contain data or virtual methods.
147    */
148   ~FrameBufferImage();
149
150   /**
151    * @brief This copy constructor is required for (smart) pointer semantics.
152    *
153    * @param [in] handle A reference to the copied handle
154    */
155   FrameBufferImage(const FrameBufferImage& handle);
156
157   /**
158    * @brief This assignment operator is required for (smart) pointer semantics.
159    *
160    * @param [in] rhs  A reference to the copied handle
161    * @return A reference to this
162    */
163   FrameBufferImage& operator=(const FrameBufferImage& rhs);
164
165 public: // Not intended for application developers
166
167   explicit DALI_INTERNAL FrameBufferImage(Internal::FrameBufferImage*);
168 }; //class FrameBufferImage
169
170 /**
171  * @}
172  */
173 } // namespace Dali
174
175 #endif // __DALI_FRAME_BUFFER_IMAGE_H__