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.

220 lines
8.5 KiB

  1. //===== Copyright � 1996-2005, 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. #include "datacache/idatacache.h"
  17. //-----------------------------------------------------------------------------
  18. // forward declarations
  19. //-----------------------------------------------------------------------------
  20. struct mstudioanimdesc_t;
  21. struct mstudioseqdesc_t;
  22. struct model_t;
  23. class IClientRenderable;
  24. class Vector;
  25. struct studiohdr_t;
  26. class IMaterial;
  27. class CStudioHdr;
  28. struct MaterialLightingState_t;
  29. FORWARD_DECLARE_HANDLE( LightCacheHandle_t );
  30. //-----------------------------------------------------------------------------
  31. // Model rendering state
  32. //-----------------------------------------------------------------------------
  33. struct DrawModelState_t
  34. {
  35. studiohdr_t* m_pStudioHdr;
  36. studiohwdata_t* m_pStudioHWData;
  37. IClientRenderable* m_pRenderable;
  38. const matrix3x4_t *m_pModelToWorld;
  39. StudioDecalHandle_t m_decals;
  40. int m_drawFlags;
  41. int m_lod;
  42. };
  43. //-----------------------------------------------------------------------------
  44. // Model Rendering + instance data
  45. //-----------------------------------------------------------------------------
  46. // change this when the new version is incompatable with the old
  47. #define VENGINE_HUDMODEL_INTERFACE_VERSION "VEngineModel016"
  48. typedef unsigned short ModelInstanceHandle_t;
  49. enum
  50. {
  51. MODEL_INSTANCE_INVALID = (ModelInstanceHandle_t)~0
  52. };
  53. struct ModelRenderInfo_t
  54. {
  55. Vector origin;
  56. QAngle angles;
  57. IClientRenderable *pRenderable;
  58. const model_t *pModel;
  59. const matrix3x4_t *pModelToWorld;
  60. const matrix3x4_t *pLightingOffset;
  61. const Vector *pLightingOrigin;
  62. int flags;
  63. int entity_index;
  64. int skin;
  65. int body;
  66. int hitboxset;
  67. ModelInstanceHandle_t instance;
  68. ModelRenderInfo_t()
  69. {
  70. pModelToWorld = NULL;
  71. pLightingOffset = NULL;
  72. pLightingOrigin = NULL;
  73. }
  74. };
  75. struct StaticPropRenderInfo_t
  76. {
  77. const matrix3x4_t *pModelToWorld;
  78. const model_t *pModel;
  79. IClientRenderable *pRenderable;
  80. Vector *pLightingOrigin;
  81. ModelInstanceHandle_t instance;
  82. uint8 skin;
  83. uint8 alpha;
  84. };
  85. struct LightingQuery_t
  86. {
  87. Vector m_LightingOrigin;
  88. ModelInstanceHandle_t m_InstanceHandle;
  89. bool m_bAmbientBoost;
  90. };
  91. struct StaticLightingQuery_t : public LightingQuery_t
  92. {
  93. IClientRenderable *m_pRenderable;
  94. };
  95. // UNDONE: Move this to hud export code, subsume previous functions
  96. abstract_class IVModelRender
  97. {
  98. public:
  99. virtual int DrawModel( int flags,
  100. IClientRenderable *pRenderable,
  101. ModelInstanceHandle_t instance,
  102. int entity_index,
  103. const model_t *model,
  104. Vector const& origin,
  105. QAngle const& angles,
  106. int skin,
  107. int body,
  108. int hitboxset,
  109. const matrix3x4_t *modelToWorld = NULL,
  110. const matrix3x4_t *pLightingOffset = NULL ) = 0;
  111. // This causes a material to be used when rendering the model instead
  112. // of the materials the model was compiled with
  113. virtual void ForcedMaterialOverride( IMaterial *newMaterial, OverrideType_t nOverrideType = OVERRIDE_NORMAL, int nMaterialIndex = -1 ) = 0;
  114. virtual bool IsForcedMaterialOverride() = 0;
  115. virtual void SetViewTarget( const CStudioHdr *pStudioHdr, int nBodyIndex, const Vector& target ) = 0;
  116. // Creates, destroys instance data to be associated with the model
  117. virtual ModelInstanceHandle_t CreateInstance( IClientRenderable *pRenderable, LightCacheHandle_t *pCache = NULL ) = 0;
  118. virtual void DestroyInstance( ModelInstanceHandle_t handle ) = 0;
  119. // Associates a particular lighting condition with a model instance handle.
  120. // FIXME: This feature currently only works for static props. To make it work for entities, etc.,
  121. // we must clean up the lightcache handles as the model instances are removed.
  122. // At the moment, since only the static prop manager uses this, it cleans up all LightCacheHandles
  123. // at level shutdown.
  124. virtual void SetStaticLighting( ModelInstanceHandle_t handle, LightCacheHandle_t* pHandle ) = 0;
  125. virtual LightCacheHandle_t GetStaticLighting( ModelInstanceHandle_t handle ) = 0;
  126. // moves an existing InstanceHandle to a nex Renderable to keep decals etc. Models must be the same
  127. virtual bool ChangeInstance( ModelInstanceHandle_t handle, IClientRenderable *pRenderable ) = 0;
  128. // Creates a decal on a model instance by doing a planar projection
  129. // along the ray. The material is the decal material, the radius is the
  130. // radius of the decal to create.
  131. virtual void AddDecal( ModelInstanceHandle_t handle, Ray_t const& ray,
  132. Vector const& decalUp, int decalIndex, int body, bool noPokeThru = false, int maxLODToDecal = ADDDECAL_TO_ALL_LODS, IMaterial *pSpecifyMaterial = NULL, float w=1.0f, float h=1.0f, void *pvProxyUserData = NULL, int nAdditionalDecalFlags = 0 ) = 0;
  133. // Removes all the decals on a model instance
  134. virtual void RemoveAllDecals( ModelInstanceHandle_t handle ) = 0;
  135. // Returns true if the model instance is valid and the decal list is not empty
  136. virtual bool ModelHasDecals( ModelInstanceHandle_t handle ) = 0;
  137. // Remove all decals from all models
  138. virtual void RemoveAllDecalsFromAllModels( bool bRenderContextValid ) = 0;
  139. // Shadow rendering, DrawModelShadowSetup returns the address of the bone-to-world array, NULL in case of error
  140. virtual matrix3x4a_t* DrawModelShadowSetup( IClientRenderable *pRenderable, int body, int skin, DrawModelInfo_t *pInfo, matrix3x4a_t *pCustomBoneToWorld = NULL ) = 0;
  141. virtual void DrawModelShadow( IClientRenderable *pRenderable, const DrawModelInfo_t &info, matrix3x4a_t *pCustomBoneToWorld = NULL ) = 0;
  142. // This gets called when overbright, etc gets changed to recompute static prop lighting.
  143. virtual bool RecomputeStaticLighting( ModelInstanceHandle_t handle ) = 0;
  144. virtual void ReleaseAllStaticPropColorData( void ) = 0;
  145. virtual void RestoreAllStaticPropColorData( void ) = 0;
  146. // Extended version of drawmodel
  147. virtual int DrawModelEx( ModelRenderInfo_t &pInfo ) = 0;
  148. virtual int DrawModelExStaticProp( IMatRenderContext *pRenderContext, ModelRenderInfo_t &pInfo ) = 0;
  149. virtual bool DrawModelSetup( IMatRenderContext *pRenderContext, ModelRenderInfo_t &pInfo, DrawModelState_t *pState, matrix3x4_t **ppBoneToWorldOut ) = 0;
  150. virtual void DrawModelExecute( IMatRenderContext *pRenderContext, const DrawModelState_t &state, const ModelRenderInfo_t &pInfo, matrix3x4_t *pCustomBoneToWorld = NULL ) = 0;
  151. // Sets up lighting context for a point in space
  152. virtual void SetupLighting( const Vector &vecCenter ) = 0;
  153. // doesn't support any debug visualization modes or other model options, but draws static props in the
  154. // fastest way possible
  155. virtual int DrawStaticPropArrayFast( StaticPropRenderInfo_t *pProps, int count, bool bShadowDepth ) = 0;
  156. // Allow client to override lighting state
  157. virtual void SuppressEngineLighting( bool bSuppress ) = 0;
  158. virtual void SetupColorMeshes( int nTotalVerts ) = 0;
  159. // Sets up lighting context for a point in space, with smooth interpolation per model.
  160. // Passing MODEL_INSTANCE_INVALID as a handle is equivalent to calling SetupLighting.
  161. virtual void SetupLightingEx( const Vector &vecCenter, ModelInstanceHandle_t handle ) = 0;
  162. // Finds the brightest light source illuminating a point. Returns false if there isn't any.
  163. virtual bool GetBrightestShadowingLightSource( const Vector &vecCenter, Vector& lightPos, Vector& lightBrightness, bool bAllowNonTaggedLights ) = 0;
  164. // Computes lighting state for an array of lighting requests
  165. virtual void ComputeLightingState( int nCount, const LightingQuery_t *pQuery, MaterialLightingState_t *pState, ITexture **ppEnvCubemapTexture ) = 0;
  166. // Gets an array of decal handles given model instances
  167. virtual void GetModelDecalHandles( StudioDecalHandle_t *pDecals, int nDecalStride, int nCount, const ModelInstanceHandle_t *pHandles ) = 0;
  168. // Computes lighting state for an array of lighting requests for renderables which use static lighting
  169. virtual void ComputeStaticLightingState( int nCount, const StaticLightingQuery_t *pQuery, MaterialLightingState_t *pState, MaterialLightingState_t *pDecalState, ColorMeshInfo_t **ppStaticLighting, ITexture **ppEnvCubemapTexture, DataCacheHandle_t *pColorMeshHandles ) = 0;
  170. // Cleans up lighting state. Must be called after the draw call that uses
  171. // the color meshes return from ComputeStaticLightingState has been issued
  172. virtual void CleanupStaticLightingState( int nCount, DataCacheHandle_t *pColorMeshHandles ) = 0;
  173. };
  174. #endif // IVMODELRENDER_H