Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SSW_8_11.doc
Скачиваний:
2
Добавлен:
01.05.2025
Размер:
5 Мб
Скачать
☆

Optimizations and Customizations

All of the DirectDraw samples supplied with this SDK are relatively simple and assume a lot of things about the system they are running on. This section examines the following optimizations and customizations to the samples that will allow your code to work better in real-world situations:

  • Getting the Flip and Blit Status

  • Blitting with Color Fill

  • Determining the Capabilities of the Display Hardware

  • Storing Bitmaps in Display Memory

  • Triple Buffering

Getting the Flip and Blit Status

When the IDirectDrawSurface2::Flip method is called, the primary surface and back buffer are exchanged. However, the exchange may not occur immediately. For example, if a previous flip has not finished, or if it did not succeed, this method returns DDERR_WASSTILLDRAWING. In the samples included with this SDK, the IDirectDrawSurface2::Flip call continues to loop until it returns DD_OK. Also, a IDirectDrawSurface2::Flip call does not complete immediately. It schedules a flip for the next time a vertical blank occurs on the system.

An application that waits until the DDERR_WASSTILLDRAWING value is not returned is very inefficient. Instead, you could create a function in your application that calls the IDirectDrawSurface2::GetFlipStatus method on the back buffer to determine if the previous flip has finished.

If the previous flip has not finished and the call returns DDERR_WASSTILLDRAWING, your application can use the time to perform another task before it checks the status again. Otherwise, you can perform the next flip. The following example demonstrates this concept:

while(lpDDSBack->GetFlipStatus(DDGFS_ISFLIPDONE) ==

DDERR_WASSTILLDRAWING);

// Waiting for the previous flip to finish. The application can

// perform another task here.

ddrval = lpDDSPrimary->Flip(NULL, 0);

You can use the IDirectDrawSurface2::GetBltStatus method in much the same way to determine whether a blit has finished. Because IDirectDrawSurface2::GetFlipStatus and IDirectDrawSurface2::GetBltStatus return immediately, you can use them periodically in your application with little loss in speed.

Blitting with Color Fill

You can use the IDirectDrawSurface2::Blt method to perform a color fill of the most common color you want to be displayed. For example, if the most common color your application displays is blue, you can use IDirectDrawSurface2::Blt with the DDBLT_COLORFILL flag to first fill the surface with the color blue. Then you can write everything else on top of it. This allows you to fill in the most common color very quickly, and you then only have to write a minimum number of colors to the surface.

The following example demonstrates one way to perform a color fill:

DDBLTFX ddbltfx;

ddbltfx.dwSize = sizeof(ddbltfx);

ddbltfx.dwFillColor = 0;

ddrval = lpDDSPrimary->Blt(

NULL, // Destination

NULL, NULL, // Source rectangle

DDBLT_COLORFILL, &ddbltfx);

switch(ddrval)

{ case DDERR_WASSTILLDRAWING:

.

case DDERR_SURFACELOST:

.

case DD_OK:

.

default:

}

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]