2014-02-10 18:54:46 +00:00
|
|
|
// Copyright 2014 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2012-12-17 21:01:52 +00:00
|
|
|
|
2013-03-15 01:40:08 +00:00
|
|
|
#include <wx/panel.h>
|
|
|
|
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "DolphinWX/GLInterface/GLInterface.h"
|
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
|
|
|
{
|
|
|
|
[GLWin.cocoaCtx flushBuffer];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create rendering window.
|
2014-02-17 04:51:41 +00:00
|
|
|
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
2012-12-17 21:01:52 +00:00
|
|
|
bool cInterfaceAGL::Create(void *&window_handle)
|
|
|
|
{
|
2014-08-05 07:33:45 +00:00
|
|
|
// FIXME: Get rid of the explicit use of wxPanel here. This shouldn't be necessary.
|
|
|
|
GLWin.cocoaWin = reinterpret_cast<NSView*>(((wxPanel*)window_handle)->GetHandle());
|
|
|
|
NSSize size = [GLWin.cocoaWin frame].size;
|
2013-03-31 18:36:42 +00:00
|
|
|
|
|
|
|
// Enable high-resolution display support.
|
|
|
|
[GLWin.cocoaWin setWantsBestResolutionOpenGLSurface:YES];
|
|
|
|
|
|
|
|
NSWindow *window = [GLWin.cocoaWin window];
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-03-11 15:36:07 +00:00
|
|
|
NSOpenGLPixelFormatAttribute attr[] = { NSOpenGLPFADoubleBuffer, NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, NSOpenGLPFAAccelerated, 0 };
|
2012-12-17 21:01:52 +00:00
|
|
|
NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc]
|
|
|
|
initWithAttributes: attr];
|
|
|
|
if (fmt == nil) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
GLWin.cocoaCtx = [[NSOpenGLContext alloc]
|
2013-02-07 09:34:29 +00:00
|
|
|
initWithFormat: fmt shareContext: nil];
|
2012-12-17 21:01:52 +00:00
|
|
|
[fmt release];
|
|
|
|
if (GLWin.cocoaCtx == nil) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (GLWin.cocoaWin == nil) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-03-31 18:36:42 +00:00
|
|
|
[window makeFirstResponder:GLWin.cocoaWin];
|
2013-03-14 02:34:52 +00:00
|
|
|
[GLWin.cocoaCtx setView: GLWin.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()
|
|
|
|
{
|
|
|
|
[GLWin.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()
|
|
|
|
{
|
|
|
|
// not tested at all
|
|
|
|
//clearCurrentContext();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-17 21:01:52 +00:00
|
|
|
// Close backend
|
|
|
|
void cInterfaceAGL::Shutdown()
|
|
|
|
{
|
|
|
|
[GLWin.cocoaCtx clearDrawable];
|
|
|
|
[GLWin.cocoaCtx release];
|
2013-03-18 22:15:59 +00:00
|
|
|
GLWin.cocoaCtx = nil;
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 01:58:43 +00:00
|
|
|
void cInterfaceAGL::Update()
|
|
|
|
{
|
2013-03-31 18:36:42 +00:00
|
|
|
NSWindow *window = [GLWin.cocoaWin window];
|
|
|
|
NSSize size = [GLWin.cocoaWin frame].size;
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-03-18 01:58:43 +00:00
|
|
|
[GLWin.cocoaCtx update];
|
|
|
|
}
|
|
|
|
|
2014-01-27 12:24:35 +00:00
|
|
|
void cInterfaceAGL::SwapInterval(int interval)
|
2014-01-27 12:11:03 +00:00
|
|
|
{
|
2014-01-27 12:40:28 +00:00
|
|
|
[GLWin.cocoaCtx setValues:(GLint *)&interval forParameter:NSOpenGLCPSwapInterval];
|
2014-01-27 12:11:03 +00:00
|
|
|
}
|
2012-12-17 21:01:52 +00:00
|
|
|
|