DXGL r938 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r937‎ | r938 | r939 >
Date:22:47, 18 August 2019
Author:admin
Status:new
Tags:
Comment:
Rewrite EnumTextureFormats for D3D2 and below.
Add option (default true) to limit the number of texture formats in EnumTextureFormats (not yet implemented).
Modified paths:
  • /cfgmgr/cfgmgr.c (modified) (history)
  • /cfgmgr/cfgmgr.h (modified) (history)
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.h (modified) (history)
  • /dxgl-example.ini (modified) (history)
  • /dxglcfg/dxglcfg.cpp (modified) (history)
  • /dxglcfg/dxglcfg.rc (modified) (history)
  • /dxglcfg/resource.h (modified) (history)

Diff [purge]

Index: cfgmgr/cfgmgr.c
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2018 William Feely
 3+// Copyright (C) 2011-2019 William Feely
44 // Portions copyright (C) 2018 Syahmi Azhar
55
66 // This library is free software; you can redistribute it and/or
@@ -645,6 +645,7 @@
646646 cfg->aspect3d = ReadDWORD(hKey,cfg->aspect3d,&cfgmask->aspect3d,_T("AdjustAspectRatio"));
647647 cfg->LowColorRendering = ReadDWORD(hKey, cfg->LowColorRendering, &cfgmask->LowColorRendering, _T("LowColorRendering"));
648648 cfg->EnableDithering = ReadDWORD(hKey, cfg->EnableDithering, &cfgmask->EnableDithering, _T("EnableDithering"));
 649+ cfg->LimitTextureFormats = ReadDWORD(hKey, cfg->LimitTextureFormats, &cfgmask->LimitTextureFormats, _T("LimitTextureFormats"));
649650 cfg->primaryscale = ReadDWORD(hKey,cfg->primaryscale,&cfgmask->primaryscale,_T("AdjustPrimaryResolution"));
650651 cfg->primaryscalex = ReadFloat(hKey,cfg->primaryscalex,&cfgmask->primaryscalex,_T("PrimaryScaleX"));
651652 cfg->primaryscaley = ReadFloat(hKey,cfg->primaryscaley,&cfgmask->primaryscaley,_T("PrimaryScaleY"));
@@ -816,6 +817,7 @@
817818 WriteDWORD(hKey,cfg->aspect3d,cfgmask->aspect3d,_T("AdjustAspectRatio"));
818819 WriteDWORD(hKey, cfg->LowColorRendering, cfgmask->LowColorRendering, _T("LowColorRendering"));
819820 WriteDWORD(hKey, cfg->EnableDithering, cfgmask->EnableDithering, _T("EnableDithering"));
 821+ WriteDWORD(hKey, cfg->LimitTextureFormats, cfgmask->LimitTextureFormats, _T("LimitTextureFormats"));
820822 WriteDWORD(hKey,cfg->primaryscale,cfgmask->primaryscale,_T("AdjustPrimaryResolution"));
821823 WriteFloat(hKey,cfg->primaryscalex,cfgmask->primaryscalex,_T("PrimaryScaleX"));
822824 WriteFloat(hKey,cfg->primaryscaley,cfgmask->primaryscaley,_T("PrimaryScaleY"));
@@ -977,6 +979,7 @@
978980 cfg->WindowWidth = 640;
979981 cfg->WindowHeight = 480;
980982 cfg->HackPaletteDelay = 30;
 983+ cfg->LimitTextureFormats = TRUE;
981984 if (!cfg->Windows8Detected)
982985 {
983986 OSVERSIONINFO osver;
@@ -1129,6 +1132,7 @@
11301133 if (!_stricmp(name, "D3DAspect")) cfg->aspect3d = INIIntValue(value);
11311134 if (!_stricmp(name, "LowColorRendering")) cfg->LowColorRendering = INIIntValue(value);
11321135 if (!_stricmp(name, "EnableDithering")) cfg->EnableDithering = INIIntValue(value);
 1136+ if (!_stricmp(name, "LimitTextureFormats")) cfg->LimitTextureFormats = INIIntValue(value);
11331137 }
11341138 if (!_stricmp(section, "advanced"))
11351139 {
@@ -1548,6 +1552,7 @@
15491553 INIWriteInt(file, "D3DAspect", cfg->aspect3d, mask->aspect3d, INISECTION_D3D);
15501554 INIWriteInt(file, "LowColorRendering", cfg->LowColorRendering, mask->LowColorRendering, INISECTION_D3D);
15511555 INIWriteInt(file, "EnableDithering", cfg->EnableDithering, mask->EnableDithering, INISECTION_D3D);
 1556+ INIWriteBool(file, "LimitTextureFormats", cfg->LimitTextureFormats, mask->LimitTextureFormats, INISECTION_D3D);
15521557 // [advanced]
15531558 INIWriteInt(file, "TextureFormat", cfg->TextureFormat, mask->TextureFormat, INISECTION_ADVANCED);
15541559 INIWriteInt(file, "TexUpload", cfg->TexUpload, mask->TexUpload, INISECTION_ADVANCED);
Index: cfgmgr/cfgmgr.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2018 William Feely
 3+// Copyright (C) 2011-2019 William Feely
44 // Portions copyright (C) 2018 Syahmi Azhar
55
66 // This library is free software; you can redistribute it and/or
@@ -67,6 +67,7 @@
6868 DWORD aspect3d;
6969 DWORD LowColorRendering;
7070 DWORD EnableDithering;
 71+ BOOL LimitTextureFormats;
7172 // [advanced]
7273 DWORD vsync;
7374 DWORD TextureFormat;
Index: ddraw/glDirect3DDevice.cpp
@@ -1016,7 +1016,7 @@
10171017 DDPIXELFORMAT fmt;
10181018 for(int i = 0; i < numtexformats; i++)
10191019 {
1020 - if (i == 7) continue;
 1020+ if (i == 11) continue;
10211021 if(::texformats[i].dwFlags & DDPF_ZBUFFER) continue;
10221022 //FIXME: Remove these line after implementing palette textures
10231023 if(::texformats[i].dwFlags & DDPF_PALETTEINDEXED1) continue;
@@ -1030,6 +1030,35 @@
10311031 TRACE_EXIT(23,D3D_OK);
10321032 return D3D_OK;
10331033 }
 1034+
 1035+HRESULT WINAPI glDirect3DDevice7::EnumTextureFormats2(LPD3DENUMTEXTUREFORMATSCALLBACK lpd3dEnumTextureProc, LPVOID lpArg)
 1036+{
 1037+ TRACE_ENTER(3, 14, this, 14, lpd3dEnumTextureProc, 14, lpArg);
 1038+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 1039+ HRESULT result;
 1040+ DDSURFACEDESC ddsd;
 1041+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
 1042+ ddsd.dwSize = sizeof(DDSURFACEDESC);
 1043+ ddsd.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT;
 1044+ ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
 1045+ for (int i = 0; i < numtexformats; i++)
 1046+ {
 1047+ if (i == 11) continue;
 1048+ if (::texformats[i].dwFlags & DDPF_ZBUFFER) continue;
 1049+ if (::texformats[i].dwFlags & DDPF_FOURCC) continue;
 1050+ //FIXME: Remove these line after implementing palette textures
 1051+ if (::texformats[i].dwFlags & DDPF_PALETTEINDEXED1) continue;
 1052+ if (::texformats[i].dwFlags & DDPF_PALETTEINDEXED2) continue;
 1053+ if (::texformats[i].dwFlags & DDPF_PALETTEINDEXED4) continue;
 1054+ if (::texformats[i].dwFlags & DDPF_PALETTEINDEXED8) continue;
 1055+ memcpy(&ddsd.ddpfPixelFormat, &::texformats[i], sizeof(DDPIXELFORMAT));
 1056+ result = lpd3dEnumTextureProc(&ddsd, lpArg);
 1057+ if (result != D3DENUMRET_OK) TRACE_RET(HRESULT, 23, D3D_OK);
 1058+ }
 1059+ TRACE_EXIT(23, D3D_OK);
 1060+ return D3D_OK;
 1061+}
 1062+
10341063 HRESULT WINAPI glDirect3DDevice7::GetCaps(LPD3DDEVICEDESC7 lpD3DDevDesc)
10351064 {
10361065 TRACE_ENTER(2,14,this,14,lpD3DDevDesc);
@@ -3325,30 +3354,11 @@
33263355 TRACE_RET(HRESULT,23,glD3DDev7->EndScene());
33273356 }
33283357
3329 -HRESULT WINAPI EnumTex2(LPDDPIXELFORMAT ddpf, LPVOID lpUserArg)
3330 -{
3331 - if(ddpf->dwFlags & DDPF_LUMINANCE) return D3DENUMRET_OK;
3332 - if(ddpf->dwFlags & DDPF_ALPHA) return D3DENUMRET_OK;
3333 - int *args = (int*)lpUserArg;
3334 - LPD3DENUMTEXTUREFORMATSCALLBACK callback = (LPD3DENUMTEXTUREFORMATSCALLBACK)args[0];
3335 - DDSURFACEDESC ddsd;
3336 - ZeroMemory(&ddsd,sizeof(DDSURFACEDESC));
3337 - ddsd.dwSize = sizeof(DDSURFACEDESC);
3338 - ddsd.dwFlags = DDSD_CAPS|DDSD_PIXELFORMAT;
3339 - ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
3340 - ddsd.ddpfPixelFormat = *ddpf;
3341 - HRESULT ret = callback(&ddsd,(LPVOID)args[1]);
3342 - return ret;
3343 -}
3344 -
33453358 HRESULT WINAPI glDirect3DDevice2::EnumTextureFormats(LPD3DENUMTEXTUREFORMATSCALLBACK lpd3dEnumTextureProc, LPVOID lpArg)
33463359 {
33473360 TRACE_ENTER(3,14,this,14,lpd3dEnumTextureProc,14,lpArg);
33483361 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
3349 - LPVOID context[2];
3350 - context[0] = (LPVOID)lpd3dEnumTextureProc;
3351 - context[1] = lpArg;
3352 - TRACE_RET(HRESULT,23,glD3DDev7->EnumTextureFormats(EnumTex2,&context));
 3362+ TRACE_RET(HRESULT, 23, glD3DDev7->EnumTextureFormats2(lpd3dEnumTextureProc, lpArg));
33533363 }
33543364
33553365 HRESULT WINAPI glDirect3DDevice2::GetCaps(LPD3DDEVICEDESC lpD3DHWDevDesc, LPD3DDEVICEDESC lpD3DHELDevDesc)
@@ -3618,10 +3628,7 @@
36193629 {
36203630 TRACE_ENTER(3,14,this,14,lpd3dEnumTextureProc,14,lpArg);
36213631 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
3622 - LPVOID context[2];
3623 - context[0] = (LPVOID)lpd3dEnumTextureProc;
3624 - context[1] = lpArg;
3625 - TRACE_RET(HRESULT,23,glD3DDev7->EnumTextureFormats(EnumTex2,&context));
 3632+ TRACE_RET(HRESULT, 23, glD3DDev7->EnumTextureFormats2(lpd3dEnumTextureProc, lpArg));
36263633 }
36273634 HRESULT WINAPI glDirect3DDevice1::Execute(LPDIRECT3DEXECUTEBUFFER lpDirect3DExecuteBuffer, LPDIRECT3DVIEWPORT lpDirect3DViewport, DWORD dwFlags)
36283635 {
Index: ddraw/glDirect3DDevice.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2017 William Feely
 3+// Copyright (C) 2011-2019 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -67,6 +67,7 @@
6868 HRESULT WINAPI EndScene();
6969 HRESULT WINAPI EndStateBlock(LPDWORD lpdwBlockHandle);
7070 HRESULT WINAPI EnumTextureFormats(LPD3DENUMPIXELFORMATSCALLBACK lpd3dEnumPixelProc, LPVOID lpArg);
 71+ HRESULT WINAPI EnumTextureFormats2(LPD3DENUMTEXTUREFORMATSCALLBACK lpd3dEnumTextureProc, LPVOID lpArg);
7172 HRESULT WINAPI GetCaps(LPD3DDEVICEDESC7 lpD3DDevDesc);
7273 HRESULT WINAPI GetClipPlane(DWORD dwIndex, D3DVALUE *pPlaneEquation);
7374 HRESULT WINAPI GetClipStatus(LPD3DCLIPSTATUS lpD3DClipStatus);
Index: dxgl-example.ini
@@ -411,6 +411,11 @@
412412 ; Default is 0
413413 EnableDithering=0
414414
 415+; LimitTextureFormats - Boolean
 416+; Limits the available texture formats returned by EnumTextureFormats to
 417+; avoid crashes in some games. Default is true.
 418+LimitTextureFormats=true
 419+
415420 [advanced]
416421 ; TextureFormat - Integer
417422 ; Determines the internal format to use for textures and DirectDraw
@@ -598,6 +603,18 @@
599604 ; Default is false
600605 DebugDisableErrors=true
601606
 607+; DebugTraceLevel - Boolean
 608+; Sets the debug tracing level for DXGL. This can be used to diagnose bugs
 609+; in DXGL. The log will be saved as dxgl.log and will be overwritten if it
 610+; already exists.
 611+; The following values are valid:
 612+; 0 - Disable tracing.
 613+; 1 - Log system info and errors only
 614+; 2 - Log system info, errors, and certain informational messages
 615+; 3 - Log system info, errors, and certain informational messages, and log
 616+; a trace of API calls.
 617+DebugTraceLevel=0
 618+
602619 [hacks]
603620 ; Hacks are intended for specific scenarios, and may cause undesired effects
604621 ; if used with games they do not apply to or are combined.
Index: dxglcfg/dxglcfg.cpp
@@ -1981,6 +1981,12 @@
19821982 EnableWindow(GetDlgItem(hDialog, IDC_APPLY), TRUE);
19831983 *dirty = TRUE;
19841984 break;
 1985+ case IDC_LIMITTEXFORMATS:
 1986+ cfg->LimitTextureFormats = GetCheck(hWnd, IDC_SINGLEBUFFER, &cfgmask->LimitTextureFormats);
 1987+ EnableWindow(GetDlgItem(hDialog, IDC_APPLY), TRUE);
 1988+ *dirty = TRUE;
 1989+ break;
 1990+
19851991 default:
19861992 break;
19871993 }
@@ -2884,6 +2890,7 @@
28852891 SendDlgItemMessage(hTabs[2], IDC_ASPECT3D, CB_ADDSTRING, 0, (LPARAM)strdefault);
28862892 SendDlgItemMessage(hTabs[2], IDC_LOWCOLORRENDER, CB_ADDSTRING, 0, (LPARAM)strdefault);
28872893 SendDlgItemMessage(hTabs[2], IDC_DITHERING, CB_ADDSTRING, 0, (LPARAM)strdefault);
 2894+ SendDlgItemMessage(hTabs[2], IDC_LIMITTEXFORMATS, BM_SETSTYLE, BS_AUTO3STATE, (LPARAM)TRUE);
28882895 // Advanced tab
28892896 SendDlgItemMessage(hTabs[3], IDC_TEXTUREFORMAT, CB_ADDSTRING, 0, (LPARAM)strdefault);
28902897 SendDlgItemMessage(hTabs[3], IDC_TEXUPLOAD, CB_ADDSTRING, 0, (LPARAM)strdefault);
@@ -2942,6 +2949,7 @@
29432950 SendDlgItemMessage(hTabs[2], IDC_LOWCOLORRENDER, CB_FINDSTRING, -1, (LPARAM)strdefault), 0);
29442951 SendDlgItemMessage(hTabs[2], IDC_DITHERING, CB_DELETESTRING,
29452952 SendDlgItemMessage(hTabs[2], IDC_DITHERING, CB_FINDSTRING, -1, (LPARAM)strdefault), 0);
 2953+ SendDlgItemMessage(hTabs[2], IDC_LIMITTEXFORMATS, BM_SETSTYLE, BS_AUTOCHECKBOX, TRUE);
29462954 // Advanced tab
29472955 SendDlgItemMessage(hTabs[3], IDC_TEXTUREFORMAT, CB_DELETESTRING,
29482956 SendDlgItemMessage(hTabs[3], IDC_TEXTUREFORMAT, CB_FINDSTRING, -1, (LPARAM)strdefault), 0);
@@ -3040,6 +3048,7 @@
30413049 SetCombo(hTabs[2], IDC_ASPECT3D, cfg->aspect3d, cfgmask->aspect3d, tristate);
30423050 SetCombo(hTabs[2], IDC_LOWCOLORRENDER, cfg->LowColorRendering, cfgmask->LowColorRendering, tristate);
30433051 SetCombo(hTabs[2], IDC_DITHERING, cfg->EnableDithering, cfgmask->EnableDithering, tristate);
 3052+ SetCheck(hTabs[2], IDC_LIMITTEXFORMATS, cfg->LimitTextureFormats, cfgmask->LimitTextureFormats, tristate);
30443053 // Advanced tab
30453054 SetCombo(hTabs[3], IDC_TEXTUREFORMAT, cfg->TextureFormat, cfgmask->TextureFormat, tristate);
30463055 SetCombo(hTabs[3], IDC_TEXUPLOAD, cfg->TexUpload, cfgmask->TexUpload, tristate);
@@ -3607,6 +3616,9 @@
36083617 _tcscpy(buffer, _T("Always enabled, low color"));
36093618 SendDlgItemMessage(hTabs[2], IDC_DITHERING, CB_ADDSTRING, 0, (LPARAM)buffer);
36103619 SendDlgItemMessage(hTabs[2], IDC_DITHERING, CB_SETCURSEL, cfg->EnableDithering, 0);
 3620+ if (cfg->LimitTextureFormats) SendDlgItemMessage(hTabs[2], IDC_LIMITTEXFORMATS, BM_SETCHECK, BST_CHECKED, 0);
 3621+ else SendDlgItemMessage(hTabs[2], IDC_LIMITTEXFORMATS, BM_SETCHECK, BST_UNCHECKED, 0);
 3622+
36113623 // sort modes
36123624 _tcscpy(buffer,_T("Use system order"));
36133625 SendDlgItemMessage(hTabs[0], IDC_SORTMODES, CB_ADDSTRING, 0, (LPARAM)buffer);
Index: dxglcfg/dxglcfg.rc
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2018 William Feely
 3+// Copyright (C) 2011-2019 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -102,6 +102,7 @@
103103 COMBOBOX IDC_LOWCOLORRENDER, 7, 68, 102, 64, CBS_DROPDOWNLIST | CBS_HASSTRINGS, WS_EX_LEFT
104104 LTEXT "Enable dithering", IDC_STATIC, 114, 58, 52, 9, SS_LEFT, WS_EX_LEFT
105105 COMBOBOX IDC_DITHERING, 114, 68, 102, 64, CBS_DROPDOWNLIST | CBS_HASSTRINGS, WS_EX_LEFT
 106+ AUTOCHECKBOX "Limit D3D Texture Formats", IDC_LIMITTEXFORMATS, 7, 86, 99, 8, 0, WS_EX_LEFT
106107 }
107108
108109
Index: dxglcfg/resource.h
@@ -102,6 +102,7 @@
103103 #define IDC_MSAA 2203
104104 #define IDC_ASPECT3D 2204
105105 #define IDC_DITHERING 2205
 106+#define IDC_LIMITTEXFORMATS 2206
106107
107108 // Controls - Advanced Tab
108109 #define IDC_TEXTUREFORMAT 2301