Code cleanup

Fixes #449, Fixes #450, Fixes #452
This commit is contained in:
saschawillems 2018-04-07 09:16:42 +02:00
parent 7b28549bef
commit 2d3babb45a

View file

@ -239,8 +239,7 @@ public:
void createAttachment( void createAttachment(
VkFormat format, VkFormat format,
VkImageUsageFlagBits usage, VkImageUsageFlagBits usage,
FrameBufferAttachment *attachment, FrameBufferAttachment *attachment)
VkCommandBuffer layoutCmd)
{ {
VkImageAspectFlags aspectMask = 0; VkImageAspectFlags aspectMask = 0;
VkImageLayout imageLayout; VkImageLayout imageLayout;
@ -300,8 +299,6 @@ public:
// blitted to our render target // blitted to our render target
void prepareOffscreenFramebuffer() void prepareOffscreenFramebuffer()
{ {
VkCommandBuffer layoutCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
offScreenFrameBuf.width = this->width; offScreenFrameBuf.width = this->width;
offScreenFrameBuf.height = this->height; offScreenFrameBuf.height = this->height;
@ -314,22 +311,19 @@ public:
createAttachment( createAttachment(
VK_FORMAT_R16G16B16A16_SFLOAT, VK_FORMAT_R16G16B16A16_SFLOAT,
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
&offScreenFrameBuf.position, &offScreenFrameBuf.position);
layoutCmd);
// (World space) Normals // (World space) Normals
createAttachment( createAttachment(
VK_FORMAT_R16G16B16A16_SFLOAT, VK_FORMAT_R16G16B16A16_SFLOAT,
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
&offScreenFrameBuf.normal, &offScreenFrameBuf.normal);
layoutCmd);
// Albedo (color) // Albedo (color)
createAttachment( createAttachment(
VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM,
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
&offScreenFrameBuf.albedo, &offScreenFrameBuf.albedo);
layoutCmd);
// Depth attachment // Depth attachment
@ -341,10 +335,7 @@ public:
createAttachment( createAttachment(
attDepthFormat, attDepthFormat,
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
&offScreenFrameBuf.depth, &offScreenFrameBuf.depth);
layoutCmd);
VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true);
// Set up separate renderpass with references // Set up separate renderpass with references
// to the color and depth attachments // to the color and depth attachments
@ -458,14 +449,15 @@ public:
// Build command buffer for rendering the scene to the offscreen frame buffer attachments // Build command buffer for rendering the scene to the offscreen frame buffer attachments
void buildDeferredCommandBuffer() void buildDeferredCommandBuffer()
{ {
if (offScreenCmdBuffer == VK_NULL_HANDLE) if (offScreenCmdBuffer == VK_NULL_HANDLE) {
{
offScreenCmdBuffer = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false); offScreenCmdBuffer = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false);
} }
// Create a semaphore used to synchronize offscreen rendering and usage // Create a semaphore used to synchronize offscreen rendering and usage
if (offscreenSemaphore == VK_NULL_HANDLE) {
VkSemaphoreCreateInfo semaphoreCreateInfo = vks::initializers::semaphoreCreateInfo(); VkSemaphoreCreateInfo semaphoreCreateInfo = vks::initializers::semaphoreCreateInfo();
VK_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &offscreenSemaphore)); VK_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &offscreenSemaphore));
}
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
@ -1048,19 +1040,9 @@ public:
void updateUniformBufferDeferredMatrices() void updateUniformBufferDeferredMatrices()
{ {
uboOffscreenVS.projection = glm::perspective(glm::radians(45.0f), (float)width / (float)height, 0.1f, 256.0f);
uboOffscreenVS.view = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom));
uboOffscreenVS.model = glm::mat4(1.0f);
uboOffscreenVS.model = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.25f, 0.0f) + cameraPos);
uboOffscreenVS.model = glm::rotate(uboOffscreenVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
uboOffscreenVS.model = glm::rotate(uboOffscreenVS.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
uboOffscreenVS.model = glm::rotate(uboOffscreenVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
uboOffscreenVS.projection = camera.matrices.perspective; uboOffscreenVS.projection = camera.matrices.perspective;
uboOffscreenVS.view = camera.matrices.view; uboOffscreenVS.view = camera.matrices.view;
uboOffscreenVS.model = glm::mat4(1.0f); uboOffscreenVS.model = glm::mat4(1.0f);
memcpy(uniformBuffers.vsOffscreen.mapped, &uboOffscreenVS, sizeof(uboOffscreenVS)); memcpy(uniformBuffers.vsOffscreen.mapped, &uboOffscreenVS, sizeof(uboOffscreenVS));
} }