2 * Copyright (c) 2019 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/public-api/rendering/frame-buffer.h>
22 #include <type_traits>
25 #include <dali/integration-api/debug.h> // DALI_LOG_WARNING_NOFN
26 #include <dali/internal/event/rendering/frame-buffer-impl.h> // Dali::Internal::FrameBuffer
27 #include <dali/internal/event/rendering/texture-impl.h> // Dali::Internal::Texture
34 /// Bool operator for FrameBuffer::Attachment::Mask.
35 /// in cpp as only used in this file
36 bool operator&( FrameBuffer::Attachment::Mask lhs, FrameBuffer::Attachment::Mask rhs )
38 using UnderlyingType = typename std::underlying_type< FrameBuffer::Attachment::Mask >::type;
39 return static_cast<bool>( static_cast<UnderlyingType>( lhs ) & static_cast<UnderlyingType>( rhs ) );
42 } // unnamed namespace
44 FrameBuffer FrameBuffer::New( uint32_t width, uint32_t height )
46 return New( width, height, FrameBuffer::Attachment::COLOR );
49 FrameBuffer FrameBuffer::New( uint32_t width, uint32_t height, Attachment::Mask attachments )
51 Internal::FrameBufferPtr frameBuffer = Internal::FrameBuffer::New( width, height, attachments );
52 if( attachments & FrameBuffer::Attachment::COLOR )
54 Internal::TexturePtr texture = Internal::Texture::New( Dali::TextureType::TEXTURE_2D, Pixel::RGB888, width, height );
55 frameBuffer->AttachColorTexture( texture, 0u, 0u );
57 return FrameBuffer( frameBuffer.Get() );
60 FrameBuffer FrameBuffer::New( uint32_t width, uint32_t height, uint32_t attachments )
62 DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: FrameBuffer::New(uint32_t,uint32_t,uint32_t) is deprecated and will be removed from next release. use New(uint32_t, uint32_t,Attachment::Mask) instead.\n" );
63 // have to static cast, which according to standard since C++11 is undefined behaviour, hence this variant is deprecated
64 Internal::FrameBufferPtr frameBuffer = Internal::FrameBuffer::New( width, height, static_cast<Attachment::Mask>( attachments ) );
65 return FrameBuffer( frameBuffer.Get() );
68 FrameBuffer::FrameBuffer()
72 FrameBuffer::~FrameBuffer()
76 FrameBuffer::FrameBuffer( const FrameBuffer& handle )
77 : BaseHandle( handle )
81 FrameBuffer FrameBuffer::DownCast( BaseHandle handle )
83 return FrameBuffer( dynamic_cast<Dali::Internal::FrameBuffer*>(handle.GetObjectPtr()));
86 FrameBuffer& FrameBuffer::operator=( const FrameBuffer& handle )
88 BaseHandle::operator=( handle );
92 FrameBuffer::FrameBuffer( Internal::FrameBuffer* pointer )
93 : BaseHandle( pointer )
97 void FrameBuffer::AttachColorTexture( Texture& texture )
99 AttachColorTexture( texture, 0u, 0u );
102 void FrameBuffer::AttachColorTexture( Texture& texture, uint32_t mipmapLevel, uint32_t layer )
106 Internal::TexturePtr texturePtr( &GetImplementation( texture ) );
107 GetImplementation(*this).AttachColorTexture( texturePtr, mipmapLevel, layer );
111 Texture FrameBuffer::GetColorTexture()
113 Internal::Texture* texturePtr = GetImplementation(*this).GetColorTexture();
114 return Dali::Texture( texturePtr );