Team Fortress 2 Source Code as on 22/4/2020
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.

139 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #include "materialsystem/imaterialsystem.h"
  9. #include "materialsystem/MaterialSystem_Config.h"
  10. #include "tier0/dbg.h"
  11. #include <windows.h>
  12. #include "filesystem.h"
  13. #include "FileSystem_Tools.h"
  14. #include "../materialsystem/ishadersystem.h"
  15. #include "utlvector.h"
  16. #include "tier0/icommandline.h"
  17. #include "tier2/tier2.h"
  18. CreateInterfaceFn g_MatSysFactory = NULL;
  19. CreateInterfaceFn g_ShaderAPIFactory = NULL;
  20. class CShaderDLLInfo
  21. {
  22. public:
  23. char m_Filename[MAX_PATH];
  24. IShaderDLLInternal *m_pInternal;
  25. };
  26. CUtlVector<CShaderDLLInfo> g_ShaderDLLs;
  27. bool LoadShaderDLL( const char *pFilename )
  28. {
  29. // Load the new shader
  30. CSysModule *hInstance = g_pFullFileSystem->LoadModule( pFilename );
  31. if ( !hInstance )
  32. return false;
  33. // Get at the shader DLL interface
  34. CreateInterfaceFn factory = Sys_GetFactory( hInstance );
  35. if (!factory)
  36. {
  37. g_pFullFileSystem->UnloadModule( hInstance );
  38. return false;
  39. }
  40. IShaderDLLInternal *pShaderDLL = (IShaderDLLInternal*)factory( SHADER_DLL_INTERFACE_VERSION, NULL );
  41. if ( !pShaderDLL )
  42. {
  43. g_pFullFileSystem->UnloadModule( hInstance );
  44. return false;
  45. }
  46. CShaderDLLInfo *pOut = &g_ShaderDLLs[ g_ShaderDLLs.AddToTail() ];
  47. pOut->m_pInternal = pShaderDLL;
  48. Q_strncpy( pOut->m_Filename, pFilename, sizeof( pOut->m_Filename ) );
  49. return true;
  50. }
  51. void PrintHeader( void )
  52. {
  53. printf( "<HTML>\n" );
  54. printf( "<HEAD>\n" );
  55. printf( "<TITLE>Valve Source Shader Reference</TITLE>\n" );
  56. printf( "</HEAD>\n" );
  57. printf( "<CENTER>\n" );
  58. printf( "<H1>Valve Source Shader Reference</H1>\n" );
  59. printf( "</CENTER>\n" );
  60. }
  61. void PrintShaderContents( int dllID )
  62. {
  63. IShaderDLLInternal *pShaderDLL = g_ShaderDLLs[dllID].m_pInternal;
  64. int nShaders = pShaderDLL->ShaderCount();
  65. int i;
  66. printf( "<H2>%s</H2><BR>\n", g_ShaderDLLs[dllID].m_Filename );
  67. printf( "<dl>\n" ); // define list
  68. for( i = 0; i < nShaders; i++ )
  69. {
  70. IShader *pShader = pShaderDLL->GetShader( i );
  71. printf( "<A HREF=\"#%s_%s\">\n", g_ShaderDLLs[dllID].m_Filename, pShader->GetName() );
  72. printf( "<dt>%s</A>\n", pShader->GetName() );
  73. // int nParams = pShader->GetNumParams();
  74. }
  75. printf( "</dl>\n" ); // end define list
  76. }
  77. void PrintShaderHelp( int dllID )
  78. {
  79. IShaderDLLInternal *pShaderDLL = g_ShaderDLLs[dllID].m_pInternal;
  80. int nShaders = pShaderDLL->ShaderCount();
  81. int i;
  82. printf( "<H2>%s</H2><BR>\n", g_ShaderDLLs[dllID].m_Filename );
  83. printf( "<dl>\n" ); // define list
  84. for( i = 0; i < nShaders; i++ )
  85. {
  86. IShader *pShader = pShaderDLL->GetShader( i );
  87. printf( "<A NAME=\"%s_%s\"></A>\n", g_ShaderDLLs[dllID].m_Filename, pShader->GetName() );
  88. printf( "<dt>%s<dl>\n", pShader->GetName() );
  89. int nParams = pShader->GetNumParams();
  90. int j;
  91. for( j = 0; j < nParams; j++ )
  92. {
  93. printf( "<dt>%s\n<dd>%s\n",
  94. pShader->GetParamName( j ),
  95. pShader->GetParamHelp( j )
  96. );
  97. }
  98. printf( "</dl><br>\n" ); // end define list
  99. }
  100. printf( "</dl>\n" ); // end define list
  101. }
  102. void PrintFooter( void )
  103. {
  104. printf( "</HTML>\n" );
  105. }
  106. int main( int argc, char **argv )
  107. {
  108. CommandLine()->CreateCmdLine( argc, argv );
  109. FileSystem_Init( "" );
  110. PrintHeader();
  111. LoadShaderDLL( "stdshader_dx6.dll" );
  112. LoadShaderDLL( "stdshader_dx7.dll" );
  113. LoadShaderDLL( "stdshader_dx8.dll" );
  114. LoadShaderDLL( "stdshader_dx9.dll" );
  115. int i;
  116. for( i = 0; i < g_ShaderDLLs.Count(); i++ )
  117. {
  118. PrintShaderContents( i );
  119. }
  120. for( i = 0; i < g_ShaderDLLs.Count(); i++ )
  121. {
  122. PrintShaderHelp( i );
  123. }
  124. PrintFooter();
  125. FileSystem_Term();
  126. return 0;
  127. }