From 656e9011fd3b62335fe026d50a10f305d0494f50 Mon Sep 17 00:00:00 2001 From: Kevin Blackburn-Matzen Date: Thu, 3 Oct 2024 20:58:39 -0700 Subject: [PATCH 1/4] track XDisplay and propagate to bgfx --- .../Include/Platform/Unix/Babylon/Graphics/Platform.h | 4 +++- Core/Graphics/Source/DeviceImpl_Unix.cpp | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Core/Graphics/Include/Platform/Unix/Babylon/Graphics/Platform.h b/Core/Graphics/Include/Platform/Unix/Babylon/Graphics/Platform.h index 4ae32778a..d129c30ef 100644 --- a/Core/Graphics/Include/Platform/Unix/Babylon/Graphics/Platform.h +++ b/Core/Graphics/Include/Platform/Unix/Babylon/Graphics/Platform.h @@ -2,7 +2,9 @@ #include +#include + namespace Babylon::Graphics { - using WindowT = Window; + using WindowT = std::tuple; } diff --git a/Core/Graphics/Source/DeviceImpl_Unix.cpp b/Core/Graphics/Source/DeviceImpl_Unix.cpp index 80c9df92e..dd4f8b254 100644 --- a/Core/Graphics/Source/DeviceImpl_Unix.cpp +++ b/Core/Graphics/Source/DeviceImpl_Unix.cpp @@ -5,19 +5,20 @@ namespace Babylon::Graphics { void DeviceImpl::ConfigureBgfxPlatformData(bgfx::PlatformData& pd, WindowT window) { - pd.nwh = reinterpret_cast(window); + pd.nwh = reinterpret_cast(std::get<0>(window)); + pd.ndt = reinterpret_cast(std::get<1>(window)); } void DeviceImpl::ConfigureBgfxRenderType(bgfx::PlatformData& /*pd*/, bgfx::RendererType::Enum& /*renderType*/) { } - float DeviceImpl::GetDevicePixelRatio(WindowT) + float DeviceImpl::GetDevicePixelRatio(WindowT window) { // TODO: We should persist a Display object instead of opening a new display. // See https://github.com/BabylonJS/BabylonNative/issues/625 - auto display = XOpenDisplay(nullptr); + auto display = std::get<1>(window); auto screen = DefaultScreen(display); auto width = DisplayWidthMM(display, screen); @@ -36,4 +37,4 @@ namespace Babylon::Graphics return 1; } -} \ No newline at end of file +} From 50f21a007257e3b318866c794c0cd1cefd627804 Mon Sep 17 00:00:00 2001 From: Kevin Blackburn-Matzen Date: Thu, 3 Oct 2024 21:49:34 -0700 Subject: [PATCH 2/4] fix test --- Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp b/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp index ee30b66f0..5dfb2c7cb 100644 --- a/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp +++ b/Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp @@ -17,7 +17,7 @@ namespace Babylon::Plugins::Internal { void TestUtils::Exit(const Napi::CallbackInfo& info) { - auto window = (Window)m_implData->m_window; + auto window = (Window)std::get<0>(m_implData->m_window); const int32_t exitCode = info[0].As().Int32Value(); Plugins::TestUtils::errorCode = exitCode; Display* display = XOpenDisplay(NULL); @@ -38,7 +38,7 @@ namespace Babylon::Plugins::Internal { const auto title = info[0].As().Utf8Value(); Display* display = XOpenDisplay(NULL); - auto window = (Window)m_implData->m_window; + auto window = (Window)std::get<0>(m_implData->m_window); XStoreName(display, window, title.c_str()); } @@ -64,4 +64,4 @@ namespace Babylon::Plugins::TestUtils auto implData{std::make_shared(window)}; Internal::TestUtils::CreateInstance(env, implData); } -} \ No newline at end of file +} From 2400834d3e77907dbaf80df6219c8cfbd1585ffe Mon Sep 17 00:00:00 2001 From: Kevin Blackburn-Matzen Date: Thu, 3 Oct 2024 22:06:29 -0700 Subject: [PATCH 3/4] fix tests and playground --- Apps/Playground/X11/App.cpp | 3 ++- Apps/UnitTests/X11/App.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Apps/Playground/X11/App.cpp b/Apps/Playground/X11/App.cpp index af59771b3..859e25d2c 100644 --- a/Apps/Playground/X11/App.cpp +++ b/Apps/Playground/X11/App.cpp @@ -75,7 +75,8 @@ namespace Babylon::DebugTrace::SetTraceOutput([](const char* trace) { printf("%s\n", trace); fflush(stdout); }); Babylon::Graphics::Configuration graphicsConfig{}; - graphicsConfig.Window = window; + Display* display = XOpenDisplay(nullptr); + graphicsConfig.Window = std::make_tuple(window, display); graphicsConfig.Width = static_cast(width); graphicsConfig.Height = static_cast(height); graphicsConfig.MSAASamples = 4; diff --git a/Apps/UnitTests/X11/App.cpp b/Apps/UnitTests/X11/App.cpp index d3ad4fbd0..e6b367b01 100644 --- a/Apps/UnitTests/X11/App.cpp +++ b/Apps/UnitTests/X11/App.cpp @@ -46,7 +46,7 @@ int main() XStoreName(display, window, applicationName); Babylon::Graphics::Configuration config{}; - config.Window = window; + config.Window = std::make_tuple(window, display); config.Width = static_cast(width); config.Height = static_cast(height); @@ -54,4 +54,4 @@ int main() Babylon::DebugTrace::SetTraceOutput([](const char* trace) { printf("%s\n", trace); fflush(stdout); }); return RunTests(config); -} \ No newline at end of file +} From 7afb88c83e49b2aef7fe9576adeab85e8785a4ea Mon Sep 17 00:00:00 2001 From: Kevin Blackburn-Matzen Date: Thu, 3 Oct 2024 22:07:04 -0700 Subject: [PATCH 4/4] switch NULL --- Apps/Playground/X11/App.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Apps/Playground/X11/App.cpp b/Apps/Playground/X11/App.cpp index 859e25d2c..252d4a375 100644 --- a/Apps/Playground/X11/App.cpp +++ b/Apps/Playground/X11/App.cpp @@ -75,7 +75,7 @@ namespace Babylon::DebugTrace::SetTraceOutput([](const char* trace) { printf("%s\n", trace); fflush(stdout); }); Babylon::Graphics::Configuration graphicsConfig{}; - Display* display = XOpenDisplay(nullptr); + Display* display = XOpenDisplay(NULL); graphicsConfig.Window = std::make_tuple(window, display); graphicsConfig.Width = static_cast(width); graphicsConfig.Height = static_cast(height);