A few DirectDraw questions

Started by
1 comment, last by Densun 23 years, 7 months ago
What will cause surfaces to be lost, so that I need to call the Restore function? When I change the resolution of the screen, can I call the Restore function for the back and front buffer? If I set up a flipping double buffer, do both the front and the back surface need to be in the same memory space (such as either in video memory or system memory)?
Advertisement
1. I think surfaces are often lost when your application loses focus. But, to be on the safe side, all you need to do is add the following after blt, flip, etc. functions:

    HRESULT hRet;hRet = Surface->Blt(...);if (hRet != DD_OK)   RestoreAllSurfaces();    


2. You should be able to, but I am not sure about this one.

3. I don''t think so. DirectDraw handles all of the surface location stuff I''m pretty sure, it''s just that the surfaces in video memory are faster, so if there isn''t enough video memory for all the surfaces in the flipping chain, it should be slower.
1) Video memory and AGP memory is a shared resource throughout the entire system. Another application may gain focus and allocate video memory surfaces, causing some of your surfaces to be freed. You can check WM_ACTIVATEAPP messages to see when the user alt-tab''s back into your application.

2)No, Restore() is to only reclaim lost video memory. You should probably destroy the primary surface and back buffer, and then recreate if you change the resolution.

3)Hmm, the DDraw HEL may emulate a sys-memory back buffer to vid-memory front buffer flip, but you wouldn''t want to do that. Performance would be worse (a massive copy of bits over the bus to the video card.) Also, if it may be expected that the primary surface''s bits be in the back buffer after the flip (I don''t know if the contents of the back buffer are defined or undefined after a flip) which would result in reading from video memory (which is even slower than writing to video memory.)

If you want a system memory back buffer (which you want only if you absolutely need to read and write the surface frequently), do a Blt yourself, don''t flip. Normally, place both in video memory.

This topic is closed to new replies.

Advertisement