summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/glfw_view.cpp9
-rw-r--r--common/glfw_view.hpp1
-rw-r--r--common/headless_view.cpp25
-rw-r--r--common/headless_view.hpp1
4 files changed, 30 insertions, 6 deletions
diff --git a/common/glfw_view.cpp b/common/glfw_view.cpp
index f53090a000..0908786bb6 100644
--- a/common/glfw_view.cpp
+++ b/common/glfw_view.cpp
@@ -8,7 +8,10 @@ GLFWView::GLFWView(bool fullscreen) : fullscreen(fullscreen) {
#endif
}
-GLFWView::~GLFWView() { glfwTerminate(); }
+GLFWView::~GLFWView() {
+ map->terminate();
+ glfwTerminate();
+}
void GLFWView::initialize(mbgl::Map *map) {
View::initialize(map);
@@ -192,6 +195,10 @@ void GLFWView::make_active() {
glfwMakeContextCurrent(window);
}
+void GLFWView::make_inactive() {
+ glfwMakeContextCurrent(nullptr);
+}
+
void GLFWView::swap() {
glfwPostEmptyEvent();
diff --git a/common/glfw_view.hpp b/common/glfw_view.hpp
index d2f6872fc7..04085f7750 100644
--- a/common/glfw_view.hpp
+++ b/common/glfw_view.hpp
@@ -17,6 +17,7 @@ public:
void initialize(mbgl::Map *map);
void swap();
void make_active();
+ void make_inactive();
void notify_map_change(mbgl::MapChange change, mbgl::timestamp delay = 0);
static void key(GLFWwindow *window, int key, int scancode, int action, int mods);
diff --git a/common/headless_view.cpp b/common/headless_view.cpp
index 94a6cd03bc..d3c6491d0d 100644
--- a/common/headless_view.cpp
+++ b/common/headless_view.cpp
@@ -110,10 +110,7 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) {
#if MBGL_USE_GLX
x_pixmap = XCreatePixmap(x_display, DefaultRootWindow(x_display), width, height, 32);
glx_pixmap = glXCreateGLXPixmap(x_display, x_info, x_pixmap);
-
- make_active();
#endif
-
}
void HeadlessView::clear_buffers() {
@@ -136,6 +133,8 @@ void HeadlessView::clear_buffers() {
glDeleteRenderbuffersEXT(1, &fbo_depth_stencil);
fbo_depth_stencil = 0;
}
+
+ make_inactive();
#endif
#if MBGL_USE_GLX
@@ -152,7 +151,7 @@ void HeadlessView::clear_buffers() {
}
HeadlessView::~HeadlessView() {
- clear_buffers();
+ make_inactive();
#if MBGL_USE_CGL
CGLDestroyContext(gl_context);
@@ -163,7 +162,7 @@ HeadlessView::~HeadlessView() {
std::cerr << "x_display: " << x_display << '\n';
std::cerr << "glx_pixmap: " << glx_pixmap << '\n';
std::cerr << "gl_context: " << gl_context << '\n';
- glXMakeCurrent(x_display, None, NULL);
+
glXDestroyContext(x_display, gl_context);
XFree(x_info);
XCloseDisplay(x_display);
@@ -187,12 +186,28 @@ void HeadlessView::make_active() {
std::cerr << "x_display: " << x_display << '\n';
std::cerr << "glx_pixmap: " << glx_pixmap << '\n';
std::cerr << "gl_context: " << gl_context << '\n';
+
if (!glXMakeCurrent(x_display, glx_pixmap, gl_context)) {
fprintf(stderr, "Switching OpenGL context failed\n");
}
#endif
}
+void HeadlessView::make_inactive() {
+#if MBGL_USE_CGL
+ CGLError error = CGLSetCurrentContext(nullptr);
+ if (error) {
+ fprintf(stderr, "Removing OpenGL context failed\n");
+ }
+#endif
+
+#if MBGL_USE_GLX
+ if (!glXMakeCurrent(x_display, None, NULL)) {
+ fprintf(stderr, "Removing OpenGL context failed\n");
+ }
+#endif
+}
+
void HeadlessView::swap() {}
unsigned int HeadlessView::root_fbo() {
diff --git a/common/headless_view.hpp b/common/headless_view.hpp
index a8ce4aa325..c8475a2516 100644
--- a/common/headless_view.hpp
+++ b/common/headless_view.hpp
@@ -23,6 +23,7 @@ public:
void notify_map_change(MapChange change, timestamp delay = 0);
void make_active();
+ void make_inactive();
void swap();
unsigned int root_fbo();