forked from PixarAnimationStudios/OpenUSD
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathglPlatformContextDarwin.mm
More file actions
131 lines (114 loc) · 2.73 KB
/
glPlatformContextDarwin.mm
File metadata and controls
131 lines (114 loc) · 2.73 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// Copyright 2016 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://openusd.org/license.
//
#import <Foundation/Foundation.h>
#include "pxr/pxr.h"
#include "glPlatformContextDarwin.h"
#if defined(PXR_GL_SUPPORT_ENABLED)
#ifdef ARCH_OS_IPHONE
#import <UIKit/UIKit.h>
typedef EAGLContext NSGLContext;
#else
#import <AppKit/NSOpenGL.h>
typedef NSOpenGLContext NSGLContext;
#endif
#else
typedef void* NSGLContext;
#endif
PXR_NAMESPACE_OPEN_SCOPE
class GarchNSGLContextState::Detail
{
public:
Detail() {
#if defined(PXR_GL_SUPPORT_ENABLED)
context = [NSGLContext currentContext];
#else
context = nil;
#endif
}
Detail(NullState) {
context = nil;
}
~Detail() {
context = nil; // garbage collect
}
NSGLContext * context;
};
/// Construct with the current state.
GarchNSGLContextState::GarchNSGLContextState()
: _detail(std::make_shared<GarchNSGLContextState::Detail>())
{
}
GarchNSGLContextState::GarchNSGLContextState(NullState)
: _detail(std::make_shared<GarchNSGLContextState::Detail>(
NullState::nullstate))
{
}
/// Construct with the given state.
//GarchNSGLContextState(const GarchNSGLContextState& copy);
/// Compare for equality.
bool
GarchNSGLContextState::operator==(const GarchNSGLContextState& rhs) const
{
return rhs._detail->context == _detail->context;
}
/// Returns a hash value for the state.
size_t
GarchNSGLContextState::GetHash() const
{
return static_cast<size_t>(reinterpret_cast<uintptr_t>(_detail->context));
}
/// Returns \c true if the context state is valid.
bool
GarchNSGLContextState::IsValid() const
{
return _detail->context != nil;
}
/// Make the context current.
void
GarchNSGLContextState::MakeCurrent()
{
#if defined(PXR_GL_SUPPORT_ENABLED)
#if defined(ARCH_OS_IPHONE)
[EAGLContext setCurrentContext:_detail->context];
#else
[_detail->context makeCurrentContext];
#endif
#endif
}
/// Make no context current.
void
GarchNSGLContextState::DoneCurrent()
{
#if defined(PXR_GL_SUPPORT_ENABLED)
#if defined(ARCH_OS_IPHONE)
[EAGLContext setCurrentContext:nil];
#else
[NSGLContext clearCurrentContext];
#endif
#endif
}
GarchGLPlatformContextState
GarchGetNullGLPlatformContextState()
{
return GarchNSGLContextState(GarchNSGLContextState::NullState::nullstate);
}
void *
GarchSelectCoreProfileMacVisual()
{
#if defined(ARCH_OS_OSX)
NSOpenGLPixelFormatAttribute attribs[10];
int c = 0;
attribs[c++] = NSOpenGLPFAOpenGLProfile;
attribs[c++] = NSOpenGLProfileVersion3_2Core;
attribs[c++] = NSOpenGLPFADoubleBuffer;
attribs[c++] = 0;
return [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
#else // ARCH_OS_MACOS
return NULL;
#endif
}
PXR_NAMESPACE_CLOSE_SCOPE