Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
4.3 KiB

  1. //====== Copyright � 1996-2006, Valve Corporation, All rights reserved. =======//
  2. //
  3. // Purpose: Make dynamic loading of dx_proxy.dll and methods acquisition easier.
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #ifndef DX_PROXY_H
  9. #define DX_PROXY_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. /*
  14. class DxProxyModule
  15. Uses a lazy-load technique to load the dx_proxy.dll module and acquire the
  16. function pointers.
  17. The dx_proxy.dll module is automatically unloaded during desctruction.
  18. */
  19. class DxProxyModule
  20. {
  21. public:
  22. /// Construction
  23. DxProxyModule( void );
  24. /// Destruction
  25. ~DxProxyModule( void );
  26. private: // Prevent copying via copy constructor or assignment
  27. DxProxyModule( const DxProxyModule & );
  28. DxProxyModule & operator = ( const DxProxyModule & );
  29. public:
  30. /// Loads the module and acquires function pointers, returns if the module was
  31. /// loaded successfully.
  32. /// If the module was already loaded the call has no effect and returns TRUE.
  33. BOOL Load( void );
  34. /// Frees the loaded module.
  35. void Free( void );
  36. private:
  37. enum Func {
  38. fnD3DXCompileShaderFromFile = 0,
  39. fnTotal
  40. };
  41. HMODULE m_hModule; //!< The handle of the loaded dx_proxy.dll
  42. FARPROC m_arrFuncs[fnTotal]; //!< The array of loaded function pointers
  43. ///
  44. /// Interface functions calling into DirectX proxy
  45. ///
  46. public:
  47. HRESULT D3DXCompileShaderFromFile(
  48. LPCSTR pSrcFile,
  49. CONST D3DXMACRO* pDefines,
  50. LPD3DXINCLUDE pInclude,
  51. LPCSTR pFunctionName,
  52. LPCSTR pProfile,
  53. DWORD Flags,
  54. LPD3DXBUFFER* ppShader,
  55. LPD3DXBUFFER* ppErrorMsgs,
  56. LPD3DXCONSTANTTABLE* ppConstantTable );
  57. };
  58. //////////////////////////////////////////////////////////////////////////
  59. //////////////////////////////////////////////////////////////////////////
  60. //
  61. // IMPLEMENTATION
  62. //
  63. //////////////////////////////////////////////////////////////////////////
  64. //////////////////////////////////////////////////////////////////////////
  65. inline DxProxyModule::DxProxyModule( void )
  66. {
  67. m_hModule = NULL;
  68. ZeroMemory( m_arrFuncs, sizeof( m_arrFuncs ) );
  69. }
  70. inline DxProxyModule::~DxProxyModule( void )
  71. {
  72. Free();
  73. }
  74. inline BOOL DxProxyModule::Load( void )
  75. {
  76. if ( (m_hModule == NULL) &&
  77. ( m_hModule = ::LoadLibrary( "dx_proxy.dll" ) ) != NULL )
  78. {
  79. // Requested function names array
  80. LPCSTR const arrFuncNames[fnTotal] = {
  81. "Proxy_D3DXCompileShaderFromFile"
  82. };
  83. // Acquire the functions
  84. for ( int k = 0; k < fnTotal; ++ k )
  85. {
  86. m_arrFuncs[k] = ::GetProcAddress( m_hModule, arrFuncNames[k] );
  87. }
  88. }
  89. return !!m_hModule;
  90. }
  91. inline void DxProxyModule::Free( void )
  92. {
  93. if ( m_hModule )
  94. {
  95. ::FreeLibrary( m_hModule );
  96. m_hModule = NULL;
  97. ZeroMemory( m_arrFuncs, sizeof( m_arrFuncs ) );
  98. }
  99. }
  100. //////////////////////////////////////////////////////////////////////////
  101. //////////////////////////////////////////////////////////////////////////
  102. //
  103. // INTERFACE FUNCTIONS IMPLEMENTATION
  104. //
  105. //////////////////////////////////////////////////////////////////////////
  106. //////////////////////////////////////////////////////////////////////////
  107. inline HRESULT DxProxyModule::D3DXCompileShaderFromFile(
  108. LPCSTR pSrcFile,
  109. CONST D3DXMACRO* pDefines,
  110. LPD3DXINCLUDE pInclude,
  111. LPCSTR pFunctionName,
  112. LPCSTR pProfile,
  113. DWORD Flags,
  114. LPD3DXBUFFER* ppShader,
  115. LPD3DXBUFFER* ppErrorMsgs,
  116. LPD3DXCONSTANTTABLE* ppConstantTable )
  117. {
  118. if ( !Load() )
  119. return MAKE_HRESULT( SEVERITY_ERROR, FACILITY_ITF, 1 );
  120. if ( !m_arrFuncs[fnD3DXCompileShaderFromFile] )
  121. return MAKE_HRESULT( SEVERITY_ERROR, FACILITY_ITF, 2 );
  122. return
  123. ( *
  124. ( HRESULT (WINAPI *)
  125. ( LPCSTR, CONST D3DXMACRO*, LPD3DXINCLUDE,
  126. LPCSTR, LPCSTR, DWORD, LPD3DXBUFFER*,
  127. LPD3DXBUFFER*, LPD3DXCONSTANTTABLE* )
  128. )
  129. m_arrFuncs[fnD3DXCompileShaderFromFile]
  130. )
  131. ( pSrcFile, pDefines, pInclude, pFunctionName, pProfile, Flags, ppShader, ppErrorMsgs, ppConstantTable );
  132. }
  133. #endif // #ifndef DX_PROXY_H