[dali_1.3.54] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / rendering / frame-buffer.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/public-api/rendering/frame-buffer.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/debug.h> // DALI_LOG_WARNING_NOFN
23 #include <dali/internal/event/rendering/frame-buffer-impl.h> // Dali::Internal::FrameBuffer
24 #include <dali/internal/event/rendering/texture-impl.h> // Dali::Internal::Texture
25
26 namespace Dali
27 {
28
29 FrameBuffer FrameBuffer::New( uint32_t width, uint32_t height )
30 {
31   return New( width, height, FrameBuffer::Attachment::COLOR );
32 }
33
34 FrameBuffer FrameBuffer::New( uint32_t width, uint32_t height, Attachment::Mask attachments )
35 {
36   Internal::FrameBufferPtr frameBuffer = Internal::FrameBuffer::New( width, height, attachments );
37   if( attachments & FrameBuffer::Attachment::COLOR )
38   {
39     Internal::TexturePtr texture = Internal::Texture::New( Dali::TextureType::TEXTURE_2D, Pixel::RGB888, width, height );
40     frameBuffer->AttachColorTexture( texture, 0u, 0u );
41   }
42   return FrameBuffer( frameBuffer.Get() );
43 }
44
45 FrameBuffer FrameBuffer::New( uint32_t width, uint32_t height, uint32_t attachments )
46 {
47   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" );
48   // have to static cast, which according to standard since C++11 is undefined behaviour, hence this variant is deprecated
49   Internal::FrameBufferPtr frameBuffer = Internal::FrameBuffer::New( width, height, static_cast<Attachment::Mask>( attachments ) );
50   return FrameBuffer( frameBuffer.Get() );
51 }
52
53 FrameBuffer::FrameBuffer()
54 {
55 }
56
57 FrameBuffer::~FrameBuffer()
58 {
59 }
60
61 FrameBuffer::FrameBuffer( const FrameBuffer& handle )
62 : BaseHandle( handle )
63 {
64 }
65
66 FrameBuffer FrameBuffer::DownCast( BaseHandle handle )
67 {
68   return FrameBuffer( dynamic_cast<Dali::Internal::FrameBuffer*>(handle.GetObjectPtr()));
69 }
70
71 FrameBuffer& FrameBuffer::operator=( const FrameBuffer& handle )
72 {
73   BaseHandle::operator=( handle );
74   return *this;
75 }
76
77 FrameBuffer::FrameBuffer( Internal::FrameBuffer* pointer )
78 : BaseHandle( pointer )
79 {
80 }
81
82 void FrameBuffer::AttachColorTexture( Texture& texture )
83 {
84   AttachColorTexture( texture, 0u, 0u );
85 }
86
87 void FrameBuffer::AttachColorTexture( Texture& texture, uint32_t mipmapLevel, uint32_t layer )
88 {
89   if( texture )
90   {
91     Internal::TexturePtr texturePtr( &GetImplementation( texture ) );
92     GetImplementation(*this).AttachColorTexture( texturePtr, mipmapLevel, layer );
93   }
94 }
95
96 Texture FrameBuffer::GetColorTexture()
97 {
98   Internal::Texture* texturePtr = GetImplementation(*this).GetColorTexture();
99   return Dali::Texture( texturePtr );
100 }
101
102 } //namespace Dali