File: AGL.cpp

package info (click to toggle)
dolphin-emu 5.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 28,976 kB
  • ctags: 35,666
  • sloc: cpp: 213,139; java: 6,252; asm: 2,277; xml: 1,998; ansic: 1,514; python: 462; sh: 279; pascal: 247; makefile: 124; perl: 97
file content (106 lines) | stat: -rw-r--r-- 2,419 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2012 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "Common/GL/GLInterface/AGL.h"
#include "Common/Logging/Log.h"

void cInterfaceAGL::Swap()
{
	[cocoaCtx flushBuffer];
}

// Create rendering window.
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
bool cInterfaceAGL::Create(void *window_handle, bool core)
{
	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, core ? NSOpenGLProfileVersion3_2Core : NSOpenGLProfileVersionLegacy, 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];
}