mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
140 lines
5.3 KiB
140 lines
5.3 KiB
|
10 years ago
|
#ifndef Magnum_Vk_RenderPass_h
|
||
|
|
#define Magnum_Vk_RenderPass_h
|
||
|
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
|
||
|
|
Vladimír Vondruš <mosra@centrum.cz>
|
||
|
|
Copyright © 2016 Jonathan Hale <squareys@googlemail.com>
|
||
|
|
|
||
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
|
copy of this software and associated documentation files (the "Software"),
|
||
|
|
to deal in the Software without restriction, including without limitation
|
||
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
|
||
|
|
The above copyright notice and this permission notice shall be included
|
||
|
|
in all copies or substantial portions of the Software.
|
||
|
|
|
||
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
|
DEALINGS IN THE SOFTWARE.
|
||
|
|
*/
|
||
|
|
|
||
|
|
/** @file
|
||
|
|
* @brief Class @ref Magnum::Vk::RenderPass
|
||
|
|
*/
|
||
|
|
|
||
|
|
#include "Magnum/Magnum.h"
|
||
|
|
#include "Magnum/Vk/Device.h"
|
||
|
|
#include "Magnum/Vk/visibility.h"
|
||
|
|
|
||
|
|
#include "vulkan.h"
|
||
|
|
|
||
|
|
namespace Magnum { namespace Vk {
|
||
|
|
|
||
|
|
class MAGNUM_VK_EXPORT RenderPass {
|
||
|
|
public:
|
||
|
|
|
||
|
|
RenderPass(NoCreateT) noexcept: _device{nullptr} {
|
||
|
|
}
|
||
|
|
|
||
|
|
RenderPass(Device& device, VkFormat depthFormat): _device{&device} {
|
||
|
|
VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
|
||
|
|
|
||
|
|
VkAttachmentDescription attachments[2];
|
||
|
|
attachments[0].format = VK_FORMAT_B8G8R8A8_UNORM;
|
||
|
|
attachments[0].samples = sampleCount;
|
||
|
|
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||
|
|
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||
|
|
attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||
|
|
attachments[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||
|
|
attachments[0].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||
|
|
attachments[0].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||
|
|
|
||
|
|
attachments[1].format = depthFormat;
|
||
|
|
attachments[1].samples = sampleCount;
|
||
|
|
attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||
|
|
attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||
|
|
attachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||
|
|
attachments[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||
|
|
attachments[1].initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||
|
|
attachments[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||
|
|
|
||
|
|
VkAttachmentReference colorReference = {};
|
||
|
|
colorReference.attachment = 0;
|
||
|
|
colorReference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||
|
|
|
||
|
|
VkAttachmentReference depthReference = {};
|
||
|
|
depthReference.attachment = 1;
|
||
|
|
depthReference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||
|
|
|
||
|
|
VkSubpassDescription subpass = {};
|
||
|
|
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||
|
|
subpass.flags = 0;
|
||
|
|
subpass.inputAttachmentCount = 0;
|
||
|
|
subpass.pInputAttachments = nullptr;
|
||
|
|
subpass.colorAttachmentCount = 1;
|
||
|
|
subpass.pColorAttachments = &colorReference;
|
||
|
|
subpass.pResolveAttachments = nullptr;
|
||
|
|
subpass.pDepthStencilAttachment = &depthReference;
|
||
|
|
subpass.preserveAttachmentCount = 0;
|
||
|
|
subpass.pPreserveAttachments = nullptr;
|
||
|
|
|
||
|
|
VkRenderPassCreateInfo renderPassInfo = {};
|
||
|
|
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||
|
|
renderPassInfo.pNext = nullptr;
|
||
|
|
renderPassInfo.attachmentCount = 2;
|
||
|
|
renderPassInfo.pAttachments = attachments;
|
||
|
|
renderPassInfo.subpassCount = 1;
|
||
|
|
renderPassInfo.pSubpasses = &subpass;
|
||
|
|
renderPassInfo.dependencyCount = 0;
|
||
|
|
renderPassInfo.pDependencies = nullptr;
|
||
|
|
|
||
|
|
VkResult err = vkCreateRenderPass(*_device, &renderPassInfo, nullptr, &_renderPass);
|
||
|
|
MAGNUM_VK_ASSERT_ERROR(err);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** @brief Copying is not allowed */
|
||
|
|
RenderPass(const RenderPass&) = delete;
|
||
|
|
|
||
|
|
/** @brief Move constructor */
|
||
|
|
RenderPass(RenderPass&& other): _device{other._device}, _renderPass{other._renderPass}{
|
||
|
|
other._renderPass = VK_NULL_HANDLE;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Destructor
|
||
|
|
*
|
||
|
|
* @see @fn_vk{DestroyRenderPass}
|
||
|
|
*/
|
||
|
|
~RenderPass();
|
||
|
|
|
||
|
|
/** @brief Copying is not allowed */
|
||
|
|
RenderPass& operator=(const RenderPass&) = delete;
|
||
|
|
|
||
|
|
RenderPass& operator=(RenderPass&& sem) noexcept {
|
||
|
|
std::swap(_renderPass, sem._renderPass);
|
||
|
|
std::swap(_device, sem._device);
|
||
|
|
|
||
|
|
return *this;
|
||
|
|
}
|
||
|
|
|
||
|
|
operator VkRenderPass() const {
|
||
|
|
return _renderPass;
|
||
|
|
}
|
||
|
|
|
||
|
|
private:
|
||
|
|
Device* _device;
|
||
|
|
VkRenderPass _renderPass;
|
||
|
|
};
|
||
|
|
|
||
|
|
}}
|
||
|
|
|
||
|
|
#endif
|