10 __int16 *found_compatible_mode) {
11 if (pSurfaceDesc->ddsCaps.dwCaps | DDSCAPS_3DDEVICE) {
12 *found_compatible_mode = 1;
19 const GUID *lpGUID,
const char *lpDeviceDesc,
const char *lpDeviceName,
20 D3DDEVICEDESC *pHWDesc, D3DDEVICEDESC *pSWDesc,
RenderD3D_aux *a6) {
22 if (pHWDesc->dwFlags) {
24 if (pHWDesc->dwFlags && a6->
ptr_4->
pGUID) v7 = 1;
26 if (!strcmp(lpDeviceName,
"RGB Emulation") && !a6->
ptr_4->
pGUID) v7 = 2;
27 if (!strcmp(lpDeviceName,
"Reference Rasterizer") && !a6->
ptr_4->
pGUID)
32 if (!(pHWDesc->dpcTriCaps.dwSrcBlendCaps & 0x10))
34 if (!(pHWDesc->dpcTriCaps.dwSrcBlendCaps & 2)) a6->
pInfo[v7].
uCaps |= 4;
35 if (!(pHWDesc->dpcTriCaps.dwSrcBlendCaps & 1)) a6->
pInfo[v7].
uCaps |= 8;
36 if (!(pHWDesc->dpcTriCaps.dwDestBlendCaps & 0x20))
38 if (!(pHWDesc->dpcTriCaps.dwDestBlendCaps & 2))
40 if (!(pHWDesc->dpcTriCaps.dwDestBlendCaps & 4))
42 if (!(pHWDesc->dwDevCaps & 0x1000)) a6->
pInfo[v7].
uCaps |= 0x100;
43 if (pHWDesc->dpcTriCaps.dwTextureCaps & 0x20)
46 a6->
pInfo[v7].
pName =
new char[strlen(lpDeviceName) + 1];
71 const char *lpDriverName,
75 DDDEVICEIDENTIFIER ddDevId;
78 unsigned int uFreeVideoMem;
80 IDirect3D3 *pDirect3D3;
81 int is_there_a_compatible_screen_mode;
82 IDirectDraw4 *pDirectDraw4;
85 size_t v4 = strlen(lpDriverName);
87 v5 = strlen(lpDevDesc);
93 memcpy(v20.
pGUID, lpGUID, 0x10);
98 LPDIRECTDRAW pDirectDraw =
nullptr;
99 if (FAILED(DirectDrawCreate(v20.
pGUID, &pDirectDraw, 0))) {
104 if (FAILED(pDirectDraw->QueryInterface(IID_IDirectDraw4,
105 (LPVOID *)&pDirectDraw4))) {
109 pDirectDraw->Release();
111 pDirectDraw->Release();
112 if (FAILED(pDirectDraw4->GetDeviceIdentifier(&ddDevId, 1))) {
115 v7 = strlen(ddDevId.szDescription);
119 memset(&ddsCaps, 0,
sizeof(ddsCaps));
120 if (FAILED(pDirectDraw4->GetAvailableVidMem(
122 (LPDWORD)&uFreeVideoMem)))
124 memset(&v10, 0,
sizeof(v10));
127 v10.dwHeight =
window->GetWidth();
128 v10.dwWidth =
window->GetHeight();
129 v10.ddpfPixelFormat.dwSize = 32;
131 is_there_a_compatible_screen_mode =
false;
132 if (FAILED(pDirectDraw4->EnumDisplayModes(
133 0, 0, &is_there_a_compatible_screen_mode,
135 !is_there_a_compatible_screen_mode ||
136 FAILED(pDirectDraw4->QueryInterface(IID_IDirect3D3,
137 (LPVOID *)&pDirect3D3))) {
143 pDirectDraw4->Release();
147 pDirect3D3->EnumDevices(
153 pDirectDraw4->Release();
155 pDirect3D3->Release();
163 DDPIXELFORMAT *Dst) {
164 if (Src->dwFlags & (0x400 | 0x2000)) {
165 if (Src->dwRGBBitCount == 16 && !Src->dwRBitMask) {
166 memcpy(Dst, Src,
sizeof(DDPIXELFORMAT));
170 memcpy(Dst, Src,
sizeof(DDPIXELFORMAT));
182 memset(
v2, 0,
sizeof(
v2));
184 *pOutDevices, DDENUM_ATTACHEDSECONDARYDEVICES);
188 this->
pHost =
nullptr;
190 this->
pUnk =
nullptr;
204 this->
pHost->RestoreDisplayMode();
205 this->
pHost->SetCooperativeLevel(this->
hWindow, DDSCL_NORMAL);
206 this->
pHost->FlipToGDISurface();
210 for (
int i = 0; i < 4; i++) {
256 this->
pUnk->Release();
286 this->
pHost->Release();
295 DDSURFACEDESC2 ddsd2;
297 IDirectDrawClipper *lpddclipper;
300 auto hWnd = (HWND)
window->GetWinApiHandle();
301 int game_width =
window->GetWidth();
302 int game_height =
window->GetHeight();
311 "Init - Failed to create DirectDraw interface.\n");
316 if (FAILED(lpDD->QueryInterface(IID_IDirectDraw4, (LPVOID *)&
pHost))) {
318 "Init - Failed to create DirectDraw4 interface.\n");
319 if (lpDD) lpDD->Release();
328 if (FAILED(
pHost->SetCooperativeLevel(
329 hWnd, DDSCL_MULTITHREADED | DDSCL_NORMAL))) {
330 sprintf(
pErrorMessage,
"Init - Failed to set cooperative level.\n");
339 memset(&ddsd2, 0,
sizeof(DDSURFACEDESC2));
340 ddsd2.dwSize =
sizeof(DDSURFACEDESC2);
341 ddsd2.dwFlags = DDSD_CAPS;
342 ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
345 sprintf(
pErrorMessage,
"Init - Failed to create front buffer.\n");
352 ddsd2.dwSize =
sizeof(DDSURFACEDESC2);
353 pHost->GetDisplayMode(&ddsd2);
355 ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
356 ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
357 ddsd2.dwWidth = game_width;
358 ddsd2.dwHeight = game_height;
360 sprintf(
pErrorMessage,
"Init - Failed to create back buffer.\n");
372 if (
pHost->CreateClipper(0, &lpddclipper, NULL)) {
373 sprintf(
pErrorMessage,
"Init - Failed to create clipper.\n");
388 lpddclipper->SetHWnd(0, hWnd);
391 lpddclipper->Release();
397 ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
398 ddsd2.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
399 ddsd2.dwWidth = game_width;
400 ddsd2.dwHeight = game_height;
404 (HRESULT(__stdcall *)(DDPIXELFORMAT *,
406 &ddsd2.ddpfPixelFormat)) {
408 "Init - Failed to enumerate Z buffer formats.\n");
423 if (uDeviceID == 2 || uDeviceID == 3)
424 ddsd2.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
431 memset(&d3dvp2, 0,
sizeof(D3DVIEWPORT2));
432 d3dvp2.dvClipWidth = 2.0;
433 d3dvp2.dvClipY = 1.0;
434 d3dvp2.dvClipHeight = 2.0;
439 sprintf(
pErrorMessage,
"Init - Failed to create D3D device.\n");
463 "Init - Failed to attach z-buffer to back buffer.\n");
482 sprintf(
pErrorMessage,
"Init - Failed to create z-buffer.\n");
501 if (
pHost->SetCooperativeLevel(hWnd, v26)) {
502 sprintf(
pErrorMessage,
"Init - Failed to set cooperative level.\n");
511 sprintf(
pErrorMessage,
"Init - Failed to set display mode.\n");
519 memset(&ddsd2, 0,
sizeof(DDSURFACEDESC2));
520 ddsd2.dwSize =
sizeof(DDSURFACEDESC2);
522 ddsd2.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
524 ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE |
525 DDSCAPS_FLIP | DDSCAPS_COMPLEX;
527 ddsd2.dwBackBufferCount = 1;
529 sprintf(
pErrorMessage,
"Init - Failed to create front buffer.\n");
538 memset(&v27, 0,
sizeof(DDSCAPS2));
540 v27.dwCaps = DDSCAPS_BACKBUFFER;
546 sprintf(
pErrorMessage,
"Init - Failed to get D3D interface.\n");
562 ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
563 ddsd2.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
565 ddsd2.dwHeight = 480;
568 (HRESULT(__stdcall *)(DDPIXELFORMAT *,
570 &ddsd2.ddpfPixelFormat)) {
572 "Init - Failed to enumerate Z buffer formats.\n");
587 if (uDeviceID == 2 || uDeviceID == 3) ddsd2.ddsCaps.dwCaps |= 8;
590 sprintf(
pErrorMessage,
"Init - Failed to create z-buffer.\n");
608 "Init - Failed to attach z-buffer to back buffer.\n");
630 sprintf(
pErrorMessage,
"Init - Failed to create D3D device.\n");
653 memset(&d3dvp2, 0,
sizeof(D3DVIEWPORT2));
654 d3dvp2.dvClipWidth = 2.0;
655 d3dvp2.dvClipY = 1.0;
656 d3dvp2.dvClipHeight = 2.0;
660 d3dvp2.dwSize =
sizeof(D3DVIEWPORT2);
662 d3dvp2.dwWidth = game_width;
663 d3dvp2.dwHeight = game_height;
664 d3dvp2.dvClipX = -1.0;
668 sprintf(
pErrorMessage,
"Init - Failed to create viewport.\n");
705 D3DDEVICEDESC refCaps;
706 D3DDEVICEDESC halCaps;
710 memset(&halCaps, 0,
sizeof(halCaps));
711 halCaps.dwSize =
sizeof(halCaps);
713 memset(&refCaps, 0,
sizeof(refCaps));
714 refCaps.dwSize =
sizeof(refCaps);
716 if (this->
pDevice->GetCaps(&halCaps, &refCaps)) {
719 if (!(halCaps.dpcTriCaps.dwSrcBlendCaps & D3DPBLENDCAPS_SRCALPHA))
721 if (!(halCaps.dpcTriCaps.dwSrcBlendCaps & D3DPBLENDCAPS_ONE))
v1 |= 4;
722 if (!(halCaps.dpcTriCaps.dwSrcBlendCaps & D3DPBLENDCAPS_ZERO))
v1 |= 8;
723 if (!(halCaps.dpcTriCaps.dwDestBlendCaps & D3DPBLENDCAPS_INVSRCALPHA))
725 if (!(halCaps.dpcTriCaps.dwDestBlendCaps & D3DPBLENDCAPS_ONE))
v1 |= 32;
726 if (!(halCaps.dpcTriCaps.dwDestBlendCaps & D3DPBLENDCAPS_SRCCOLOR))
728 if (halCaps.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY)
736 unsigned int bClearDepth,
float z_clear) {
737 unsigned int uClearFlags = 0;
739 if (bClearColor) uClearFlags |= D3DCLEAR_TARGET;
740 if (bClearDepth) uClearFlags |= D3DCLEAR_ZBUFFER;
744 pViewport->Clear2(1,
rects, uClearFlags, uClearColor, z_clear, 0);
749 struct tagPOINT
Point;
751 source_rect.left = 0;
755 source_rect.right = 640;
759 GetClientRect(
hWindow, &dest_rect);
773 unsigned int v3 = uDim - 1;
778 return v3 == 0 ?
v2 : 0;
782 unsigned int uTextureHeight,
783 IDirectDrawSurface4 **pOutSurface,
784 IDirect3DTexture2 **pOutTexture,
785 bool bAlphaChannel,
bool bMipmaps,
786 unsigned int uMinDeviceTexDim) {
787 DDSURFACEDESC2 ddsd2 = { 0 };
788 ddsd2.dwSize =
sizeof(ddsd2);
789 ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
790 ddsd2.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
791 ddsd2.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
792 ddsd2.dwHeight = uTextureHeight;
793 ddsd2.dwWidth = uTextureWidth;
795 if (uTextureHeight <= uTextureWidth) {
798 if (ddsd2.dwMipMapCount) {
799 ddsd2.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH |
800 DDSD_PIXELFORMAT | DDSD_MIPMAPCOUNT;
801 ddsd2.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
805 if (uTextureWidth < uMinDeviceTexDim) {
807 if (ddsd2.dwMipMapCount) {
808 ddsd2.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH |
809 DDSD_PIXELFORMAT | DDSD_MIPMAPCOUNT;
810 ddsd2.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
816 ddsd2.dwMipMapCount = v9 - v10;
817 if (ddsd2.dwMipMapCount == 0) {
818 ddsd2.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
819 ddsd2.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX;
823 ddsd2.dwMipMapCount = 1;
825 ddsd2.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT |
827 ddsd2.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
829 ddsd2.ddpfPixelFormat.dwRGBBitCount = 16;
830 ddsd2.ddpfPixelFormat.dwSize =
sizeof(DDPIXELFORMAT);
832 ddsd2.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
833 ddsd2.ddpfPixelFormat.dwRBitMask = 0x7C00;
834 ddsd2.ddpfPixelFormat.dwGBitMask = 0x03E0;
835 ddsd2.ddpfPixelFormat.dwBBitMask = 0x001F;
836 ddsd2.ddpfPixelFormat.dwRGBAlphaBitMask = 0x8000;
838 ddsd2.ddpfPixelFormat.dwFlags = DDPF_RGB;
839 ddsd2.ddpfPixelFormat.dwRBitMask = 0xF800;
840 ddsd2.ddpfPixelFormat.dwGBitMask = 0x07E0;
841 ddsd2.ddpfPixelFormat.dwBBitMask = 0x001F;
842 ddsd2.ddpfPixelFormat.dwRGBAlphaBitMask = 0;
844 if (FAILED(
pHost->CreateSurface(&ddsd2, pOutSurface, NULL))) {
848 if (FAILED((*pOutSurface)->QueryInterface(IID_IDirect3DTexture2, (
void**)pOutTexture))) {
849 (*pOutSurface)->Release();