Code cleanup, fixed validation error

Refs #277
This commit is contained in:
saschawillems 2018-10-20 11:38:43 +02:00
parent 69914d9033
commit 09c6e42468

View file

@ -159,8 +159,6 @@ public:
uint32_t mipLevels; uint32_t mipLevels;
} texture; } texture;
bool regenerateNoise = true;
struct { struct {
vks::Model cube; vks::Model cube;
} models; } models;
@ -307,6 +305,8 @@ public:
texture.descriptor.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; texture.descriptor.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
texture.descriptor.imageView = texture.view; texture.descriptor.imageView = texture.view;
texture.descriptor.sampler = texture.sampler; texture.descriptor.sampler = texture.sampler;
updateNoiseTexture();
} }
// Generate randomized noise and upload it to the 3D texture using staging // Generate randomized noise and upload it to the 3D texture using staging
@ -384,9 +384,7 @@ public:
VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); VkCommandBuffer copyCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
// Image barrier for optimal image // The sub resource range describes the regions of the image we will be transitioned
// The sub resource range describes the regions of the image we will be transition
VkImageSubresourceRange subresourceRange = {}; VkImageSubresourceRange subresourceRange = {};
subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
subresourceRange.baseMipLevel = 0; subresourceRange.baseMipLevel = 0;
@ -437,7 +435,6 @@ public:
delete[] data; delete[] data;
vkFreeMemory(device, stagingMemory, nullptr); vkFreeMemory(device, stagingMemory, nullptr);
vkDestroyBuffer(device, stagingBuffer, nullptr); vkDestroyBuffer(device, stagingBuffer, nullptr);
regenerateNoise = false;
} }
// Free all Vulkan resources used a texture object // Free all Vulkan resources used a texture object
@ -789,7 +786,7 @@ public:
generateQuad(); generateQuad();
setupVertexDescriptions(); setupVertexDescriptions();
prepareUniformBuffers(); prepareUniformBuffers();
prepareNoiseTexture(256, 256, 256); prepareNoiseTexture(128, 128, 128);
setupDescriptorSetLayout(); setupDescriptorSetLayout();
preparePipelines(); preparePipelines();
setupDescriptorPool(); setupDescriptorPool();
@ -803,28 +800,15 @@ public:
if (!prepared) if (!prepared)
return; return;
draw(); draw();
if (regenerateNoise) if (!paused || camera.updated)
{ updateUniformBuffers(camera.updated);
updateNoiseTexture();
}
if (!paused)
updateUniformBuffers(false);
}
virtual void viewChanged()
{
updateUniformBuffers();
} }
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
{ {
if (overlay->header("Settings")) { if (overlay->header("Settings")) {
if (regenerateNoise) { if (overlay->button("Generate new texture")) {
overlay->text("Generating new noise texture..."); updateNoiseTexture();
} else {
if (overlay->button("Generate new texture")) {
regenerateNoise = true;
}
} }
} }
} }