update NazaraImgui to reflect latest changes in Nazara
This commit is contained in:
parent
0a50ad12ad
commit
14c36368de
|
|
@ -1,10 +1,16 @@
|
|||
|
||||
#include <Nazara/Core/Modules.hpp>
|
||||
#include <Nazara/Core/Application.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Graphics/Graphics.hpp>
|
||||
#include <Nazara/Renderer/RenderWindow.hpp>
|
||||
#include <Nazara/Platform/AppWindowingComponent.hpp>
|
||||
#include <Nazara/Platform/Platform.hpp>
|
||||
#include <Nazara/Renderer/GpuSwitch.hpp>
|
||||
#include <Nazara/Renderer/WindowSwapchain.hpp>
|
||||
|
||||
#include <NazaraImgui/NazaraImgui.hpp>
|
||||
|
||||
NAZARA_REQUEST_DEDICATED_GPU()
|
||||
|
||||
struct MyImguiWindow
|
||||
: private Nz::ImguiHandler
|
||||
{
|
||||
|
|
@ -28,12 +34,22 @@ struct MyImguiWindow
|
|||
float values[4] = { 0 };
|
||||
};
|
||||
|
||||
#if 1
|
||||
int main(int argc, char* argv[])
|
||||
#else
|
||||
int WinMain(int argc, char* argv[])
|
||||
#endif
|
||||
{
|
||||
NazaraUnused(argc);
|
||||
NazaraUnused(argv);
|
||||
|
||||
Nz::Modules<Nz::Graphics, Nz::Imgui> nazara;
|
||||
Nz::Application<Nz::Graphics, Nz::Imgui> nazara;
|
||||
auto& windowing = nazara.AddComponent<Nz::AppWindowingComponent>();
|
||||
std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();
|
||||
|
||||
std::string windowTitle = "Nazara Imgui Demo";
|
||||
Nz::Window& window = windowing.CreateWindow(Nz::VideoMode(1280, 720, 32), windowTitle);
|
||||
Nz::WindowSwapchain windowSwapchain(device, window);
|
||||
|
||||
// Load test texture
|
||||
Nz::TextureParams texParams;
|
||||
|
|
@ -41,11 +57,6 @@ int WinMain(int argc, char* argv[])
|
|||
texParams.loadFormat = Nz::PixelFormat::RGBA8;
|
||||
auto logo = Nz::Texture::LoadFromFile("LogoMini.png", texParams);
|
||||
|
||||
std::string windowTitle = "Nazara Imgui Demo";
|
||||
Nz::RenderWindow window;
|
||||
if (!window.Create(Nz::Graphics::Instance()->GetRenderDevice(), Nz::VideoMode(1280, 720, 32), windowTitle))
|
||||
return false;
|
||||
|
||||
// connect basic handler
|
||||
window.GetEventHandler().OnQuit.Connect([&window](const auto* handler) {
|
||||
NazaraUnused(handler);
|
||||
|
|
@ -58,20 +69,20 @@ int WinMain(int argc, char* argv[])
|
|||
float val = 0.f;
|
||||
float color[4] = { 1,0,0,1 };
|
||||
|
||||
Nz::Clock updateClock;
|
||||
Nz::MillisecondClock updateClock;
|
||||
|
||||
while (window.IsOpen())
|
||||
{
|
||||
window.ProcessEvents();
|
||||
|
||||
Nz::RenderFrame frame = window.AcquireFrame();
|
||||
Nz::RenderFrame frame = windowSwapchain.AcquireFrame();
|
||||
if (!frame)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
continue;
|
||||
}
|
||||
|
||||
float deltaTime = updateClock.GetSeconds();
|
||||
float deltaTime = updateClock.GetElapsedTime().AsSeconds();
|
||||
Nz::Imgui::Instance()->Update(window, deltaTime);
|
||||
|
||||
ImGui::Begin("Loop Window");
|
||||
|
|
@ -83,7 +94,7 @@ int WinMain(int argc, char* argv[])
|
|||
ImGui::InputFloat4("value from 2nd window", mywindow.values, "%.3f", ImGuiInputTextFlags_ReadOnly);
|
||||
ImGui::End();
|
||||
|
||||
Nz::Imgui::Instance()->Render(window, frame);
|
||||
Nz::Imgui::Instance()->Render(&windowSwapchain, frame);
|
||||
|
||||
frame.Present();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
#include <Nazara/Core/ModuleBase.hpp>
|
||||
#include <Nazara/Graphics/Graphics.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Utils/TypeList.hpp>
|
||||
|
||||
#include <NazaraImgui/Config.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
|
|
@ -13,12 +11,12 @@
|
|||
namespace Nz
|
||||
{
|
||||
class Cursor;
|
||||
class EventHandler;
|
||||
class RenderFrame;
|
||||
class RenderTarget;
|
||||
class RenderWindow;
|
||||
class Texture;
|
||||
class Window;
|
||||
class WindowEventHandler;
|
||||
|
||||
struct ImguiHandler
|
||||
{
|
||||
|
|
@ -39,7 +37,7 @@ namespace Nz
|
|||
|
||||
bool Init(Nz::Window& window, bool bLoadDefaultFont = true);
|
||||
void Update(Nz::Window& window, float dt);
|
||||
void Render(Nz::RenderWindow& window, Nz::RenderFrame& frame);
|
||||
void Render(Nz::RenderTarget* renderTarget, Nz::RenderFrame& frame);
|
||||
|
||||
// User-defined
|
||||
void AddHandler(ImguiHandler* handler);
|
||||
|
|
@ -55,7 +53,7 @@ namespace Nz
|
|||
};
|
||||
|
||||
private:
|
||||
void SetupInputs(Nz::EventHandler& handler);
|
||||
void SetupInputs(Nz::WindowEventHandler& handler);
|
||||
void Update(const Nz::Vector2i& mousePosition, const Nz::Vector2ui& displaySize, float dt);
|
||||
|
||||
// Cursor functions
|
||||
|
|
@ -66,7 +64,7 @@ namespace Nz
|
|||
bool LoadUntexturedPipeline();
|
||||
void UpdateFontTexture();
|
||||
|
||||
void RenderDrawLists(Nz::RenderWindow& window, Nz::RenderFrame& frame, ImDrawData* drawData);
|
||||
void RenderDrawLists(Nz::RenderTarget* renderTarget, Nz::RenderFrame& frame, ImDrawData* drawData);
|
||||
|
||||
std::string m_clipboardText;
|
||||
|
||||
|
|
@ -101,14 +99,14 @@ namespace ImGui
|
|||
// custom ImGui widgets for SFML stuff
|
||||
|
||||
// Image overloads
|
||||
void Image(const Nz::Texture* texture, const Nz::Color& tintColor = Nz::Color::White, const Nz::Color& borderColor = Nz::Color(0,0,0,0));
|
||||
void Image(const Nz::Texture* texture, const Nz::Vector2f& size, const Nz::Color& tintColor = Nz::Color::White, const Nz::Color& borderColor = Nz::Color(0,0,0,0));
|
||||
void Image(const Nz::Texture* texture, const Nz::Rectf& textureRect, const Nz::Color& tintColor = Nz::Color::White, const Nz::Color& borderColor = Nz::Color(0,0,0,0));
|
||||
void Image(const Nz::Texture* texture, const Nz::Vector2f& size, const Nz::Rectf& textureRect, const Nz::Color& tintColor = Nz::Color::White, const Nz::Color& borderColor = Nz::Color(0,0,0,0));
|
||||
void Image(const Nz::Texture* texture, const Nz::Color& tintColor = Nz::Color::White(), const Nz::Color& borderColor = Nz::Color(0, 0, 0, 0));
|
||||
void Image(const Nz::Texture* texture, const Nz::Vector2f& size, const Nz::Color& tintColor = Nz::Color::White(), const Nz::Color& borderColor = Nz::Color(0, 0, 0, 0));
|
||||
void Image(const Nz::Texture* texture, const Nz::Rectf& textureRect, const Nz::Color& tintColor = Nz::Color::White(), const Nz::Color& borderColor = Nz::Color(0, 0, 0, 0));
|
||||
void Image(const Nz::Texture* texture, const Nz::Vector2f& size, const Nz::Rectf& textureRect, const Nz::Color& tintColor = Nz::Color::White(), const Nz::Color& borderColor = Nz::Color(0, 0, 0, 0));
|
||||
|
||||
// ImageButton overloads
|
||||
bool ImageButton(const Nz::Texture* texture, const int framePadding = -1, const Nz::Color& bgColor = Nz::Color(0,0,0,0), const Nz::Color& tintColor = Nz::Color::White);
|
||||
bool ImageButton(const Nz::Texture* texture, const Nz::Vector2f& size, const int framePadding = -1, const Nz::Color& bgColor = Nz::Color(0,0,0,0), const Nz::Color& tintColor = Nz::Color::White);
|
||||
bool ImageButton(const Nz::Texture* texture, const int framePadding = -1, const Nz::Color& bgColor = Nz::Color(0,0,0,0), const Nz::Color& tintColor = Nz::Color::White());
|
||||
bool ImageButton(const Nz::Texture* texture, const Nz::Vector2f& size, const int framePadding = -1, const Nz::Color& bgColor = Nz::Color(0,0,0,0), const Nz::Color& tintColor = Nz::Color::White());
|
||||
|
||||
// Draw_list overloads. All positions are in relative coordinates (relative to top-left of the current window)
|
||||
void DrawLine(const Nz::Vector2f& a, const Nz::Vector2f& b, const Nz::Color& col, float thickness = 1.0f);
|
||||
|
|
|
|||
|
|
@ -4,12 +4,11 @@
|
|||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Platform/Cursor.hpp>
|
||||
#include <Nazara/Platform/Clipboard.hpp>
|
||||
#include <Nazara/Platform/Event.hpp>
|
||||
#include <Nazara/Platform/Window.hpp>
|
||||
#include <Nazara/Renderer/CommandBufferBuilder.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Renderer/RenderWindow.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <NZSL/Parser.hpp>
|
||||
|
||||
|
|
@ -174,7 +173,7 @@ namespace Nz
|
|||
#endif
|
||||
}
|
||||
|
||||
void Imgui::SetupInputs(Nz::EventHandler& handler)
|
||||
void Imgui::SetupInputs(Nz::WindowEventHandler& handler)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
|
|
@ -202,14 +201,14 @@ namespace Nz
|
|||
io.KeyMap[ImGuiKey_Z] = (int)Nz::Keyboard::Scancode::Z;
|
||||
|
||||
// Setup event handler
|
||||
handler.OnMouseMoved.Connect([this](const Nz::EventHandler*, const Nz::WindowEvent::MouseMoveEvent&) {
|
||||
handler.OnMouseMoved.Connect([this](const Nz::WindowEventHandler*, const Nz::WindowEvent::MouseMoveEvent&) {
|
||||
if (!m_bWindowHasFocus)
|
||||
return;
|
||||
|
||||
m_bMouseMoved = true;
|
||||
});
|
||||
|
||||
handler.OnMouseButtonPressed.Connect([this](const Nz::EventHandler*, const Nz::WindowEvent::MouseButtonEvent& event) {
|
||||
handler.OnMouseButtonPressed.Connect([this](const Nz::WindowEventHandler*, const Nz::WindowEvent::MouseButtonEvent& event) {
|
||||
if (!m_bWindowHasFocus)
|
||||
return;
|
||||
|
||||
|
|
@ -221,7 +220,7 @@ namespace Nz
|
|||
}
|
||||
});
|
||||
|
||||
handler.OnMouseButtonReleased.Connect([this](const Nz::EventHandler*, const Nz::WindowEvent::MouseButtonEvent& event) {
|
||||
handler.OnMouseButtonReleased.Connect([this](const Nz::WindowEventHandler*, const Nz::WindowEvent::MouseButtonEvent& event) {
|
||||
if (!m_bWindowHasFocus)
|
||||
return;
|
||||
|
||||
|
|
@ -233,7 +232,7 @@ namespace Nz
|
|||
}
|
||||
});
|
||||
|
||||
handler.OnMouseWheelMoved.Connect([this](const Nz::EventHandler*, const Nz::WindowEvent::MouseWheelEvent& event) {
|
||||
handler.OnMouseWheelMoved.Connect([this](const Nz::WindowEventHandler*, const Nz::WindowEvent::MouseWheelEvent& event) {
|
||||
if (!m_bWindowHasFocus)
|
||||
return;
|
||||
|
||||
|
|
@ -241,7 +240,7 @@ namespace Nz
|
|||
io.MouseWheel += event.delta;
|
||||
});
|
||||
|
||||
handler.OnKeyPressed.Connect([this](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& event) {
|
||||
handler.OnKeyPressed.Connect([this](const Nz::WindowEventHandler*, const Nz::WindowEvent::KeyEvent& event) {
|
||||
if (!m_bWindowHasFocus)
|
||||
return;
|
||||
|
||||
|
|
@ -249,7 +248,7 @@ namespace Nz
|
|||
io.KeysDown[(int)event.scancode] = true;
|
||||
});
|
||||
|
||||
handler.OnKeyReleased.Connect([this](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& event) {
|
||||
handler.OnKeyReleased.Connect([this](const Nz::WindowEventHandler*, const Nz::WindowEvent::KeyEvent& event) {
|
||||
if (!m_bWindowHasFocus)
|
||||
return;
|
||||
|
||||
|
|
@ -257,7 +256,7 @@ namespace Nz
|
|||
io.KeysDown[(int)event.scancode] = false;
|
||||
});
|
||||
|
||||
handler.OnTextEntered.Connect([this](const Nz::EventHandler*, const Nz::WindowEvent::TextEvent& event) {
|
||||
handler.OnTextEntered.Connect([this](const Nz::WindowEventHandler*, const Nz::WindowEvent::TextEvent& event) {
|
||||
if (!m_bWindowHasFocus)
|
||||
return;
|
||||
|
||||
|
|
@ -271,11 +270,11 @@ namespace Nz
|
|||
io.AddInputCharacter(event.character);
|
||||
});
|
||||
|
||||
handler.OnGainedFocus.Connect([this](const Nz::EventHandler*) {
|
||||
handler.OnGainedFocus.Connect([this](const Nz::WindowEventHandler*) {
|
||||
m_bWindowHasFocus = true;
|
||||
});
|
||||
|
||||
handler.OnLostFocus.Connect([this](const Nz::EventHandler*) {
|
||||
handler.OnLostFocus.Connect([this](const Nz::WindowEventHandler*) {
|
||||
m_bWindowHasFocus = false;
|
||||
});
|
||||
}
|
||||
|
|
@ -310,13 +309,13 @@ namespace Nz
|
|||
ImGui::NewFrame();
|
||||
}
|
||||
|
||||
void Imgui::Render(Nz::RenderWindow& window, Nz::RenderFrame& frame)
|
||||
void Imgui::Render(Nz::RenderTarget* renderTarget, Nz::RenderFrame& frame)
|
||||
{
|
||||
for (auto* handler : m_handlers)
|
||||
handler->OnRenderImgui();
|
||||
|
||||
ImGui::Render();
|
||||
RenderDrawLists(window, frame, ImGui::GetDrawData());
|
||||
RenderDrawLists(renderTarget, frame, ImGui::GetDrawData());
|
||||
}
|
||||
|
||||
void Imgui::AddHandler(ImguiHandler* handler)
|
||||
|
|
@ -438,7 +437,7 @@ namespace Nz
|
|||
pipelineInfo.shaderModules.emplace_back(shader);
|
||||
|
||||
pipelineInfo.depthBuffer = false;
|
||||
pipelineInfo.faceCulling = false;
|
||||
pipelineInfo.faceCulling = Nz::FaceCulling::None;
|
||||
pipelineInfo.scissorTest = true;
|
||||
|
||||
pipelineInfo.blending = true;
|
||||
|
|
@ -505,7 +504,7 @@ namespace Nz
|
|||
pipelineInfo.shaderModules.emplace_back(shader);
|
||||
|
||||
pipelineInfo.depthBuffer = false;
|
||||
pipelineInfo.faceCulling = false;
|
||||
pipelineInfo.faceCulling = Nz::FaceCulling::None;
|
||||
pipelineInfo.scissorTest = true;
|
||||
|
||||
pipelineInfo.blending = true;
|
||||
|
|
@ -534,7 +533,7 @@ namespace Nz
|
|||
}
|
||||
|
||||
// Rendering callback
|
||||
void Imgui::RenderDrawLists(Nz::RenderWindow& window, Nz::RenderFrame& frame, ImDrawData* drawData)
|
||||
void Imgui::RenderDrawLists(Nz::RenderTarget* renderTarget, Nz::RenderFrame& frame, ImDrawData* drawData)
|
||||
{
|
||||
if (drawData->CmdListsCount == 0)
|
||||
return;
|
||||
|
|
@ -555,7 +554,7 @@ namespace Nz
|
|||
|
||||
frame.Execute([&](Nz::CommandBufferBuilder& builder)
|
||||
{
|
||||
builder.BeginDebugRegion("UBO Update", Nz::Color::Yellow);
|
||||
builder.BeginDebugRegion("UBO Update", Nz::Color::Yellow());
|
||||
{
|
||||
builder.PreTransferBarrier();
|
||||
builder.CopyBuffer(allocation, m_uboBuffer.get());
|
||||
|
|
@ -611,14 +610,12 @@ namespace Nz
|
|||
vertices.clear();
|
||||
indices.clear();
|
||||
|
||||
auto* windowRT = window.GetRenderTarget();
|
||||
|
||||
frame.Execute([this, windowRT, &frame, fb_width, fb_height, drawCalls, vertexBuffer, indexBuffer](Nz::CommandBufferBuilder& builder) {
|
||||
builder.BeginDebugRegion("ImGui", Nz::Color::Green);
|
||||
frame.Execute([this, renderTarget, &frame, fb_width, fb_height, drawCalls, vertexBuffer, indexBuffer](Nz::CommandBufferBuilder& builder) {
|
||||
builder.BeginDebugRegion("ImGui", Nz::Color::Green());
|
||||
{
|
||||
Nz::Recti renderRect(0, 0, fb_width, fb_height);
|
||||
|
||||
builder.BeginRenderPass(windowRT->GetFramebuffer(frame.GetFramebufferIndex()), windowRT->GetRenderPass(), renderRect);
|
||||
builder.BeginRenderPass(renderTarget->GetFramebuffer(frame.GetFramebufferIndex()), renderTarget->GetRenderPass(), renderRect);
|
||||
{
|
||||
builder.SetViewport(Nz::Recti{ 0, 0, fb_width, fb_height });
|
||||
builder.BindIndexBuffer(*indexBuffer, Nz::IndexType::U16);
|
||||
|
|
@ -643,7 +640,7 @@ namespace Nz
|
|||
binding->Update({
|
||||
{
|
||||
0,
|
||||
Nz::ShaderBinding::TextureBinding {
|
||||
Nz::ShaderBinding::SampledTextureBinding {
|
||||
texture, m_texturedPipeline.textureSampler.get()
|
||||
}
|
||||
}
|
||||
|
|
@ -651,14 +648,14 @@ namespace Nz
|
|||
m_texturedPipeline.textureShaderBindings[texture] = std::move(binding);
|
||||
}
|
||||
|
||||
builder.BindPipeline(*m_texturedPipeline.pipeline);
|
||||
builder.BindShaderBinding(0, *m_texturedPipeline.uboShaderBinding);
|
||||
builder.BindShaderBinding(1, *m_texturedPipeline.textureShaderBindings[texture]);
|
||||
builder.BindRenderPipeline(*m_texturedPipeline.pipeline);
|
||||
builder.BindRenderShaderBinding(0, *m_texturedPipeline.uboShaderBinding);
|
||||
builder.BindRenderShaderBinding(1, *m_texturedPipeline.textureShaderBindings[texture]);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.BindPipeline(*m_untexturedPipeline.pipeline);
|
||||
builder.BindShaderBinding(0, *m_untexturedPipeline.uboShaderBinding);
|
||||
builder.BindRenderPipeline(*m_untexturedPipeline.pipeline);
|
||||
builder.BindRenderShaderBinding(0, *m_untexturedPipeline.uboShaderBinding);
|
||||
}
|
||||
|
||||
builder.SetScissor(Nz::Recti{ int(rect.x), int(rect.y), int(rect.z - rect.x), int(rect.w - rect.y) });// Nz::Recti{ int(rect.x), int(fb_height - rect.w), int(rect.z - rect.x), int(rect.w - rect.y) });
|
||||
|
|
|
|||
Loading…
Reference in New Issue