dolphin/Source/Core/VideoBackends/OGL/GLInterface/AGL.cpp

110 lines
2.4 KiB
C++
Raw Normal View History

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