Code cleanup, release resources

This commit is contained in:
saschawillems 2018-06-02 09:05:19 +02:00
parent c56868d660
commit 539fbcdf10
2 changed files with 20 additions and 14 deletions

View file

@ -63,6 +63,7 @@ set(EXAMPLES
mesh mesh
multisampling multisampling
multithreading multithreading
multiview
occlusionquery occlusionquery
offscreen offscreen
parallaxmapping parallaxmapping

View file

@ -24,7 +24,6 @@
#include "VulkanModel.hpp" #include "VulkanModel.hpp"
#define ENABLE_VALIDATION false #define ENABLE_VALIDATION false
//#define VULKAN_1_1
class VulkanExample : public VulkanExampleBase class VulkanExample : public VulkanExampleBase
{ {
@ -44,13 +43,13 @@ public:
vks::Model scene; vks::Model scene;
struct UBOGS { struct UBO {
glm::mat4 projection[2]; glm::mat4 projection[2];
glm::mat4 modelview[2]; glm::mat4 modelview[2];
glm::vec4 lightPos = glm::vec4(-2.5f, -3.5f, 0.0f, 1.0f); glm::vec4 lightPos = glm::vec4(-2.5f, -3.5f, 0.0f, 1.0f);
} uboGS; } ubo;
vks::Buffer uniformBufferGS; vks::Buffer uniformBuffer;
VkPipeline pipeline; VkPipeline pipeline;
VkPipelineLayout pipelineLayout; VkPipelineLayout pipelineLayout;
@ -88,9 +87,15 @@ public:
vkDestroyPipelineLayout(device, pipelineLayout, nullptr); vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr); vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
vkDestroyImageView(device, colorAttachment.view, nullptr);
vkDestroyImage(device, colorAttachment.image, nullptr);
vkFreeMemory(device, colorAttachment.memory, nullptr);
vkDestroySemaphore(device, blitCompleteSemaphore, nullptr);
scene.destroy(); scene.destroy();
uniformBufferGS.destroy(); uniformBuffer.destroy();
} }
/* /*
@ -476,7 +481,7 @@ public:
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocateInfo, &descriptorSet)); VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocateInfo, &descriptorSet));
std::vector<VkWriteDescriptorSet> writeDescriptorSets = { std::vector<VkWriteDescriptorSet> writeDescriptorSets = {
// Binding 0: Vertex shader UBO // Binding 0: Vertex shader UBO
vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBufferGS.descriptor), vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffer.descriptor),
}; };
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, nullptr); vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, nullptr);
} }
@ -574,9 +579,9 @@ public:
VK_CHECK_RESULT(vulkanDevice->createBuffer( VK_CHECK_RESULT(vulkanDevice->createBuffer(
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
&uniformBufferGS, &uniformBuffer,
sizeof(uboGS))); sizeof(ubo)));
VK_CHECK_RESULT(uniformBufferGS.map()); VK_CHECK_RESULT(uniformBuffer.map());
updateUniformBuffers(); updateUniformBuffers();
} }
@ -613,8 +618,8 @@ public:
transM = glm::translate(glm::mat4(1.0f), camera.position - camRight * (eyeSeparation / 2.0f)); transM = glm::translate(glm::mat4(1.0f), camera.position - camRight * (eyeSeparation / 2.0f));
uboGS.projection[0] = glm::frustum(left, right, bottom, top, zNear, zFar); ubo.projection[0] = glm::frustum(left, right, bottom, top, zNear, zFar);
uboGS.modelview[0] = rotM * transM; ubo.modelview[0] = rotM * transM;
// Right eye // Right eye
left = -aspectRatio * wd2 - 0.5f * eyeSeparation * ndfl; left = -aspectRatio * wd2 - 0.5f * eyeSeparation * ndfl;
@ -622,10 +627,10 @@ public:
transM = glm::translate(glm::mat4(1.0f), camera.position + camRight * (eyeSeparation / 2.0f)); transM = glm::translate(glm::mat4(1.0f), camera.position + camRight * (eyeSeparation / 2.0f));
uboGS.projection[1] = glm::frustum(left, right, bottom, top, zNear, zFar); ubo.projection[1] = glm::frustum(left, right, bottom, top, zNear, zFar);
uboGS.modelview[1] = rotM * transM; ubo.modelview[1] = rotM * transM;
memcpy(uniformBufferGS.mapped, &uboGS, sizeof(uboGS)); memcpy(uniformBuffer.mapped, &ubo, sizeof(ubo));
} }
void draw() void draw()