2017-10-29 11:41:43 +01:00
|
|
|
/*
|
|
|
|
|
* UI overlay class using ImGui
|
|
|
|
|
*
|
2024-04-17 18:36:06 +02:00
|
|
|
* Copyright (C) 2017-2024 by Sascha Willems - www.saschawillems.de
|
2017-10-29 11:41:43 +01:00
|
|
|
*
|
|
|
|
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
|
#include "VulkanTools.h"
|
|
|
|
|
#include "VulkanDebug.h"
|
2020-08-08 22:18:35 +02:00
|
|
|
#include "VulkanBuffer.h"
|
2020-08-08 22:36:01 +02:00
|
|
|
#include "VulkanDevice.h"
|
2017-10-29 11:41:43 +01:00
|
|
|
|
|
|
|
|
#include "../external/imgui/imgui.h"
|
|
|
|
|
|
|
|
|
|
#if defined(__ANDROID__)
|
|
|
|
|
#include "VulkanAndroid.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-04-17 18:36:06 +02:00
|
|
|
namespace vks
|
2017-10-29 11:41:43 +01:00
|
|
|
{
|
2024-04-17 18:36:06 +02:00
|
|
|
class UIOverlay
|
2017-10-29 11:41:43 +01:00
|
|
|
{
|
2018-08-31 21:15:43 +02:00
|
|
|
public:
|
2024-04-17 18:36:06 +02:00
|
|
|
vks::VulkanDevice* device{ nullptr };
|
|
|
|
|
VkQueue queue{ VK_NULL_HANDLE };
|
2018-08-31 21:15:43 +02:00
|
|
|
|
2024-04-17 18:36:06 +02:00
|
|
|
VkSampleCountFlagBits rasterizationSamples{ VK_SAMPLE_COUNT_1_BIT };
|
|
|
|
|
uint32_t subpass{ 0 };
|
2017-10-29 11:41:43 +01:00
|
|
|
|
|
|
|
|
vks::Buffer vertexBuffer;
|
|
|
|
|
vks::Buffer indexBuffer;
|
2024-04-17 18:36:06 +02:00
|
|
|
int32_t vertexCount{ 0 };
|
|
|
|
|
int32_t indexCount{ 0 };
|
2017-10-29 11:41:43 +01:00
|
|
|
|
2018-08-31 21:15:43 +02:00
|
|
|
std::vector<VkPipelineShaderStageCreateInfo> shaders;
|
|
|
|
|
|
2024-04-17 18:36:06 +02:00
|
|
|
VkDescriptorPool descriptorPool{ VK_NULL_HANDLE };
|
|
|
|
|
VkDescriptorSetLayout descriptorSetLayout{ VK_NULL_HANDLE };
|
|
|
|
|
VkDescriptorSet descriptorSet{ VK_NULL_HANDLE };
|
|
|
|
|
VkPipelineLayout pipelineLayout{ VK_NULL_HANDLE };
|
|
|
|
|
VkPipeline pipeline{ VK_NULL_HANDLE };
|
2017-10-29 11:41:43 +01:00
|
|
|
|
2024-04-17 18:36:06 +02:00
|
|
|
VkDeviceMemory fontMemory{ VK_NULL_HANDLE };
|
|
|
|
|
VkImage fontImage{ VK_NULL_HANDLE };
|
|
|
|
|
VkImageView fontView{ VK_NULL_HANDLE };
|
|
|
|
|
VkSampler sampler{ VK_NULL_HANDLE };
|
2017-10-29 11:41:43 +01:00
|
|
|
|
|
|
|
|
struct PushConstBlock {
|
|
|
|
|
glm::vec2 scale;
|
|
|
|
|
glm::vec2 translate;
|
|
|
|
|
} pushConstBlock;
|
|
|
|
|
|
2024-04-17 18:36:06 +02:00
|
|
|
bool visible{ true };
|
|
|
|
|
bool updated{ false };
|
|
|
|
|
float scale{ 1.0f };
|
2024-05-23 21:52:24 +02:00
|
|
|
float updateTimer{ 0.0f };
|
2017-10-29 11:41:43 +01:00
|
|
|
|
2018-08-31 21:15:43 +02:00
|
|
|
UIOverlay();
|
2017-10-29 11:41:43 +01:00
|
|
|
~UIOverlay();
|
|
|
|
|
|
2022-08-01 19:05:37 -04:00
|
|
|
void preparePipeline(const VkPipelineCache pipelineCache, const VkRenderPass renderPass, const VkFormat colorFormat, const VkFormat depthFormat);
|
2018-08-31 21:15:43 +02:00
|
|
|
void prepareResources();
|
2017-10-29 11:41:43 +01:00
|
|
|
|
2018-08-29 20:49:13 +02:00
|
|
|
bool update();
|
|
|
|
|
void draw(const VkCommandBuffer commandBuffer);
|
|
|
|
|
void resize(uint32_t width, uint32_t height);
|
2017-10-30 12:37:36 +01:00
|
|
|
|
2018-08-31 21:15:43 +02:00
|
|
|
void freeResources();
|
|
|
|
|
|
2017-10-30 12:37:36 +01:00
|
|
|
bool header(const char* caption);
|
|
|
|
|
bool checkBox(const char* caption, bool* value);
|
2017-10-31 11:52:48 +01:00
|
|
|
bool checkBox(const char* caption, int32_t* value);
|
2021-12-26 18:42:03 +01:00
|
|
|
bool radioButton(const char* caption, bool value);
|
2017-10-30 12:37:36 +01:00
|
|
|
bool inputFloat(const char* caption, float* value, float step, uint32_t precision);
|
2017-10-30 18:02:51 +01:00
|
|
|
bool sliderFloat(const char* caption, float* value, float min, float max);
|
2017-10-31 11:52:48 +01:00
|
|
|
bool sliderInt(const char* caption, int32_t* value, int32_t min, int32_t max);
|
2017-10-30 12:37:36 +01:00
|
|
|
bool comboBox(const char* caption, int32_t* itemindex, std::vector<std::string> items);
|
2017-10-31 11:52:48 +01:00
|
|
|
bool button(const char* caption);
|
2023-02-24 16:13:31 +01:00
|
|
|
bool colorPicker(const char* caption, float* color);
|
2017-10-31 11:52:48 +01:00
|
|
|
void text(const char* formatstr, ...);
|
2017-10-29 11:41:43 +01:00
|
|
|
};
|
2022-08-01 19:05:37 -04:00
|
|
|
}
|