Fix Discord streaming for OpenGL
Check if the OpenGL context is valid on every operation, and if not re-initialize it. Also rebind the textures every time the frame is drawn. Also rename the SetCurrent method to SetContext, which is clearer. Fix #643 Fix #767 Fix #840 Fix #843 Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
parent
24b92462f9
commit
7561ca97c1
|
@ -38,10 +38,11 @@ protected:
|
|||
void DrawArea(wxWindowDC& dc);
|
||||
void OnSize(wxSizeEvent& ev);
|
||||
void AdjustViewport();
|
||||
void RefreshGL();
|
||||
#ifndef wxGL_IMPLICIT_CONTEXT
|
||||
wxGLContext* ctx;
|
||||
wxGLContext* ctx = nullptr;
|
||||
#endif
|
||||
bool SetCurrent();
|
||||
bool SetContext();
|
||||
void DrawingPanelInit();
|
||||
GLuint texid, vlist;
|
||||
int texsize;
|
||||
|
|
|
@ -2183,9 +2183,26 @@ static int glopts[] = {
|
|||
WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0
|
||||
};
|
||||
|
||||
bool GLDrawingPanel::SetCurrent()
|
||||
bool GLDrawingPanel::SetContext()
|
||||
{
|
||||
#ifndef wxGL_IMPLICIT_CONTEXT
|
||||
// Check if the current context is valid
|
||||
if (!ctx
|
||||
#if wxCHECK_VERSION(3, 1, 0)
|
||||
|| !ctx->IsOK()
|
||||
#endif
|
||||
)
|
||||
{
|
||||
// Delete the old context
|
||||
if (ctx) {
|
||||
delete ctx;
|
||||
ctx = nullptr;
|
||||
}
|
||||
|
||||
// Create a new context
|
||||
ctx = new wxGLContext(this);
|
||||
DrawingPanelInit();
|
||||
}
|
||||
return wxGLCanvas::SetCurrent(*ctx);
|
||||
#else
|
||||
return wxGLContext::SetCurrent(*this);
|
||||
|
@ -2198,11 +2215,7 @@ GLDrawingPanel::GLDrawingPanel(wxWindow* parent, int _width, int _height)
|
|||
wxFULL_REPAINT_ON_RESIZE | wxWANTS_CHARS)
|
||||
{
|
||||
widgets::RequestHighResolutionOpenGlSurfaceForWindow(this);
|
||||
#ifndef wxGL_IMPLICIT_CONTEXT
|
||||
ctx = new wxGLContext(this);
|
||||
#endif
|
||||
SetCurrent();
|
||||
if (!did_init) DrawingPanelInit();
|
||||
SetContext();
|
||||
}
|
||||
|
||||
GLDrawingPanel::~GLDrawingPanel()
|
||||
|
@ -2211,7 +2224,7 @@ GLDrawingPanel::~GLDrawingPanel()
|
|||
// it's also unsafe if panel no longer displayed
|
||||
if (did_init)
|
||||
{
|
||||
SetCurrent();
|
||||
SetContext();
|
||||
glDeleteLists(vlist, 1);
|
||||
glDeleteTextures(1, &texid);
|
||||
}
|
||||
|
@ -2223,7 +2236,7 @@ GLDrawingPanel::~GLDrawingPanel()
|
|||
|
||||
void GLDrawingPanel::DrawingPanelInit()
|
||||
{
|
||||
SetCurrent();
|
||||
SetContext();
|
||||
|
||||
DrawingPanelBase::DrawingPanelInit();
|
||||
|
||||
|
@ -2361,7 +2374,6 @@ void GLDrawingPanel::DrawingPanelInit()
|
|||
|
||||
void GLDrawingPanel::OnSize(wxSizeEvent& ev)
|
||||
{
|
||||
SetCurrent();
|
||||
AdjustViewport();
|
||||
|
||||
// Temporary hack to backport 800d6ed69b from wxWidgets until 3.2.2 is released.
|
||||
|
@ -2373,7 +2385,7 @@ void GLDrawingPanel::OnSize(wxSizeEvent& ev)
|
|||
|
||||
void GLDrawingPanel::AdjustViewport()
|
||||
{
|
||||
SetCurrent();
|
||||
SetContext();
|
||||
|
||||
int x, y;
|
||||
widgets::GetRealPixelClientSize(this, &x, &y);
|
||||
|
@ -2387,10 +2399,20 @@ void GLDrawingPanel::AdjustViewport()
|
|||
#endif
|
||||
}
|
||||
|
||||
void GLDrawingPanel::RefreshGL()
|
||||
{
|
||||
SetContext();
|
||||
|
||||
// Rebind any textures or other OpenGL resources here
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texid);
|
||||
}
|
||||
|
||||
void GLDrawingPanel::DrawArea(wxWindowDC& dc)
|
||||
{
|
||||
(void)dc; // unused params
|
||||
SetCurrent();
|
||||
SetContext();
|
||||
RefreshGL();
|
||||
|
||||
if (!did_init)
|
||||
DrawingPanelInit();
|
||||
|
@ -2678,4 +2700,4 @@ void GameArea::UnsuspendScreenSaver() {
|
|||
xscreensaver_suspended = false;
|
||||
}
|
||||
#endif // HAVE_XSS
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue