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.

100 lines
3.0 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "matsys_controls/matsyscontrols.h"
  8. #include <materialsystem/imaterialsystem.h>
  9. #include <materialsystem/imaterialsystemhardwareconfig.h>
  10. #include <datacache/imdlcache.h>
  11. #include <VGuiMatSurface/IMatSystemSurface.h>
  12. #include <istudiorender.h>
  13. #include "vgui_controls/Controls.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. namespace vgui
  17. {
  18. IMaterialSystem *g_pMaterialSystem = NULL;
  19. IMaterialSystem *MaterialSystem()
  20. {
  21. return g_pMaterialSystem;
  22. }
  23. IMaterialSystemHardwareConfig *g_pMaterialSystemHardwareConfig = NULL;
  24. IMaterialSystemHardwareConfig *MaterialSystemHardwareConfig()
  25. {
  26. return g_pMaterialSystemHardwareConfig;
  27. }
  28. IMDLCache *g_pMDLCache = NULL;
  29. IMDLCache *MDLCache()
  30. {
  31. return g_pMDLCache;
  32. }
  33. IMatSystemSurface *g_pMatSystemSurface = NULL;
  34. IMatSystemSurface *MatSystemSurface()
  35. {
  36. return g_pMatSystemSurface;
  37. }
  38. IStudioRender *g_pStudioRender = NULL;
  39. IStudioRender *StudioRender()
  40. {
  41. return g_pStudioRender;
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose: finds a particular interface in the factory set
  45. //-----------------------------------------------------------------------------
  46. static void *InitializeInterface( char const *interfaceName, CreateInterfaceFn *factoryList, int numFactories )
  47. {
  48. void *retval;
  49. for ( int i = 0; i < numFactories; i++ )
  50. {
  51. CreateInterfaceFn factory = factoryList[ i ];
  52. if ( !factory )
  53. continue;
  54. retval = factory( interfaceName, NULL );
  55. if ( retval )
  56. return retval;
  57. }
  58. // No provider for requested interface!!!
  59. // Assert( !"No provider for requested interface!!!" );
  60. return NULL;
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Purpose: Initializes the controls
  64. //-----------------------------------------------------------------------------
  65. bool VGui_InitMatSysInterfacesList( const char *moduleName, CreateInterfaceFn *factoryList, int numFactories )
  66. {
  67. if ( !vgui::VGui_InitInterfacesList( moduleName, factoryList, numFactories ) )
  68. return false;
  69. g_pMaterialSystem = (IMaterialSystem *)InitializeInterface( MATERIAL_SYSTEM_INTERFACE_VERSION, factoryList, numFactories );
  70. g_pMatSystemSurface = (IMatSystemSurface *)InitializeInterface( MAT_SYSTEM_SURFACE_INTERFACE_VERSION, factoryList, numFactories );
  71. g_pMDLCache = (IMDLCache *)InitializeInterface( MDLCACHE_INTERFACE_VERSION, factoryList, numFactories );
  72. g_pStudioRender = (IStudioRender *)InitializeInterface( STUDIO_RENDER_INTERFACE_VERSION, factoryList, numFactories );
  73. g_pMaterialSystemHardwareConfig = (IMaterialSystemHardwareConfig *)InitializeInterface( MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION, factoryList, numFactories );
  74. // MDL cache + studiorender are optional
  75. return ( g_pMaterialSystem && g_pMatSystemSurface && g_pMaterialSystemHardwareConfig );
  76. }
  77. } // namespace vgui