1 // Copyright 2021 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "Framebuffer.hpp"
16
Framebuffer(vk::Device device,vk::PhysicalDevice physicalDevice,vk::ImageView attachment,vk::Format colorFormat,vk::RenderPass renderPass,vk::Extent2D extent,bool multisample)17 Framebuffer::Framebuffer(vk::Device device, vk::PhysicalDevice physicalDevice, vk::ImageView attachment, vk::Format colorFormat, vk::RenderPass renderPass, vk::Extent2D extent, bool multisample)
18 : device(device)
19 {
20 std::vector<vk::ImageView> attachments(multisample ? 2 : 1);
21
22 if(multisample)
23 {
24 multisampleImage.reset(new Image(device, physicalDevice, extent.width, extent.height, colorFormat, vk::SampleCountFlagBits::e4));
25
26 // We'll be rendering to attachment location 0
27 attachments[0] = multisampleImage->getImageView();
28 attachments[1] = attachment; // Resolve attachment
29 }
30 else
31 {
32 attachments[0] = attachment;
33 }
34
35 vk::FramebufferCreateInfo framebufferCreateInfo;
36
37 framebufferCreateInfo.renderPass = renderPass;
38 framebufferCreateInfo.attachmentCount = static_cast<uint32_t>(attachments.size());
39 framebufferCreateInfo.pAttachments = attachments.data();
40 framebufferCreateInfo.width = extent.width;
41 framebufferCreateInfo.height = extent.height;
42 framebufferCreateInfo.layers = 1;
43
44 framebuffer = device.createFramebuffer(framebufferCreateInfo);
45 }
46
~Framebuffer()47 Framebuffer::~Framebuffer()
48 {
49 multisampleImage.reset();
50 device.destroyFramebuffer(framebuffer);
51 }
52