The bgfx renderer - MadLadSquad/UImGuiRendererExamples GitHub Wiki
The bgfx renderer uses the bgfx library to do rendering operations in an API-agnostic manner.
Testing the bgfx renderer
Building
In your root project directory, clone bgfx.cmake with submodules:
user $ git clone https://github.com/bkaradzic/bgfx.cmake --recursive
Next, in your Config/cmake/UImGuiDemo.cmake
make sure your custom setup and compile steps look like this:
function(custom_setup_step)
add_subdirectory(bgfx.cmake/)
endfunction()
function(custom_compile_step)
if (EMSCRIPTEN)
target_link_libraries(UImGuiDemo bgfx)
elseif (WIN32)
target_link_libraries(UntitledImGuiFramework bgfx)
target_compile_options(UntitledImGuiFramework PRIVATE "/Zc:preprocessor")
else ()
target_link_libraries(UImGuiDemoLib bgfx)
endif ()
include_directories(bgfx.cmake/bgfx/include bgfx.cmake/bx/include bgfx.cmake/bimg/include)
endfunction()
In bgfx.cmake/CMakeLists.txt
make sure to explicitly disable BGFX_CONFIG_MULTITHREADED
:
option(BGFX_CONFIG_MULTITHREADED "Build bgfx with multithreaded configuration" OFF)
[!CAUTION] Leaving
BGFX_CONFIG_MULTITHREADED
will result in nothing being output to the screen as the example backend code is not written to be used in a multithreaded configuration
[!TIP] For faster compile times you can also disable
BGFX_BUILD_TOOLS
,BGFX_BUILD_EXAMPLES
andBGFX_INSTALL
Integrating the renderer
In Source/Instance.hpp
include the bgfx renderer:
#include <UImGuiRendererExamples/bgfx/bgfx.hpp>
And create an instance of the UImGuiRendererExamples::BGFXRenderer
class inside the instance.
After that, in Source/Instance.cpp
, make sure your constructor looks like this:
UImGuiDemo::Instance::Instance() noexcept
{
initInfo =
{
.titlebarComponents = { reinterpret_cast<UImGui::TitlebarComponent*>(&title) },
.windowComponents = { reinterpret_cast<UImGui::WindowComponent*>(&demoWindow) },
.customRenderer = &bgfxRenderer,
UIMGUI_INIT_INFO_DEFAULT_DIRS,
};
}
Integrating the custom texture
A custom texture renderer is also provided. To use it, include the following in Source/Instance.hpp
:
#include <UImGuiRendererExamples/bgfx/bgfx.hpp>
#include <UImGuiRendererExamples/bgfx/bgfx_texture.hpp>
Create an instance of UImGuiRendererExamples::BGFXTexture
as a member variable inside the UImGuiDemo::Instance
class and then pass the instance to the init info:
UImGuiDemo::Instance::Instance() noexcept
{
initInfo =
{
.titlebarComponents = { reinterpret_cast<UImGui::TitlebarComponent*>(&title) },
.windowComponents = { reinterpret_cast<UImGui::WindowComponent*>(&demoWindow) },
.customRenderer = &bgfxRenderer,
.customTexture = &bgfxTexture
UIMGUI_INIT_INFO_DEFAULT_DIRS,
};
}
Testing
The example bgfx renderer can run on any operating system that is supported by the framework. It can also be compiled with Emscripten for targeting WASM.