Fixes to OpenGL samples to avoid asserts/crashes.
Don't call wxGLCanvas::SetCurrent() when the window is not shown. Closes #13424. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68909 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -323,10 +323,11 @@ void TestGLCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
|
|||||||
// is wrong when next another canvas is repainted.
|
// is wrong when next another canvas is repainted.
|
||||||
const wxSize ClientSize = GetClientSize();
|
const wxSize ClientSize = GetClientSize();
|
||||||
|
|
||||||
|
TestGLContext& canvas = wxGetApp().GetContext(this);
|
||||||
glViewport(0, 0, ClientSize.x, ClientSize.y);
|
glViewport(0, 0, ClientSize.x, ClientSize.y);
|
||||||
|
|
||||||
// Render the graphics and swap the buffers.
|
// Render the graphics and swap the buffers.
|
||||||
wxGetApp().GetContext(this).DrawRotatedCube(m_xangle, m_yangle);
|
canvas.DrawRotatedCube(m_xangle, m_yangle);
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -136,10 +136,13 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
|||||||
g_doubleBuffer = GL_FALSE;
|
g_doubleBuffer = GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_canvas = new TestGLCanvas(this, wxID_ANY, gl_attrib);
|
||||||
|
|
||||||
// Show the frame
|
// Show the frame
|
||||||
Show(true);
|
Show(true);
|
||||||
|
Raise();
|
||||||
|
|
||||||
m_canvas = new TestGLCanvas(this, wxID_ANY, gl_attrib);
|
m_canvas->InitGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
MyFrame::~MyFrame()
|
MyFrame::~MyFrame()
|
||||||
@@ -177,13 +180,6 @@ TestGLCanvas::TestGLCanvas(wxWindow *parent,
|
|||||||
|
|
||||||
// Explicitly create a new rendering context instance for this canvas.
|
// Explicitly create a new rendering context instance for this canvas.
|
||||||
m_glRC = new wxGLContext(this);
|
m_glRC = new wxGLContext(this);
|
||||||
|
|
||||||
// Make the new context current (activate it for use) with this canvas.
|
|
||||||
SetCurrent(*m_glRC);
|
|
||||||
|
|
||||||
InitGL();
|
|
||||||
InitMaterials();
|
|
||||||
LoadSurface("isosurf.dat.gz");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TestGLCanvas::~TestGLCanvas()
|
TestGLCanvas::~TestGLCanvas()
|
||||||
@@ -279,6 +275,8 @@ void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
|
|||||||
|
|
||||||
void TestGLCanvas::OnSize(wxSizeEvent& event)
|
void TestGLCanvas::OnSize(wxSizeEvent& event)
|
||||||
{
|
{
|
||||||
|
if ( !IsShownOnScreen() )
|
||||||
|
return;
|
||||||
// This is normally only necessary if there is more than one wxGLCanvas
|
// This is normally only necessary if there is more than one wxGLCanvas
|
||||||
// or more than one wxGLContext in the application.
|
// or more than one wxGLContext in the application.
|
||||||
SetCurrent(*m_glRC);
|
SetCurrent(*m_glRC);
|
||||||
@@ -406,6 +404,9 @@ void TestGLCanvas::InitMaterials()
|
|||||||
|
|
||||||
void TestGLCanvas::InitGL()
|
void TestGLCanvas::InitGL()
|
||||||
{
|
{
|
||||||
|
// Make the new context current (activate it for use) with this canvas.
|
||||||
|
SetCurrent(*m_glRC);
|
||||||
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
glShadeModel(GL_SMOOTH);
|
glShadeModel(GL_SMOOTH);
|
||||||
@@ -428,5 +429,8 @@ void TestGLCanvas::InitGL()
|
|||||||
glEnable( GL_VERTEX_ARRAY );
|
glEnable( GL_VERTEX_ARRAY );
|
||||||
glEnable( GL_NORMAL_ARRAY );
|
glEnable( GL_NORMAL_ARRAY );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InitMaterials();
|
||||||
|
LoadSurface("isosurf.dat.gz");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -153,9 +153,6 @@ TestGLCanvas::TestGLCanvas(wxWindow *parent,
|
|||||||
// Explicitly create a new rendering context instance for this canvas.
|
// Explicitly create a new rendering context instance for this canvas.
|
||||||
m_glRC = new wxGLContext(this);
|
m_glRC = new wxGLContext(this);
|
||||||
|
|
||||||
// Make the new context current (activate it for use) with this canvas.
|
|
||||||
SetCurrent(*m_glRC);
|
|
||||||
|
|
||||||
m_gldata.initialized = false;
|
m_gldata.initialized = false;
|
||||||
|
|
||||||
// initialize view matrix
|
// initialize view matrix
|
||||||
@@ -303,6 +300,9 @@ void TestGLCanvas::InitGL()
|
|||||||
|
|
||||||
void TestGLCanvas::ResetProjectionMode()
|
void TestGLCanvas::ResetProjectionMode()
|
||||||
{
|
{
|
||||||
|
if ( !IsShownOnScreen() )
|
||||||
|
return;
|
||||||
|
|
||||||
// This is normally only necessary if there is more than one wxGLCanvas
|
// This is normally only necessary if there is more than one wxGLCanvas
|
||||||
// or more than one wxGLContext in the application.
|
// or more than one wxGLContext in the application.
|
||||||
SetCurrent(*m_glRC);
|
SetCurrent(*m_glRC);
|
||||||
|
Reference in New Issue
Block a user