Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/macos/gl_manager_macos_legacy.h
10277 views
1
/**************************************************************************/
2
/* gl_manager_macos_legacy.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#if defined(MACOS_ENABLED) && defined(GLES3_ENABLED)
34
35
#include "core/os/os.h"
36
#include "core/templates/local_vector.h"
37
#include "servers/display_server.h"
38
39
#import <AppKit/AppKit.h>
40
#import <ApplicationServices/ApplicationServices.h>
41
#import <CoreVideo/CoreVideo.h>
42
43
GODOT_CLANG_WARNING_PUSH_AND_IGNORE("-Wdeprecated-declarations") // OpenGL is deprecated in macOS 10.14.
44
45
typedef CGLError (*CGLEnablePtr)(CGLContextObj ctx, CGLContextEnable pname);
46
typedef CGLError (*CGLSetParameterPtr)(CGLContextObj ctx, CGLContextParameter pname, const GLint *params);
47
typedef CGLContextObj (*CGLGetCurrentContextPtr)(void);
48
49
class GLManagerLegacy_MacOS {
50
struct GLWindow {
51
id window_view = nullptr;
52
NSOpenGLContext *context = nullptr;
53
};
54
55
RBMap<DisplayServer::WindowID, GLWindow> windows;
56
57
NSOpenGLContext *shared_context = nullptr;
58
DisplayServer::WindowID current_window = DisplayServer::INVALID_WINDOW_ID;
59
60
Error create_context(GLWindow &win);
61
62
bool framework_loaded = false;
63
bool use_vsync = false;
64
CGLEnablePtr CGLEnable = nullptr;
65
CGLSetParameterPtr CGLSetParameter = nullptr;
66
CGLGetCurrentContextPtr CGLGetCurrentContext = nullptr;
67
68
public:
69
Error window_create(DisplayServer::WindowID p_window_id, id p_view, int p_width, int p_height);
70
void window_destroy(DisplayServer::WindowID p_window_id);
71
void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height);
72
73
void release_current();
74
void swap_buffers();
75
76
void window_make_current(DisplayServer::WindowID p_window_id);
77
78
void window_set_per_pixel_transparency_enabled(DisplayServer::WindowID p_window_id, bool p_enabled);
79
80
Error initialize();
81
82
void set_use_vsync(bool p_use);
83
bool is_using_vsync() const;
84
85
NSOpenGLContext *get_context(DisplayServer::WindowID p_window_id);
86
87
GLManagerLegacy_MacOS();
88
~GLManagerLegacy_MacOS();
89
};
90
91
GODOT_CLANG_WARNING_PUSH
92
93
#endif // MACOS_ENABLED && GLES3_ENABLED
94
95