0
\$\begingroup\$

I am creating an application using Direct3D 9. I want to implement triple buffering with vsync. I can successfully create a graphics device object with 2 back buffers. How do I know which buffer to draw to?

EDIT:

Here is how I retrieve a pointer to the back buffer onto which I will draw using a deferred shading technique:

// graphics device object
IDirect3DDevice9 *pd3dDevice = GetDevice();

// back buffer pointer
IDirect3DSurface9 *pBackBuffer = null;

// get pointer to back buffer
pd3dDevice->GetBackBuffer(0, 1, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);

UPDATE: The application appears to run faster when I use a pointer to the first back buffer like so:

// graphics device object
IDirect3DDevice9 *pd3dDevice = GetDevice();

// back buffer pointer
IDirect3DSurface9 *pBackBuffer = null;

// get pointer to back buffer --- NOTICE THE Back Buffer Index parameter is now 0 ---
pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);

When using the back buffer at index 1 the frame rate falls to 30fps while using vsync. This produces artifacts and Horizontal Shearing. Using the back buffer at index 0 seems to be correct. When using this buffer the application presents a frame at the refresh rate of the monitor. Therefore in order to correctly implement triple buffering using Direct3D 9 you should draw to the back buffer at index 0.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

How do I know which buffer to draw to?

You don't. Direct3D will automatically manage this for you and correctly rotate the back buffers at Present time.

\$\endgroup\$
2
  • \$\begingroup\$ I implement deferred shading in my application...retrieving a pointer to the back buffer (onto which I will draw ) is necessary. Do I simply get a pointer to the '2nd' back buffer? See code above... \$\endgroup\$
    – P. Avery
    Mar 8, 2015 at 20:59
  • \$\begingroup\$ So long as you make this call each frame you will get the correct backbuffer - whichever one is current. You shouldn't expect it to be correct if you reuse the same pointer over multiple frames. \$\endgroup\$ Mar 8, 2015 at 21:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .