[dali_2.3.23] Merge branch 'devel/master'
[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) 2023 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/devel-api/rendering/frame-buffer-devel.h>
22 #include <dali/internal/render/renderers/render-sampler.h>
23 #include <dali/public-api/rendering/frame-buffer.h>
24
25 namespace Dali
26 {
27 using Mask = Dali::FrameBuffer::Attachment::Mask;
28
29 namespace Internal
30 {
31 namespace Render
32 {
33 class Texture;
34
35 class FrameBuffer
36 {
37 public:
38   /**
39    * Constructor
40    */
41   FrameBuffer(uint32_t width, uint32_t height, Mask attachments);
42
43   /**
44    * Destructor
45    */
46   virtual ~FrameBuffer();
47
48   /**
49    * Creates a FrameBuffer object in the GPU.
50    * @param[in] graphicsController The Graphics Controller
51    */
52   virtual void Initialize(Graphics::Controller& graphicsController);
53
54   /**
55    * Deletes the framebuffer object from the GPU
56    */
57   virtual void Destroy();
58
59   /**
60    * @brief Create the graphics objects if needed.
61    *
62    * Doesn't re-create them if they are already generated, also doesn't
63    * check for new attachments.
64    *
65    * Creates the framebuffer, attaches color and depth textures, set multi sampling level,
66    * generates render target and render passes.
67    *
68    * @return true if there are attachments and the graphics objects have been created.
69    */
70   virtual bool CreateGraphicsObjects();
71
72   /**
73    * @brief Get the width of the FrameBuffer
74    * @return The width of the framebuffer
75    */
76   virtual uint32_t GetWidth() const;
77
78   /**
79    * @brief Get the height of the FrameBuffer
80    * @return The height of the framebuffer
81    */
82   virtual uint32_t GetHeight() const;
83
84   /**
85    * @brief Attaches a texture for the color rendering. This API is valid only for frame buffer with COLOR attachments.
86    * @param[in] texture The texture that will be used as output when rendering
87    * @param[in] mipmapLevel The mipmap of the texture to be attached
88    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
89    * @note A maximum of Dali::FrameBuffer::MAX_COLOR_ATTACHMENTS are supported.
90    */
91   void AttachColorTexture(Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer);
92
93   /**
94    * @brief Attaches a texture for the depth rendering. This API is valid only for frame buffer with DEPTH attachments.
95    * @param[in] texture The texture that will be used as output when rendering
96    * @param[in] mipmapLevel The mipmap of the texture to be attached
97    */
98   void AttachDepthTexture(Render::Texture* texture, uint32_t mipmapLevel);
99
100   /**
101    * @brief Attaches a texture for the depth/stencil rendering. This API is valid only for frame buffer with DEPTH_STENCIL attachments.
102    * @param[in] texture The texture that will be used as output when rendering
103    * @param[in] mipmapLevel The mipmap of the texture to be attached
104    */
105   void AttachDepthStencilTexture(Render::Texture* texture, uint32_t mipmapLevel);
106
107   /**
108    * @brief Sets the level of multisampling in the frame buffer. This API is valid only GL_EXT_multisampled_render_to_texture supported.
109    * @param[in] multiSamplingLevel The level of multisampling
110    */
111   void SetMultiSamplingLevel(uint8_t multiSamplingLevel);
112
113   /**
114    * @brief Get the number of textures bound to this frame buffer as color attachments.
115    * @return The number of color attachments.
116    */
117   uint8_t GetColorAttachmentCount() const
118   {
119     return mCreateInfo.colorAttachments.size();
120   }
121
122   Graphics::Framebuffer* GetGraphicsObject()
123   {
124     return mGraphicsObject.get();
125   }
126
127   [[nodiscard]] Graphics::RenderTarget* GetGraphicsRenderTarget() const
128   {
129     return mRenderTarget.get();
130   }
131
132   [[nodiscard]] Graphics::RenderPass* GetGraphicsRenderPass(Graphics::AttachmentLoadOp  colorLoadOp,
133                                                             Graphics::AttachmentStoreOp colorStoreOp) const;
134
135   /**
136    * The function returns initialized array of clear values
137    * which then can be modified and assed to BeginRenderPass()
138    * command.
139    */
140   [[nodiscard]] auto& GetGraphicsRenderPassClearValues()
141   {
142     return mClearValues;
143   }
144
145 private:
146   /**
147    * @brief Undefined copy constructor. FrameBuffer cannot be copied
148    */
149   FrameBuffer(const FrameBuffer& rhs) = delete;
150
151   /**
152    * @brief Undefined assignment operator. FrameBuffer cannot be copied
153    */
154   FrameBuffer& operator=(const FrameBuffer& rhs) = delete;
155
156 private:
157   Graphics::Controller*                      mGraphicsController{nullptr};
158   Graphics::UniquePtr<Graphics::Framebuffer> mGraphicsObject{nullptr};
159
160   Graphics::FramebufferCreateInfo mCreateInfo;
161
162   // Render pass and render target
163
164   /**
165    * Render passes are created on fly depending on Load and Store operations
166    * The default render pass (most likely to be used) is the load = CLEAR
167    * amd store = STORE for color attachment.
168    */
169   std::vector<Graphics::UniquePtr<Graphics::RenderPass>> mRenderPass{};
170   Graphics::UniquePtr<Graphics::RenderTarget>            mRenderTarget{nullptr};
171
172   // clear colors
173   std::vector<Graphics::ClearValue> mClearValues{};
174
175   uint32_t mWidth;
176   uint32_t mHeight;
177
178   bool mDepthBuffer;
179   bool mStencilBuffer;
180 };
181
182 } // namespace Render
183
184 } // namespace Internal
185
186 } // namespace Dali
187
188 #endif // DALI_INTERNAL_RENDER_FRAME_BUFFER_H