|
7 | 7 |
|
8 | 8 | #include <SDL.h> |
9 | 9 | #include <SDL_syswm.h> |
| 10 | +#include <SDL_vulkan.h> |
10 | 11 | #undef far |
11 | 12 | #undef near |
12 | 13 |
|
@@ -346,7 +347,41 @@ void CGameHost::GetVideoModes(Array<SysVideoMode>& displayModes) const |
346 | 347 | #endif |
347 | 348 | } |
348 | 349 |
|
349 | | -static void* Helper_GetWindowInfo(void* userData, RenderWindowInfo::Attribute attrib) |
| 350 | +struct HostRenderWindowInfoSDL : RenderWindowInfo |
| 351 | +{ |
| 352 | + void* GetWindowInfo(RenderWindowInfo::Attribute attrib, void* arg) const; |
| 353 | + void* CreateVulkanSurface(RenderWindowInfo::Attribute attrib, void* arg) const; |
| 354 | +}; |
| 355 | + |
| 356 | +void* HostRenderWindowInfoSDL::CreateVulkanSurface(RenderWindowInfo::Attribute attrib, void* arg) const |
| 357 | +{ |
| 358 | + SDL_Window* window = reinterpret_cast<SDL_Window*>(userData); |
| 359 | + if(attrib == RenderWindowInfo::SURFACE) |
| 360 | + { |
| 361 | + VkSurfaceKHR surface = nullptr; |
| 362 | + if(!SDL_Vulkan_CreateSurface( window, (VkInstance)arg, &surface )) |
| 363 | + { |
| 364 | + MsgError( "SDL_Vulkan_CreateSurface failed: %s\n", SDL_GetError() ); |
| 365 | + return nullptr; |
| 366 | + } |
| 367 | + return surface; |
| 368 | + } |
| 369 | + else if(attrib == RenderWindowInfo::EXTENSIONS) |
| 370 | + { |
| 371 | + uint32_t sdlCount = 0; |
| 372 | + static Array<const char*> sdlInstanceExtensions(PP_SL); |
| 373 | + |
| 374 | + SDL_Vulkan_GetInstanceExtensions( window, &sdlCount, nullptr ); |
| 375 | + sdlInstanceExtensions.setNum( sdlCount ); |
| 376 | + SDL_Vulkan_GetInstanceExtensions( window, &sdlCount, sdlInstanceExtensions.ptr() ); |
| 377 | + |
| 378 | + return &sdlInstanceExtensions; |
| 379 | + } |
| 380 | + ASSERT_FAIL("Unsupported attribute %d", attrib); |
| 381 | + return nullptr; |
| 382 | +} |
| 383 | + |
| 384 | +void* HostRenderWindowInfoSDL::GetWindowInfo(RenderWindowInfo::Attribute attrib, void* arg) const |
350 | 385 | { |
351 | 386 | // set window info |
352 | 387 | SDL_Window* window = reinterpret_cast<SDL_Window*>(userData); |
@@ -405,7 +440,7 @@ static void* Helper_GetWindowInfo(void* userData, RenderWindowInfo::Attribute at |
405 | 440 | } |
406 | 441 | #endif // PLAT_WIN |
407 | 442 | default: |
408 | | - ASSERT_FAIL("Not supported window type - %d", winfo.subsystem); |
| 443 | + ASSERT_FAIL("Unsupported window type %d or attribute %d", winfo.subsystem, attrib); |
409 | 444 | } |
410 | 445 |
|
411 | 446 | return nullptr; |
@@ -469,9 +504,15 @@ bool CGameHost::InitSystems() |
469 | 504 | else |
470 | 505 | rhiParams.screenFormat = FORMAT_RGB8; |
471 | 506 |
|
| 507 | + RenderWindowInfo sdlWinInfo; |
| 508 | + sdlWinInfo.getFunc = (RenderWindowInfo::GetterFunc)&HostRenderWindowInfoSDL::CreateVulkanSurface; |
| 509 | + sdlWinInfo.userData = m_window; |
| 510 | + sdlWinInfo.windowType = RHI_WINDOW_HANDLE_SDL; |
| 511 | + |
472 | 512 | RenderWindowInfo& winInfo = rhiParams.windowInfo; |
| 513 | + winInfo.parent = &sdlWinInfo; |
473 | 514 | winInfo.userData = m_window; |
474 | | - winInfo.get = Helper_GetWindowInfo; |
| 515 | + winInfo.getFunc = (RenderWindowInfo::GetterFunc)&HostRenderWindowInfoSDL::GetWindowInfo; |
475 | 516 |
|
476 | 517 | // needed for initialization |
477 | 518 | switch (winfo.subsystem) |
|
0 commit comments