diff options
Diffstat (limited to 'gpu/command_buffer/client')
-rw-r--r-- | gpu/command_buffer/client/gles2_demo.cc | 9 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_lib.cc | 24 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_lib.h | 22 |
3 files changed, 35 insertions, 20 deletions
diff --git a/gpu/command_buffer/client/gles2_demo.cc b/gpu/command_buffer/client/gles2_demo.cc index 2b96ba8..9b5977e 100644 --- a/gpu/command_buffer/client/gles2_demo.cc +++ b/gpu/command_buffer/client/gles2_demo.cc @@ -77,10 +77,11 @@ bool GLES2Demo::Setup(void* hwnd, int32 size) { return false; - gles2::g_gl_impl = new GLES2Implementation(helper, - transfer_buffer.size, - transfer_buffer.ptr, - transfer_buffer_id); + gles2::Initialize(); + gles2::SetGLContext(new GLES2Implementation(helper, + transfer_buffer.size, + transfer_buffer.ptr, + transfer_buffer_id)); return command_buffer.release() != NULL; } diff --git a/gpu/command_buffer/client/gles2_lib.cc b/gpu/command_buffer/client/gles2_lib.cc index cd7cfed..003a4cc 100644 --- a/gpu/command_buffer/client/gles2_lib.cc +++ b/gpu/command_buffer/client/gles2_lib.cc @@ -3,11 +3,29 @@ // found in the LICENSE file. #include "gpu/command_buffer/client/gles2_lib.h" +#include "gpu/command_buffer/common/thread_local.h" namespace gles2 { - -THREAD_LOCAL ::gpu::gles2::GLES2Implementation* g_gl_impl; - +namespace { +gpu::ThreadLocalKey g_gl_context_key; +} // namespace anonymous + +void Initialize() { + g_gl_context_key = gpu::ThreadLocalAlloc(); +} + +void Terminate() { + gpu::ThreadLocalFree(g_gl_context_key); +} + +gpu::gles2::GLES2Implementation* GetGLContext() { + return static_cast<gpu::gles2::GLES2Implementation*>( + gpu::ThreadLocalGetValue(g_gl_context_key)); +} + +void SetGLContext(gpu::gles2::GLES2Implementation* context) { + gpu::ThreadLocalSetValue(g_gl_context_key, context); +} } // namespace gles2 diff --git a/gpu/command_buffer/client/gles2_lib.h b/gpu/command_buffer/client/gles2_lib.h index e2825fa..2242cc8 100644 --- a/gpu/command_buffer/client/gles2_lib.h +++ b/gpu/command_buffer/client/gles2_lib.h @@ -9,23 +9,19 @@ #include "gpu/command_buffer/client/gles2_implementation.h" -#if defined(_MSC_VER) -#define THREAD_LOCAL __declspec(thread) -#else -#define THREAD_LOCAL __thread -#endif - namespace gles2 { -extern THREAD_LOCAL gpu::gles2::GLES2Implementation* g_gl_impl; +// Initialize the GLES2 library. +void Initialize(); + +// Terminate the GLES2 library. +void Terminate(); -inline gpu::gles2::GLES2Implementation* GetGLContext() { - return g_gl_impl; -} +// Get the current GL context. +gpu::gles2::GLES2Implementation* GetGLContext(); -inline void SetGLContext(gpu::gles2::GLES2Implementation* impl) { - g_gl_impl = impl; -} +// Set the current GL context. +void SetGLContext(gpu::gles2::GLES2Implementation* impl); } // namespace gles2 |