Use swapchain colorformat instead of fixed format (Refs #238, Fixes #254)

This commit is contained in:
saschawillems 2017-01-25 18:54:09 +01:00
parent 127ed7b483
commit 9a59b24c8d
6 changed files with 11 additions and 14 deletions

View file

@ -183,7 +183,7 @@ void VulkanExampleBase::prepare()
vulkanDevice,
queue,
frameBuffers,
colorformat,
swapChain.colorFormat,
depthFormat,
&width,
&height,
@ -1466,7 +1466,7 @@ void VulkanExampleBase::setupRenderPass()
{
std::array<VkAttachmentDescription, 2> attachments = {};
// Color attachment
attachments[0].format = colorformat;
attachments[0].format = swapChain.colorFormat;
attachments[0].samples = VK_SAMPLE_COUNT_1_BIT;
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;

View file

@ -89,10 +89,7 @@ protected:
vk::VulkanDevice *vulkanDevice;
// Handle to the device graphics queue that command buffers are submitted to
VkQueue queue;
// Color buffer format
VkFormat colorformat = VK_FORMAT_B8G8R8A8_UNORM;
// Depth buffer format
// Depth format is selected during Vulkan initialization
// Depth buffer format (selected during Vulkan initialization)
VkFormat depthFormat;
// Command buffer pool
VkCommandPool cmdPool;

View file

@ -127,7 +127,7 @@ public:
// Color target
VkImageCreateInfo info = vkTools::initializers::imageCreateInfo();
info.imageType = VK_IMAGE_TYPE_2D;
info.format = colorformat;
info.format = swapChain.colorFormat;
info.extent.width = width;
info.extent.height = height;
info.extent.depth = 1;
@ -162,7 +162,7 @@ public:
VkImageViewCreateInfo viewInfo = vkTools::initializers::imageViewCreateInfo();
viewInfo.image = multisampleTarget.color.image;
viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
viewInfo.format = colorformat;
viewInfo.format = swapChain.colorFormat;
viewInfo.components.r = VK_COMPONENT_SWIZZLE_R;
viewInfo.components.g = VK_COMPONENT_SWIZZLE_G;
viewInfo.components.b = VK_COMPONENT_SWIZZLE_B;
@ -228,7 +228,7 @@ public:
std::array<VkAttachmentDescription, 4> attachments = {};
// Multisampled attachment that we render to
attachments[0].format = colorformat;
attachments[0].format = swapChain.colorFormat;
attachments[0].samples = SAMPLE_COUNT;
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
// No longer required after resolve, this may save some bandwidth on certain GPUs
@ -240,7 +240,7 @@ public:
// This is the frame buffer attachment to where the multisampled image
// will be resolved to and which will be presented to the swapchain
attachments[1].format = colorformat;
attachments[1].format = swapChain.colorFormat;
attachments[1].samples = VK_SAMPLE_COUNT_1_BIT;
attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE;

View file

@ -261,7 +261,7 @@ public:
std::array<VkAttachmentDescription, 5> attachments{};
// Color attachment
attachments[0].format = colorformat;
attachments[0].format = swapChain.colorFormat;
attachments[0].samples = VK_SAMPLE_COUNT_1_BIT;
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;

View file

@ -1147,7 +1147,7 @@ public:
vulkanDevice,
queue,
frameBuffers,
colorformat,
swapChain.colorFormat,
depthFormat,
&width,
&height,

View file

@ -703,7 +703,7 @@ public:
std::array<VkAttachmentDescription, 2> attachments = {};
// Color attachment
attachments[0].format = colorformat;
attachments[0].format = swapChain.colorFormat; // Use the color format selected by the swapchain
attachments[0].samples = VK_SAMPLE_COUNT_1_BIT; // We don't use multi sampling in this example
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; // Clear this attachment at the start of the render pass
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE; // Keep it's contents after the render pass is finished (for displaying it)
@ -713,7 +713,7 @@ public:
attachments[0].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; // Layout to which the attachment is transitioned when the render pass is finished
// As we want to present the color buffer to the swapchain, we transition to PRESENT_KHR
// Depth attachment
attachments[1].format = depthFormat;
attachments[1].format = depthFormat; // A proper depth format is selected in the example base
attachments[1].samples = VK_SAMPLE_COUNT_1_BIT;
attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; // Clear depth at start of first subpass
attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; // We don't need depth after render pass has finished (DONT_CARE may result in better performance)