ce39488dc34cd1e8b4f2b8e3eaca6f8cc5172cc7
[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) 2021 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/integration-api/gl-defines.h>
23 #include <dali/internal/render/gl-resources/context.h>
24 #include <dali/internal/render/renderers/render-sampler.h>
25 #include <dali/public-api/rendering/frame-buffer.h>
26
27 namespace Dali
28 {
29 using Mask = Dali::FrameBuffer::Attachment::Mask;
30
31 namespace Internal
32 {
33 namespace Render
34 {
35 class Texture;
36
37 class FrameBuffer
38 {
39 public:
40   /**
41    * Constructor
42    */
43   FrameBuffer(uint32_t width, uint32_t height, Mask attachments);
44
45   /**
46    * Destructor
47    */
48   virtual ~FrameBuffer();
49
50   /**
51    * Creates a FrameBuffer object in the GPU.
52    * @param[in] graphicsController The Graphics Controller
53    */
54   virtual void Initialize(Graphics::Controller& graphicsController);
55
56   /**
57    * Deletes the framebuffer object from the GPU
58    */
59   virtual void Destroy();
60
61   /**
62    * @brief Bind the framebuffer. Do nothing
63    */
64   virtual void Bind();
65
66   /**
67    * @brief Get the width of the FrameBuffer
68    * @return The width of the framebuffer
69    */
70   virtual uint32_t GetWidth() const;
71
72   /**
73    * @brief Get the height of the FrameBuffer
74    * @return The height of the framebuffer
75    */
76   virtual uint32_t GetHeight() const;
77
78   /**
79    * @brief Attaches a texture for the color rendering. This API is valid only for frame buffer with COLOR attachments.
80    * @param[in] texture The texture that will be used as output when rendering
81    * @param[in] mipmapLevel The mipmap of the texture to be attached
82    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
83    * @note A maximum of Dali::FrameBuffer::MAX_COLOR_ATTACHMENTS are supported.
84    */
85   void AttachColorTexture(Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer);
86
87   /**
88    * @brief Attaches a texture for the depth rendering. This API is valid only for frame buffer with DEPTH attachments.
89    * @param[in] texture The texture that will be used as output when rendering
90    * @param[in] mipmapLevel The mipmap of the texture to be attached
91    */
92   void AttachDepthTexture(Render::Texture* texture, uint32_t mipmapLevel);
93
94   /**
95    * @brief Attaches a texture for the depth/stencil rendering. This API is valid only for frame buffer with DEPTH_STENCIL attachments.
96    * @param[in] texture The texture that will be used as output when rendering
97    * @param[in] mipmapLevel The mipmap of the texture to be attached
98    */
99   void AttachDepthStencilTexture(Render::Texture* texture, uint32_t mipmapLevel);
100
101   /**
102    * @brief Get the number of textures bound to this frame buffer as color attachments.
103    * @return The number of color attachments.
104    */
105   uint8_t GetColorAttachmentCount() const
106   {
107     return mCreateInfo.colorAttachments.size();
108   }
109
110   /**
111    * @brief Get the texture bound to this frame buffer as color attachment @a index.
112    * @return The texture.
113    */
114   Graphics::Texture* GetTexture(uint8_t index)
115   {
116     return mCreateInfo.colorAttachments[index].texture;
117   };
118
119   Graphics::Framebuffer* GetGraphicsObject()
120   {
121     return mGraphicsObject.get();
122   }
123
124 private:
125   /**
126    * @brief Undefined copy constructor. FrameBuffer cannot be copied
127    */
128   FrameBuffer(const FrameBuffer& rhs) = delete;
129
130   /**
131    * @brief Undefined assignment operator. FrameBuffer cannot be copied
132    */
133   FrameBuffer& operator=(const FrameBuffer& rhs) = delete;
134
135 private:
136   Graphics::Controller*                      mGraphicsController{nullptr};
137   Graphics::UniquePtr<Graphics::Framebuffer> mGraphicsObject{nullptr};
138
139   Graphics::FramebufferCreateInfo mCreateInfo;
140
141   uint32_t mWidth;
142   uint32_t mHeight;
143
144   bool mDepthBuffer;
145   bool mStencilBuffer;
146 };
147
148 } // namespace Render
149
150 } // namespace Internal
151
152 } // namespace Dali
153
154 #endif // DALI_INTERNAL_RENDER_FRAME_BUFFER_H