dolphin/Source/Core/DolphinWX/GLInterface/AGL.cpp
Ryan Houdek 71681de81a [GLExtensions] Initial code drop for GLExtensions. This drops GLEW entirely from the codebase. This has been tested on Android and Linux+ATI. Of course untested on Windows and Apple. Also untested with Linux + EGL but should be fine there. There are most likely a couple of extensions I'm missing which would result in null pointer runs but not bad for the initial commit.
Conflicts:
	CMakeLists.txt
	Externals/GLew/glew.vcxproj
	Externals/GLew/glew.vcxproj.filters
	Source/Core/VideoBackends/OGL/CMakeLists.txt
	Source/Core/VideoBackends/OGL/GLFunctions.cpp
	Source/Core/VideoBackends/OGL/GLFunctions.h
	Source/Core/VideoBackends/OGL/GLUtil.h
	Source/Core/VideoBackends/OGL/Render.cpp
	Source/VSProps/Base.props
2014-01-17 15:50:51 +01:00

145 lines
3.7 KiB
C++

// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "VideoConfig.h"
#include "Host.h"
#include "RenderBase.h"
#include "ConfigManager.h"
#include <wx/panel.h>
#include "VertexShaderManager.h"
#include "../GLInterface.h"
#include "AGL.h"
// Copied from
// https://developer.apple.com/library/mac/documentation/graphicsimaging/conceptual/opengl-macprogguide/opengl_entrypts/opengl_entrypts.html
void* NSGLGetProcAddress (const char *name)
{
NSSymbol symbol;
char *symbolName;
symbolName = malloc (strlen (name) + 2); // 1
strcpy(symbolName + 1, name); // 2
symbolName[0] = '_'; // 3
symbol = NULL;
if (NSIsSymbolNameDefined (symbolName)) // 4
symbol = NSLookupAndBindSymbol (symbolName);
free (symbolName); // 5
return symbol ? NSAddressOfSymbol (symbol) : NULL; // 6
}
void cInterfaceAGL::Swap()
{
[GLWin.cocoaCtx flushBuffer];
}
void* cInterfaceAGL::GetProcAddress(std::string name)
{
return NSGLGetProcAddress(name.c_str());
}
// Create rendering window.
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
bool cInterfaceAGL::Create(void *&window_handle)
{
int _tx, _ty, _twidth, _theight;
Host_GetRenderWindowSize(_tx, _ty, _twidth, _theight);
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;
// Control window size and picture scaling
s_backbuffer_width = _twidth;
s_backbuffer_height = _theight;
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;
}
GLWin.cocoaCtx = [[NSOpenGLContext alloc]
initWithFormat: fmt shareContext: nil];
[fmt release];
if (GLWin.cocoaCtx == nil) {
ERROR_LOG(VIDEO, "failed to create context");
return false;
}
if (GLWin.cocoaWin == nil) {
ERROR_LOG(VIDEO, "failed to create window");
return false;
}
[window makeFirstResponder:GLWin.cocoaWin];
[GLWin.cocoaCtx setView: GLWin.cocoaWin];
[window makeKeyAndOrderFront: nil];
return true;
}
bool cInterfaceAGL::MakeCurrent()
{
[GLWin.cocoaCtx makeCurrentContext];
return true;
}
bool cInterfaceAGL::ClearCurrent()
{
// not tested at all
//clearCurrentContext();
return true;
}
// Close backend
void cInterfaceAGL::Shutdown()
{
[GLWin.cocoaCtx clearDrawable];
[GLWin.cocoaCtx release];
GLWin.cocoaCtx = nil;
}
void cInterfaceAGL::Update()
{
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;
s_backbuffer_width = size.width;
s_backbuffer_height = size.height;
[GLWin.cocoaCtx update];
}