2 * Copyright (c) 2018 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.
18 #include <dali/graphics/vulkan/vulkan-framebuffer.h>
19 #include <dali/graphics/vulkan/vulkan-graphics.h>
20 #include <dali/graphics/vulkan/vulkan-image.h>
29 struct Framebuffer::Impl
31 Impl( Framebuffer& owner, Graphics& graphics, uint32_t width, uint32_t height ) :
38 // Framebuffer creation may be deferred
52 auto attRef = vk::AttachmentReference{};
54 attRef.setAttachment();
56 // creating single subpass per framebuffer
57 auto subpassDesc = vk::SubpassDescription{};
58 subpassDesc.setPipelineBindPoint( vk::PipelineBindPoint::eGraphics );
59 subpassDesc.setColorAttachmentCount(0);
60 subpassDesc.setInputAttachmentCount(0);
61 subpassDesc.setPDepthStencilAttachment(nullptr);
62 subpassDesc.setPColorAttachments( nullptr );
63 subpassDesc.setPInputAttachments( nullptr );
64 subpassDesc.setPPreserveAttachments( nullptr );
65 subpassDesc.setPResolveAttachments( nullptr );
68 auto rpInfo = vk::RenderPassCreateInfo{};
69 rpInfo.setAttachmentCount( mAttachments.size() );
70 //rpInfo.setPAttachments( )
71 rpInfo.setDependencyCount( 0 );
72 rpInfo.setPDependencies( nullptr );
73 rpInfo.setPSubpasses( &subpassDesc );
74 rpInfo.setSubpassCount( 1 );
76 auto fbInfo = vk::FramebufferCreateInfo{};
77 fbInfo.setWidth( mWidth );
78 fbInfo.setHeight( mHeight );
79 //fbInfo.setRenderPass( )
80 //fbInfo.setAttachmentCount( 0 );
81 //fbInfo.setPAttachments( ImageViews );
87 void SetAttachment( Handle<Image> image, Framebuffer::AttachmentType type, uint32_t index )
89 std::vector<Handle<Image>>& attachments =
90 type == AttachmentType::COLOR ? mColorAttachments : mDepthStencilAttachments;
92 if( attachments.size() <= index )
94 attachments.resize( index+1 );
96 attachments[index] = image;
99 ImageRef GetAttachmentImage( AttachmentType type, uint32_t index ) const
104 ImageViewRef GetAttachmentImageView( AttachmentType type, uint32_t index ) const
106 return ImageViewRef();
111 if( mWidth == 0u || mHeight == 0 )
122 vk::RenderPass GetVkRenderPass() const
124 return mVkRenderPass;
127 vk::Framebuffer GetVkFramebuffer() const
129 return mVkFramebuffer;
132 Framebuffer& mInterface;
137 std::vector<Handle<Image>> mColorAttachments;
138 std::vector<Handle<Image>> mDepthStencilAttachments;
140 std::vector<ImageView> mImageViewAttachments;
141 vk::Framebuffer mVkFramebuffer;
142 vk::RenderPass mVkRenderPass;
144 bool mInitialised { false };
148 Handle<Framebuffer> Framebuffer::New( Graphics& graphics, uint32_t width, uint32_t height )
150 return FramebufferRef();
153 void Framebuffer::SetAttachment( Handle<Image> image, Framebuffer::AttachmentType type, uint32_t index )
155 mImpl->SetAttachment( image, type, index );
158 uint32_t Framebuffer::GetWidth() const
160 return mImpl->mWidth;
163 uint32_t Framebuffer::GetHeight() const
165 return mImpl->mHeight;
168 Handle<Image> Framebuffer::GetAttachmentImage( AttachmentType type, uint32_t index ) const
170 return mImpl->GetAttachmentImage( type, index );
173 Handle<ImageView> Framebuffer::GetAttachmentImageView( AttachmentType type, uint32_t index ) const
175 return mImpl->GetAttachmentImageView( type, index );
178 } // Namespace Vulkan
180 } // Namespace Graphics