Add an easier to use New in FrameBuffer for the 99% of the cases where we use offscreens
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-frame-buffer.h
1 #ifndef DALI_INTERNAL_RENDER_FRAME_BUFFER_H
2 #define DALI_INTERNAL_RENDER_FRAME_BUFFER_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 // INTERNAL INCLUDES
21 #include <dali/public-api/rendering/frame-buffer.h>
22 #include <dali/internal/render/gl-resources/context.h>
23 #include <dali/internal/render/renderers/render-sampler.h>
24 #include <dali/integration-api/gl-defines.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 namespace Render
31 {
32 class Texture;
33
34 class FrameBuffer
35 {
36 public:
37
38   using Mask = Dali::FrameBuffer::Attachment::Mask;
39
40   /**
41    * Constructor
42    * @param[in] width The width of the FrameBuffer
43    * @param[in] height The height of the FrameBuffer
44    * @param[in] attachments The attachments comprising the format of the FrameBuffer (bit-mask)
45    */
46   FrameBuffer( uint32_t width, uint32_t height, Mask attachments );
47
48   /**
49    * Destructor
50    */
51   ~FrameBuffer();
52
53   /**
54    * Creates a FrameBuffer object in the GPU.
55    * @param[in] context The GL context
56    */
57   void Initialize(Context& context);
58
59   /**
60    * Deletes the framebuffer object from the GPU
61    * @param[in] context The GL context
62    */
63   void Destroy( Context& context );
64
65   /**
66    * Called by RenderManager to inform the framebuffer that the context has been destroyed
67    */
68   void GlContextDestroyed();
69
70   /**
71    * @brief Attach a texture for color rendering. Valid only for Framebuffers with COLOR attachments.
72    * param[in] context The GL context
73    * @param[in] texture The texture that will be used as output when rendering
74    * @param[in] mipmapLevel The mipmap of the texture to be attached
75    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
76    */
77   void AttachColorTexture( Context& context, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer );
78
79   /**
80    * @brief Bind the framebuffer
81    * @param[in] context The GL context
82    */
83   void Bind( Context& context );
84
85   /**
86    * @brief Get the width of the FrameBuffer
87    * @return The width of the framebuffer
88    */
89   uint32_t GetWidth() const;
90
91   /**
92    * @brief Get the height of the FrameBuffer
93    * @return The height of the framebuffer
94    */
95   uint32_t GetHeight() const;
96
97 private:
98
99   GLuint mId;
100   GLuint mDepthBuffer;
101   GLuint mStencilBuffer;
102   uint32_t mWidth;
103   uint32_t mHeight;
104 };
105
106
107 } // namespace Render
108
109 } // namespace Internal
110
111 } // namespace Dali
112
113
114 #endif // DALI_INTERNAL_RENDER_FRAME_BUFFER_H