Skip to content

Commit

Permalink
Use swapchain colorformat instead of fixed format (Refs SaschaWillems…
Browse files Browse the repository at this point in the history
  • Loading branch information
SaschaWillems committed Jan 25, 2017
1 parent 127ed7b commit 9a59b24
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions base/vulkanexamplebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void VulkanExampleBase::prepare()
vulkanDevice,
queue,
frameBuffers,
colorformat,
swapChain.colorFormat,
depthFormat,
&width,
&height,
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions base/vulkanexamplebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ class VulkanExampleBase
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;
Expand Down
8 changes: 4 additions & 4 deletions multisampling/multisampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class VulkanExample : public VulkanExampleBase
// 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;
Expand Down Expand Up @@ -162,7 +162,7 @@ class VulkanExample : public VulkanExampleBase
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;
Expand Down Expand Up @@ -228,7 +228,7 @@ class VulkanExample : public VulkanExampleBase
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
Expand All @@ -240,7 +240,7 @@ class VulkanExample : public VulkanExampleBase

// 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;
Expand Down
2 changes: 1 addition & 1 deletion subpasses/subpasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class VulkanExample : public VulkanExampleBase

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;
Expand Down
2 changes: 1 addition & 1 deletion textoverlay/textoverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ class VulkanExample : public VulkanExampleBase
vulkanDevice,
queue,
frameBuffers,
colorformat,
swapChain.colorFormat,
depthFormat,
&width,
&height,
Expand Down
4 changes: 2 additions & 2 deletions triangle/triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ class VulkanExample : public VulkanExampleBase
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)
Expand All @@ -713,7 +713,7 @@ class VulkanExample : public VulkanExampleBase
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)
Expand Down

0 comments on commit 9a59b24

Please sign in to comment.