Skip to content

Conversation

@octopoulos
Copy link

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.

@octopoulos octopoulos requested a review from bkaradzic as a code owner July 21, 2025 01:56
@bkaradzic
Copy link
Owner

bkaradzic commented Jul 21, 2025

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.

@octopoulos
Copy link
Author

octopoulos commented Jul 21, 2025

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.

@bkaradzic
Copy link
Owner

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.

@mcourteaux
Copy link
Contributor

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.

@bkaradzic
Copy link
Owner

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?

@mcourteaux
Copy link
Contributor

mcourteaux commented Jul 22, 2025

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();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants