2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali/internal/render/renderers/render-frame-buffer.h>
21 #include <dali/internal/render/renderers/render-texture.h>
29 FrameBuffer::FrameBuffer(uint32_t width, uint32_t height, Mask attachments)
32 mDepthBuffer(attachments & Dali::FrameBuffer::Attachment::DEPTH),
33 mStencilBuffer(attachments & Dali::FrameBuffer::Attachment::STENCIL)
37 FrameBuffer::~FrameBuffer() = default;
39 void FrameBuffer::Destroy()
41 mGraphicsObject.reset();
44 void FrameBuffer::Initialize(Graphics::Controller& graphicsController)
46 mGraphicsController = &graphicsController;
49 void FrameBuffer::AttachColorTexture(Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer)
53 if(!texture->GetGraphicsObject())
55 texture->Create(0 | Graphics::TextureUsageFlagBits::COLOR_ATTACHMENT | Graphics::TextureUsageFlagBits::SAMPLE);
58 uint32_t attachmentId = mCreateInfo.colorAttachments.size();
59 Graphics::ColorAttachment colorAttachment{attachmentId, texture->GetGraphicsObject(), layer, mipmapLevel};
60 mCreateInfo.colorAttachments.push_back(colorAttachment);
64 void FrameBuffer::AttachDepthTexture(Render::Texture* texture, uint32_t mipmapLevel)
66 if(texture && mDepthBuffer)
68 if(!texture->GetGraphicsObject())
70 texture->Create(0 | Graphics::TextureUsageFlagBits::DEPTH_STENCIL_ATTACHMENT | Graphics::TextureUsageFlagBits::SAMPLE);
73 mCreateInfo.depthStencilAttachment.depthTexture = texture->GetGraphicsObject();
74 mCreateInfo.depthStencilAttachment.depthLevel = mipmapLevel;
78 void FrameBuffer::AttachDepthStencilTexture(Render::Texture* texture, uint32_t mipmapLevel)
80 if(texture && mStencilBuffer)
82 if(!texture->GetGraphicsObject())
84 texture->Create(0 | Graphics::TextureUsageFlagBits::DEPTH_STENCIL_ATTACHMENT | Graphics::TextureUsageFlagBits::SAMPLE);
86 mCreateInfo.depthStencilAttachment.stencilTexture = texture->GetGraphicsObject();
87 mCreateInfo.depthStencilAttachment.stencilLevel = mipmapLevel;
91 void FrameBuffer::Bind()
95 mGraphicsObject = mGraphicsController->CreateFramebuffer(mCreateInfo, nullptr);
99 uint32_t FrameBuffer::GetWidth() const
104 uint32_t FrameBuffer::GetHeight() const
109 } // namespace Render
111 } // namespace Internal