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.

282 lines
10 KiB

  1. //========= Copyright 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. };
  39. // This provides a way for entities to know when they've entered or left the PVS.
  40. // Normally, server entities can use NotifyShouldTransmit to get this info, but client-only
  41. // entities can use this. Store a CPVSNotifyInfo in your
  42. //
  43. // When bInPVS=true, it's being called DURING rendering. It might be after rendering any
  44. // number of views.
  45. //
  46. // If no views had the entity, then it is called with bInPVS=false after rendering.
  47. abstract_class IPVSNotify
  48. {
  49. public:
  50. virtual void OnPVSStatusChanged( bool bInPVS ) = 0;
  51. };
  52. //-----------------------------------------------------------------------------
  53. // Purpose: All client entities must implement this interface.
  54. //-----------------------------------------------------------------------------
  55. abstract_class IClientRenderable
  56. {
  57. public:
  58. // Gets at the containing class...
  59. virtual IClientUnknown* GetIClientUnknown() = 0;
  60. // Data accessors
  61. virtual Vector const& GetRenderOrigin( void ) = 0;
  62. virtual QAngle const& GetRenderAngles( void ) = 0;
  63. virtual bool ShouldDraw( void ) = 0;
  64. virtual bool IsTransparent( void ) = 0;
  65. virtual bool UsesPowerOfTwoFrameBufferTexture() = 0;
  66. virtual bool UsesFullFrameBufferTexture() = 0;
  67. virtual ClientShadowHandle_t GetShadowHandle() const = 0;
  68. // Used by the leaf system to store its render handle.
  69. virtual ClientRenderHandle_t& RenderHandle() = 0;
  70. // Render baby!
  71. virtual const model_t* GetModel( ) const = 0;
  72. virtual int DrawModel( int flags ) = 0;
  73. // Get the body parameter
  74. virtual int GetBody() = 0;
  75. // Determine alpha and blend amount for transparent objects based on render state info
  76. virtual void ComputeFxBlend( ) = 0;
  77. virtual int GetFxBlend( void ) = 0;
  78. // Determine the color modulation amount
  79. virtual void GetColorModulation( float* color ) = 0;
  80. // Returns false if the entity shouldn't be drawn due to LOD.
  81. // (NOTE: This is no longer used/supported, but kept in the vtable for backwards compat)
  82. virtual bool LODTest() = 0;
  83. // Call this to get the current bone transforms for the model.
  84. // currentTime parameter will affect interpolation
  85. // nMaxBones specifies how many matrices pBoneToWorldOut can hold. (Should be greater than or
  86. // equal to studiohdr_t::numbones. Use MAXSTUDIOBONES to be safe.)
  87. virtual bool SetupBones( matrix3x4_t *pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime ) = 0;
  88. virtual void SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights ) = 0;
  89. virtual void DoAnimationEvents( void ) = 0;
  90. // Return this if you want PVS notifications. See IPVSNotify for more info.
  91. // Note: you must always return the same value from this function. If you don't,
  92. // undefined things will occur, and they won't be good.
  93. virtual IPVSNotify* GetPVSNotifyInterface() = 0;
  94. // Returns the bounds relative to the origin (render bounds)
  95. virtual void GetRenderBounds( Vector& mins, Vector& maxs ) = 0;
  96. // returns the bounds as an AABB in worldspace
  97. virtual void GetRenderBoundsWorldspace( Vector& mins, Vector& maxs ) = 0;
  98. // These normally call through to GetRenderAngles/GetRenderBounds, but some entities custom implement them.
  99. virtual void GetShadowRenderBounds( Vector &mins, Vector &maxs, ShadowType_t shadowType ) = 0;
  100. // Should this object be able to have shadows cast onto it?
  101. virtual bool ShouldReceiveProjectedTextures( int flags ) = 0;
  102. // These methods return true if we want a per-renderable shadow cast direction + distance
  103. virtual bool GetShadowCastDistance( float *pDist, ShadowType_t shadowType ) const = 0;
  104. virtual bool GetShadowCastDirection( Vector *pDirection, ShadowType_t shadowType ) const = 0;
  105. // Other methods related to shadow rendering
  106. virtual bool IsShadowDirty( ) = 0;
  107. virtual void MarkShadowDirty( bool bDirty ) = 0;
  108. // Iteration over shadow hierarchy
  109. virtual IClientRenderable *GetShadowParent() = 0;
  110. virtual IClientRenderable *FirstShadowChild() = 0;
  111. virtual IClientRenderable *NextShadowPeer() = 0;
  112. // Returns the shadow cast type
  113. virtual ShadowType_t ShadowCastType() = 0;
  114. // Create/get/destroy model instance
  115. virtual void CreateModelInstance() = 0;
  116. virtual ModelInstanceHandle_t GetModelInstance() = 0;
  117. // Returns the transform from RenderOrigin/RenderAngles to world
  118. virtual const matrix3x4_t &RenderableToWorldTransform() = 0;
  119. // Attachments
  120. virtual int LookupAttachment( const char *pAttachmentName ) = 0;
  121. virtual bool GetAttachment( int number, Vector &origin, QAngle &angles ) = 0;
  122. virtual bool GetAttachment( int number, matrix3x4_t &matrix ) = 0;
  123. // Rendering clip plane, should be 4 floats, return value of NULL indicates a disabled render clip plane
  124. virtual float *GetRenderClipPlane( void ) = 0;
  125. // Get the skin parameter
  126. virtual int GetSkin() = 0;
  127. // Is this a two-pass renderable?
  128. virtual bool IsTwoPass( void ) = 0;
  129. virtual void OnThreadedDrawSetup() = 0;
  130. virtual bool UsesFlexDelayedWeights() = 0;
  131. virtual void RecordToolMessage() = 0;
  132. virtual bool IgnoresZBuffer( void ) const = 0;
  133. };
  134. // This class can be used to implement default versions of some of the
  135. // functions of IClientRenderable.
  136. abstract_class CDefaultClientRenderable : public IClientUnknown, public IClientRenderable
  137. {
  138. public:
  139. CDefaultClientRenderable()
  140. {
  141. m_hRenderHandle = INVALID_CLIENT_RENDER_HANDLE;
  142. }
  143. virtual const Vector & GetRenderOrigin( void ) = 0;
  144. virtual const QAngle & GetRenderAngles( void ) = 0;
  145. virtual const matrix3x4_t & RenderableToWorldTransform() = 0;
  146. virtual bool ShouldDraw( void ) = 0;
  147. virtual bool IsTransparent( void ) = 0;
  148. virtual bool IsTwoPass( void ) { return false; }
  149. virtual void OnThreadedDrawSetup() {}
  150. virtual bool UsesPowerOfTwoFrameBufferTexture( void ) { return false; }
  151. virtual bool UsesFullFrameBufferTexture( void ) { return false; }
  152. virtual ClientShadowHandle_t GetShadowHandle() const
  153. {
  154. return CLIENTSHADOW_INVALID_HANDLE;
  155. }
  156. virtual ClientRenderHandle_t& RenderHandle()
  157. {
  158. return m_hRenderHandle;
  159. }
  160. virtual int GetBody() { return 0; }
  161. virtual int GetSkin() { return 0; }
  162. virtual bool UsesFlexDelayedWeights() { return false; }
  163. virtual const model_t* GetModel( ) const { return NULL; }
  164. virtual int DrawModel( int flags ) { return 0; }
  165. virtual void ComputeFxBlend( ) { return; }
  166. virtual int GetFxBlend( ) { return 255; }
  167. virtual bool LODTest() { return true; }
  168. virtual bool SetupBones( matrix3x4_t *pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime ) { return true; }
  169. virtual void SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights ) {}
  170. virtual void DoAnimationEvents( void ) {}
  171. virtual IPVSNotify* GetPVSNotifyInterface() { return NULL; }
  172. virtual void GetRenderBoundsWorldspace( Vector& absMins, Vector& absMaxs ) { DefaultRenderBoundsWorldspace( this, absMins, absMaxs ); }
  173. // Determine the color modulation amount
  174. virtual void GetColorModulation( float* color )
  175. {
  176. Assert(color);
  177. color[0] = color[1] = color[2] = 1.0f;
  178. }
  179. // Should this object be able to have shadows cast onto it?
  180. virtual bool ShouldReceiveProjectedTextures( int flags )
  181. {
  182. return false;
  183. }
  184. // These methods return true if we want a per-renderable shadow cast direction + distance
  185. virtual bool GetShadowCastDistance( float *pDist, ShadowType_t shadowType ) const { return false; }
  186. virtual bool GetShadowCastDirection( Vector *pDirection, ShadowType_t shadowType ) const { return false; }
  187. virtual void GetShadowRenderBounds( Vector &mins, Vector &maxs, ShadowType_t shadowType )
  188. {
  189. GetRenderBounds( mins, maxs );
  190. }
  191. virtual bool IsShadowDirty( ) { return false; }
  192. virtual void MarkShadowDirty( bool bDirty ) {}
  193. virtual IClientRenderable *GetShadowParent() { return NULL; }
  194. virtual IClientRenderable *FirstShadowChild(){ return NULL; }
  195. virtual IClientRenderable *NextShadowPeer() { return NULL; }
  196. virtual ShadowType_t ShadowCastType() { return SHADOWS_NONE; }
  197. virtual void CreateModelInstance() {}
  198. virtual ModelInstanceHandle_t GetModelInstance() { return MODEL_INSTANCE_INVALID; }
  199. // Attachments
  200. virtual int LookupAttachment( const char *pAttachmentName ) { return -1; }
  201. virtual bool GetAttachment( int number, Vector &origin, QAngle &angles ) { return false; }
  202. virtual bool GetAttachment( int number, matrix3x4_t &matrix ) { return false; }
  203. // Rendering clip plane, should be 4 floats, return value of NULL indicates a disabled render clip plane
  204. virtual float *GetRenderClipPlane() { return NULL; }
  205. virtual void RecordToolMessage() {}
  206. virtual bool IgnoresZBuffer( void ) const { return false; }
  207. // IClientUnknown implementation.
  208. public:
  209. virtual void SetRefEHandle( const CBaseHandle &handle ) { Assert( false ); }
  210. virtual const CBaseHandle& GetRefEHandle() const { Assert( false ); return *((CBaseHandle*)0); }
  211. virtual IClientUnknown* GetIClientUnknown() { return this; }
  212. virtual ICollideable* GetCollideable() { return 0; }
  213. virtual IClientRenderable* GetClientRenderable() { return this; }
  214. virtual IClientNetworkable* GetClientNetworkable() { return 0; }
  215. virtual IClientEntity* GetIClientEntity() { return 0; }
  216. virtual C_BaseEntity* GetBaseEntity() { return 0; }
  217. virtual IClientThinkable* GetClientThinkable() { return 0; }
  218. public:
  219. ClientRenderHandle_t m_hRenderHandle;
  220. };
  221. #endif // ICLIENTRENDERABLE_H