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.

335 lines
13 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef ICLIENTRENDERABLE_H
  8. #define ICLIENTRENDERABLE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "mathlib/mathlib.h"
  13. #include "interface.h"
  14. #include "iclientunknown.h"
  15. #include "client_render_handle.h"
  16. #include "engine/ivmodelrender.h"
  17. struct model_t;
  18. struct matrix3x4_t;
  19. extern void DefaultRenderBoundsWorldspace( IClientRenderable *pRenderable, Vector &absMins, Vector &absMaxs );
  20. //-----------------------------------------------------------------------------
  21. // Handles to a client shadow
  22. //-----------------------------------------------------------------------------
  23. typedef unsigned short ClientShadowHandle_t;
  24. enum
  25. {
  26. CLIENTSHADOW_INVALID_HANDLE = (ClientShadowHandle_t)~0
  27. };
  28. //-----------------------------------------------------------------------------
  29. // What kind of shadows to render?
  30. //-----------------------------------------------------------------------------
  31. enum ShadowType_t
  32. {
  33. SHADOWS_NONE = 0,
  34. SHADOWS_SIMPLE,
  35. SHADOWS_RENDER_TO_TEXTURE,
  36. SHADOWS_RENDER_TO_TEXTURE_DYNAMIC, // the shadow is always changing state
  37. SHADOWS_RENDER_TO_DEPTH_TEXTURE,
  38. SHADOWS_RENDER_TO_TEXTURE_DYNAMIC_CUSTOM, // changing, and entity uses custom rendering code for shadow
  39. };
  40. // This provides a way for entities to know when they've entered or left the PVS.
  41. // Normally, server entities can use NotifyShouldTransmit to get this info, but client-only
  42. // entities can use this. Store a CPVSNotifyInfo in your
  43. //
  44. // When bInPVS=true, it's being called DURING rendering. It might be after rendering any
  45. // number of views.
  46. //
  47. // If no views had the entity, then it is called with bInPVS=false after rendering.
  48. abstract_class IPVSNotify
  49. {
  50. public:
  51. virtual void OnPVSStatusChanged( bool bInPVS ) = 0;
  52. };
  53. //-----------------------------------------------------------------------------
  54. // Information needed to draw a model
  55. //-----------------------------------------------------------------------------
  56. struct RenderableInstance_t
  57. {
  58. uint8 m_nAlpha;
  59. };
  60. // client renderable frame buffer usage flags
  61. #define ERENDERFLAGS_NEEDS_POWER_OF_TWO_FB 1 // needs refract texture
  62. #define ERENDERFLAGS_NEEDS_FULL_FB 2 // needs full framebuffer texture
  63. #define ERENDERFLAGS_REFRACT_ONLY_ONCE_PER_FRAME 4 // even if it needs a the refract texture, don't update it >once/ frame
  64. //-----------------------------------------------------------------------------
  65. // Purpose: All client entities must implement this interface.
  66. //-----------------------------------------------------------------------------
  67. abstract_class IClientRenderable
  68. {
  69. public:
  70. // Gets at the containing class...
  71. virtual IClientUnknown* GetIClientUnknown() = 0;
  72. // Data accessors
  73. virtual Vector const& GetRenderOrigin( void ) = 0;
  74. virtual QAngle const& GetRenderAngles( void ) = 0;
  75. virtual bool ShouldDraw( void ) = 0;
  76. virtual int GetRenderFlags( void ) = 0; // ERENDERFLAGS_xxx
  77. virtual void Unused( void ) const {}
  78. virtual ClientShadowHandle_t GetShadowHandle() const = 0;
  79. // Used by the leaf system to store its render handle.
  80. virtual ClientRenderHandle_t& RenderHandle() = 0;
  81. // Render baby!
  82. virtual const model_t* GetModel( ) const = 0;
  83. virtual int DrawModel( int flags, const RenderableInstance_t &instance ) = 0;
  84. // Get the body parameter
  85. virtual int GetBody() = 0;
  86. // Determine the color modulation amount
  87. virtual void GetColorModulation( float* color ) = 0;
  88. // Returns false if the entity shouldn't be drawn due to LOD.
  89. // (NOTE: This is no longer used/supported, but kept in the vtable for backwards compat)
  90. virtual bool LODTest() = 0;
  91. // Call this to get the current bone transforms for the model.
  92. // currentTime parameter will affect interpolation
  93. // nMaxBones specifies how many matrices pBoneToWorldOut can hold. (Should be greater than or
  94. // equal to studiohdr_t::numbones. Use MAXSTUDIOBONES to be safe.)
  95. virtual bool SetupBones( matrix3x4a_t *pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime ) = 0;
  96. virtual void SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights ) = 0;
  97. virtual void DoAnimationEvents( void ) = 0;
  98. // Return this if you want PVS notifications. See IPVSNotify for more info.
  99. // Note: you must always return the same value from this function. If you don't,
  100. // undefined things will occur, and they won't be good.
  101. virtual IPVSNotify* GetPVSNotifyInterface() = 0;
  102. // Returns the bounds relative to the origin (render bounds)
  103. virtual void GetRenderBounds( Vector& mins, Vector& maxs ) = 0;
  104. // returns the bounds as an AABB in worldspace
  105. virtual void GetRenderBoundsWorldspace( Vector& mins, Vector& maxs ) = 0;
  106. // These normally call through to GetRenderAngles/GetRenderBounds, but some entities custom implement them.
  107. virtual void GetShadowRenderBounds( Vector &mins, Vector &maxs, ShadowType_t shadowType ) = 0;
  108. // Should this object be able to have shadows cast onto it?
  109. virtual bool ShouldReceiveProjectedTextures( int flags ) = 0;
  110. // These methods return true if we want a per-renderable shadow cast direction + distance
  111. virtual bool GetShadowCastDistance( float *pDist, ShadowType_t shadowType ) const = 0;
  112. virtual bool GetShadowCastDirection( Vector *pDirection, ShadowType_t shadowType ) const = 0;
  113. // Other methods related to shadow rendering
  114. virtual bool IsShadowDirty( ) = 0;
  115. virtual void MarkShadowDirty( bool bDirty ) = 0;
  116. // Iteration over shadow hierarchy
  117. virtual IClientRenderable *GetShadowParent() = 0;
  118. virtual IClientRenderable *FirstShadowChild() = 0;
  119. virtual IClientRenderable *NextShadowPeer() = 0;
  120. // Returns the shadow cast type
  121. virtual ShadowType_t ShadowCastType() = 0;
  122. virtual void Unused2() {}
  123. // Create/get/destroy model instance
  124. virtual void CreateModelInstance() = 0;
  125. virtual ModelInstanceHandle_t GetModelInstance() = 0;
  126. // Returns the transform from RenderOrigin/RenderAngles to world
  127. virtual const matrix3x4_t &RenderableToWorldTransform() = 0;
  128. // Attachments
  129. virtual int LookupAttachment( const char *pAttachmentName ) = 0;
  130. virtual bool GetAttachment( int number, Vector &origin, QAngle &angles ) = 0;
  131. virtual bool GetAttachment( int number, matrix3x4_t &matrix ) = 0;
  132. virtual bool ComputeLightingOrigin( int nAttachmentIndex, Vector modelLightingCenter, const matrix3x4_t &matrix, Vector &transformedLightingCenter ) = 0;
  133. // Rendering clip plane, should be 4 floats, return value of NULL indicates a disabled render clip plane
  134. virtual float *GetRenderClipPlane( void ) = 0;
  135. // Get the skin parameter
  136. virtual int GetSkin() = 0;
  137. virtual void OnThreadedDrawSetup() = 0;
  138. virtual bool UsesFlexDelayedWeights() = 0;
  139. virtual void RecordToolMessage() = 0;
  140. virtual bool ShouldDrawForSplitScreenUser( int nSlot ) = 0;
  141. // NOTE: This is used by renderables to override the default alpha modulation,
  142. // not including fades, for a renderable. The alpha passed to the function
  143. // is the alpha computed based on the current renderfx.
  144. virtual uint8 OverrideAlphaModulation( uint8 nAlpha ) = 0;
  145. // NOTE: This is used by renderables to override the default alpha modulation,
  146. // not including fades, for a renderable's shadow. The alpha passed to the function
  147. // is the alpha computed based on the current renderfx + any override
  148. // computed in OverrideAlphaModulation
  149. virtual uint8 OverrideShadowAlphaModulation( uint8 nAlpha ) = 0;
  150. virtual IClientModelRenderable* GetClientModelRenderable() = 0;
  151. };
  152. //-----------------------------------------------------------------------------
  153. // Purpose: All client renderables supporting the fast-path mdl
  154. // rendering algorithm must inherit from this interface
  155. //-----------------------------------------------------------------------------
  156. enum RenderableLightingModel_t
  157. {
  158. LIGHTING_MODEL_NONE = -1,
  159. LIGHTING_MODEL_STANDARD = 0,
  160. LIGHTING_MODEL_STATIC_PROP,
  161. LIGHTING_MODEL_PHYSICS_PROP,
  162. LIGHTING_MODEL_COUNT,
  163. };
  164. enum ModelDataCategory_t
  165. {
  166. MODEL_DATA_LIGHTING_MODEL, // data type returned is a RenderableLightingModel_t
  167. MODEL_DATA_STENCIL, // data type returned is a ShaderStencilState_t
  168. MODEL_DATA_CATEGORY_COUNT,
  169. };
  170. abstract_class IClientModelRenderable
  171. {
  172. public:
  173. virtual bool GetRenderData( void *pData, ModelDataCategory_t nCategory ) = 0;
  174. };
  175. // This class can be used to implement default versions of some of the
  176. // functions of IClientRenderable.
  177. abstract_class CDefaultClientRenderable : public IClientUnknown, public IClientRenderable
  178. {
  179. public:
  180. CDefaultClientRenderable()
  181. {
  182. m_hRenderHandle = INVALID_CLIENT_RENDER_HANDLE;
  183. }
  184. virtual const Vector & GetRenderOrigin( void ) = 0;
  185. virtual const QAngle & GetRenderAngles( void ) = 0;
  186. virtual const matrix3x4_t & RenderableToWorldTransform() = 0;
  187. virtual bool ShouldDraw( void ) = 0;
  188. virtual void OnThreadedDrawSetup() {}
  189. virtual int GetRenderFlags( void ) { return 0; }
  190. virtual ClientShadowHandle_t GetShadowHandle() const
  191. {
  192. return CLIENTSHADOW_INVALID_HANDLE;
  193. }
  194. virtual ClientRenderHandle_t& RenderHandle()
  195. {
  196. return m_hRenderHandle;
  197. }
  198. virtual int GetBody() { return 0; }
  199. virtual int GetSkin() { return 0; }
  200. virtual bool UsesFlexDelayedWeights() { return false; }
  201. virtual const model_t* GetModel( ) const { return NULL; }
  202. virtual int DrawModel( int flags, const RenderableInstance_t &instance ) { return 0; }
  203. virtual bool LODTest() { return true; }
  204. virtual bool SetupBones( matrix3x4a_t *pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime ) { return true; }
  205. virtual void SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights ) {}
  206. virtual void DoAnimationEvents( void ) {}
  207. virtual IPVSNotify* GetPVSNotifyInterface() { return NULL; }
  208. virtual void GetRenderBoundsWorldspace( Vector& absMins, Vector& absMaxs ) { DefaultRenderBoundsWorldspace( this, absMins, absMaxs ); }
  209. // Determine the color modulation amount
  210. virtual void GetColorModulation( float* color )
  211. {
  212. Assert(color);
  213. color[0] = color[1] = color[2] = 1.0f;
  214. }
  215. // Should this object be able to have shadows cast onto it?
  216. virtual bool ShouldReceiveProjectedTextures( int flags )
  217. {
  218. return false;
  219. }
  220. // These methods return true if we want a per-renderable shadow cast direction + distance
  221. virtual bool GetShadowCastDistance( float *pDist, ShadowType_t shadowType ) const { return false; }
  222. virtual bool GetShadowCastDirection( Vector *pDirection, ShadowType_t shadowType ) const { return false; }
  223. virtual void GetShadowRenderBounds( Vector &mins, Vector &maxs, ShadowType_t shadowType )
  224. {
  225. GetRenderBounds( mins, maxs );
  226. }
  227. virtual bool IsShadowDirty( ) { return false; }
  228. virtual void MarkShadowDirty( bool bDirty ) {}
  229. virtual IClientRenderable *GetShadowParent() { return NULL; }
  230. virtual IClientRenderable *FirstShadowChild(){ return NULL; }
  231. virtual IClientRenderable *NextShadowPeer() { return NULL; }
  232. virtual ShadowType_t ShadowCastType() { return SHADOWS_NONE; }
  233. virtual void CreateModelInstance() {}
  234. virtual ModelInstanceHandle_t GetModelInstance() { return MODEL_INSTANCE_INVALID; }
  235. // Attachments
  236. virtual int LookupAttachment( const char *pAttachmentName ) { return -1; }
  237. virtual bool GetAttachment( int number, Vector &origin, QAngle &angles ) { return false; }
  238. virtual bool GetAttachment( int number, matrix3x4_t &matrix ) { return false; }
  239. virtual bool ComputeLightingOrigin( int nAttachmentIndex, Vector modelLightingCenter, const matrix3x4_t &matrix, Vector &transformedLightingCenter ) { return false; }
  240. // Rendering clip plane, should be 4 floats, return value of NULL indicates a disabled render clip plane
  241. virtual float *GetRenderClipPlane() { return NULL; }
  242. virtual void RecordToolMessage() {}
  243. virtual bool ShouldDrawForSplitScreenUser( int nSlot ) { return true; }
  244. virtual uint8 OverrideAlphaModulation( uint8 nAlpha ) { return nAlpha; }
  245. virtual uint8 OverrideShadowAlphaModulation( uint8 nAlpha ) { return nAlpha; }
  246. virtual IClientModelRenderable* GetClientModelRenderable() { return 0; }
  247. // IClientUnknown implementation.
  248. public:
  249. virtual void SetRefEHandle( const CBaseHandle &handle ) { Assert( false ); }
  250. virtual const CBaseHandle& GetRefEHandle() const { Assert( false ); return *((CBaseHandle*)0); }
  251. virtual IClientUnknown* GetIClientUnknown() { return this; }
  252. virtual ICollideable* GetCollideable() { return 0; }
  253. virtual IClientRenderable* GetClientRenderable() { return this; }
  254. virtual IClientNetworkable* GetClientNetworkable() { return 0; }
  255. virtual IClientEntity* GetIClientEntity() { return 0; }
  256. virtual C_BaseEntity* GetBaseEntity() { return 0; }
  257. virtual IClientThinkable* GetClientThinkable() { return 0; }
  258. virtual IClientAlphaProperty* GetClientAlphaProperty() { return 0; }
  259. public:
  260. ClientRenderHandle_t m_hRenderHandle;
  261. };
  262. #endif // ICLIENTRENDERABLE_H