Add imgui
This commit is contained in:
@@ -41,3 +41,6 @@
|
|||||||
[submodule "destrum/third_party/assimp"]
|
[submodule "destrum/third_party/assimp"]
|
||||||
path = destrum/third_party/assimp
|
path = destrum/third_party/assimp
|
||||||
url = https://github.com/assimp/assimp.git
|
url = https://github.com/assimp/assimp.git
|
||||||
|
[submodule "destrum/third_party/imgui"]
|
||||||
|
path = destrum/third_party/imgui
|
||||||
|
url = https://github.com/ocornut/imgui.git
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ set(SRC_FILES
|
|||||||
"src/Graphics/Pipelines/MeshPipeline.cpp"
|
"src/Graphics/Pipelines/MeshPipeline.cpp"
|
||||||
"src/Graphics/Pipelines/SkyboxPipeline.cpp"
|
"src/Graphics/Pipelines/SkyboxPipeline.cpp"
|
||||||
"src/Graphics/Pipelines/SkinningPipeline.cpp"
|
"src/Graphics/Pipelines/SkinningPipeline.cpp"
|
||||||
|
"src/Graphics/Pipelines/ImguiPass.cpp"
|
||||||
|
|
||||||
"src/Input/InputManager.cpp"
|
"src/Input/InputManager.cpp"
|
||||||
|
|
||||||
@@ -76,6 +77,7 @@ target_link_libraries(destrum
|
|||||||
stb::image
|
stb::image
|
||||||
tinygltf
|
tinygltf
|
||||||
assimp
|
assimp
|
||||||
|
imgui
|
||||||
|
|
||||||
PRIVATE
|
PRIVATE
|
||||||
freetype::freetype
|
freetype::freetype
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include <destrum/Graphics/GfxDevice.h>
|
#include <destrum/Graphics/GfxDevice.h>
|
||||||
#include <destrum/Graphics/Renderer.h>
|
#include <destrum/Graphics/Renderer.h>
|
||||||
|
#include <destrum/Graphics/Pipelines/ImguiPass.h>
|
||||||
|
|
||||||
#include <destrum/Input/InputManager.h>
|
#include <destrum/Input/InputManager.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -40,6 +42,7 @@ protected:
|
|||||||
AppParams m_params{};
|
AppParams m_params{};
|
||||||
|
|
||||||
GfxDevice gfxDevice;
|
GfxDevice gfxDevice;
|
||||||
|
ImguiPass imguiPass;
|
||||||
|
|
||||||
Camera camera{glm::vec3(0.f, 0.f, -5.f), glm::vec3(0, 1, 0)};
|
Camera camera{glm::vec3(0.f, 0.f, -5.f), glm::vec3(0, 1, 0)};
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
class MeshCache;
|
class MeshCache;
|
||||||
|
class ImguiPass;
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
using ImmediateExecuteFunction = std::function<void(VkCommandBuffer)>;
|
using ImmediateExecuteFunction = std::function<void(VkCommandBuffer)>;
|
||||||
@@ -54,6 +56,7 @@ public:
|
|||||||
struct EndFrameProps {
|
struct EndFrameProps {
|
||||||
const VkClearColorValue clearColor{{0.f, 0.f, 0.f, 1.f}};
|
const VkClearColorValue clearColor{{0.f, 0.f, 0.f, 1.f}};
|
||||||
glm::ivec4 drawImageBlitRect{}; // where to blit draw image to
|
glm::ivec4 drawImageBlitRect{}; // where to blit draw image to
|
||||||
|
ImguiPass* imguiPass = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
void endFrame(VkCommandBuffer cmd, const GPUImage& drawImage, const EndFrameProps& props);
|
void endFrame(VkCommandBuffer cmd, const GPUImage& drawImage, const EndFrameProps& props);
|
||||||
@@ -110,6 +113,19 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] ImageID getWhiteTextureID() const { return whiteImageId; }
|
[[nodiscard]] ImageID getWhiteTextureID() const { return whiteImageId; }
|
||||||
|
|
||||||
|
VkInstance getVkInstance() const { return instance; }
|
||||||
|
VkPhysicalDevice getVkPhysicalDevice() const { return physicalDevice; }
|
||||||
|
VkDevice getVkDevice() const { return device; }
|
||||||
|
|
||||||
|
std::uint32_t getGraphicsQueueFamily() const { return graphicsQueueFamily; }
|
||||||
|
VkQueue getGraphicsQueue() const { return graphicsQueue; }
|
||||||
|
|
||||||
|
VkFormat getSwapchainFormat() const { return swapchainFormat; }
|
||||||
|
std::uint32_t getSwapchainImageCount() const { return swapchain.getImageCount(); }
|
||||||
|
VkImageView getSwapchainImageView(std::uint32_t imageIndex) const {
|
||||||
|
return swapchain.getImageView(imageIndex);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vkb::Instance instance;
|
vkb::Instance instance;
|
||||||
vkb::PhysicalDevice physicalDevice;
|
vkb::PhysicalDevice physicalDevice;
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#ifndef DESTRUM_IMGUI_PASS_H
|
||||||
|
#define DESTRUM_IMGUI_PASS_H
|
||||||
|
|
||||||
|
#include <vulkan/vulkan.h>
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
class GfxDevice;
|
||||||
|
|
||||||
|
class ImguiPass {
|
||||||
|
public:
|
||||||
|
ImguiPass() = default;
|
||||||
|
ImguiPass(const ImguiPass&) = delete;
|
||||||
|
ImguiPass& operator=(const ImguiPass&) = delete;
|
||||||
|
|
||||||
|
void init(SDL_Window* window, GfxDevice& gfxDevice);
|
||||||
|
void handleEvent(const SDL_Event& event);
|
||||||
|
|
||||||
|
void beginFrame();
|
||||||
|
void endFrame();
|
||||||
|
|
||||||
|
void render(
|
||||||
|
VkCommandBuffer cmd,
|
||||||
|
VkImage targetImage,
|
||||||
|
VkImageView targetImageView,
|
||||||
|
VkImageLayout& targetImageLayout,
|
||||||
|
VkExtent2D targetExtent
|
||||||
|
);
|
||||||
|
|
||||||
|
void onSwapchainRecreated();
|
||||||
|
void cleanup();
|
||||||
|
|
||||||
|
[[nodiscard]] bool isInitialized() const { return initialized; }
|
||||||
|
[[nodiscard]] bool wantsMouse() const;
|
||||||
|
[[nodiscard]] bool wantsKeyboard() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void transitionToColorAttachment(
|
||||||
|
VkCommandBuffer cmd,
|
||||||
|
VkImage image,
|
||||||
|
VkImageLayout oldLayout,
|
||||||
|
VkImageLayout newLayout
|
||||||
|
) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
GfxDevice* gfx = nullptr;
|
||||||
|
SDL_Window* sdlWindow = nullptr;
|
||||||
|
|
||||||
|
VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
|
||||||
|
VkFormat colorFormat = VK_FORMAT_UNDEFINED;
|
||||||
|
|
||||||
|
bool initialized = false;
|
||||||
|
bool frameBegun = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DESTRUM_IMGUI_PASS_H
|
||||||
@@ -35,6 +35,11 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] VkImageView getImageView(int index) const { return imageViews[index]; }
|
[[nodiscard]] VkImageView getImageView(int index) const { return imageViews[index]; }
|
||||||
|
|
||||||
|
|
||||||
|
VkImageView getImageView(std::uint32_t imageIndex) const {
|
||||||
|
return imageViews.at(imageIndex);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct FrameData {
|
struct FrameData {
|
||||||
VkSemaphore swapchainSemaphore;
|
VkSemaphore swapchainSemaphore;
|
||||||
|
|||||||
+31
-5
@@ -6,12 +6,14 @@
|
|||||||
#include <destrum/FS/AssetFS.h>
|
#include <destrum/FS/AssetFS.h>
|
||||||
#include <destrum/Util/DeltaTime.h>
|
#include <destrum/Util/DeltaTime.h>
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
#include "glm/gtx/transform.hpp"
|
#include "glm/gtx/transform.hpp"
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
App::App() {}
|
App::App() {
|
||||||
|
}
|
||||||
|
|
||||||
void App::init(const AppParams& params) {
|
void App::init(const AppParams ¶ms) {
|
||||||
m_params = params;
|
m_params = params;
|
||||||
|
|
||||||
AssetFS::GetInstance().Init(params.exeDir);
|
AssetFS::GetInstance().Init(params.exeDir);
|
||||||
@@ -35,6 +37,8 @@ void App::init(const AppParams& params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gfxDevice.init(window, params.appName, false);
|
gfxDevice.init(window, params.appName, false);
|
||||||
|
imguiPass.init(window, gfxDevice);
|
||||||
|
|
||||||
|
|
||||||
InputManager::GetInstance().Init();
|
InputManager::GetInstance().Init();
|
||||||
Time::GetInstance().Update();
|
Time::GetInstance().Update();
|
||||||
@@ -68,9 +72,9 @@ void App::run() {
|
|||||||
camera.Update(dt);
|
camera.Update(dt);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
|
imguiPass.handleEvent(event);
|
||||||
if (event.type == SDL_QUIT) {
|
if (event.type == SDL_QUIT) {
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
break;
|
break;
|
||||||
@@ -78,22 +82,44 @@ void App::run() {
|
|||||||
if (event.type == SDL_WINDOWEVENT) {
|
if (event.type == SDL_WINDOWEVENT) {
|
||||||
switch (event.window.event) {
|
switch (event.window.event) {
|
||||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||||
case SDL_WINDOWEVENT_RESIZED:
|
case SDL_WINDOWEVENT_RESIZED: {
|
||||||
{
|
|
||||||
resizePending = true;
|
resizePending = true;
|
||||||
lastResizeTime = std::chrono::steady_clock::now();
|
lastResizeTime = std::chrono::steady_clock::now();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const bool mouseEvent =
|
||||||
|
event.type == SDL_MOUSEBUTTONDOWN ||
|
||||||
|
event.type == SDL_MOUSEBUTTONUP ||
|
||||||
|
event.type == SDL_MOUSEMOTION ||
|
||||||
|
event.type == SDL_MOUSEWHEEL;
|
||||||
|
|
||||||
|
const bool keyboardEvent =
|
||||||
|
event.type == SDL_KEYDOWN ||
|
||||||
|
event.type == SDL_KEYUP ||
|
||||||
|
event.type == SDL_TEXTINPUT;
|
||||||
|
|
||||||
|
const bool capturedByImgui =
|
||||||
|
(mouseEvent && imguiPass.wantsMouse()) ||
|
||||||
|
(keyboardEvent && imguiPass.wantsKeyboard());
|
||||||
|
|
||||||
|
if (!capturedByImgui) {
|
||||||
if (InputManager::GetInstance().ProcessEvent(event)) {
|
if (InputManager::GetInstance().ProcessEvent(event)) {
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!isRunning) break;
|
if (!isRunning) break;
|
||||||
|
imguiPass.beginFrame();
|
||||||
|
|
||||||
customUpdate(dt);
|
customUpdate(dt);
|
||||||
|
|
||||||
|
ImGui::Begin("Debug");
|
||||||
|
ImGui::Text("FPS: %.2f", avgFPS);
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
imguiPass.endFrame();
|
||||||
int steps = 0;
|
int steps = 0;
|
||||||
while (accumulator >= fixedDt && steps < maxSteps) {
|
while (accumulator >= fixedDt && steps < maxSteps) {
|
||||||
// physics.Update(fixedDt);
|
// physics.Update(fixedDt);
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
#include <SDL2/SDL_vulkan.h>
|
#include <SDL2/SDL_vulkan.h>
|
||||||
|
|
||||||
#include <destrum/Graphics/Init.h>
|
#include <destrum/Graphics/Init.h>
|
||||||
|
#include <destrum/Graphics/Pipelines/ImguiPass.h>
|
||||||
|
|
||||||
|
|
||||||
#include "destrum/Graphics/imageLoader.h"
|
#include "destrum/Graphics/imageLoader.h"
|
||||||
#include "destrum/Util/GameState.h"
|
#include "destrum/Util/GameState.h"
|
||||||
@@ -77,6 +79,8 @@ void GfxDevice::init(SDL_Window* window, const std::string& appName, bool vSync)
|
|||||||
.value();
|
.value();
|
||||||
|
|
||||||
device = vkb::DeviceBuilder{physicalDevice}.build().value();
|
device = vkb::DeviceBuilder{physicalDevice}.build().value();
|
||||||
|
volkLoadDevice(device);
|
||||||
|
|
||||||
|
|
||||||
graphicsQueueFamily = device.get_queue_index(vkb::QueueType::graphics).value();
|
graphicsQueueFamily = device.get_queue_index(vkb::QueueType::graphics).value();
|
||||||
graphicsQueue = device.get_queue(vkb::QueueType::graphics).value();
|
graphicsQueue = device.get_queue(vkb::QueueType::graphics).value();
|
||||||
@@ -234,6 +238,20 @@ void GfxDevice::endFrame(VkCommandBuffer cmd, const GPUImage& drawImage, const E
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prepare for present
|
||||||
|
// vkutil::transitionImage(cmd, swapchainImage, swapchainLayout, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||||
|
// swapchainLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||||
|
|
||||||
|
if (props.imguiPass) {
|
||||||
|
props.imguiPass->render(
|
||||||
|
cmd,
|
||||||
|
swapchainImage,
|
||||||
|
getSwapchainImageView(static_cast<std::uint32_t>(swapchainImageIndex)),
|
||||||
|
swapchainLayout,
|
||||||
|
getSwapchainExtent()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// prepare for present
|
// prepare for present
|
||||||
vkutil::transitionImage(cmd, swapchainImage, swapchainLayout, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
vkutil::transitionImage(cmd, swapchainImage, swapchainLayout, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||||
swapchainLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
swapchainLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||||
|
|||||||
@@ -0,0 +1,240 @@
|
|||||||
|
#include <destrum/Graphics/Pipelines/ImguiPass.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include <imgui.h>
|
||||||
|
#include <backends/imgui_impl_sdl2.h>
|
||||||
|
#include <backends/imgui_impl_vulkan.h>
|
||||||
|
|
||||||
|
#include <destrum/Graphics/GfxDevice.h>
|
||||||
|
#include <destrum/Graphics/Init.h>
|
||||||
|
|
||||||
|
void ImguiPass::init(SDL_Window* window, GfxDevice& gfxDevice) {
|
||||||
|
if (initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx = &gfxDevice;
|
||||||
|
sdlWindow = window;
|
||||||
|
colorFormat = gfx->getSwapchainFormat();
|
||||||
|
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
ImGui::CreateContext();
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
||||||
|
|
||||||
|
ImGui::StyleColorsDark();
|
||||||
|
|
||||||
|
if (!ImGui_ImplSDL2_InitForVulkan(sdlWindow)) {
|
||||||
|
throw std::runtime_error("ImGui_ImplSDL2_InitForVulkan failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::array<VkDescriptorPoolSize, 11> poolSizes{{
|
||||||
|
{ VK_DESCRIPTOR_TYPE_SAMPLER, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000 },
|
||||||
|
}};
|
||||||
|
|
||||||
|
VkDescriptorPoolCreateInfo poolInfo{};
|
||||||
|
poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||||
|
poolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||||
|
poolInfo.maxSets = 1000;
|
||||||
|
poolInfo.poolSizeCount = static_cast<uint32_t>(poolSizes.size());
|
||||||
|
poolInfo.pPoolSizes = poolSizes.data();
|
||||||
|
|
||||||
|
VK_CHECK(vkCreateDescriptorPool(gfx->getVkDevice(), &poolInfo, nullptr, &descriptorPool));
|
||||||
|
|
||||||
|
VkPipelineRenderingCreateInfoKHR pipelineRenderingInfo{};
|
||||||
|
pipelineRenderingInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR;
|
||||||
|
pipelineRenderingInfo.colorAttachmentCount = 1;
|
||||||
|
pipelineRenderingInfo.pColorAttachmentFormats = &colorFormat;
|
||||||
|
pipelineRenderingInfo.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
|
||||||
|
pipelineRenderingInfo.stencilAttachmentFormat = VK_FORMAT_UNDEFINED;
|
||||||
|
|
||||||
|
ImGui_ImplVulkan_PipelineInfo pipelineInfo{};
|
||||||
|
pipelineInfo.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
pipelineInfo.PipelineRenderingCreateInfo = pipelineRenderingInfo;
|
||||||
|
|
||||||
|
ImGui_ImplVulkan_InitInfo initInfo{};
|
||||||
|
initInfo.ApiVersion = VK_API_VERSION_1_3;
|
||||||
|
initInfo.Instance = gfxDevice.getVkInstance();
|
||||||
|
initInfo.PhysicalDevice = gfxDevice.getVkPhysicalDevice();
|
||||||
|
initInfo.Device = gfxDevice.getDevice();
|
||||||
|
initInfo.Queue = gfxDevice.getGraphicsQueue();
|
||||||
|
initInfo.DescriptorPool = descriptorPool;
|
||||||
|
initInfo.MinImageCount = 3;
|
||||||
|
initInfo.ImageCount = 3;
|
||||||
|
initInfo.UseDynamicRendering = true;
|
||||||
|
initInfo.PipelineInfoMain = pipelineInfo;
|
||||||
|
|
||||||
|
if (!ImGui_ImplVulkan_Init(&initInfo)) {
|
||||||
|
throw std::runtime_error("ImGui_ImplVulkan_Init failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImguiPass::handleEvent(const SDL_Event& event) {
|
||||||
|
if (!initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImguiPass::beginFrame() {
|
||||||
|
if (!initialized || frameBegun) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui_ImplVulkan_NewFrame();
|
||||||
|
ImGui_ImplSDL2_NewFrame();
|
||||||
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
frameBegun = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImguiPass::endFrame() {
|
||||||
|
if (!initialized || !frameBegun) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Render();
|
||||||
|
|
||||||
|
frameBegun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImguiPass::render(
|
||||||
|
VkCommandBuffer cmd,
|
||||||
|
VkImage targetImage,
|
||||||
|
VkImageView targetImageView,
|
||||||
|
VkImageLayout& targetImageLayout,
|
||||||
|
VkExtent2D targetExtent
|
||||||
|
) {
|
||||||
|
if (!initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImDrawData* drawData = ImGui::GetDrawData();
|
||||||
|
if (drawData == nullptr || drawData->CmdListsCount == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetImageLayout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
|
||||||
|
transitionToColorAttachment(
|
||||||
|
cmd,
|
||||||
|
targetImage,
|
||||||
|
targetImageLayout,
|
||||||
|
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
|
||||||
|
);
|
||||||
|
|
||||||
|
targetImageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkRenderingAttachmentInfo colorAttachment{};
|
||||||
|
colorAttachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
|
||||||
|
colorAttachment.imageView = targetImageView;
|
||||||
|
colorAttachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
|
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||||
|
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
|
|
||||||
|
VkRenderingInfo renderingInfo{};
|
||||||
|
renderingInfo.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
|
||||||
|
renderingInfo.renderArea.offset = { 0, 0 };
|
||||||
|
renderingInfo.renderArea.extent = targetExtent;
|
||||||
|
renderingInfo.layerCount = 1;
|
||||||
|
renderingInfo.colorAttachmentCount = 1;
|
||||||
|
renderingInfo.pColorAttachments = &colorAttachment;
|
||||||
|
|
||||||
|
vkCmdBeginRendering(cmd, &renderingInfo);
|
||||||
|
ImGui_ImplVulkan_RenderDrawData(drawData, cmd);
|
||||||
|
vkCmdEndRendering(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImguiPass::onSwapchainRecreated() {
|
||||||
|
if (!initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui_ImplVulkan_SetMinImageCount(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImguiPass::cleanup() {
|
||||||
|
if (!initialized || gfx == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vkDeviceWaitIdle(gfx->getVkDevice());
|
||||||
|
|
||||||
|
ImGui_ImplVulkan_Shutdown();
|
||||||
|
ImGui_ImplSDL2_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
if (descriptorPool != VK_NULL_HANDLE) {
|
||||||
|
vkDestroyDescriptorPool(gfx->getVkDevice(), descriptorPool, nullptr);
|
||||||
|
descriptorPool = VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx = nullptr;
|
||||||
|
sdlWindow = nullptr;
|
||||||
|
colorFormat = VK_FORMAT_UNDEFINED;
|
||||||
|
initialized = false;
|
||||||
|
frameBegun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImguiPass::wantsMouse() const {
|
||||||
|
if (!initialized) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ImGui::GetIO().WantCaptureMouse;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImguiPass::wantsKeyboard() const {
|
||||||
|
if (!initialized) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ImGui::GetIO().WantCaptureKeyboard;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImguiPass::transitionToColorAttachment(
|
||||||
|
VkCommandBuffer cmd,
|
||||||
|
VkImage image,
|
||||||
|
VkImageLayout oldLayout,
|
||||||
|
VkImageLayout newLayout
|
||||||
|
) const {
|
||||||
|
VkImageMemoryBarrier2 imageBarrier{};
|
||||||
|
imageBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2;
|
||||||
|
imageBarrier.srcStageMask = VK_PIPELINE_STAGE_2_TRANSFER_BIT | VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
imageBarrier.srcAccessMask = VK_ACCESS_2_TRANSFER_WRITE_BIT | VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
|
||||||
|
imageBarrier.dstStageMask = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
imageBarrier.dstAccessMask = VK_ACCESS_2_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
|
||||||
|
imageBarrier.oldLayout = oldLayout;
|
||||||
|
imageBarrier.newLayout = newLayout;
|
||||||
|
imageBarrier.image = image;
|
||||||
|
imageBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
imageBarrier.subresourceRange.baseMipLevel = 0;
|
||||||
|
imageBarrier.subresourceRange.levelCount = 1;
|
||||||
|
imageBarrier.subresourceRange.baseArrayLayer = 0;
|
||||||
|
imageBarrier.subresourceRange.layerCount = 1;
|
||||||
|
|
||||||
|
VkDependencyInfo dependencyInfo{};
|
||||||
|
dependencyInfo.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO;
|
||||||
|
dependencyInfo.imageMemoryBarrierCount = 1;
|
||||||
|
dependencyInfo.pImageMemoryBarriers = &imageBarrier;
|
||||||
|
|
||||||
|
vkCmdPipelineBarrier2(cmd, &dependencyInfo);
|
||||||
|
}
|
||||||
@@ -33,7 +33,7 @@ void Swapchain::createSwapchain(GfxDevice* gfxDevice, VkFormat format, std::uint
|
|||||||
.format = format,
|
.format = format,
|
||||||
.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
|
.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
|
||||||
})
|
})
|
||||||
.add_image_usage_flags(VK_IMAGE_USAGE_TRANSFER_DST_BIT)
|
.add_image_usage_flags(VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
|
||||||
.set_desired_present_mode(
|
.set_desired_present_mode(
|
||||||
vSync ? VK_PRESENT_MODE_FIFO_KHR : VK_PRESENT_MODE_IMMEDIATE_KHR)
|
vSync ? VK_PRESENT_MODE_FIFO_KHR : VK_PRESENT_MODE_IMMEDIATE_KHR)
|
||||||
.set_desired_extent(width, height)
|
.set_desired_extent(width, height)
|
||||||
@@ -89,7 +89,7 @@ void Swapchain::recreateSwapchain(
|
|||||||
.format = format,
|
.format = format,
|
||||||
.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
|
.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
|
||||||
})
|
})
|
||||||
.add_image_usage_flags(VK_IMAGE_USAGE_TRANSFER_DST_BIT)
|
.add_image_usage_flags(VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
|
||||||
.set_desired_present_mode(
|
.set_desired_present_mode(
|
||||||
vSync ? VK_PRESENT_MODE_FIFO_KHR : VK_PRESENT_MODE_IMMEDIATE_KHR)
|
vSync ? VK_PRESENT_MODE_FIFO_KHR : VK_PRESENT_MODE_IMMEDIATE_KHR)
|
||||||
.set_desired_extent(width, height)
|
.set_desired_extent(width, height)
|
||||||
|
|||||||
Vendored
+29
@@ -65,3 +65,32 @@ set(ASSIMP_INJECT_DEBUG_POSTFIX OFF CACHE BOOL "" FORCE)
|
|||||||
set(ASSIMP_INSTALL OFF CACHE BOOL "" FORCE)
|
set(ASSIMP_INSTALL OFF CACHE BOOL "" FORCE)
|
||||||
set(ASSIMP_WARNINGS_AS_ERRORS OFF CACHE BOOL "" FORCE)
|
set(ASSIMP_WARNINGS_AS_ERRORS OFF CACHE BOOL "" FORCE)
|
||||||
add_subdirectory(assimp)
|
add_subdirectory(assimp)
|
||||||
|
|
||||||
|
set(IMGUI_DIR "${CMAKE_CURRENT_LIST_DIR}/imgui")
|
||||||
|
|
||||||
|
add_library(imgui STATIC
|
||||||
|
"${IMGUI_DIR}/imgui.cpp"
|
||||||
|
"${IMGUI_DIR}/imgui_draw.cpp"
|
||||||
|
"${IMGUI_DIR}/imgui_tables.cpp"
|
||||||
|
"${IMGUI_DIR}/imgui_widgets.cpp"
|
||||||
|
"${IMGUI_DIR}/imgui_demo.cpp"
|
||||||
|
|
||||||
|
# Backends you use:
|
||||||
|
"${IMGUI_DIR}/backends/imgui_impl_sdl2.cpp"
|
||||||
|
"${IMGUI_DIR}/backends/imgui_impl_vulkan.cpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(imgui PUBLIC
|
||||||
|
"${IMGUI_DIR}"
|
||||||
|
"${IMGUI_DIR}/backends"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Because you use volk with Vulkan
|
||||||
|
target_compile_definitions(imgui PUBLIC
|
||||||
|
IMGUI_IMPL_VULKAN_USE_VOLK
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(imgui PUBLIC
|
||||||
|
SDL2::SDL2
|
||||||
|
volk
|
||||||
|
)
|
||||||
+1
Submodule destrum/third_party/imgui added at d15966ff6c
@@ -16,6 +16,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
#include "destrum/Util/ModelDocUtils.h"
|
#include "destrum/Util/ModelDocUtils.h"
|
||||||
|
|
||||||
LightKeeper::LightKeeper() : App(), renderer(meshCache, materialCache) {
|
LightKeeper::LightKeeper() : App(), renderer(meshCache, materialCache) {
|
||||||
@@ -385,7 +386,8 @@ void LightKeeper::customDraw() {
|
|||||||
gfxDevice.endFrame(
|
gfxDevice.endFrame(
|
||||||
cmd, drawImage, {
|
cmd, drawImage, {
|
||||||
.clearColor = {{0.f, 0.f, 0.5f, 1.f}},
|
.clearColor = {{0.f, 0.f, 0.5f, 1.f}},
|
||||||
.drawImageBlitRect = glm::ivec4{}
|
.drawImageBlitRect = glm::ivec4{},
|
||||||
|
.imguiPass = &imguiPass,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
LightKeeper app;
|
LightKeeper app;
|
||||||
app.init({
|
app.init({
|
||||||
.windowSize = {800, 600},
|
.windowSize = {1200, 800},
|
||||||
.renderSize = {800, 600},
|
.renderSize = {1200, 800},
|
||||||
.appName = "Astro Engine",
|
.appName = "Destrum Engine",
|
||||||
.windowTitle = "Lightkeeper",
|
.windowTitle = "Lightkeeper",
|
||||||
.exeDir = exeDir,
|
.exeDir = exeDir,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user