Wireframe toggle
This commit is contained in:
parent
de0c29b586
commit
44e26648e5
1 changed files with 36 additions and 6 deletions
|
|
@ -34,6 +34,8 @@ struct Vertex {
|
||||||
class VulkanExample : public VulkanExampleBase
|
class VulkanExample : public VulkanExampleBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
bool wireframe = false;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
vkTools::VulkanTexture colorMap;
|
vkTools::VulkanTexture colorMap;
|
||||||
} textures;
|
} textures;
|
||||||
|
|
@ -67,11 +69,12 @@ public:
|
||||||
struct {
|
struct {
|
||||||
glm::mat4 projection;
|
glm::mat4 projection;
|
||||||
glm::mat4 model;
|
glm::mat4 model;
|
||||||
glm::vec4 lightPos = glm::vec4(5.0f, 5.0f, 5.0f, 1.0f);
|
glm::vec4 lightPos = glm::vec4(25.0f, 5.0f, 5.0f, 1.0f);
|
||||||
} uboVS;
|
} uboVS;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
VkPipeline solid;
|
VkPipeline solid;
|
||||||
|
VkPipeline wireframe;
|
||||||
} pipelines;
|
} pipelines;
|
||||||
|
|
||||||
VkPipelineLayout pipelineLayout;
|
VkPipelineLayout pipelineLayout;
|
||||||
|
|
@ -80,12 +83,11 @@ public:
|
||||||
|
|
||||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||||
{
|
{
|
||||||
width = 1280;
|
zoom = -5.5f;
|
||||||
height = 720;
|
|
||||||
zoom = -5.5;
|
|
||||||
zoomSpeed = 2.5f;
|
zoomSpeed = 2.5f;
|
||||||
rotationSpeed = 0.5f;
|
rotationSpeed = 0.5f;
|
||||||
rotation = { -25.5, -123.75, 0.0 };
|
rotation = { -0.5f, -112.75f, 0.0f };
|
||||||
|
cameraPos = { 0.1f, 1.1f, 0.0f };
|
||||||
title = "Vulkan Example - Mesh rendering";
|
title = "Vulkan Example - Mesh rendering";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,6 +111,16 @@ public:
|
||||||
vkTools::destroyUniformData(device, &uniformData.vsScene);
|
vkTools::destroyUniformData(device, &uniformData.vsScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void reBuildCommandBuffers()
|
||||||
|
{
|
||||||
|
if (!checkCommandBuffers())
|
||||||
|
{
|
||||||
|
destroyCommandBuffers();
|
||||||
|
createCommandBuffers();
|
||||||
|
}
|
||||||
|
buildCommandBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
void buildCommandBuffers()
|
void buildCommandBuffers()
|
||||||
{
|
{
|
||||||
VkCommandBufferBeginInfo cmdBufInfo = vkTools::initializers::commandBufferBeginInfo();
|
VkCommandBufferBeginInfo cmdBufInfo = vkTools::initializers::commandBufferBeginInfo();
|
||||||
|
|
@ -142,7 +154,7 @@ public:
|
||||||
vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);
|
vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);
|
||||||
|
|
||||||
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, NULL);
|
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, NULL);
|
||||||
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.solid);
|
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, wireframe ? pipelines.wireframe : pipelines.solid);
|
||||||
|
|
||||||
VkDeviceSize offsets[1] = { 0 };
|
VkDeviceSize offsets[1] = { 0 };
|
||||||
// Bind mesh vertex buffer
|
// Bind mesh vertex buffer
|
||||||
|
|
@ -536,6 +548,12 @@ public:
|
||||||
pipelineCreateInfo.pStages = shaderStages.data();
|
pipelineCreateInfo.pStages = shaderStages.data();
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.solid));
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.solid));
|
||||||
|
|
||||||
|
// Wire frame rendering pipeline
|
||||||
|
rasterizationState.polygonMode = VK_POLYGON_MODE_LINE;
|
||||||
|
rasterizationState.lineWidth = 1.0f;
|
||||||
|
|
||||||
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.wireframe));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare and initialize uniform buffer containing shader uniforms
|
// Prepare and initialize uniform buffer containing shader uniforms
|
||||||
|
|
@ -596,6 +614,18 @@ public:
|
||||||
vkDeviceWaitIdle(device);
|
vkDeviceWaitIdle(device);
|
||||||
updateUniformBuffers();
|
updateUniformBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void keyPressed(uint32_t keyCode)
|
||||||
|
{
|
||||||
|
switch (keyCode)
|
||||||
|
{
|
||||||
|
case 0x57:
|
||||||
|
case GAMEPAD_BUTTON_A:
|
||||||
|
wireframe = !wireframe;
|
||||||
|
reBuildCommandBuffers();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VulkanExample *vulkanExample;
|
VulkanExample *vulkanExample;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue