DXGL r488 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r487‎ | r488 | r489 >
Date:11:59, 16 August 2014
Author:admin
Status:new
Tags:
Comment:
Add 90 degree rotated Blt() support.
Modified paths:
  • /ddraw/glRenderer.cpp (modified) (history)
  • /dxgltest/Tests2D.cpp (modified) (history)
  • /dxgltest/dxgltest.cpp (modified) (history)
  • /dxgltest/surfacegen.cpp (modified) (history)
  • /dxgltest/surfacegen.h (modified) (history)

Diff [purge]

Index: ddraw/glRenderer.cpp
@@ -1094,6 +1094,48 @@
10951095 vertices[3].t = t2;
10961096 }
10971097
 1098+void RotateBlt90(BltVertex *vertices, int times)
 1099+{
 1100+ GLfloat s0, s1, s2, s3;
 1101+ GLfloat t0, t1, t2, t3;
 1102+ switch (times)
 1103+ {
 1104+ case 0:
 1105+ default:
 1106+ return;
 1107+ case 1:
 1108+ s0 = vertices[0].s; t0 = vertices[0].t;
 1109+ s1 = vertices[1].s; t1 = vertices[1].t;
 1110+ s2 = vertices[2].s; t2 = vertices[2].t;
 1111+ s3 = vertices[3].s; t3 = vertices[3].t;
 1112+ vertices[0].s = s1; vertices[0].t = t1;
 1113+ vertices[1].s = s3; vertices[1].t = t3;
 1114+ vertices[2].s = s0; vertices[2].t = t0;
 1115+ vertices[3].s = s2; vertices[3].t = t2;
 1116+ break;
 1117+ case 2:
 1118+ s0 = vertices[0].s; t0 = vertices[0].t;
 1119+ s1 = vertices[1].s; t1 = vertices[1].t;
 1120+ s2 = vertices[2].s; t2 = vertices[2].t;
 1121+ s3 = vertices[3].s; t3 = vertices[3].t;
 1122+ vertices[0].s = s3; vertices[0].t = t3;
 1123+ vertices[1].s = s2; vertices[1].t = t2;
 1124+ vertices[2].s = s1; vertices[2].t = t1;
 1125+ vertices[3].s = s0; vertices[3].t = t0;
 1126+ break;
 1127+ case 3:
 1128+ s0 = vertices[0].s; t0 = vertices[0].t;
 1129+ s1 = vertices[1].s; t1 = vertices[1].t;
 1130+ s2 = vertices[2].s; t2 = vertices[2].t;
 1131+ s3 = vertices[3].s; t3 = vertices[3].t;
 1132+ vertices[0].s = s2; vertices[0].t = t2;
 1133+ vertices[1].s = s0; vertices[1].t = t0;
 1134+ vertices[2].s = s3; vertices[2].t = t3;
 1135+ vertices[3].s = s1; vertices[3].t = t1;
 1136+ break;
 1137+ }
 1138+}
 1139+
10981140 void glRenderer__Blt(glRenderer *This, LPRECT lpDestRect, glDirectDrawSurface7 *src,
10991141 glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
11001142 {
@@ -1178,6 +1220,7 @@
11791221 rotates &= 3;
11801222 if (rotates)
11811223 {
 1224+ RotateBlt90(This->bltvertices, rotates);
11821225 }
11831226 }
11841227 if (dwFlags & 0x10000000)
Index: dxgltest/Tests2D.cpp
@@ -629,7 +629,7 @@
630630 ddsrender->GetSurfaceDesc(&ddsd);
631631 ddsrender->GetPalette(&palette);
632632 sprites[0].ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
633 - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
 633+ sprites[0].ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
634634 if (ddver > 3) sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC2);
635635 else sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC);
636636 memcpy(&sprites[1], &sprites[0], sizeof(DDSPRITE));
@@ -665,6 +665,18 @@
666666 ddcaps.dwSize = sizeof(DDCAPS);
667667 ddinterface->GetCaps(&ddcaps, NULL);
668668 DrawROPPatterns(ddsrender, sprites, backbuffers, ddver, bpp, ddcaps.dwRops,hWnd,palette);
 669+ break;
 670+ case 8:
 671+ ddsrender->GetSurfaceDesc(&ddsd);
 672+ sprites[0].ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 673+ sprites[0].ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
 674+ if (ddver > 3) sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC2);
 675+ else sprites[0].ddsd.dwSize = sizeof(DDSURFACEDESC);
 676+ sprites[0].ddsd.dwWidth = sprites[0].ddsd.dwHeight =
 677+ sprites[0].rect.right = sprites[0].rect.bottom = 64;
 678+ ddinterface->CreateSurface(&sprites[0].ddsd, &sprites[0].surface, NULL);
 679+ DrawRotatedBlt(ddsrender, sprites);
 680+ break;
669681 }
670682 }
671683
Index: dxgltest/dxgltest.cpp
@@ -226,7 +226,8 @@
227227 {1, 7, 0, 1, true, 60.0, false, false, _T("BltFast background and sprites")},
228228 {1, 7, 0, 0, false, 0.0, false, false, _T("Random color fill Blt() paterns")},
229229 {1, 7, 0, 0, false, 0.0, false, false, _T("Mouse pointer event test")},
230 - {1, 7, 1, 1, true, 1.0, false, false, _T("Raster Operation Blt() test")}
 230+ {1, 7, 1, 1, true, 1.0, false, false, _T("Raster Operation Blt() test")},
 231+ {1, 7, 0, 0, false, 0.0, false, false, _T("Mirrored and Rotated Blt() test")}
231232 };
232233 const int END_2D = __LINE__ - 4;
233234 const int numtests2d = END_2D - START_2D;
@@ -383,7 +384,9 @@
384385 case IDC_TEST:
385386 if(SendDlgItemMessage(hWnd,IDC_RESIZABLE,BM_GETCHECK,0,0)) resizable2d = true;
386387 else resizable2d = false;
387 - i = SendDlgItemMessage(hWnd,IDC_VIDMODES,LB_GETCURSEL,0,0);
 388+ if (buffer2d < minbuffer2d) buffer2d = minbuffer2d;
 389+ if (buffer2d > maxbuffer2d) buffer2d = maxbuffer2d;
 390+ i = SendDlgItemMessage(hWnd, IDC_VIDMODES, LB_GETCURSEL, 0, 0);
388391 SendDlgItemMessage(hWnd,IDC_VIDMODES,LB_GETTEXT,i,(LPARAM)tmpstring);
389392 TranslateResolutionString(tmpstring,width,height,bpp,refresh);
390393 RunTest2D(currenttest2d,width,height,bpp,refresh,buffer2d,api2d,framerate2d,fullscreen2d,resizable2d);
Index: dxgltest/surfacegen.cpp
@@ -1121,4 +1121,87 @@
11221122 back->Release();
11231123 }
11241124 free(bmi);
 1125+}
 1126+
 1127+void DrawRotatedBlt(MultiDirectDrawSurface *primary, DDSPRITE *sprites)
 1128+{
 1129+ HDC hdc;
 1130+ DDBLTFX bltfx;
 1131+ ZeroMemory(&bltfx, sizeof(DDBLTFX));
 1132+ bltfx.dwSize = sizeof(DDBLTFX);
 1133+ sprites[0].surface->GetDC(&hdc);
 1134+ DrawBitmap(hdc, 0, 0, 64, 64, MAKEINTRESOURCE(IDB_DXGLINV64), SRCCOPY);
 1135+ sprites[0].surface->ReleaseDC(hdc);
 1136+ RECT r;
 1137+ r.left = 0;
 1138+ r.right = 64;
 1139+ r.top = 0;
 1140+ r.bottom = 64;
 1141+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1142+ r.left = 64;
 1143+ r.right = 128;
 1144+ bltfx.dwDDFX = DDBLTFX_MIRRORLEFTRIGHT;
 1145+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1146+ r.left = 128;
 1147+ r.right = 192;
 1148+ bltfx.dwDDFX = DDBLTFX_MIRRORUPDOWN;
 1149+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1150+ r.left = 192;
 1151+ r.right = 256;
 1152+ bltfx.dwDDFX = DDBLTFX_MIRRORLEFTRIGHT | DDBLTFX_MIRRORUPDOWN;
 1153+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1154+ r.top = 64;
 1155+ r.bottom = 128;
 1156+ r.left = 0;
 1157+ r.right = 64;
 1158+ bltfx.dwDDFX = DDBLTFX_ROTATE90;
 1159+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1160+ r.left = 64;
 1161+ r.right = 128;
 1162+ bltfx.dwDDFX = DDBLTFX_ROTATE90 | DDBLTFX_MIRRORLEFTRIGHT;
 1163+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1164+ r.left = 128;
 1165+ r.right = 192;
 1166+ bltfx.dwDDFX = DDBLTFX_ROTATE90 | DDBLTFX_MIRRORUPDOWN;
 1167+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1168+ r.left = 192;
 1169+ r.right = 256;
 1170+ bltfx.dwDDFX = DDBLTFX_ROTATE90 | DDBLTFX_MIRRORLEFTRIGHT | DDBLTFX_MIRRORUPDOWN;
 1171+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1172+ r.top = 128;
 1173+ r.bottom = 192;
 1174+ r.left = 0;
 1175+ r.right = 64;
 1176+ bltfx.dwDDFX = DDBLTFX_ROTATE180;
 1177+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1178+ r.left = 64;
 1179+ r.right = 128;
 1180+ bltfx.dwDDFX = DDBLTFX_ROTATE180 | DDBLTFX_MIRRORLEFTRIGHT;
 1181+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1182+ r.left = 128;
 1183+ r.right = 192;
 1184+ bltfx.dwDDFX = DDBLTFX_ROTATE180 | DDBLTFX_MIRRORUPDOWN;
 1185+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1186+ r.left = 192;
 1187+ r.right = 256;
 1188+ bltfx.dwDDFX = DDBLTFX_ROTATE180 | DDBLTFX_MIRRORLEFTRIGHT | DDBLTFX_MIRRORUPDOWN;
 1189+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1190+ r.top = 192;
 1191+ r.bottom = 256;
 1192+ r.left = 0;
 1193+ r.right = 64;
 1194+ bltfx.dwDDFX = DDBLTFX_ROTATE270;
 1195+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1196+ r.left = 64;
 1197+ r.right = 128;
 1198+ bltfx.dwDDFX = DDBLTFX_ROTATE270 | DDBLTFX_MIRRORLEFTRIGHT;
 1199+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1200+ r.left = 128;
 1201+ r.right = 192;
 1202+ bltfx.dwDDFX = DDBLTFX_ROTATE270 | DDBLTFX_MIRRORUPDOWN;
 1203+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
 1204+ r.left = 192;
 1205+ r.right = 256;
 1206+ bltfx.dwDDFX = DDBLTFX_ROTATE270 | DDBLTFX_MIRRORLEFTRIGHT | DDBLTFX_MIRRORUPDOWN;
 1207+ primary->Blt(&r, sprites[0].surface, NULL, DDBLT_DDFX, &bltfx);
11251208 }
\ No newline at end of file
Index: dxgltest/surfacegen.h
@@ -24,5 +24,6 @@
2525 void DrawGDIPatterns(DDSURFACEDESC2 ddsd, HDC hDC, int type); // GDI pattern test
2626 void DrawROPPatterns(MultiDirectDrawSurface *primary, DDSPRITE *sprites, int backbuffers, int ddver, int bpp, DWORD *ropcaps,
2727 HWND hwnd, LPDIRECTDRAWPALETTE palette); // ROP pattern test
 28+void DrawRotatedBlt(MultiDirectDrawSurface *primary, DDSPRITE *sprites);
2829
2930 #endif //_SURFACEGEN_H
\ No newline at end of file