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
107
108
109
110
111
|
/*
* Copyright (C) 2021- Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#import "OSXGLView.h"
#include "ServiceBroker.h"
#include "application/AppInboundProtocol.h"
#include "application/AppParamParser.h"
#include "application/Application.h"
#include "messaging/ApplicationMessenger.h"
#include "settings/AdvancedSettings.h"
#include "settings/SettingsComponent.h"
#include "utils/log.h"
#include "system_gl.h"
@implementation OSXGLView
{
NSOpenGLContext* m_glcontext;
NSOpenGLPixelFormat* m_pixFmt;
NSTrackingArea* m_trackingArea;
BOOL pause;
}
- (id)initWithFrame:(NSRect)frameRect
{
NSOpenGLPixelFormatAttribute wattrs[] = {
NSOpenGLPFANoRecovery, NSOpenGLPFAAccelerated,
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)32,
NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)8,
NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
NSOpenGLPFADoubleBuffer, (NSOpenGLPixelFormatAttribute)0};
self = [super initWithFrame:frameRect];
if (self)
{
m_pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:wattrs];
m_glcontext = [[NSOpenGLContext alloc] initWithFormat:m_pixFmt shareContext:nil];
}
[self updateTrackingAreas];
GLint swapInterval = 1;
[m_glcontext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
[m_glcontext makeCurrentContext];
return self;
}
- (void)dealloc
{
[NSOpenGLContext clearCurrentContext];
[m_glcontext clearDrawable];
}
- (void)drawRect:(NSRect)rect
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[m_glcontext setView:self];
// clear screen on first render
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0, 0, 0, 0);
[m_glcontext update];
});
}
- (void)updateTrackingAreas
{
if (m_trackingArea != nil)
{
[self removeTrackingArea:m_trackingArea];
}
const int opts =
(NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveAlways);
m_trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
options:opts
owner:self
userInfo:nil];
[self addTrackingArea:m_trackingArea];
}
- (void)mouseEntered:(NSEvent*)theEvent
{
[NSCursor hide];
}
- (void)mouseMoved:(NSEvent*)theEvent
{
}
- (void)mouseExited:(NSEvent*)theEvent
{
[NSCursor unhide];
}
- (NSOpenGLContext*)getGLContext
{
return m_glcontext;
}
@end
|