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.
19 #include <dali/internal/event/rendering/frame-buffer-impl.h>
22 #include <dali/internal/render/renderers/render-frame-buffer.h>
23 #include <dali/internal/update/manager/update-manager.h>
29 FrameBufferPtr FrameBuffer::New(uint32_t width, uint32_t height, Mask attachments)
31 FrameBufferPtr frameBuffer(new FrameBuffer(width, height, attachments));
32 frameBuffer->Initialize();
36 Render::FrameBuffer* FrameBuffer::GetRenderObject() const
41 FrameBuffer::FrameBuffer(uint32_t width, uint32_t height, Mask attachments)
42 : mEventThreadServices(EventThreadServices::Get()),
43 mRenderObject(nullptr),
49 mAttachments(attachments),
50 mColorAttachmentCount(0)
54 void FrameBuffer::Initialize()
56 mRenderObject = new Render::FrameBuffer(mWidth, mHeight, mAttachments);
58 OwnerPointer<Render::FrameBuffer> transferOwnership(mRenderObject);
59 AddFrameBuffer(mEventThreadServices.GetUpdateManager(), transferOwnership);
62 void FrameBuffer::AttachColorTexture(TexturePtr texture, uint32_t mipmapLevel, uint32_t layer)
64 if((texture->GetWidth() / (1u << mipmapLevel) != mWidth) ||
65 (texture->GetHeight() / (1u << mipmapLevel) != mHeight))
67 DALI_LOG_ERROR("Failed to attach color texture to FrameBuffer: Size mismatch \n");
69 else if(mColorAttachmentCount >= Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS)
71 DALI_LOG_ERROR("Failed to attach color texture to FrameBuffer: Exceeded maximum supported color attachments.\n");
75 mColor[mColorAttachmentCount] = texture;
76 ++mColorAttachmentCount;
78 AttachColorTextureToFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel, layer);
82 void FrameBuffer::AttachDepthTexture(TexturePtr texture, uint32_t mipmapLevel)
84 if((texture->GetWidth() / (1u << mipmapLevel) != mWidth) ||
85 (texture->GetHeight() / (1u << mipmapLevel) != mHeight))
87 DALI_LOG_ERROR("Failed to attach depth texture to FrameBuffer: Size mismatch \n");
92 AttachDepthTextureToFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel);
96 void FrameBuffer::AttachDepthStencilTexture(TexturePtr texture, unsigned int mipmapLevel)
98 if((texture->GetWidth() / (1u << mipmapLevel) != mWidth) ||
99 (texture->GetHeight() / (1u << mipmapLevel) != mHeight))
101 DALI_LOG_ERROR("Failed to attach depth/stencil texture to FrameBuffer: Size mismatch \n");
106 AttachDepthStencilTextureToFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel);
110 Texture* FrameBuffer::GetColorTexture(uint8_t index) const
112 return (index >= mColorAttachmentCount) ? nullptr : mColor[index].Get();
115 Texture* FrameBuffer::GetDepthTexture() const
117 return (mDepth) ? mDepth.Get() : nullptr;
120 Texture* FrameBuffer::GetDepthStencilTexture() const
122 return (mStencil) ? mStencil.Get() : nullptr;
125 void FrameBuffer::SetSize(uint32_t width, uint32_t height)
131 FrameBuffer::~FrameBuffer()
133 if(EventThreadServices::IsCoreRunning() && mRenderObject)
135 RemoveFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject);
139 } // namespace Internal