summaryrefslogtreecommitdiffstats
path: root/src/osd/mac/oglview.mm
blob: 8ef0a94f880743c3792d965bfd7c4baf2c712f99 (plain) (blame)
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
// license:BSD-3-Clause
// copyright-holders:R. Belmont
//============================================================
//
//  oglview.mm - our OpenGL view
//
//  Mac OSD by R. Belmont
//
//============================================================

#import "oglview.h"

#define SUPPORT_RETINA_RESOLUTION 1

@interface MAMEGLView ()
{
}
@end

@implementation MAMEGLView

- (void) awakeFromNib
{
	NSOpenGLPixelFormatAttribute attrs[] =
	{
		NSOpenGLPFADoubleBuffer,
		NSOpenGLPFADepthSize, 24,
		0
	};

	NSOpenGLPixelFormat *pf = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
	NSOpenGLContext* context = [[NSOpenGLContext alloc] initWithFormat:pf shareContext:nil];

	[self setPixelFormat:pf];
	[self setOpenGLContext:context];

#if SUPPORT_RETINA_RESOLUTION
	// Opt-In to Retina resolution
	[self setWantsBestResolutionOpenGLSurface:YES];
#endif // SUPPORT_RETINA_RESOLUTION
}

- (void) prepareOpenGL
{
	[super prepareOpenGL];

	[self initGL];
}

- (void) windowWillClose:(NSNotification*)notification
{
}

- (void) initGL
{
	[[self openGLContext] makeCurrentContext];
	GLint swapInt = 1;
	[[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
}

- (void)reshape
{
	[super reshape];

	CGLLockContext([[self openGLContext] CGLContextObj]);

//  NSRect viewRectPoints = [self bounds];

//#if SUPPORT_RETINA_RESOLUTION
//    NSRect viewRectPixels = [self convertRectToBacking:viewRectPoints];
//#else
//    NSRect viewRectPixels = viewRectPoints;
//#endif

	CGLUnlockContext([[self openGLContext] CGLContextObj]);
}


- (void)renewGState
{
	[[self window] disableScreenUpdatesUntilFlush];
	[super renewGState];
}

- (void) drawRect: (NSRect) theRect
{
}

- (void) startDrawView
{
	[[self openGLContext] makeCurrentContext];

	CGLLockContext([[self openGLContext] CGLContextObj]);
}

- (void) completeDrawView
{
	CGLFlushDrawable([[self openGLContext] CGLContextObj]);
	CGLUnlockContext([[self openGLContext] CGLContextObj]);
}

- (void) dealloc
{
	[super dealloc];
}
@end