Skip to content

Commit

Permalink
Scaffolding for Imgui Resizing
Browse files Browse the repository at this point in the history
The actual resizing of ImGui Pipelines so it can actually work will come later. In the meantime, I've asked here: ocornut/imgui#6515
  • Loading branch information
KarimIO committed Jul 9, 2023
1 parent f17c678 commit 9656816
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 14 deletions.
2 changes: 2 additions & 0 deletions sources/code/Common/Window/Win32Window.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#ifndef NOMINMAX
#define NOMINMAX
#endif

#include "Window.hpp"
#include <windows.h>
Expand Down
37 changes: 27 additions & 10 deletions sources/code/Editor/ImguiEditor/ImguiEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
#include <iostream>
#include <imgui.h>
#include <imgui_internal.h>
#if EDITOR_USE_OPENGL
#include <imgui_impl_opengl3.h>
#include "GL/gl3w.h"
#else
#include <imgui_impl_vulkan.h>
#include <Plugins/GraphicsVulkan/VulkanCore.hpp>
#include <Plugins/GraphicsVulkan/VulkanRenderPass.hpp>
#include <Plugins/GraphicsVulkan/VulkanCommandBuffer.hpp>
#endif
#include <imgui_impl_win32.h>
#include <ImGuizmo.h>
#include <Windows.h>
#include <Winuser.h>

#include "Common/Window/WindowManager.hpp"
#include "EngineCore/EngineCore.hpp"
#include "EngineCore/Events/Dispatcher.hpp"
#include "Common/Event/WindowEvent.hpp"
#include "Editor/EditorManager.hpp"
#include "Modals/ModelConverterModal.hpp"
#include "Modals/ImageConverterModal.hpp"
Expand Down Expand Up @@ -68,6 +60,12 @@ ImguiEditor::ImguiEditor(EngineCore* engineCore) : engineCore(engineCore) {
controlBar = new ControlBar(imguiRenderer);
menubar = new Menubar(this);
statusBar = new StatusBar(imguiRenderer);

auto eventDispatcher = engineCore->GetEventDispatcher();
eventDispatcher->AddEventListener(
Events::EventType::WindowResize,
std::bind(&ImguiEditor::OnWindowResize, this, std::placeholders::_1)
);
}

ImguiEditor::~ImguiEditor() {
Expand All @@ -91,6 +89,20 @@ ImguiEditor::~ImguiEditor() {
delete statusBar;
}

void ImguiEditor::PerformResize() {
queueResize = false;
imguiRenderer->Resize();
}

bool ImguiEditor::OnWindowResize(Events::BaseEvent* ev) {
if (ev->GetEventType() == Events::EventType::WindowResize) {
Events::WindowResizeEvent* winResizeEvent = (Events::WindowResizeEvent*)ev;
queueResize = true;
}

return false;
}

void ImguiEditor::SetupFonts() {
auto& io = ImGui::GetIO();

Expand Down Expand Up @@ -210,6 +222,11 @@ void ImguiEditor::SetupStyles() {
}

void ImguiEditor::Update() {
if (queueResize) {
PerformResize();
return;
}

if (!imguiRenderer->PreRender()) {
return;
}
Expand Down
5 changes: 5 additions & 0 deletions sources/code/Editor/ImguiEditor/ImguiEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <entt/entt.hpp>
#include <vulkan/vulkan.h>

#include <Common/Event/BaseEvent.hpp>

namespace Grindstone {
class EngineCore;

Expand Down Expand Up @@ -48,7 +50,10 @@ namespace Grindstone {
void SetupFonts();
void SetupStyles();
void SetupColors();
bool OnWindowResize(Events::BaseEvent* ev);
void PerformResize();
private:
bool queueResize = false;
EngineCore* engineCore = nullptr;
ImguiInput* input = nullptr;
ImageConverterModal* imageConverterModal = nullptr;
Expand Down
1 change: 1 addition & 0 deletions sources/code/Editor/ImguiEditor/ImguiRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Grindstone {
virtual bool PreRender() = 0;
virtual void PrepareImguiRendering() = 0;
virtual void PostRender() = 0;
virtual void Resize() = 0;
virtual ImTextureID CreateTexture(std::filesystem::path path) = 0;
};
}
Expand Down
4 changes: 4 additions & 0 deletions sources/code/Editor/ImguiEditor/ImguiRendererOpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ void ImguiRendererOpenGL::PostRender() {
ImGui::RenderPlatformWindowsDefault();
}

void ImguiRendererOpenGL::Resize() {

}

ImTextureID ImguiRendererOpenGL::CreateTexture(std::filesystem::path path) {
std::filesystem::path fullPath = "../engineassets/editor/" / path;
auto assetManager = Editor::Manager::GetEngineCore().assetManager;
Expand Down
1 change: 1 addition & 0 deletions sources/code/Editor/ImguiEditor/ImguiRendererOpenGL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Grindstone {
virtual bool PreRender() override;
virtual void PrepareImguiRendering() override;
virtual void PostRender() override;
virtual void Resize() override;
virtual ImTextureID CreateTexture(std::filesystem::path path) override;
};
}
Expand Down
8 changes: 8 additions & 0 deletions sources/code/Editor/ImguiEditor/ImguiRendererVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <Windows.h>

#include <Common/Window/WindowManager.hpp>
#include <Common/Window/Win32Window.hpp>
#include <Editor/EditorManager.hpp>
#include <EngineCore/Assets/AssetManager.hpp>
#include <EngineCore/Assets/Textures/TextureAsset.hpp>
Expand Down Expand Up @@ -140,6 +141,13 @@ void ImguiRendererVulkan::PostRender() {
window->PresentSwapchain();
}

void ImguiRendererVulkan::Resize() {
Grindstone::EngineCore& engineCore = Grindstone::Editor::Manager::GetEngineCore();
auto vulkanCore = static_cast<Grindstone::GraphicsAPI::VulkanCore*>(engineCore.GetGraphicsCore());
auto window = static_cast<Win32Window*>(engineCore.windowManager->GetWindowByIndex(0));
auto wgb = window->GetWindowGraphicsBinding();
}

ImTextureID ImguiRendererVulkan::CreateTexture(std::filesystem::path path) {
std::filesystem::path fullPath = "../engineassets/editor/" / path;
auto assetManager = Editor::Manager::GetEngineCore().assetManager;
Expand Down
1 change: 1 addition & 0 deletions sources/code/Editor/ImguiEditor/ImguiRendererVulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Grindstone {
virtual bool PreRender() override;
virtual void PrepareImguiRendering() override;
virtual void PostRender() override;
virtual void Resize() override;
virtual ImTextureID CreateTexture(std::filesystem::path path) override;
private:
VkDescriptorPool imguiPool = nullptr;
Expand Down
10 changes: 6 additions & 4 deletions sources/code/EngineCore/CoreSystems/RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ glm::vec3 EulerToForward(glm::vec3 eulerAngle) {
float pitch = eulerAngle.x;
float yaw = eulerAngle.y;

glm::vec3 forwardVector;
forwardVector.x = cos(yaw) * cos(pitch);
forwardVector.y = sin(pitch);
forwardVector.z = sin(yaw) * cos(pitch);
glm::vec3 forwardVector {
cos(yaw)* cos(pitch),
sin(pitch),
sin(yaw)* cos(pitch)
};

return glm::normalize(forwardVector);
}

Expand Down
4 changes: 4 additions & 0 deletions sources/code/Plugins/GraphicsVulkan/VulkanCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,10 @@ VkCommandBuffer VulkanCore::BeginSingleTimeCommands() {
return GraphicsAPI::BeginSingleTimeCommands();
}

uint32_t VulkanCore::GetGraphicsFamily() {
return graphicsFamily;
}

void VulkanCore::EndSingleTimeCommands(VkCommandBuffer commandBuffer) {
GraphicsAPI::EndSingleTimeCommands(commandBuffer);
}
Expand Down
1 change: 1 addition & 0 deletions sources/code/Plugins/GraphicsVulkan/VulkanCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace Grindstone {
virtual VkDevice GetDevice();
virtual VkPhysicalDevice GetPhysicalDevice();
virtual VkCommandBuffer BeginSingleTimeCommands();
virtual uint32_t GetGraphicsFamily();
virtual void EndSingleTimeCommands(VkCommandBuffer commandBuffer);
VkCommandPool GetGraphicsCommandPool();
std::function<void(LogSeverity, const char*)> logFunction;
Expand Down

0 comments on commit 9656816

Please sign in to comment.