Archived

This topic is now archived and is closed to further replies.

How does one take advantage of triple buffering??

This topic is 6008 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I still don't understand what I have to do in my code to take advantage of Triple Buffering (GIVEN that 2 backbuffers have already been setup with primary surface when it was created at startup). Can I just do: lpFrontBuffer->Flip( NULL, DDFLIP_WAIT ); then when it returns I go on drawing in lpBackBuffer? At least that's what I did when I used to use Double Buffering. Or do I have to process HRESULT returned by Flip() in the case of Triple Buffering? I hear that the whole point of triple buffering is that I can draw in 2nd backbuffer "even while waiting for flip to take place". Does that mean that I have to keep on reading every error returned by Flip() without using DDFLIP_WAIT flag?? Please drop a note or two regarding any of these matters... I really need help, I have so far failed to find an answer to this anywhere. Edited by - PugPenguin on June 28, 2001 6:08:47 PM

Share this post


Link to post
Share on other sites
I believe the advantage of Triple Buffering is in multi-threading. You can have a seperate thread running which will be drawing the next frame while the primary thread is waiting for refresh and flipping the buffers. Then when the flip is done you switch your 2nd and 3rd buffers and do it again

Not sure the exact way to do it in DX but in general I believe that is how it is done.

Seeya
Krippy

Share this post


Link to post
Share on other sites
Krippy2k's post is pretty much correct, but to be totally clear, you don't need to do multithreading (in your app) to take advantage of triple buffering.

The big benefit to triple buffering is that you can draw to the third buffer in your app while the video card hardware is flipping the second buffer to the front buffer. In a double-buffering situation, you'd be locked out from doing that, unless you disabled vsync, which can cause some nasty tearing.

Of course the downside is you use up significantly more video memory, especially in very high resolution modes.

The real answer to your question is you don't have to do anything special to take advantage of triple buffering. Just turn it on, if the card supports it, and write to the backbuffer as you would normally. Flip, when called with DDFLIP_WAIT and in a multiple-backbuffer situation, will return as soon as the furthest backbuffer is available for drawing (so, hopefully, immediatelly). Let DirectX worry about the specifics.


Edited by - gmcbay on June 28, 2001 12:19:04 AM

Share this post


Link to post
Share on other sites
Yes, I do understand the "concept" of multi-threading regarding Triple buffering. What I didn''t know was HOW it''s applied in practice when dealing with DirectX.

Thank you for replying Krippy2k and gmcbay, I think I get it now. So basically, what you are saying is that I don''t have to write my own code to make my render function draw in back-most surface when Flip() returns DDFLIP_WASSTILLDRAWING (and other errors)? DirectDraw automatically starts another thread which it uses to wait for Vertical blank? And hence, from my point of view, I can just do "single thread programing" just like when using Double Buffering?

If I''m not being very clear above... another way to ask this question is, Can I program flip & render routine just like when I use a single backbuffer?

Share this post


Link to post
Share on other sites
Yes. Just write to the back buffer that DirectX gives you and flip as usual.

The benefit of triple buffering will more or less automagically be granted by DirectX by way of having Flip return faster on average (because the third buffer is decoupled from worrying about the vblank).

Of course, as a side note, rather than using DDFLIP_WAIT your code could get complex (in either a 3 or 2 buffer situation) and NOT wait, and if it gets a "still drawing" message it could spend the time doing something else like doing some physics calculations for the next frame or such. Using triple buffering reduces the practical usefulness of doing this, but as I''m sure you know true triple buffering isn''t always supported in hardware, especially when dealing with high res modes (because of lack of video mem to hold all the buffers).

Share this post


Link to post
Share on other sites
Nice. So long as there''s hardware support, benefit of tripple buffering is pretty much automatic then. Not just that, I can see it''s easy to write a code which works both for double and tripple buffering... so we can give users a choice.

Thanks, it''s crystal clear now... there''s no apparent document that seems to discuss this issue regarding the implementation aspect of DirectDraw flip(). Dx SDK suplements only explains the reason WHY tripple buffering can provide an advantage... which I had known anyway. As for sample codes, they only used a single backbuffer.

Thank you again.

Share this post


Link to post
Share on other sites