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

Fixed creating MoltenVk surface with agnostic backends such as SDL2 #3158

Merged
merged 1 commit into from
Aug 15, 2023
Merged
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
25 changes: 20 additions & 5 deletions src/renderer_vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6832,17 +6832,32 @@ VK_DESTROY
if (NULL != vkCreateMacOSSurfaceMVK)
{
NSWindow* window = (NSWindow*)(m_nwh);
NSView* contentView = (NSView*)window.contentView;
CAMetalLayer* layer = [CAMetalLayer layer];
CAMetalLayer* layer = (CAMetalLayer*)(m_nwh);

if ([window isKindOfClass:[NSWindow class]])
{
NSView *contentView = (NSView *)window.contentView;
layer = [CAMetalLayer layer];

[contentView setWantsLayer : YES];
[contentView setLayer : layer];
}
else if ([layer isKindOfClass:[CAMetalLayer class]])
{
NSView *contentView = (NSView *)layer.delegate;
window = contentView.window;
}
else
{
BX_WARN(0, "Unable to create MoltenVk surface. Please set platform data window to an NSWindow or CAMetalLayer");
return result;
}

if (m_resolution.reset & BGFX_RESET_HIDPI)
{
layer.contentsScale = [window backingScaleFactor];
}

[contentView setWantsLayer : YES];
[contentView setLayer : layer];

VkMacOSSurfaceCreateInfoMVK sci;
sci.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
sci.pNext = NULL;
Expand Down