-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Enable SDL3 in addition to SDL2 in examples #3445
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
base: master
Are you sure you want to change the base?
Conversation
|
It would be better to wait for various package managers to catch up with SDL3, and then just switch implementation to libsdl3... As-in your PR looks good, but I would rather have only one SDL implementation here. |
|
vcpkg has SDL3, emscripten has SDL3 support too. I think the main problem is that SDL2 is not going away anytime soon, a lot of people will be using SDL2, and a lot of people will start using SDL3 ... so it might take years for the majority of people to switch to SDL3. |
I'm not concern about people switching to SDL3. Rather all package managers have SDL3 available. Since SDL3 changes are mostly cosmetic it's not important to have both. And since SDL3 is future, we would just abandon SDL2 in favor of SDL3 once SDL3 is available everywhere. |
|
I'm concerned that the SURFACE_POINTER property is not used on Linux. In my application, I have this code: bgfx::PlatformData pd;
if (SDL_strcmp(video_driver, "wayland") == 0) {
pd.ndt = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, NULL);
pd.nwh = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, NULL);
pd.type = bgfx::NativeWindowHandleType::Wayland;
return;
} else if (SDL_strcmp(video_driver, "x11") == 0) {
pd.ndt = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL);
pd.nwh = (void *)SDL_GetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
pd.type = bgfx::NativeWindowHandleType::Default;
return;
}In general, I don't like how in all those example entries, all of that platform data is pulled apart into 3 functions: nativeWindowHandle, nativeSurfaceHandle, nativeWindowType. |
How it should be done? |
I like: void entry_set_platform_data(bgfx::PlatformData *pd) {
pd->nwh = ...;
pd->ndt = ...;
pd->type = ...;
}Personally, in SilverNode, I have exactly this for SDL3: void setup_bgfx_platform_data(bgfx::PlatformData &pd, SDL_Window *sdl_window)
{
pd.context = NULL;
pd.backBuffer = NULL;
pd.backBufferDS = NULL;
// Print SDL version fun
spdlog::info("SDL version [compiled]: {}", SDL_VERSION);
spdlog::info("SDL version [linked ]: {}", SDL_GetVersion());
const char *video_driver = SDL_GetCurrentVideoDriver();
spdlog::info("Window System: {}", video_driver);
SDL_PropertiesID props = SDL_GetWindowProperties(sdl_window);
#if defined(SDL_PLATFORM_UNIX)
if (SDL_strcmp(video_driver, "wayland") == 0) {
pd.ndt = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, NULL);
pd.nwh = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, NULL);
pd.type = bgfx::NativeWindowHandleType::Wayland;
return;
} else if (SDL_strcmp(video_driver, "x11") == 0) {
pd.ndt = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL);
pd.nwh = (void *)SDL_GetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
pd.type = bgfx::NativeWindowHandleType::Default;
return;
}
#endif
#if defined(SDL_PLATFORM_WIN32)
if (SDL_strcmp(video_driver, "windows") == 0) {
pd.ndt = NULL;
pd.nwh = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
return;
}
#endif
#if defined(SDL_PLATFORM_MACOS)
if (SDL_strcmp(video_driver, "cocoa") == 0) {
pd.ndt = NULL;
pd.nwh = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_COCOA_WINDOW_POINTER, NULL);
return;
}
#endif
spdlog::critical("Unknown Window System.");
std::abort();
} |
Enable SDL3 in addition to SDL2.
new file: entry_sdl3.cpp
new option: with-sdl3
So far, tested on windows and macOS.
I kept the syntax as close to the entry_sdl.cpp as possible, so that we can easily compare the files and see what changed.