From 3d85a593bf0812f50f08f4852fae00fdd16fffd8 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 14 Sep 2012 22:18:22 +0200 Subject: menu/application: add possibility to query if ogl thread opengl calls should only executed in the thread, that created the opengl context. To query whether the current thread is the opengl thread, the application class stores the current thread id of the opengl thread after initializing opengl. --- src/menu/application.cpp | 8 ++++++++ src/menu/application.hpp | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/menu/application.cpp b/src/menu/application.cpp index 1e82b6e2..b8392802 100644 --- a/src/menu/application.cpp +++ b/src/menu/application.cpp @@ -80,6 +80,11 @@ namespace usdx return get_instance()->config; } + bool Application::is_gl_thread(void) + { + return boost::this_thread::get_id() == get_instance()->gl_thread; + } + void Application::main_loop(SDL_Surface* display) { SDL_Event event; @@ -157,6 +162,9 @@ namespace usdx glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); + // save current thread, to be able to detect whether some method is + // called from the thread owning the OpenGL contect + gl_thread = boost::this_thread::get_id(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); diff --git a/src/menu/application.hpp b/src/menu/application.hpp index 9e6ab5c5..78b4e01d 100644 --- a/src/menu/application.hpp +++ b/src/menu/application.hpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -55,6 +56,7 @@ namespace usdx * This is the main loop. */ void main_loop(SDL_Surface* display); + boost::thread::id gl_thread; void init_fps_manager(void); @@ -66,6 +68,7 @@ namespace usdx static Application* get_instance(void); static Config* get_config(void); + static bool is_gl_thread(void); void run(void); -- cgit v1.2.3