2 * Copyright (c) 2020 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/update/manager/update-manager.h>
23 #include <dali/internal/render/renderers/render-frame-buffer.h>
30 FrameBufferPtr FrameBuffer::New( uint32_t width, uint32_t height, Mask attachments )
32 FrameBufferPtr frameBuffer( new FrameBuffer( width, height, attachments ) );
33 frameBuffer->Initialize();
37 Render::FrameBuffer* FrameBuffer::GetRenderObject() const
42 FrameBuffer::FrameBuffer( uint32_t width, uint32_t height, Mask attachments )
43 : mEventThreadServices( EventThreadServices::Get() ),
44 mRenderObject( NULL ),
48 mAttachments( attachments ),
49 mColorAttachmentCount( 0 )
53 void FrameBuffer::Initialize()
55 mRenderObject = new Render::FrameBuffer( mWidth, mHeight, mAttachments );
57 OwnerPointer< Render::FrameBuffer > transferOwnership( mRenderObject );
58 AddFrameBuffer( mEventThreadServices.GetUpdateManager(), transferOwnership );
61 void FrameBuffer::AttachColorTexture( TexturePtr texture, uint32_t mipmapLevel, uint32_t layer )
63 if( ( texture->GetWidth() / ( 1u << mipmapLevel ) != mWidth ) ||
64 ( texture->GetHeight() / ( 1u << mipmapLevel ) != mHeight ) )
66 DALI_LOG_ERROR( "Failed to attach color texture to FrameBuffer: Size mismatch \n" );
68 else if ( mColorAttachmentCount >= Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS )
70 DALI_LOG_ERROR( "Failed to attach color texture to FrameBuffer: Exceeded maximum supported color attachments.\n" );
74 mColor[mColorAttachmentCount] = texture;
75 ++mColorAttachmentCount;
77 AttachColorTextureToFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject, texture->GetRenderObject(), mipmapLevel, layer );
81 Texture* FrameBuffer::GetColorTexture(uint8_t index) const
83 return ( index >= mColorAttachmentCount ) ? nullptr : mColor[index].Get();
86 void FrameBuffer::SetSize( uint32_t width, uint32_t height )
92 FrameBuffer::~FrameBuffer()
94 if( EventThreadServices::IsCoreRunning() && mRenderObject )
96 RemoveFrameBuffer( mEventThreadServices.GetUpdateManager(), *mRenderObject );
101 } // namespace Internal