1 #ifndef DALI_INTERNAL_RENDER_FRAME_BUFFER_H
2 #define DALI_INTERNAL_RENDER_FRAME_BUFFER_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
27 using Mask = Dali::FrameBuffer::Attachment::Mask;
41 FrameBuffer(uint32_t width, uint32_t height, Mask attachments);
46 virtual ~FrameBuffer();
49 * Creates a FrameBuffer object in the GPU.
50 * @param[in] graphicsController The Graphics Controller
52 virtual void Initialize(Graphics::Controller& graphicsController);
55 * Deletes the framebuffer object from the GPU
57 virtual void Destroy();
60 * @brief Create the graphics objects if needed.
62 * Doesn't re-create them if they are already generated, also doesn't
63 * check for new attachments.
65 * Creates the framebuffer, attaches color and depth textures, generates
66 * render target and render passes.
68 * @return true if there are attachments and the graphics objects have been created.
70 virtual bool CreateGraphicsObjects();
73 * @brief Get the width of the FrameBuffer
74 * @return The width of the framebuffer
76 virtual uint32_t GetWidth() const;
79 * @brief Get the height of the FrameBuffer
80 * @return The height of the framebuffer
82 virtual uint32_t GetHeight() const;
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.
91 void AttachColorTexture(Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer);
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
98 void AttachDepthTexture(Render::Texture* texture, uint32_t mipmapLevel);
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
105 void AttachDepthStencilTexture(Render::Texture* texture, uint32_t mipmapLevel);
108 * @brief Get the number of textures bound to this frame buffer as color attachments.
109 * @return The number of color attachments.
111 uint8_t GetColorAttachmentCount() const
113 return mCreateInfo.colorAttachments.size();
117 * @brief Get the texture bound to this frame buffer as color attachment @a index.
118 * @return The texture.
120 Graphics::Texture* GetTexture(uint8_t index)
122 return mCreateInfo.colorAttachments[index].texture;
125 Graphics::Framebuffer* GetGraphicsObject()
127 return mGraphicsObject.get();
130 [[nodiscard]] Graphics::RenderTarget* GetGraphicsRenderTarget() const
132 return mRenderTarget.get();
135 [[nodiscard]] Graphics::RenderPass* GetGraphicsRenderPass(Graphics::AttachmentLoadOp colorLoadOp,
136 Graphics::AttachmentStoreOp colorStoreOp) const;
139 * The function returns initialized array of clear values
140 * which then can be modified and assed to BeginRenderPass()
143 [[nodiscard]] auto& GetGraphicsRenderPassClearValues()
150 * @brief Undefined copy constructor. FrameBuffer cannot be copied
152 FrameBuffer(const FrameBuffer& rhs) = delete;
155 * @brief Undefined assignment operator. FrameBuffer cannot be copied
157 FrameBuffer& operator=(const FrameBuffer& rhs) = delete;
160 Graphics::Controller* mGraphicsController{nullptr};
161 Graphics::UniquePtr<Graphics::Framebuffer> mGraphicsObject{nullptr};
163 Graphics::FramebufferCreateInfo mCreateInfo;
165 // Render pass and render target
168 * Render passes are created on fly depending on Load and Store operations
169 * The default render pass (most likely to be used) is the load = CLEAR
170 * amd store = STORE for color attachment.
172 std::vector<Graphics::UniquePtr<Graphics::RenderPass>> mRenderPass{};
173 Graphics::UniquePtr<Graphics::RenderTarget> mRenderTarget{nullptr};
176 std::vector<Graphics::ClearValue> mClearValues{};
185 } // namespace Render
187 } // namespace Internal
191 #endif // DALI_INTERNAL_RENDER_FRAME_BUFFER_H