Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: OpenGL RC Sharing (wglShareList)

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2011
    Posts
    4

    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:
    Code :
     
    int CProcKLView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    ...
    	hRCChild1 = wglCreateContext(m_pCDC->GetSafeHdc());			
    	GetDocument()->ContextShareList(hRCChild1);
     
    	wglMakeCurrent(m_pCDC->GetSafeHdc(), hRCChild1);						
     
    ...
    }

    In Doc i have:
    Code :
    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?

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: OpenGL RC Sharing (wglShareList)

    can I share context between two windows?
    You sure can if true from wglShareLists.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Member Regular Contributor
    Join Date
    Dec 2007
    Posts
    250

    Re: OpenGL RC Sharing (wglShareList)

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

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2011
    Posts
    4

    Re: OpenGL RC Sharing (wglShareList)

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

  5. #5
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: OpenGL RC Sharing (wglShareList)

    yup
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  6. #6
    Junior Member Newbie
    Join Date
    Jul 2011
    Posts
    4

    Re: OpenGL RC Sharing (wglShareList)

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

    View:
    Code :
    	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:
    Code :
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •