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.

185 lines
6.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef IVMODELRENDER_H
  9. #define IVMODELRENDER_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "interface.h"
  14. #include "mathlib/mathlib.h"
  15. #include "istudiorender.h"
  16. //-----------------------------------------------------------------------------
  17. // forward declarations
  18. //-----------------------------------------------------------------------------
  19. struct mstudioanimdesc_t;
  20. struct mstudioseqdesc_t;
  21. struct model_t;
  22. class IClientRenderable;
  23. class Vector;
  24. struct studiohdr_t;
  25. class IMaterial;
  26. class CStudioHdr;
  27. FORWARD_DECLARE_HANDLE( LightCacheHandle_t );
  28. //-----------------------------------------------------------------------------
  29. // Model rendering state
  30. //-----------------------------------------------------------------------------
  31. struct DrawModelState_t
  32. {
  33. studiohdr_t* m_pStudioHdr;
  34. studiohwdata_t* m_pStudioHWData;
  35. IClientRenderable* m_pRenderable;
  36. const matrix3x4_t *m_pModelToWorld;
  37. StudioDecalHandle_t m_decals;
  38. int m_drawFlags;
  39. int m_lod;
  40. };
  41. //-----------------------------------------------------------------------------
  42. // Model Rendering + instance data
  43. //-----------------------------------------------------------------------------
  44. // change this when the new version is incompatable with the old
  45. #define VENGINE_HUDMODEL_INTERFACE_VERSION "VEngineModel016"
  46. typedef unsigned short ModelInstanceHandle_t;
  47. enum
  48. {
  49. MODEL_INSTANCE_INVALID = (ModelInstanceHandle_t)~0
  50. };
  51. struct ModelRenderInfo_t
  52. {
  53. Vector origin;
  54. QAngle angles;
  55. IClientRenderable *pRenderable;
  56. const model_t *pModel;
  57. const matrix3x4_t *pModelToWorld;
  58. const matrix3x4_t *pLightingOffset;
  59. const Vector *pLightingOrigin;
  60. int flags;
  61. int entity_index;
  62. int skin;
  63. int body;
  64. int hitboxset;
  65. ModelInstanceHandle_t instance;
  66. ModelRenderInfo_t()
  67. {
  68. pModelToWorld = NULL;
  69. pLightingOffset = NULL;
  70. pLightingOrigin = NULL;
  71. }
  72. };
  73. struct StaticPropRenderInfo_t
  74. {
  75. const matrix3x4_t *pModelToWorld;
  76. const model_t *pModel;
  77. IClientRenderable *pRenderable;
  78. Vector *pLightingOrigin;
  79. short skin;
  80. ModelInstanceHandle_t instance;
  81. };
  82. // UNDONE: Move this to hud export code, subsume previous functions
  83. abstract_class IVModelRender
  84. {
  85. public:
  86. virtual int DrawModel( int flags,
  87. IClientRenderable *pRenderable,
  88. ModelInstanceHandle_t instance,
  89. int entity_index,
  90. const model_t *model,
  91. Vector const& origin,
  92. QAngle const& angles,
  93. int skin,
  94. int body,
  95. int hitboxset,
  96. const matrix3x4_t *modelToWorld = NULL,
  97. const matrix3x4_t *pLightingOffset = NULL ) = 0;
  98. // This causes a material to be used when rendering the model instead
  99. // of the materials the model was compiled with
  100. virtual void ForcedMaterialOverride( IMaterial *newMaterial, OverrideType_t nOverrideType = OVERRIDE_NORMAL ) = 0;
  101. virtual void SetViewTarget( const CStudioHdr *pStudioHdr, int nBodyIndex, const Vector& target ) = 0;
  102. // Creates, destroys instance data to be associated with the model
  103. virtual ModelInstanceHandle_t CreateInstance( IClientRenderable *pRenderable, LightCacheHandle_t *pCache = NULL ) = 0;
  104. virtual void DestroyInstance( ModelInstanceHandle_t handle ) = 0;
  105. // Associates a particular lighting condition with a model instance handle.
  106. // FIXME: This feature currently only works for static props. To make it work for entities, etc.,
  107. // we must clean up the lightcache handles as the model instances are removed.
  108. // At the moment, since only the static prop manager uses this, it cleans up all LightCacheHandles
  109. // at level shutdown.
  110. virtual void SetStaticLighting( ModelInstanceHandle_t handle, LightCacheHandle_t* pHandle ) = 0;
  111. virtual LightCacheHandle_t GetStaticLighting( ModelInstanceHandle_t handle ) = 0;
  112. // moves an existing InstanceHandle to a nex Renderable to keep decals etc. Models must be the same
  113. virtual bool ChangeInstance( ModelInstanceHandle_t handle, IClientRenderable *pRenderable ) = 0;
  114. // Creates a decal on a model instance by doing a planar projection
  115. // along the ray. The material is the decal material, the radius is the
  116. // radius of the decal to create.
  117. virtual void AddDecal( ModelInstanceHandle_t handle, Ray_t const& ray,
  118. Vector const& decalUp, int decalIndex, int body, bool noPokeThru = false, int maxLODToDecal = ADDDECAL_TO_ALL_LODS ) = 0;
  119. // Removes all the decals on a model instance
  120. virtual void RemoveAllDecals( ModelInstanceHandle_t handle ) = 0;
  121. // Remove all decals from all models
  122. virtual void RemoveAllDecalsFromAllModels() = 0;
  123. // Shadow rendering, DrawModelShadowSetup returns the address of the bone-to-world array, NULL in case of error
  124. virtual matrix3x4_t* DrawModelShadowSetup( IClientRenderable *pRenderable, int body, int skin, DrawModelInfo_t *pInfo, matrix3x4_t *pCustomBoneToWorld = NULL ) = 0;
  125. virtual void DrawModelShadow( IClientRenderable *pRenderable, const DrawModelInfo_t &info, matrix3x4_t *pCustomBoneToWorld = NULL ) = 0;
  126. // This gets called when overbright, etc gets changed to recompute static prop lighting.
  127. virtual bool RecomputeStaticLighting( ModelInstanceHandle_t handle ) = 0;
  128. virtual void ReleaseAllStaticPropColorData( void ) = 0;
  129. virtual void RestoreAllStaticPropColorData( void ) = 0;
  130. // Extended version of drawmodel
  131. virtual int DrawModelEx( ModelRenderInfo_t &pInfo ) = 0;
  132. virtual int DrawModelExStaticProp( ModelRenderInfo_t &pInfo ) = 0;
  133. virtual bool DrawModelSetup( ModelRenderInfo_t &pInfo, DrawModelState_t *pState, matrix3x4_t *pCustomBoneToWorld, matrix3x4_t** ppBoneToWorldOut ) = 0;
  134. virtual void DrawModelExecute( const DrawModelState_t &state, const ModelRenderInfo_t &pInfo, matrix3x4_t *pCustomBoneToWorld = NULL ) = 0;
  135. // Sets up lighting context for a point in space
  136. virtual void SetupLighting( const Vector &vecCenter ) = 0;
  137. // doesn't support any debug visualization modes or other model options, but draws static props in the
  138. // fastest way possible
  139. virtual int DrawStaticPropArrayFast( StaticPropRenderInfo_t *pProps, int count, bool bShadowDepth ) = 0;
  140. // Allow client to override lighting state
  141. virtual void SuppressEngineLighting( bool bSuppress ) = 0;
  142. virtual void SetupColorMeshes( int nTotalVerts ) = 0;
  143. virtual void AddColoredDecal( ModelInstanceHandle_t handle, Ray_t const& ray,
  144. Vector const& decalUp, int decalIndex, int body, Color cColor, bool noPokeThru = false, int maxLODToDecal = ADDDECAL_TO_ALL_LODS ) = 0;
  145. virtual void GetMaterialOverride( IMaterial** ppOutForcedMaterial, OverrideType_t* pOutOverrideType ) = 0;
  146. };
  147. #endif // IVMODELRENDER_H