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.

108 lines
4.8 KiB

  1. //============ Copyright (c) Valve Corporation, All rights reserved. ============
  2. #ifndef IMATERIAL2_H
  3. #define IMATERIAL2_H
  4. #ifdef _WIN32
  5. #pragma once
  6. #endif
  7. #include "tier0/platform.h"
  8. #include "tier1/utlsymbol.h"
  9. // TODO: Split out common enums and typedefs out of irenderdevice.h and include the lighter-weight .h file here
  10. #include "rendersystem/irenderdevice.h"
  11. /* Example API usage
  12. IMaterialMode *pMode = pMaterial->GetMode( 0 );
  13. if ( pMode != NULL ) // NULL if unsupported mode
  14. {
  15. MaterialRenderablePass_t renderablePassArray[ MATERIAL_RENDERABLE_PASS_MAX ];
  16. int nNumPasses = pMode->ComputeRenderablePassesForContext( *pRenderContext, renderablePassArray );
  17. for ( int i = 0; i < nNumPasses; i++ )
  18. {
  19. g_pMaterialSystem2->SetRenderStateForRenderablePass( *pRenderContext, g_hLayout, renderablePassArray[i] );
  20. pRenderContext->DrawIndexed( RENDER_PRIM_TRIANGLES, 0, 6 );
  21. }
  22. }
  23. //*/
  24. //---------------------------------------------------------------------------------------------------------------------------------------------------
  25. // Forward declarations
  26. //---------------------------------------------------------------------------------------------------------------------------------------------------
  27. class IRenderContext;
  28. //---------------------------------------------------------------------------------------------------------------------------------------------------
  29. abstract_class IMaterialLayer
  30. {
  31. public:
  32. // Need calls to get shader handle and anything else that will help the renderer bucket passes
  33. };
  34. //---------------------------------------------------------------------------------------------------------------------------------------------------
  35. #define MATERIAL_RENDERABLE_PASS_MAX 8 // For code that wants to hard-code the array size to pass into ComputeRenderablePassesForContext() below
  36. enum MaterialShaderProgram_t
  37. {
  38. MATERIAL_SHADER_PROGRAM_VS = 0,
  39. MATERIAL_SHADER_PROGRAM_GS,
  40. MATERIAL_SHADER_PROGRAM_PS,
  41. MATERIAL_SHADER_PROGRAM_MAX,
  42. };
  43. struct MaterialRenderablePass_t
  44. {
  45. const IMaterialLayer *pLayer;
  46. //MaterialDataFromClient *data;
  47. // TODO: This data needs to be compacted
  48. int nLayerIndex;
  49. int nPassIndex;
  50. // TODO: Change this to shader handles
  51. uint64 staticComboIdArray[ MATERIAL_SHADER_PROGRAM_MAX ]; // Should these be a 16-bit index to a post-skipped combo or anything smaller than 64-bits?
  52. uint64 dynamicComboIdArray[ MATERIAL_SHADER_PROGRAM_MAX ];
  53. };
  54. //---------------------------------------------------------------------------------------------------------------------------------------------------
  55. abstract_class IMaterialMode
  56. {
  57. public:
  58. // This gets the max number of passes this mode will ever render
  59. virtual int GetTotalNumPasses() const = 0;
  60. // This must be called to converge on a dynamic combo before calling g_pMaterialSystem2->SetRenderStateForRenderablePass().
  61. // The array size must be at least GetTotalNumPasses() large, but using MATERIAL_RENDERABLE_PASS_MAX will always work.
  62. // NOTE: If you pass in a NULL pRenderContext, it will return all possible passes
  63. virtual int ComputeRenderablePassesForContext( IRenderContext &renderContext, MaterialRenderablePass_t *pRenderablePassArray, int nRenderablePassArraySize = MATERIAL_RENDERABLE_PASS_MAX ) = 0;
  64. };
  65. //---------------------------------------------------------------------------------------------------------------------------------------------------
  66. // Material interface
  67. //---------------------------------------------------------------------------------------------------------------------------------------------------
  68. abstract_class IMaterial2
  69. {
  70. public:
  71. // Get the name of the material. This is a full path to the vmt file starting from "mod/materials" without a file extension
  72. virtual const char *GetName() const = 0;
  73. virtual CUtlSymbol GetNameSymbol() const = 0;
  74. // When async loading, this will let the caller know everything is loaded
  75. virtual bool IsLoaded() const = 0;
  76. // If there was a problem loading the material, this will reference the error material internally
  77. virtual bool IsErrorMaterial() const = 0;
  78. // The number of modes is constant for all materials and is defined by the client and stored in the material system.
  79. // Returning NULL means this is an unsupported mode. A non-NULL mode can still have 0 passes depending on game state, so
  80. // NULL here means the mode isn't supported by this material and it is up to the caller to decide what to do.
  81. // For a simple renderer that doesn't create custom render modes in the material system, GetMode(0) is always valid.
  82. virtual IMaterialMode *GetMode( int nMode ) = 0;
  83. // Decrement the ref count on the material. The memory will eventually be freed if the ref count hits 0.
  84. virtual void Release() = 0;
  85. };
  86. #endif // IMATERIAL2_H