mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 16:19:28 +01:00
AGL: refactor some functions
This commit is contained in:
parent
5298328cb1
commit
4770e66811
@ -5,6 +5,45 @@
|
|||||||
#include "Common/GL/GLInterface/AGL.h"
|
#include "Common/GL/GLInterface/AGL.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
|
|
||||||
|
static bool UpdateCachedDimensions(NSView* view, u32* width, u32* height)
|
||||||
|
{
|
||||||
|
NSWindow* window = [view window];
|
||||||
|
NSSize size = [view frame].size;
|
||||||
|
|
||||||
|
float scale = [window backingScaleFactor];
|
||||||
|
size.width *= scale;
|
||||||
|
size.height *= scale;
|
||||||
|
|
||||||
|
if (*width == size.width && *height == size.height)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*width = size.width;
|
||||||
|
*height = size.height;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool AttachContextToView(NSOpenGLContext* context, NSView* view, u32* width, u32* height)
|
||||||
|
{
|
||||||
|
// Enable high-resolution display support.
|
||||||
|
[view setWantsBestResolutionOpenGLSurface:YES];
|
||||||
|
|
||||||
|
NSWindow* window = [view window];
|
||||||
|
if (window == nil)
|
||||||
|
{
|
||||||
|
ERROR_LOG(VIDEO, "failed to get NSWindow");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)UpdateCachedDimensions(view, width, height);
|
||||||
|
|
||||||
|
[window makeFirstResponder:view];
|
||||||
|
[context setView:view];
|
||||||
|
[window makeKeyAndOrderFront:nil];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void cInterfaceAGL::Swap()
|
void cInterfaceAGL::Swap()
|
||||||
{
|
{
|
||||||
[cocoaCtx flushBuffer];
|
[cocoaCtx flushBuffer];
|
||||||
@ -33,36 +72,11 @@ bool cInterfaceAGL::Create(void* window_handle, bool core)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window_handle)
|
if (!window_handle)
|
||||||
{
|
return true;
|
||||||
cocoaWin = reinterpret_cast<NSView*>(window_handle);
|
|
||||||
NSSize size = [cocoaWin frame].size;
|
|
||||||
|
|
||||||
// Enable high-resolution display support.
|
cocoaWin = static_cast<NSView*>(window_handle);
|
||||||
[cocoaWin setWantsBestResolutionOpenGLSurface:YES];
|
return AttachContextToView(cocoaCtx, cocoaWin, &s_backbuffer_width, &s_backbuffer_height);
|
||||||
|
|
||||||
NSWindow* window = [cocoaWin window];
|
|
||||||
|
|
||||||
float scale = [window backingScaleFactor];
|
|
||||||
size.width *= scale;
|
|
||||||
size.height *= scale;
|
|
||||||
|
|
||||||
// Control window size and picture scaling
|
|
||||||
s_backbuffer_width = size.width;
|
|
||||||
s_backbuffer_height = size.height;
|
|
||||||
|
|
||||||
if (cocoaWin == nil)
|
|
||||||
{
|
|
||||||
ERROR_LOG(VIDEO, "failed to create window");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
[window makeFirstResponder:cocoaWin];
|
|
||||||
[cocoaCtx setView:cocoaWin];
|
|
||||||
[window makeKeyAndOrderFront:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cInterfaceAGL::MakeCurrent()
|
bool cInterfaceAGL::MakeCurrent()
|
||||||
@ -87,23 +101,11 @@ void cInterfaceAGL::Shutdown()
|
|||||||
|
|
||||||
void cInterfaceAGL::Update()
|
void cInterfaceAGL::Update()
|
||||||
{
|
{
|
||||||
if (cocoaWin)
|
if (!cocoaWin)
|
||||||
{
|
return;
|
||||||
NSWindow* window = [cocoaWin window];
|
|
||||||
NSSize size = [cocoaWin frame].size;
|
|
||||||
|
|
||||||
float scale = [window backingScaleFactor];
|
if (UpdateCachedDimensions(cocoaWin, &s_backbuffer_width, &s_backbuffer_height))
|
||||||
size.width *= scale;
|
[cocoaCtx update];
|
||||||
size.height *= scale;
|
|
||||||
|
|
||||||
if (s_backbuffer_width == size.width && s_backbuffer_height == size.height)
|
|
||||||
return;
|
|
||||||
|
|
||||||
s_backbuffer_width = size.width;
|
|
||||||
s_backbuffer_height = size.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
[cocoaCtx update];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cInterfaceAGL::SwapInterval(int interval)
|
void cInterfaceAGL::SwapInterval(int interval)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user