Code cleanup

This commit is contained in:
Sascha Willems 2024-01-13 19:25:52 +01:00
parent 8143b2d9e5
commit 8238547d5b

View file

@ -1,5 +1,5 @@
/* /*
* Vulkan Example - Order Independent Transparency rendering * Vulkan Example - Order Independent Transparency rendering using linked lists
* *
* Copyright by Sascha Willems - www.saschawillems.de * Copyright by Sascha Willems - www.saschawillems.de
* Copyright by Daemyung Jang - dm86.jang@gmail.com * Copyright by Daemyung Jang - dm86.jang@gmail.com
@ -20,33 +20,30 @@ public:
vkglTF::Model cube; vkglTF::Model cube;
} models; } models;
struct {
vks::Buffer renderPass;
} uniformBuffers;
struct Node { struct Node {
glm::vec4 color; glm::vec4 color;
float depth; float depth{ 0.0f };
uint32_t next; uint32_t next{ 0 };
}; };
struct { struct {
uint32_t count; uint32_t count{ 0 };
uint32_t maxNodeCount; uint32_t maxNodeCount{ 0 };
} geometrySBO; } geometrySBO;
struct GeometryPass { struct GeometryPass {
VkRenderPass renderPass; VkRenderPass renderPass{ VK_NULL_HANDLE };
VkFramebuffer framebuffer; VkFramebuffer framebuffer{ VK_NULL_HANDLE };
vks::Buffer geometry; vks::Buffer geometry;
vks::Texture headIndex; vks::Texture headIndex;
vks::Buffer linkedList; vks::Buffer linkedList;
} geometryPass; } geometryPass;
struct { struct RenderPassUniformData {
glm::mat4 projection; glm::mat4 projection;
glm::mat4 view; glm::mat4 view;
} renderPassUBO; } renderPassUniformData;
vks::Buffer renderPassUniformBuffer;
struct ObjectData { struct ObjectData {
glm::mat4 model; glm::mat4 model;
@ -54,25 +51,27 @@ public:
}; };
struct { struct {
VkDescriptorSetLayout geometry; VkDescriptorSetLayout geometry{ VK_NULL_HANDLE };
VkDescriptorSetLayout color; VkDescriptorSetLayout color{ VK_NULL_HANDLE };
} descriptorSetLayouts; } descriptorSetLayouts;
struct { struct {
VkPipelineLayout geometry; VkPipelineLayout geometry{ VK_NULL_HANDLE };
VkPipelineLayout color; VkPipelineLayout color{ VK_NULL_HANDLE };
} pipelineLayouts; } pipelineLayouts;
struct { struct {
VkPipeline geometry; VkPipeline geometry{ VK_NULL_HANDLE };
VkPipeline color; VkPipeline color{ VK_NULL_HANDLE };
} pipelines; } pipelines;
struct { struct {
VkDescriptorSet geometry; VkDescriptorSet geometry{ VK_NULL_HANDLE };
VkDescriptorSet color; VkDescriptorSet color{ VK_NULL_HANDLE };
} descriptorSets; } descriptorSets;
VkDeviceSize objectUniformBufferSize{ 0 };
VulkanExample() : VulkanExampleBase() VulkanExample() : VulkanExampleBase()
{ {
title = "Order independent transparency rendering"; title = "Order independent transparency rendering";
@ -84,22 +83,21 @@ public:
~VulkanExample() ~VulkanExample()
{ {
vkDestroyPipeline(device, pipelines.geometry, nullptr); if (device) {
vkDestroyPipeline(device, pipelines.color, nullptr); vkDestroyPipeline(device, pipelines.geometry, nullptr);
vkDestroyPipeline(device, pipelines.color, nullptr);
vkDestroyPipelineLayout(device, pipelineLayouts.geometry, nullptr); vkDestroyPipelineLayout(device, pipelineLayouts.geometry, nullptr);
vkDestroyPipelineLayout(device, pipelineLayouts.color, nullptr); vkDestroyPipelineLayout(device, pipelineLayouts.color, nullptr);
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.geometry, nullptr);
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.geometry, nullptr); vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.color, nullptr);
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.color, nullptr); destroyGeometryPass();
renderPassUniformBuffer.destroy();
destroyGeometryPass(); }
uniformBuffers.renderPass.destroy();
} }
void getEnabledFeatures() override void getEnabledFeatures() override
{ {
// The linked lists are built in a fragment shader using atomic stores, so the sample won't work without that feature available
if (deviceFeatures.fragmentStoresAndAtomics) { if (deviceFeatures.fragmentStoresAndAtomics) {
enabledFeatures.fragmentStoresAndAtomics = VK_TRUE; enabledFeatures.fragmentStoresAndAtomics = VK_TRUE;
} else { } else {
@ -107,45 +105,6 @@ public:
} }
}; };
void prepare() override
{
VulkanExampleBase::prepare();
loadAssets();
prepareUniformBuffers();
prepareGeometryPass();
setupDescriptorSetLayout();
preparePipelines();
setupDescriptorPool();
setupDescriptorSets();
buildCommandBuffers();
updateUniformBuffers();
prepared = true;
}
void render() override
{
if (!prepared)
return;
draw();
}
void windowResized() override
{
destroyGeometryPass();
prepareGeometryPass();
vkResetDescriptorPool(device, descriptorPool, 0);
setupDescriptorSets();
resized = false;
buildCommandBuffers();
}
void viewChanged() override
{
updateUniformBuffers();
}
private:
void loadAssets() void loadAssets()
{ {
const uint32_t glTFLoadingFlags = vkglTF::FileLoadingFlags::PreTransformVertices | vkglTF::FileLoadingFlags::FlipY; const uint32_t glTFLoadingFlags = vkglTF::FileLoadingFlags::PreTransformVertices | vkglTF::FileLoadingFlags::FlipY;
@ -156,13 +115,8 @@ private:
void prepareUniformBuffers() void prepareUniformBuffers()
{ {
// Create an uniform buffer for a render pass. // Create an uniform buffer for a render pass.
VK_CHECK_RESULT(vulkanDevice->createBuffer( VK_CHECK_RESULT(vulkanDevice->createBuffer(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, &renderPassUniformBuffer, sizeof(RenderPassUniformData)));
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_CHECK_RESULT(renderPassUniformBuffer.map());
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
&uniformBuffers.renderPass,
sizeof(renderPassUBO)));
VK_CHECK_RESULT(uniformBuffers.renderPass.map());
} }
void prepareGeometryPass() void prepareGeometryPass()
@ -311,36 +265,81 @@ private:
VK_CHECK_RESULT(vkQueueWaitIdle(queue)); VK_CHECK_RESULT(vkQueueWaitIdle(queue));
} }
void setupDescriptorSetLayout() void setupDescriptors()
{ {
// Create a geometry descriptor set layout. // Pool
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings = { std::vector<VkDescriptorPoolSize> poolSizes = {
// RenderPassUBO vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1),
vks::initializers::descriptorSetLayoutBinding( vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1),
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 3),
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 2),
0),
// AtomicSBO
vks::initializers::descriptorSetLayoutBinding(
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
VK_SHADER_STAGE_FRAGMENT_BIT,
1),
// headIndexImage
vks::initializers::descriptorSetLayoutBinding(
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
VK_SHADER_STAGE_FRAGMENT_BIT,
2),
// LinkedListSBO
vks::initializers::descriptorSetLayoutBinding(
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
VK_SHADER_STAGE_FRAGMENT_BIT,
3),
}; };
VkDescriptorPoolCreateInfo descriptorPoolInfo = vks::initializers::descriptorPoolCreateInfo(poolSizes, 2);
VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool));
// Layouts
// Create a geometry descriptor set layout
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings = {
// renderPassUniformData
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0),
// AtomicSBO
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_FRAGMENT_BIT, 1),
// headIndexImage
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_FRAGMENT_BIT, 2),
// LinkedListSBO
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_FRAGMENT_BIT, 3),
};
VkDescriptorSetLayoutCreateInfo descriptorLayoutCI = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings); VkDescriptorSetLayoutCreateInfo descriptorLayoutCI = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings);
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorLayoutCI, nullptr, &descriptorSetLayouts.geometry)); VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorLayoutCI, nullptr, &descriptorSetLayouts.geometry));
// Create a geometry pipeline layout. // Create a color descriptor set layout
setLayoutBindings = {
// headIndexImage
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_FRAGMENT_BIT, 0),
// LinkedListSBO
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_FRAGMENT_BIT, 1),
};
descriptorLayoutCI = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings);
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorLayoutCI, nullptr, &descriptorSetLayouts.color));
// Sets
VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.geometry, 1);
// Update a geometry descriptor set
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.geometry));
std::vector<VkWriteDescriptorSet> writeDescriptorSets = {
// Binding 0: renderPassUniformData
vks::initializers::writeDescriptorSet(descriptorSets.geometry, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &renderPassUniformBuffer.descriptor),
// Binding 2: GeometrySBO
vks::initializers::writeDescriptorSet(descriptorSets.geometry, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, &geometryPass.geometry.descriptor),
// Binding 3: headIndexImage
vks::initializers::writeDescriptorSet(descriptorSets.geometry, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 2, &geometryPass.headIndex.descriptor),
// Binding 4: LinkedListSBO
vks::initializers::writeDescriptorSet(descriptorSets.geometry, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 3, &geometryPass.linkedList.descriptor)
};
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, nullptr);
// Update a color descriptor set
allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.color, 1);
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.color));
writeDescriptorSets = {
// Binding 0: headIndexImage
vks::initializers::writeDescriptorSet(descriptorSets.color, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 0, &geometryPass.headIndex.descriptor),
// Binding 1: LinkedListSBO
vks::initializers::writeDescriptorSet(descriptorSets.color, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, &geometryPass.linkedList.descriptor)
};
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, nullptr);
}
void preparePipelines()
{
// Layouts
// Create a geometry pipeline layout
VkPipelineLayoutCreateInfo pipelineLayoutCI = vks::initializers::pipelineLayoutCreateInfo(&descriptorSetLayouts.geometry, 1); VkPipelineLayoutCreateInfo pipelineLayoutCI = vks::initializers::pipelineLayoutCreateInfo(&descriptorSetLayouts.geometry, 1);
// Static object data passed using push constants // Static object data passed using push constants
VkPushConstantRange pushConstantRange = vks::initializers::pushConstantRange(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(ObjectData), 0); VkPushConstantRange pushConstantRange = vks::initializers::pushConstantRange(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(ObjectData), 0);
@ -348,30 +347,11 @@ private:
pipelineLayoutCI.pPushConstantRanges = &pushConstantRange; pipelineLayoutCI.pPushConstantRanges = &pushConstantRange;
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCI, nullptr, &pipelineLayouts.geometry)); VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCI, nullptr, &pipelineLayouts.geometry));
// Create a color descriptor set layout. // Create a color pipeline layout
setLayoutBindings = {
// headIndexImage
vks::initializers::descriptorSetLayoutBinding(
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
VK_SHADER_STAGE_FRAGMENT_BIT,
0),
// LinkedListSBO
vks::initializers::descriptorSetLayoutBinding(
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
VK_SHADER_STAGE_FRAGMENT_BIT,
1),
};
descriptorLayoutCI = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings);
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorLayoutCI, nullptr, &descriptorSetLayouts.color));
// Create a color pipeline layout.
pipelineLayoutCI = vks::initializers::pipelineLayoutCreateInfo(&descriptorSetLayouts.color, 1); pipelineLayoutCI = vks::initializers::pipelineLayoutCreateInfo(&descriptorSetLayouts.color, 1);
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCI, nullptr, &pipelineLayouts.color)); VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCI, nullptr, &pipelineLayouts.color));
}
void preparePipelines() // Pipelines
{
VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = vks::initializers::pipelineInputAssemblyStateCreateInfo(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0, VK_FALSE); VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = vks::initializers::pipelineInputAssemblyStateCreateInfo(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0, VK_FALSE);
VkPipelineRasterizationStateCreateInfo rasterizationState = vks::initializers::pipelineRasterizationStateCreateInfo(VK_POLYGON_MODE_FILL, VK_CULL_MODE_BACK_BIT, VK_FRONT_FACE_COUNTER_CLOCKWISE, 0); VkPipelineRasterizationStateCreateInfo rasterizationState = vks::initializers::pipelineRasterizationStateCreateInfo(VK_POLYGON_MODE_FILL, VK_CULL_MODE_BACK_BIT, VK_FRONT_FACE_COUNTER_CLOCKWISE, 0);
VkPipelineColorBlendStateCreateInfo colorBlendState = vks::initializers::pipelineColorBlendStateCreateInfo(0, nullptr); VkPipelineColorBlendStateCreateInfo colorBlendState = vks::initializers::pipelineColorBlendStateCreateInfo(0, nullptr);
@ -382,7 +362,6 @@ private:
VkPipelineDynamicStateCreateInfo dynamicState = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables); VkPipelineDynamicStateCreateInfo dynamicState = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables);
std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages; std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages;
// Create a geometry pipeline.
VkGraphicsPipelineCreateInfo pipelineCI = vks::initializers::pipelineCreateInfo(pipelineLayouts.geometry, geometryPass.renderPass); VkGraphicsPipelineCreateInfo pipelineCI = vks::initializers::pipelineCreateInfo(pipelineLayouts.geometry, geometryPass.renderPass);
pipelineCI.pInputAssemblyState = &inputAssemblyState; pipelineCI.pInputAssemblyState = &inputAssemblyState;
pipelineCI.pRasterizationState = &rasterizationState; pipelineCI.pRasterizationState = &rasterizationState;
@ -395,12 +374,13 @@ private:
pipelineCI.pStages = shaderStages.data(); pipelineCI.pStages = shaderStages.data();
pipelineCI.pVertexInputState = vkglTF::Vertex::getPipelineVertexInputState({ vkglTF::VertexComponent::Position }); pipelineCI.pVertexInputState = vkglTF::Vertex::getPipelineVertexInputState({ vkglTF::VertexComponent::Position });
// Create a geometry pipeline
shaderStages[0] = loadShader(getShadersPath() + "oit/geometry.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); shaderStages[0] = loadShader(getShadersPath() + "oit/geometry.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
shaderStages[1] = loadShader(getShadersPath() + "oit/geometry.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); shaderStages[1] = loadShader(getShadersPath() + "oit/geometry.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.geometry)); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.geometry));
// Create a color pipeline. // Create a color pipeline
VkPipelineColorBlendAttachmentState blendAttachmentState = vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE); VkPipelineColorBlendAttachmentState blendAttachmentState = vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE);
colorBlendState = vks::initializers::pipelineColorBlendStateCreateInfo(1, &blendAttachmentState); colorBlendState = vks::initializers::pipelineColorBlendStateCreateInfo(1, &blendAttachmentState);
@ -427,88 +407,6 @@ private:
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.color)); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.color));
} }
void setupDescriptorPool()
{
std::vector<VkDescriptorPoolSize> poolSizes = {
vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1),
vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1),
vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 3),
vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 2),
};
VkDescriptorPoolCreateInfo descriptorPoolInfo =
vks::initializers::descriptorPoolCreateInfo(poolSizes, 2);
VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool));
}
void setupDescriptorSets()
{
// Update a geometry descriptor set
VkDescriptorSetAllocateInfo allocInfo =
vks::initializers::descriptorSetAllocateInfo(
descriptorPool,
&descriptorSetLayouts.geometry,
1);
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.geometry));
std::vector<VkWriteDescriptorSet> writeDescriptorSets = {
// Binding 0: RenderPassUBO
vks::initializers::writeDescriptorSet(
descriptorSets.geometry,
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
0,
&uniformBuffers.renderPass.descriptor),
// Binding 2: GeometrySBO
vks::initializers::writeDescriptorSet(
descriptorSets.geometry,
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1,
&geometryPass.geometry.descriptor),
// Binding 3: headIndexImage
vks::initializers::writeDescriptorSet(
descriptorSets.geometry,
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
2,
&geometryPass.headIndex.descriptor),
// Binding 4: LinkedListSBO
vks::initializers::writeDescriptorSet(
descriptorSets.geometry,
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
3,
&geometryPass.linkedList.descriptor)
};
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
// Update a color descriptor set.
allocInfo =
vks::initializers::descriptorSetAllocateInfo(
descriptorPool,
&descriptorSetLayouts.color,
1);
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSets.color));
writeDescriptorSets = {
// Binding 0: headIndexImage
vks::initializers::writeDescriptorSet(
descriptorSets.color,
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
0,
&geometryPass.headIndex.descriptor),
// Binding 1: LinkedListSBO
vks::initializers::writeDescriptorSet(
descriptorSets.color,
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1,
&geometryPass.linkedList.descriptor)
};
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
}
void buildCommandBuffers() override void buildCommandBuffers() override
{ {
if (resized) if (resized)
@ -631,9 +529,22 @@ private:
void updateUniformBuffers() void updateUniformBuffers()
{ {
renderPassUBO.projection = camera.matrices.perspective; renderPassUniformData.projection = camera.matrices.perspective;
renderPassUBO.view = camera.matrices.view; renderPassUniformData.view = camera.matrices.view;
memcpy(uniformBuffers.renderPass.mapped, &renderPassUBO, sizeof(renderPassUBO)); memcpy(renderPassUniformBuffer.mapped, &renderPassUniformData, sizeof(RenderPassUniformData));
}
void prepare() override
{
VulkanExampleBase::prepare();
loadAssets();
prepareUniformBuffers();
prepareGeometryPass();
setupDescriptors();
preparePipelines();
buildCommandBuffers();
updateUniformBuffers();
prepared = true;
} }
void draw() void draw()
@ -645,6 +556,24 @@ private:
VulkanExampleBase::submitFrame(); VulkanExampleBase::submitFrame();
} }
void render() override
{
if (!prepared)
return;
updateUniformBuffers();
draw();
}
void windowResized() override
{
destroyGeometryPass();
prepareGeometryPass();
vkResetDescriptorPool(device, descriptorPool, 0);
setupDescriptors();
resized = false;
buildCommandBuffers();
}
void destroyGeometryPass() void destroyGeometryPass()
{ {
vkDestroyRenderPass(device, geometryPass.renderPass, nullptr); vkDestroyRenderPass(device, geometryPass.renderPass, nullptr);
@ -653,9 +582,6 @@ private:
geometryPass.headIndex.destroy(); geometryPass.headIndex.destroy();
geometryPass.linkedList.destroy(); geometryPass.linkedList.destroy();
} }
private:
VkDeviceSize objectUniformBufferSize;
}; };
VULKAN_EXAMPLE_MAIN() VULKAN_EXAMPLE_MAIN()