From 60c544e1ff637445cfc0b0a0e56077792239a40a Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 29 Nov 2013 23:42:20 -0500 Subject: [PATCH 1/9] Don't lazy-load D3D9.dll We already link against it, so that's just a waste of time. Also, cleanup some unneeded ddraw includes. Remember that in Direct3D9, all devices can render in windowed mode. --- .../PubUtilLib/plGImage/hsDXTDirectXCodec.cpp | 27 +++---- .../PubUtilLib/plPipeline/CMakeLists.txt | 3 +- .../plPipeline/DX/plDXEnumerate.cpp | 43 +--------- .../PubUtilLib/plPipeline/DX/plDXPipeline.cpp | 13 +--- .../PubUtilLib/plPipeline/hsGDDrawDllLoad.cpp | 78 ------------------- .../PubUtilLib/plPipeline/hsGDDrawDllLoad.h | 62 --------------- 6 files changed, 18 insertions(+), 208 deletions(-) delete mode 100644 Sources/Plasma/PubUtilLib/plPipeline/hsGDDrawDllLoad.cpp delete mode 100644 Sources/Plasma/PubUtilLib/plPipeline/hsGDDrawDllLoad.h diff --git a/Sources/Plasma/PubUtilLib/plGImage/hsDXTDirectXCodec.cpp b/Sources/Plasma/PubUtilLib/plGImage/hsDXTDirectXCodec.cpp index 9933bdf9..b8075739 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/hsDXTDirectXCodec.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/hsDXTDirectXCodec.cpp @@ -53,16 +53,19 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" +#include +#include + #if HS_BUILD_FOR_WIN32 -#include -#include +# include "hsWindows.h" +# include +# include #endif #include "hsDXTDirectXCodec.h" #include "hsColorRGBA.h" #include "plMipmap.h" #include "hsCodecManager.h" -#include "plPipeline/hsGDDrawDllLoad.h" #if HS_BUILD_FOR_WIN32 namespace { @@ -144,26 +147,20 @@ bool hsDXTDirectXCodec::IInitialize() { fFlags |= kInitialized; -// if( hsGDDrawDllLoad::GetDDrawDll() == nil ) -// return false; - - DIRECTDRAWCREATEEX DirectDrawCreateEx = 0; + DIRECTDRAWCREATEEX DirectDrawCreateEx = nullptr; // Initialize DirectDraw - HRESULT hr; - DirectDrawCreateEx = (DIRECTDRAWCREATEEX)GetProcAddress( hsGDDrawDllLoad::GetD3DDll(), "DirectDrawCreateEx" ); - if( DirectDrawCreateEx == nil ) + std::unique_ptr> ddraw(LoadLibraryA("ddraw.dll"), FreeLibrary); + DirectDrawCreateEx = (DIRECTDRAWCREATEEX)GetProcAddress(ddraw.get(), "DirectDrawCreateEx"); + if (!DirectDrawCreateEx) return false; /// Using EMULATIONONLY here usually fails--using NULL forces the /// use of the standard display driver, which DOES work. - if (FAILED(hr = DirectDrawCreateEx((GUID FAR *)NULL/*DDCREATE_EMULATIONONLY*/, (VOID**)&fDirectDraw, IID_IDirectDraw7, NULL))) - return false; - - if (FAILED(hr = fDirectDraw->SetCooperativeLevel(NULL, DDSCL_NORMAL))) + if (FAILED(DirectDrawCreateEx((GUID FAR *)NULL/*DDCREATE_EMULATIONONLY*/, (VOID**)&fDirectDraw, IID_IDirectDraw7, NULL))) return false; - return true; + return SUCCEEDED(fDirectDraw->SetCooperativeLevel(NULL, DDSCL_NORMAL)); } #endif diff --git a/Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt index 52e60d0c..45a5fa6c 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt @@ -14,7 +14,6 @@ endif(WIN32) set(plPipeline_SOURCES hsG3DDeviceSelector.cpp hsGColorizer.cpp - hsGDDrawDllLoad.cpp plCaptureRender.cpp plCubicRenderTargetModifier.cpp plCullTree.cpp @@ -46,7 +45,6 @@ set(plPipeline_HEADERS hsFogControl.h hsG3DDeviceSelector.h hsGColorizer.h - hsGDDrawDllLoad.h hsGDeviceRef.h hsWinRef.h plBinkPlayer.h @@ -91,6 +89,7 @@ set(plDXPipeline_HEADERS if(WIN32) add_library(plPipeline STATIC ${plPipeline_SOURCES} ${plDXPipeline_SOURCES} ${plPipeline_HEADERS} ${plDXPipeline_HEADERS}) + target_link_libraries(plPipeline ${DirectX_LIBRARIES}) else() add_library(plPipeline STATIC ${plPipeline_SOURCES} ${plPipeline_HEADERS}) endif() diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp index 3cb8d9a6..c0d3ae23 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp @@ -39,10 +39,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com Mead, WA 99021 *==LICENSE==*/ -#include "plDXEnumerate.h" -#include -#include "plPipeline/hsGDDrawDllLoad.h" +#include "plDXEnumerate.h" #include "plPipeline/hsG3DDeviceSelector.h" @@ -219,8 +217,7 @@ HRESULT hsGDirect3DTnLEnumerate::D3DEnum_SelectDefaultDriver( DWORD dwFlags ) { if( dwFlags & D3DENUM_CANWINDOW ) { - if( (pDriver == &fDrivers[0]) - &&( pDevice->fDDCaps.Caps2 & DDCAPS2_CANRENDERWINDOWED ) ) + if( (pDriver == &fDrivers[0]) ) { if( ( pDevice->fDDCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ) ^ !(dwFlags & D3DENUM_TNLHAL) ) @@ -286,26 +283,8 @@ hsGDirect3DTnLEnumerate::hsGDirect3DTnLEnumerate() fCurrentDriver = NULL; // The selected DD driver fDrivers.Reset(); // List of DD drivers - - /// New DX Enumeration - - // Get a pointer to the creation function - if( hsGDDrawDllLoad::GetD3DDll() == nil ) - { - strcpy( fEnumeErrorStr, "Cannot load Direct3D driver!" ); - return; - } - - Direct3DCreateProc procPtr; - procPtr = (Direct3DCreateProc)GetProcAddress( hsGDDrawDllLoad::GetD3DDll(), "Direct3DCreate9" ); - if( procPtr == nil ) - { - strcpy( fEnumeErrorStr, "Cannot load D3D Create Proc!" ); - return; - } - // Create a D3D object to use - IDirect3D9 *pD3D = procPtr( D3D_SDK_VERSION ); + IDirect3D9 *pD3D = Direct3DCreate9( D3D_SDK_VERSION ); if( pD3D == nil ) { strcpy( fEnumeErrorStr, "Cannot load DirectX!" ); @@ -684,22 +663,8 @@ bool hsG3DDeviceSelector::IGetD3DCardInfo( hsG3DDeviceRecord &record, bool hsG3DDeviceSelector::IInitDirect3D( void ) { - if( hsGDDrawDllLoad::GetD3DDll() == nil ) - { - strcpy( fErrorString, "Cannot load Direct3D driver!" ); - return false; - } - - Direct3DCreateProc procPtr; - procPtr = (Direct3DCreateProc)GetProcAddress( hsGDDrawDllLoad::GetD3DDll(), "Direct3DCreate9" ); - if( procPtr == nil ) - { - strcpy( fErrorString, "Cannot load D3D Create Proc!" ); - return false; - } - // Create a D3D object to use - IDirect3D9 *pD3D = procPtr( D3D_SDK_VERSION ); + IDirect3D9 *pD3D = Direct3DCreate9( D3D_SDK_VERSION ); if( pD3D == nil ) { strcpy( fErrorString, "Cannot load DirectX!" ); diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp index 9aed343b..42dd103d 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp @@ -55,7 +55,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsWindows.h" #include -#include #include #if defined(DX_OLD_SDK) || defined(__MINGW32__) @@ -78,7 +77,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plPipeline/plDebugText.h" #include "plDXEnumerate.h" #include "plPipeline/hsG3DDeviceSelector.h" -#include "plPipeline/hsGDDrawDllLoad.h" #include "hsResMgr.h" #include "plPipeline/plStatusLogDrawer.h" #include "plQuality.h" @@ -1593,16 +1591,7 @@ bool plDXPipeline::ICreateMaster() hsAssert( !fD3DObject, "ICreateMaster() should only be called for Master Direct3DDevice" ); /// The new DirectX Way: Create a Direct3D object, out of which everything else springs - if( hsGDDrawDllLoad::GetD3DDll() == nil ) - return ICreateFail( "Cannot load Direct3D driver!" ); - - Direct3DCreateProc procPtr; - procPtr = (Direct3DCreateProc)GetProcAddress( hsGDDrawDllLoad::GetD3DDll(), "Direct3DCreate9" ); - if( procPtr == nil ) - return ICreateFail( "Cannot load D3D Create Proc!" ); - - // Create a D3D object to use - fD3DObject = procPtr( D3D_SDK_VERSION ); + fD3DObject = Direct3DCreate9( D3D_SDK_VERSION ); if( fD3DObject == nil ) return ICreateFail( "Cannot create Direct3D object" ); diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsGDDrawDllLoad.cpp b/Sources/Plasma/PubUtilLib/plPipeline/hsGDDrawDllLoad.cpp deleted file mode 100644 index e070a778..00000000 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsGDDrawDllLoad.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ - -#ifdef HS_BUILD_FOR_WIN32 - -#include "hsWindows.h" - -#include - -#include "hsGDDrawDllLoad.h" - -static hsGDDrawDllLoad staticDllLoad; - -hsGDDrawDllLoad::hsGDDrawDllLoad() -{ - hsAssert(!staticDllLoad.fD3DDll, "Don't make instances of this class, just use GetDDrawDll func"); - - fD3DDll = LoadLibrary( "D3D9.DLL" ); - if (fD3DDll) - hsStatusMessage( "--- D3D9.DLL loaded successfully.\n" ); - else - hsStatusMessage( "--- Unable to load D3D9.DLL successfully.\n" ); -} - -hsGDDrawDllLoad::~hsGDDrawDllLoad() -{ - if (fD3DDll != nil) - { - hsStatusMessage( "--- Unloading D3D.DLL.\n" ); - FreeLibrary(fD3DDll); - } -} - -HMODULE hsGDDrawDllLoad::GetD3DDll() -{ - return staticDllLoad.fD3DDll; -} - -#endif //HS_BUILD_FOR_WIN32 diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsGDDrawDllLoad.h b/Sources/Plasma/PubUtilLib/plPipeline/hsGDDrawDllLoad.h deleted file mode 100644 index cc80bb20..00000000 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsGDDrawDllLoad.h +++ /dev/null @@ -1,62 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ - -#ifndef hsGDDrawDllLoad_inc -#define hsGDDrawDllLoad_inc - -#include "HeadSpin.h" - -#if HS_BUILD_FOR_WIN32 -class hsGDDrawDllLoad -{ -private: - HMODULE fD3DDll; - -public: - hsGDDrawDllLoad(); - ~hsGDDrawDllLoad(); - - static HMODULE GetD3DDll(); -}; -#endif - -#endif // hsGDDrawDllLoad_inc From bbae6a76d7745f3a1e3ea9e00fb5a95d5e76cbfc Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 30 Nov 2013 20:02:08 -0500 Subject: [PATCH 2/9] We don't support 3dfx cards... Come on, man... They made some good cards, but they went out of business in 1999! Ain't nobody got time fo' dat. --- .../plPipeline/DX/plDXEnumerate.cpp | 23 ----------- .../plPipeline/hsG3DDeviceSelector.cpp | 41 ++----------------- .../plPipeline/hsG3DDeviceSelector.h | 2 - 3 files changed, 4 insertions(+), 62 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp index c0d3ae23..2d3cc839 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp @@ -723,29 +723,6 @@ void hsG3DDeviceSelector::ITryDirect3DTnLDriver(D3DEnum_DriverInfo* drivInfo) /// Done first now, so we can alter the D3D type later ITryDirect3DTnLDevice( &drivInfo->fDevices[i], currDevRec ); - - /// Check the vendor ID to see if it's 3dfx (#0x121a). If it is, don't add it. - /// (we don't support 3dfx D3D devices) -mcn - /// 11.25.2000 mcn - Knew this was going to come back and bite me. Now we just - /// append (3dfx) to the end of the device description, so that our latter test - /// can throw it out or not, depending on whether we're "strong". - - if( drivInfo->fAdapterInfo.VendorId == 0x121a && - ( currDevRec.GetG3DHALorHEL() == hsG3DDeviceSelector::kHHD3DHALDev || - currDevRec.GetG3DHALorHEL() == hsG3DDeviceSelector::kHHD3DTnLHalDev ) ) - { - if( drivInfo->fAdapterInfo.DeviceId >= 0x00000009 ) - { - currDevRec.SetG3DHALorHEL( kHHD3D3dfxVoodoo5Dev ); - plDemoDebugFile::Write( " Tagging device as a 3dfx Voodoo5 or above" ); - } - else - { - currDevRec.SetG3DHALorHEL( kHHD3D3dfxDev ); - plDemoDebugFile::Write( " Tagging device as a non-V5 3dfx card" ); - } - } - IFudgeDirectXDevice( currDevRec, (D3DEnum_DriverInfo *)drivInfo, (D3DEnum_DeviceInfo *)&drivInfo->fDevices[ i ] ); if( currDevRec.GetModes().GetCount() ) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp index bfe0169e..3a31591f 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp @@ -570,37 +570,19 @@ void hsG3DDeviceSelector::RemoveUnusableDevModes(bool bTough) else if( fRecords[i].GetG3DDeviceType() == hsG3DDeviceSelector::kDevTypeDirect3D || fRecords[i].GetG3DDeviceType() == hsG3DDeviceSelector::kDevTypeDirect3DTnL ) { - uint32_t totalMem; - char devDesc[ 256 ]; - - - // For our 3dfx test later - strncpy( devDesc, fRecords[i].GetDriverDesc(), sizeof( devDesc ) - 1 ); - hsStrLower( devDesc ); + uint32_t totalMem; // Remove software Direct3D devices if ((fRecords[i].GetG3DHALorHEL() != hsG3DDeviceSelector::kHHD3DHALDev) && - (fRecords[i].GetG3DHALorHEL() != hsG3DDeviceSelector::kHHD3DTnLHalDev) && - (fRecords[i].GetG3DHALorHEL() != hsG3DDeviceSelector::kHHD3D3dfxDev) && - (fRecords[i].GetG3DHALorHEL() != hsG3DDeviceSelector::kHHD3D3dfxVoodoo5Dev) + (fRecords[i].GetG3DHALorHEL() != hsG3DDeviceSelector::kHHD3DTnLHalDev) #ifdef HS_ALLOW_D3D_REF_DRIVER - && (fRecords[i].GetG3DHALorHEL() != hsG3DDeviceSelector::kHHD3DRefDev) + && (fRecords[i].GetG3DHALorHEL() != hsG3DDeviceSelector::kHHD3DRefDev) #endif ) { plDemoDebugFile::Write( " Removing software Direct3D device. Description", (char *)fRecords[ i ].GetDriverDesc() ); fRecords[i].SetDiscarded(true); } - // Remove 3Dfx Direct3D devices, take 2 - // 10.13.2000 mcn - Now we do it even when we're wimpy - // 10.25.2000 mcn - Think again. - // 11.3.2000 mcn - Shesh, is this EVER going to be stable?? - else if( bTough && fRecords[i].GetG3DHALorHEL() == hsG3DDeviceSelector::kHHD3D3dfxDev ) -// else if( bTough && ( strstr( devDesc, "3dfx" ) || strstr( devDesc, "voodoo" ) ) ) - { - plDemoDebugFile::Write( " Removing 3Dfx non-Voodoo5 Direct3D device (We only support Glide on 3Dfx). Description", (char *)fRecords[ i ].GetDriverDesc() ); - fRecords[i].SetDiscarded(true); - } // Remove Direct3D devices with less than 11 megs of RAM else if (bTough && ( totalMem = IAdjustDirectXMemory( fRecords[i].GetMemoryBytes() ) ) < 11*1024*1024 ) { @@ -720,7 +702,7 @@ bool hsG3DDeviceSelector::GetDefault (hsG3DDeviceModeRecord *dmr) iTnL = i; } } - else if (fRecords[i].GetG3DHALorHEL() == kHHD3DHALDev || fRecords[i].GetG3DHALorHEL() == kHHD3D3dfxVoodoo5Dev ) + else if (fRecords[i].GetG3DHALorHEL() == kHHD3DHALDev) { if (iD3D == -1 #ifndef PLASMA_EXTERNAL_RELEASE @@ -1264,7 +1246,6 @@ namespace kATIGenericChipset, kMatroxGenericChipset, kKYROChipset, - k3dfxV5Chipset, kSavage3DChipset, kATIRadeonChipset, kATIR7X00Chipset, @@ -1417,11 +1398,6 @@ namespace 1, // First integer is always the length hsG3DDeviceSelector::kCapsNoKindaSmallTexs }; - uint32_t ds3dfxV5CapsClr[] = { - 2, // First integer is always the length - hsG3DDeviceSelector::kCapsFogExp, - hsG3DDeviceSelector::kCapsFogExp2 }; - uint32_t dsMatroxParheliaSet[] = { 1, hsG3DDeviceSelector::kCapsNoAA }; @@ -1470,7 +1446,6 @@ namespace { kSavage2000Chipset, dsSavageCapsSet, dsSavage2kCapsClr, 4.0f, 1, 0, &dsDefaultFogVals }, { kS3GenericChipset, dsSavageCapsSet, dsS3GenerCapsClr, 4.0f, 1, 0, &dsDefaultFogVals }, { kKYROChipset, dsKYROCapsSet, dsKYROCapsClr, -151.0f, 1, 0, &dsDefaultFogVals }, - { k3dfxV5Chipset, nil, ds3dfxV5CapsClr, 3.5f, 0, 0, &dsDefaultFogVals }, { kSavage3DChipset, nil, dsDefaultCapsClr, 0, 0, 0, &dsS3DFogVals }, { kATIRadeonChipset, dsATIRadeonCapsSet, dsATIRadeonCapsClr, 0, 0, 0, &dsRadeonFogVals }, { kATIR7X00Chipset, dsATIR7X00CapsSet, dsATIR7X00CapsClr, 3.f, 2, 0, &dsRadeonFogVals }, @@ -1734,14 +1709,6 @@ void hsG3DDeviceSelector::IFudgeDirectXDevice( hsG3DDeviceRecord &record, plDemoDebugFile::Write( " Using fudge factors for a KYRO chipset" ); ISetFudgeFactors( kKYROChipset, record ); } - /// Detect for a 3dfx Voodoo5 - else if( vendorID == 0x121a && deviceID == 0x00000009 && - stricmp( szDriver, "3dfxvs.dll" ) == 0 ) - { - hsStatusMessage( "== Using fudge factors for a 3dfx Voodoo5 chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for a 3dfx Voodoo5 chipset" ); - ISetFudgeFactors( k3dfxV5Chipset, record ); - } /// Detect for a GeForce-class card. We can be loose here because we want /// to get ALL GeForce/2/256 cards else if( strstr( desc, "nvidia" ) != nil && strstr( desc, "geforce2" ) != nil ) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h index 9b686b87..0ea9557b 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h @@ -325,8 +325,6 @@ public: kHHD3DMMXDev, kHHD3DTnLHalDev, kHHD3DRefDev, - kHHD3D3dfxDev, - kHHD3D3dfxVoodoo5Dev, kNumHHTypes }; From a30a326d17a7266fe7af799a0771b4147103f495 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 30 Nov 2013 20:06:19 -0500 Subject: [PATCH 3/9] We only support DirectX 9... If you have less than 11MB VRAM or need to use the ref implementation, then you are using a dinosaur and have no business even attempting to play this game. --- Sources/Plasma/Apps/plClient/plClient.cpp | 25 ++--------------- .../plPipeline/DX/plDXEnumerate.cpp | 3 -- .../plPipeline/hsG3DDeviceSelector.cpp | 28 +------------------ .../plPipeline/hsG3DDeviceSelector.h | 12 -------- 4 files changed, 4 insertions(+), 64 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index 8fdb544f..9c21bb94 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/Sources/Plasma/Apps/plClient/plClient.cpp @@ -2237,9 +2237,6 @@ void plClient::IDetectAudioVideoSettings() bool pixelshaders = rec->GetCap(hsG3DDeviceSelector::kCapsPixelShader); int psMajor = 0, psMinor = 0; rec->GetPixelShaderVersion(psMajor, psMinor); - bool refDevice = false; - if(rec->GetG3DHALorHEL() == hsG3DDeviceSelector::kHHD3DRefDev) - refDevice = true; plPipeline::fDefaultPipeParams.ColorDepth = hsG3DDeviceSelector::kDefaultDepth; #if defined(HS_DEBUGGING) || defined(DEBUG) @@ -2266,17 +2263,10 @@ void plClient::IDetectAudioVideoSettings() plPipeline::fDefaultPipeParams.Shadows = 1; // enable planar reflections if pixelshaders are available - if(pixelshaders && !refDevice) - { plPipeline::fDefaultPipeParams.PlanarReflections = 1; - } - else - { - plPipeline::fDefaultPipeParams.PlanarReflections = 0; - } // enable 2x antialiasing and anisotropic to 2 samples if pixelshader version is greater that 2.0 - if(psMajor >= 2 && !refDevice) + if(psMajor >= 2) { plPipeline::fDefaultPipeParams.AntiAliasingAmount = rec->GetMaxAnisotropicSamples() ? 2 : 0; plPipeline::fDefaultPipeParams.AnisotropicLevel = mode->GetNumFSAATypes() ? 2 : 0; @@ -2287,17 +2277,8 @@ void plClient::IDetectAudioVideoSettings() plPipeline::fDefaultPipeParams.AnisotropicLevel = 0; } - if(refDevice) - { - plPipeline::fDefaultPipeParams.TextureQuality = 0; - plPipeline::fDefaultPipeParams.VideoQuality = 0; - - } - else - { - plPipeline::fDefaultPipeParams.TextureQuality = psMajor >= 2 ? 2 : 1; - plPipeline::fDefaultPipeParams.VideoQuality = pixelshaders ? 2 : 1; - } + plPipeline::fDefaultPipeParams.TextureQuality = psMajor >= 2 ? 2 : 1; + plPipeline::fDefaultPipeParams.VideoQuality = pixelshaders ? 2 : 1; plPipeline::fDefaultPipeParams.VSync = false; // card specific overrides diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp index 2d3cc839..7ec0e622 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp @@ -100,9 +100,6 @@ HRESULT hsGDirect3DTnLEnumerate::SelectFromDevMode(const hsG3DDeviceRecord* devR if( !colorDepth ) enumFlags |= D3DENUM_CANWINDOW; enumFlags |= D3DENUM_TNLHAL; -#ifdef HS_ALLOW_D3D_REF_DRIVER - enumFlags |= D3DENUM_REFERENCERAST; -#endif D3DEnum_SelectDefaultDriver(enumFlags); diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp index 3a31591f..1c1baca0 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp @@ -574,23 +574,11 @@ void hsG3DDeviceSelector::RemoveUnusableDevModes(bool bTough) // Remove software Direct3D devices if ((fRecords[i].GetG3DHALorHEL() != hsG3DDeviceSelector::kHHD3DHALDev) && - (fRecords[i].GetG3DHALorHEL() != hsG3DDeviceSelector::kHHD3DTnLHalDev) -#ifdef HS_ALLOW_D3D_REF_DRIVER - && (fRecords[i].GetG3DHALorHEL() != hsG3DDeviceSelector::kHHD3DRefDev) -#endif - ) + (fRecords[i].GetG3DHALorHEL() != hsG3DDeviceSelector::kHHD3DTnLHalDev)) { plDemoDebugFile::Write( " Removing software Direct3D device. Description", (char *)fRecords[ i ].GetDriverDesc() ); fRecords[i].SetDiscarded(true); } - // Remove Direct3D devices with less than 11 megs of RAM - else if (bTough && ( totalMem = IAdjustDirectXMemory( fRecords[i].GetMemoryBytes() ) ) < 11*1024*1024 ) - { - plString log = plString::Format(" Removing Direct3D device with < 11MB RAM. Device RAM (in kB): %d (Description: %s)", - totalMem / 1024, fRecords[ i ].GetDriverDesc() ); - plDemoDebugFile::Write( log.c_str() ); - fRecords[i].SetDiscarded(true); - } else { if( fRecords[i].GetG3DDeviceType() == hsG3DDeviceSelector::kDevTypeDirect3DTnL ) @@ -663,10 +651,6 @@ void hsG3DDeviceSelector::Enumerate(hsWinRef winRef) #endif /// Now try our devices -#ifdef HS_SELECT_DX7 - ITryDirect3D(winRef); -#endif // HS_SELECT_DX7 - ITryDirect3DTnL(winRef); // ITryOpenGL(winRef); @@ -1478,16 +1462,6 @@ void hsG3DDeviceSelector::IFudgeDirectXDevice( hsG3DDeviceRecord &record, hsAssert( false, "Trying to fudge D3D device but D3D support isn't in this EXE!" ); } } -#ifdef HS_SELECT_DX7 - else if( record.GetG3DDeviceType() == kDevTypeDirect3D ) - { - if( !IGetD3D7CardInfo( record, driverInfo, deviceInfo, &vendorID, &deviceID, &szDriver, &szDesc ) ) - { - // {} to make VC6 happy in release build - hsAssert( false, "Trying to fudge D3D7 device but D3D7 support isn't in this EXE!" ); - } - } -#endif // HS_SELECT_DX7 else { hsAssert( false, "IFudgeDirectXDevice got a device type that support wasn't compiled for!" ); diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h index 0ea9557b..ec3318f5 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h @@ -69,9 +69,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define DYNAHEADER 1 #endif // HS_BUILD_FOR_WIN32 -/// #define the following to allow selection of the D3D reference driver -#define HS_ALLOW_D3D_REF_DRIVER 1 - class hsStream; struct D3DEnum_DeviceInfo; @@ -384,21 +381,12 @@ protected: void ITryDirect3DTnL(hsWinRef winRef); bool IInitDirect3D( void ); -#ifdef HS_SELECT_DX7 - void ITryDirect3DDevice(D3DEnum_DeviceInfo* devInfo, hsG3DDeviceRecord& srcDevRec); - void ITryDirect3DDriver(D3DEnum_DriverInfo* drivInfo); - void ITryDirect3D(hsWinRef winRef); -#endif // HS_SELECT_DX7 void IFudgeDirectXDevice( hsG3DDeviceRecord &record, D3DEnum_DriverInfo *driverInfo, D3DEnum_DeviceInfo *deviceInfo ); uint32_t IAdjustDirectXMemory( uint32_t cardMem ); bool IGetD3DCardInfo( hsG3DDeviceRecord &record, void *driverInfo, void *deviceInfo, uint32_t *vendorID, uint32_t *deviceID, char **driverString, char **descString ); -#ifdef HS_SELECT_DX7 - bool IGetD3D7CardInfo( hsG3DDeviceRecord &record, void *driverInfo, void *deviceInfo, - uint32_t *vendorID, uint32_t *deviceID, char **driverString, char **descString ); -#endif // HS_SELECT_DX7 void ITryOpenGL( hsWinRef winRef ); void IGetExtOpenGLInfo( hsG3DDeviceRecord &devRec ); From 544abef39e1aa5fe27968e927831de7020454440 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 30 Nov 2013 20:41:56 -0500 Subject: [PATCH 4/9] Wow, those cards are old... Remove detection for cards that are don't support at LEAST DirectX 8. There's no way they would even be able to get past Direct3DCreate9, so we shouldn't need to worry about them... I hope. --- Sources/Plasma/Apps/plClient/plClient.cpp | 7 - .../plPipeline/hsG3DDeviceSelector.cpp | 381 +----------------- 2 files changed, 21 insertions(+), 367 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index 9c21bb94..a588f75c 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/Sources/Plasma/Apps/plClient/plClient.cpp @@ -2281,13 +2281,6 @@ void plClient::IDetectAudioVideoSettings() plPipeline::fDefaultPipeParams.VideoQuality = pixelshaders ? 2 : 1; plPipeline::fDefaultPipeParams.VSync = false; - // card specific overrides - if(rec->GetDriverDesc() && strstr(rec->GetDriverDesc(), "FX 5200")) - { - plPipeline::fDefaultPipeParams.AntiAliasingAmount = 0; - } - - int val = 0; hsStream *stream = nil; hsUNIXStream s; diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp index 1c1baca0..f43332e3 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp @@ -1218,28 +1218,12 @@ namespace enum { kDefaultChipset = 0x00, - kSavage4Chipset, - kATIRageFuryChipset, - kATIRageProChipset, - kNVidiaTNTChipset, - kNVidiaGeForceChipset, - kMatroxG400Chipset, kIntelI810Chipset, - kSavage2000Chipset, kS3GenericChipset, - kATIGenericChipset, - kMatroxGenericChipset, kKYROChipset, - kSavage3DChipset, kATIRadeonChipset, - kATIR7X00Chipset, - kATIR7500Chipset, kATIR8X00Chipset, kMatroxParhelia, - kNVidiaGeForce2Chipset, - kNVidiaGeForce3Chipset, - kNVidiaGeForce4MXChipset, - kNVidiaGeForce4Chipset, kNVidiaGeForceFXChipset }; @@ -1255,8 +1239,6 @@ namespace } FogTweakTable; FogTweakTable dsDefaultFogVals = { 0, 0, 254.0 / 255.0, 0.5f, 0.15f, 0.5f, 0.15f }; - FogTweakTable dsATIFogVals = { 0.1f, 0.1f, 254.0 / 255.0, 0.85f, 0.15f, 0.5f, 0.15f }; - FogTweakTable dsS3DFogVals = { 0, 0, 254.0 / 255.0, 1.0f, 1.0f, 1.0f, 1.0f }; FogTweakTable dsi810FogVals = { 0, 0, 254.0 / 255.0, 0.6f, 0.15f, 0.4f, 0.15f }; FogTweakTable dsRadeonFogVals = { 0, 0, 254.0 / 255.0, 0.7f, 0.15f, 0.5f, 0.2f }; @@ -1271,24 +1253,9 @@ namespace FogTweakTable *fFogTweaks; } CFTable; - uint32_t dsSavageCapsClr[] = { - 4, // First integer is always the length - hsG3DDeviceSelector::kCapsCompressTextures, - hsG3DDeviceSelector::kCapsFogExp, - hsG3DDeviceSelector::kCapsFogExp2, - hsG3DDeviceSelector::kCapsDoesSmallTextures }; - - uint32_t dsSavageCapsSet[] = { + uint32_t dsGeForceFXCapsSet[] = { 1, // First integer is always the length - hsG3DDeviceSelector::kCapsBadYonStuff }; - - uint32_t dsSavage2kCapsClr[] = { - 5, // First integer is always the length - hsG3DDeviceSelector::kCapsCompressTextures, - hsG3DDeviceSelector::kCapsPixelFog, - hsG3DDeviceSelector::kCapsFogExp, - hsG3DDeviceSelector::kCapsFogExp2, - hsG3DDeviceSelector::kCapsDoesSmallTextures }; + hsG3DDeviceSelector::kCapsNoAA }; uint32_t dsS3GenerCapsClr[] = { 4, // First integer is always the length @@ -1297,59 +1264,6 @@ namespace hsG3DDeviceSelector::kCapsFogExp2, hsG3DDeviceSelector::kCapsDoesSmallTextures }; - uint32_t dsATIFuryCapsClr[] = { - 3, // First integer is always the length - hsG3DDeviceSelector::kCapsFogExp, - hsG3DDeviceSelector::kCapsFogExp2, - hsG3DDeviceSelector::kCapsPixelFog }; - - uint32_t dsATIRageCapsClr[] = { - 4, // First integer is always the length - hsG3DDeviceSelector::kCapsFogExp, - hsG3DDeviceSelector::kCapsFogExp2, - hsG3DDeviceSelector::kCapsDoesSmallTextures, - hsG3DDeviceSelector::kCapsPixelFog }; - - uint32_t dsATIGenerCapsClr[] = { - 4, // First integer is always the length - hsG3DDeviceSelector::kCapsPixelFog, - hsG3DDeviceSelector::kCapsFogExp, - hsG3DDeviceSelector::kCapsFogExp2, - hsG3DDeviceSelector::kCapsDoesSmallTextures }; - - uint32_t dsATIRadeonCapsSet[] = { - 2, // First integer is always the length - hsG3DDeviceSelector::kCapsBadManaged, - hsG3DDeviceSelector::kCapsShareDepth - }; - - uint32_t dsATIRadeonCapsClr[] = { - 2, // First integer is always the length - hsG3DDeviceSelector::kCapsWBuffer, - hsG3DDeviceSelector::kCapsDoesSmallTextures }; - - uint32_t dsATIR7X00CapsSet[] = { - 4, // First integer is always the length - hsG3DDeviceSelector::kCapsCantShadow, - hsG3DDeviceSelector::kCapsBadManaged, - hsG3DDeviceSelector::kCapsShareDepth, - hsG3DDeviceSelector::kCapsNoAniso - }; - - uint32_t dsATIR7500CapsSet[] = { - 5, // First integer is always the length - hsG3DDeviceSelector::kCapsMaxUVWSrc2, - hsG3DDeviceSelector::kCapsCantShadow, - hsG3DDeviceSelector::kCapsBadManaged, - hsG3DDeviceSelector::kCapsShareDepth, - hsG3DDeviceSelector::kCapsNoAniso - }; - - uint32_t dsATIR7X00CapsClr[] = { - 2, // First integer is always the length - hsG3DDeviceSelector::kCapsWBuffer, - hsG3DDeviceSelector::kCapsDoesSmallTextures }; - uint32_t dsATIR8X00CapsSet[] = { 2, // First integer is always the length hsG3DDeviceSelector::kCapsBadManaged, @@ -1361,18 +1275,10 @@ namespace hsG3DDeviceSelector::kCapsWBuffer, hsG3DDeviceSelector::kCapsDoesSmallTextures }; - uint32_t dsTNTCapsClr[] = { - 1, // First integer is always the length - hsG3DDeviceSelector::kCapsDoesSmallTextures }; - uint32_t dsDefaultCapsClr[] = { 1, // First integer is always the length hsG3DDeviceSelector::kCapsDoesSmallTextures }; - uint32_t dsMG400CapsClr[] = { - 1, // First integer is always the length - hsG3DDeviceSelector::kCapsDoesSmallTextures }; - uint32_t dsKYROCapsClr[] = { 2, // First integer is always the length hsG3DDeviceSelector::kCapsDoesSmallTextures, @@ -1382,59 +1288,14 @@ namespace 1, // First integer is always the length hsG3DDeviceSelector::kCapsNoKindaSmallTexs }; - uint32_t dsMatroxParheliaSet[] = { - 1, - hsG3DDeviceSelector::kCapsNoAA }; - - uint32_t dsGeForceSet[] = { - 2, - hsG3DDeviceSelector::kCapsCantProj, - hsG3DDeviceSelector::kCapsDoubleFlush }; - - uint32_t dsGeForce2Set[] = { - 1, - hsG3DDeviceSelector::kCapsDoubleFlush }; - - uint32_t dsGeForce3Set[] = { - 1, - hsG3DDeviceSelector::kCapsSingleFlush }; - - uint32_t dsGeForce4MXSet[] = { - 1, - hsG3DDeviceSelector::kCapsSingleFlush }; - - uint32_t dsGeForce4Set[] = { - 1, - hsG3DDeviceSelector::kCapsSingleFlush - }; - CFTable dsCFTable[] = { - // Chipset ID // F2Set // F2Clear // ZSuck // MaxLayers // LODBias // Fog Value Tables - { kDefaultChipset, nil, dsDefaultCapsClr, 0, 0, 0, &dsDefaultFogVals }, - { kATIRageFuryChipset, nil, dsATIFuryCapsClr, 4.25f, 1, 0, &dsATIFogVals }, - { kATIRageProChipset, nil, dsATIRageCapsClr, 4.25f, 1, 0, &dsATIFogVals }, - { kATIGenericChipset, nil, dsATIGenerCapsClr, 4.25f, 1, 0, &dsATIFogVals }, - { kNVidiaTNTChipset, nil, dsTNTCapsClr, 0, 0, 0, &dsDefaultFogVals }, - { kNVidiaGeForce2Chipset,dsGeForce2Set, nil, 0, 0, 0, &dsDefaultFogVals }, - { kNVidiaGeForce3Chipset,dsGeForce3Set, nil, 0, 0, 0, &dsDefaultFogVals }, - { kNVidiaGeForce4MXChipset,dsGeForce4MXSet, nil, 0, 0, 0, &dsDefaultFogVals }, - { kNVidiaGeForce4Chipset,dsGeForce4Set, nil, 0, 0, 0, &dsDefaultFogVals }, - { kNVidiaGeForceChipset,dsGeForceSet, nil, 0, 0, 0, &dsDefaultFogVals }, - { kNVidiaGeForceFXChipset,nil, nil, 0, 0, 0, &dsDefaultFogVals }, - { kMatroxG400Chipset, nil, dsMG400CapsClr, 3.25f, 0, 0, &dsDefaultFogVals }, - { kMatroxParhelia, dsMatroxParheliaSet,nil, 0, 0, 0, &dsDefaultFogVals }, - { kMatroxGenericChipset,nil, dsMG400CapsClr, 3.25f, 0, 0, &dsDefaultFogVals }, - { kIntelI810Chipset, nil, dsDefaultCapsClr, 4.5f, 1, -0.5f, &dsi810FogVals }, - { kSavage4Chipset, dsSavageCapsSet, dsSavageCapsClr, 4.0f, 1, 0, &dsDefaultFogVals }, // LOD bias should be -0.5 here - { kSavage2000Chipset, dsSavageCapsSet, dsSavage2kCapsClr, 4.0f, 1, 0, &dsDefaultFogVals }, - { kS3GenericChipset, dsSavageCapsSet, dsS3GenerCapsClr, 4.0f, 1, 0, &dsDefaultFogVals }, - { kKYROChipset, dsKYROCapsSet, dsKYROCapsClr, -151.0f, 1, 0, &dsDefaultFogVals }, - { kSavage3DChipset, nil, dsDefaultCapsClr, 0, 0, 0, &dsS3DFogVals }, - { kATIRadeonChipset, dsATIRadeonCapsSet, dsATIRadeonCapsClr, 0, 0, 0, &dsRadeonFogVals }, - { kATIR7X00Chipset, dsATIR7X00CapsSet, dsATIR7X00CapsClr, 3.f, 2, 0, &dsRadeonFogVals }, - { kATIR7500Chipset, dsATIR7500CapsSet, dsATIR7X00CapsClr, 3.f, 2, 0, &dsRadeonFogVals }, - { kATIR8X00Chipset, dsATIR8X00CapsSet, dsATIR8X00CapsClr, 0, 0, 0, &dsRadeonFogVals }, + // Chipset ID // F2Set // F2Clear // ZSuck // MaxLayers // LODBias // Fog Value Tables + { kDefaultChipset, nullptr, dsDefaultCapsClr, 0, 0, 0, &dsDefaultFogVals }, + { kNVidiaGeForceFXChipset, dsGeForceFXCapsSet, nullptr, 0, 0, 0, &dsDefaultFogVals }, + { kIntelI810Chipset, nullptr, dsDefaultCapsClr, 4.5f, 1, -0.5f, &dsi810FogVals }, + { kKYROChipset, dsKYROCapsSet, dsKYROCapsClr, -151.0f, 1, 0, &dsDefaultFogVals }, + { kATIR8X00Chipset, dsATIR8X00CapsSet, dsATIR8X00CapsClr, 0, 0, 0, &dsRadeonFogVals }, }; }; @@ -1471,202 +1332,47 @@ void hsG3DDeviceSelector::IFudgeDirectXDevice( hsG3DDeviceRecord &record, hsAssert( strlen( szDesc ) < sizeof( desc ), "D3D device description longer than expected!" ); hsStrcpy( desc, szDesc ); hsStrLower( desc ); - - //// S3-based Cards /////////////////////////////////////////////////////// - /// Detect Savage 4 chipset - if( deviceID == 0x00008a22 || stricmp( szDriver, "s3savg4.dll" ) == 0 || - ( strstr( desc, "diamond" ) != nil && strstr( desc, "stealth iii" ) != nil ) || - strstr( desc, "savage4 " ) != nil ) - { - /// Yup, Savage 4. - hsStatusMessage( "== Using fudge factors for a Savage 4 chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for a Savage 4 chipset" ); - ISetFudgeFactors( kSavage4Chipset, record ); - } - /// Detect Savage 2000 chipset - else if( deviceID == 0x00009102 || - stricmp( szDriver, "s3sav2k.dll" ) == 0 || - ( strstr( desc, "diamond" ) != nil && - strstr( desc, "viperii" ) != nil ) || - strstr( desc, "savage2000 " ) != nil ) - { - /// Yup, Savage 2000. - hsStatusMessage( "== Using fudge factors for a Savage 2000 chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for a Savage 2000 chipset" ); - ISetFudgeFactors( kSavage2000Chipset, record ); - } - /// Detect Savage3D chipset - else if( deviceID == 0x00008a20 || - stricmp( szDriver, "s3_6.dll" ) == 0 || - strstr( desc, "savage3d" ) != nil ) - { - /// Yup, Savage3D. - hsStatusMessage( "== Using fudge factors for a Savage3D chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for a Savage3D chipset" ); - ISetFudgeFactors( kSavage3DChipset, record ); - } - /// Detect Generic S3 chipset - else if( ( strncmp( szDriver, "s3", 2 ) == 0 ) || ( strstr( desc, "savage" ) != nil ) ) - { - /// Yup, Generic S3. - hsStatusMessage( "== Using fudge factors for a generic S3 chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for a generic S3 chipset" ); - ISetFudgeFactors( kS3GenericChipset, record ); - } - //// ATI-based Cards ////////////////////////////////////////////////////// - /// Detect ATI Radeon HD - else if (strstr( desc, "radeon hd" ) != nullptr) - { - hsStatusMessage( "== Using fudge factors for an ATI Radeon HD chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for an ATI Radeon HD chipset" ); - ISetFudgeFactors( kDefaultChipset, record ); - } - - /// Detect ATI Rage 128 Pro chipset - else if( ( deviceID == 0x00005046 && // Normal ATI Rage 128 Pro detection - ( stricmp( szDriver, "ati2dvaa.dll" ) == 0 - || strstr( desc, "rage 128 pro" ) != nil ) ) || - ( deviceID == 0x00005246 && // ATI All-in-wonder--same chipset, diff values - ( stricmp( szDriver, "ati3draa.dll" ) == 0 - || strstr( desc, "all-in-wonder 128" ) != nil ) ) ) - { - hsStatusMessage( "== Using fudge factors for an ATI Rage 128 Pro chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for an ATI Rage 128 Pro chipset" ); - ISetFudgeFactors( kATIRageProChipset, record ); - } - /// Detect(detest?) ATI Rage FURY MAXX chipset - else if( deviceID == 0x00005046 && - ( stricmp( szDriver, "ati3drau.dll" ) == 0 - || strstr( desc, "rage fury" ) != nil ) ) - { - hsStatusMessage( "== Using fudge factors for an ATI Rage Fury MAXX chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for an ATI Rage Fury MAXX chipset" ); - ISetFudgeFactors( kATIRageFuryChipset, record ); - } /// Detect ATI Radeon chipset // We will probably need to differentiate between different Radeons at some point in // the future, but not now. - else if( // deviceID == 0x00005144 && - ( stricmp( szDriver, "ati2dvag.dll" ) == 0 - || strstr( desc, "radeon" ) != nil ) ) + if (stricmp(szDriver, "ati2dvag.dll") == 0 || strstr(desc, "radeon") != nullptr) { int series = 0; const char* str = strstr(desc, "radeon"); if( str ) str += strlen("radeon"); - else - { - str = strstr(desc, "all-in-wonder"); - if( str ) - str += strlen("all-in-wonder"); - } if( str ) { if( 1 == sscanf(str, "%d", &series) ) { - if( (series == 7500) || (series == 7200) ) - { - hsStatusMessage( "== Using fudge factors for ATI Radeon 7200/7500 chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for ATI Radeon 7200/7500 chipset" ); - ISetFudgeFactors( kATIR7500Chipset, record ); - } - else - if( (series >= 7000) && (series < 8000) ) - { - hsStatusMessage( "== Using fudge factors for ATI Radeon 7X00 chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for ATI Radeon 7X00 chipset" ); - ISetFudgeFactors( kATIR7X00Chipset, record ); - } - else if( (series >= 8000) && (series < 9000) ) { hsStatusMessage( "== Using fudge factors for ATI Radeon 8X00 chipset ==\n" ); plDemoDebugFile::Write( " Using fudge factors for ATI Radeon 8X00 chipset" ); ISetFudgeFactors( kATIR8X00Chipset, record ); } - else + else if (series >= 9000) { - series = 0; + hsStatusMessage("== Using fudge factors for ATI Radeon 9X00 chipset ==\n"); + plDemoDebugFile::Write(" Using fudge factors for ATI Radeon 9X00 chipset"); + ISetFudgeFactors(kATIRadeonChipset, record); } - } - else - { - series = 0; - - // Skip white space - while( *str && (*str <= 0x32) ) - str++; - - // I've still never seen either of these, so I'm just going by ATI's site. - // Don't have the option of using device-id's. - if( (str[0] == 'v') && (str[1] == 'e') ) + else { - // Got an alias here. If it's an All-in-Wonder VE, it's really a 7500. - // If it's a Radeon VE, it's really a 7000. - if( strstr(desc, "radeon") ) - series = 7000; - else if( strstr(desc, "all-in-wonder") ) - series = 7500; + series = 0; } } } - if( !series ) + if (series == 0) { - hsStatusMessage( "== Using fudge factors for ATI Radeon chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for ATI Radeon chipset" ); - ISetFudgeFactors( kATIRadeonChipset, record ); + hsStatusMessage("== Using fudge factors for ATI/AMD Radeon X/HD/R chipset ==\n"); + plDemoDebugFile::Write(" Using fudge factors for ATI/AMD Radeon X/HD/R chipset"); + ISetFudgeFactors(kDefaultChipset, record); } } - /// Detect generic ATI chipset - else if( ( strncmp( szDriver, "ati", 3 ) == 0 ) || ( strstr( desc, "ati " ) != nil ) ) - { - hsStatusMessage( "== Using fudge factors for a generic ATI chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for a generic ATI chipset" ); - ISetFudgeFactors( kATIGenericChipset, record ); - } - - //// Matrox-based Cards /////////////////////////////////////////////////// - else if( (deviceID == 0x527) - || strstr(desc, "parhelia") ) - { - hsStatusMessage( "== Using fudge factors for a Matrox Parhelia chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for a Matrox Millenium G400 chipset" ); - ISetFudgeFactors( kMatroxParhelia, record ); - } - /// Detect Matrox G400 chipset - else if( deviceID == 0x00000525 && - ( stricmp( szDriver, "g400d.dll" ) == 0 - || ( strstr( desc, "matrox" ) != nil && strstr( desc, "g400" ) != nil ) ) ) - { - hsStatusMessage( "== Using fudge factors for a Matrox Millenium G400 chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for a Matrox Millenium G400 chipset" ); - ISetFudgeFactors( kMatroxG400Chipset, record ); - } - /// Detect generic Matrox chipset - else if( strstr( desc, "matrox" ) != nil ) - { - hsStatusMessage( "== Using fudge factors for a generic Matrox chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for a generic Matrox chipset" ); - ISetFudgeFactors( kMatroxGenericChipset, record ); - } //// Other Cards ////////////////////////////////////////////////////////// - /// Detect NVidia RIVA TNT chipset - else if( deviceID == 0x00000020 && - ( stricmp( szDriver, "nvdd32.dll" ) == 0 - || strstr( desc, "nvidia riva tnt" ) != nil ) ) - { - hsStatusMessage( "== Using fudge factors for an NVidia RIVA TNT chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for an NVidia RIVA TNT chipset" ); - ISetFudgeFactors( kNVidiaTNTChipset, record ); - if( record.GetMemoryBytes() < 16 * 1024 * 1024 ) - { - hsStatusMessage( "== (also fudging memory up to 16MB) ==\n" ); - plDemoDebugFile::Write( " (also fudging memory up to 16MB)" ); - record.SetMemoryBytes( 16 * 1024 * 1024 ); - } - } /// Detect Intel i810 chipset else if( deviceID == 0x00007125 && ( stricmp( szDriver, "i81xdd.dll" ) == 0 @@ -1683,58 +1389,13 @@ void hsG3DDeviceSelector::IFudgeDirectXDevice( hsG3DDeviceRecord &record, plDemoDebugFile::Write( " Using fudge factors for a KYRO chipset" ); ISetFudgeFactors( kKYROChipset, record ); } - /// Detect for a GeForce-class card. We can be loose here because we want - /// to get ALL GeForce/2/256 cards - else if( strstr( desc, "nvidia" ) != nil && strstr( desc, "geforce2" ) != nil ) - { - hsStatusMessage( "== Using fudge factors for an NVidia GeForce2-based chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for an NVidia GeForce2-based chipset" ); - ISetFudgeFactors( kNVidiaGeForce2Chipset, record ); - } - else if( strstr( desc, "nvidia" ) != nil && strstr( desc, "geforce3" ) != nil ) - { - hsStatusMessage( "== Using fudge factors for an NVidia GeForce3-based chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for an NVidia GeForce3-based chipset" ); - ISetFudgeFactors( kNVidiaGeForce3Chipset, record ); - } - else if( strstr( desc, "nvidia" ) != nil && strstr( desc, "geforce4 mx" ) != nil ) - { - hsStatusMessage( "== Using fudge factors for an NVidia GeForce4MX-based chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for an NVidia GeForce4MX-based chipset" ); - ISetFudgeFactors( kNVidiaGeForce4MXChipset, record ); - } - else if( strstr( desc, "nvidia" ) != nil && strstr( desc, "geforce4" ) != nil ) - { - hsStatusMessage( "== Using fudge factors for an NVidia GeForce4-based chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for an NVidia GeForce4-based chipset" ); - ISetFudgeFactors( kNVidiaGeForce4Chipset, record ); - } - else if( - strstr( desc, "nvidia" ) && strstr( desc, "geforce" ) - && ( - (deviceID == 0x101) - ||(deviceID == 0x100) - ||strstr(desc, "256") - ) - ) - { - hsStatusMessage( "== Using fudge factors for an NVidia GeForce-based chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for an NVidia GeForce-based chipset" ); - ISetFudgeFactors( kNVidiaGeForceChipset, record ); - } - else if( strstr( desc, "nvidia" ) != nil && strstr( desc, "geforce" ) != nil ) + /// Detect for a GeForc FX card. We only need to nerf the really low end one. + else if( strstr( desc, "nvidia" ) != nil && strstr( desc, "geforce fx 5200" ) != nil ) { hsStatusMessage( "== Using fudge factors for an NVidia GeForceFX-based chipset ==\n" ); plDemoDebugFile::Write( " Using fudge factors for an NVidia GeForceFX-based chipset" ); ISetFudgeFactors( kNVidiaGeForceFXChipset, record ); } - /// Detect for a TNT-based card and force it to >= 16MB memory, so we always use it - else if( strstr( desc, "tnt" ) != nil && record.GetMemoryBytes() < 16 * 1024 * 1024 ) - { - hsStatusMessage( "== NVidia TNT-based card detected. Fudging memory reading to 16MB ==\n" ); - plDemoDebugFile::Write( " NVidia TNT-based card detected. Fudging memory reading to 16MB" ); - record.SetMemoryBytes( 16 * 1024 * 1024 ); - } /// Default fudge values else From 9070d70e504a65145d270ad601b32583f814c991 Mon Sep 17 00:00:00 2001 From: Branan Purvine-Riley Date: Sat, 27 Jul 2013 14:50:20 -0700 Subject: [PATCH 5/9] Lots of cleanups to hsG3DeviceDelector --- Sources/Plasma/Apps/plClient/plClient.cpp | 72 -- Sources/Plasma/Apps/plClient/plClient.h | 2 - .../plPipeline/DX/plDXEnumerate.cpp | 34 +- .../plPipeline/hsG3DDeviceSelector.cpp | 622 +----------------- .../plPipeline/hsG3DDeviceSelector.h | 75 +-- 5 files changed, 11 insertions(+), 794 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index a588f75c..610cc3bc 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/Sources/Plasma/Apps/plClient/plClient.cpp @@ -2070,78 +2070,6 @@ void plClient::IAddRenderRequest(plRenderRequest* req) } } -hsG3DDeviceModeRecord plClient::ILoadDevMode(const char* devModeFile) -{ - hsStatusMessage("Load DevMode client\n"); - HWND hWnd = fWindowHndl; - - hsUNIXStream stream; - bool gottaCreate = false; - - // If DevModeFind is specified, use the old method -// if ((GetGameFlags() & kDevModeFind)) -// FindAndSaveDevMode(hWnd, devModeFile); - // Otherwise, use the new method - hsG3DDeviceModeRecord dmr; - if (stream.Open(devModeFile, "rb")) - { - /// It's there, but is the device record valid? - hsG3DDeviceRecord selRec; - hsG3DDeviceMode selMode; - - selRec.Read(&stream); - if( selRec.IsInvalid() ) - { - hsStatusMessage( "WARNING: Old DeviceRecord found on file. Setting defaults..." ); - gottaCreate = true; - } - else - { - /// Read the rest in - selMode.Read(&stream); - - uint16_t performance = stream.ReadLE16(); - - if( performance < 25 ) - plBitmap::SetGlobalLevelChopCount( 2 ); - else if( performance < 75 ) - plBitmap::SetGlobalLevelChopCount( 1 ); - else - plBitmap::SetGlobalLevelChopCount( 0 ); - } - stream.Close(); - - dmr = hsG3DDeviceModeRecord(selRec, selMode); - } - else - gottaCreate = true; - - if( gottaCreate ) - { - - hsG3DDeviceSelector devSel; - devSel.Enumerate(hWnd); - devSel.RemoveUnusableDevModes(true); - - if (!devSel.GetDefault(&dmr)) - { - //hsAssert(0, "plGame::LoadDevMode - No acceptable hardware found"); - hsMessageBox("No suitable rendering devices found.","realMYST",hsMessageBoxNormal); - return dmr; - } - - if (stream.Open(devModeFile, "wb")) - { - dmr.GetDevice()->Write(&stream); - dmr.GetMode()->Write(&stream); - stream.WriteLE16((uint16_t)(0*100)); - stream.Close(); - } - - } - return dmr; -} - void plClient::ResetDisplayDevice(int Width, int Height, int ColorDepth, bool Windowed, int NumAASamples, int MaxAnisotropicSamples, bool VSync) { if(!fPipeline) return; diff --git a/Sources/Plasma/Apps/plClient/plClient.h b/Sources/Plasma/Apps/plClient/plClient.h index 108b9c36..1984b041 100644 --- a/Sources/Plasma/Apps/plClient/plClient.h +++ b/Sources/Plasma/Apps/plClient/plClient.h @@ -135,8 +135,6 @@ protected: pfGameGUIMgr *fGameGUIMgr; - virtual hsG3DDeviceModeRecord ILoadDevMode(const char* devModeFile); - bool IUpdate(); bool IDraw(); bool IDrawProgress(); diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp index 7ec0e622..d1eb4613 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp @@ -367,12 +367,7 @@ void hsGDirect3DTnLEnumerate::IEnumAdapterDevices( IDirect3D9 *pD3D, UINT iAd /// Confirm that HW vertex processing works on this device if (deviceInfo->fDDCaps.DevCaps & D3DDEVCAPS_PUREDEVICE) { -#if 0 - behavior[iFormat] = D3DCREATE_HARDWARE_VERTEXPROCESSING | - D3DCREATE_PUREDEVICE; -#else behavior[iFormat] = D3DCREATE_HARDWARE_VERTEXPROCESSING; -#endif if (SUCCEEDED(IConfirmDevice(&deviceInfo->fDDCaps, behavior[iFormat], currFormat))) { @@ -638,16 +633,6 @@ bool hsG3DDeviceSelector::IGetD3DCardInfo( hsG3DDeviceRecord &record, adapterInfo = &driverD3DInfo->fAdapterInfo; - /// Print out to our demo data file - plDemoDebugFile::Write( "DeviceSelector detected DX Direct3D device. Info:" ); - plDemoDebugFile::Write( " Driver Description", (char *)adapterInfo->Description ); - plDemoDebugFile::Write( " Driver Name", (char *)adapterInfo->Driver ); - plDemoDebugFile::Write( " Vendor ID", (int32_t)adapterInfo->VendorId ); - plDemoDebugFile::Write( " Device ID", (int32_t)adapterInfo->DeviceId ); - plDemoDebugFile::Write( " Version", (char *)record.GetDriverVersion() ); - plDemoDebugFile::Write( " Memory size (in MB)", record.GetMemoryBytes() / ( 1024 * 1024 ) ); - plDemoDebugFile::Write( " Memory size (in bytes)", record.GetMemoryBytes() ); - *vendorID = adapterInfo->VendorId; *deviceID = adapterInfo->DeviceId; *driverString = adapterInfo->Driver; @@ -656,23 +641,6 @@ bool hsG3DDeviceSelector::IGetD3DCardInfo( hsG3DDeviceRecord &record, return true; } -//// IInitDirect3D //////////////////////////////////////////////////////////// - -bool hsG3DDeviceSelector::IInitDirect3D( void ) -{ - // Create a D3D object to use - IDirect3D9 *pD3D = Direct3DCreate9( D3D_SDK_VERSION ); - if( pD3D == nil ) - { - strcpy( fErrorString, "Cannot load DirectX!" ); - return false; - } - pD3D->Release(); - - fErrorString[ 0 ] = 0; - return true; -} - //// ITryDirect3DTnL ////////////////////////////////////////////////////////// void hsG3DDeviceSelector::ITryDirect3DTnL(hsWinRef winRef) @@ -694,7 +662,7 @@ void hsG3DDeviceSelector::ITryDirect3DTnLDriver(D3DEnum_DriverInfo* drivInfo) { hsG3DDeviceRecord devRec; devRec.Clear(); - devRec.SetG3DDeviceType( kDevTypeDirect3DTnL ); + devRec.SetG3DDeviceType( kDevTypeDirect3D ); devRec.SetDriverName( drivInfo->fAdapterInfo.Driver ); devRec.SetDriverDesc( drivInfo->fAdapterInfo.Description ); diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp index f43332e3..58cefbf5 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp @@ -47,21 +47,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include - - #include "hsG3DDeviceSelector.h" #include "hsStream.h" #include "plPipeline.h" -#ifdef HS_OPEN_GL -#if HS_BUILD_FOR_WIN32 -#include -#include -#include -#endif -#endif - /////////////////////////////////////////////////// /////////////////////////////////////////////////// /////////////////////////////////////////////////// @@ -248,7 +238,6 @@ const char* hsG3DDeviceRecord::GetG3DDeviceTypeName() const { static const char* deviceNames[hsG3DDeviceSelector::kNumDevTypes] = { "Unknown", - "Glide", "Direct3D", "OpenGL" }; @@ -499,10 +488,10 @@ hsG3DDeviceSelector::hsG3DDeviceSelector() hsG3DDeviceSelector::~hsG3DDeviceSelector() { - Clear(); + IClear(); } -void hsG3DDeviceSelector::RemoveDiscarded() +void hsG3DDeviceSelector::IRemoveDiscarded() { int i; for( i = 0; i < fRecords.GetCount(); ) @@ -519,7 +508,7 @@ void hsG3DDeviceSelector::RemoveDiscarded() } } -void hsG3DDeviceSelector::Clear() +void hsG3DDeviceSelector::IClear() { int i; for( i = 0; i < fRecords.GetCount(); i++ ) @@ -529,7 +518,6 @@ void hsG3DDeviceSelector::Clear() void hsG3DDeviceSelector::RemoveUnusableDevModes(bool bTough) { - plDemoDebugFile::Write( "Removing unusable devices and modes..." ); for (int i = 0; i < fRecords.GetCount(); i++) { // @@ -543,20 +531,13 @@ void hsG3DDeviceSelector::RemoveUnusableDevModes(bool bTough) (modes[j].GetHeight() == 0) && (modes[j].GetColorDepth() == 0)) { - plDemoDebugFile::Write( " Removing windowed mode on ", (char *)fRecords[ i ].GetDriverDesc() ); modes[j].SetDiscarded(true); } // If tough, remove modes less than 640x480 else if (bTough && ((modes[j].GetWidth() < 640) || (modes[j].GetHeight() < 480))) { - plDemoDebugFile::Write( " Removing mode < 640x480 on ", (char *)fRecords[ i ].GetDriverDesc() ); modes[j].SetDiscarded(true); } - else - { - plString log = plString::Format(" Keeping mode (%dx%d) on device %s", modes[j].GetWidth(), modes[j].GetHeight(), fRecords[ i ].GetDriverDesc()); - plDemoDebugFile::Write( log.c_str() ); - } } // @@ -564,11 +545,9 @@ void hsG3DDeviceSelector::RemoveUnusableDevModes(bool bTough) // if (fRecords[i].GetG3DDeviceType() == hsG3DDeviceSelector::kDevTypeUnknown) { - plDemoDebugFile::Write( " Removing unknown device. Description", (char *)fRecords[ i ].GetDriverDesc() ); fRecords[i].SetDiscarded(true); } - else if( fRecords[i].GetG3DDeviceType() == hsG3DDeviceSelector::kDevTypeDirect3D || - fRecords[i].GetG3DDeviceType() == hsG3DDeviceSelector::kDevTypeDirect3DTnL ) + else if (fRecords[i].GetG3DDeviceType() == hsG3DDeviceSelector::kDevTypeDirect3D) { uint32_t totalMem; @@ -576,22 +555,12 @@ void hsG3DDeviceSelector::RemoveUnusableDevModes(bool bTough) if ((fRecords[i].GetG3DHALorHEL() != hsG3DDeviceSelector::kHHD3DHALDev) && (fRecords[i].GetG3DHALorHEL() != hsG3DDeviceSelector::kHHD3DTnLHalDev)) { - plDemoDebugFile::Write( " Removing software Direct3D device. Description", (char *)fRecords[ i ].GetDriverDesc() ); fRecords[i].SetDiscarded(true); } - else - { - if( fRecords[i].GetG3DDeviceType() == hsG3DDeviceSelector::kDevTypeDirect3DTnL ) - plDemoDebugFile::Write( " Keeping DX8 Direct3D device", (char *)fRecords[ i ].GetDriverDesc() ); - else - plDemoDebugFile::Write( " Keeping Direct3D device", (char *)fRecords[ i ].GetDriverDesc() ); - } } - else - plDemoDebugFile::Write( " Keeping device", (char *)fRecords[ i ].GetDriverDesc() ); } - RemoveDiscarded(); + IRemoveDiscarded(); } //// IAdjustDirectXMemory ///////////////////////////////////////////////////// @@ -621,20 +590,9 @@ uint32_t hsG3DDeviceSelector::IAdjustDirectXMemory( uint32_t cardMem ) #endif } -bool hsG3DDeviceSelector::Init( void ) -{ - // See if we're all capable of initing - if( !IInitDirect3D() ) - { - return false; - } - - return true; -} - void hsG3DDeviceSelector::Enumerate(hsWinRef winRef) { - Clear(); + IClear(); #ifdef HS_BUILD_FOR_WIN32 /// 9.6.2000 - Create the class to use as our temporary window class @@ -650,11 +608,8 @@ void hsG3DDeviceSelector::Enumerate(hsWinRef winRef) hsAssert(ret, "Cannot create temporary window class to test for device modes" ); #endif - /// Now try our devices ITryDirect3DTnL(winRef); -// ITryOpenGL(winRef); - #ifdef HS_BUILD_FOR_WIN32 /// Get rid of the class UnregisterClass( fTempWinClass, GetModuleHandle( nil ) ); @@ -674,7 +629,6 @@ bool hsG3DDeviceSelector::GetDefault (hsG3DDeviceModeRecord *dmr) switch (fRecords[i].GetG3DDeviceType()) { case kDevTypeDirect3D: - case kDevTypeDirect3DTnL: if (fRecords[i].GetG3DHALorHEL() == kHHD3DTnLHalDev) { if (iTnL == -1 @@ -754,437 +708,6 @@ bool hsG3DDeviceSelector::GetDefault (hsG3DDeviceModeRecord *dmr) return true; } -//// ITryOpenGL /////////////////////////////////////////////////////////////// -// Updated 8.24.2000 mcn to (hopefully) detect OpenGL drivers. - -void hsG3DDeviceSelector::ITryOpenGL(hsWinRef winRef) -{ -#ifdef HS_OPEN_GL -#if HS_BUILD_FOR_WIN32 - int i, numDrivers; - int modeRes[ 6 ][ 3 ] = { { 640, 480, 16 }, { 800, 600, 16 }, { 1024, 768, 16 }, - { 1152, 864, 16 }, { 1280, 1024, 16 }, { 1600, 1200, 16 } }; - gls_driver_info driverInfo; - hsG3DDeviceRecord devRec; - hsG3DDeviceMode devMode; - char str[ 128 ]; - HDC hDC; - HGLRC tempContext; - HWND testWindow = nil, testWindow2 = nil; - - WINDOWPLACEMENT oldWindowPlace; - - - /// Save old window position - oldWindowPlace.length = sizeof( oldWindowPlace ); - GetWindowPlacement( (HWND)winRef, &oldWindowPlace ); - - /// Use the GLS API to get us a list of all OpenGL drivers available on - /// this system and their capabilities - numDrivers = glsGetNumberOfDrivers(); - for( i = 0; i < numDrivers; i++ ) - { - /// Get main driver info - glsGetDriverInfo( i, &driverInfo ); - - devRec.SetG3DDeviceType( kDevTypeOpenGL ); - - devRec.SetDriverDesc( driverInfo.aDriverDescription ); - devRec.SetDriverName( driverInfo.GLDriver.aDriverFilePath ); - - sprintf( str, "%d.%d", driverInfo.GLDriver.DriverFileVersionHigh, - driverInfo.GLDriver.DriverFileVersionLow ); - devRec.SetDriverVersion( str ); - - devRec.SetCap( kCapsMipmap ); - devRec.SetCap( kCapsMipmap ); - devRec.SetCap( kCapsPerspective ); - - if( driverInfo.DriverFlags & GLS_FLAGS_FULLSCREEN_ONLY ) - devRec.SetCap( kCapsNoWindow ); - if( !( driverInfo.DriverFlags & GLS_FLAGS_SOFTWARE_ONLY ) ) - devRec.SetCap( kCapsHardware ); - devRec.SetCap( kCapsDoesSmallTextures ); - - /// We have a problem here--OpenGL has no way of detecting the rest of - /// the information we want, so we'll have to guess/kludge on most of it. - - glsLoadDriver( i ); - sprintf( str, "ITryOpenGL(): FOUND OpenGL Driver: %s (%s)\n", driverInfo.aDriverDescription, - driverInfo.GLDriver.aDriverFilePath ); - hsStatusMessage( str ); - - /// (and of COURSE we have to open a bloody rendering context for - /// glGetString to work...whose bright idea was THAT?) - testWindow = CreateWindowEx( WS_EX_APPWINDOW, fTempWinClass, "OpenGL Screen Test Window", - WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE, - 0, 0, 640, 480, nil, nil, GetModuleHandle( nil ), 0 ); - hDC = GetDC( testWindow ); - tempContext = (HGLRC)ICreateTempOpenGLContext( hDC, - driverInfo.DriverFlags & GLS_FLAGS_FULLSCREEN_ONLY ); - if( tempContext != nil ) - { - wglMakeCurrent( hDC, tempContext ); - - IGetExtOpenGLInfo( devRec ); - - /// Reset everything back now - wglMakeCurrent( nil, nil ); - wglDeleteContext( tempContext ); - ReleaseDC( testWindow, hDC ); - } - - /// Resize window to hide what we're about to do - SetWindowPos( testWindow, nil, 0, 0, 1600, 1200, SWP_NOZORDER | SWP_NOMOVE ); - - /// Check for windowed screen mode (which SOMEBODY decided to test for - /// bitdepth of 0 instead of the caps flag we're setting....hmmmm wasn't me....) - if( !( driverInfo.DriverFlags & GLS_FLAGS_FULLSCREEN_ONLY ) ) - { - devMode.Clear(); - devMode.SetWidth( 0 ); - devMode.SetHeight( 0 ); - devMode.SetColorDepth( 0 ); - devRec.GetModes().Append( devMode ); - } - - /// Go get the screen modes - IGetOpenGLModes( devRec, driverInfo.aDriverDescription ); - - /// Get rid of the window now - DestroyWindow( testWindow ); - - /// Unload this driver now - glsUnloadDriver(); - } - - /// Restore old window position - SetWindowPlacement( (HWND)winRef, &oldWindowPlace ); -#endif -#endif -} - -//// IGetOpenGLModes ////////////////////////////////////////////////////////// -// Scans through all the possible imaginable combinations of screen modes, -// pixel formats whatnot and adds the final, culled-down list of graphics -// modes to the given device record. - -void hsG3DDeviceSelector::IGetOpenGLModes( hsG3DDeviceRecord &devRec, char *driverName ) -{ -#ifdef HS_OPEN_GL -#if HS_BUILD_FOR_WIN32 - int j; - int maxMode, mode; - int modeRes[ 6 ][ 3 ] = { { 640, 480, 16 }, { 800, 600, 16 }, { 1024, 768, 16 }, - { 1152, 864, 16 }, { 1280, 1024, 16 }, { 1600, 1200, 16 } }; - int bitDepths[ 3 ] = { 32, 24, 16 }, bitDepth; - hsG3DDeviceMode devMode; - DEVMODE modeInfo; - HWND testWindow = nil, testWindow2 = nil; - char str[ 128 ]; - - - /// Find the maximum resolution that we can support on this monitor--then - /// we'll start there and work down until we find a mode supported by OpenGL - modeInfo.dmSize = sizeof( modeInfo ); - maxMode = -1; - for( j = 0; EnumDisplaySettings( nil, j, &modeInfo ) != 0; j++ ) - { - for( mode = 0; mode < sizeof( modeRes ) / sizeof( modeRes[ 0 ] ); mode++ ) - { - if( modeRes[ mode ][ 0 ] == modeInfo.dmPelsWidth && - modeRes[ mode ][ 1 ] == modeInfo.dmPelsHeight ) - { - if( modeInfo.dmBitsPerPel > modeRes[ mode ][ 2 ] ) - modeRes[ mode ][ 2 ] = modeInfo.dmBitsPerPel; - - if( mode > maxMode ) - { - maxMode = mode; - break; - } - } - } - } - if( maxMode != -1 ) - { - /// Outer loop: loop through color depths - for( bitDepth = 0; bitDepth < 3; bitDepth++ ) - { - /// Loop through each of the display settings, starting at - /// the maxMode and going down, happily get pixel formats for each - modeInfo.dmSize = sizeof( modeInfo ); - modeInfo.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; - for( mode = maxMode; mode >= 0; mode-- ) - { - /// Does this resolution work at this bit depth? - if( modeRes[ mode ][ 2 ] < bitDepths[ bitDepth ] ) - continue; - - /// Attempt to set this screen mode - modeInfo.dmPelsWidth = modeRes[ mode ][ 0 ]; - modeInfo.dmPelsHeight = modeRes[ mode ][ 1 ]; - modeInfo.dmBitsPerPel = bitDepths[ bitDepth ]; - if( ChangeDisplaySettings( &modeInfo, CDS_FULLSCREEN ) == DISP_CHANGE_SUCCESSFUL ) - { - if( ITestOpenGLRes( modeRes[ mode ][ 0 ], modeRes[ mode ][ 1 ], - bitDepths[ bitDepth ], - devRec, driverName ) ) - { - /// Go and add the rest of 'em (we just assume that we can get - /// lower resolutions if we got this one) - for( mode--; mode >= 0; mode-- ) - { - devMode.SetWidth( modeRes[ mode ][ 0 ] ); - devMode.SetHeight( modeRes[ mode ][ 1 ] ); - devMode.SetColorDepth( bitDepths[ bitDepth ] ); - devRec.GetModes().Append( devMode ); - - sprintf( str, "ITryOpenGL(): Assuming mode: %dx%dx%dbpp, %s\n", - modeRes[ mode ][ 0 ], modeRes[ mode ][ 1 ], bitDepths[ bitDepth ], driverName ); - hsStatusMessage( str ); - } - } - } - } - } - - /// Note: this will also reset the screen after any mode changes from - /// creating our context - ChangeDisplaySettings( nil, 0 ); - - if( devRec.GetModes().GetCount() ) - fRecords.Append( devRec ); - } -#endif -#endif -} - -//// ITestOpenGLRes /////////////////////////////////////////////////////////// -// Tests all the possible OpenGL settings once the screen has been set -// to a given test resolution. - -bool hsG3DDeviceSelector::ITestOpenGLRes( int width, int height, int bitDepth, - hsG3DDeviceRecord &devRec, char *driverName ) -{ - bool retValue = false; - -#ifdef HS_OPEN_GL -#if HS_BUILD_FOR_WIN32 - int j, bitDepthFlags, myBitDepth; - hsG3DDeviceMode devMode; - char str[ 128 ]; - HDC hDC, hDC2; - HGLRC tempContext; - HWND testWindow = nil, testWindow2 = nil; - - PIXELFORMATDESCRIPTOR pfd; - - - /// Create test window #1 - testWindow = CreateWindowEx( WS_EX_APPWINDOW, fTempWinClass, "OpenGL Screen Test Window", - WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE, - 0, 0, width, height, - nil, nil, GetModuleHandle( nil ), 0 ); - hDC = GetDC( testWindow ); - - /// Loop through using DescribePixelFormat in an attempt to find all the - /// pixel formats we actually do support using this OpenGL driver - devMode.Clear(); - pfd.nSize = sizeof( pfd ); - bitDepthFlags = 0; - for( j = 1; retValue == false && DescribePixelFormat( hDC, j, sizeof( pfd ), &pfd ) != 0; j++ ) - { - /// Can we use this one? - if( pfd.cColorBits != bitDepth ) - continue; - - myBitDepth = ( pfd.cColorBits == 32 ) ? 0x04 : ( pfd.cColorBits == 24 ) ? 0x02 : 0x01; - - if( ( pfd.dwFlags & PFD_SUPPORT_OPENGL ) && - ( pfd.dwFlags & PFD_DRAW_TO_WINDOW ) && - ( pfd.dwFlags & PFD_DOUBLEBUFFER ) && - ( pfd.iPixelType == PFD_TYPE_RGBA ) && - ( pfd.iLayerType == PFD_MAIN_PLANE ) && - ( ( bitDepthFlags & myBitDepth ) == 0 ) ) - { - /// Looks like it! But is it REALLY? - testWindow2 = CreateWindowEx( WS_EX_APPWINDOW, fTempWinClass, "OpenGL Screen Test Window #2", - WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE, - 0, 0, width, height, - nil, nil, GetModuleHandle( nil ), 0 ); - hDC2 = GetDC( testWindow2 ); - - if( SetPixelFormat( hDC2, j, &pfd ) ) - { - tempContext = wglCreateContext( hDC2 ); - if( tempContext != nil ) - { - if( wglMakeCurrent( hDC2, tempContext ) ) - { - /// Guess it really does work... - devMode.SetWidth( width ); - devMode.SetHeight( height ); - devMode.SetColorDepth( pfd.cColorBits ); - devRec.GetModes().Append( devMode ); - bitDepthFlags |= myBitDepth; - - sprintf( str, "ITryOpenGL(): Adding mode: %dx%dx%dbpp, %s\n", - width, height, pfd.cColorBits, driverName ); - hsStatusMessage( str ); - - wglMakeCurrent( nil, nil ); - retValue = true; /// Break us out - } - wglDeleteContext( tempContext ); - } - } - ReleaseDC( testWindow2, hDC2 ); - DestroyWindow( testWindow2 ); - } - } - ReleaseDC( testWindow, hDC ); - DestroyWindow( testWindow ); - -#endif -#endif - return retValue; -} - - -//// IGetExtOpenGLInfo //////////////////////////////////////////////////////// -// Gets extended info--i.e. info requiring an OpenGL context. Assumes the -// said context is already created and active. - -void hsG3DDeviceSelector::IGetExtOpenGLInfo( hsG3DDeviceRecord &devRec ) -{ -#ifdef HS_OPEN_GL -#if HS_BUILD_FOR_WIN32 - GLint numTMUs; - char *extString, *c, *c2; - char str[ 128 ]; - int j; - - - if( ( extString = (char *)glGetString( GL_RENDERER ) ) != nil ) - { - devRec.SetDeviceDesc( extString ); - - /// Can we guess at the amount of texture memory? - c = strstr( extString, "MB" ); - if( c != nil && c != extString && ( isdigit( *( c - 1 ) ) || isspace( *( c - 1 ) ) ) ) - { - /// Looks like we found a "xxMB" texture memory specification--use it - /// as our guess - c2 = c; - do { - c2--; - } while( c2 >= extString && ( isdigit( *c2 ) || isspace( *c2 ) ) ); - c2++; - - strncpy( str, c2, (uint32_t)c - (uint32_t)c2 ); - j = atoi( str ); - sprintf( str, "ITryOpenGL(): Device has %d MB texture memory\n", j ); - hsStatusMessage( str ); - - j *= 1024 * 1024; /// Translate to bytes - devRec.SetMemoryBytes( j ); - } - else - { - devRec.SetMemoryBytes( 4 * 1024 * 1024 ); - hsStatusMessage( "ITryOpenGL(): WARNING: Cannot determine texture memory for this card, assuming 4MB\n" ); - } - } - else - { - devRec.SetDeviceDesc( "" ); - devRec.SetMemoryBytes( 4 * 1024 * 1024 ); - hsStatusMessage( "ITryOpenGL(): WARNING: Cannot determine texture memory for this card, assuming 4MB\n" ); - } - - - if( ( extString = (char *)glGetString( GL_EXTENSIONS ) ) != nil ) - { - /// For the number of TMUs, we'll detect for the availability of the - /// multitexture extension--if it's there, we'll assume we have two TMUs - /// (if we don't, OpenGL will probably handle it for us--or rather, it BETTER). - if( strstr( extString, "ARB_multitexture" ) ) - devRec.SetLayersAtOnce( 2 ); - else - devRec.SetLayersAtOnce( 1 ); - - /// Can we use compressed textures? - if( strstr( extString, "ARB_texture_compression" ) ) - devRec.SetCap( kCapsCompressTextures ); - } - - /// Get TMU count - glGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &numTMUs ); - if( numTMUs <= 0 ) - numTMUs = 0; - devRec.SetLayersAtOnce( numTMUs ); -#endif -#endif -} - -//// ICreateTempOpenGLContext ///////////////////////////////////////////////// -// Creates a temporary context for testing OpenGL stuff with. - -#ifdef HS_OPEN_GL -#if HS_BUILD_FOR_WIN32 - -uint32_t hsG3DDeviceSelector::ICreateTempOpenGLContext( HDC hDC, bool32 makeItFull ) -{ - DEVMODE modeInfo; - int pixFmt; - - - if( makeItFull ) - { - /// Attempt resolution change to 640x480x32bpp - memset( &modeInfo, 0, sizeof( modeInfo ) ); - modeInfo.dmSize = sizeof( modeInfo ); - modeInfo.dmBitsPerPel = 16; - modeInfo.dmPelsWidth = 640; - modeInfo.dmPelsHeight = 480; - if( ChangeDisplaySettings( &modeInfo, CDS_FULLSCREEN ) != DISP_CHANGE_SUCCESSFUL ) - { - return nil; /// We want fullscreen, can't get it, oops. - } - } - - /// Now try to set a pixel format - PIXELFORMATDESCRIPTOR pfd = { - sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd - 1, // version number - PFD_DRAW_TO_WINDOW | // support window - PFD_SUPPORT_OPENGL | // support OpenGL - PFD_DOUBLEBUFFER, // double buffered - PFD_TYPE_RGBA, // RGBA type - 16, // 24-bit color depth - 0, 0, 0, 0, 0, 0, // color bits ignored - 0, // no alpha buffer - 0, // shift bit ignored - 0, // no accumulation buffer - 0, 0, 0, 0, // accum bits ignored - 0, // 32-bit z-buffer - 0, // no stencil buffer - 0, // no auxiliary buffer - PFD_MAIN_PLANE, // main layer - 0, // reserved - 0, 0, 0 // layer masks ignored - }; - - pixFmt = ChoosePixelFormat( hDC, &pfd ); - if( pixFmt > 0 && SetPixelFormat( hDC, pixFmt, &pfd ) ) - return (uint32_t)wglCreateContext( hDC ); - - return 0; -} -#endif -#endif - /////////////////////////////////////////////////////////////////////////////// //// Fudging Routines ///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// @@ -1315,7 +838,7 @@ void hsG3DDeviceSelector::IFudgeDirectXDevice( hsG3DDeviceRecord &record, /// Send it off to each D3D device, respectively - if( record.GetG3DDeviceType() == kDevTypeDirect3DTnL ) + if( record.GetG3DDeviceType() == kDevTypeDirect3D ) { if( !IGetD3DCardInfo( record, driverInfo, deviceInfo, &vendorID, &deviceID, &szDriver, &szDesc ) ) { @@ -1349,13 +872,11 @@ void hsG3DDeviceSelector::IFudgeDirectXDevice( hsG3DDeviceRecord &record, if( (series >= 8000) && (series < 9000) ) { hsStatusMessage( "== Using fudge factors for ATI Radeon 8X00 chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for ATI Radeon 8X00 chipset" ); ISetFudgeFactors( kATIR8X00Chipset, record ); } else if (series >= 9000) { hsStatusMessage("== Using fudge factors for ATI Radeon 9X00 chipset ==\n"); - plDemoDebugFile::Write(" Using fudge factors for ATI Radeon 9X00 chipset"); ISetFudgeFactors(kATIRadeonChipset, record); } else @@ -1367,7 +888,6 @@ void hsG3DDeviceSelector::IFudgeDirectXDevice( hsG3DDeviceRecord &record, if (series == 0) { hsStatusMessage("== Using fudge factors for ATI/AMD Radeon X/HD/R chipset ==\n"); - plDemoDebugFile::Write(" Using fudge factors for ATI/AMD Radeon X/HD/R chipset"); ISetFudgeFactors(kDefaultChipset, record); } } @@ -1379,29 +899,24 @@ void hsG3DDeviceSelector::IFudgeDirectXDevice( hsG3DDeviceRecord &record, || ( strstr( desc, "intel" ) != nil && strstr( desc, "810" ) != nil ) ) ) { hsStatusMessage( "== Using fudge factors for an Intel i810 chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for an Intel i810 chipset" ); ISetFudgeFactors( kIntelI810Chipset, record ); } /// Detect STMicroelectronics KYRO chipset else if( deviceID == 0x00000010 && ( strstr( desc, "kyro" ) != nil ) ) { hsStatusMessage( "== Using fudge factors for a KYRO chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for a KYRO chipset" ); ISetFudgeFactors( kKYROChipset, record ); } /// Detect for a GeForc FX card. We only need to nerf the really low end one. else if( strstr( desc, "nvidia" ) != nil && strstr( desc, "geforce fx 5200" ) != nil ) { hsStatusMessage( "== Using fudge factors for an NVidia GeForceFX-based chipset ==\n" ); - plDemoDebugFile::Write( " Using fudge factors for an NVidia GeForceFX-based chipset" ); ISetFudgeFactors( kNVidiaGeForceFXChipset, record ); } - /// Default fudge values else { hsStatusMessage( "== Using default fudge factors ==\n" ); - plDemoDebugFile::Write( " Using default fudge factors" ); ISetFudgeFactors( kDefaultChipset, record ); } } @@ -1468,126 +983,3 @@ void hsG3DDeviceSelector::ISetFudgeFactors( uint8_t chipsetID, hsG3DDeviceRec } } } - - - -/////////////////////////////////////////////////////////////////////////////// -// -// Demo Debug File functions -// Created 10.10.2000 by Mathew Burrack @ Cyan, Inc. -// Modified 10.11 mcn to conform (more) to coding standards. -// -/////////////////////////////////////////////////////////////////////////////// - -//// Local Globals //////////////////////////////////////////////////////////// - -#if M3DDEMOINFO // Demo Debug Build -static plDemoDebugFile sMyDDFWriter; - -bool plDemoDebugFile::fIsOpen = false; -FILE *plDemoDebugFile::fDemoDebugFP = nil; -bool plDemoDebugFile::fEnabled = false; -#endif - - -//// IDDFOpen ///////////////////////////////////////////////////////////////// -// Internal function--opens the demo debug file for writing. Returns true -// if successful, false otherwise. - -bool plDemoDebugFile::IDDFOpen( void ) -{ -#if M3DDEMOINFO // Demo Debug Build - char fileName[] = "log/debug_info.dat"; - time_t currTime; - struct tm *localTime; - char timeString[ 27 ]; // see definition of asctime() - char *c; - - - /// Don't open if we're not enabled - if( !fEnabled ) - return false; - - /// Open the file - if( fDemoDebugFP == nil ) - fDemoDebugFP = fopen( fileName, "wt" ); - - if( fDemoDebugFP == nil ) - return( fIsOpen = false ); - - /// Write out a header line - time( &currTime ); - localTime = localtime( &currTime ); - - // Note: asctime includes a carriage return. Gotta strip... - strcpy( timeString, asctime( localTime ) ); - c = strchr( timeString, '\n' ); - if( c != nil ) - *c = 0; - - fprintf( fDemoDebugFP, "\n--- Demo Debug Info File (Created %s) ---\n", timeString ); - - /// All done! - return( fIsOpen = true ); -#else - return false; -#endif -} - -//// IDDFClose //////////////////////////////////////////////////////////////// -// "Whatcha gonna do when the lightning strikes and hits you...." -// -- "Lightning Strikes", Yes, 1999 - - -void plDemoDebugFile::IDDFClose( void ) -{ -#if M3DDEMOINFO // Demo Debug Build - if( fDemoDebugFP != nil ) - { - // Write an exit line (fun fun) - fputs( "--- End of Demo Debug Info File ---\n\n", fDemoDebugFP ); - - // Close - fclose( fDemoDebugFP ); - } - - fIsOpen = false; -#endif -} - -//// Write //////////////////////////////////////////////////////////////////// -// Writes a string to the DDF. If the DDF isn't open, opens it. - -void plDemoDebugFile::Write( const char *string ) -{ -#if M3DDEMOINFO // Demo Debug Build - if( !fIsOpen ) - IDDFOpen(); - - if( fIsOpen ) - fprintf( fDemoDebugFP, "%s\n", string ); -#endif -} - -void plDemoDebugFile::Write( const char *string1, const char *string2 ) -{ -#if M3DDEMOINFO // Demo Debug Build - if( !fIsOpen ) - IDDFOpen(); - - if( fIsOpen ) - fprintf( fDemoDebugFP, "%s: %s\n", string1, string2 ); -#endif -} - -void plDemoDebugFile::Write( const char *string1, int32_t value ) -{ -#if M3DDEMOINFO // Demo Debug Build - if( !fIsOpen ) - IDDFOpen(); - - if( fIsOpen ) - fprintf( fDemoDebugFP, "%s: %d (0x%x)\n", string1, value, value ); -#endif -} - diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h index ec3318f5..ac6cbcb3 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h @@ -306,20 +306,15 @@ class hsG3DDeviceSelector : public hsRefCnt public: enum { kDevTypeUnknown = 0, - kDevTypeGlide, kDevTypeDirect3D, kDevTypeOpenGL, - kDevTypeDirect3DTnL, kNumDevTypes }; enum { kHHTypeUnknown = 0, kHHD3DNullDev, - kHHD3DRampDev, - kHHD3DRGBDev, kHHD3DHALDev, - kHHD3DMMXDev, kHHD3DTnLHalDev, kHHD3DRefDev, @@ -376,10 +371,12 @@ protected: char fErrorString[ 128 ]; + void IClear(); + void IRemoveDiscarded(); + void ITryDirect3DTnLDevice(D3DEnum_DeviceInfo* devInfo, hsG3DDeviceRecord& srcDevRec); void ITryDirect3DTnLDriver(D3DEnum_DriverInfo* drivInfo); void ITryDirect3DTnL(hsWinRef winRef); - bool IInitDirect3D( void ); void IFudgeDirectXDevice( hsG3DDeviceRecord &record, D3DEnum_DriverInfo *driverInfo, D3DEnum_DeviceInfo *deviceInfo ); @@ -388,82 +385,16 @@ protected: bool IGetD3DCardInfo( hsG3DDeviceRecord &record, void *driverInfo, void *deviceInfo, uint32_t *vendorID, uint32_t *deviceID, char **driverString, char **descString ); - void ITryOpenGL( hsWinRef winRef ); - void IGetExtOpenGLInfo( hsG3DDeviceRecord &devRec ); - void IGetOpenGLModes( hsG3DDeviceRecord &devRec, char *driverName ); - bool ITestOpenGLRes( int width, int height, int bitDepth, - hsG3DDeviceRecord &devRec, char *driverName ); -#ifdef HS_OPEN_GL -#if HS_BUILD_FOR_WIN32 - uint32_t ICreateTempOpenGLContext( HDC hDC, bool makeItFull ); -#endif -#endif - void ISetFudgeFactors( uint8_t chipsetID, hsG3DDeviceRecord &record ); public: hsG3DDeviceSelector(); virtual ~hsG3DDeviceSelector(); - void Clear(); - void RemoveDiscarded(); void RemoveUnusableDevModes(bool bTough); // Removes modes and devices not allowed supported in release - bool Init( void ); // Returns false if couldn't init - const char *GetErrorString( void ) { return fErrorString; } - void Enumerate(hsWinRef winRef); - hsTArray& GetDeviceRecords() { return fRecords; } bool GetDefault(hsG3DDeviceModeRecord *dmr); - - hsG3DDeviceRecord* GetRecord(int i) { return &fRecords[i]; } - - void Read(hsStream* s); - void Write(hsStream* s); }; - - -#define M3DDEMOINFO 1 /// Always compiled now, but only enabled if - /// WIN_INIT has DemoInfoOutput in it -/////////////////////////////////////////////////////////////////////////////// -// -// Demo Debug File header file stuff -// Created 10.10.2000 by Mathew Burrack @ Cyan, Inc. -// -/////////////////////////////////////////////////////////////////////////////// - -#include "HeadSpin.h" - -class plDemoDebugFile -{ - public: - plDemoDebugFile() { fDemoDebugFP = nil; fIsOpen = false; fEnabled = false; } - ~plDemoDebugFile() { IDDFClose(); } - - // Static function to write a string to the DDF - static void Write( const char *string ); - - // Static function to write two strings to the DDF - static void Write( const char *string1, const char *string2 ); - - // Static function to write a string and a signed integer value to the DDF - static void Write( const char *string1, int32_t value ); - - // Enables or disables the DDF class - static void Enable( bool yes ) { fEnabled = yes; } - - protected: - static bool fIsOpen; - static FILE *fDemoDebugFP; - static bool fEnabled; - - // Opens the DDF for writing - static bool IDDFOpen( void ); - - // Closes the DDF - static void IDDFClose( void ); -}; - - #endif // hsG3DDeviceSelector_inc From ac238353842ab085179957ab2562f9ba5ea3bbcc Mon Sep 17 00:00:00 2001 From: Branan Purvine-Riley Date: Sat, 27 Jul 2013 15:09:24 -0700 Subject: [PATCH 6/9] Get rid of obsolete readers/writes for device info --- .../plPipeline/hsG3DDeviceSelector.cpp | 195 +----------------- .../plPipeline/hsG3DDeviceSelector.h | 28 --- 2 files changed, 2 insertions(+), 221 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp index 58cefbf5..a13bec23 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp @@ -94,61 +94,13 @@ void hsG3DDeviceMode::Clear() fFSAATypes.Reset(); } -void hsG3DDeviceMode::Read( hsStream* s ) -{ - Clear(); - - fFlags = s->ReadLE32(); - fWidth = s->ReadLE32(); - fHeight = s->ReadLE32(); - fDepth = s->ReadLE32(); - - fZStencilDepths.Reset(); - uint8_t count= s->ReadByte(); - while( count-- ) - fZStencilDepths.Append( s->ReadLE16() ); - - /// Version 9 - fFSAATypes.Reset(); - count = s->ReadByte(); - while( count-- ) - fFSAATypes.Append( s->ReadByte() ); - - fCanRenderToCubics = s->ReadBool(); -} - -void hsG3DDeviceMode::Write( hsStream* s ) const -{ - s->WriteLE32(fFlags); - s->WriteLE32(fWidth); - s->WriteLE32(fHeight); - s->WriteLE32(fDepth); - - uint8_t i, count = (uint8_t)fZStencilDepths.GetCount(); - s->WriteByte( count ); - for( i = 0; i < count; i++ ) - s->WriteLE16( fZStencilDepths[ i ] ); - - /// Version 9 - count = (uint8_t)fFSAATypes.GetCount(); - s->WriteByte( count ); - for( i = 0; i < count; i++ ) - s->WriteByte( fFSAATypes[ i ] ); - - s->WriteBool( fCanRenderToCubics ); -} - -/////////////////////////////////////////////////// -/////////////////////////////////////////////////// -/////////////////////////////////////////////////// - hsG3DDeviceRecord::hsG3DDeviceRecord() : fFlags(kNone), fG3DDeviceType(hsG3DDeviceSelector::kDevTypeUnknown), fG3DDriverDesc(nil), fG3DDriverName(nil), fG3DDriverVersion(nil), fG3DDeviceDesc(nil), fLayersAtOnce(0), fMemoryBytes(0), fG3DHALorHEL(hsG3DDeviceSelector::kHHTypeUnknown), - fZBiasRating( 0 ), fRecordVersion( kCurrRecordVersion ), fLODBiasRating( 0 ), + fZBiasRating( 0 ), fLODBiasRating( 0 ), fFogExpApproxStart( 0.0 ), fFogExp2ApproxStart( 0.0 ), fFogEndBias( 0.0 ), fMaxAnisotropicSamples( 1 ) { SetFogKneeParams( kFogExp, 0, 0 ); @@ -165,7 +117,7 @@ hsG3DDeviceRecord::hsG3DDeviceRecord(const hsG3DDeviceRecord& src) fG3DDeviceType(hsG3DDeviceSelector::kDevTypeUnknown), fG3DDriverDesc(nil), fG3DDriverName(nil), fG3DDriverVersion(nil), fG3DDeviceDesc(nil), fG3DHALorHEL(hsG3DDeviceSelector::kHHTypeUnknown), - fZBiasRating( src.fZBiasRating ), fRecordVersion( kCurrRecordVersion ), fLODBiasRating( 0 ), + fZBiasRating( src.fZBiasRating ), fLODBiasRating( 0 ), fFogExpApproxStart( src.fFogExpApproxStart ), fFogExp2ApproxStart( src.fFogExp2ApproxStart ), fFogEndBias( src.fFogEndBias ), fMaxAnisotropicSamples( src.fMaxAnisotropicSamples ) { @@ -311,149 +263,6 @@ void hsG3DDeviceRecord::Clear() fMaxAnisotropicSamples = 1; } -//// Read ///////////////////////////////////////////////////////////////////// -// 9.6.2000 mcn - Updated to reflect version 2 format -// 9.8.2000 mcn - (temporary?) set to invalid on old (<2) versions - -void hsG3DDeviceRecord::Read(hsStream* s) -{ - Clear(); - - /// Read version - fRecordVersion = s->ReadLE32(); - hsAssert( fRecordVersion <= kCurrRecordVersion, "Invalid version number in hsG3DDeviceRecord::Read()" ); - if( fRecordVersion == kCurrRecordVersion ) - { - fFlags = s->ReadLE32(); - } - else - { - SetInvalid(); - return; -// fFlags = fRecordVersion; -// fRecordVersion = 1; -// hsStatusMessage( "WARNING: Old version of hsG3DDeviceRecord found. Attempting to read." ); - } - - /// Now read everything else in as normal - fG3DDeviceType = s->ReadLE32(); - - int len; - - len = s->ReadLE32(); - fG3DDriverDesc = new char[len + 1]; - s->Read(len, fG3DDriverDesc); - fG3DDriverDesc[len] = 0; - - len = s->ReadLE32(); - fG3DDriverName = new char[len + 1]; - s->Read(len, fG3DDriverName); - fG3DDriverName[len] = 0; - - len = s->ReadLE32(); - fG3DDriverVersion = new char[len + 1]; - s->Read(len, fG3DDriverVersion); - fG3DDriverVersion[len] = 0; - - len = s->ReadLE32(); - fG3DDeviceDesc = new char[len + 1]; - s->Read(len, fG3DDeviceDesc); - fG3DDeviceDesc[len] = 0; - - - fCaps.Read(s); - fLayersAtOnce = s->ReadLE32(); - fMemoryBytes = s->ReadLE32(); - - len = s->ReadLE32(); - fModes.SetCount(len); - int i; - for( i = 0; i < len; i++ ) - fModes[i].Read( s ); - - /// Version 3 stuff - fZBiasRating = s->ReadLEFloat(); - fLODBiasRating = s->ReadLEFloat(); - fFogExpApproxStart = s->ReadLEFloat(); - fFogExp2ApproxStart = s->ReadLEFloat(); - fFogEndBias = s->ReadLEFloat(); - - /// Version 7 stuff - float knee, kneeVal; - knee = s->ReadLEFloat(); kneeVal = s->ReadLEFloat(); - SetFogKneeParams( kFogExp, knee, kneeVal ); - knee = s->ReadLEFloat(); kneeVal = s->ReadLEFloat(); - SetFogKneeParams( kFogExp2, knee, kneeVal ); - - /// Version 9 stuff - fAASetting = s->ReadByte(); - - /// Version A stuff - fMaxAnisotropicSamples = s->ReadByte(); - - /// Reset record version now - fRecordVersion = kCurrRecordVersion; -} - -void hsG3DDeviceRecord::Write(hsStream* s) const -{ - s->WriteLE32( fRecordVersion ); - - s->WriteLE32(fFlags); - - s->WriteLE32(fG3DDeviceType); - - int len; - - len = strlen(fG3DDriverDesc); - s->WriteLE32(len); - s->Write(len, fG3DDriverDesc); - - len = strlen(fG3DDriverName); - s->WriteLE32(len); - s->Write(len, fG3DDriverName); - - len = strlen(fG3DDriverVersion); - s->WriteLE32(len); - s->Write(len, fG3DDriverVersion); - - len = strlen(fG3DDeviceDesc); - s->WriteLE32(len); - s->Write(len, fG3DDeviceDesc); - - fCaps.Write(s); - s->WriteLE32(fLayersAtOnce); - s->WriteLE32(fMemoryBytes); - - s->WriteLE32(fModes.GetCount()); - int i; - for( i = 0; i < fModes.GetCount(); i++ ) - fModes[i].Write( s ); - - /// Version 3 data - s->WriteLEFloat( fZBiasRating ); - s->WriteLEFloat( fLODBiasRating ); - s->WriteLEFloat( fFogExpApproxStart ); - s->WriteLEFloat( fFogExp2ApproxStart ); - s->WriteLEFloat( fFogEndBias ); - - /// Version 7 data - s->WriteLEFloat( fFogKnees[ kFogExp ] ); - s->WriteLEFloat( fFogKneeVals[ kFogExp ] ); - s->WriteLEFloat( fFogKnees[ kFogExp2 ] ); - s->WriteLEFloat( fFogKneeVals[ kFogExp2 ] ); - - /// Version 9 data - s->WriteByte( fAASetting ); - - /// Version A stuff - s->WriteByte( fMaxAnisotropicSamples ); -} - -/////////////////////////////////////////////////// -/////////////////////////////////////////////////// -/////////////////////////////////////////////////// - hsG3DDeviceModeRecord::hsG3DDeviceModeRecord(const hsG3DDeviceRecord& devRec, const hsG3DDeviceMode& devMode) : fDevice(devRec), fMode(devMode) { diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h index ac6cbcb3..df00609d 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h @@ -124,9 +124,6 @@ public: void AddFSAAType( uint8_t type ) { fFSAATypes.Append( type ); } void SetCanRenderToCubics( bool can ) { fCanRenderToCubics = can; } - - void Read(hsStream* s); - void Write(hsStream* s) const; }; class hsG3DDeviceRecord @@ -146,23 +143,6 @@ public: protected: - uint32_t fRecordVersion; /// Version starts at 2 (see .cpp for explanation) - enum { - kCurrRecordVersion = 0x0b - /// Version history: - /// 1 - Initial version (had no version #) - /// 2 - Added Z and LOD bias - /// 3 - Changed Z and LOD bias to floats, added fog tweaks - /// 4 - Changed values for fog tweaks; force reload through version # - /// 5 - Same as #4, updated fog end bias to be based solely on fog quantization/bit depth - /// 6 - Updated values for the ATI boards, Matrox, and i810 - /// 7 - Added fog knee tweaks - /// 8 - Added support for multiple depth/stencil formats per mode - /// 9 - Added multisample types to the mode record - /// A - Added anisotropic sample field - /// B - Added flag for cubic textures support - }; - /// Version < 2 Data uint32_t fFlags; @@ -272,16 +252,8 @@ public: void Clear(); void RemoveDiscarded(); - // PlaceHolder - Whether a mode can window is restricted by the current setup - // of the PC. E.g. if the user changes from 16 bit to TrueColor, the Modes that - // can window are pretty much flipped. So we'll have to pass in enough info (like - // the hWnd?) to find out what the current setup is to make sure it's compatible. - bool ModeCanWindow(void* ctx, hsG3DDeviceMode* mode) { return false; } void SetPixelShaderVersion(int major, int minor) { fPixelShaderMajorVer = major; fPixelShaderMinorVer = minor; } void GetPixelShaderVersion(int &major, int &minor) { major = fPixelShaderMajorVer; minor = fPixelShaderMinorVer; } - - void Read(hsStream* s); - void Write(hsStream* s) const; }; class hsG3DDeviceModeRecord From 696ceace192620cd427862a602e89656e1c7c0aa Mon Sep 17 00:00:00 2001 From: Branan Purvine-Riley Date: Sat, 27 Jul 2013 15:12:28 -0700 Subject: [PATCH 7/9] Remove some unused PS version stuff --- Sources/Plasma/Apps/plClient/plClient.cpp | 22 +++++-------------- .../plPipeline/hsG3DDeviceSelector.h | 5 ----- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index 610cc3bc..5ae7c507 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/Sources/Plasma/Apps/plClient/plClient.cpp @@ -2163,8 +2163,6 @@ void plClient::IDetectAudioVideoSettings() const hsG3DDeviceMode *mode = dmr.GetMode(); bool pixelshaders = rec->GetCap(hsG3DDeviceSelector::kCapsPixelShader); - int psMajor = 0, psMinor = 0; - rec->GetPixelShaderVersion(psMajor, psMinor); plPipeline::fDefaultPipeParams.ColorDepth = hsG3DDeviceSelector::kDefaultDepth; #if defined(HS_DEBUGGING) || defined(DEBUG) @@ -2185,28 +2183,18 @@ void plClient::IDetectAudioVideoSettings() plPipeline::fDefaultPipeParams.Height = hsG3DDeviceSelector::kDefaultHeight; } - plPipeline::fDefaultPipeParams.Shadows = 0; - // enable shadows if TnL is available, meaning not an intel extreme. - if(rec->GetG3DHALorHEL() == hsG3DDeviceSelector::kHHD3DTnLHalDev) - plPipeline::fDefaultPipeParams.Shadows = 1; + plPipeline::fDefaultPipeParams.Shadows = 1; // enable planar reflections if pixelshaders are available plPipeline::fDefaultPipeParams.PlanarReflections = 1; // enable 2x antialiasing and anisotropic to 2 samples if pixelshader version is greater that 2.0 - if(psMajor >= 2) - { - plPipeline::fDefaultPipeParams.AntiAliasingAmount = rec->GetMaxAnisotropicSamples() ? 2 : 0; - plPipeline::fDefaultPipeParams.AnisotropicLevel = mode->GetNumFSAATypes() ? 2 : 0; - } - else - { - plPipeline::fDefaultPipeParams.AntiAliasingAmount = 0; - plPipeline::fDefaultPipeParams.AnisotropicLevel = 0; - } + plPipeline::fDefaultPipeParams.AntiAliasingAmount = rec->GetMaxAnisotropicSamples() ? 2 : 0; + plPipeline::fDefaultPipeParams.AnisotropicLevel = mode->GetNumFSAATypes() ? 2 : 0; - plPipeline::fDefaultPipeParams.TextureQuality = psMajor >= 2 ? 2 : 1; + plPipeline::fDefaultPipeParams.TextureQuality = pixelshaders ? 2 : 1; plPipeline::fDefaultPipeParams.VideoQuality = pixelshaders ? 2 : 1; + plPipeline::fDefaultPipeParams.VSync = false; int val = 0; diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h index df00609d..442ffd81 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h @@ -179,8 +179,6 @@ protected: /// Version A - the anisotropic level we use uint8_t fMaxAnisotropicSamples; // 1 to disable, up to max allowed in hardware - int fPixelShaderMajorVer; - int fPixelShaderMinorVer; public: hsG3DDeviceRecord(); @@ -251,9 +249,6 @@ public: void ClearModes(); void Clear(); void RemoveDiscarded(); - - void SetPixelShaderVersion(int major, int minor) { fPixelShaderMajorVer = major; fPixelShaderMinorVer = minor; } - void GetPixelShaderVersion(int &major, int &minor) { major = fPixelShaderMajorVer; minor = fPixelShaderMinorVer; } }; class hsG3DDeviceModeRecord From fc67738ee80989e79ba65c34521c42e1a30934f4 Mon Sep 17 00:00:00 2001 From: Branan Purvine-Riley Date: Sat, 27 Jul 2013 15:50:10 -0700 Subject: [PATCH 8/9] Remove some obviously obsolete caps --- .../plPipeline/DX/plDXEnumerate.cpp | 4 - .../PubUtilLib/plPipeline/DX/plDXPipeline.cpp | 86 +++---------------- .../PubUtilLib/plPipeline/DX/plDXPipeline.h | 26 +++--- .../plPipeline/hsG3DDeviceSelector.cpp | 22 +---- .../plPipeline/hsG3DDeviceSelector.h | 12 --- 5 files changed, 25 insertions(+), 125 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp index d1eb4613..8588b545 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp @@ -729,10 +729,6 @@ void hsG3DDeviceSelector::ITryDirect3DTnLDevice(D3DEnum_DeviceInfo* devInfo, hsG devRec.SetCap(kCapsPerspective); if( devInfo->fIsHardware ) devRec.SetCap( kCapsHardware ); - if( devInfo->fDDCaps.RasterCaps & D3DPRASTERCAPS_DITHER ) - devRec.SetCap(kCapsDither); - if( devInfo->fDDCaps.RasterCaps & D3DPRASTERCAPS_WBUFFER ) - devRec.SetCap(kCapsWBuffer); if( devInfo->fDDCaps.RasterCaps & D3DPRASTERCAPS_FOGTABLE ) { devRec.SetCap( kCapsFogLinear ); diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp index 42dd103d..496cc6cf 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp @@ -890,7 +890,6 @@ void plDXGeneralSettings::Reset() fNoGammaCorrect = false; fMaxUVWSrc = 8; fCantProj = false; - fLimitedProj = false; fBadManaged = false; fShareDepth = false; fCurrAnisotropy = false; @@ -929,7 +928,7 @@ void plDXPipeline::IInitDeviceState() fD3DDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_LESSEQUAL ); fD3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE ); - fD3DDevice->SetRenderState( D3DRS_ZENABLE, ( fSettings.fD3DCaps & kCapsWBuffer ) ? D3DZB_USEW : D3DZB_TRUE ); + fD3DDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE ); fD3DDevice->SetRenderState( D3DRS_CLIPPING, TRUE ); fD3DDevice->SetRenderState( D3DRS_CULLMODE, fCurrCullMode ); ISetCullMode(); @@ -941,7 +940,7 @@ void plDXPipeline::IInitDeviceState() fD3DDevice->SetRenderState( D3DRS_MULTISAMPLEANTIALIAS, ( fSettings.fD3DCaps & kCapsFSAntiAlias ) ? TRUE : FALSE ); fD3DDevice->SetRenderState( D3DRS_ANTIALIASEDLINEENABLE, FALSE ); - fD3DDevice->SetRenderState( D3DRS_DITHERENABLE, ( fSettings.fD3DCaps & kCapsDither ) ? TRUE : FALSE ); + fD3DDevice->SetRenderState( D3DRS_DITHERENABLE, FALSE ); fD3DDevice->SetRenderState( D3DRS_SPECULARENABLE, FALSE ); fD3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE ); fCurrD3DLiteState = false; @@ -1038,10 +1037,6 @@ void plDXPipeline::ISetCaps() fSettings.fD3DCaps |= kCapsMipmap; if (fCurrentDevice->fDDCaps.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP) fSettings.fD3DCaps |= kCapsCubicMipmap; - if (fCurrentDevice->fDDCaps.RasterCaps & D3DPRASTERCAPS_WBUFFER) - fSettings.fD3DCaps |= kCapsWBuffer; - if (fCurrentDevice->fDDCaps.RasterCaps & D3DPRASTERCAPS_DITHER) - fSettings.fD3DCaps |= kCapsDither; if (fSettings.fNumAASamples > 0) fSettings.fD3DCaps |= kCapsFSAntiAlias; if (fCurrentDevice->fDDCaps.RasterCaps & D3DPRASTERCAPS_WFOG) @@ -1165,16 +1160,8 @@ void plDXPipeline::IRestrictCaps( const hsG3DDeviceRecord& devRec ) fSettings.fD3DCaps &= ~kCapsMipmap; if( !devRec.GetCap( hsG3DDeviceSelector::kCapsCubicMipmap ) ) fSettings.fD3DCaps &= ~kCapsCubicMipmap; - if( !devRec.GetCap( hsG3DDeviceSelector::kCapsWBuffer ) ) - fSettings.fD3DCaps &= ~kCapsWBuffer; if( !devRec.GetCap( hsG3DDeviceSelector::kCapsZBias ) ) fSettings.fD3DCaps &= ~kCapsZBias; -// if( !devRec.GetCap( hsG3DDeviceSelector::kCapsHWTransform ) ) -// fSettings.fD3DCaps &= ~kCapsHWTransform; - if( !devRec.GetCap( hsG3DDeviceSelector::kCapsDither ) ) - fSettings.fD3DCaps &= ~kCapsDither; -// if( devRec.GetAASetting() == 0 ) -// fSettings.fD3DCaps &= ~kCapsFSAntiAlias; if( !devRec.GetCap( hsG3DDeviceSelector::kCapsFogExp ) ) fSettings.fD3DCaps &= ~kCapsExpFog; if( !devRec.GetCap( hsG3DDeviceSelector::kCapsCubicTextures ) ) @@ -1185,8 +1172,6 @@ void plDXPipeline::IRestrictCaps( const hsG3DDeviceRecord& devRec ) if( devRec.GetCap(hsG3DDeviceSelector::kCapsCantProj) ) fSettings.fCantProj = true; - if( devRec.GetCap(hsG3DDeviceSelector::kCapsLimitedProj) ) - fSettings.fLimitedProj = true; if( devRec.GetCap(hsG3DDeviceSelector::kCapsBadManaged) ) fSettings.fBadManaged = true; if( devRec.GetCap(hsG3DDeviceSelector::kCapsShareDepth) ) @@ -1202,11 +1187,6 @@ void plDXPipeline::IRestrictCaps( const hsG3DDeviceRecord& devRec ) if( devRec.GetCap( hsG3DDeviceSelector::kCapsBadYonStuff ) ) fSettings.fD3DCaps |= kCapsHasBadYonStuff; - /// 10.31.2000 mcn - Flag for can't-handle-under-8-pixel-dimensions-on-textures - /// (see, isn't the name flag actually better in retrospect? :) - if( devRec.GetCap( hsG3DDeviceSelector::kCapsNoKindaSmallTexs ) ) - fSettings.fD3DCaps |= kCapsNoKindaSmallTexs; - /// Note: the following SHOULD be here, but we later detect for texture /// formats and reset this flag. It should only be set if it is set already, /// but that means ensuring it's set beforehand, which it might not be. @@ -1268,15 +1248,8 @@ void plDXPipeline::IRestrictCaps( const hsG3DDeviceRecord& devRec ) fManagedCutoff = 1; } - //// Our temp debug flag to force z-buffering... - if( !( fDbgSetupInitFlags & 0x00000001 ) ) - fSettings.fD3DCaps &= ~kCapsWBuffer; - - /// Set up the z-bias scale values, based on z- or w-buffering - if( fSettings.fD3DCaps & kCapsWBuffer ) - fTweaks.fDefaultPerspLayerScale = kPerspLayerScaleW; - else - fTweaks.fDefaultPerspLayerScale = kPerspLayerScale; + /// Set up the z-bias scale values + fTweaks.fDefaultPerspLayerScale = kPerspLayerScale; // Less than 4 layers at once means we have to fallback on uv bumpmapping @@ -3909,9 +3882,7 @@ bool plDXPipeline::BeginRender() } // Superfluous setting of Z state. - fD3DDevice->SetRenderState( D3DRS_ZENABLE, - ( fView.IsPerspective() && ( fSettings.fD3DCaps & kCapsWBuffer ) ) - ? D3DZB_USEW : D3DZB_TRUE ); + fD3DDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE ); /// If we have a renderTarget active, use its viewport ISetViewport(); @@ -8693,11 +8664,6 @@ bool plDXPipeline::IProcessMipmapLevels( plMipmap *mipmap, uint32_t &numLevels, { uint32_t sizeMask = 0x03; - /// 10.31.2000 - If we have this flag set, we really have to cut out - /// sizes under 8x8. So far only true on the KYRO... - if( fSettings.fD3DCaps & kCapsNoKindaSmallTexs ) - sizeMask = 0x07; - int maxLevel = mipmap->GetNumLevels() - 1; /// 9.7.2000 - Also do this test if the card doesn't support @@ -9713,34 +9679,15 @@ hsMatrix44 plDXPipeline::IGetCameraToNDC() // is [x/w, y/w, z/w + t/s, 1/sw] - if( fSettings.fD3DCaps & kCapsWBuffer ) - { - // W-buffering is only true w-buffering on 3dfx cards. On everything else, - // they REALLY base it off the Z value. So we want to scale (but NOT translate) - // the Z... - // Note: the base value for perspLayerScale should be 0.001 for w-buffering, - // not the normal 0.00001 - float scale = 1.f - float(fCurrRenderLayer) * fTweaks.fPerspLayerScale; - - cam2ndc.fMap[0][0] *= scale; - cam2ndc.fMap[1][1] *= scale; - cam2ndc.fMap[2][2] *= scale; - cam2ndc.fMap[3][2] *= scale; - } - else - { - // Z-buffering, so do it the traditional way - float scale = 1.f - float(fCurrRenderLayer) * fTweaks.fPerspLayerScale; -// scale = -1.f; - float zTrans = -scale * float(fCurrRenderLayer) * fTweaks.fPerspLayerTrans; + float scale = 1.f - float(fCurrRenderLayer) * fTweaks.fPerspLayerScale; + float zTrans = -scale * float(fCurrRenderLayer) * fTweaks.fPerspLayerTrans; - cam2ndc.fMap[0][0] *= scale; - cam2ndc.fMap[1][1] *= scale; + cam2ndc.fMap[0][0] *= scale; + cam2ndc.fMap[1][1] *= scale; - cam2ndc.fMap[2][2] *= scale; - cam2ndc.fMap[2][2] += zTrans * cam2ndc.fMap[3][2]; - cam2ndc.fMap[3][2] *= scale; - } + cam2ndc.fMap[2][2] *= scale; + cam2ndc.fMap[2][2] += zTrans * cam2ndc.fMap[3][2]; + cam2ndc.fMap[3][2] *= scale; } else { @@ -11408,9 +11355,6 @@ void plDXPipeline::IRenderProjectionEach(const plRenderPrimFunc& render, hsGMate int iNextPass = iPass + fCurrNumLayers; - if( fSettings.fLimitedProj && (material->GetLayer(iPass)->GetUVWSrc() & ~plLayerInterface::kUVWIdxMask) ) - return; - // For each projector: int k; for( k = 0; k < fLights.fProjEach.GetCount(); k++ ) @@ -12239,12 +12183,6 @@ void plDXPipeline::SubmitShadowSlave(plShadowSlave* slave) if( !(slave && slave->fCaster && slave->fCaster->GetKey()) ) return; - // A board with limited projection capability (i.e. GeForce1) can't - // do perspective shadows (from point source lights) because it - // requires a count3 uvw on 2 texture units (0,1) simultaneously. Just skip. - if( (fSettings.fLimitedProj || fSettings.fCantProj) && slave->fView.GetPerspective() ) - return; - // Ref the shadow caster so we're sure it will still be around when we go to // render it. slave->fCaster->GetKey()->RefObject(); diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.h b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.h index 58dca47a..d0f933fe 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.h @@ -187,21 +187,17 @@ protected: kCapsExpFog = 0x00000040, kCapsExp2Fog = 0x00000080, kCapsRangeFog = 0x00000100, - kCapsWBuffer = 0x00000200, - kCapsTexBoundToStage = 0x00000400, - kCapsDither = 0x00000800, - kCapsLODWatch = 0x00001000, - kCapsFSAntiAlias = 0x00002000, - kCapsLuminanceTextures = 0x00004000, - kCapsDoesSmallTextures = 0x00008000, - kCapsDoesWFog = 0x00010000, - kCapsPixelFog = 0x00020000, - kCapsHasBadYonStuff = 0x00040000, - kCapsNoKindaSmallTexs = 0x00080000, - kCapsNpotTextures = 0x00100000, - - kCapsCubicTextures = 0x00200000, - kCapsCubicMipmap = 0x00400000 + kCapsTexBoundToStage = 0x00000200, + kCapsLODWatch = 0x00000400, + kCapsFSAntiAlias = 0x00000800, + kCapsLuminanceTextures = 0x00001000, + kCapsDoesSmallTextures = 0x00002000, + kCapsDoesWFog = 0x00004000, + kCapsPixelFog = 0x00008000, + kCapsHasBadYonStuff = 0x00010000, + kCapsNpotTextures = 0x00020000, + kCapsCubicTextures = 0x00040000, + kCapsCubicMipmap = 0x00080000 }; enum { kKNone = 0x0, diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp index a13bec23..c896b3df 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp @@ -552,7 +552,6 @@ namespace kDefaultChipset = 0x00, kIntelI810Chipset, kS3GenericChipset, - kKYROChipset, kATIRadeonChipset, kATIR8X00Chipset, kMatroxParhelia, @@ -603,30 +602,19 @@ namespace }; uint32_t dsATIR8X00CapsClr[] = { - 2, // First integer is always the length - hsG3DDeviceSelector::kCapsWBuffer, + 1, // First integer is always the length hsG3DDeviceSelector::kCapsDoesSmallTextures }; uint32_t dsDefaultCapsClr[] = { 1, // First integer is always the length hsG3DDeviceSelector::kCapsDoesSmallTextures }; - uint32_t dsKYROCapsClr[] = { - 2, // First integer is always the length - hsG3DDeviceSelector::kCapsDoesSmallTextures, - hsG3DDeviceSelector::kCapsPixelFog }; - - uint32_t dsKYROCapsSet[] = { - 1, // First integer is always the length - hsG3DDeviceSelector::kCapsNoKindaSmallTexs }; - CFTable dsCFTable[] = - { + { // Chipset ID // F2Set // F2Clear // ZSuck // MaxLayers // LODBias // Fog Value Tables { kDefaultChipset, nullptr, dsDefaultCapsClr, 0, 0, 0, &dsDefaultFogVals }, { kNVidiaGeForceFXChipset, dsGeForceFXCapsSet, nullptr, 0, 0, 0, &dsDefaultFogVals }, { kIntelI810Chipset, nullptr, dsDefaultCapsClr, 4.5f, 1, -0.5f, &dsi810FogVals }, - { kKYROChipset, dsKYROCapsSet, dsKYROCapsClr, -151.0f, 1, 0, &dsDefaultFogVals }, { kATIR8X00Chipset, dsATIR8X00CapsSet, dsATIR8X00CapsClr, 0, 0, 0, &dsRadeonFogVals }, }; @@ -710,12 +698,6 @@ void hsG3DDeviceSelector::IFudgeDirectXDevice( hsG3DDeviceRecord &record, hsStatusMessage( "== Using fudge factors for an Intel i810 chipset ==\n" ); ISetFudgeFactors( kIntelI810Chipset, record ); } - /// Detect STMicroelectronics KYRO chipset - else if( deviceID == 0x00000010 && ( strstr( desc, "kyro" ) != nil ) ) - { - hsStatusMessage( "== Using fudge factors for a KYRO chipset ==\n" ); - ISetFudgeFactors( kKYROChipset, record ); - } /// Detect for a GeForc FX card. We only need to nerf the really low end one. else if( strstr( desc, "nvidia" ) != nil && strstr( desc, "geforce fx 5200" ) != nil ) { diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h index 442ffd81..1ae4602a 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h @@ -143,7 +143,6 @@ public: protected: - /// Version < 2 Data uint32_t fFlags; uint32_t fG3DDeviceType; @@ -161,7 +160,6 @@ protected: hsTArray fModes; - /// New to Version 3 float fZBiasRating; float fLODBiasRating; float fFogExpApproxStart; @@ -170,14 +168,11 @@ protected: // (i.e. for Z fog, it's a percentage of 1 to add on, // for W fog, it's a percentage of the yon) - /// Version 7 - Fog Knee values float fFogKnees[ kNumFogTypes ]; float fFogKneeVals[ kNumFogTypes ]; - /// Version 9 - The actual AA setting we use uint8_t fAASetting; - /// Version A - the anisotropic level we use uint8_t fMaxAnisotropicSamples; // 1 to disable, up to max allowed in hardware public: @@ -289,24 +284,18 @@ public: }; enum { kCapsNone = 0, - kCapsNoWindow, kCapsMipmap, kCapsPerspective, kCapsHardware, - kCapsWBuffer, kCapsCompressTextures, kCapsHWTransform, - kCapsDither, kCapsFogLinear, kCapsFogExp, kCapsFogExp2, kCapsFogRange, - kCapsLODWatch, - kCapsUNUSED, kCapsDoesSmallTextures, kCapsPixelFog, kCapsBadYonStuff, - kCapsNoKindaSmallTexs, kCapsCubicTextures, kCapsCubicMipmap, kCapsZBias, @@ -317,7 +306,6 @@ public: kCapsCantShadow, kCapsMaxUVWSrc2, kCapsCantProj, - kCapsLimitedProj, kCapsShareDepth, kCapsBadManaged, kCapsNoAniso, From 185118d21cddddd338d278025f55f2d5daf4e200 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 30 Nov 2013 22:51:23 -0500 Subject: [PATCH 9/9] Better management of TnLEnums and Direct3D9 object Two of the big nasties, according to profiling, are the TnL enum and creation of Direct3D objects. It turned out we were doing these things several times (3 and 4 respectively) during the init process. So, now we have an hsGDirect3D namespace and some smart pointers to manage them! --- .../PubUtilLib/plPipeline/CMakeLists.txt | 2 + .../PubUtilLib/plPipeline/DX/hsGDirect3D.cpp | 82 ++++++++++ .../PubUtilLib/plPipeline/DX/hsGDirect3D.h | 60 ++++++++ .../plPipeline/DX/plDXEnumerate.cpp | 10 +- .../PubUtilLib/plPipeline/DX/plDXEnumerate.h | 2 - .../PubUtilLib/plPipeline/DX/plDXPipeline.cpp | 142 +++++++----------- .../PubUtilLib/plPipeline/DX/plDXPipeline.h | 2 - 7 files changed, 205 insertions(+), 95 deletions(-) create mode 100644 Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.cpp create mode 100644 Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.h diff --git a/Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt index 45a5fa6c..2f7012f0 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt @@ -32,6 +32,7 @@ set(plPipeline_SOURCES ) set(plDXPipeline_SOURCES + DX/hsGDirect3D.cpp DX/plDXDeviceRefs.cpp DX/plDXEnumerate.cpp DX/plDXPipeline.cpp @@ -73,6 +74,7 @@ set(plPipeline_HEADERS ) set(plDXPipeline_HEADERS + DX/hsGDirect3D.h DX/plDXBufferRefs.h DX/plDXDeviceRef.h DX/plDXEnumerate.h diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.cpp b/Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.cpp new file mode 100644 index 00000000..75e27227 --- /dev/null +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.cpp @@ -0,0 +1,82 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#include "hsGDirect3D.h" +#include "plDXEnumerate.h" + +#include +#include +#include + +static std::unique_ptr s_tnlEnum; +hsGDirect3DTnLEnumerate& hsGDirect3D::EnumerateTnL(bool reenum) +{ + if (reenum || !s_tnlEnum.get()) + s_tnlEnum.reset(new hsGDirect3DTnLEnumerate()); + + // Be nice to legacy code and return a reference... + hsGDirect3DTnLEnumerate* ptr = s_tnlEnum.get(); + return *ptr; +} + +void hsGDirect3D::ReleaseTnLEnum() +{ + s_tnlEnum.release(); +} + +static void IDeleteDirect3D(IDirect3D9* d3d) +{ + while (d3d->Release()) { } +} + +static std::unique_ptr> s_direct3d(nullptr, IDeleteDirect3D); +IDirect3D9* hsGDirect3D::GetDirect3D(bool recreate) +{ + if (recreate || !s_direct3d.get()) { + IDirect3D9* ptr = Direct3DCreate9(D3D_SDK_VERSION); + hsAssert(ptr, "failed to create Direct3D"); + + s_direct3d.reset(ptr); + } + return s_direct3d.get(); +} + diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.h b/Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.h new file mode 100644 index 00000000..4088514c --- /dev/null +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.h @@ -0,0 +1,60 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#ifndef _hsGDirect3D_inc_ +#define _hsGDirect3D_inc_ + +class hsGDirect3DTnLEnumerate; +struct IDirect3D9; + +namespace hsGDirect3D +{ + hsGDirect3DTnLEnumerate& EnumerateTnL(bool reenum=false); + void ReleaseTnLEnum(); + + /** Get a root Direct3D object. + * \remarks You should not hold this pointer. + */ + IDirect3D9* GetDirect3D(bool recreate=false); +} + +#endif // _hsGDirect3D_inc_ diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp index 8588b545..de401b52 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp @@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plDXEnumerate.h" #include "plPipeline/hsG3DDeviceSelector.h" +#include "hsGDirect3D.h" //// Local Typedefs /////////////////////////////////////////////////////////// @@ -281,8 +282,8 @@ hsGDirect3DTnLEnumerate::hsGDirect3DTnLEnumerate() fDrivers.Reset(); // List of DD drivers // Create a D3D object to use - IDirect3D9 *pD3D = Direct3DCreate9( D3D_SDK_VERSION ); - if( pD3D == nil ) + IDirect3D9* pD3D = hsGDirect3D::GetDirect3D(); + if (!pD3D) { strcpy( fEnumeErrorStr, "Cannot load DirectX!" ); return; @@ -309,9 +310,6 @@ hsGDirect3DTnLEnumerate::hsGDirect3DTnLEnumerate() /// Do the mode and device enumeration for this adapter IEnumAdapterDevices( pD3D, iAdapter, newDriver ); } - - // Cleanup - pD3D->Release(); } //// IEnumAdapterDevices ////////////////////////////////////////////////////// @@ -645,7 +643,7 @@ bool hsG3DDeviceSelector::IGetD3DCardInfo( hsG3DDeviceRecord &record, void hsG3DDeviceSelector::ITryDirect3DTnL(hsWinRef winRef) { - hsGDirect3DTnLEnumerate d3dEnum; + hsGDirect3DTnLEnumerate& d3dEnum = hsGDirect3D::EnumerateTnL(); int i; for( i = 0; i < d3dEnum.GetNumDrivers(); i++ ) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.h b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.h index 5a65803f..0a1e0e18 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.h @@ -121,8 +121,6 @@ class hsG3DDeviceMode; class hsGDirect3DTnLEnumerate { protected: - HMODULE fDDrawDLL; - char fEnumeErrorStr[128]; // ドライバ、デバイス列挙エラーメッセージ格納バッファ hsTArray fDrivers; diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp index 496cc6cf..7fee0784 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp @@ -56,6 +56,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include +#include "hsGDirect3D.h" #if defined(DX_OLD_SDK) || defined(__MINGW32__) #include @@ -623,7 +624,7 @@ plDXPipeline::plDXPipeline( hsWinRef hWnd, const hsG3DDeviceModeRecord *devModeR else fSettings.fNumAASamples = devMode->GetFSAAType( devRec->GetAASetting() - 1 ); - hsGDirect3DTnLEnumerate d3dEnum; + hsGDirect3DTnLEnumerate& d3dEnum = hsGDirect3D::EnumerateTnL(); if( d3dEnum.GetEnumeErrorStr()[ 0 ] ) { IShowErrorMessage( (char *)d3dEnum.GetEnumeErrorStr() ); @@ -636,16 +637,6 @@ plDXPipeline::plDXPipeline( hsWinRef hWnd, const hsG3DDeviceModeRecord *devModeR return; } - // Gotta create this very first, so that the device/driver init works - if( !fD3DObject ) - { - if( ICreateMaster() ) - { - IShowErrorMessage( "Cannot create D3D master object" ); - return; - } - } - // Record the requested mode/setup. ISetCurrentDriver( d3dEnum.GetCurrentDriver() ); ISetCurrentDevice( d3dEnum.GetCurrentDevice() ); @@ -693,6 +684,8 @@ plDXPipeline::plDXPipeline( hsWinRef hWnd, const hsG3DDeviceModeRecord *devModeR plStatusLog::AddLineS("pipeline.log", "%d, %d, %d", temp[i].Width, temp[i].Height, 32); }*/ + // We don't need the TnL enumeration for the lifetime of the game, so say goodbye! + hsGDirect3D::ReleaseTnLEnum(); } // Cleanup - Most happens in IReleaseDeviceObject(). @@ -720,7 +713,7 @@ plDXPipeline::~plDXPipeline() // built from. For example, the fD3DObject pointer is set to nil so that it's safe // to delete or set to a valid pointer. It must be set to a valid pointer // before the pipeline can be used for much. -// After the core initialization is done (in ICreateMaster and ICreateDeviceObjects) +// After the core initialization is done (in ICreateDeviceObjects) // render state will be initialized in IInitDeviceState. void plDXPipeline::IClearMembers() @@ -772,7 +765,6 @@ void plDXPipeline::IClearMembers() fBlurVBuffers[i] = nil; fBlurVSHandle = 0; - fD3DObject = nil; fD3DDevice = nil; fD3DBackBuff = nil; fD3DDepthSurface = nil; @@ -1388,11 +1380,13 @@ void plDXPipeline::ISetCurrentDriver( D3DEnum_DriverInfo *driv ) fCurrentDriver->fCurrentDevice = nil; /// Go looking for an adapter to match this one + IDirect3D9* d3d = hsGDirect3D::GetDirect3D(); UINT iAdapter; - for( fCurrentAdapter = 0, iAdapter = 0; iAdapter < fD3DObject->GetAdapterCount(); iAdapter++ ) + + for( fCurrentAdapter = 0, iAdapter = 0; iAdapter < d3d->GetAdapterCount(); iAdapter++ ) { D3DADAPTER_IDENTIFIER9 adapterInfo; - fD3DObject->GetAdapterIdentifier( iAdapter, 0, &adapterInfo ); + d3d->GetAdapterIdentifier( iAdapter, 0, &adapterInfo ); if( adapterInfo.DeviceIdentifier == fCurrentDriver->fAdapterInfo.DeviceIdentifier ) { @@ -1469,9 +1463,9 @@ bool plDXPipeline::IFindCompressedFormats() for( i = 0; toCheckFor[ i ] != D3DFMT_UNKNOWN; i++ ) { - if( FAILED( fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, - fCurrentMode->fDDmode.Format, - 0, D3DRTYPE_TEXTURE, toCheckFor[ i ] ) ) ) + if( FAILED( hsGDirect3D::GetDirect3D()->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, + fCurrentMode->fDDmode.Format, + 0, D3DRTYPE_TEXTURE, toCheckFor[ i ] ) ) ) return false; } @@ -1491,9 +1485,9 @@ bool plDXPipeline::IFindLuminanceFormats() for( i = 0; toCheckFor[ i ] != D3DFMT_UNKNOWN; i++ ) { - if( FAILED( fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, - fCurrentMode->fDDmode.Format, - 0, D3DRTYPE_TEXTURE, toCheckFor[ i ] ) ) ) + if (FAILED(hsGDirect3D::GetDirect3D()->CheckDeviceFormat(fCurrentAdapter, fCurrentDevice->fDDType, + fCurrentMode->fDDmode.Format, + 0, D3DRTYPE_TEXTURE, toCheckFor[ i ] ) ) ) return false; } @@ -1508,9 +1502,9 @@ bool plDXPipeline::IFindLuminanceFormats() bool plDXPipeline::ITextureFormatAllowed( D3DFORMAT format ) { - if( FAILED( fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, - fCurrentMode->fDDmode.Format, - 0, D3DRTYPE_TEXTURE, format ) ) ) + if (FAILED( hsGDirect3D::GetDirect3D()->CheckDeviceFormat(fCurrentAdapter, fCurrentDevice->fDDType, + fCurrentMode->fDDmode.Format, + 0, D3DRTYPE_TEXTURE, format ) ) ) return false; return true; @@ -1555,23 +1549,6 @@ bool plDXPipeline::IsDebugFlagSet( uint32_t flag ) const //// Device Creation ////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -//// ICreateMaster //////////////////////////////////////////////////////////// -// Creates the master Direct3D objects. I guess just in case you want -// multiple Direct3D devices.... :~ - -bool plDXPipeline::ICreateMaster() -{ - hsAssert( !fD3DObject, "ICreateMaster() should only be called for Master Direct3DDevice" ); - - /// The new DirectX Way: Create a Direct3D object, out of which everything else springs - fD3DObject = Direct3DCreate9( D3D_SDK_VERSION ); - - if( fD3DObject == nil ) - return ICreateFail( "Cannot create Direct3D object" ); - - return false; -} - //// ICreateDevice //////////////////////////////////////////////////// // // Creates the device. Surfaces, buffers, etc. created separately (in case of lost device). @@ -1587,7 +1564,11 @@ bool plDXPipeline::ICreateDevice(bool windowed) char msg[ 256 ]; #endif // DBG_WRITE_FORMATS - INIT_ERROR_CHECK( fD3DObject->GetAdapterDisplayMode( fCurrentAdapter, &dispMode ), + IDirect3D9* d3d = hsGDirect3D::GetDirect3D(); + if (!d3d) + return ICreateFail("Failed to get Direct3D Object"); + + INIT_ERROR_CHECK( d3d->GetAdapterDisplayMode( fCurrentAdapter, &dispMode ), "Cannot get desktop display mode" ); // save desktop properties @@ -1684,10 +1665,10 @@ bool plDXPipeline::ICreateDevice(bool windowed) #ifndef PLASMA_EXTERNAL_RELEASE UINT adapter; - for (adapter = 0; adapter < fD3DObject->GetAdapterCount(); adapter++) + for (adapter = 0; adapter < d3d->GetAdapterCount(); adapter++) { D3DADAPTER_IDENTIFIER9 id; - fD3DObject->GetAdapterIdentifier(adapter, 0, &id); + d3d->GetAdapterIdentifier(adapter, 0, &id); // We should be matching against "NVIDIA NVPerfHUD", but the space // in the description seems to be bogus. This seems to be a fair @@ -1705,9 +1686,9 @@ bool plDXPipeline::ICreateDevice(bool windowed) } #endif // PLASMA_EXTERNAL_RELEASE - INIT_ERROR_CHECK( fD3DObject->CreateDevice( fCurrentAdapter, fCurrentDevice->fDDType, - fSettings.fHWnd, fCurrentMode->fDDBehavior, - ¶ms, &fD3DDevice ), + INIT_ERROR_CHECK( d3d->CreateDevice( fCurrentAdapter, fCurrentDevice->fDDType, + fSettings.fHWnd, fCurrentMode->fDDBehavior, + ¶ms, &fD3DDevice ), "Cannot create primary display surface via CreateDevice()" ); fSettings.fPresentParams = params; @@ -1736,6 +1717,8 @@ bool plDXPipeline::ICreateDevice(bool windowed) // will work. bool plDXPipeline::IFindDepthFormat(D3DPRESENT_PARAMETERS& params) { + IDirect3D9* d3d = hsGDirect3D::GetDirect3D(); + // Okay, we're not using the stencil buffer right now, and it's bringing out // some painful driver bugs on the GeForce2. So rather than go out of our way // looking for trouble, we're going to look for a depth buffer with NO STENCIL. @@ -1747,11 +1730,11 @@ bool plDXPipeline::IFindDepthFormat(D3DPRESENT_PARAMETERS& params) ||(fmt == D3DFMT_D24X8) ||(fmt == D3DFMT_D16) ) { - HRESULT hr = fD3DObject->CheckDeviceMultiSampleType(fCurrentAdapter, - fCurrentDevice->fDDType, - fmt, - fCurrentMode->fWindowed ? TRUE : FALSE, - params.MultiSampleType, NULL); + HRESULT hr = d3d->CheckDeviceMultiSampleType(fCurrentAdapter, + fCurrentDevice->fDDType, + fmt, + fCurrentMode->fWindowed ? TRUE : FALSE, + params.MultiSampleType, NULL); if( !FAILED(hr) ) { params.AutoDepthStencilFormat = fmt; @@ -1767,11 +1750,11 @@ bool plDXPipeline::IFindDepthFormat(D3DPRESENT_PARAMETERS& params) D3DFORMAT fmt = fCurrentMode->fDepthFormats[ i ]; if( fmt == D3DFMT_D15S1 || fmt == D3DFMT_D24X4S4 || fmt == D3DFMT_D24S8 ) { - HRESULT hr = fD3DObject->CheckDeviceMultiSampleType(fCurrentAdapter, - fCurrentDevice->fDDType, - fmt, - fCurrentMode->fWindowed ? TRUE : FALSE, - params.MultiSampleType, NULL); + HRESULT hr = d3d->CheckDeviceMultiSampleType(fCurrentAdapter, + fCurrentDevice->fDDType, + fmt, + fCurrentMode->fWindowed ? TRUE : FALSE, + params.MultiSampleType, NULL); if( !FAILED(hr) ) { params.AutoDepthStencilFormat = fmt; @@ -2033,16 +2016,6 @@ void plDXPipeline::IReleaseDeviceObjects() fD3DDevice = nil; } - if( fD3DObject != nil ) - { - LONG ret; - while( ret = fD3DObject->Release() ) - { - hsStatusMessageF("%d - Error releasing Direct3D Object", ret); - } - fD3DObject = nil; - } - fManagedAlloced = false; fAllocUnManaged = false; } @@ -2541,13 +2514,10 @@ void plDXPipeline::Resize( uint32_t width, uint32_t height ) } // Recreate - if( !fD3DObject ) + if( hsGDirect3D::GetDirect3D(true) ) { - if( ICreateMaster() ) - { - IShowErrorMessage( "Cannot create D3D master object" ); - return; - } + IShowErrorMessage( "Cannot create D3D master object" ); + return; } // Go recreate surfaces and DX-dependent objects @@ -4780,6 +4750,7 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur uint16_t flags, width, height; int8_t bitDepth, zDepth, stencilDepth, stencilIndex; D3DFORMAT depthFormats[] = { D3DFMT_D24X8, D3DFMT_D24X4S4, D3DFMT_D24S8 }; + IDirect3D9* d3d = hsGDirect3D::GetDirect3D(); flags = owner->GetFlags(); @@ -4846,8 +4817,8 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur } /// Check the device format - if( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, - D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) + if( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, + D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) { if( bitDepth == 16 ) { @@ -4859,8 +4830,8 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur bitDepth = 16; surfFormat = D3DFMT_A4R4G4B4; } - if( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, - D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) + if( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, + D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) { IGetD3DError(); return false; @@ -4869,8 +4840,8 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur if( zDepth ) { - while( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, - D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthFormat ) ) ) + while( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, + D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthFormat ) ) ) { if( stencilIndex < sizeof( depthFormats ) / sizeof( depthFormats[ 0 ] ) - 1 ) { @@ -4884,8 +4855,8 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur } } - if( FAILED( fSettings.fDXError = fD3DObject->CheckDepthStencilMatch( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, - surfFormat, depthFormat ) ) ) + if( FAILED( fSettings.fDXError = d3d->CheckDepthStencilMatch( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, + surfFormat, depthFormat ) ) ) { IGetD3DError(); return false; @@ -4912,6 +4883,7 @@ bool plDXPipeline::IFindRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur height = owner->GetHeight(); bitDepth = owner->GetPixelSize(); + IDirect3D9* d3d = hsGDirect3D::GetDirect3D(); if( flags != 0 ) { if( flags & plRenderTarget::kIsTexture ) @@ -4932,8 +4904,8 @@ bool plDXPipeline::IFindRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur } /// Check the device format - if( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, - D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) + if( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, + D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) { if( bitDepth == 16 ) { @@ -4945,8 +4917,8 @@ bool plDXPipeline::IFindRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur bitDepth = 16; surfFormat = D3DFMT_A4R4G4B4; } - if( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, - D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) + if( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, + D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) { IGetD3DError(); return false; diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.h b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.h index d0f933fe..46d40412 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.h @@ -208,7 +208,6 @@ protected: plDXPlateManager* fPlateMgr; // The main D3D interfaces - LPDIRECT3D9 fD3DObject; // The main D3D object LPDIRECT3DDEVICE9 fD3DDevice; // The D3D rendering device IDirect3DSurface9* fD3DMainSurface; IDirect3DSurface9* fD3DDepthSurface; @@ -502,7 +501,6 @@ protected: void ISetCurrentDevice( D3DEnum_DeviceInfo *dev ); void ISetCurrentMode( D3DEnum_ModeInfo *mode ); - bool ICreateMaster(); bool ICreateDevice(bool windowed); bool ICreateNormalSurfaces();