Browse Source

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.
Adam Johnson 11 years ago
parent
commit
60c544e1ff
  1. 23
      Sources/Plasma/PubUtilLib/plGImage/hsDXTDirectXCodec.cpp
  2. 3
      Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt
  3. 43
      Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp
  4. 13
      Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp
  5. 78
      Sources/Plasma/PubUtilLib/plPipeline/hsGDDrawDllLoad.cpp
  6. 62
      Sources/Plasma/PubUtilLib/plPipeline/hsGDDrawDllLoad.h

23
Sources/Plasma/PubUtilLib/plGImage/hsDXTDirectXCodec.cpp

@ -53,7 +53,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h" #include "HeadSpin.h"
#include <functional>
#include <memory>
#if HS_BUILD_FOR_WIN32 #if HS_BUILD_FOR_WIN32
# include "hsWindows.h"
# include <ddraw.h> # include <ddraw.h>
# include <d3d9.h> # include <d3d9.h>
#endif #endif
@ -62,7 +66,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsColorRGBA.h" #include "hsColorRGBA.h"
#include "plMipmap.h" #include "plMipmap.h"
#include "hsCodecManager.h" #include "hsCodecManager.h"
#include "plPipeline/hsGDDrawDllLoad.h"
#if HS_BUILD_FOR_WIN32 #if HS_BUILD_FOR_WIN32
namespace { namespace {
@ -144,26 +147,20 @@ bool hsDXTDirectXCodec::IInitialize()
{ {
fFlags |= kInitialized; fFlags |= kInitialized;
// if( hsGDDrawDllLoad::GetDDrawDll() == nil ) DIRECTDRAWCREATEEX DirectDrawCreateEx = nullptr;
// return false;
DIRECTDRAWCREATEEX DirectDrawCreateEx = 0;
// Initialize DirectDraw // Initialize DirectDraw
HRESULT hr; std::unique_ptr<HINSTANCE__, std::function<BOOL(HMODULE)>> ddraw(LoadLibraryA("ddraw.dll"), FreeLibrary);
DirectDrawCreateEx = (DIRECTDRAWCREATEEX)GetProcAddress( hsGDDrawDllLoad::GetD3DDll(), "DirectDrawCreateEx" ); DirectDrawCreateEx = (DIRECTDRAWCREATEEX)GetProcAddress(ddraw.get(), "DirectDrawCreateEx");
if( DirectDrawCreateEx == nil ) if (!DirectDrawCreateEx)
return false; return false;
/// Using EMULATIONONLY here usually fails--using NULL forces the /// Using EMULATIONONLY here usually fails--using NULL forces the
/// use of the standard display driver, which DOES work. /// use of the standard display driver, which DOES work.
if (FAILED(hr = DirectDrawCreateEx((GUID FAR *)NULL/*DDCREATE_EMULATIONONLY*/, (VOID**)&fDirectDraw, IID_IDirectDraw7, NULL))) if (FAILED(DirectDrawCreateEx((GUID FAR *)NULL/*DDCREATE_EMULATIONONLY*/, (VOID**)&fDirectDraw, IID_IDirectDraw7, NULL)))
return false;
if (FAILED(hr = fDirectDraw->SetCooperativeLevel(NULL, DDSCL_NORMAL)))
return false; return false;
return true; return SUCCEEDED(fDirectDraw->SetCooperativeLevel(NULL, DDSCL_NORMAL));
} }
#endif #endif

3
Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt

@ -14,7 +14,6 @@ endif(WIN32)
set(plPipeline_SOURCES set(plPipeline_SOURCES
hsG3DDeviceSelector.cpp hsG3DDeviceSelector.cpp
hsGColorizer.cpp hsGColorizer.cpp
hsGDDrawDllLoad.cpp
plCaptureRender.cpp plCaptureRender.cpp
plCubicRenderTargetModifier.cpp plCubicRenderTargetModifier.cpp
plCullTree.cpp plCullTree.cpp
@ -46,7 +45,6 @@ set(plPipeline_HEADERS
hsFogControl.h hsFogControl.h
hsG3DDeviceSelector.h hsG3DDeviceSelector.h
hsGColorizer.h hsGColorizer.h
hsGDDrawDllLoad.h
hsGDeviceRef.h hsGDeviceRef.h
hsWinRef.h hsWinRef.h
plBinkPlayer.h plBinkPlayer.h
@ -91,6 +89,7 @@ set(plDXPipeline_HEADERS
if(WIN32) if(WIN32)
add_library(plPipeline STATIC ${plPipeline_SOURCES} ${plDXPipeline_SOURCES} ${plPipeline_HEADERS} ${plDXPipeline_HEADERS}) add_library(plPipeline STATIC ${plPipeline_SOURCES} ${plDXPipeline_SOURCES} ${plPipeline_HEADERS} ${plDXPipeline_HEADERS})
target_link_libraries(plPipeline ${DirectX_LIBRARIES})
else() else()
add_library(plPipeline STATIC ${plPipeline_SOURCES} ${plPipeline_HEADERS}) add_library(plPipeline STATIC ${plPipeline_SOURCES} ${plPipeline_HEADERS})
endif() endif()

43
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 Mead, WA 99021
*==LICENSE==*/ *==LICENSE==*/
#include "plDXEnumerate.h"
#include <ddraw.h>
#include "plPipeline/hsGDDrawDllLoad.h" #include "plDXEnumerate.h"
#include "plPipeline/hsG3DDeviceSelector.h" #include "plPipeline/hsG3DDeviceSelector.h"
@ -219,8 +217,7 @@ HRESULT hsGDirect3DTnLEnumerate::D3DEnum_SelectDefaultDriver( DWORD dwFlags )
{ {
if( dwFlags & D3DENUM_CANWINDOW ) if( dwFlags & D3DENUM_CANWINDOW )
{ {
if( (pDriver == &fDrivers[0]) if( (pDriver == &fDrivers[0]) )
&&( pDevice->fDDCaps.Caps2 & DDCAPS2_CANRENDERWINDOWED ) )
{ {
if( ( pDevice->fDDCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ) if( ( pDevice->fDDCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
^ !(dwFlags & D3DENUM_TNLHAL) ) ^ !(dwFlags & D3DENUM_TNLHAL) )
@ -286,26 +283,8 @@ hsGDirect3DTnLEnumerate::hsGDirect3DTnLEnumerate()
fCurrentDriver = NULL; // The selected DD driver fCurrentDriver = NULL; // The selected DD driver
fDrivers.Reset(); // List of DD drivers 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 // Create a D3D object to use
IDirect3D9 *pD3D = procPtr( D3D_SDK_VERSION ); IDirect3D9 *pD3D = Direct3DCreate9( D3D_SDK_VERSION );
if( pD3D == nil ) if( pD3D == nil )
{ {
strcpy( fEnumeErrorStr, "Cannot load DirectX!" ); strcpy( fEnumeErrorStr, "Cannot load DirectX!" );
@ -684,22 +663,8 @@ bool hsG3DDeviceSelector::IGetD3DCardInfo( hsG3DDeviceRecord &record,
bool hsG3DDeviceSelector::IInitDirect3D( void ) 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 // Create a D3D object to use
IDirect3D9 *pD3D = procPtr( D3D_SDK_VERSION ); IDirect3D9 *pD3D = Direct3DCreate9( D3D_SDK_VERSION );
if( pD3D == nil ) if( pD3D == nil )
{ {
strcpy( fErrorString, "Cannot load DirectX!" ); strcpy( fErrorString, "Cannot load DirectX!" );

13
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 "hsWindows.h"
#include <d3d9.h> #include <d3d9.h>
#include <ddraw.h>
#include <d3dx9mesh.h> #include <d3dx9mesh.h>
#if defined(DX_OLD_SDK) || defined(__MINGW32__) #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 "plPipeline/plDebugText.h"
#include "plDXEnumerate.h" #include "plDXEnumerate.h"
#include "plPipeline/hsG3DDeviceSelector.h" #include "plPipeline/hsG3DDeviceSelector.h"
#include "plPipeline/hsGDDrawDllLoad.h"
#include "hsResMgr.h" #include "hsResMgr.h"
#include "plPipeline/plStatusLogDrawer.h" #include "plPipeline/plStatusLogDrawer.h"
#include "plQuality.h" #include "plQuality.h"
@ -1593,16 +1591,7 @@ bool plDXPipeline::ICreateMaster()
hsAssert( !fD3DObject, "ICreateMaster() should only be called for Master Direct3DDevice" ); hsAssert( !fD3DObject, "ICreateMaster() should only be called for Master Direct3DDevice" );
/// The new DirectX Way: Create a Direct3D object, out of which everything else springs /// The new DirectX Way: Create a Direct3D object, out of which everything else springs
if( hsGDDrawDllLoad::GetD3DDll() == nil ) fD3DObject = Direct3DCreate9( D3D_SDK_VERSION );
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 );
if( fD3DObject == nil ) if( fD3DObject == nil )
return ICreateFail( "Cannot create Direct3D object" ); return ICreateFail( "Cannot create Direct3D object" );

78
Sources/Plasma/PubUtilLib/plPipeline/hsGDDrawDllLoad.cpp

@ -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 <http://www.gnu.org/licenses/>.
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 <ddraw.h>
#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

62
Sources/Plasma/PubUtilLib/plPipeline/hsGDDrawDllLoad.h

@ -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 <http://www.gnu.org/licenses/>.
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
Loading…
Cancel
Save