procedural-3d-engine/base/VulkanUIOverlay.h

94 lines
2.5 KiB
C
Raw Normal View History

/*
* UI overlay class using ImGui
*
2024-04-17 18:36:06 +02:00
* Copyright (C) 2017-2024 by Sascha Willems - www.saschawillems.de
*
* 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"
#include "VulkanBuffer.h"
#include "VulkanDevice.h"
#include "../external/imgui/imgui.h"
#if defined(__ANDROID__)
#include "VulkanAndroid.h"
#endif
2024-04-17 18:36:06 +02:00
namespace vks
{
2024-04-17 18:36:06 +02:00
class UIOverlay
{
public:
2024-04-17 18:36:06 +02:00
vks::VulkanDevice* device{ nullptr };
VkQueue queue{ VK_NULL_HANDLE };
2024-04-17 18:36:06 +02:00
VkSampleCountFlagBits rasterizationSamples{ VK_SAMPLE_COUNT_1_BIT };
uint32_t subpass{ 0 };
vks::Buffer vertexBuffer;
vks::Buffer indexBuffer;
2024-04-17 18:36:06 +02:00
int32_t vertexCount{ 0 };
int32_t indexCount{ 0 };
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 };
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 };
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 };
UIOverlay();
~UIOverlay();
void preparePipeline(const VkPipelineCache pipelineCache, const VkRenderPass renderPass, const VkFormat colorFormat, const VkFormat depthFormat);
void prepareResources();
bool update();
void draw(const VkCommandBuffer commandBuffer);
void resize(uint32_t width, uint32_t height);
void freeResources();
bool header(const char* caption);
bool checkBox(const char* caption, bool* value);
bool checkBox(const char* caption, int32_t* value);
bool radioButton(const char* caption, bool value);
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);
bool sliderInt(const char* caption, int32_t* value, int32_t min, int32_t max);
bool comboBox(const char* caption, int32_t* itemindex, std::vector<std::string> items);
bool button(const char* caption);
bool colorPicker(const char* caption, float* color);
void text(const char* formatstr, ...);
};
}