Skip to content

Commit

Permalink
Added Sample 'Disabled' to test program running with netImgui Disabled.
Browse files Browse the repository at this point in the history
Few comments / window size corrections
  • Loading branch information
sammyfreg committed Aug 23, 2020
1 parent a704b4e commit 11cae6f
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 26 deletions.
28 changes: 26 additions & 2 deletions Build/netImgui.sharpmake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public ProjectSample(string inName)
: base(true)
{
Name = inName;
SourceRootPath = @"[project.SharpmakeCsPath]\..\Code\Sample\" + inName;
SourceRootPath = @"[project.SharpmakeCsPath]\..\Code\Sample\" + Name;
AdditionalSourceRootPaths.Add(@"[project.SharpmakeCsPath]\..\Code\Sample\Common");
}

Expand All @@ -262,10 +262,33 @@ public ProjectSample(string inName)
}
}

[Sharpmake.Generate]
public class ProjectSample_Disabled : ProjectBase
{
public ProjectSample_Disabled()
: base(true)
{
Name = "SampleDisabled";
SourceRootPath = @"[project.SharpmakeCsPath]\..\Code\Sample\" + Name;
AdditionalSourceRootPaths.Add(@"[project.SharpmakeCsPath]\..\Code\Sample\Common");
}

[Configure()]
public new void ConfigureAll(Configuration conf, NetImguiTarget target)
{
base.ConfigureAll(conf, target);
conf.AddPublicDependency<ProjectImgui_Default>(target);
conf.AddPublicDependency<ProjectNetImgui_Disabled>(target);
conf.IncludePaths.Add(@"[project.SharpmakeCsPath]\..\Code\ThirdParty\" + SolutionAll.sDefaultImguiVersion);
conf.IncludePaths.Add(@"[project.SharpmakeCsPath]\..\Code\Client");
conf.Defines.Add("NETIMGUI_ENABLED=0");
}
}

[Sharpmake.Generate] public class ProjectSample_Basic : ProjectSample { public ProjectSample_Basic() : base("SampleBasic"){} }
[Sharpmake.Generate] public class ProjectSample_DualUI : ProjectSample { public ProjectSample_DualUI() : base("SampleDualUI"){} }
[Sharpmake.Generate] public class ProjectSample_Textures: ProjectSample { public ProjectSample_Textures() : base("SampleTextures"){} }
[Sharpmake.Generate] public class ProjectSample_NewFrame: ProjectSample { public ProjectSample_NewFrame() : base("SampleNewFrame"){} }
[Sharpmake.Generate] public class ProjectSample_NewFrame: ProjectSample { public ProjectSample_NewFrame() : base("SampleNewFrame"){} }

//=============================================================================================
// SOLUTIONS
Expand Down Expand Up @@ -308,6 +331,7 @@ public static void AddProjects(Configuration conf, NetImguiTarget target)
conf.AddProject<ProjectSample_NewFrame>(target, false, SolutionFolder);
conf.AddProject<ProjectSample_DualUI>(target, false, SolutionFolder);
conf.AddProject<ProjectSample_Textures>(target, false, SolutionFolder);
conf.AddProject<ProjectSample_Disabled>(target, false, SolutionFolder);
}
}

Expand Down
35 changes: 22 additions & 13 deletions Code/Client/Private/NetImgui_Api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,24 +558,29 @@ bool InputUpdateData(void)

namespace NetImgui {

#ifdef IMGUI_VERSION
static bool sIsDrawing = false;
#endif

bool Startup(void) { return false; }
void Shutdown(void) { }
bool Connect(const char*, const char*, uint32_t) { return false; }
bool Connect(ThreadFunctPtr, const char*, const char*, uint32_t) { return false; }
void Disconnect(void) { }
bool IsConnected(void) { return false; }
bool IsDrawingRemote(void) { return false; }
void SendDataTexture(uint64_t, void*, uint16_t, uint16_t, eTexFormat){ }
uint8_t GetTexture_BitsPerPixel(eTexFormat) { return 0; }
uint32_t GetTexture_BytePerLine(eTexFormat, uint32_t) { return 0; }
uint32_t GetTexture_BytePerImage(eTexFormat, uint32_t, uint32_t) { return 0; }
bool Startup(void) { return true; }
void Shutdown(void) { }
bool ConnectToApp(const char*, const char*, uint32_t, bool) { return false; }
bool ConnectToApp(ThreadFunctPtr, const char*, const char*, uint32_t, bool) { return false; }
bool ConnectFromApp(const char*, uint32_t, bool) { return false; }
bool ConnectFromApp(ThreadFunctPtr, const char*, uint32_t, bool) { return false; }
void Disconnect(void) { }
bool IsConnected(void) { return false; }
bool IsDrawingRemote(void) { return false; }
bool IsConnectionPending(void) { return false; }
void SendDataTexture(uint64_t, void*, uint16_t, uint16_t, eTexFormat) { }
uint8_t GetTexture_BitsPerPixel(eTexFormat) { return 0; }
uint32_t GetTexture_BytePerLine(eTexFormat, uint32_t) { return 0; }
uint32_t GetTexture_BytePerImage(eTexFormat, uint32_t, uint32_t) { return 0; }

//=================================================================================================
// If ImGui is enabled but not NetImgui, handle the BeginFrame/EndFrame normally
//=================================================================================================
bool NewFrame(void)
bool NewFrame(bool)
{
#ifdef IMGUI_VERSION
if( !sIsDrawing )
Expand All @@ -593,7 +598,7 @@ void EndFrame(void)
#ifdef IMGUI_VERSION
if( sIsDrawing )
{
ImGui::EndFrame();
ImGui::Render();
sIsDrawing = false;
}
#endif
Expand All @@ -610,7 +615,11 @@ const ImDrawData* GetDrawData(void)

bool IsDrawing(void)
{
#ifdef IMGUI_VERSION
return sIsDrawing;
#else
return false;
#endif
}

} // namespace NetImgui
Expand Down
2 changes: 2 additions & 0 deletions Code/Sample/SampleBasic/SampleBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const ImDrawData* Client_Draw()
// (2) Draw ImGui Content
//-----------------------------------------------------------------------------------------
ClientUtil_ImGuiContent_Common("SampleBasic", false);
ImGui::SetNextWindowPos(ImVec2(32,48), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(400,400), ImGuiCond_Once);
if( ImGui::Begin("Sample Basic", nullptr) )
{
ImGui::TextColored(ImVec4(0.1, 1, 0.1, 1), "Basic demonstration of netImgui code integration.");
Expand Down
89 changes: 89 additions & 0 deletions Code/Sample/SampleDisabled/SampleDisabled.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//=================================================================================================
// SAMPLE DISABLED
//-------------------------------------------------------------------------------------------------
// This sample demonstrate compiling your code with netImgui disabled but ImGui still active.
// It relies on the Define 'NETIMGUI_ENABLED' assigned in the project properties.
//=================================================================================================

#include <NetImgui_Api.h>
#include "..\Common\Sample.h"
#include "..\Common\WarningDisable.h"

namespace SampleClient
{
//=================================================================================================
//
//=================================================================================================
bool Client_Startup()
{
if( !NetImgui::Startup() )
return false;

// Can have more ImGui initialization here, like loading extra fonts.
// ...

return true;
}

//=================================================================================================
//
//=================================================================================================
void Client_Shutdown()
{
NetImgui::Shutdown();
}

//=================================================================================================
// Added a call to this function in 'ImGui_ImplDX11_CreateFontsTexture()', allowing us to
// forward the Font Texture information to netImgui.
//=================================================================================================
void Client_AddFontTexture(uint64_t texId, void* pData, uint16_t width, uint16_t height)
{
NetImgui::SendDataTexture(texId, pData, width, height, NetImgui::eTexFormat::kTexFmtRGBA8 );
}

//=================================================================================================
// Function used by the sample, to draw all ImGui Content
//=================================================================================================
const ImDrawData* Client_Draw()
{
//---------------------------------------------------------------------------------------------
// (1) Start a new Frame
//---------------------------------------------------------------------------------------------
NetImgui::NewFrame();

//-----------------------------------------------------------------------------------------
// (2) Draw ImGui Content
//-----------------------------------------------------------------------------------------
ClientUtil_ImGuiContent_Common("SampleDisabled", false);
ImGui::SetNextWindowPos(ImVec2(32,48), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(400,400), ImGuiCond_Once);
if( ImGui::Begin("Sample Basic", nullptr) )
{
ImGui::TextColored(ImVec4(0.1, 1, 0.1, 1), "Compiling with netImgui Disabled.");
ImGui::TextWrapped( "This shows being able to continue using ImGui normally, while netImgui code has been disabled. "
"No connection with the remote netImgui will be possible since the client code is entirely ifdef out "
"and the netImgui client API left with shell content calling Dear Imgui directly.");
ImGui::NewLine();
ImGui::TextColored(ImVec4(0.1, 1, 0.1, 1), "Where are we drawing: ");
ImGui::SameLine();
ImGui::TextUnformatted(NetImgui::IsDrawingRemote() ? "Remote Draw" : "Local Draw");
ImGui::NewLine();
ImGui::TextColored(ImVec4(0.1, 1, 0.1, 1), "Filler content");
ImGui::TextWrapped("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
}
ImGui::End();

//---------------------------------------------------------------------------------------------
// (3) Finish the frame, preparing the drawing data and...
// (3a) Send the data to the netImGui server when connected
//---------------------------------------------------------------------------------------------
NetImgui::EndFrame();

//---------------------------------------------------------------------------------------------
// (4) Forward to drawing data our local renderer when not remotely drawing
//---------------------------------------------------------------------------------------------
return !NetImgui::IsConnected() ? NetImgui::GetDrawData() : nullptr;
}

} // namespace SampleClient
3 changes: 2 additions & 1 deletion Code/Sample/SampleDualUI/SampleDualUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ const ImDrawData* Client_Draw()
// not planning to keep drawing in local windows while connected, or you can manage this
// yourself using your own new context.
ClientUtil_ImGuiContent_Common("SampleDualUI", true);

ImGui::SetNextWindowPos(ImVec2(32,48), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(400,400), ImGuiCond_Once);
if (ImGui::Begin("SampleDualUI", nullptr))
{
Client_Draw_MainContent();
Expand Down
16 changes: 9 additions & 7 deletions Code/Sample/SampleNewFrame/SampleNewFrame.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//=================================================================================================
// SAMPLE DUAL UI
// SAMPLE NEW FRAME
//-------------------------------------------------------------------------------------------------
// Example of supporting 2 differents ImGui display at the same time. One on the remote server
// and the second in the local client.
// Example of handling frame skipping. When connected with remote netImgui Server, we don't need
// to refresh the ImGui content every frame. If you program can handle skipping drawing, this
// allow to save CPU cycles when no refresh is expected.
//=================================================================================================

#include <NetImgui_Api.h>
Expand Down Expand Up @@ -58,7 +59,8 @@ void Client_Draw_Content()
bool bModeChanged(false);

ClientUtil_ImGuiContent_Common("SampleNewFrame", false);

ImGui::SetNextWindowPos(ImVec2(32,48), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(400,400), ImGuiCond_Once);
if (ImGui::Begin("Sample NewFrame", nullptr))
{
ImGui::TextColored(ImVec4(0.1, 1, 0.1, 1), "Demonstration of frame skip handling.");
Expand Down Expand Up @@ -130,9 +132,9 @@ const ImDrawData* Client_Draw_ModeOnDemand()
//---------------------------------------------------------------------------------------------
// (1) Start a new Frame
// When 'NewFrame' returns false, we should skip drawing this frame
// Note 1 : Key point is using 'true' in 'NewFrame()', letting system know to skip empty frames
// Note 2 : Frame skipping only happens when remote drawing
// Note 3 : Instead of relying on 'NewFrame()' return value of 'NewFrame', can use 'IsDrawing()'
// Note 1 : Key point is using the 'NewFrame()' return value to decide when to skip drawing
// Note 2 : Instead of relying on 'NewFrame()' return value, 'IsDrawing()' can be queried
// Note 3 : Frame skipping only happens when remote drawing
//---------------------------------------------------------------------------------------------
if (NetImgui::NewFrame(true))
{
Expand Down
9 changes: 6 additions & 3 deletions Code/Sample/SampleTextures/SampleTextures.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//=================================================================================================
// SAMPLE DUAL UI
// SAMPLE TEXTURES
//-------------------------------------------------------------------------------------------------
// Example of supporting 2 differents ImGui display at the same time. One on the remote server
// and the second in the local client.
// Example of using various textures in the ImGui context, after making netImgui aware of them.
// We need to always provide the Font texture (this sample calls Client_AddFontTexture to do that)
// but it also apply to any other textures we might want to display.
//=================================================================================================

#include <NetImgui_Api.h>
Expand Down Expand Up @@ -122,6 +123,8 @@ const ImDrawData* Client_Draw()
// (2) Draw ImGui Content
//-----------------------------------------------------------------------------------------
ClientUtil_ImGuiContent_Common("SampleTextures", false);
ImGui::SetNextWindowPos(ImVec2(32, 48), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiCond_Once);
if (ImGui::Begin("Sample Textures", nullptr))
{
const ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
Expand Down

0 comments on commit 11cae6f

Please sign in to comment.