mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +02:00
metal: implement vsync toggle on macOS
This commit is contained in:
@@ -49,6 +49,12 @@ std::string checkDropEvents();
|
|||||||
**/
|
**/
|
||||||
void requestAttention(bool continuous);
|
void requestAttention(bool continuous);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether vsync is enabled for the given CAMetalLayer
|
||||||
|
**/
|
||||||
|
void setMetalLayerVSync(void *metallayer, bool vsync);
|
||||||
|
bool getMetalLayerVSync(void *metallayer);
|
||||||
|
|
||||||
} // macos
|
} // macos
|
||||||
} // love
|
} // love
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import <QuartzCore/CAMetalLayer.h>
|
||||||
|
|
||||||
#ifdef LOVE_MACOSX_SDL_DIRECT_INCLUDE
|
#ifdef LOVE_MACOSX_SDL_DIRECT_INCLUDE
|
||||||
# include <SDL.h>
|
# include <SDL.h>
|
||||||
@@ -85,6 +86,32 @@ void requestAttention(bool continuous)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setMetalLayerVSync(void *metallayer, bool vsync)
|
||||||
|
{
|
||||||
|
@autoreleasepool
|
||||||
|
{
|
||||||
|
if (@available(macOS 10.13, *))
|
||||||
|
{
|
||||||
|
CAMetalLayer *layer = (__bridge CAMetalLayer *) metallayer;
|
||||||
|
layer.displaySyncEnabled = vsync;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getMetalLayerVSync(void *metallayer)
|
||||||
|
{
|
||||||
|
@autoreleasepool
|
||||||
|
{
|
||||||
|
if (@available(macOS 10.13, *))
|
||||||
|
{
|
||||||
|
CAMetalLayer *layer = (__bridge CAMetalLayer *) metallayer;
|
||||||
|
return layer.displaySyncEnabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // osx
|
} // osx
|
||||||
} // love
|
} // love
|
||||||
|
|
||||||
|
|||||||
@@ -1070,20 +1070,43 @@ love::image::ImageData *Window::getIcon()
|
|||||||
|
|
||||||
void Window::setVSync(int vsync)
|
void Window::setVSync(int vsync)
|
||||||
{
|
{
|
||||||
if (glcontext == nullptr)
|
if (glcontext != nullptr)
|
||||||
return;
|
{
|
||||||
|
SDL_GL_SetSwapInterval(vsync);
|
||||||
|
|
||||||
SDL_GL_SetSwapInterval(vsync);
|
// Check if adaptive vsync was requested but not supported, and fall
|
||||||
|
// back to regular vsync if so.
|
||||||
|
if (vsync == -1 && SDL_GL_GetSwapInterval() != -1)
|
||||||
|
SDL_GL_SetSwapInterval(1);
|
||||||
|
}
|
||||||
|
|
||||||
// Check if adaptive vsync was requested but not supported, and fall back
|
#if defined(LOVE_GRAPHICS_METAL) && defined(LOVE_MACOS)
|
||||||
// to regular vsync if so.
|
if (metalView != nullptr)
|
||||||
if (vsync == -1 && SDL_GL_GetSwapInterval() != -1)
|
{
|
||||||
SDL_GL_SetSwapInterval(1);
|
void *metallayer = SDL_Metal_GetLayer(metalView);
|
||||||
|
love::macos::setMetalLayerVSync(metallayer, vsync != 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int Window::getVSync() const
|
int Window::getVSync() const
|
||||||
{
|
{
|
||||||
return glcontext != nullptr ? SDL_GL_GetSwapInterval() : 0;
|
if (glcontext != nullptr)
|
||||||
|
return SDL_GL_GetSwapInterval();
|
||||||
|
|
||||||
|
#if defined(LOVE_GRAPHICS_METAL)
|
||||||
|
if (metalView != nullptr)
|
||||||
|
{
|
||||||
|
#ifdef LOVE_MACOS
|
||||||
|
void *metallayer = SDL_Metal_GetLayer(metalView);
|
||||||
|
return love::macos::getMetalLayerVSync(metallayer) ? 1 : 0;
|
||||||
|
#else
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setDisplaySleepEnabled(bool enable)
|
void Window::setDisplaySleepEnabled(bool enable)
|
||||||
|
|||||||
Reference in New Issue
Block a user