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.

312 lines
9.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. // Implements local hooks into named renderable textures.
  5. // See matrendertexture.cpp in material system for list of available RT's
  6. //
  7. //=============================================================================//
  8. #include "materialsystem/imesh.h"
  9. #include "materialsystem/itexture.h"
  10. #include "materialsystem/MaterialSystemUtil.h"
  11. #include "tier1/strtools.h"
  12. #include "rendertexture.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. void ReleaseRenderTargets( int nChangeFlags );
  16. void AddReleaseFunc( void )
  17. {
  18. static bool bAdded = false;
  19. if( !bAdded )
  20. {
  21. bAdded = true;
  22. materials->AddReleaseFunc( ReleaseRenderTargets );
  23. }
  24. }
  25. //=============================================================================
  26. // Stereo Param Texture
  27. //=============================================================================
  28. static CTextureReference s_pStereoParamTexture;
  29. ITexture *GetStereoParamTexture( void )
  30. {
  31. if ( !s_pStereoParamTexture )
  32. {
  33. s_pStereoParamTexture.Init( materials->FindTexture( "stereoparam", TEXTURE_GROUP_OTHER ) );
  34. Assert( !IsErrorTexture( s_pStereoParamTexture ) );
  35. AddReleaseFunc();
  36. }
  37. return s_pStereoParamTexture;
  38. }
  39. //=============================================================================
  40. // Power of Two Frame Buffer Texture
  41. //=============================================================================
  42. static CTextureReference s_pPowerOfTwoFrameBufferTexture;
  43. ITexture *GetPowerOfTwoFrameBufferTexture( void )
  44. {
  45. if ( IsGameConsole() )
  46. {
  47. return GetFullFrameFrameBufferTexture( 1 );
  48. }
  49. if ( !s_pPowerOfTwoFrameBufferTexture )
  50. {
  51. s_pPowerOfTwoFrameBufferTexture.Init( materials->FindTexture( "_rt_PowerOfTwoFB", TEXTURE_GROUP_RENDER_TARGET ) );
  52. Assert( !IsErrorTexture( s_pPowerOfTwoFrameBufferTexture ) );
  53. AddReleaseFunc();
  54. }
  55. return s_pPowerOfTwoFrameBufferTexture;
  56. }
  57. //=============================================================================
  58. // Fullscreen Texture
  59. //=============================================================================
  60. static CTextureReference s_pFullscreenTexture;
  61. ITexture *GetFullscreenTexture( void )
  62. {
  63. if ( !s_pFullscreenTexture )
  64. {
  65. s_pFullscreenTexture.Init( materials->FindTexture( "_rt_Fullscreen", TEXTURE_GROUP_RENDER_TARGET ) );
  66. Assert( !IsErrorTexture( s_pFullscreenTexture ) );
  67. AddReleaseFunc();
  68. }
  69. return s_pFullscreenTexture;
  70. }
  71. //=============================================================================
  72. // Camera Texture
  73. //=============================================================================
  74. static CTextureReference s_pCameraTexture;
  75. ITexture *GetCameraTexture( void )
  76. {
  77. if ( !s_pCameraTexture )
  78. {
  79. s_pCameraTexture.Init( materials->FindTexture( "_rt_Camera", TEXTURE_GROUP_RENDER_TARGET ) );
  80. Assert( !IsErrorTexture( s_pCameraTexture ) );
  81. AddReleaseFunc();
  82. }
  83. return s_pCameraTexture;
  84. }
  85. //=============================================================================
  86. // Full Frame Depth Texture
  87. //=============================================================================
  88. static CTextureReference s_pFullFrameDepthTexture;
  89. ITexture *GetFullFrameDepthTexture( void )
  90. {
  91. if ( !s_pFullFrameDepthTexture )
  92. {
  93. s_pFullFrameDepthTexture.Init( materials->FindTexture( "_rt_FullFrameDepth", TEXTURE_GROUP_RENDER_TARGET ) );
  94. Assert( !IsErrorTexture( s_pFullFrameDepthTexture ) );
  95. AddReleaseFunc();
  96. }
  97. return s_pFullFrameDepthTexture;
  98. }
  99. //=============================================================================
  100. // Full Frame Buffer Textures
  101. //=============================================================================
  102. static CTextureReference s_pFullFrameFrameBufferTexture[MAX_FB_TEXTURES];
  103. ITexture *GetFullFrameFrameBufferTexture( int textureIndex )
  104. {
  105. if ( !s_pFullFrameFrameBufferTexture[textureIndex] )
  106. {
  107. char name[256];
  108. if( textureIndex != 0 )
  109. {
  110. Q_snprintf( name, ARRAYSIZE( name ), "_rt_FullFrameFB%d", textureIndex );
  111. }
  112. else
  113. {
  114. Q_strcpy( name, "_rt_FullFrameFB" );
  115. }
  116. s_pFullFrameFrameBufferTexture[textureIndex].Init( materials->FindTexture( name, TEXTURE_GROUP_RENDER_TARGET ) );
  117. Assert( !IsErrorTexture( s_pFullFrameFrameBufferTexture[textureIndex] ) );
  118. AddReleaseFunc();
  119. }
  120. return s_pFullFrameFrameBufferTexture[textureIndex];
  121. }
  122. //=============================================================================
  123. // Water reflection
  124. //=============================================================================
  125. static CTextureReference s_pWaterReflectionTexture;
  126. ITexture *GetWaterReflectionTexture( void )
  127. {
  128. if ( !s_pWaterReflectionTexture )
  129. {
  130. s_pWaterReflectionTexture.Init( materials->FindTexture( "_rt_WaterReflection", TEXTURE_GROUP_RENDER_TARGET ) );
  131. Assert( !IsErrorTexture( s_pWaterReflectionTexture ) );
  132. AddReleaseFunc();
  133. }
  134. return s_pWaterReflectionTexture;
  135. }
  136. //=============================================================================
  137. // Water refraction
  138. //=============================================================================
  139. static CTextureReference s_pWaterRefractionTexture;
  140. ITexture *GetWaterRefractionTexture( void )
  141. {
  142. if ( !s_pWaterRefractionTexture )
  143. {
  144. s_pWaterRefractionTexture.Init( materials->FindTexture( "_rt_WaterRefraction", TEXTURE_GROUP_RENDER_TARGET ) );
  145. Assert( !IsErrorTexture( s_pWaterRefractionTexture ) );
  146. AddReleaseFunc();
  147. }
  148. return s_pWaterRefractionTexture;
  149. }
  150. //=============================================================================
  151. // Custom Weapon RT
  152. //=============================================================================
  153. static CTextureReference s_pCustomWeaponTexture;
  154. ITexture *GetCustomWeaponTexture( void )
  155. {
  156. if ( !s_pCustomWeaponTexture )
  157. {
  158. s_pCustomWeaponTexture.Init( materials->FindTexture( "_rt_CustomWeapon", TEXTURE_GROUP_RENDER_TARGET ) );
  159. Assert( !IsErrorTexture( s_pCustomWeaponTexture ) );
  160. AddReleaseFunc();
  161. }
  162. return s_pCustomWeaponTexture;
  163. }
  164. //=============================================================================
  165. // Custom Weapon RT for exponent
  166. //=============================================================================
  167. static CTextureReference s_pCustomWeaponTextureExp;
  168. ITexture *GetCustomWeaponTextureExp( void )
  169. {
  170. if ( !s_pCustomWeaponTextureExp )
  171. {
  172. s_pCustomWeaponTextureExp.Init( materials->FindTexture( "_rt_CustomWeaponExp", TEXTURE_GROUP_RENDER_TARGET ) );
  173. Assert( !IsErrorTexture( s_pCustomWeaponTextureExp ) );
  174. AddReleaseFunc();
  175. }
  176. return s_pCustomWeaponTextureExp;
  177. }
  178. //=============================================================================
  179. // Small Buffer HDR0
  180. //=============================================================================
  181. static CTextureReference s_pSmallBufferHDR0;
  182. ITexture *GetSmallBufferHDR0( void )
  183. {
  184. if ( !s_pSmallBufferHDR0 )
  185. {
  186. s_pSmallBufferHDR0.Init( materials->FindTexture( "_rt_SmallHDR0", TEXTURE_GROUP_RENDER_TARGET ) );
  187. Assert( !IsErrorTexture( s_pSmallBufferHDR0 ) );
  188. AddReleaseFunc();
  189. }
  190. return s_pSmallBufferHDR0;
  191. }
  192. //=============================================================================
  193. // Small Buffer HDR1
  194. //=============================================================================
  195. static CTextureReference s_pSmallBufferHDR1;
  196. ITexture *GetSmallBufferHDR1( void )
  197. {
  198. if ( !s_pSmallBufferHDR1 )
  199. {
  200. s_pSmallBufferHDR1.Init( materials->FindTexture( "_rt_SmallHDR1", TEXTURE_GROUP_RENDER_TARGET ) );
  201. Assert( !IsErrorTexture( s_pSmallBufferHDR1 ) );
  202. AddReleaseFunc();
  203. }
  204. return s_pSmallBufferHDR1;
  205. }
  206. //=============================================================================
  207. // Quarter Sized FB0
  208. //=============================================================================
  209. static CTextureReference s_pQuarterSizedFB0;
  210. ITexture *GetSmallBuffer0( void )
  211. {
  212. if ( !s_pQuarterSizedFB0 )
  213. {
  214. s_pQuarterSizedFB0.Init( materials->FindTexture( "_rt_SmallFB0", TEXTURE_GROUP_RENDER_TARGET ) );
  215. Assert( !IsErrorTexture( s_pQuarterSizedFB0 ) );
  216. AddReleaseFunc();
  217. }
  218. return s_pQuarterSizedFB0;
  219. }
  220. //=============================================================================
  221. // Quarter Sized FB1
  222. //=============================================================================
  223. static CTextureReference s_pQuarterSizedFB1;
  224. ITexture *GetSmallBuffer1( void )
  225. {
  226. if ( !s_pQuarterSizedFB1 )
  227. {
  228. s_pQuarterSizedFB1.Init( materials->FindTexture( "_rt_SmallFB1", TEXTURE_GROUP_RENDER_TARGET ) );
  229. Assert( !IsErrorTexture( s_pQuarterSizedFB1 ) );
  230. AddReleaseFunc();
  231. }
  232. return s_pQuarterSizedFB1;
  233. }
  234. //=============================================================================
  235. // Teeny Textures
  236. //=============================================================================
  237. static CTextureReference s_TeenyTextures[MAX_TEENY_TEXTURES];
  238. ITexture *GetTeenyTexture( int which )
  239. {
  240. if ( IsGameConsole() )
  241. {
  242. Assert( 0 );
  243. return NULL;
  244. }
  245. Assert( which < MAX_TEENY_TEXTURES );
  246. if ( !s_TeenyTextures[which] )
  247. {
  248. char nbuf[20];
  249. Q_snprintf( nbuf, ARRAYSIZE( nbuf ), "_rt_TeenyFB%d", which );
  250. s_TeenyTextures[which].Init( materials->FindTexture( nbuf, TEXTURE_GROUP_RENDER_TARGET ) );
  251. Assert( !IsErrorTexture( s_TeenyTextures[which] ) );
  252. AddReleaseFunc();
  253. }
  254. return s_TeenyTextures[which];
  255. }
  256. void ReleaseRenderTargets( int nChangeFlags )
  257. {
  258. if ( nChangeFlags & MATERIAL_RESTORE_VERTEX_FORMAT_CHANGED )
  259. return;
  260. s_pPowerOfTwoFrameBufferTexture.Shutdown();
  261. s_pCameraTexture.Shutdown();
  262. s_pWaterReflectionTexture.Shutdown();
  263. s_pWaterRefractionTexture.Shutdown();
  264. s_pQuarterSizedFB0.Shutdown();
  265. s_pQuarterSizedFB1.Shutdown();
  266. s_pFullFrameDepthTexture.Shutdown();
  267. s_pCustomWeaponTexture.Shutdown();
  268. for (int i=0; i<MAX_FB_TEXTURES; ++i)
  269. {
  270. s_pFullFrameFrameBufferTexture[i].Shutdown();
  271. }
  272. }