DXGL r624 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r623‎ | r624 | r625 >
Date:15:50, 1 November 2015
Author:admin
Status:new
Tags:
Comment:
Add dithered effect to background of BltFast test, to better test destination color keys.
Modified paths:
  • /dxgltest/Tests2D.cpp (modified) (history)
  • /dxgltest/surfacegen.cpp (modified) (history)
  • /dxgltest/surfacegen.h (modified) (history)

Diff [purge]

Index: dxgltest/Tests2D.cpp
@@ -577,6 +577,7 @@
578578 error = sprites[0].surface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
579579 if(palette) palette->Release();
580580 DrawGradients(ddsd, (unsigned char *)ddsd.lpSurface, hWnd, palette, 1, 0);
 581+ DrawDitheredColor(&ddsd, (unsigned char *)ddsd.lpSurface, 0, FALSE);
581582 error = sprites[0].surface->Unlock(NULL);
582583 sprites[0].width = (float)ddsd.dwWidth;
583584 sprites[0].height = (float)ddsd.dwHeight;
@@ -697,6 +698,8 @@
698699 {
699700 if(stoptimer) return;
700701 DDSCAPS2 ddscaps;
 702+ DDBLTFX bltfx;
 703+ bltfx.dwSize = sizeof(DDBLTFX);
701704 ZeroMemory(&ddscaps,sizeof(DDSCAPS2));
702705 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
703706 MultiDirectDrawSurface *temp1 = NULL;
@@ -707,7 +710,12 @@
708711 default:
709712 if(fullscreen) ddsurface->Flip(NULL,DDFLIP_WAIT);
710713 break;
711 - case 4: // FastBlt sprites
 714+ case 4: // BltFast sprites
 715+ if (backbuffers) ddsrender->GetAttachedSurface(&ddscaps, &temp1);
 716+ else temp1 = ddsrender;
 717+ bltfx.dwFillColor = 0;
 718+ temp1->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &bltfx);
 719+ if (backbuffers) temp1->Release();
712720 for(int i = 0; i < 16; i++)
713721 {
714722 sprites[i].x += sprites[i].xvelocity;
Index: dxgltest/surfacegen.cpp
@@ -281,6 +281,83 @@
282282 }
283283 }
284284
 285+void DrawDitheredColor(DDSURFACEDESC2 *ddsd, unsigned char *buffer, DWORD color, BOOL invert)
 286+{
 287+ DWORD *dwordptr = (DWORD*)buffer;
 288+ WORD *wordptr = (WORD*)buffer;
 289+ DWORD ptr;
 290+ BOOL pixel;
 291+ DWORD x, y;
 292+ switch (ddsd->ddpfPixelFormat.dwRGBBitCount)
 293+ {
 294+ default:
 295+ case 8:
 296+ for (y = 0; y < ddsd->dwHeight; y++)
 297+ {
 298+ ptr = ddsd->lPitch * y;
 299+ if (y & 1) pixel = TRUE;
 300+ else pixel = FALSE;
 301+ if (invert) pixel ^= 1;
 302+ for (x = 0; x < ddsd->dwWidth; x++)
 303+ {
 304+ if (pixel) buffer[ptr] = (unsigned char)color;
 305+ pixel ^= 1;
 306+ ptr++;
 307+ }
 308+ }
 309+ break;
 310+ case 15:
 311+ case 16:
 312+ for (y = 0; y < ddsd->dwHeight; y++)
 313+ {
 314+ ptr = (ddsd->lPitch / 2) * y;
 315+ if (y & 1) pixel = TRUE;
 316+ else pixel = FALSE;
 317+ if (invert) pixel ^= 1;
 318+ for (x = 0; x < ddsd->dwWidth; x++)
 319+ {
 320+ if (pixel) wordptr[ptr] = (WORD)color;
 321+ pixel ^= 1;
 322+ ptr++;
 323+ }
 324+ }
 325+ break;
 326+ case 24:
 327+ for (y = 0; y < ddsd->dwHeight; y++)
 328+ {
 329+ ptr = ddsd->lPitch * y;
 330+ if (y & 1) pixel = TRUE;
 331+ else pixel = FALSE;
 332+ if (invert) pixel ^= 1;
 333+ for (x = 0; x < ddsd->dwWidth; x++)
 334+ {
 335+ if (pixel) buffer[ptr] = (unsigned char)(color & 255);
 336+ ptr++;
 337+ if (pixel) buffer[ptr] = (unsigned char)((color >> 8) & 255);
 338+ ptr++;
 339+ if (pixel) buffer[ptr] = (unsigned char)((color >> 16) & 255);
 340+ pixel ^= 1;
 341+ ptr++;
 342+ }
 343+ }
 344+ break;
 345+ case 32:
 346+ for (y = 0; y < ddsd->dwHeight; y++)
 347+ {
 348+ ptr = (ddsd->lPitch / 4) * y;
 349+ if (y & 1) pixel = TRUE;
 350+ else pixel = FALSE;
 351+ if (invert) pixel ^= 1;
 352+ for (x = 0; x < ddsd->dwWidth; x++)
 353+ {
 354+ if (pixel) dwordptr[ptr] = (DWORD)color;
 355+ pixel ^= 1;
 356+ ptr++;
 357+ }
 358+ }
 359+ break;
 360+ }
 361+}
285362
286363 void DrawGradient(HDC hdc, int left, int right, int top, int bottom, DWORD color, bool usegdi)
287364 {
Index: dxgltest/surfacegen.h
@@ -20,6 +20,7 @@
2121 #define _SURFACEGEN_H
2222
2323 void DrawPalette(DDSURFACEDESC2 ddsd, unsigned char *buffer); // Palette test
 24+void DrawDitheredColor(DDSURFACEDESC2 *ddsd, unsigned char *buffer, DWORD color, BOOL invert); // Draw a dithered color over the surface
2425 void DrawGradients(DDSURFACEDESC2 ddsd, unsigned char *buffer, HWND hwnd, LPDIRECTDRAWPALETTE palette, int type, DWORD color); // Gradients
2526 void DrawGDIPatterns(DDSURFACEDESC2 ddsd, HDC hDC, int type); // GDI pattern test
2627 void DrawROPPatterns(MultiDirectDrawSurface *primary, DDSPRITE *sprites, int backbuffers, int ddver, int bpp, DWORD *ropcaps,