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/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
33 /// Bool operator for FrameBuffer::Attachment::Mask.
34 /// in cpp as only used in this file
35 bool operator&(FrameBuffer::Attachment::Mask lhs, FrameBuffer::Attachment::Mask rhs)
37 using UnderlyingType = typename std::underlying_type<FrameBuffer::Attachment::Mask>::type;
38 return static_cast<bool>(static_cast<UnderlyingType>(lhs) & static_cast<UnderlyingType>(rhs));
41 } // unnamed namespace
43 FrameBuffer FrameBuffer::New(uint32_t width, uint32_t height)
45 return New(width, height, FrameBuffer::Attachment::COLOR);
48 FrameBuffer FrameBuffer::New(uint32_t width, uint32_t height, Attachment::Mask attachments)
50 Internal::FrameBufferPtr frameBuffer = Internal::FrameBuffer::New(width, height, attachments);
51 if(attachments & FrameBuffer::Attachment::COLOR)
53 Internal::TexturePtr texture = Internal::Texture::New(Dali::TextureType::TEXTURE_2D, Pixel::RGB888, width, height);
54 frameBuffer->AttachColorTexture(texture, 0u, 0u);
56 return FrameBuffer(frameBuffer.Get());
59 FrameBuffer::FrameBuffer() = default;
61 FrameBuffer::~FrameBuffer() = default;
63 FrameBuffer::FrameBuffer(const FrameBuffer& handle) = default;
65 FrameBuffer FrameBuffer::DownCast(BaseHandle handle)
67 return FrameBuffer(dynamic_cast<Dali::Internal::FrameBuffer*>(handle.GetObjectPtr()));
70 FrameBuffer& FrameBuffer::operator=(const FrameBuffer& handle) = default;
72 FrameBuffer::FrameBuffer(Internal::FrameBuffer* pointer)
77 FrameBuffer::FrameBuffer(FrameBuffer&& rhs) = default;
79 FrameBuffer& FrameBuffer::operator=(FrameBuffer&& rhs) = default;
81 void FrameBuffer::AttachColorTexture(Texture& texture)
83 AttachColorTexture(texture, 0u, 0u);
86 void FrameBuffer::AttachColorTexture(Texture& texture, uint32_t mipmapLevel, uint32_t layer)
90 Internal::TexturePtr texturePtr(&GetImplementation(texture));
91 GetImplementation(*this).AttachColorTexture(texturePtr, mipmapLevel, layer);
95 Texture FrameBuffer::GetColorTexture()
97 Internal::Texture* texturePtr = GetImplementation(*this).GetColorTexture(0);
98 return Dali::Texture(texturePtr);