OpenGL RC Sharing (wglShareList)

Hi,
I’m using wglShareList to share color beetween two rendering contexts. I’m using MFC Doc/View in VS2010 C++. Here is what i was code:

View:



int CProcKLView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
...
	hRCChild1 = wglCreateContext(m_pCDC->GetSafeHdc());			
	GetDocument()->ContextShareList(hRCChild1);
	
	wglMakeCurrent(m_pCDC->GetSafeHdc(), hRCChild1);						

...
}

In Doc i have:


CProcKLDoc::CProcKLDoc()
{
	m_hRC = NULL;
	CreateVirtualWindow(m_hRC);

}

...

void CProcKLDoc::ContextShareList(HGLRC hRCshare)
{
	HGLRC shareCtx = hRCshare;

	if(shareCtx!=0) {
		wglShareLists(shareCtx, m_hRC);
		wglMakeCurrent(m_hDCV,m_hRC);
		Colorize();
	}
}

void CProcGLDoc::CreateVirtualWindow(HGLRC &hRC)
{

		CFrameWnd* pWnd = new CFrameWnd();
		pWnd->Create(NULL, NULL);
		m_hDCV = pWnd->GetDC()->GetSafeHdc();
		m_pDCV = pWnd->GetDC();

		SetupPixelFormat();
		hRC = wglCreateContext(m_hDCV);

}

As you see i have two windows. One is virtual and there is a “parent” rendering context. Child is create in the view.

I have true from sharelist and pixelformat is the same for both context. So… can I share context between two windows?

can I share context between two windows?

You sure can if true from wglShareLists.

assuming the windows are the same pixel format, it should work

But it’s ok when one is a CMDIFrameWnd and the other is CMDIChildWnd ?

yup

Thx. It works in Doc/View, but if i want to open another view in the same doc it crash.

View:

	int CoglmfcView::OnCreate(LPCREATESTRUCT lpCreateStruct)
	{
		if (CView::OnCreate(lpCreateStruct) == -1)
			return -1;

		hDC = ::GetDC(m_hWnd);

		GetDocument()->SetDCPixelFormat(hDC);		
		hRC = wglCreateContext(hDC);

		GetDocument()->ShareContext(hDC,hRC);
		wglMakeCurrent(hDC, hRC);
		//GetDocument()->InitDocTexture();
		InitOpenGL();

		return 0;
	}

InDoc:

void CoglmfcDoc::ShareContext(HDC ihDC, HGLRC ihRC)
{
	wglShareLists(ihRC, p_hRC);
	wglMakeCurrent(p_hDCV, p_hRC);
	//if(TextureExist == 0)
		InitDocTexture();
	//TextureExist = 1;
	
	wglMakeCurrent(NULL,NULL);
}


void CoglmfcDoc::CreateParentRC()
{
	CFrameWnd* pWnd = new CFrameWnd();
	
	pWnd->Create(NULL, NULL);
	p_hDCV = pWnd->GetDC()->GetSafeHdc();
	p_pDCV = pWnd->GetDC();
	
	SetDCPixelFormat(p_hDCV);
	p_hRC = wglCreateContext(p_hDCV);
}

CreateParentRC() i call in Doc constructor. InitDocTexture() put texture on my model and it’s works, but not for different view.

A crash indicates an unhandled exception such as accessing a memory location that doesn’t belong to you. It could be a driver issue. Can you locate which function causes a crash? And since we are talking about GL, which video card? Are you drivers up to date?