Code cleanup
This commit is contained in:
parent
eff719099a
commit
9ccb7cbd54
5 changed files with 88 additions and 118 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Vulkan Example - glTF scene loading and rendering
|
* Vulkan Example - glTF scene loading and rendering
|
||||||
*
|
*
|
||||||
* Copyright (C) 2020-2022 by Sascha Willems - www.saschawillems.de
|
* Copyright (C) 2020-2023 by Sascha Willems - www.saschawillems.de
|
||||||
*
|
*
|
||||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||||
*/
|
*/
|
||||||
|
|
@ -395,16 +395,16 @@ public:
|
||||||
} shaderData;
|
} shaderData;
|
||||||
|
|
||||||
struct Pipelines {
|
struct Pipelines {
|
||||||
VkPipeline solid;
|
VkPipeline solid{ VK_NULL_HANDLE };
|
||||||
VkPipeline wireframe = VK_NULL_HANDLE;
|
VkPipeline wireframe{ VK_NULL_HANDLE };
|
||||||
} pipelines;
|
} pipelines;
|
||||||
|
|
||||||
VkPipelineLayout pipelineLayout;
|
VkPipelineLayout pipelineLayout{ VK_NULL_HANDLE };
|
||||||
VkDescriptorSet descriptorSet;
|
VkDescriptorSet descriptorSet{ VK_NULL_HANDLE };
|
||||||
|
|
||||||
struct DescriptorSetLayouts {
|
struct DescriptorSetLayouts {
|
||||||
VkDescriptorSetLayout matrices;
|
VkDescriptorSetLayout matrices{ VK_NULL_HANDLE };
|
||||||
VkDescriptorSetLayout textures;
|
VkDescriptorSetLayout textures{ VK_NULL_HANDLE };
|
||||||
} descriptorSetLayouts;
|
} descriptorSetLayouts;
|
||||||
|
|
||||||
VulkanExample() : VulkanExampleBase()
|
VulkanExample() : VulkanExampleBase()
|
||||||
|
|
@ -419,18 +419,16 @@ public:
|
||||||
|
|
||||||
~VulkanExample()
|
~VulkanExample()
|
||||||
{
|
{
|
||||||
// Clean up used Vulkan resources
|
if (device) {
|
||||||
// Note : Inherited destructor cleans up resources stored in base class
|
vkDestroyPipeline(device, pipelines.solid, nullptr);
|
||||||
vkDestroyPipeline(device, pipelines.solid, nullptr);
|
if (pipelines.wireframe != VK_NULL_HANDLE) {
|
||||||
if (pipelines.wireframe != VK_NULL_HANDLE) {
|
vkDestroyPipeline(device, pipelines.wireframe, nullptr);
|
||||||
vkDestroyPipeline(device, pipelines.wireframe, nullptr);
|
}
|
||||||
|
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
||||||
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.matrices, nullptr);
|
||||||
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.textures, nullptr);
|
||||||
|
shaderData.buffer.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.matrices, nullptr);
|
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.textures, nullptr);
|
|
||||||
|
|
||||||
shaderData.buffer.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void getEnabledFeatures()
|
virtual void getEnabledFeatures()
|
||||||
|
|
@ -446,7 +444,6 @@ public:
|
||||||
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
|
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
|
||||||
|
|
||||||
VkClearValue clearValues[2];
|
VkClearValue clearValues[2];
|
||||||
clearValues[0].color = defaultClearColor;
|
|
||||||
clearValues[0].color = { { 0.25f, 0.25f, 0.25f, 1.0f } };;
|
clearValues[0].color = { { 0.25f, 0.25f, 0.25f, 1.0f } };;
|
||||||
clearValues[1].depthStencil = { 1.0f, 0 };
|
clearValues[1].depthStencil = { 1.0f, 0 };
|
||||||
|
|
||||||
|
|
@ -617,15 +614,6 @@ public:
|
||||||
// Descriptor set layout for passing material textures
|
// Descriptor set layout for passing material textures
|
||||||
setLayoutBinding = vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 0);
|
setLayoutBinding = vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 0);
|
||||||
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.textures));
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.textures));
|
||||||
// Pipeline layout using both descriptor sets (set 0 = matrices, set 1 = material)
|
|
||||||
std::array<VkDescriptorSetLayout, 2> setLayouts = { descriptorSetLayouts.matrices, descriptorSetLayouts.textures };
|
|
||||||
VkPipelineLayoutCreateInfo pipelineLayoutCI= vks::initializers::pipelineLayoutCreateInfo(setLayouts.data(), static_cast<uint32_t>(setLayouts.size()));
|
|
||||||
// We will use push constants to push the local matrices of a primitive to the vertex shader
|
|
||||||
VkPushConstantRange pushConstantRange = vks::initializers::pushConstantRange(VK_SHADER_STAGE_VERTEX_BIT, sizeof(glm::mat4), 0);
|
|
||||||
// Push constant ranges are part of the pipeline layout
|
|
||||||
pipelineLayoutCI.pushConstantRangeCount = 1;
|
|
||||||
pipelineLayoutCI.pPushConstantRanges = &pushConstantRange;
|
|
||||||
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCI, nullptr, &pipelineLayout));
|
|
||||||
|
|
||||||
// Descriptor set for scene matrices
|
// Descriptor set for scene matrices
|
||||||
VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.matrices, 1);
|
VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.matrices, 1);
|
||||||
|
|
@ -643,6 +631,18 @@ public:
|
||||||
|
|
||||||
void preparePipelines()
|
void preparePipelines()
|
||||||
{
|
{
|
||||||
|
// Layout
|
||||||
|
// The pipeline layout uses both descriptor sets (set 0 = matrices, set 1 = material)
|
||||||
|
std::array<VkDescriptorSetLayout, 2> setLayouts = { descriptorSetLayouts.matrices, descriptorSetLayouts.textures };
|
||||||
|
VkPipelineLayoutCreateInfo pipelineLayoutCI = vks::initializers::pipelineLayoutCreateInfo(setLayouts.data(), static_cast<uint32_t>(setLayouts.size()));
|
||||||
|
// We will use push constants to push the local matrices of a primitive to the vertex shader
|
||||||
|
VkPushConstantRange pushConstantRange = vks::initializers::pushConstantRange(VK_SHADER_STAGE_VERTEX_BIT, sizeof(glm::mat4), 0);
|
||||||
|
// Push constant ranges are part of the pipeline layout
|
||||||
|
pipelineLayoutCI.pushConstantRangeCount = 1;
|
||||||
|
pipelineLayoutCI.pPushConstantRanges = &pushConstantRange;
|
||||||
|
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCI, nullptr, &pipelineLayout));
|
||||||
|
|
||||||
|
// Pipeline
|
||||||
VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCI = vks::initializers::pipelineInputAssemblyStateCreateInfo(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0, VK_FALSE);
|
VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCI = vks::initializers::pipelineInputAssemblyStateCreateInfo(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0, VK_FALSE);
|
||||||
VkPipelineRasterizationStateCreateInfo rasterizationStateCI = vks::initializers::pipelineRasterizationStateCreateInfo(VK_POLYGON_MODE_FILL, VK_CULL_MODE_BACK_BIT, VK_FRONT_FACE_COUNTER_CLOCKWISE, 0);
|
VkPipelineRasterizationStateCreateInfo rasterizationStateCI = vks::initializers::pipelineRasterizationStateCreateInfo(VK_POLYGON_MODE_FILL, VK_CULL_MODE_BACK_BIT, VK_FRONT_FACE_COUNTER_CLOCKWISE, 0);
|
||||||
VkPipelineColorBlendAttachmentState blendAttachmentStateCI = vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE);
|
VkPipelineColorBlendAttachmentState blendAttachmentStateCI = vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE);
|
||||||
|
|
@ -651,7 +651,7 @@ public:
|
||||||
VkPipelineViewportStateCreateInfo viewportStateCI = vks::initializers::pipelineViewportStateCreateInfo(1, 1, 0);
|
VkPipelineViewportStateCreateInfo viewportStateCI = vks::initializers::pipelineViewportStateCreateInfo(1, 1, 0);
|
||||||
VkPipelineMultisampleStateCreateInfo multisampleStateCI = vks::initializers::pipelineMultisampleStateCreateInfo(VK_SAMPLE_COUNT_1_BIT, 0);
|
VkPipelineMultisampleStateCreateInfo multisampleStateCI = vks::initializers::pipelineMultisampleStateCreateInfo(VK_SAMPLE_COUNT_1_BIT, 0);
|
||||||
const std::vector<VkDynamicState> dynamicStateEnables = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
|
const std::vector<VkDynamicState> dynamicStateEnables = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
|
||||||
VkPipelineDynamicStateCreateInfo dynamicStateCI = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables.data(), static_cast<uint32_t>(dynamicStateEnables.size()), 0);
|
VkPipelineDynamicStateCreateInfo dynamicStateCI = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables);
|
||||||
// Vertex input bindings and attributes
|
// Vertex input bindings and attributes
|
||||||
const std::vector<VkVertexInputBindingDescription> vertexInputBindings = {
|
const std::vector<VkVertexInputBindingDescription> vertexInputBindings = {
|
||||||
vks::initializers::vertexInputBindingDescription(0, sizeof(VulkanglTFModel::Vertex), VK_VERTEX_INPUT_RATE_VERTEX),
|
vks::initializers::vertexInputBindingDescription(0, sizeof(VulkanglTFModel::Vertex), VK_VERTEX_INPUT_RATE_VERTEX),
|
||||||
|
|
@ -700,16 +700,9 @@ public:
|
||||||
void prepareUniformBuffers()
|
void prepareUniformBuffers()
|
||||||
{
|
{
|
||||||
// Vertex shader uniform buffer block
|
// Vertex shader uniform buffer block
|
||||||
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, &shaderData.buffer, sizeof(shaderData.values)));
|
||||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
|
||||||
&shaderData.buffer,
|
|
||||||
sizeof(shaderData.values)));
|
|
||||||
|
|
||||||
// Map persistent
|
// Map persistent
|
||||||
VK_CHECK_RESULT(shaderData.buffer.map());
|
VK_CHECK_RESULT(shaderData.buffer.map());
|
||||||
|
|
||||||
updateUniformBuffers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateUniformBuffers()
|
void updateUniformBuffers()
|
||||||
|
|
@ -732,16 +725,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void render()
|
virtual void render()
|
||||||
{
|
|
||||||
renderFrame();
|
|
||||||
if (camera.updated) {
|
|
||||||
updateUniformBuffers();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void viewChanged()
|
|
||||||
{
|
{
|
||||||
updateUniformBuffers();
|
updateUniformBuffers();
|
||||||
|
renderFrame();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Vulkan Example - Scene rendering
|
* Vulkan Example - Scene rendering
|
||||||
*
|
*
|
||||||
* Copyright (C) 2020-202- by Sascha Willems - www.saschawillems.de
|
* Copyright (C) 2020-2023 by Sascha Willems - www.saschawillems.de
|
||||||
*
|
*
|
||||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||||
*
|
*
|
||||||
|
|
@ -296,10 +296,12 @@ VulkanExample::VulkanExample() : VulkanExampleBase()
|
||||||
|
|
||||||
VulkanExample::~VulkanExample()
|
VulkanExample::~VulkanExample()
|
||||||
{
|
{
|
||||||
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
if (device) {
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.matrices, nullptr);
|
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.textures, nullptr);
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.matrices, nullptr);
|
||||||
shaderData.buffer.destroy();
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.textures, nullptr);
|
||||||
|
shaderData.buffer.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanExample::getEnabledFeatures()
|
void VulkanExample::getEnabledFeatures()
|
||||||
|
|
@ -501,16 +503,6 @@ void VulkanExample::setupDescriptors()
|
||||||
descriptorSetLayoutCI.bindingCount = 2;
|
descriptorSetLayoutCI.bindingCount = 2;
|
||||||
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.textures));
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.textures));
|
||||||
|
|
||||||
// Pipeline layout using both descriptor sets (set 0 = matrices, set 1 = material)
|
|
||||||
std::array<VkDescriptorSetLayout, 2> setLayouts = { descriptorSetLayouts.matrices, descriptorSetLayouts.textures };
|
|
||||||
VkPipelineLayoutCreateInfo pipelineLayoutCI = vks::initializers::pipelineLayoutCreateInfo(setLayouts.data(), static_cast<uint32_t>(setLayouts.size()));
|
|
||||||
// We will use push constants to push the local matrices of a primitive to the vertex shader
|
|
||||||
VkPushConstantRange pushConstantRange = vks::initializers::pushConstantRange(VK_SHADER_STAGE_VERTEX_BIT, sizeof(glm::mat4), 0);
|
|
||||||
// Push constant ranges are part of the pipeline layout
|
|
||||||
pipelineLayoutCI.pushConstantRangeCount = 1;
|
|
||||||
pipelineLayoutCI.pPushConstantRanges = &pushConstantRange;
|
|
||||||
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCI, nullptr, &pipelineLayout));
|
|
||||||
|
|
||||||
// Descriptor set for scene matrices
|
// Descriptor set for scene matrices
|
||||||
VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.matrices, 1);
|
VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.matrices, 1);
|
||||||
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet));
|
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet));
|
||||||
|
|
@ -533,6 +525,18 @@ void VulkanExample::setupDescriptors()
|
||||||
|
|
||||||
void VulkanExample::preparePipelines()
|
void VulkanExample::preparePipelines()
|
||||||
{
|
{
|
||||||
|
// Layout
|
||||||
|
// Pipeline layout uses both descriptor sets (set 0 = matrices, set 1 = material)
|
||||||
|
std::array<VkDescriptorSetLayout, 2> setLayouts = { descriptorSetLayouts.matrices, descriptorSetLayouts.textures };
|
||||||
|
VkPipelineLayoutCreateInfo pipelineLayoutCI = vks::initializers::pipelineLayoutCreateInfo(setLayouts.data(), static_cast<uint32_t>(setLayouts.size()));
|
||||||
|
// We will use push constants to push the local matrices of a primitive to the vertex shader
|
||||||
|
VkPushConstantRange pushConstantRange = vks::initializers::pushConstantRange(VK_SHADER_STAGE_VERTEX_BIT, sizeof(glm::mat4), 0);
|
||||||
|
// Push constant ranges are part of the pipeline layout
|
||||||
|
pipelineLayoutCI.pushConstantRangeCount = 1;
|
||||||
|
pipelineLayoutCI.pPushConstantRanges = &pushConstantRange;
|
||||||
|
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCI, nullptr, &pipelineLayout));
|
||||||
|
|
||||||
|
// Pipelines
|
||||||
VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCI = vks::initializers::pipelineInputAssemblyStateCreateInfo(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0, VK_FALSE);
|
VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCI = vks::initializers::pipelineInputAssemblyStateCreateInfo(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0, VK_FALSE);
|
||||||
VkPipelineRasterizationStateCreateInfo rasterizationStateCI = vks::initializers::pipelineRasterizationStateCreateInfo(VK_POLYGON_MODE_FILL, VK_CULL_MODE_BACK_BIT, VK_FRONT_FACE_COUNTER_CLOCKWISE, 0);
|
VkPipelineRasterizationStateCreateInfo rasterizationStateCI = vks::initializers::pipelineRasterizationStateCreateInfo(VK_POLYGON_MODE_FILL, VK_CULL_MODE_BACK_BIT, VK_FRONT_FACE_COUNTER_CLOCKWISE, 0);
|
||||||
VkPipelineColorBlendAttachmentState blendAttachmentStateCI = vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE);
|
VkPipelineColorBlendAttachmentState blendAttachmentStateCI = vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE);
|
||||||
|
|
@ -599,13 +603,8 @@ void VulkanExample::preparePipelines()
|
||||||
|
|
||||||
void VulkanExample::prepareUniformBuffers()
|
void VulkanExample::prepareUniformBuffers()
|
||||||
{
|
{
|
||||||
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, &shaderData.buffer, sizeof(shaderData.values)));
|
||||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
|
||||||
&shaderData.buffer,
|
|
||||||
sizeof(shaderData.values)));
|
|
||||||
VK_CHECK_RESULT(shaderData.buffer.map());
|
VK_CHECK_RESULT(shaderData.buffer.map());
|
||||||
updateUniformBuffers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanExample::updateUniformBuffers()
|
void VulkanExample::updateUniformBuffers()
|
||||||
|
|
@ -628,16 +627,9 @@ void VulkanExample::prepare()
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanExample::render()
|
void VulkanExample::render()
|
||||||
{
|
|
||||||
renderFrame();
|
|
||||||
if (camera.updated) {
|
|
||||||
updateUniformBuffers();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VulkanExample::viewChanged()
|
|
||||||
{
|
{
|
||||||
updateUniformBuffers();
|
updateUniformBuffers();
|
||||||
|
renderFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay* overlay)
|
void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay* overlay)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Vulkan Example - Scene rendering
|
* Vulkan Example - Scene rendering
|
||||||
*
|
*
|
||||||
* Copyright (C) 2020-2022 by Sascha Willems - www.saschawillems.de
|
* Copyright (C) 2020-2023 by Sascha Willems - www.saschawillems.de
|
||||||
*
|
*
|
||||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||||
*
|
*
|
||||||
|
|
@ -146,12 +146,12 @@ public:
|
||||||
} values;
|
} values;
|
||||||
} shaderData;
|
} shaderData;
|
||||||
|
|
||||||
VkPipelineLayout pipelineLayout;
|
VkPipelineLayout pipelineLayout{ VK_NULL_HANDLE };
|
||||||
VkDescriptorSet descriptorSet;
|
VkDescriptorSet descriptorSet{ VK_NULL_HANDLE };
|
||||||
|
|
||||||
struct DescriptorSetLayouts {
|
struct DescriptorSetLayouts {
|
||||||
VkDescriptorSetLayout matrices;
|
VkDescriptorSetLayout matrices{ VK_NULL_HANDLE };
|
||||||
VkDescriptorSetLayout textures;
|
VkDescriptorSetLayout textures{ VK_NULL_HANDLE };
|
||||||
} descriptorSetLayouts;
|
} descriptorSetLayouts;
|
||||||
|
|
||||||
VulkanExample();
|
VulkanExample();
|
||||||
|
|
@ -166,6 +166,5 @@ public:
|
||||||
void updateUniformBuffers();
|
void updateUniformBuffers();
|
||||||
void prepare();
|
void prepare();
|
||||||
virtual void render();
|
virtual void render();
|
||||||
virtual void viewChanged();
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay* overlay);
|
virtual void OnUpdateUIOverlay(vks::UIOverlay* overlay);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Vulkan Example - glTF skinned animation
|
* Vulkan Example - glTF skinned animation
|
||||||
*
|
*
|
||||||
* Copyright (C) 2020-2021 by Sascha Willems - www.saschawillems.de
|
* Copyright (C) 2020-2023 by Sascha Willems - www.saschawillems.de
|
||||||
*
|
*
|
||||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||||
*/
|
*/
|
||||||
|
|
@ -849,23 +849,6 @@ void VulkanExample::setupDescriptors()
|
||||||
setLayoutBinding = vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 0);
|
setLayoutBinding = vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 0);
|
||||||
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.jointMatrices));
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.jointMatrices));
|
||||||
|
|
||||||
// The pipeline layout uses three sets:
|
|
||||||
// Set 0 = Scene matrices (VS)
|
|
||||||
// Set 1 = Joint matrices (VS)
|
|
||||||
// Set 2 = Material texture (FS)
|
|
||||||
std::array<VkDescriptorSetLayout, 3> setLayouts = {
|
|
||||||
descriptorSetLayouts.matrices,
|
|
||||||
descriptorSetLayouts.jointMatrices,
|
|
||||||
descriptorSetLayouts.textures};
|
|
||||||
VkPipelineLayoutCreateInfo pipelineLayoutCI = vks::initializers::pipelineLayoutCreateInfo(setLayouts.data(), static_cast<uint32_t>(setLayouts.size()));
|
|
||||||
|
|
||||||
// We will use push constants to push the local matrices of a primitive to the vertex shader
|
|
||||||
VkPushConstantRange pushConstantRange = vks::initializers::pushConstantRange(VK_SHADER_STAGE_VERTEX_BIT, sizeof(glm::mat4), 0);
|
|
||||||
// Push constant ranges are part of the pipeline layout
|
|
||||||
pipelineLayoutCI.pushConstantRangeCount = 1;
|
|
||||||
pipelineLayoutCI.pPushConstantRanges = &pushConstantRange;
|
|
||||||
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCI, nullptr, &pipelineLayout));
|
|
||||||
|
|
||||||
// Descriptor set for scene matrices
|
// Descriptor set for scene matrices
|
||||||
VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.matrices, 1);
|
VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayouts.matrices, 1);
|
||||||
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet));
|
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet));
|
||||||
|
|
@ -893,6 +876,25 @@ void VulkanExample::setupDescriptors()
|
||||||
|
|
||||||
void VulkanExample::preparePipelines()
|
void VulkanExample::preparePipelines()
|
||||||
{
|
{
|
||||||
|
// Layout
|
||||||
|
// The pipeline layout uses three sets:
|
||||||
|
// Set 0 = Scene matrices (VS)
|
||||||
|
// Set 1 = Joint matrices (VS)
|
||||||
|
// Set 2 = Material texture (FS)
|
||||||
|
std::array<VkDescriptorSetLayout, 3> setLayouts = {
|
||||||
|
descriptorSetLayouts.matrices,
|
||||||
|
descriptorSetLayouts.jointMatrices,
|
||||||
|
descriptorSetLayouts.textures };
|
||||||
|
VkPipelineLayoutCreateInfo pipelineLayoutCI = vks::initializers::pipelineLayoutCreateInfo(setLayouts.data(), static_cast<uint32_t>(setLayouts.size()));
|
||||||
|
|
||||||
|
// We will use push constants to push the local matrices of a primitive to the vertex shader
|
||||||
|
VkPushConstantRange pushConstantRange = vks::initializers::pushConstantRange(VK_SHADER_STAGE_VERTEX_BIT, sizeof(glm::mat4), 0);
|
||||||
|
// Push constant ranges are part of the pipeline layout
|
||||||
|
pipelineLayoutCI.pushConstantRangeCount = 1;
|
||||||
|
pipelineLayoutCI.pPushConstantRanges = &pushConstantRange;
|
||||||
|
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCI, nullptr, &pipelineLayout));
|
||||||
|
|
||||||
|
// Pipeline
|
||||||
VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCI = vks::initializers::pipelineInputAssemblyStateCreateInfo(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0, VK_FALSE);
|
VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCI = vks::initializers::pipelineInputAssemblyStateCreateInfo(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0, VK_FALSE);
|
||||||
VkPipelineRasterizationStateCreateInfo rasterizationStateCI = vks::initializers::pipelineRasterizationStateCreateInfo(VK_POLYGON_MODE_FILL, VK_CULL_MODE_BACK_BIT, VK_FRONT_FACE_COUNTER_CLOCKWISE, 0);
|
VkPipelineRasterizationStateCreateInfo rasterizationStateCI = vks::initializers::pipelineRasterizationStateCreateInfo(VK_POLYGON_MODE_FILL, VK_CULL_MODE_BACK_BIT, VK_FRONT_FACE_COUNTER_CLOCKWISE, 0);
|
||||||
VkPipelineColorBlendAttachmentState blendAttachmentStateCI = vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE);
|
VkPipelineColorBlendAttachmentState blendAttachmentStateCI = vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE);
|
||||||
|
|
@ -982,21 +984,12 @@ void VulkanExample::prepare()
|
||||||
|
|
||||||
void VulkanExample::render()
|
void VulkanExample::render()
|
||||||
{
|
{
|
||||||
renderFrame();
|
updateUniformBuffers();
|
||||||
if (camera.updated)
|
|
||||||
{
|
|
||||||
updateUniformBuffers();
|
|
||||||
}
|
|
||||||
// POI: Advance animation
|
// POI: Advance animation
|
||||||
if (!paused)
|
if (!paused) {
|
||||||
{
|
|
||||||
glTFModel.updateAnimation(frameTimer);
|
glTFModel.updateAnimation(frameTimer);
|
||||||
}
|
}
|
||||||
}
|
renderFrame();
|
||||||
|
|
||||||
void VulkanExample::viewChanged()
|
|
||||||
{
|
|
||||||
updateUniformBuffers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Vulkan Example - glTF skinned animation
|
* Vulkan Example - glTF skinned animation
|
||||||
*
|
*
|
||||||
* Copyright (C) 2020 by Sascha Willems - www.saschawillems.de
|
* Copyright (C) 2020-2023 by Sascha Willems - www.saschawillems.de
|
||||||
*
|
*
|
||||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||||
*/
|
*/
|
||||||
|
|
@ -205,17 +205,17 @@ class VulkanExample : public VulkanExampleBase
|
||||||
VkPipelineLayout pipelineLayout;
|
VkPipelineLayout pipelineLayout;
|
||||||
struct Pipelines
|
struct Pipelines
|
||||||
{
|
{
|
||||||
VkPipeline solid;
|
VkPipeline solid{ VK_NULL_HANDLE };
|
||||||
VkPipeline wireframe = VK_NULL_HANDLE;
|
VkPipeline wireframe{ VK_NULL_HANDLE };
|
||||||
} pipelines;
|
} pipelines;
|
||||||
|
|
||||||
struct DescriptorSetLayouts
|
struct DescriptorSetLayouts
|
||||||
{
|
{
|
||||||
VkDescriptorSetLayout matrices;
|
VkDescriptorSetLayout matrices{ VK_NULL_HANDLE };
|
||||||
VkDescriptorSetLayout textures;
|
VkDescriptorSetLayout textures{ VK_NULL_HANDLE };
|
||||||
VkDescriptorSetLayout jointMatrices;
|
VkDescriptorSetLayout jointMatrices{ VK_NULL_HANDLE };
|
||||||
} descriptorSetLayouts;
|
} descriptorSetLayouts;
|
||||||
VkDescriptorSet descriptorSet;
|
VkDescriptorSet descriptorSet{ VK_NULL_HANDLE };
|
||||||
|
|
||||||
VulkanglTFModel glTFModel;
|
VulkanglTFModel glTFModel;
|
||||||
|
|
||||||
|
|
@ -231,6 +231,5 @@ class VulkanExample : public VulkanExampleBase
|
||||||
void updateUniformBuffers();
|
void updateUniformBuffers();
|
||||||
void prepare();
|
void prepare();
|
||||||
virtual void render();
|
virtual void render();
|
||||||
virtual void viewChanged();
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay);
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue