locked
copy frontbuffer to backbuffer

    Question

  • Hi,

    how can one copy the data of the frontbuffer to the backbuffer? In my case I'm using the Direct2D-app template. Thx for your answers!

    Tuesday, June 11, 2013 4:10 PM

Answers

  • Hi, get data from the front buffer is always a bad idea due to performance issue, you need to copy your back buffer before you flip (Present method) the back buffer to the front buffer.. or just perform all your drawings to an off screen bitmap an then blit it (CopyFromBitmap method) or draw it to the back buffer.

    Wednesday, June 12, 2013 1:15 PM
  • Thank you for your answer! I've added the functionality I wanted. Here's my solution if anyone is interested:

    void Renderer::Render()
    {
    	m_d2dContext->BeginDraw();
    
    	if(cleared)
    	{
    		m_d2dContext->DrawBitmap(m_d2dCopyBitmap, &D2D1::RectF(0,0, m_d2dCopyBitmap->GetSize().width, m_d2dCopyBitmap->GetSize().height));
    	}
    	else
    	{
    		m_d2dContext->Clear(ColorF(ColorF::White));
    		cleared = true;
    	}
    
    //Drawing stuff
    
    	HRESULT hr = m_d2dContext->EndDraw();
    	if (hr != D2DERR_RECREATE_TARGET)
    	{
    		DX::ThrowIfFailed(hr);
    	}
    
    	m_d2dCopyBitmap->CopyFromRenderTarget(&D2D1::Point2U(0, 0),m_d2dContext.Get(), &D2D1::RectU(0, 0, m_d2dCopyBitmap->GetSize().width, m_d2dCopyBitmap->GetSize().height));
    
    	m_renderNeeded = false;
    }

    Wednesday, June 12, 2013 5:03 PM

All replies

  • Can you explain WHY you want to do this? Better yet, WHAT are you trying to do that makes you think you'd want to copy Front to Back?
    Tuesday, June 11, 2013 5:40 PM
  • The reason why I want to do this is simple. The content of the frontbuffer is essential for the next frame that is rendered. The next frame will only be the previous one with additional geometries, but it takes to long to draw all of them again. My app is going to draw fractals and it's not possible to draw the amount of lines and geometries at once.
    Tuesday, June 11, 2013 7:05 PM
  • Hi, get data from the front buffer is always a bad idea due to performance issue, you need to copy your back buffer before you flip (Present method) the back buffer to the front buffer.. or just perform all your drawings to an off screen bitmap an then blit it (CopyFromBitmap method) or draw it to the back buffer.

    Wednesday, June 12, 2013 1:15 PM
  • Thank you for your answer! I've added the functionality I wanted. Here's my solution if anyone is interested:

    void Renderer::Render()
    {
    	m_d2dContext->BeginDraw();
    
    	if(cleared)
    	{
    		m_d2dContext->DrawBitmap(m_d2dCopyBitmap, &D2D1::RectF(0,0, m_d2dCopyBitmap->GetSize().width, m_d2dCopyBitmap->GetSize().height));
    	}
    	else
    	{
    		m_d2dContext->Clear(ColorF(ColorF::White));
    		cleared = true;
    	}
    
    //Drawing stuff
    
    	HRESULT hr = m_d2dContext->EndDraw();
    	if (hr != D2DERR_RECREATE_TARGET)
    	{
    		DX::ThrowIfFailed(hr);
    	}
    
    	m_d2dCopyBitmap->CopyFromRenderTarget(&D2D1::Point2U(0, 0),m_d2dContext.Get(), &D2D1::RectU(0, 0, m_d2dCopyBitmap->GetSize().width, m_d2dCopyBitmap->GetSize().height));
    
    	m_renderNeeded = false;
    }

    Wednesday, June 12, 2013 5:03 PM