From 3d93c383d8ea4e7d73da256b3d281df3f84cc5d6 Mon Sep 17 00:00:00 2001 From: saschawillems Date: Fri, 20 May 2016 21:30:17 +0200 Subject: [PATCH] Use example base prepare and submit frame function, added ext overlay --- sphericalenvmapping/sphericalenvmapping.cpp | 45 ++++++++++----------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/sphericalenvmapping/sphericalenvmapping.cpp b/sphericalenvmapping/sphericalenvmapping.cpp index 7422063a..c306120c 100644 --- a/sphericalenvmapping/sphericalenvmapping.cpp +++ b/sphericalenvmapping/sphericalenvmapping.cpp @@ -80,6 +80,7 @@ public: rotationSpeed = 0.75f; zoomSpeed = 0.25f; rotation = glm::vec3(-25.0f, 23.75f, 0.0f); + enableTextOverlay = true; title = "Vulkan Example - Spherical Environment Mapping"; } @@ -157,27 +158,6 @@ public: } } - void draw() - { - // Get next image in the swap chain (back/front buffer) - VK_CHECK_RESULT(swapChain.acquireNextImage(semaphores.presentComplete, ¤tBuffer)); - - submitPostPresentBarrier(swapChain.buffers[currentBuffer].image); - - // Command buffer to be sumitted to the queue - submitInfo.commandBufferCount = 1; - submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer]; - - // Submit to queue - VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE)); - - submitPrePresentBarrier(swapChain.buffers[currentBuffer].image); - - VK_CHECK_RESULT(swapChain.queuePresent(queue, currentBuffer, semaphores.renderComplete)); - - VK_CHECK_RESULT(vkQueueWaitIdle(queue)); - } - void loadMeshes() { loadMesh(getAssetPath() + "models/chinesedragon.dae", &meshes.object, vertexLayout, 0.05f); @@ -397,6 +377,7 @@ public: // Vertex shader uniform buffer block createBuffer( VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, sizeof(uboVS), &uboVS, &uniformData.vertexShader.buffer, @@ -429,6 +410,17 @@ public: vkUnmapMemory(device, uniformData.vertexShader.memory); } + void draw() + { + VulkanExampleBase::prepareFrame(); + + submitInfo.commandBufferCount = 1; + submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer]; + VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE)); + + VulkanExampleBase::submitFrame(); + } + void prepare() { VulkanExampleBase::prepare(); @@ -448,9 +440,7 @@ public: { if (!prepared) return; - vkDeviceWaitIdle(device); draw(); - vkDeviceWaitIdle(device); } virtual void viewChanged() @@ -474,6 +464,15 @@ public: } } + virtual void getOverlayText(VulkanTextOverlay *textOverlay) + { +#if defined(__ANDROID__) + textOverlay->addText("Press \"Button A\" to toggle material cap", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); +#else + textOverlay->addText("Press \"space\" to toggle material cap", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); +#endif + } + void changeMatCapIndex(uint32_t delta) { uboVS.texIndex += delta;