2016-02-16 15:07:25 +01:00
|
|
|
/*
|
|
|
|
|
* Vulkan Example - Displacement mapping with tessellation shaders
|
|
|
|
|
*
|
2024-01-15 19:12:06 +01:00
|
|
|
* This samples uses tessellation shaders to displace geometry based on a height map
|
|
|
|
|
*
|
2016-02-16 15:07:25 +01:00
|
|
|
* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de
|
|
|
|
|
*
|
|
|
|
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "vulkanexamplebase.h"
|
2020-07-28 20:20:38 +02:00
|
|
|
#include "VulkanglTFModel.h"
|
2016-02-16 15:07:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class VulkanExample : public VulkanExampleBase
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
bool splitScreen = true;
|
2016-06-06 14:28:13 +02:00
|
|
|
bool displacement = true;
|
2016-02-16 15:07:25 +01:00
|
|
|
|
2020-07-28 20:20:38 +02:00
|
|
|
vkglTF::Model plane;
|
2024-01-15 19:12:06 +01:00
|
|
|
vks::Texture2D colorHeightMap;
|
2016-02-16 15:07:25 +01:00
|
|
|
|
2024-01-15 19:12:06 +01:00
|
|
|
// Uniform data/buffer used by both tessellation shader stages
|
|
|
|
|
struct UniformData {
|
2016-02-16 15:07:25 +01:00
|
|
|
glm::mat4 projection;
|
2020-04-22 20:58:24 +02:00
|
|
|
glm::mat4 modelView;
|
2016-06-06 14:28:13 +02:00
|
|
|
glm::vec4 lightPos = glm::vec4(0.0f, -1.0f, 0.0f, 0.0f);
|
|
|
|
|
float tessAlpha = 1.0f;
|
|
|
|
|
float tessStrength = 0.1f;
|
2024-01-15 19:12:06 +01:00
|
|
|
float tessLevel = 64.0f;
|
|
|
|
|
} uniformData;
|
|
|
|
|
vks::Buffer uniformBuffer;
|
2016-02-16 15:07:25 +01:00
|
|
|
|
2017-03-17 18:21:15 +01:00
|
|
|
struct Pipelines {
|
2024-01-15 19:12:06 +01:00
|
|
|
VkPipeline solid{ VK_NULL_HANDLE };
|
|
|
|
|
VkPipeline wireframe{ VK_NULL_HANDLE };
|
2016-02-16 15:07:25 +01:00
|
|
|
} pipelines;
|
|
|
|
|
|
2024-01-15 19:12:06 +01:00
|
|
|
VkPipelineLayout pipelineLayout{ VK_NULL_HANDLE };
|
|
|
|
|
VkDescriptorSet descriptorSet{ VK_NULL_HANDLE };
|
|
|
|
|
VkDescriptorSetLayout descriptorSetLayout{ VK_NULL_HANDLE };
|
2016-02-16 15:07:25 +01:00
|
|
|
|
2023-12-30 13:15:37 +01:00
|
|
|
VulkanExample() : VulkanExampleBase()
|
2016-02-16 15:07:25 +01:00
|
|
|
{
|
2017-11-01 14:22:10 +01:00
|
|
|
title = "Tessellation shader displacement";
|
2020-04-22 20:58:24 +02:00
|
|
|
camera.type = Camera::CameraType::lookat;
|
|
|
|
|
camera.setPosition(glm::vec3(0.0f, 0.0f, -1.25f));
|
|
|
|
|
camera.setRotation(glm::vec3(-20.0f, 45.0f, 0.0f));
|
|
|
|
|
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
2016-02-16 15:07:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~VulkanExample()
|
|
|
|
|
{
|
2024-01-15 19:12:06 +01:00
|
|
|
if (device) {
|
|
|
|
|
vkDestroyPipeline(device, pipelines.solid, nullptr);
|
|
|
|
|
if (pipelines.wireframe != VK_NULL_HANDLE) {
|
|
|
|
|
vkDestroyPipeline(device, pipelines.wireframe, nullptr);
|
|
|
|
|
};
|
|
|
|
|
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
|
|
|
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
|
|
|
|
|
uniformBuffer.destroy();
|
|
|
|
|
colorHeightMap.destroy();
|
|
|
|
|
}
|
2016-02-16 15:07:25 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-29 16:08:53 +01:00
|
|
|
// Enable physical device features required for this example
|
2017-03-17 18:21:15 +01:00
|
|
|
virtual void getEnabledFeatures()
|
|
|
|
|
{
|
2017-03-17 20:48:13 +01:00
|
|
|
// Tessellation shader support is required for this example
|
|
|
|
|
if (deviceFeatures.tessellationShader) {
|
|
|
|
|
enabledFeatures.tessellationShader = VK_TRUE;
|
2017-03-17 18:21:15 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2018-01-21 18:28:17 +01:00
|
|
|
vks::tools::exitFatal("Selected GPU does not support tessellation shaders!", VK_ERROR_FEATURE_NOT_PRESENT);
|
2017-03-17 18:21:15 +01:00
|
|
|
}
|
|
|
|
|
// Fill mode non solid is required for wireframe display
|
|
|
|
|
if (deviceFeatures.fillModeNonSolid) {
|
|
|
|
|
enabledFeatures.fillModeNonSolid = VK_TRUE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
splitScreen = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-09 21:55:35 +01:00
|
|
|
void loadAssets()
|
2016-02-16 15:07:25 +01:00
|
|
|
{
|
2020-07-28 20:20:38 +02:00
|
|
|
const uint32_t glTFLoadingFlags = vkglTF::FileLoadingFlags::PreTransformVertices | vkglTF::FileLoadingFlags::PreMultiplyVertexColors | vkglTF::FileLoadingFlags::FlipY;
|
|
|
|
|
plane.loadFromFile(getAssetPath() + "models/displacement_plane.gltf", vulkanDevice, queue, glTFLoadingFlags);
|
2024-01-15 19:12:06 +01:00
|
|
|
colorHeightMap.loadFromFile(getAssetPath() + "textures/stonefloor03_color_height_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue);
|
2016-02-16 15:07:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void buildCommandBuffers()
|
|
|
|
|
{
|
2017-02-12 11:12:42 +01:00
|
|
|
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
|
2016-02-16 15:07:25 +01:00
|
|
|
|
|
|
|
|
VkClearValue clearValues[2];
|
|
|
|
|
clearValues[0].color = defaultClearColor;
|
|
|
|
|
clearValues[1].depthStencil = { 1.0f, 0 };
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo();
|
2016-02-16 15:07:25 +01:00
|
|
|
renderPassBeginInfo.renderPass = renderPass;
|
|
|
|
|
renderPassBeginInfo.renderArea.offset.x = 0;
|
|
|
|
|
renderPassBeginInfo.renderArea.offset.y = 0;
|
|
|
|
|
renderPassBeginInfo.renderArea.extent.width = width;
|
|
|
|
|
renderPassBeginInfo.renderArea.extent.height = height;
|
|
|
|
|
renderPassBeginInfo.clearValueCount = 2;
|
|
|
|
|
renderPassBeginInfo.pClearValues = clearValues;
|
|
|
|
|
|
|
|
|
|
for (int32_t i = 0; i < drawCmdBuffers.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
// Set target frame buffer
|
|
|
|
|
renderPassBeginInfo.framebuffer = frameBuffers[i];
|
|
|
|
|
|
2016-06-06 11:35:04 +02:00
|
|
|
VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo));
|
2016-02-16 15:07:25 +01:00
|
|
|
|
|
|
|
|
vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkViewport viewport = vks::initializers::viewport((float)width, (float)height, 0.0f, 1.0f);
|
2016-02-16 15:07:25 +01:00
|
|
|
vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport);
|
|
|
|
|
|
2017-02-12 11:12:42 +01:00
|
|
|
VkRect2D scissor = vks::initializers::rect2D(splitScreen ? width / 2 : width, height, 0, 0);
|
2016-02-16 15:07:25 +01:00
|
|
|
vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);
|
|
|
|
|
|
|
|
|
|
vkCmdSetLineWidth(drawCmdBuffers[i], 1.0f);
|
|
|
|
|
|
|
|
|
|
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, NULL);
|
|
|
|
|
|
2020-07-28 20:20:38 +02:00
|
|
|
plane.bindBuffers(drawCmdBuffers[i]);
|
2016-02-16 15:07:25 +01:00
|
|
|
|
|
|
|
|
if (splitScreen)
|
|
|
|
|
{
|
2016-06-06 14:28:13 +02:00
|
|
|
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.wireframe);
|
2020-07-28 20:20:38 +02:00
|
|
|
plane.draw(drawCmdBuffers[i]);
|
2016-06-06 14:28:13 +02:00
|
|
|
scissor.offset.x = width / 2;
|
|
|
|
|
vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);
|
2016-02-16 15:07:25 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-06 14:28:13 +02:00
|
|
|
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.solid);
|
2020-07-28 20:20:38 +02:00
|
|
|
plane.draw(drawCmdBuffers[i]);
|
2016-02-16 15:07:25 +01:00
|
|
|
|
2018-08-30 21:08:02 +02:00
|
|
|
drawUI(drawCmdBuffers[i]);
|
|
|
|
|
|
2016-02-16 15:07:25 +01:00
|
|
|
vkCmdEndRenderPass(drawCmdBuffers[i]);
|
|
|
|
|
|
2016-06-06 11:35:04 +02:00
|
|
|
VK_CHECK_RESULT(vkEndCommandBuffer(drawCmdBuffers[i]));
|
2016-02-16 15:07:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-15 19:12:06 +01:00
|
|
|
void setupDescriptors()
|
2016-02-16 15:07:25 +01:00
|
|
|
{
|
2024-01-15 19:12:06 +01:00
|
|
|
// Pool
|
2020-07-28 20:20:38 +02:00
|
|
|
std::vector<VkDescriptorPoolSize> poolSizes = {
|
2017-02-12 11:12:42 +01:00
|
|
|
vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 2),
|
|
|
|
|
vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1)
|
2016-02-16 15:07:25 +01:00
|
|
|
};
|
2020-07-28 20:20:38 +02:00
|
|
|
VkDescriptorPoolCreateInfo descriptorPoolInfo = vks::initializers::descriptorPoolCreateInfo(poolSizes, 2);
|
2016-06-06 11:35:04 +02:00
|
|
|
VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool));
|
2016-02-16 15:07:25 +01:00
|
|
|
|
2024-01-15 19:12:06 +01:00
|
|
|
// Layout
|
|
|
|
|
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings = {
|
|
|
|
|
// Binding 0 : Tessellation shader ubo
|
|
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, 0),
|
|
|
|
|
// Binding 1 : Combined color (rgb) and height (alpha) map
|
|
|
|
|
vks::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 1),
|
2016-02-16 15:07:25 +01:00
|
|
|
};
|
2024-01-15 19:12:06 +01:00
|
|
|
VkDescriptorSetLayoutCreateInfo descriptorLayout = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings);
|
2016-06-06 11:35:04 +02:00
|
|
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorLayout, nullptr, &descriptorSetLayout));
|
2016-02-16 15:07:25 +01:00
|
|
|
|
2024-01-15 19:12:06 +01:00
|
|
|
// Set
|
2018-10-20 12:14:11 +02:00
|
|
|
VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayout, 1);
|
2016-06-06 11:35:04 +02:00
|
|
|
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet));
|
2018-10-20 12:14:11 +02:00
|
|
|
std::vector<VkWriteDescriptorSet> writeDescriptorSets = {
|
2024-01-15 19:12:06 +01:00
|
|
|
// Binding 0 : Tessellation shader ubo
|
|
|
|
|
vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffer.descriptor),
|
|
|
|
|
// Binding 1 : Color and displacement map (alpha channel)
|
|
|
|
|
vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &colorHeightMap.descriptor),
|
2016-02-16 15:07:25 +01:00
|
|
|
};
|
2024-01-15 19:12:06 +01:00
|
|
|
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, nullptr);
|
2016-02-16 15:07:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void preparePipelines()
|
|
|
|
|
{
|
2024-01-15 19:12:06 +01:00
|
|
|
// Layout
|
|
|
|
|
VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo = vks::initializers::pipelineLayoutCreateInfo(&descriptorSetLayout, 1);
|
|
|
|
|
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCreateInfo, nullptr, &pipelineLayout));
|
|
|
|
|
|
|
|
|
|
// Pipelines
|
|
|
|
|
VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = vks::initializers::pipelineInputAssemblyStateCreateInfo(VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, 0, VK_FALSE);
|
|
|
|
|
VkPipelineRasterizationStateCreateInfo rasterizationState = vks::initializers::pipelineRasterizationStateCreateInfo(VK_POLYGON_MODE_FILL, VK_CULL_MODE_BACK_BIT, VK_FRONT_FACE_COUNTER_CLOCKWISE, 0);
|
|
|
|
|
VkPipelineColorBlendAttachmentState blendAttachmentState = vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE);
|
|
|
|
|
VkPipelineColorBlendStateCreateInfo colorBlendState = vks::initializers::pipelineColorBlendStateCreateInfo(1, &blendAttachmentState);
|
|
|
|
|
VkPipelineDepthStencilStateCreateInfo depthStencilState = vks::initializers::pipelineDepthStencilStateCreateInfo(VK_TRUE, VK_TRUE, VK_COMPARE_OP_LESS_OR_EQUAL);
|
|
|
|
|
VkPipelineViewportStateCreateInfo viewportState = vks::initializers::pipelineViewportStateCreateInfo(1, 1, 0);
|
|
|
|
|
VkPipelineMultisampleStateCreateInfo multisampleState = vks::initializers::pipelineMultisampleStateCreateInfo(VK_SAMPLE_COUNT_1_BIT, 0);
|
|
|
|
|
std::vector<VkDynamicState> dynamicStateEnables = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH };
|
|
|
|
|
VkPipelineDynamicStateCreateInfo dynamicState = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables);
|
|
|
|
|
VkPipelineTessellationStateCreateInfo tessellationState = vks::initializers::pipelineTessellationStateCreateInfo(3);
|
2016-02-16 15:07:25 +01:00
|
|
|
|
|
|
|
|
// Load shaders
|
|
|
|
|
std::array<VkPipelineShaderStageCreateInfo, 4> shaderStages;
|
2020-05-29 16:08:53 +01:00
|
|
|
shaderStages[0] = loadShader(getShadersPath() + "displacement/base.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
|
|
|
|
shaderStages[1] = loadShader(getShadersPath() + "displacement/base.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
|
|
|
|
shaderStages[2] = loadShader(getShadersPath() + "displacement/displacement.tesc.spv", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT);
|
|
|
|
|
shaderStages[3] = loadShader(getShadersPath() + "displacement/displacement.tese.spv", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT);
|
2016-02-16 15:07:25 +01:00
|
|
|
|
2020-07-28 20:20:38 +02:00
|
|
|
VkGraphicsPipelineCreateInfo pipelineCI = vks::initializers::pipelineCreateInfo(pipelineLayout, renderPass);
|
|
|
|
|
pipelineCI.pInputAssemblyState = &inputAssemblyState;
|
|
|
|
|
pipelineCI.pRasterizationState = &rasterizationState;
|
|
|
|
|
pipelineCI.pColorBlendState = &colorBlendState;
|
|
|
|
|
pipelineCI.pMultisampleState = &multisampleState;
|
|
|
|
|
pipelineCI.pViewportState = &viewportState;
|
|
|
|
|
pipelineCI.pDepthStencilState = &depthStencilState;
|
|
|
|
|
pipelineCI.pDynamicState = &dynamicState;
|
|
|
|
|
pipelineCI.pTessellationState = &tessellationState;
|
|
|
|
|
pipelineCI.stageCount = static_cast<uint32_t>(shaderStages.size());
|
|
|
|
|
pipelineCI.pStages = shaderStages.data();
|
|
|
|
|
pipelineCI.pVertexInputState = vkglTF::Vertex::getPipelineVertexInputState({ vkglTF::VertexComponent::Position, vkglTF::VertexComponent::Normal, vkglTF::VertexComponent::UV });
|
2016-02-16 15:07:25 +01:00
|
|
|
|
2024-01-15 19:12:06 +01:00
|
|
|
// Tessellation pipelines
|
2016-02-16 15:07:25 +01:00
|
|
|
// Solid pipeline
|
2020-07-28 20:20:38 +02:00
|
|
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.solid));
|
2017-03-17 18:21:15 +01:00
|
|
|
if (deviceFeatures.fillModeNonSolid) {
|
|
|
|
|
// Wireframe pipeline
|
|
|
|
|
rasterizationState.polygonMode = VK_POLYGON_MODE_LINE;
|
|
|
|
|
rasterizationState.cullMode = VK_CULL_MODE_NONE;
|
2020-07-28 20:20:38 +02:00
|
|
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.wireframe));
|
2017-03-17 18:21:15 +01:00
|
|
|
}
|
2016-02-16 15:07:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prepare and initialize uniform buffer containing shader uniforms
|
|
|
|
|
void prepareUniformBuffers()
|
|
|
|
|
{
|
|
|
|
|
// Tessellation evaluation shader uniform buffer
|
2024-01-15 19:12:06 +01:00
|
|
|
VK_CHECK_RESULT(vulkanDevice->createBuffer(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, &uniformBuffer, sizeof(UniformData)));
|
2016-12-24 12:48:01 +01:00
|
|
|
// Map persistent
|
2024-01-15 19:12:06 +01:00
|
|
|
VK_CHECK_RESULT(uniformBuffer.map());
|
2016-02-16 15:07:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateUniformBuffers()
|
|
|
|
|
{
|
2024-01-15 19:12:06 +01:00
|
|
|
uniformData.projection = camera.matrices.perspective;
|
|
|
|
|
uniformData.modelView = camera.matrices.view;
|
|
|
|
|
uniformData.lightPos.y = -0.5f - uniformData.tessStrength;
|
2016-02-16 15:07:25 +01:00
|
|
|
// Tessellation control
|
2024-01-15 19:12:06 +01:00
|
|
|
float savedLevel = uniformData.tessLevel;
|
|
|
|
|
// If displacement is unchecked, we simply set the tessellation level to 1.0f, which disables tessellation
|
|
|
|
|
if (!displacement) {
|
|
|
|
|
uniformData.tessLevel = 1.0f;
|
2016-06-06 14:28:13 +02:00
|
|
|
}
|
2024-01-15 19:12:06 +01:00
|
|
|
memcpy(uniformBuffer.mapped, &uniformData, sizeof(UniformData));
|
|
|
|
|
if (!displacement) {
|
|
|
|
|
uniformData.tessLevel = savedLevel;
|
2016-06-06 14:28:13 +02:00
|
|
|
}
|
2016-02-16 15:07:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void prepare()
|
|
|
|
|
{
|
|
|
|
|
VulkanExampleBase::prepare();
|
2017-02-09 21:55:35 +01:00
|
|
|
loadAssets();
|
2016-02-16 15:07:25 +01:00
|
|
|
prepareUniformBuffers();
|
2024-01-15 19:12:06 +01:00
|
|
|
setupDescriptors();
|
2016-02-16 15:07:25 +01:00
|
|
|
preparePipelines();
|
|
|
|
|
buildCommandBuffers();
|
|
|
|
|
prepared = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-15 19:12:06 +01:00
|
|
|
void draw()
|
2016-02-16 15:07:25 +01:00
|
|
|
{
|
2024-01-15 19:12:06 +01:00
|
|
|
VulkanExampleBase::prepareFrame();
|
|
|
|
|
submitInfo.commandBufferCount = 1;
|
|
|
|
|
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
|
|
|
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
|
|
|
|
VulkanExampleBase::submitFrame();
|
2016-02-16 15:07:25 +01:00
|
|
|
}
|
2022-06-13 23:04:53 -04:00
|
|
|
|
2024-01-15 19:12:06 +01:00
|
|
|
virtual void render()
|
2022-06-13 23:04:53 -04:00
|
|
|
{
|
2024-01-15 19:12:06 +01:00
|
|
|
if (!prepared)
|
|
|
|
|
return;
|
2022-06-13 23:04:53 -04:00
|
|
|
updateUniformBuffers();
|
2024-01-15 19:12:06 +01:00
|
|
|
draw();
|
2022-06-13 23:04:53 -04:00
|
|
|
}
|
|
|
|
|
|
2017-11-01 14:22:10 +01:00
|
|
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
2016-02-16 15:07:25 +01:00
|
|
|
{
|
2017-11-01 14:22:10 +01:00
|
|
|
if (overlay->header("Settings")) {
|
|
|
|
|
if (overlay->checkBox("Tessellation displacement", &displacement)) {
|
|
|
|
|
updateUniformBuffers();
|
|
|
|
|
}
|
2024-01-15 19:12:06 +01:00
|
|
|
if (overlay->inputFloat("Strength", &uniformData.tessStrength, 0.025f, 3)) {
|
2017-11-01 14:22:10 +01:00
|
|
|
updateUniformBuffers();
|
|
|
|
|
}
|
2024-01-15 19:12:06 +01:00
|
|
|
if (overlay->inputFloat("Level", &uniformData.tessLevel, 0.5f, 2)) {
|
2017-11-01 14:22:10 +01:00
|
|
|
updateUniformBuffers();
|
|
|
|
|
}
|
2017-03-17 18:21:15 +01:00
|
|
|
if (deviceFeatures.fillModeNonSolid) {
|
2017-11-01 14:22:10 +01:00
|
|
|
if (overlay->checkBox("Splitscreen", &splitScreen)) {
|
|
|
|
|
buildCommandBuffers();
|
|
|
|
|
updateUniformBuffers();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-06 11:35:04 +02:00
|
|
|
|
2017-03-17 18:21:15 +01:00
|
|
|
}
|
2016-06-06 11:35:04 +02:00
|
|
|
}
|
2016-02-16 15:07:25 +01:00
|
|
|
};
|
|
|
|
|
|
2022-06-13 23:04:53 -04:00
|
|
|
VULKAN_EXAMPLE_MAIN()
|