PDA

View Full Version : OpenGL RC Sharing (wglShareList)



SimpleMan
07-28-2011, 02:38 AM
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?

V-man
07-28-2011, 08:31 AM
can I share context between two windows?
You sure can if true from wglShareLists.

dukey
07-28-2011, 09:31 AM
assuming the windows are the same pixel format, it should work

SimpleMan
07-29-2011, 01:15 AM
But it's ok when one is a CMDIFrameWnd and the other is CMDIChildWnd ?

V-man
07-29-2011, 09:25 AM
yup

SimpleMan
08-01-2011, 05:04 AM
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.

V-man
08-01-2011, 07:11 AM
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?