Implement viewChanged() in multiple examples for proper window resize handling, fix triangle example resizing on macOS
This commit is contained in:
parent
b2f501dc98
commit
279c95422d
42 changed files with 240 additions and 37 deletions
|
|
@ -654,6 +654,12 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
camera.setPerspective(60.0f, (float)width * 0.5f / (float)height, 1.0f, 256.0f);
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -330,6 +330,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Visibility")) {
|
if (overlay->header("Visibility")) {
|
||||||
|
|
|
||||||
|
|
@ -777,6 +777,10 @@ public:
|
||||||
updateUniformBuffers();
|
updateUniformBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -809,6 +809,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBufferOffscreen();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -647,6 +647,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBufferOffscreen();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -808,6 +808,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBufferOffscreen();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -409,6 +409,11 @@ public:
|
||||||
updateUniformBuffersCamera();
|
updateUniformBuffersCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffersCamera();
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
VULKAN_EXAMPLE_MAIN()
|
VULKAN_EXAMPLE_MAIN()
|
||||||
|
|
@ -385,6 +385,12 @@ public:
|
||||||
updateUniformBuffers();
|
updateUniformBuffers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -643,6 +643,7 @@ public:
|
||||||
|
|
||||||
virtual void viewChanged()
|
virtual void viewChanged()
|
||||||
{
|
{
|
||||||
|
camera.setPerspective(splitScreen ? 30.0f : 45.0f, (float)width / (float)(height * ((splitScreen) ? 0.5f : 1.0f)), 1.0f, 256.0f);
|
||||||
updateUniformBuffers();
|
updateUniformBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -729,6 +729,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -631,6 +631,11 @@ void VulkanExample::render()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VulkanExample::viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay* overlay)
|
void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay* overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Visibility")) {
|
if (overlay->header("Visibility")) {
|
||||||
|
|
|
||||||
|
|
@ -162,5 +162,6 @@ 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);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -995,6 +995,11 @@ void VulkanExample::render()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VulkanExample::viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings"))
|
if (overlay->header("Settings"))
|
||||||
|
|
|
||||||
|
|
@ -232,5 +232,6 @@ 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);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -870,6 +870,11 @@ public:
|
||||||
updateUniformBuffers();
|
updateUniformBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -499,6 +499,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffer(true);
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (!vulkanDevice->features.multiDrawIndirect) {
|
if (!vulkanDevice->features.multiDrawIndirect) {
|
||||||
|
|
|
||||||
|
|
@ -357,6 +357,11 @@ public:
|
||||||
updateUniformBuffers();
|
updateUniformBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
[POI] Update descriptor sets at runtime
|
[POI] Update descriptor sets at runtime
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -606,6 +606,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -482,6 +482,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffer(true);
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Statistics")) {
|
if (overlay->header("Statistics")) {
|
||||||
|
|
|
||||||
|
|
@ -541,6 +541,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the maximum sample count usable by the platform
|
// Returns the maximum sample count usable by the platform
|
||||||
VkSampleCountFlagBits getMaxUsableSampleCount()
|
VkSampleCountFlagBits getMaxUsableSampleCount()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -527,6 +527,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateMatrices();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Statistics")) {
|
if (overlay->header("Statistics")) {
|
||||||
|
|
|
||||||
|
|
@ -738,6 +738,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -507,7 +507,7 @@ private:
|
||||||
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
|
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void buildCommandBuffers()
|
void buildCommandBuffers() override
|
||||||
{
|
{
|
||||||
if (resized)
|
if (resized)
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -589,6 +589,11 @@ public:
|
||||||
updateUniformBuffers();
|
updateUniformBuffers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VULKAN_EXAMPLE_MAIN()
|
VULKAN_EXAMPLE_MAIN()
|
||||||
|
|
@ -1340,6 +1340,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -334,6 +334,12 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
camera.setPerspective(60.0f, (float)(width / 3.0f) / (float)height, 0.1f, 256.0f);
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (!deviceFeatures.fillModeNonSolid) {
|
if (!deviceFeatures.fillModeNonSolid) {
|
||||||
|
|
|
||||||
|
|
@ -337,6 +337,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -320,7 +320,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void windowResized()
|
virtual void viewChanged()
|
||||||
{
|
{
|
||||||
updateUniformBuffers();
|
updateUniformBuffers();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -277,6 +277,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -944,6 +944,12 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBufferMatrices();
|
||||||
|
updateUniformBufferSSAOParams();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -903,6 +903,12 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBufferDeferredMatrices();
|
||||||
|
updateUniformBufferDeferredLights();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Subpasses")) {
|
if (overlay->header("Subpasses")) {
|
||||||
|
|
|
||||||
|
|
@ -828,6 +828,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -326,6 +326,12 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
camera.setPerspective(45.0f, (float)(width * ((splitScreen) ? 0.5f : 1.0f)) / (float)height, 0.1f, 256.0f);
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -514,6 +514,8 @@ public:
|
||||||
case alignCenter:
|
case alignCenter:
|
||||||
x -= textWidth / 2.0f;
|
x -= textWidth / 2.0f;
|
||||||
break;
|
break;
|
||||||
|
case alignLeft:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a uv mapped quad per char in the new text
|
// Generate a uv mapped quad per char in the new text
|
||||||
|
|
@ -885,6 +887,10 @@ public:
|
||||||
if (!prepared)
|
if (!prepared)
|
||||||
return;
|
return;
|
||||||
draw();
|
draw();
|
||||||
|
if (camera.updated)
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
if (frameCounter == 0)
|
if (frameCounter == 0)
|
||||||
{
|
{
|
||||||
vkDeviceWaitIdle(device);
|
vkDeviceWaitIdle(device);
|
||||||
|
|
@ -892,13 +898,6 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void viewChanged()
|
|
||||||
{
|
|
||||||
vkDeviceWaitIdle(device);
|
|
||||||
updateUniformBuffers();
|
|
||||||
updateTextOverlay();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void windowResized()
|
virtual void windowResized()
|
||||||
{
|
{
|
||||||
// SRS - Recreate text overlay resources in case number of swapchain images has changed on resize
|
// SRS - Recreate text overlay resources in case number of swapchain images has changed on resize
|
||||||
|
|
@ -906,6 +905,12 @@ public:
|
||||||
prepareTextOverlay();
|
prepareTextOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
updateTextOverlay();
|
||||||
|
}
|
||||||
|
|
||||||
#if !defined(__ANDROID__)
|
#if !defined(__ANDROID__)
|
||||||
virtual void keyPressed(uint32_t keyCode)
|
virtual void keyPressed(uint32_t keyCode)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -773,6 +773,11 @@ public:
|
||||||
updateUniformBuffers(camera.updated);
|
updateUniformBuffers(camera.updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers(true);
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -550,6 +550,10 @@ public:
|
||||||
updateUniformBuffersCamera();
|
updateUniformBuffersCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffersCamera();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VULKAN_EXAMPLE_MAIN()
|
VULKAN_EXAMPLE_MAIN()
|
||||||
|
|
@ -529,6 +529,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
|
|
|
||||||
|
|
@ -708,6 +708,11 @@ void VulkanExample::render()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VulkanExample::viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
// Fills a buffer with random colors
|
// Fills a buffer with random colors
|
||||||
void VulkanExample::randomPattern(uint8_t* buffer, uint32_t width, uint32_t height)
|
void VulkanExample::randomPattern(uint8_t* buffer, uint32_t width, uint32_t height)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,7 @@ public:
|
||||||
void updateUniformBuffers();
|
void updateUniformBuffers();
|
||||||
void prepare();
|
void prepare();
|
||||||
virtual void render();
|
virtual void render();
|
||||||
|
virtual void viewChanged();
|
||||||
void uploadContent(VirtualTexturePage page, VkImage image);
|
void uploadContent(VirtualTexturePage page, VkImage image);
|
||||||
void fillRandomPages();
|
void fillRandomPages();
|
||||||
void fillMipTail();
|
void fillMipTail();
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ public:
|
||||||
|
|
||||||
// Fences
|
// Fences
|
||||||
// Used to check the completion of queue operations (e.g. command buffer execution)
|
// Used to check the completion of queue operations (e.g. command buffer execution)
|
||||||
std::vector<VkFence> waitFences;
|
std::vector<VkFence> queueCompleteFences;
|
||||||
|
|
||||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||||
{
|
{
|
||||||
|
|
@ -148,7 +148,7 @@ public:
|
||||||
vkDestroySemaphore(device, presentCompleteSemaphore, nullptr);
|
vkDestroySemaphore(device, presentCompleteSemaphore, nullptr);
|
||||||
vkDestroySemaphore(device, renderCompleteSemaphore, nullptr);
|
vkDestroySemaphore(device, renderCompleteSemaphore, nullptr);
|
||||||
|
|
||||||
for (auto& fence : waitFences)
|
for (auto& fence : queueCompleteFences)
|
||||||
{
|
{
|
||||||
vkDestroyFence(device, fence, nullptr);
|
vkDestroyFence(device, fence, nullptr);
|
||||||
}
|
}
|
||||||
|
|
@ -196,8 +196,8 @@ public:
|
||||||
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||||
// Create in signaled state so we don't wait on first render of each command buffer
|
// Create in signaled state so we don't wait on first render of each command buffer
|
||||||
fenceCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
|
fenceCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
|
||||||
waitFences.resize(drawCmdBuffers.size());
|
queueCompleteFences.resize(drawCmdBuffers.size());
|
||||||
for (auto& fence : waitFences)
|
for (auto& fence : queueCompleteFences)
|
||||||
{
|
{
|
||||||
VK_CHECK_RESULT(vkCreateFence(device, &fenceCreateInfo, nullptr, &fence));
|
VK_CHECK_RESULT(vkCreateFence(device, &fenceCreateInfo, nullptr, &fence));
|
||||||
}
|
}
|
||||||
|
|
@ -337,6 +337,16 @@ public:
|
||||||
|
|
||||||
void draw()
|
void draw()
|
||||||
{
|
{
|
||||||
|
#if defined(VK_USE_PLATFORM_MACOS_MVK)
|
||||||
|
// SRS - on macOS use swapchain helper function with common semaphores/fences for proper resize handling
|
||||||
|
// Get next image in the swap chain (back/front buffer)
|
||||||
|
prepareFrame();
|
||||||
|
|
||||||
|
// Use a fence to wait until the command buffer has finished execution before using it again
|
||||||
|
VK_CHECK_RESULT(vkWaitForFences(device, 1, &waitFences[currentBuffer], VK_TRUE, UINT64_MAX));
|
||||||
|
VK_CHECK_RESULT(vkResetFences(device, 1, &waitFences[currentBuffer]));
|
||||||
|
#else
|
||||||
|
// SRS - on other platforms use original bare code with local semaphores/fences for illustrative purposes
|
||||||
// Get next image in the swap chain (back/front buffer)
|
// Get next image in the swap chain (back/front buffer)
|
||||||
VkResult acquire = swapChain.acquireNextImage(presentCompleteSemaphore, ¤tBuffer);
|
VkResult acquire = swapChain.acquireNextImage(presentCompleteSemaphore, ¤tBuffer);
|
||||||
if (!((acquire == VK_SUCCESS) || (acquire == VK_SUBOPTIMAL_KHR))) {
|
if (!((acquire == VK_SUCCESS) || (acquire == VK_SUBOPTIMAL_KHR))) {
|
||||||
|
|
@ -344,8 +354,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use a fence to wait until the command buffer has finished execution before using it again
|
// Use a fence to wait until the command buffer has finished execution before using it again
|
||||||
VK_CHECK_RESULT(vkWaitForFences(device, 1, &waitFences[currentBuffer], VK_TRUE, UINT64_MAX));
|
VK_CHECK_RESULT(vkWaitForFences(device, 1, &queueCompleteFences[currentBuffer], VK_TRUE, UINT64_MAX));
|
||||||
VK_CHECK_RESULT(vkResetFences(device, 1, &waitFences[currentBuffer]));
|
VK_CHECK_RESULT(vkResetFences(device, 1, &queueCompleteFences[currentBuffer]));
|
||||||
|
#endif
|
||||||
|
|
||||||
// Pipeline stage at which the queue submission will wait (via pWaitSemaphores)
|
// Pipeline stage at which the queue submission will wait (via pWaitSemaphores)
|
||||||
VkPipelineStageFlags waitStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
VkPipelineStageFlags waitStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
|
@ -353,16 +364,29 @@ public:
|
||||||
VkSubmitInfo submitInfo = {};
|
VkSubmitInfo submitInfo = {};
|
||||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
submitInfo.pWaitDstStageMask = &waitStageMask; // Pointer to the list of pipeline stages that the semaphore waits will occur at
|
submitInfo.pWaitDstStageMask = &waitStageMask; // Pointer to the list of pipeline stages that the semaphore waits will occur at
|
||||||
submitInfo.pWaitSemaphores = &presentCompleteSemaphore; // Semaphore(s) to wait upon before the submitted command buffer starts executing
|
|
||||||
submitInfo.waitSemaphoreCount = 1; // One wait semaphore
|
submitInfo.waitSemaphoreCount = 1; // One wait semaphore
|
||||||
submitInfo.pSignalSemaphores = &renderCompleteSemaphore; // Semaphore(s) to be signaled when command buffers have completed
|
|
||||||
submitInfo.signalSemaphoreCount = 1; // One signal semaphore
|
submitInfo.signalSemaphoreCount = 1; // One signal semaphore
|
||||||
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer]; // Command buffers(s) to execute in this batch (submission)
|
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer]; // Command buffers(s) to execute in this batch (submission)
|
||||||
submitInfo.commandBufferCount = 1; // One command buffer
|
submitInfo.commandBufferCount = 1; // One command buffer
|
||||||
|
|
||||||
|
#if defined(VK_USE_PLATFORM_MACOS_MVK)
|
||||||
|
// SRS - on macOS use swapchain helper function with common semaphores/fences for proper resize handling
|
||||||
|
submitInfo.pWaitSemaphores = &semaphores.presentComplete; // Semaphore(s) to wait upon before the submitted command buffer starts executing
|
||||||
|
submitInfo.pSignalSemaphores = &semaphores.renderComplete; // Semaphore(s) to be signaled when command buffers have completed
|
||||||
|
|
||||||
// Submit to the graphics queue passing a wait fence
|
// Submit to the graphics queue passing a wait fence
|
||||||
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, waitFences[currentBuffer]));
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, waitFences[currentBuffer]));
|
||||||
|
|
||||||
|
// Present the current buffer to the swap chain
|
||||||
|
submitFrame();
|
||||||
|
#else
|
||||||
|
// SRS - on other platforms use original bare code with local semaphores/fences for illustrative purposes
|
||||||
|
submitInfo.pWaitSemaphores = &presentCompleteSemaphore; // Semaphore(s) to wait upon before the submitted command buffer starts executing
|
||||||
|
submitInfo.pSignalSemaphores = &renderCompleteSemaphore; // Semaphore(s) to be signaled when command buffers have completed
|
||||||
|
|
||||||
|
// Submit to the graphics queue passing a wait fence
|
||||||
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, queueCompleteFences[currentBuffer]));
|
||||||
|
|
||||||
// Present the current buffer to the swap chain
|
// Present the current buffer to the swap chain
|
||||||
// Pass the semaphore signaled by the command buffer submission from the submit info as the wait semaphore for swap chain presentation
|
// Pass the semaphore signaled by the command buffer submission from the submit info as the wait semaphore for swap chain presentation
|
||||||
// This ensures that the image is not presented to the windowing system until all commands have been submitted
|
// This ensures that the image is not presented to the windowing system until all commands have been submitted
|
||||||
|
|
@ -370,7 +394,7 @@ public:
|
||||||
if (!((present == VK_SUCCESS) || (present == VK_SUBOPTIMAL_KHR))) {
|
if (!((present == VK_SUCCESS) || (present == VK_SUBOPTIMAL_KHR))) {
|
||||||
VK_CHECK_RESULT(present);
|
VK_CHECK_RESULT(present);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare vertex and index buffers for an indexed triangle
|
// Prepare vertex and index buffers for an indexed triangle
|
||||||
|
|
@ -1235,7 +1259,7 @@ int main(const int argc, const char *argv[])
|
||||||
vulkanExample->setupWindow(nullptr);
|
vulkanExample->setupWindow(nullptr);
|
||||||
vulkanExample->prepare();
|
vulkanExample->prepare();
|
||||||
vulkanExample->renderLoop();
|
vulkanExample->renderLoop();
|
||||||
delete(vulkanExample);
|
//delete(vulkanExample); // SRS - vulkanExample deleted by AppDelegate termination event handler
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -580,6 +580,11 @@ void VulkanExample::render()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VulkanExample::viewChanged()
|
||||||
|
{
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay* overlay)
|
void VulkanExample::OnUpdateUIOverlay(vks::UIOverlay* overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Vertex buffer attributes")) {
|
if (overlay->header("Vertex buffer attributes")) {
|
||||||
|
|
|
||||||
|
|
@ -139,5 +139,6 @@ public:
|
||||||
void loadSceneNode(const tinygltf::Node& inputNode, const tinygltf::Model& input, Node* parent);
|
void loadSceneNode(const tinygltf::Node& inputNode, const tinygltf::Model& input, Node* parent);
|
||||||
void drawSceneNode(VkCommandBuffer commandBuffer, Node node);
|
void drawSceneNode(VkCommandBuffer commandBuffer, Node node);
|
||||||
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