summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/OGL/GLInterface/AGL.cpp
diff options
context:
space:
mode:
authorJules Blok <jules.blok@gmail.com>2015-06-10 00:00:12 +0200
committerJules Blok <jules.blok@gmail.com>2015-06-10 00:00:12 +0200
commit7dfced21a2e5aac7195e0e1ad76468e30306766b (patch)
treebd671b639d3d911460b767caabad8fc8a759a6bf /Source/Core/VideoBackends/OGL/GLInterface/AGL.cpp
parentc25be031fc1031d795157d8344b87b7841145197 (diff)
parent7b0a65e295c784f9d573f2ef52d4e2a7b9bb2889 (diff)
Merge branch 'master' into stable
Diffstat (limited to 'Source/Core/VideoBackends/OGL/GLInterface/AGL.cpp')
-rw-r--r--Source/Core/VideoBackends/OGL/GLInterface/AGL.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/Source/Core/VideoBackends/OGL/GLInterface/AGL.cpp b/Source/Core/VideoBackends/OGL/GLInterface/AGL.cpp
new file mode 100644
index 0000000000..924fdea821
--- /dev/null
+++ b/Source/Core/VideoBackends/OGL/GLInterface/AGL.cpp
@@ -0,0 +1,109 @@
+// Copyright 2012 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#include "VideoBackends/OGL/GLInterface/AGL.h"
+
+#include "VideoCommon/RenderBase.h"
+#include "VideoCommon/VertexShaderManager.h"
+#include "VideoCommon/VideoConfig.h"
+
+void cInterfaceAGL::Swap()
+{
+ [cocoaCtx flushBuffer];
+}
+
+// Create rendering window.
+// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
+bool cInterfaceAGL::Create(void *window_handle)
+{
+ 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, NSOpenGLProfileVersion3_2Core, 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;
+}
+
+bool cInterfaceAGL::MakeCurrent()
+{
+ [cocoaCtx makeCurrentContext];
+ return true;
+}
+
+bool cInterfaceAGL::ClearCurrent()
+{
+ [NSOpenGLContext clearCurrentContext];
+ return true;
+}
+
+// Close backend
+void cInterfaceAGL::Shutdown()
+{
+ [cocoaCtx clearDrawable];
+ [cocoaCtx release];
+ cocoaCtx = nil;
+}
+
+void cInterfaceAGL::Update()
+{
+ NSWindow *window = [cocoaWin window];
+ NSSize size = [cocoaWin frame].size;
+
+ float scale = [window backingScaleFactor];
+ size.width *= scale;
+ 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)
+{
+ [cocoaCtx setValues:(GLint *)&interval forParameter:NSOpenGLCPSwapInterval];
+}
+