dolphin/Source/Core/DolphinWX/GLInterface/AGL.cpp

115 lines
2.6 KiB
C++
Raw Normal View History

// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
2012-12-17 22:01:52 +01:00
#include <wx/panel.h>
#include "Core/ConfigManager.h"
#include "Core/Host.h"
#include "DolphinWX/GLInterface/GLInterface.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
{
[GLWin.cocoaCtx flushBuffer];
}
// Create rendering window.
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
2012-12-17 22:01:52 +01:00
bool cInterfaceAGL::Create(void *&window_handle)
{
int _tx, _ty, _twidth, _theight;
Host_GetRenderWindowSize(_tx, _ty, _twidth, _theight);
2013-03-31 20:36:42 +02:00
GLWin.cocoaWin = (NSView*)(((wxPanel*)window_handle)->GetHandle());
// Enable high-resolution display support.
[GLWin.cocoaWin setWantsBestResolutionOpenGLSurface:YES];
NSWindow *window = [GLWin.cocoaWin window];
float scale = [window backingScaleFactor];
_twidth *= scale;
_theight *= scale;
2012-12-17 22:01:52 +01:00
// Control window size and picture scaling
s_backbuffer_width = _twidth;
s_backbuffer_height = _theight;
2013-03-11 16:36:07 +01:00
NSOpenGLPixelFormatAttribute attr[] = { NSOpenGLPFADoubleBuffer, NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, NSOpenGLPFAAccelerated, 0 };
2012-12-17 22:01:52 +01:00
NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc]
initWithAttributes: attr];
if (fmt == nil) {
ERROR_LOG(VIDEO, "failed to create pixel format");
return false;
2012-12-17 22:01:52 +01:00
}
GLWin.cocoaCtx = [[NSOpenGLContext alloc]
initWithFormat: fmt shareContext: nil];
2012-12-17 22:01:52 +01:00
[fmt release];
if (GLWin.cocoaCtx == nil) {
ERROR_LOG(VIDEO, "failed to create context");
return false;
2012-12-17 22:01:52 +01:00
}
if (GLWin.cocoaWin == nil) {
ERROR_LOG(VIDEO, "failed to create window");
return false;
2012-12-17 22:01:52 +01:00
}
2013-03-31 20:36:42 +02:00
[window makeFirstResponder:GLWin.cocoaWin];
2013-03-14 03:34:52 +01:00
[GLWin.cocoaCtx setView: GLWin.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()
{
[GLWin.cocoaCtx makeCurrentContext];
return true;
2012-12-17 22:01:52 +01:00
}
bool cInterfaceAGL::ClearCurrent()
{
// not tested at all
//clearCurrentContext();
return true;
}
2012-12-17 22:01:52 +01:00
// Close backend
void cInterfaceAGL::Shutdown()
{
[GLWin.cocoaCtx clearDrawable];
[GLWin.cocoaCtx release];
GLWin.cocoaCtx = nil;
2012-12-17 22:01:52 +01:00
}
void cInterfaceAGL::Update()
{
2013-03-31 20:36:42 +02:00
NSWindow *window = [GLWin.cocoaWin window];
NSSize size = [GLWin.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;
2013-03-31 20:36:42 +02:00
s_backbuffer_width = size.width;
s_backbuffer_height = size.height;
[GLWin.cocoaCtx update];
}
2014-01-27 13:24:35 +01:00
void cInterfaceAGL::SwapInterval(int interval)
{
2014-01-27 13:40:28 +01:00
[GLWin.cocoaCtx setValues:(GLint *)&interval forParameter:NSOpenGLCPSwapInterval];
}
2012-12-17 22:01:52 +01:00