diff options
author | Leith Bade <leith@leithalweapon.geek.nz> | 2014-06-24 00:25:20 +1000 |
---|---|---|
committer | Mike Morris <michael.patrick.morris@gmail.com> | 2014-09-10 18:21:03 -0400 |
commit | c004c036964e9012b08aa4a2f8b16094630d62be (patch) | |
tree | be5f77b5286b924616a91f574c453bf3aa463ced | |
parent | c836bc2b01c1c8642875d86126c1ef2a76dfd359 (diff) | |
download | qtlocation-mapboxgl-c004c036964e9012b08aa4a2f8b16094630d62be.tar.gz |
Add View::make_inactive() to remove context from rendering thread
View::make_inactive() is called just before termination of the
rendering thread. The implementation must clear the thread's GL
context.
This ensures there is no context still bound to a thread during
GL shutdown. This is needed as GL will not actually delete a
context until it is not active on any thread.
Fixes mapbox/mapbox-gl-native#340
Conflicts:
common/glfw_view.hpp
include/llmr/map/view.hpp
test/headless.cpp
-rw-r--r-- | common/glfw_view.cpp | 4 | ||||
-rw-r--r-- | common/glfw_view.hpp | 1 | ||||
-rw-r--r-- | common/headless_view.cpp | 13 | ||||
-rw-r--r-- | common/headless_view.hpp | 1 | ||||
-rw-r--r-- | include/mbgl/map/view.hpp | 4 | ||||
-rw-r--r-- | src/map/map.cpp | 2 |
6 files changed, 25 insertions, 0 deletions
diff --git a/common/glfw_view.cpp b/common/glfw_view.cpp index f53090a000..724b8bf180 100644 --- a/common/glfw_view.cpp +++ b/common/glfw_view.cpp @@ -192,6 +192,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 f790d90cec..34326ae29c 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -179,6 +179,19 @@ void HeadlessView::make_active() { #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 + // no-op +#endif +} + void HeadlessView::swap() {} unsigned int HeadlessView::root_fbo() { diff --git a/common/headless_view.hpp b/common/headless_view.hpp index 0b255b4a38..a4432bbae3 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(); diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp index 92d60d4d02..3e2f1a4b5a 100644 --- a/include/mbgl/map/view.hpp +++ b/include/mbgl/map/view.hpp @@ -35,6 +35,10 @@ public: // renderer setup since the render thread doesn't switch the contexts. virtual void make_active() = 0; + // Called from the render thread. Makes the GL context inactive in the current + // thread. This is called once just before the rendering thread terminates. + virtual void make_inactive() = 0; + // Returns the base framebuffer object, if any, and 0 if using the system // provided framebuffer. virtual unsigned int root_fbo() { diff --git a/src/map/map.cpp b/src/map/map.cpp index 9984f1b181..de7a7032dc 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -114,6 +114,8 @@ void Map::run() { prepare(); render(); } + + view.make_inactive(); } void Map::rerender() { |