2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2012 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2014-02-10 18:54:46 +00:00
|
|
|
// Refer to the license.txt file included.
|
2012-12-17 21:01:52 +00:00
|
|
|
|
2014-11-01 14:33:02 +00:00
|
|
|
#include "VideoBackends/OGL/GLInterface/AGL.h"
|
2014-08-09 13:49:45 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/RenderBase.h"
|
|
|
|
#include "VideoCommon/VertexShaderManager.h"
|
|
|
|
#include "VideoCommon/VideoConfig.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
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
[cocoaCtx flushBuffer];
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create rendering window.
|
2014-02-17 04:51:41 +00:00
|
|
|
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
2015-09-17 15:48:25 +00:00
|
|
|
bool cInterfaceAGL::Create(void *window_handle, bool core)
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
2014-09-14 05:06:25 +00:00
|
|
|
cocoaWin = reinterpret_cast<NSView*>(window_handle);
|
2014-08-09 13:49:45 +00:00
|
|
|
NSSize size = [cocoaWin frame].size;
|
2013-03-31 18:36:42 +00:00
|
|
|
|
|
|
|
// Enable high-resolution display support.
|
2014-08-09 13:49:45 +00:00
|
|
|
[cocoaWin setWantsBestResolutionOpenGLSurface:YES];
|
2013-03-31 18:36:42 +00:00
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
NSWindow *window = [cocoaWin window];
|
2013-03-31 18:36:42 +00:00
|
|
|
|
|
|
|
float scale = [window backingScaleFactor];
|
2014-08-05 07:33:45 +00:00
|
|
|
size.width *= scale;
|
|
|
|
size.height *= scale;
|
2013-03-31 18:36:42 +00:00
|
|
|
|
2012-12-17 21:01:52 +00:00
|
|
|
// Control window size and picture scaling
|
2014-08-05 07:33:45 +00:00
|
|
|
s_backbuffer_width = size.width;
|
|
|
|
s_backbuffer_height = size.height;
|
2012-12-17 21:01:52 +00:00
|
|
|
|
2015-09-17 15:48:25 +00:00
|
|
|
NSOpenGLPixelFormatAttribute attr[] = { NSOpenGLPFADoubleBuffer, NSOpenGLPFAOpenGLProfile, NSOpenGLPFAAccelerated, core ? NSOpenGLProfileVersion3_2Core : 0u, 0u };
|
2012-12-17 21:01:52 +00:00
|
|
|
NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc]
|
|
|
|
initWithAttributes: attr];
|
2014-08-30 21:01:19 +00:00
|
|
|
if (fmt == nil)
|
|
|
|
{
|
2012-12-17 21:01:52 +00:00
|
|
|
ERROR_LOG(VIDEO, "failed to create pixel format");
|
2013-08-29 05:33:24 +00:00
|
|
|
return false;
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
|
|
|
|
2014-08-30 21:01:19 +00:00
|
|
|
cocoaCtx = [[NSOpenGLContext alloc] initWithFormat: fmt shareContext: nil];
|
2012-12-17 21:01:52 +00:00
|
|
|
[fmt release];
|
2014-08-30 21:01:19 +00:00
|
|
|
if (cocoaCtx == nil)
|
|
|
|
{
|
2012-12-17 21:01:52 +00:00
|
|
|
ERROR_LOG(VIDEO, "failed to create context");
|
2013-08-29 05:33:24 +00:00
|
|
|
return false;
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
|
|
|
|
2014-08-30 21:01:19 +00:00
|
|
|
if (cocoaWin == nil)
|
|
|
|
{
|
2012-12-17 21:01:52 +00:00
|
|
|
ERROR_LOG(VIDEO, "failed to create window");
|
2013-08-29 05:33:24 +00:00
|
|
|
return false;
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
[window makeFirstResponder:cocoaWin];
|
|
|
|
[cocoaCtx setView: cocoaWin];
|
2013-03-31 18:36:42 +00:00
|
|
|
[window makeKeyAndOrderFront: nil];
|
2012-12-17 21:01:52 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cInterfaceAGL::MakeCurrent()
|
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
[cocoaCtx makeCurrentContext];
|
2013-03-18 22:15:59 +00:00
|
|
|
return true;
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-11 01:32:07 +00:00
|
|
|
bool cInterfaceAGL::ClearCurrent()
|
|
|
|
{
|
2014-10-23 14:56:42 +00:00
|
|
|
[NSOpenGLContext clearCurrentContext];
|
2013-04-11 01:32:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-17 21:01:52 +00:00
|
|
|
// Close backend
|
|
|
|
void cInterfaceAGL::Shutdown()
|
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
[cocoaCtx clearDrawable];
|
|
|
|
[cocoaCtx release];
|
|
|
|
cocoaCtx = nil;
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 01:58:43 +00:00
|
|
|
void cInterfaceAGL::Update()
|
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
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;
|
|
|
|
|
2014-03-10 11:30:55 +00:00
|
|
|
if (s_backbuffer_width == size.width &&
|
|
|
|
s_backbuffer_height == size.height)
|
2013-03-18 01:58:43 +00:00
|
|
|
return;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-03-31 18:36:42 +00:00
|
|
|
s_backbuffer_width = size.width;
|
|
|
|
s_backbuffer_height = size.height;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
[cocoaCtx update];
|
2013-03-18 01:58:43 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 12:24:35 +00:00
|
|
|
void cInterfaceAGL::SwapInterval(int interval)
|
2014-01-27 12:11:03 +00:00
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
[cocoaCtx setValues:(GLint *)&interval forParameter:NSOpenGLCPSwapInterval];
|
2014-01-27 12:11:03 +00:00
|
|
|
}
|
2012-12-17 21:01:52 +00:00
|
|
|
|