Skip to content

Commit

Permalink
Merge branch 'imgui_ws_merge'
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Apr 18, 2024
2 parents 382289e + 2fb2b44 commit de2f2b4
Show file tree
Hide file tree
Showing 13 changed files with 612 additions and 58 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,18 @@ option(HELLOIMGUI_USE_IMGUI_CMAKE_PACKAGE "Use imgui from cmake package (provide

#------------------------------------------------------------------------------
# Options / Remoting
# (Unsupported, and highly experimental. Requires specific forks of the remote rendering libraries)
#------------------------------------------------------------------------------
# Using https://github.com/sammyfreg/netImgui, you can use HelloImGui with remote rendering
# (Unsupported, and highly experimental. Requires a specific fork of netImgui)
# Using https://github.com/sammyfreg/netImgui
option(HELLOIMGUI_WITH_NETIMGUI "Use netImgui for remote rendering" OFF)
# Using https://github.com/ggerganov/imgui-ws
option(HELLOIMGUI_WITH_IMGUIWS "Use imgui-ws for remote rendering" OFF)

###############################################################################
# End of options
###############################################################################




###############################################################################
# HelloImGui Build Actions
###############################################################################
Expand Down
1 change: 1 addition & 0 deletions external/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ SDL
SDL2-*/
qtimgui/
netImgui/
imgui-ws/
20 changes: 19 additions & 1 deletion hello_imgui_cmake/hello_imgui_build_lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ endfunction()
###################################################################################################
function(him_with_netimgui)
target_compile_definitions(${HELLOIMGUI_TARGET} PUBLIC HELLOIMGUI_WITH_NETIMGUI)
target_compile_definitions(${HELLOIMGUI_TARGET} PUBLIC HELLOIMGUI_WITH_REMOTE_DISPLAY)

# message(STATUS "HelloImGui: downloading and building netImgui")
# include(FetchContent)
Expand All @@ -1047,7 +1048,6 @@ function(him_with_netimgui)
# )
# FetchContent_MakeAvailable(net_imgui)


# Add netImgui to the project
set(NETIMGUI_DIR ${HELLOIMGUI_BASEPATH}/external/netImgui CACHE STRING "" FORCE)
set(NETIMGUI_BUILD_IMGUI OFF CACHE BOOL "" FORCE)
Expand All @@ -1066,6 +1066,21 @@ function(him_with_netimgui)
endfunction()


###################################################################################################
# Remoting with https://github.com/ggerganov/imgui-ws: API = him_with_imguiws
###################################################################################################
function(him_with_imguiws)
target_compile_definitions(${HELLOIMGUI_TARGET} PUBLIC HELLOIMGUI_WITH_IMGUIWS)
target_compile_definitions(${HELLOIMGUI_TARGET} PUBLIC HELLOIMGUI_WITH_REMOTE_DISPLAY)

# Add imgui-ws to the project
set(IMGUIWS_DIR ${HELLOIMGUI_BASEPATH}/external/imgui-ws CACHE STRING "" FORCE)
add_subdirectory(${IMGUIWS_DIR} imgui-ws)
target_include_directories(imgui-ws PRIVATE $<BUILD_INTERFACE:${HELLOIMGUI_IMGUI_SOURCE_DIR}/..>)
target_link_libraries(${HELLOIMGUI_TARGET} PUBLIC imgui-ws)
target_compile_definitions(imgui PUBLIC "ImDrawIdx=unsigned int")
set(HELLOIMGUI_INSTALL OFF CACHE BOOL "" FORCE) # imgui-ws is not installable
endfunction()

###################################################################################################
# Miscellaneous: API = him_add_misc_options
Expand Down Expand Up @@ -1226,6 +1241,9 @@ function(him_main_add_hello_imgui_library)
if (HELLOIMGUI_WITH_NETIMGUI)
him_with_netimgui()
endif()
if (HELLOIMGUI_WITH_IMGUIWS)
him_with_imguiws()
endif()

him_add_apple_options()
him_add_linux_options()
Expand Down
6 changes: 4 additions & 2 deletions src/hello_imgui/impl/hello_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ std::string RendererBackendTypeToString(RendererBackendType rendererBackendType)
std::string GetBackendDescription()
{
const auto& params = GetRunnerParams();
#ifdef HELLOIMGUI_WITH_REMOTE_DISPLAY
if (params->remoteParams.enableRemoting)
return "Remote";
#endif
std::string platformBackend = PlatformBackendTypeToString(params->platformBackendType);
std::string rendererBackend = RendererBackendTypeToString(params->rendererBackendType);
return platformBackend + " - " + rendererBackend;
Expand All @@ -244,9 +246,9 @@ void ChangeWindowSize(const ScreenSize &windowSize)
gLastRunner->ChangeWindowSize(windowSize);
}

bool ShouldDisplayOnRemoteServer()
bool ShouldRemoteDisplay()
{
return gLastRunner->ShouldDisplayOnRemoteServer();
return gLastRunner->ShouldRemoteDisplay();
}


Expand Down
29 changes: 19 additions & 10 deletions src/hello_imgui/internal/backend_impls/abstract_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void setFinalAppWindowScreenshotRgbBuffer(const ImageBuffer& b);

// Encapsulated inside hello_imgui_font.cpp
bool _reloadAllDpiResponsiveFonts();
bool ShouldDisplayOnRemoteServer();
bool ShouldRemoteDisplay();


AbstractRunner::AbstractRunner(RunnerParams &params_)
Expand Down Expand Up @@ -360,6 +360,11 @@ float _DefaultOsFontRenderingScale()
fontSizeIncreaseFactor = (float) NSScreen.mainScreen.backingScaleFactor;
#endif

#ifdef HELLOIMGUI_WITH_REMOTE_DISPLAY
if (HelloImGui::GetRunnerParams()->remoteParams.enableRemoting)
fontSizeIncreaseFactor = 1.f;
#endif

return 1.0f / fontSizeIncreaseFactor;
}

Expand All @@ -381,10 +386,7 @@ void AbstractRunner::SetupDpiAwareParams()

if (params.dpiAwareParams.fontRenderingScale == 0.f)
{
if (params.remoteParams.enableRemoting)
params.dpiAwareParams.fontRenderingScale = 1.f;
else
params.dpiAwareParams.fontRenderingScale = _DefaultOsFontRenderingScale();
params.dpiAwareParams.fontRenderingScale = _DefaultOsFontRenderingScale();
}
ImGui::GetIO().FontGlobalScale = params.dpiAwareParams.fontRenderingScale;

Expand Down Expand Up @@ -433,7 +435,7 @@ void AbstractRunner::HandleDpiOnSecondFrame()
#endif

// High DPI handling on windows & linux
if (!ShouldDisplayOnRemoteServer())
if (!ShouldRemoteDisplay())
{
float dpiScale = params.dpiAwareParams.dpiWindowSizeFactor;
if ( dpiScale > 1.f)
Expand Down Expand Up @@ -854,7 +856,7 @@ void AbstractRunner::CreateFramesAndRender()
constexpr bool foldable_region = true;

// Will display on remote server if needed
mRemoteDisplayHandler.Heartbeat();
mRemoteDisplayHandler.Heartbeat_PreImGuiNewFrame();

if (CheckDpiAwareParamsChanges()) // Reload fonts if DPI scale changed
{
Expand Down Expand Up @@ -965,11 +967,13 @@ void AbstractRunner::CreateFramesAndRender()
}

// Transmit window size to remote server (if needed)
#ifdef HELLOIMGUI_WITH_REMOTE_DISPLAY
if ((mIdxFrame > 3) && params.remoteParams.transmitWindowSize)
{
auto windowSize = params.appWindowParams.windowGeometry.size;
mRemoteDisplayHandler.TransmitWindowSizeToDisplay(windowSize);
}
#endif
} // SCOPED_RELEASE_GIL_ON_MAIN_THREAD end

if(foldable_region) // Handle idling
Expand Down Expand Up @@ -1090,6 +1094,8 @@ void AbstractRunner::CreateFramesAndRender()
Impl_UpdateAndRenderAdditionalPlatformWindows();

Impl_SwapBuffers();

mRemoteDisplayHandler.Heartbeat_PostImGuiRender();
} // SCOPED_RELEASE_GIL_ON_MAIN_THREAD end

// AfterSwap is a user callback, so it should not be inside SCOPED_RELEASE_GIL_ON_MAIN_THREAD
Expand All @@ -1105,6 +1111,9 @@ void AbstractRunner::CreateFramesAndRender()
}
#endif

if (!mRemoteDisplayHandler.CanQuitApp())
params.appShallExit = false;

mIdxFrame += 1;
}

Expand All @@ -1117,7 +1126,7 @@ void AbstractRunner::IdleBySleeping()
return;
#endif

if (ShouldDisplayOnRemoteServer())
if (ShouldRemoteDisplay())
{
// if displaying remote, the FPS is limited on the server to a value between 30 and 60 fps
// We cannot idle too slow, other the GUI becomes really sluggish
Expand Down Expand Up @@ -1268,9 +1277,9 @@ std::string AbstractRunner::LoadUserPref(const std::string& userPrefName)
return HelloImGuiIniSettings::LoadUserPref(IniSettingsLocation(params), userPrefName);
}

bool AbstractRunner::ShouldDisplayOnRemoteServer()
bool AbstractRunner::ShouldRemoteDisplay()
{
return mRemoteDisplayHandler.ShouldDisplayOnRemoteServer();
return mRemoteDisplayHandler.ShouldRemoteDisplay();
}


Expand Down
2 changes: 1 addition & 1 deletion src/hello_imgui/internal/backend_impls/abstract_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AbstractRunner
void ChangeWindowSize(ScreenSize windowSize);

void LayoutSettings_SwitchLayout(const std::string& layoutName);
bool ShouldDisplayOnRemoteServer();
bool ShouldRemoteDisplay();


void SaveUserPref(const std::string& userPrefName, const std::string& userPrefContent);
Expand Down
Loading

0 comments on commit de2f2b4

Please sign in to comment.