Use wgl shared context lists to avoid re-creating gl context from scratch.
This commit is contained in:
@@ -677,7 +677,8 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks,
|
||||
|
||||
initDPIAwareness();
|
||||
|
||||
if (!switchContext(mFullscreen, windowSize, vsync_mode, &windowPos))
|
||||
|
||||
if (!switchContext(mFullscreen, windowSize, vsync_mode, nullptr, nullptr, &windowPos))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -956,7 +957,7 @@ BOOL LLWindowWin32::setSizeImpl(const LLCoordWindow size)
|
||||
}
|
||||
|
||||
// changing fullscreen resolution
|
||||
BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen &size, const S32 vsync_mode, const LLCoordScreen * const posp)
|
||||
BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen &size, const S32 vsync_mode, std::function<void()> stopFn, std::function<void(bool)> restoreFn, const LLCoordScreen * const posp)
|
||||
{
|
||||
GLuint pixel_format;
|
||||
DEVMODE dev_mode;
|
||||
@@ -986,20 +987,25 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen &size, co
|
||||
}
|
||||
|
||||
gGLManager.shutdownGL();
|
||||
//destroy gl context
|
||||
class ContextHandle
|
||||
{
|
||||
public:
|
||||
ContextHandle(HGLRC context) : mOldContext(context)
|
||||
{}
|
||||
~ContextHandle()
|
||||
{
|
||||
wglDeleteContext(mOldContext);
|
||||
}
|
||||
operator HGLRC() const { return mOldContext; }
|
||||
private:
|
||||
HGLRC mOldContext;
|
||||
} oldContext = mhRC;
|
||||
if (mhRC)
|
||||
{
|
||||
if (!wglMakeCurrent(NULL, NULL))
|
||||
{
|
||||
LL_WARNS("Window") << "Release of DC and RC failed" << LL_ENDL;
|
||||
}
|
||||
|
||||
if (!wglDeleteContext(mhRC))
|
||||
{
|
||||
LL_WARNS("Window") << "Release of rendering context failed" << LL_ENDL;
|
||||
}
|
||||
|
||||
mhRC = NULL;
|
||||
}
|
||||
|
||||
if (fullscreen)
|
||||
@@ -1509,6 +1515,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen &size, co
|
||||
}
|
||||
|
||||
mhRC = 0;
|
||||
bool sharedContext = false;
|
||||
if (wglCreateContextAttribsARB)
|
||||
{ //attempt to create a specific versioned context
|
||||
S32 attribs[] =
|
||||
@@ -1523,8 +1530,11 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen &size, co
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
mhRC = wglCreateContextAttribsARB(mhDC, mhRC, attribs);
|
||||
|
||||
sharedContext = oldContext && (mhRC = wglCreateContextAttribsARB(mhDC, oldContext, attribs)) != nullptr;
|
||||
if (!sharedContext)
|
||||
{
|
||||
mhRC = wglCreateContextAttribsARB(mhDC, nullptr, attribs);
|
||||
}
|
||||
if (!mhRC)
|
||||
{
|
||||
if (attribs[3] > 0)
|
||||
@@ -1555,7 +1565,11 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen &size, co
|
||||
}
|
||||
}
|
||||
|
||||
if (!mhRC && !(mhRC = wglCreateContext(mhDC)))
|
||||
bool abort = !mhRC && !(mhRC = wglCreateContext(mhDC));
|
||||
|
||||
if (!sharedContext && stopFn) stopFn();
|
||||
|
||||
if (abort)
|
||||
{
|
||||
close();
|
||||
OSMessageBox(mCallbacks->translateString("MBGLContextErr"), mCallbacks->translateString("MBError"), OSMB_OK);
|
||||
@@ -1626,6 +1640,8 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen &size, co
|
||||
glGetIntegerv(GL_SAMPLES, &buf);
|
||||
LL_INFOS() << "Acquired FSAA Samples = " << buf << LL_ENDL;
|
||||
|
||||
if(restoreFn) restoreFn(!sharedContext);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user