dolphin/Source/Core/Common/GL/GLInterface/AGL.mm

107 lines
2.5 KiB
Plaintext
Raw Normal View History

// Copyright 2012 Dolphin Emulator Project
2015-05-17 23:08:10 +00:00
// Licensed under GPLv2+
// Refer to the license.txt file included.
2012-12-17 21:01:52 +00:00
#include "Common/GL/GLInterface/AGL.h"
2015-09-18 17:43:34 +00:00
#include "Common/Logging/Log.h"
2012-12-17 21:01:52 +00:00
2012-12-26 06:34:09 +00:00
void cInterfaceAGL::Swap()
2012-12-17 21:01:52 +00:00
{
[cocoaCtx flushBuffer];
2012-12-17 21:01:52 +00:00
}
// Create rendering window.
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
bool cInterfaceAGL::Create(void* window_handle, bool core)
2012-12-17 21:01:52 +00:00
{
cocoaWin = reinterpret_cast<NSView*>(window_handle);
NSSize size = [cocoaWin frame].size;
// Enable high-resolution display support.
[cocoaWin setWantsBestResolutionOpenGLSurface:YES];
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;
NSOpenGLPixelFormatAttribute attr[] = {NSOpenGLPFADoubleBuffer, NSOpenGLPFAOpenGLProfile,
core ? NSOpenGLProfileVersion3_2Core :
NSOpenGLProfileVersionLegacy,
NSOpenGLPFAAccelerated, 0};
NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
if (fmt == nil)
{
ERROR_LOG(VIDEO, "failed to create pixel format");
return false;
}
cocoaCtx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
[fmt release];
if (cocoaCtx == nil)
{
ERROR_LOG(VIDEO, "failed to create context");
return false;
}
if (cocoaWin == nil)
{
ERROR_LOG(VIDEO, "failed to create window");
return false;
}
[window makeFirstResponder:cocoaWin];
[cocoaCtx setView:cocoaWin];
[window makeKeyAndOrderFront:nil];
return true;
2012-12-17 21:01:52 +00:00
}
bool cInterfaceAGL::MakeCurrent()
{
[cocoaCtx makeCurrentContext];
return true;
2012-12-17 21:01:52 +00:00
}
bool cInterfaceAGL::ClearCurrent()
{
[NSOpenGLContext clearCurrentContext];
return true;
}
2012-12-17 21:01:52 +00:00
// Close backend
void cInterfaceAGL::Shutdown()
{
[cocoaCtx clearDrawable];
[cocoaCtx release];
cocoaCtx = nil;
2012-12-17 21:01:52 +00:00
}
void cInterfaceAGL::Update()
{
NSWindow* window = [cocoaWin window];
NSSize size = [cocoaWin frame].size;
2013-03-31 18:36:42 +00:00
float scale = [window backingScaleFactor];
size.width *= scale;
size.height *= scale;
2013-03-31 18:36:42 +00:00
if (s_backbuffer_width == size.width && s_backbuffer_height == size.height)
return;
s_backbuffer_width = size.width;
s_backbuffer_height = size.height;
[cocoaCtx update];
}
2014-01-27 12:24:35 +00:00
void cInterfaceAGL::SwapInterval(int interval)
{
[cocoaCtx setValues:(GLint*)&interval forParameter:NSOpenGLCPSwapInterval];
}