PDA

View Full Version : Problem with WGL_ARB_buffer_region Can Somebody help?



HanWu
05-12-2003, 05:59 PM
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=(PFNWGLCREATEBUFFERREGION ARBPROC)wglGetProcAddress("wglCreateBufferRegionARB");
wglDeleteBufferRegionARB=(PFNWGLDELETEBUFFERREGION ARBPROC)wglGetProcAddress("wglDeleteBufferRegionARB");
wglSaveBufferRegionARB=(PFNWGLSAVEBUFFERREGIONARBP ROC)wglGetProcAddress("wglSaveBufferRegionARB");
wglRestoreBufferRegionARB=(PFNWGLRESTOREBUFFERREGI ONARBPROC)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(),rec t.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.

HanWu
05-12-2003, 06:48 PM
question
1) Is it we need to create a buffer region once with wglCreateBufferRegionARB untill we close the program or have to recreate a new one every time we want to save a new buffer region?
2) When will we use wglDeleteBufferRegionARB to delete buffer region, is it when we close our child view(program) or before we want to create a new buffer region?
3) Can some one tell me the proper way to use WGL_ARB_buffer_region?

shinpaughp
05-12-2003, 07:17 PM
See the extension specs http://oss.sgi.com/projects/ogl-sample/registry/ARB/wgl_buffer_region.txt

But, it appears that

1) yes, create once (multiple buffers allowed)
2) yes, delete at close or when no longer needed
3) use save and restore functions and check for errors returned by functions. TRUE is successful, FALSE is error, or NULL is error for create can be checked by GetLastError.

HanWu
05-12-2003, 11:31 PM
i am using MFC, can you tell me and show me only a part of code in which function i should create it and in which function i should delete it. Please help,

shinpaughp
05-13-2003, 02:51 PM
[CODE]
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(),rec t.Height());
}

From here where the comments have been put in. Delete it before the window closes - destructor could be good.

HanWu
05-13-2003, 08:36 PM
1) i am using MDI, so in which function i should create the region? And in which class, the base class or the CSbomView class?
2)i have tried this method, but still cant save the region. The wglSaveBufferRegionARB return a true value but when i restore it with wglRestoreBufferRegionARB it cant restore the region.
3) Did you means i should delete the region at CSbomView::~CSbomView() destructor function. i delete the region at the OnDestroy function before i delete m_pDC, cause from the documentation it says that the m_pDC who create the region must be valid when you want to delete the region.

thanks

[This message has been edited by chengseesin (edited 05-13-2003).]