diff --git a/examples/computecullandlod/computecullandlod.cpp b/examples/computecullandlod/computecullandlod.cpp index c9ce4c3f..d7000e1d 100644 --- a/examples/computecullandlod/computecullandlod.cpp +++ b/examples/computecullandlod/computecullandlod.cpp @@ -1,7 +1,7 @@ /* * Vulkan Example - Compute shader culling and LOD using indirect rendering * -* Copyright (C) 2016-2022 by Sascha Willems - www.saschawillems.de +* Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de * * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) * @@ -11,8 +11,6 @@ #include "VulkanglTFModel.h" #include "frustum.hpp" -#define VERTEX_BUFFER_BIND_ID 0 -#define INSTANCE_BUFFER_BIND_ID 1 #define ENABLE_VALIDATION false // Total number of objects (^3) in the scene @@ -188,8 +186,8 @@ public: // Mesh containing the LODs vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.plants); - vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &lodModel.vertices.buffer, offsets); - vkCmdBindVertexBuffers(drawCmdBuffers[i], INSTANCE_BUFFER_BIND_ID, 1, &instanceBuffer.buffer, offsets); + vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &lodModel.vertices.buffer, offsets); + vkCmdBindVertexBuffers(drawCmdBuffers[i], 1, 1, &instanceBuffer.buffer, offsets); vkCmdBindIndexBuffer(drawCmdBuffers[i], lodModel.indices.buffer, 0, VK_INDEX_TYPE_UINT32); @@ -382,22 +380,22 @@ public: // The instancing pipeline uses a vertex input state with two bindings bindingDescriptions = { // Binding point 0: Mesh vertex layout description at per-vertex rate - vks::initializers::vertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, sizeof(vkglTF::Vertex), VK_VERTEX_INPUT_RATE_VERTEX), + vks::initializers::vertexInputBindingDescription(0, sizeof(vkglTF::Vertex), VK_VERTEX_INPUT_RATE_VERTEX), // Binding point 1: Instanced data at per-instance rate - vks::initializers::vertexInputBindingDescription(INSTANCE_BUFFER_BIND_ID, sizeof(InstanceData), VK_VERTEX_INPUT_RATE_INSTANCE) + vks::initializers::vertexInputBindingDescription(1, sizeof(InstanceData), VK_VERTEX_INPUT_RATE_INSTANCE) }; // Vertex attribute bindings attributeDescriptions = { // Per-vertex attributes // These are advanced for each vertex fetched by the vertex shader - vks::initializers::vertexInputAttributeDescription(VERTEX_BUFFER_BIND_ID, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(vkglTF::Vertex, pos)), // Location 0: Position - vks::initializers::vertexInputAttributeDescription(VERTEX_BUFFER_BIND_ID, 1, VK_FORMAT_R32G32B32_SFLOAT, offsetof(vkglTF::Vertex, normal)), // Location 1: Normal - vks::initializers::vertexInputAttributeDescription(VERTEX_BUFFER_BIND_ID, 2, VK_FORMAT_R32G32B32_SFLOAT, offsetof(vkglTF::Vertex, color)), // Location 2: Texture coordinates + vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(vkglTF::Vertex, pos)), // Location 0: Position + vks::initializers::vertexInputAttributeDescription(0, 1, VK_FORMAT_R32G32B32_SFLOAT, offsetof(vkglTF::Vertex, normal)), // Location 1: Normal + vks::initializers::vertexInputAttributeDescription(0, 2, VK_FORMAT_R32G32B32_SFLOAT, offsetof(vkglTF::Vertex, color)), // Location 2: Texture coordinates // Per-Instance attributes // These are fetched for each instance rendered - vks::initializers::vertexInputAttributeDescription(INSTANCE_BUFFER_BIND_ID, 4, VK_FORMAT_R32G32B32_SFLOAT, offsetof(InstanceData, pos)), // Location 4: Position - vks::initializers::vertexInputAttributeDescription(INSTANCE_BUFFER_BIND_ID, 5, VK_FORMAT_R32_SFLOAT, offsetof(InstanceData, scale)), // Location 5: Scale + vks::initializers::vertexInputAttributeDescription(1, 4, VK_FORMAT_R32G32B32_SFLOAT, offsetof(InstanceData, pos)), // Location 4: Position + vks::initializers::vertexInputAttributeDescription(1, 5, VK_FORMAT_R32_SFLOAT, offsetof(InstanceData, scale)), // Location 5: Scale }; inputState.pVertexBindingDescriptions = bindingDescriptions.data(); inputState.pVertexAttributeDescriptions = attributeDescriptions.data(); @@ -593,7 +591,7 @@ public: VK_CHECK_RESULT(uniformData.scene.map()); - updateUniformBuffer(true); + updateUniformBuffer(); } void prepareCompute() @@ -739,20 +737,16 @@ public: buildComputeCommandBuffer(); } - void updateUniformBuffer(bool viewChanged) + void updateUniformBuffer() { - if (viewChanged) + uboScene.projection = camera.matrices.perspective; + uboScene.modelview = camera.matrices.view; + if (!fixedFrustum) { - uboScene.projection = camera.matrices.perspective; - uboScene.modelview = camera.matrices.view; - if (!fixedFrustum) - { - uboScene.cameraPos = glm::vec4(camera.position, 1.0f) * -1.0f; - frustum.update(uboScene.projection * uboScene.modelview); - memcpy(uboScene.frustumPlanes, frustum.planes.data(), sizeof(glm::vec4) * 6); - } + uboScene.cameraPos = glm::vec4(camera.position, 1.0f) * -1.0f; + frustum.update(uboScene.projection * uboScene.modelview); + memcpy(uboScene.frustumPlanes, frustum.planes.data(), sizeof(glm::vec4) * 6); } - memcpy(uniformData.scene.mapped, &uboScene, sizeof(uboScene)); } @@ -823,23 +817,13 @@ public: return; } draw(); - if (camera.updated) - { - updateUniformBuffer(true); - } - } - - virtual void viewChanged() - { - updateUniformBuffer(true); + updateUniformBuffer(); } virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (overlay->header("Settings")) { - if (overlay->checkBox("Freeze frustum", &fixedFrustum)) { - updateUniformBuffer(true); - } + overlay->checkBox("Freeze frustum", &fixedFrustum); } if (overlay->header("Statistics")) { overlay->text("Visible objects: %d", indirectStats.drawCount);