Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SaschaWillems committed Jan 16, 2024
1 parent 3019e4a commit f211a64
Showing 1 changed file with 37 additions and 45 deletions.
82 changes: 37 additions & 45 deletions examples/pbrtexture/pbrtexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ class VulkanExample : public VulkanExampleBase
} uboParams;

struct {
VkPipeline skybox;
VkPipeline pbr;
VkPipeline skybox{ VK_NULL_HANDLE };
VkPipeline pbr{ VK_NULL_HANDLE };
} pipelines;

struct {
VkDescriptorSet object;
VkDescriptorSet skybox;
VkDescriptorSet object{ VK_NULL_HANDLE };
VkDescriptorSet skybox{ VK_NULL_HANDLE };
} descriptorSets;

VkPipelineLayout pipelineLayout;
VkDescriptorSetLayout descriptorSetLayout;
VkPipelineLayout pipelineLayout{ VK_NULL_HANDLE };
VkDescriptorSetLayout descriptorSetLayout{ VK_NULL_HANDLE };

VulkanExample() : VulkanExampleBase()
{
Expand All @@ -82,25 +82,27 @@ class VulkanExample : public VulkanExampleBase

~VulkanExample()
{
vkDestroyPipeline(device, pipelines.skybox, nullptr);
vkDestroyPipeline(device, pipelines.pbr, nullptr);

vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);

uniformBuffers.object.destroy();
uniformBuffers.skybox.destroy();
uniformBuffers.params.destroy();

textures.environmentCube.destroy();
textures.irradianceCube.destroy();
textures.prefilteredCube.destroy();
textures.lutBrdf.destroy();
textures.albedoMap.destroy();
textures.normalMap.destroy();
textures.aoMap.destroy();
textures.metallicMap.destroy();
textures.roughnessMap.destroy();
if (device) {
vkDestroyPipeline(device, pipelines.skybox, nullptr);
vkDestroyPipeline(device, pipelines.pbr, nullptr);

vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);

uniformBuffers.object.destroy();
uniformBuffers.skybox.destroy();
uniformBuffers.params.destroy();

textures.environmentCube.destroy();
textures.irradianceCube.destroy();
textures.prefilteredCube.destroy();
textures.lutBrdf.destroy();
textures.albedoMap.destroy();
textures.normalMap.destroy();
textures.aoMap.destroy();
textures.metallicMap.destroy();
textures.roughnessMap.destroy();
}
}

virtual void getEnabledFeatures()
Expand Down Expand Up @@ -1300,17 +1302,6 @@ class VulkanExample : public VulkanExampleBase
memcpy(uniformBuffers.params.mapped, &uboParams, sizeof(uboParams));
}

void draw()
{
VulkanExampleBase::prepareFrame();

submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));

VulkanExampleBase::submitFrame();
}

void prepare()
{
VulkanExampleBase::prepare();
Expand All @@ -1325,20 +1316,21 @@ class VulkanExample : public VulkanExampleBase
prepared = true;
}

virtual void render()
void draw()
{
if (!prepared)
return;
draw();
if (camera.updated)
{
updateUniformBuffers();
}
VulkanExampleBase::prepareFrame();
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
VulkanExampleBase::submitFrame();
}

virtual void viewChanged()
virtual void render()
{
if (!prepared)
return;
updateUniformBuffers();
draw();
}

virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
Expand Down

0 comments on commit f211a64

Please sign in to comment.