currently i am using WGL_ARB_buffer_region.
i use this method to do my save/restore,
//my base class
class COpenGL : public CScrollView{
public:
HGLRC m_hRC; //Rendering Context
CDC* m_pDC; //Device Context
HANDLE region;
PFNWGLCREATEBUFFERREGIONARBPROC wglCreateBufferRegionARB;
PFNWGLDELETEBUFFERREGIONARBPROC wglDeleteBufferRegionARB;
PFNWGLSAVEBUFFERREGIONARBPROC wglSaveBufferRegionARB;
PFNWGLRESTOREBUFFERREGIONARBPROC wglRestoreBufferRegionARB;
…
}
// i setup my opengl as usual
BOOL COpenGL::InitOpenGL()
{
//Get a DC for the Client Area
m_pDC = new CClientDC(this);
//Failure to Get DC
if( m_pDC == NULL )
return FALSE;
if( !SetupPixelFormat() )
return FALSE;
//Create Rendering Context
m_hRC = ::wglCreateContext( m_pDC->GetSafeHdc() );
//Failure to Create Rendering Context
if( m_hRC == 0 )
return FALSE;
//Make the RC Current
if( ::wglMakeCurrent( m_pDC->GetSafeHdc(), m_hRC ) == FALSE )
return FALSE;
wglCreateBufferRegionARB=(PFNWGLCREATEBUFFERREGIONARBPROC)wglGetProcAddress(“wglCreateBufferRegionARB”);
wglDeleteBufferRegionARB=(PFNWGLDELETEBUFFERREGIONARBPROC)wglGetProcAddress(“wglDeleteBufferRegionARB”);
wglSaveBufferRegionARB=(PFNWGLSAVEBUFFERREGIONARBPROC)wglGetProcAddress(“wglSaveBufferRegionARB”);
wglRestoreBufferRegionARB=(PFNWGLRESTOREBUFFERREGIONARBPROC)wglGetProcAddress(“wglRestoreBufferRegionARB”);
region=NULL;
region=wglCreateBufferRegionARB(m_pDC->GetSafeHdc(),0,WGL_BACK_COLOR_BUFFER_BIT_ARB | WGL_DEPTH_BUFFER_BIT_ARB);
return TRUE;
}
// CSbomView is my View class
// CSbomDoc is my Doc class
class CSbomView : public COpenGL{
…
}
void CSbomView::SaveCurrentView()
{
CRect rect;
GetClientRect(&rect);
wglDeleteBufferRegionARB(region);
region=wglCreateBufferRegionARB(m_pDC->GetSafeHdc(),0,WGL_BACK_COLOR_BUFFER_BIT_ARB | WGL_DEPTH_BUFFER_BIT_ARB);
wglSaveBufferRegionARB(region,0,0,rect.Width(),rect.Height());
}
void CSbomView::RestoreCurrentView()
{
int port[4];
glGetIntegerv(GL_VIEWPORT,port);
wglRestoreBufferRegionARB(region,port[0],port[1],port[2],port[3],port[0],port[1]);
}
after this i use my SaveCurrentView(), and RestoreCurrentView() to do my save/restore job. It works fine at first( the first child windows never show any problem), but after i close a child window and open a new child window (repeat it a few time 7 to 10 times) my program exit with error automatically. I really dont have any idea with it. Can someone please tell me how to solve the problem Thanks.