mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
OpenGL: Set up context sharing on the GL thread, rather than the main thread
wglShareLists will only succeed when the shared context is not currently active on another thread, but it is difficult to ensure that the GL thread is paused/inactive at any given time - in particular, it's very easy to accidentally introduce deadlocks where the main thread waits for the render thread's lock while the render thread waits for the messagemanager lock. The simplest way to ensure that no other thread has activated the shared context is to share the contexts directly on the render thread itself.
This commit is contained in:
parent
10680f9bf7
commit
4bc2952419
1 changed files with 22 additions and 3 deletions
|
|
@ -47,6 +47,7 @@ public:
|
|||
void* contextToShareWithIn,
|
||||
bool /*useMultisampling*/,
|
||||
OpenGLVersion version)
|
||||
: sharedContext (contextToShareWithIn)
|
||||
{
|
||||
placeholderComponent.reset (new PlaceholderComponent (*this));
|
||||
createNativeWindow (component);
|
||||
|
|
@ -84,9 +85,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
if (contextToShareWithIn != nullptr)
|
||||
wglShareLists ((HGLRC) contextToShareWithIn, renderContext.get());
|
||||
|
||||
component.getTopLevelComponent()->repaint();
|
||||
component.repaint();
|
||||
}
|
||||
|
|
@ -107,6 +105,26 @@ public:
|
|||
{
|
||||
threadAwarenessSetter = std::make_unique<ScopedThreadDPIAwarenessSetter> (nativeWindow->getNativeHandle());
|
||||
context = &c;
|
||||
|
||||
if (sharedContext != nullptr)
|
||||
{
|
||||
if (! wglShareLists ((HGLRC) sharedContext, renderContext.get()))
|
||||
{
|
||||
TCHAR messageBuffer[256] = {};
|
||||
|
||||
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr,
|
||||
GetLastError(),
|
||||
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
messageBuffer,
|
||||
(DWORD) numElementsInArray (messageBuffer) - 1,
|
||||
nullptr);
|
||||
|
||||
DBG (messageBuffer);
|
||||
jassertfalse;
|
||||
}
|
||||
}
|
||||
|
||||
return InitResult::success;
|
||||
}
|
||||
|
||||
|
|
@ -405,6 +423,7 @@ private:
|
|||
std::unique_ptr<std::remove_pointer_t<HGLRC>, RenderContextDeleter> renderContext;
|
||||
std::unique_ptr<std::remove_pointer_t<HDC>, DeviceContextDeleter> dc;
|
||||
OpenGLContext* context = nullptr;
|
||||
void* sharedContext = nullptr;
|
||||
double nativeScaleFactor = 1.0;
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue