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.

391 lines
9.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cmaterial_queuefriendly.h"
  9. #include "tier1/callqueue.h"
  10. // NOTE: This has to be the last file included!
  11. #include "tier0/memdbgon.h"
  12. #define USE_QUEUED_MATERIAL_CALLS //uncomment to queue up material changing calls. Comment out to always use instant calls.
  13. #ifdef USE_QUEUED_MATERIAL_CALLS
  14. #define QUEUE_MATERIAL_CALL( FuncName, ... ) \
  15. { \
  16. ICallQueue *pCallQueue = materials->GetRenderContext()->GetCallQueue(); \
  17. if ( !pCallQueue ) \
  18. { \
  19. m_pRealTimeVersion->FuncName( __VA_ARGS__ ); \
  20. } \
  21. else \
  22. { \
  23. pCallQueue->QueueCall( m_pRealTimeVersion, &IMaterialInternal::FuncName, ##__VA_ARGS__ ); \
  24. } \
  25. }
  26. #else
  27. #define QUEUE_MATERIAL_CALL( FuncName, ... ) m_pRealTimeVersion->FuncName( __VA_ARGS__ );
  28. #endif
  29. const char *CMaterial_QueueFriendly::GetName() const
  30. {
  31. return m_pRealTimeVersion->GetName();
  32. }
  33. const char *CMaterial_QueueFriendly::GetTextureGroupName() const
  34. {
  35. return m_pRealTimeVersion->GetTextureGroupName();
  36. }
  37. PreviewImageRetVal_t CMaterial_QueueFriendly::GetPreviewImageProperties( int *width, int *height, ImageFormat *imageFormat, bool* isTranslucent ) const
  38. {
  39. return m_pRealTimeVersion->GetPreviewImageProperties( width, height, imageFormat, isTranslucent );
  40. }
  41. PreviewImageRetVal_t CMaterial_QueueFriendly::GetPreviewImage( unsigned char *data, int width, int height, ImageFormat imageFormat ) const
  42. {
  43. return m_pRealTimeVersion->GetPreviewImage( data, width, height, imageFormat );
  44. }
  45. int CMaterial_QueueFriendly::GetMappingWidth( )
  46. {
  47. return m_pRealTimeVersion->GetMappingWidth();
  48. }
  49. int CMaterial_QueueFriendly::GetMappingHeight( )
  50. {
  51. return m_pRealTimeVersion->GetMappingHeight();
  52. }
  53. int CMaterial_QueueFriendly::GetNumAnimationFrames( )
  54. {
  55. return m_pRealTimeVersion->GetNumAnimationFrames();
  56. }
  57. bool CMaterial_QueueFriendly::InMaterialPage( void )
  58. {
  59. return m_pRealTimeVersion->InMaterialPage();
  60. }
  61. void CMaterial_QueueFriendly::GetMaterialOffset( float *pOffset )
  62. {
  63. m_pRealTimeVersion->GetMaterialOffset( pOffset );
  64. }
  65. void CMaterial_QueueFriendly::GetMaterialScale( float *pScale )
  66. {
  67. m_pRealTimeVersion->GetMaterialScale( pScale );
  68. }
  69. IMaterial *CMaterial_QueueFriendly::GetMaterialPage( void )
  70. {
  71. return m_pRealTimeVersion->GetMaterialPage();
  72. }
  73. void CMaterial_QueueFriendly::IncrementReferenceCount( void )
  74. {
  75. m_pRealTimeVersion->IncrementReferenceCount();
  76. }
  77. int CMaterial_QueueFriendly::GetEnumerationID( void ) const
  78. {
  79. return m_pRealTimeVersion->GetEnumerationID();
  80. }
  81. bool CMaterial_QueueFriendly::HasProxy( void ) const
  82. {
  83. return m_pRealTimeVersion->HasProxy();
  84. }
  85. void CMaterial_QueueFriendly::GetReflectivity( Vector& reflect )
  86. {
  87. m_pRealTimeVersion->GetReflectivity( reflect );
  88. }
  89. bool CMaterial_QueueFriendly::GetPropertyFlag( MaterialPropertyTypes_t type )
  90. {
  91. return m_pRealTimeVersion->GetPropertyFlag( type );
  92. }
  93. bool CMaterial_QueueFriendly::IsTwoSided()
  94. {
  95. return m_pRealTimeVersion->IsTwoSided();
  96. }
  97. int CMaterial_QueueFriendly::ShaderParamCount() const
  98. {
  99. return m_pRealTimeVersion->ShaderParamCount();
  100. }
  101. bool CMaterial_QueueFriendly::IsErrorMaterial() const
  102. {
  103. return m_pRealTimeVersion->IsErrorMaterial();
  104. }
  105. bool CMaterial_QueueFriendly::IsSpriteCard()
  106. {
  107. return m_pRealTimeVersion->IsSpriteCard();
  108. }
  109. //TODO: Investigate if these are likely to change at all when setting vars/flags
  110. bool CMaterial_QueueFriendly::IsAlphaTested()
  111. {
  112. return m_pRealTimeVersion->IsAlphaTested();
  113. }
  114. bool CMaterial_QueueFriendly::IsVertexLit()
  115. {
  116. return m_pRealTimeVersion->IsVertexLit();
  117. }
  118. VertexFormat_t CMaterial_QueueFriendly::GetVertexFormat() const
  119. {
  120. return m_pRealTimeVersion->GetVertexFormat();
  121. }
  122. bool CMaterial_QueueFriendly::UsesEnvCubemap( void )
  123. {
  124. return m_pRealTimeVersion->UsesEnvCubemap();
  125. }
  126. bool CMaterial_QueueFriendly::NeedsTangentSpace( void )
  127. {
  128. return m_pRealTimeVersion->NeedsTangentSpace();
  129. }
  130. bool CMaterial_QueueFriendly::NeedsSoftwareSkinning( void )
  131. {
  132. return m_pRealTimeVersion->NeedsSoftwareSkinning();
  133. }
  134. int CMaterial_QueueFriendly::GetNumPasses( void )
  135. {
  136. return m_pRealTimeVersion->GetNumPasses();
  137. }
  138. int CMaterial_QueueFriendly::GetTextureMemoryBytes( void )
  139. {
  140. return m_pRealTimeVersion->GetTextureMemoryBytes();
  141. }
  142. bool CMaterial_QueueFriendly::NeedsLightmapBlendAlpha( void )
  143. {
  144. return m_pRealTimeVersion->NeedsLightmapBlendAlpha();
  145. }
  146. bool CMaterial_QueueFriendly::NeedsSoftwareLighting( void )
  147. {
  148. return m_pRealTimeVersion->NeedsSoftwareLighting();
  149. }
  150. void CMaterial_QueueFriendly::GetLowResColorSample( float s, float t, float *color ) const
  151. {
  152. m_pRealTimeVersion->GetLowResColorSample( s, t, color );
  153. }
  154. IMaterialVar *CMaterial_QueueFriendly::FindVar( const char *varName, bool *found, bool complain )
  155. {
  156. //TODO: return a queue friendly variable that can be get/set
  157. return m_pRealTimeVersion->FindVar( varName, found, complain );
  158. }
  159. IMaterialVar *CMaterial_QueueFriendly::FindVarFast( char const *pVarName, unsigned int *pToken )
  160. {
  161. //TODO: return a queue friendly variable that can be get/set
  162. return m_pRealTimeVersion->FindVarFast( pVarName, pToken );
  163. }
  164. IMaterialVar **CMaterial_QueueFriendly::GetShaderParams( void )
  165. {
  166. //TODO: return queue friendly variables that can be get/set
  167. return m_pRealTimeVersion->GetShaderParams();
  168. }
  169. void CMaterial_QueueFriendly::DecrementReferenceCount( void )
  170. {
  171. QUEUE_MATERIAL_CALL( DecrementReferenceCount );
  172. }
  173. void CMaterial_QueueFriendly::DeleteIfUnreferenced()
  174. {
  175. QUEUE_MATERIAL_CALL( DeleteIfUnreferenced );
  176. }
  177. void CMaterial_QueueFriendly::RecomputeStateSnapshots()
  178. {
  179. QUEUE_MATERIAL_CALL( RecomputeStateSnapshots );
  180. }
  181. bool CMaterial_QueueFriendly::IsTranslucent()
  182. {
  183. //TODO: need to base this as if the queued state is 100% up to date
  184. return m_pRealTimeVersion->IsTranslucentInternal( m_fAlphaModulationOnQueueCompletion );
  185. }
  186. bool CMaterial_QueueFriendly::IsTranslucentUnderModulation( float fAlphaModulation ) const
  187. {
  188. return m_pRealTimeVersion->IsTranslucentUnderModulation( fAlphaModulation );
  189. }
  190. bool CMaterial_QueueFriendly::NeedsPowerOfTwoFrameBufferTexture( bool bCheckSpecificToThisFrame )
  191. {
  192. //bCheckSpecificToThisFrame scares me a bit.
  193. return m_pRealTimeVersion->NeedsPowerOfTwoFrameBufferTexture( bCheckSpecificToThisFrame );
  194. }
  195. bool CMaterial_QueueFriendly::NeedsFullFrameBufferTexture( bool bCheckSpecificToThisFrame )
  196. {
  197. //bCheckSpecificToThisFrame scares me a bit.
  198. return m_pRealTimeVersion->NeedsFullFrameBufferTexture( bCheckSpecificToThisFrame );
  199. }
  200. void CMaterial_QueueFriendly::AlphaModulate( float alpha )
  201. {
  202. QUEUE_MATERIAL_CALL( AlphaModulate, alpha );
  203. m_fAlphaModulationOnQueueCompletion = alpha;
  204. }
  205. void CMaterial_QueueFriendly::ColorModulate( float r, float g, float b )
  206. {
  207. QUEUE_MATERIAL_CALL( ColorModulate, r, g, b );
  208. m_vColorModulationOnQueueCompletion.Init( r, g, b );
  209. }
  210. void CMaterial_QueueFriendly::SetMaterialVarFlag( MaterialVarFlags_t flag, bool on )
  211. {
  212. QUEUE_MATERIAL_CALL( SetMaterialVarFlag, flag, on );
  213. }
  214. bool CMaterial_QueueFriendly::GetMaterialVarFlag( MaterialVarFlags_t flag ) const
  215. {
  216. //TODO: somehow mix both queued and real time states
  217. return m_pRealTimeVersion->GetMaterialVarFlag( flag );
  218. }
  219. void CMaterial_QueueFriendly::SetShader( const char *pShaderName )
  220. {
  221. //TODO: queue it and investigate, seems like a grenade.
  222. m_pRealTimeVersion->SetShader( pShaderName );
  223. }
  224. void CMaterial_QueueFriendly::SetShaderAndParams( KeyValues *pKeyValues )
  225. {
  226. //TODO: queue it and investigate, seems like a grenade.
  227. m_pRealTimeVersion->SetShaderAndParams( pKeyValues );
  228. }
  229. const char *CMaterial_QueueFriendly::GetShaderName() const
  230. {
  231. //TODO: return as if the queue is up to date. Someone could have set the shader very recently
  232. return m_pRealTimeVersion->GetShaderName();
  233. }
  234. void CMaterial_QueueFriendly::Refresh()
  235. {
  236. //TODO: Investigate, this one seems like a grenade.
  237. m_pRealTimeVersion->Refresh();
  238. //QUEUE_MATERIAL_CALL( Refresh );
  239. }
  240. void CMaterial_QueueFriendly::RefreshPreservingMaterialVars()
  241. {
  242. //TODO: Investigate, this one seems like a grenade.
  243. m_pRealTimeVersion->RefreshPreservingMaterialVars();
  244. //QUEUE_MATERIAL_CALL( RefreshPreservingMaterialVars );
  245. }
  246. float CMaterial_QueueFriendly::GetAlphaModulation()
  247. {
  248. #ifdef USE_QUEUED_MATERIAL_CALLS
  249. return m_fAlphaModulationOnQueueCompletion;
  250. #else
  251. return m_pRealTimeVersion->GetAlphaModulation();
  252. #endif
  253. }
  254. void CMaterial_QueueFriendly::GetColorModulation( float *r, float *g, float *b )
  255. {
  256. #ifdef USE_QUEUED_MATERIAL_CALLS
  257. *r = m_vColorModulationOnQueueCompletion.x;
  258. *g = m_vColorModulationOnQueueCompletion.y;
  259. *b = m_vColorModulationOnQueueCompletion.z;
  260. #else
  261. m_pRealTimeVersion->GetColorModulation( r, g, b );
  262. #endif
  263. }
  264. void CMaterial_QueueFriendly::CallBindProxy( void *proxyData, ICallQueue *pCallQueue )
  265. {
  266. //TODO: queue it? Investigate.
  267. return m_pRealTimeVersion->CallBindProxy( proxyData, pCallQueue );
  268. }
  269. void CMaterial_QueueFriendly::PrecacheMappingDimensions()
  270. {
  271. return m_pRealTimeVersion->PrecacheMappingDimensions();
  272. }
  273. void CMaterial_QueueFriendly::FindRepresentativeTexture()
  274. {
  275. return m_pRealTimeVersion->FindRepresentativeTexture();
  276. }
  277. bool CMaterial_QueueFriendly::IsRealTimeVersion( void ) const
  278. {
  279. return false;
  280. }
  281. IMaterialInternal *CMaterial_QueueFriendly::GetRealTimeVersion( void )
  282. {
  283. return m_pRealTimeVersion;
  284. }
  285. IMaterialInternal *CMaterial_QueueFriendly::GetQueueFriendlyVersion( void )
  286. {
  287. return this;
  288. }
  289. void CMaterial_QueueFriendly::UpdateToRealTime( void )
  290. {
  291. m_fAlphaModulationOnQueueCompletion = m_pRealTimeVersion->GetAlphaModulation();
  292. m_pRealTimeVersion->GetColorModulation( &m_vColorModulationOnQueueCompletion.x,
  293. &m_vColorModulationOnQueueCompletion.y,
  294. &m_vColorModulationOnQueueCompletion.z );
  295. }
  296. bool CMaterial_QueueFriendly::SetTempExcluded( bool bSet, int nExcludedDimensionLimit )
  297. {
  298. return m_pRealTimeVersion->SetTempExcluded( bSet, nExcludedDimensionLimit );
  299. }