Compare commits

...

16 Commits

Author SHA1 Message Date
SweetId
54c43c7600 Fix examples compilation 2024-02-22 17:27:43 -05:00
Sid
eccddc2871 Merge pull request #1 from SirLynix/renderer-fixes
Renderer fixes
2024-02-22 17:25:28 -05:00
Sid
785f814e15 Merge pull request #2 from SirLynix/main
Update for latest Nazara version
2024-02-22 17:22:42 -05:00
Lynix
2156fdce4f Update for latest Nazara version 2024-02-12 15:47:28 +01:00
SweetId
c0a51732d0 fix crash 2023-12-12 12:38:01 +01:00
SweetId
1befc1a3d4 release buffers properly 2023-12-08 16:10:52 +01:00
Lynix
120ba7dcd7 Fix font texture mipmaps and setup a debug name 2023-11-28 15:22:10 +01:00
Lynix
fa10201d69 Fix clear values 2023-11-28 15:21:56 +01:00
SweetId
e3f4b74a66 minimize nazara dependencies 2023-11-28 19:00:53 +05:30
SweetId
ae70760305 fix invalide binding type 2023-11-28 19:00:03 +05:30
SweetId
fe6dec9934 Fix arguments order 2023-11-28 18:59:49 +05:30
SweetId
8cb4290a4f passing args to application 2023-11-28 18:39:55 +05:30
SweetId
635b9a58bb passing args as params to Nz::Application 2023-11-28 18:32:31 +05:30
SweetId
37b35051f7 ignore imgui.ini file 2023-11-24 16:05:33 +05:30
SweetId
9e4d157792 fix warnings 2023-11-24 16:04:05 +05:30
SweetId
1accd86a9c split NazaraImgui.hpp into multiples files to speed up compilation 2023-11-24 16:03:56 +05:30
10 changed files with 81 additions and 47 deletions

3
.gitignore vendored
View File

@@ -193,3 +193,6 @@ DocProject/Help/*.hhk
DocProject/Help/*.hhp DocProject/Help/*.hhp
DocProject/Help/Html2 DocProject/Help/Html2
DocProject/Help/html DocProject/Help/html
# Ignore Imgui files
imgui.ini

View File

@@ -2,11 +2,13 @@
#include <Nazara/Core/Application.hpp> #include <Nazara/Core/Application.hpp>
#include <Nazara/Core/Clock.hpp> #include <Nazara/Core/Clock.hpp>
#include <Nazara/Graphics/Graphics.hpp> #include <Nazara/Graphics/Graphics.hpp>
#include <Nazara/Platform/AppWindowingComponent.hpp>
#include <Nazara/Platform/Platform.hpp> #include <Nazara/Platform/Platform.hpp>
#include <Nazara/Platform/WindowingAppComponent.hpp>
#include <Nazara/Renderer/GpuSwitch.hpp> #include <Nazara/Renderer/GpuSwitch.hpp>
#include <Nazara/Renderer/WindowSwapchain.hpp> #include <Nazara/Renderer/WindowSwapchain.hpp>
#include <NazaraImgui/ImguiHandler.hpp>
#include <NazaraImgui/ImguiWidgets.hpp>
#include <NazaraImgui/NazaraImgui.hpp> #include <NazaraImgui/NazaraImgui.hpp>
NAZARA_REQUEST_DEDICATED_GPU() NAZARA_REQUEST_DEDICATED_GPU()
@@ -40,11 +42,8 @@ int main(int argc, char* argv[])
int WinMain(int argc, char* argv[]) int WinMain(int argc, char* argv[])
#endif #endif
{ {
NazaraUnused(argc); Nz::Application<Nz::Graphics, Nz::Imgui> nazara(argc, argv);
NazaraUnused(argv); auto& windowing = nazara.AddComponent<Nz::WindowingAppComponent>();
Nz::Application<Nz::Graphics, Nz::Imgui> nazara;
auto& windowing = nazara.AddComponent<Nz::AppWindowingComponent>();
std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice(); std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();
std::string windowTitle = "Nazara Imgui Demo"; std::string windowTitle = "Nazara Imgui Demo";

View File

@@ -3,8 +3,9 @@
#include <Nazara/Graphics.hpp> #include <Nazara/Graphics.hpp>
#include <Nazara/Platform.hpp> #include <Nazara/Platform.hpp>
#include <Nazara/Renderer.hpp> #include <Nazara/Renderer.hpp>
#include <Nazara/Utility.hpp>
#include <NazaraImgui/ImguiHandler.hpp>
#include <NazaraImgui/ImguiWidgets.hpp>
#include <NazaraImgui/NazaraImgui.hpp> #include <NazaraImgui/NazaraImgui.hpp>
NAZARA_REQUEST_DEDICATED_GPU() NAZARA_REQUEST_DEDICATED_GPU()
@@ -38,14 +39,11 @@ int main(int argc, char* argv[])
int WinMain(int argc, char* argv[]) int WinMain(int argc, char* argv[])
#endif #endif
{ {
NazaraUnused(argc); Nz::Application<Nz::Graphics, Nz::Imgui> nazara(argc, argv);
NazaraUnused(argv); auto& windowing = nazara.AddComponent<Nz::WindowingAppComponent>();
Nz::Application<Nz::Graphics, Nz::Imgui> nazara;
auto& windowing = nazara.AddComponent<Nz::AppWindowingComponent>();
std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice(); std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();
auto& ecs = nazara.AddComponent<Nz::AppEntitySystemComponent>(); auto& ecs = nazara.AddComponent<Nz::EntitySystemAppComponent>();
auto& world = ecs.AddWorld<Nz::EnttWorld>(); auto& world = ecs.AddWorld<Nz::EnttWorld>();
auto& renderer = world.AddSystem<Nz::RenderSystem>(); auto& renderer = world.AddSystem<Nz::RenderSystem>();

View File

@@ -0,0 +1,15 @@
#pragma once
/*
ImguiHandler.hpp
Inherit from this base class for your Imgui code to be called by the Imgui renderer
*/
namespace Nz
{
struct ImguiHandler
{
public:
virtual void OnRenderImgui() = 0;
};
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include <NazaraImgui/Config.hpp>
#include <Nazara/Math/Rect.hpp>
namespace Nz
{
class Texture;
}
namespace ImGui
{
// custom ImGui widgets for Nazara
// Image overloads
NAZARA_IMGUI_API void Image(const Nz::Texture* texture, const Nz::Color& tintColor = Nz::Color::White(), const Nz::Color& borderColor = Nz::Color(0, 0, 0, 0));
NAZARA_IMGUI_API 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));
NAZARA_IMGUI_API 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));
NAZARA_IMGUI_API 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
NAZARA_IMGUI_API 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());
NAZARA_IMGUI_API 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)
NAZARA_IMGUI_API void DrawLine(const Nz::Vector2f& a, const Nz::Vector2f& b, const Nz::Color& col, float thickness = 1.0f);
NAZARA_IMGUI_API void DrawRect(const Nz::Rectf& rect, const Nz::Color& color, float rounding = 0.0f, int rounding_corners = 0x0F, float thickness = 1.0f);
NAZARA_IMGUI_API void DrawRectFilled(const Nz::Rectf& rect, const Nz::Color& color, float rounding = 0.0f, int rounding_corners = 0x0F);
}

View File

@@ -2,7 +2,6 @@
#include <Nazara/Core/ModuleBase.hpp> #include <Nazara/Core/ModuleBase.hpp>
#include <Nazara/Graphics/Graphics.hpp> #include <Nazara/Graphics/Graphics.hpp>
#include <Nazara/Math/Rect.hpp>
#include <NazaraImgui/Config.hpp> #include <NazaraImgui/Config.hpp>
#include <NazaraImgui/ImguiDrawer.hpp> #include <NazaraImgui/ImguiDrawer.hpp>
@@ -19,11 +18,7 @@ namespace Nz
class Window; class Window;
class WindowEventHandler; class WindowEventHandler;
struct ImguiHandler struct ImguiHandler;
{
public:
virtual void OnRenderImgui() = 0;
};
class NAZARA_IMGUI_API Imgui : public Nz::ModuleBase<Imgui> class NAZARA_IMGUI_API Imgui : public Nz::ModuleBase<Imgui>
{ {
@@ -91,23 +86,6 @@ namespace Nz
namespace ImGui namespace ImGui
{ {
// custom ImGui widgets for Nazara
// Image overloads
NAZARA_IMGUI_API void Image(const Nz::Texture* texture, const Nz::Color& tintColor = Nz::Color::White(), const Nz::Color& borderColor = Nz::Color(0, 0, 0, 0));
NAZARA_IMGUI_API 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));
NAZARA_IMGUI_API 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));
NAZARA_IMGUI_API 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
NAZARA_IMGUI_API 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());
NAZARA_IMGUI_API 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)
NAZARA_IMGUI_API void DrawLine(const Nz::Vector2f& a, const Nz::Vector2f& b, const Nz::Color& col, float thickness = 1.0f);
NAZARA_IMGUI_API void DrawRect(const Nz::Rectf& rect, const Nz::Color& color, float rounding = 0.0f, int rounding_corners = 0x0F, float thickness = 1.0f);
NAZARA_IMGUI_API void DrawRectFilled(const Nz::Rectf& rect, const Nz::Color& color, float rounding = 0.0f, int rounding_corners = 0x0F);
inline void EnsureContextOnThisThread() inline void EnsureContextOnThisThread()
{ {
auto* context = Nz::Imgui::GetCurrentContext(); auto* context = Nz::Imgui::GetCurrentContext();

View File

@@ -2,11 +2,11 @@
#include <NazaraImgui/NazaraImgui.hpp> #include <NazaraImgui/NazaraImgui.hpp>
#include <Nazara/Core/VertexStruct.hpp>
#include <Nazara/Renderer/CommandBufferBuilder.hpp> #include <Nazara/Renderer/CommandBufferBuilder.hpp>
#include <Nazara/Renderer/RenderDevice.hpp> #include <Nazara/Renderer/RenderDevice.hpp>
#include <Nazara/Renderer/RenderFrame.hpp> #include <Nazara/Renderer/RenderFrame.hpp>
#include <Nazara/Renderer/UploadPool.hpp> #include <Nazara/Renderer/UploadPool.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
#include <NZSL/Parser.hpp> #include <NZSL/Parser.hpp>
@@ -69,7 +69,7 @@ namespace Nz
m_drawCalls.clear(); m_drawCalls.clear();
ImDrawData* drawData = ImGui::GetDrawData(); ImDrawData* drawData = ImGui::GetDrawData();
if (drawData->CmdListsCount == 0) if (drawData == nullptr || drawData->CmdListsCount == 0)
return; return;
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
@@ -123,6 +123,8 @@ namespace Nz
m_drawCalls.push_back(std::move(drawCall)); m_drawCalls.push_back(std::move(drawCall));
} }
frame.PushForRelease(std::move(m_vertexBuffer));
frame.PushForRelease(std::move(m_indexBuffer));
// now that we have macro buffers, allocate them on gpu // now that we have macro buffers, allocate them on gpu
size_t size = vertices.size() * sizeof(Nz::VertexStruct_XYZ_Color_UV); size_t size = vertices.size() * sizeof(Nz::VertexStruct_XYZ_Color_UV);
@@ -191,7 +193,7 @@ namespace Nz
} }
} }
void ImguiDrawer::Reset(RenderResources& renderFrame) void ImguiDrawer::Reset(RenderResources& /*renderFrame*/)
{ {
m_drawCalls.clear(); m_drawCalls.clear();
} }
@@ -223,7 +225,7 @@ namespace Nz
textureBinding.setIndex = 1; textureBinding.setIndex = 1;
textureBinding.bindingIndex = 0; textureBinding.bindingIndex = 0;
textureBinding.shaderStageFlags = nzsl::ShaderStageType::Fragment; textureBinding.shaderStageFlags = nzsl::ShaderStageType::Fragment;
textureBinding.type = Nz::ShaderBindingType::Texture; textureBinding.type = Nz::ShaderBindingType::Sampler;
std::shared_ptr<Nz::RenderPipelineLayout> renderPipelineLayout = m_renderDevice.InstantiateRenderPipelineLayout(std::move(pipelineLayoutInfo)); std::shared_ptr<Nz::RenderPipelineLayout> renderPipelineLayout = m_renderDevice.InstantiateRenderPipelineLayout(std::move(pipelineLayoutInfo));

View File

@@ -7,7 +7,7 @@
namespace Nz namespace Nz
{ {
ImguiPipelinePass::ImguiPipelinePass(PassData& passData, std::string passName, const ParameterList& /*parameters*/) : ImguiPipelinePass::ImguiPipelinePass(PassData& /*passData*/, std::string passName, const ParameterList& /*parameters*/) :
FramePipelinePass({}) FramePipelinePass({})
, m_passName(std::move(passName)) , m_passName(std::move(passName))
{ {
@@ -21,10 +21,10 @@ namespace Nz
FramePass& ImguiPipelinePass::RegisterToFrameGraph(FrameGraph& frameGraph, const PassInputOuputs& inputOuputs) FramePass& ImguiPipelinePass::RegisterToFrameGraph(FrameGraph& frameGraph, const PassInputOuputs& inputOuputs)
{ {
if (inputOuputs.inputCount != 1) if (inputOuputs.inputAttachments.size() != 1)
throw std::runtime_error("one input expected"); throw std::runtime_error("one input expected");
if (inputOuputs.outputCount != 1) if (inputOuputs.outputAttachments.size() != 1)
throw std::runtime_error("one output expected"); throw std::runtime_error("one output expected");
FramePass& imguiPass = frameGraph.AddPass("Imgui pass"); FramePass& imguiPass = frameGraph.AddPass("Imgui pass");

View File

@@ -1,6 +1,8 @@
#include <NazaraImgui/NazaraImgui.hpp> #include <NazaraImgui/NazaraImgui.hpp>
#include <NazaraImgui/ImguiPipelinePass.hpp> #include <NazaraImgui/ImguiPipelinePass.hpp>
#include <NazaraImgui/ImguiDrawer.hpp> #include <NazaraImgui/ImguiDrawer.hpp>
#include <NazaraImgui/ImguiHandler.hpp>
#include <NazaraImgui/ImguiWidgets.hpp>
#include <Nazara/Core/DynLib.hpp> #include <Nazara/Core/DynLib.hpp>
#include <Nazara/Core/Log.hpp> #include <Nazara/Core/Log.hpp>
@@ -287,8 +289,13 @@ namespace Nz
int fb_height = static_cast<int>(io.DisplaySize.y * io.DisplayFramebufferScale.y); int fb_height = static_cast<int>(io.DisplaySize.y * io.DisplayFramebufferScale.y);
Nz::Recti renderRect(0, 0, fb_width, fb_height); Nz::Recti renderRect(0, 0, fb_width, fb_height);
Nz::CommandBufferBuilder::ClearValues clearValues[2] = {
{ .color = Nz::Color::Black() },
{ .depth = 1.f }
};
builder.BeginDebugRegion("ImGui", Nz::Color::Green()); builder.BeginDebugRegion("ImGui", Nz::Color::Green());
builder.BeginRenderPass(renderTarget->GetFramebuffer(frame.GetImageIndex()), renderTarget->GetRenderPass(), renderRect); builder.BeginRenderPass(renderTarget->GetFramebuffer(frame.GetImageIndex()), renderTarget->GetRenderPass(), renderRect, clearValues, 2);
m_imguiDrawer.Draw(builder); m_imguiDrawer.Draw(builder);
builder.EndRenderPass(); builder.EndRenderPass();
builder.EndDebugRegion(); builder.EndDebugRegion();
@@ -353,8 +360,8 @@ namespace Nz
texParams.height = height; texParams.height = height;
texParams.pixelFormat = Nz::PixelFormat::RGBA8; texParams.pixelFormat = Nz::PixelFormat::RGBA8;
texParams.type = Nz::ImageType::E2D; texParams.type = Nz::ImageType::E2D;
m_fontTexture = renderDevice->InstantiateTexture(texParams); m_fontTexture = renderDevice->InstantiateTexture(texParams, pixels, true);
m_fontTexture->Update(pixels, width, height); m_fontTexture->UpdateDebugName("FontTexture");
ImTextureID textureID = m_fontTexture.get(); ImTextureID textureID = m_fontTexture.get();
io.Fonts->TexID = textureID; io.Fonts->TexID = textureID;

View File

@@ -11,6 +11,7 @@ add_requires("nazaraengine", { alias = "nazara", debug = is_mode("debug") })
add_requires("imgui v1.87-docking", { alias = "imgui" }) add_requires("imgui v1.87-docking", { alias = "imgui" })
add_includedirs("include", "src") add_includedirs("include", "src")
set_exceptions("cxx")
set_languages("c89", "c++20") set_languages("c89", "c++20")
set_rundir("./bin/$(plat)_$(arch)_$(mode)") set_rundir("./bin/$(plat)_$(arch)_$(mode)")
set_targetdir("./bin/$(plat)_$(arch)_$(mode)") set_targetdir("./bin/$(plat)_$(arch)_$(mode)")
@@ -51,7 +52,8 @@ elseif is_mode("releasedbg") then
end end
target("NazaraImgui") target("NazaraImgui")
add_packages("nazara", "nzsl", "imgui", {public = true}) add_packages("nazara", {public = true, components = "graphics"})
add_packages("nzsl", "imgui", {public = true})
set_kind("$(kind)") set_kind("$(kind)")
set_group("Libraries") set_group("Libraries")
add_headerfiles("include/(NazaraImgui/**.hpp)") add_headerfiles("include/(NazaraImgui/**.hpp)")