Skip to content

Commit

Permalink
Null backend always available
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed May 6, 2024
1 parent 25f89c6 commit da24e13
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 53 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,18 @@ option(HELLOIMGUI_ADD_APP_WITH_INSTALL "Add cmake install() instructions with he
# Platform backends:
option(HELLOIMGUI_USE_GLFW3 "Use Glfw3 as a platform backend" OFF)
option(HELLOIMGUI_USE_SDL2 "Use Sdl2 as a platform backend" OFF)
option(HELLOIMGUI_USE_NULL "Null platform backend" OFF) # for testing and remote rendering
# Rendering backends
option(HELLOIMGUI_HAS_OPENGL3 "Use OpenGL3 as a rendering backend" OFF)
option(HELLOIMGUI_HAS_METAL "Use Metal as a rendering backend" OFF)
option(HELLOIMGUI_HAS_VULKAN "Use Vulkan as a rendering backend" OFF)
option(HELLOIMGUI_HAS_DIRECTX11 "Use DirectX11 as a rendering backend" OFF)
option(HELLOIMGUI_HAS_DIRECTX12 "Use DirectX12 as a rendering backend" OFF)
option(HELLOIMGUI_HAS_NULL "Null rendering backend" OFF) # for testing and remote rendering

# Null backend: useful for testing, or for remote rendering (will set both rendering and platform backends to null)
option(HELLOIMGUI_NULL_BACKEND "Use Null rendering/platform backend" OFF)
# Headless mode: by default, HelloImGui's cmake tooling will always check that there is at least one
# rendering backend and one platform backend that is not a "Null" backend.
# If you set HELLOIMGUI_HEADLESS, you can disable this check, and compile HelloImGui,
# using only the Null rendering/platform backends.
option(HELLOIMGUI_HEADLESS "Allow headless mode (will use Null rendering/platform backend)" OFF)
# </Backends> # do not remove this line (used by the script that generates the documentation)

#------------------------------------------------------------------------------
Expand Down
28 changes: 15 additions & 13 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,36 @@
"configurePresets": [
{
"name": "build_default_glfw",
"description": "Build with default settings (opengl3 and glfw). You need to create a build directory and run from it",
"description": "Build with default settings (opengl3 and glfw)",
"cacheVariables": {
"HELLOIMGUI_USE_GLFW3": "ON",
"HELLOIMGUI_HAS_OPENGL3": "ON"
}
},
{
"name": "build_default_sdl",
"description": "Build with default settings (opengl3 and sdl). You need to create a build directory and run from it",
"description": "Build with default settings (opengl3 and sdl)",
"cacheVariables": {
"HELLOIMGUI_USE_SDL2": "ON",
"HELLOIMGUI_HAS_OPENGL3": "ON"
}
},
{
"name": "build_all_backends",
"description": "Build with all platform and renderer backends. You need to create a build directory and run from it",
"description": "Build with all platform and renderer backends",
"cacheVariables": {
"HELLOIMGUI_USE_SDL2": "ON",
"HELLOIMGUI_USE_GLFW3": "ON",
"HELLOIMGUI_USE_NULL": "ON",
"HELLOIMGUI_HAS_OPENGL3": "ON",
"HELLOIMGUI_HAS_METAL": "ON",
"HELLOIMGUI_HAS_VULKAN": "ON",
"HELLOIMGUI_HAS_DIRECTX11": "ON",
"HELLOIMGUI_HAS_DIRECTX12": "ON",
"HELLOIMGUI_HAS_NULL": "ON"
"HELLOIMGUI_HAS_DIRECTX12": "ON"
}
},
{
"name": "build_vcpkg_default",
"description": "Build with vcpkg default settings (opengl3 + sdl and glfw). You need to create a build directory and run from it",
"description": "Build with vcpkg default settings (opengl3 + sdl and glfw)",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"HELLOIMGUI_USE_GLFW3": "ON",
Expand All @@ -45,8 +43,7 @@
},
{
"name": "build_use_vcpkg_opengl3",
"description": "Build with vcpkg default settings (opengl3 + sdl and glfw). Will build inside build_use_vcpkg_opengl3/",
"binaryDir": "${sourceDir}/build_use_vcpkg_opengl3",
"description": "Build with vcpkg default settings (opengl3 + sdl and glfw)",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"HELLOIMGUI_USE_GLFW3": "ON",
Expand All @@ -57,8 +54,7 @@
},
{
"name": "build_use_vcpkg_metal",
"description": "Build with vcpkg (for metal + sdl and glfw). Will build inside build_use_vcpkg_metal/",
"binaryDir": "${sourceDir}/build_use_vcpkg_metal",
"description": "Build with vcpkg (for metal + sdl and glfw)",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"HELLOIMGUI_USE_GLFW3": "ON",
Expand All @@ -69,15 +65,21 @@
},
{
"name": "build_use_vcpkg_vulkan",
"description": "Build with vcpkg (for vulkan + sdl and glfw). Will build inside build_use_vcpkg_vulkan/",
"binaryDir": "${sourceDir}/build_use_vcpkg_vulkan",
"description": "Build with vcpkg (for vulkan + sdl and glfw)",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"HELLOIMGUI_USE_GLFW3": "ON",
"HELLOIMGUI_USE_SDL2": "ON",
"HELLOIMGUI_HAS_VULKAN": "ON",
"HELLOIMGUI_USE_IMGUI_CMAKE_PACKAGE": "ON"
}
},
{
"name": "build_headless",
"description": "Build with headless backend. No GUI will be shown",
"cacheVariables": {
"HELLOIMGUI_HEADLESS": "ON"
}
}
]
}
30 changes: 18 additions & 12 deletions hello_imgui_cmake/hello_imgui_build_lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function(him_back_available_platform_backends out_var)
set(${out_var}
HELLOIMGUI_USE_SDL2
HELLOIMGUI_USE_GLFW3
HELLOIMGUI_USE_NULL
PARENT_SCOPE)
endfunction()

Expand All @@ -45,15 +44,10 @@ function(him_back_available_rendering_backends out_var)
HELLOIMGUI_HAS_VULKAN
HELLOIMGUI_HAS_DIRECTX11
HELLOIMGUI_HAS_DIRECTX12
HELLOIMGUI_HAS_NULL
PARENT_SCOPE)
endfunction()

function(him_back_parse_legacy_combinations)
if(HELLOIMGUI_NULL_BACKEND)
set(HELLOIMGUI_USE_NULL ON CACHE BOOL "" FORCE)
set(HELLOIMGUI_HAS_NULL ON CACHE BOOL "" FORCE)
endif()
if(HELLOIMGUI_USE_SDL_OPENGL3)
message(WARNING "
HELLOIMGUI_USE_SDL_OPENGL3 is deprecated,
Expand Down Expand Up @@ -163,6 +157,10 @@ function(him_back_check_if_no_rendering_backend_selected out_var) # will set out
endfunction()

function(him_back_check_if_no_backend_option_chosen out_var)
if (HELLOIMGUI_HEADLESS)
set(${out_var} OFF PARENT_SCOPE)
return()
endif()
him_back_check_if_no_platform_backend_selected(no_platform_selected)
him_back_check_if_no_rendering_backend_selected(no_rendering_selected)
if(no_platform_selected AND no_rendering_selected)
Expand All @@ -173,6 +171,10 @@ function(him_back_check_if_no_backend_option_chosen out_var)
endfunction()

function(him_back_check_at_least_one_rendering_one_platform_backend out_var)
if (HELLOIMGUI_HEADLESS)
set(${out_var} ON PARENT_SCOPE)
return()
endif()
him_back_check_if_no_platform_backend_selected(no_platform_selected)
him_back_check_if_no_rendering_backend_selected(no_rendering_selected)
if(no_platform_selected OR no_rendering_selected)
Expand All @@ -190,6 +192,11 @@ function(him_back_describe_active_rendering_backends out_description)
set(result "${result} ${backend}")
endif()
endforeach()

if (HELLOIMGUI_HEADLESS)
set(result "${result} null-headless")
endif()

set(${out_description} ${result} PARENT_SCOPE)
endfunction()

Expand All @@ -201,6 +208,11 @@ function(him_back_describe_active_platform_backends out_description)
set(result "${result} ${backend}")
endif()
endforeach()

if (HELLOIMGUI_HEADLESS)
set(result "${result} null-headless")
endif()

set(${out_description} ${result} PARENT_SCOPE)
endfunction()

Expand Down Expand Up @@ -1212,9 +1224,6 @@ function(him_main_add_hello_imgui_library)
if (HELLOIMGUI_USE_GLFW3)
him_use_glfw3_backend(${HELLOIMGUI_TARGET})
endif()
if (HELLOIMGUI_USE_NULL)
target_compile_definitions(${HELLOIMGUI_TARGET} PUBLIC HELLOIMGUI_USE_NULL)
endif()

if (HELLOIMGUI_HAS_OPENGL3)
him_has_opengl3(${HELLOIMGUI_TARGET})
Expand All @@ -1231,9 +1240,6 @@ function(him_main_add_hello_imgui_library)
if (HELLOIMGUI_HAS_DIRECTX12)
him_has_directx12(${HELLOIMGUI_TARGET})
endif()
if (HELLOIMGUI_HAS_NULL)
target_compile_definitions(${HELLOIMGUI_TARGET} PUBLIC HELLOIMGUI_HAS_NULL)
endif()

if (HELLOIMGUI_WITH_NETIMGUI)
him_with_netimgui()
Expand Down
6 changes: 1 addition & 5 deletions src/hello_imgui/internal/backend_impls/abstract_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,7 @@ void AbstractRunner::InitRenderBackendCallbacks()
}
else if (params.rendererBackendType == RendererBackendType::Null)
{
#ifdef HELLOIMGUI_USE_NULL
mRenderingBackendCallbacks = CreateBackendCallbacks_Null();
#else
IM_ASSERT(false && "Null backend is not available!");
#endif
mRenderingBackendCallbacks = CreateBackendCallbacks_Null();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#ifdef HELLOIMGUI_USE_NULL

#include "backend_window_helper.h"
#include "hello_imgui/internal/backend_impls/null_config.h"
Expand Down Expand Up @@ -51,5 +50,3 @@ namespace HelloImGui { namespace BackendApi

};
}} // namespace HelloImGui { namespace BackendApi

#endif // #ifdef HELLOIMGUI_USE_NULL
3 changes: 0 additions & 3 deletions src/hello_imgui/internal/backend_impls/rendering_null.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#ifdef HELLOIMGUI_HAS_NULL
#include "rendering_null.h"


Expand All @@ -25,5 +24,3 @@ namespace HelloImGui
}

}

#endif
3 changes: 0 additions & 3 deletions src/hello_imgui/internal/backend_impls/rendering_null.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#pragma once
#ifdef HELLOIMGUI_HAS_NULL

#include "hello_imgui/internal/backend_impls/rendering_callbacks.h"

namespace HelloImGui
{
RenderingCallbacksPtr CreateBackendCallbacks_Null();
}

#endif
10 changes: 3 additions & 7 deletions src/hello_imgui/internal/backend_impls/runner_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void ChooseBackendTypesIfSelectedAsFirstAvailable(RunnerParams* runnerParams)
runnerParams->platformBackendType = PlatformBackendType::Glfw;
#elif defined(HELLOIMGUI_USE_SDL2)
runnerParams->platformBackendType = PlatformBackendType::Sdl;
#elif defined(HELLOIMGUI_USE_NULL)
#else
runnerParams->platformBackendType = PlatformBackendType::Null;
#endif
}
Expand All @@ -33,7 +33,7 @@ void ChooseBackendTypesIfSelectedAsFirstAvailable(RunnerParams* runnerParams)
runnerParams->rendererBackendType = RendererBackendType::DirectX11;
#elif defined(HELLOIMGUI_HAS_DIRECTX12)
runnerParams->rendererBackendType = RendererBackendType::DirectX12;
#elif defined(HELLOIMGUI_HAS_NULL)
#else
runnerParams->rendererBackendType = RendererBackendType::Null;
#endif
}
Expand Down Expand Up @@ -75,11 +75,7 @@ std::unique_ptr<AbstractRunner> FactorRunner(RunnerParams& params)
}
else if (params.platformBackendType == PlatformBackendType::Null)
{
#ifdef HELLOIMGUI_USE_NULL
return std::make_unique<RunnerNull>(params);
#else
return nullptr;
#endif
return std::make_unique<RunnerNull>(params);
}
else
return nullptr;
Expand Down
3 changes: 0 additions & 3 deletions src/hello_imgui/internal/backend_impls/runner_null.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#ifdef HELLOIMGUI_USE_NULL
#include "hello_imgui/internal/backend_impls/abstract_runner.h"
#include "hello_imgui/internal/backend_impls/backend_window_helper/null_window_helper.h"
#include "hello_imgui/internal/backend_impls/null_config.h"
Expand Down Expand Up @@ -43,5 +42,3 @@ namespace HelloImGui
};

} // namespace HelloImGui

#endif // #ifdef HELLOIMGUI_USE_NULL

0 comments on commit da24e13

Please sign in to comment.