Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

track XDisplay and propagate to bgfx #1438

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Apps/Playground/X11/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(NULL);
graphicsConfig.Window = std::make_tuple(window, display);
graphicsConfig.Width = static_cast<size_t>(width);
graphicsConfig.Height = static_cast<size_t>(height);
graphicsConfig.MSAASamples = 4;
Expand Down
4 changes: 2 additions & 2 deletions Apps/UnitTests/X11/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ int main()
XStoreName(display, window, applicationName);

Babylon::Graphics::Configuration config{};
config.Window = window;
config.Window = std::make_tuple(window, display);
config.Width = static_cast<size_t>(width);
config.Height = static_cast<size_t>(height);

Babylon::DebugTrace::EnableDebugTrace(true);
Babylon::DebugTrace::SetTraceOutput([](const char* trace) { printf("%s\n", trace); fflush(stdout); });

return RunTests(config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include <X11/Xlib.h>

#include <tuple>

namespace Babylon::Graphics
{
using WindowT = Window;
using WindowT = std::tuple<Window, Display*>;
}
9 changes: 5 additions & 4 deletions Core/Graphics/Source/DeviceImpl_Unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ namespace Babylon::Graphics
{
void DeviceImpl::ConfigureBgfxPlatformData(bgfx::PlatformData& pd, WindowT window)
{
pd.nwh = reinterpret_cast<void*>(window);
pd.nwh = reinterpret_cast<void*>(std::get<0>(window));
pd.ndt = reinterpret_cast<void*>(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);
Expand All @@ -36,4 +37,4 @@ namespace Babylon::Graphics

return 1;
}
}
}
6 changes: 3 additions & 3 deletions Plugins/TestUtils/Source/Unix/TestUtilsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Napi::Number>().Int32Value();
Plugins::TestUtils::errorCode = exitCode;
Display* display = XOpenDisplay(NULL);
Expand All @@ -38,7 +38,7 @@ namespace Babylon::Plugins::Internal
{
const auto title = info[0].As<Napi::String>().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());
}

Expand All @@ -64,4 +64,4 @@ namespace Babylon::Plugins::TestUtils
auto implData{std::make_shared<Internal::TestUtils::ImplData>(window)};
Internal::TestUtils::CreateInstance(env, implData);
}
}
}