Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 790 vs 794 for /trunk/Source Code/Platform/Video/OpenGL/SDLWindowWrapper.cpp

Diff revisions: vs.
  @@ -38,6 +38,7 @@
38 38 }
39 39
40 40 bool init(U32 size, const DisplayWindow& window) {
41 + WriteLock w_lock(_glContextLock);
41 42 _contexts.resize(size, std::make_pair(nullptr, false));
42 43 for (std::pair<SDL_GLContext, bool>& ctx : _contexts) {
43 44 ctx.first = SDL_GL_CreateContext(window.getRawWindow());
  @@ -46,6 +47,7 @@
46 47 }
47 48
48 49 bool destroy() {
50 + WriteLock w_lock(_glContextLock);
49 51 for (std::pair<SDL_GLContext, bool>& ctx : _contexts) {
50 52 SDL_GL_DeleteContext(ctx.first);
51 53 }
  @@ -54,8 +56,10 @@
54 56 }
55 57
56 58 bool getAvailableContext(SDL_GLContext& ctx) {
59 + UpgradableReadLock ur_lock(_glContextLock);
57 60 for (std::pair<SDL_GLContext, bool>& ctxIt : _contexts) {
58 61 if (!ctxIt.second) {
62 + UpgradeToWriteLock w_lock(ur_lock);
59 63 ctx = ctxIt.first;
60 64 ctxIt.second = true;
61 65 return true;
  @@ -66,6 +70,7 @@
66 70 }
67 71
68 72 private:
73 + SharedLock _glContextLock;
69 74 vectorImpl<std::pair<SDL_GLContext, bool /*in use*/>> _contexts;
70 75 } g_ContextPool;
71 76 };
  @@ -90,9 +95,6 @@
90 95 SDL_GL_DeleteContext(GLUtil::_glRenderContext);
91 96 g_ContextPool.destroy();
92 97
93 - WriteLock w_lock(GLUtil::_glContextLock);
94 - GLUtil::_glSecondaryContexts.clear();
95 -
96 98 return ErrorCode::NO_ERR;
97 99 }
98 100
  @@ -387,25 +389,15 @@
387 389 }
388 390
389 391 void GL_API::syncToThread(const std::thread::id& threadID) {
392 + ACKNOWLEDGE_UNUSED(threadID);
390 393 if (glbinding::getCurrentContext() == 0) {
391 - std::hash<std::thread::id> hasher;
392 - size_t threadHash = hasher(threadID);
393 -
394 - SDL_GLContext ctx;
395 - {
396 - WriteLock w_lock(GLUtil::_glContextLock);
397 - hashMapImpl<size_t, SDL_GLContext>::iterator it;
398 - it = GLUtil::_glSecondaryContexts.find(threadHash);
399 - assert(it == std::cend(GLUtil::_glSecondaryContexts));
400 - // This also makes the context current
401 - bool ctxFound = g_ContextPool.getAvailableContext(ctx);
402 - assert(ctxFound && "GL_API::syncToThread: context not found for current thread!");
403 - ACKNOWLEDGE_UNUSED(ctxFound);
404 -
405 - hashAlg::emplace(GLUtil::_glSecondaryContexts, threadHash, ctx);
406 - }
407 -
408 - SDL_GL_MakeCurrent(Application::instance().windowManager().getActiveWindow().getRawWindow(), ctx);
394 + // This also makes the context current
395 + assert(GLUtil::_glSecondaryContext == nullptr && "GL_API::syncToThread: double init context for current thread!");
396 + bool ctxFound = g_ContextPool.getAvailableContext(GLUtil::_glSecondaryContext);
397 + assert(ctxFound && "GL_API::syncToThread: context not found for current thread!");
398 + ACKNOWLEDGE_UNUSED(ctxFound);
399 + SDL_GL_MakeCurrent(Application::instance().windowManager().getActiveWindow().getRawWindow(),
400 + GLUtil::_glSecondaryContext);
409 401 glbinding::Binding::initialize(false);
410 402 // Enable OpenGL debug callbacks for this context as well
411 403 if (Config::ENABLE_GPU_VALIDATION) {
  @@ -413,7 +405,7 @@
413 405 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
414 406 // Debug callback in a separate thread requires a flag to distinguish it
415 407 // from the main thread's callbacks
416 - glDebugMessageCallback((GLDEBUGPROC)GLUtil::DebugCallback, ctx);
408 + glDebugMessageCallback((GLDEBUGPROC)GLUtil::DebugCallback, GLUtil::_glSecondaryContext);
417 409 }
418 410 }
419 411 }