gfxD3D9Device.pc.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "gfx/D3D9/pc/gfxPCD3D9Device.h"
  23. #include "gfx/D3D9/gfxD3D9CardProfiler.h"
  24. #include "gfx/D3D9/gfxD3D9Shader.h"
  25. #include "gfx/D3D9/gfxD3D9VertexBuffer.h"
  26. #include "gfx/D3D9/gfxD3D9EnumTranslate.h"
  27. #include "core/strings/unicode.h"
  28. #include "console/console.h"
  29. //------------------------------------------------------------------------------
  30. // D3DX Function binding
  31. //------------------------------------------------------------------------------
  32. bool d3dxBindFunction( DLibrary *dll, void *&fnAddress, const char *name )
  33. {
  34. fnAddress = dll->bind( name );
  35. if (!fnAddress)
  36. Con::warnf( "D3DX Loader: DLL bind failed for %s", name );
  37. return fnAddress != 0;
  38. }
  39. void GFXD3D9Device::initD3DXFnTable()
  40. {
  41. if ( smD3DX.isLoaded )
  42. return;
  43. // We only load the d3dx version that we compiled
  44. // and linked against which should keep unexpected
  45. // problems from newer or older SDKs to a minimum.
  46. String d3dxVersion = String::ToString( "d3dx9_%d.dll", (S32)D3DX_SDK_VERSION );
  47. smD3DX.dllRef = OsLoadLibrary( d3dxVersion );
  48. // If the d3dx version we requested didn't load then we have
  49. // a corrupt or old install of DirectX.... prompt them to update.
  50. if ( !smD3DX.dllRef )
  51. {
  52. Con::errorf( "Unsupported DirectX version!" );
  53. Platform::messageBox( Con::getVariable( "$appName" ),
  54. "DirectX could not be started!\r\n"
  55. "Please be sure you have the latest version of DirectX installed.",
  56. MBOk, MIStop );
  57. Platform::forceShutdown( -1 );
  58. }
  59. smD3DX.isLoaded = true;
  60. #define D3DX_FUNCTION(fn_name, fn_return, fn_args) \
  61. smD3DX.isLoaded &= d3dxBindFunction(smD3DX.dllRef, *(void**)&smD3DX.fn_name, #fn_name);
  62. # include "gfx/D3D9/d3dx9Functions.h"
  63. #undef D3DX_FUNCTION
  64. AssertISV( smD3DX.isLoaded, "D3DX Failed to load all functions." );
  65. // HACK: For some reason in the latest versions of
  66. // the D3D SDK on the PC the shader compiler will load
  67. // and unload the compiler DLL over and over with each
  68. // shader compiled.
  69. //
  70. // By loading the DLL once ourselves we keep it from
  71. // ever unloading it which makes shader compiling faster.
  72. //
  73. String compilerVersion = String::ToString( "D3DCompiler_%d.dll", (S32)D3DX_SDK_VERSION );
  74. smD3DX.compilerDllRef = OsLoadLibrary( compilerVersion );
  75. }