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.

258 lines
7.8 KiB

  1. //========= Copyright 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( void );
  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. // Power of Two Frame Buffer Texture
  27. //=============================================================================
  28. static CTextureReference s_pPowerOfTwoFrameBufferTexture;
  29. ITexture *GetPowerOfTwoFrameBufferTexture( void )
  30. {
  31. if ( IsX360() )
  32. {
  33. return GetFullFrameFrameBufferTexture( 1 );
  34. }
  35. if ( !s_pPowerOfTwoFrameBufferTexture )
  36. {
  37. s_pPowerOfTwoFrameBufferTexture.Init( materials->FindTexture( "_rt_PowerOfTwoFB", TEXTURE_GROUP_RENDER_TARGET ) );
  38. Assert( !IsErrorTexture( s_pPowerOfTwoFrameBufferTexture ) );
  39. AddReleaseFunc();
  40. }
  41. return s_pPowerOfTwoFrameBufferTexture;
  42. }
  43. //=============================================================================
  44. // Fullscreen Texture
  45. //=============================================================================
  46. static CTextureReference s_pFullscreenTexture;
  47. ITexture *GetFullscreenTexture( void )
  48. {
  49. if ( !s_pFullscreenTexture )
  50. {
  51. s_pFullscreenTexture.Init( materials->FindTexture( "_rt_Fullscreen", TEXTURE_GROUP_RENDER_TARGET ) );
  52. Assert( !IsErrorTexture( s_pFullscreenTexture ) );
  53. AddReleaseFunc();
  54. }
  55. return s_pFullscreenTexture;
  56. }
  57. //=============================================================================
  58. // Camera Texture
  59. //=============================================================================
  60. static CTextureReference s_pCameraTexture;
  61. ITexture *GetCameraTexture( void )
  62. {
  63. if ( !s_pCameraTexture )
  64. {
  65. s_pCameraTexture.Init( materials->FindTexture( "_rt_Camera", TEXTURE_GROUP_RENDER_TARGET ) );
  66. Assert( !IsErrorTexture( s_pCameraTexture ) );
  67. AddReleaseFunc();
  68. }
  69. return s_pCameraTexture;
  70. }
  71. //=============================================================================
  72. // Full Frame Depth Texture
  73. //=============================================================================
  74. static CTextureReference s_pFullFrameDepthTexture;
  75. ITexture *GetFullFrameDepthTexture( void )
  76. {
  77. if ( !s_pFullFrameDepthTexture )
  78. {
  79. s_pFullFrameDepthTexture.Init( materials->FindTexture( "_rt_FullFrameDepth", TEXTURE_GROUP_RENDER_TARGET ) );
  80. Assert( !IsErrorTexture( s_pFullFrameDepthTexture ) );
  81. AddReleaseFunc();
  82. }
  83. return s_pFullFrameDepthTexture;
  84. }
  85. //=============================================================================
  86. // Full Frame Buffer Textures
  87. //=============================================================================
  88. static CTextureReference s_pFullFrameFrameBufferTexture[MAX_FB_TEXTURES];
  89. ITexture *GetFullFrameFrameBufferTexture( int textureIndex )
  90. {
  91. if ( !s_pFullFrameFrameBufferTexture[textureIndex] )
  92. {
  93. char name[256];
  94. if( textureIndex != 0 )
  95. {
  96. V_sprintf_safe( name, "_rt_FullFrameFB%d", textureIndex );
  97. }
  98. else
  99. {
  100. V_strcpy_safe( name, "_rt_FullFrameFB" );
  101. }
  102. s_pFullFrameFrameBufferTexture[textureIndex].Init( materials->FindTexture( name, TEXTURE_GROUP_RENDER_TARGET ) );
  103. Assert( !IsErrorTexture( s_pFullFrameFrameBufferTexture[textureIndex] ) );
  104. AddReleaseFunc();
  105. }
  106. return s_pFullFrameFrameBufferTexture[textureIndex];
  107. }
  108. //=============================================================================
  109. // Water reflection
  110. //=============================================================================
  111. static CTextureReference s_pWaterReflectionTexture;
  112. ITexture *GetWaterReflectionTexture( void )
  113. {
  114. if ( !s_pWaterReflectionTexture )
  115. {
  116. s_pWaterReflectionTexture.Init( materials->FindTexture( "_rt_WaterReflection", TEXTURE_GROUP_RENDER_TARGET ) );
  117. Assert( !IsErrorTexture( s_pWaterReflectionTexture ) );
  118. AddReleaseFunc();
  119. }
  120. return s_pWaterReflectionTexture;
  121. }
  122. //=============================================================================
  123. // Water refraction
  124. //=============================================================================
  125. static CTextureReference s_pWaterRefractionTexture;
  126. ITexture *GetWaterRefractionTexture( void )
  127. {
  128. if ( !s_pWaterRefractionTexture )
  129. {
  130. s_pWaterRefractionTexture.Init( materials->FindTexture( "_rt_WaterRefraction", TEXTURE_GROUP_RENDER_TARGET ) );
  131. Assert( !IsErrorTexture( s_pWaterRefractionTexture ) );
  132. AddReleaseFunc();
  133. }
  134. return s_pWaterRefractionTexture;
  135. }
  136. //=============================================================================
  137. // Small Buffer HDR0
  138. //=============================================================================
  139. static CTextureReference s_pSmallBufferHDR0;
  140. ITexture *GetSmallBufferHDR0( void )
  141. {
  142. if ( !s_pSmallBufferHDR0 )
  143. {
  144. s_pSmallBufferHDR0.Init( materials->FindTexture( "_rt_SmallHDR0", TEXTURE_GROUP_RENDER_TARGET ) );
  145. Assert( !IsErrorTexture( s_pSmallBufferHDR0 ) );
  146. AddReleaseFunc();
  147. }
  148. return s_pSmallBufferHDR0;
  149. }
  150. //=============================================================================
  151. // Small Buffer HDR1
  152. //=============================================================================
  153. static CTextureReference s_pSmallBufferHDR1;
  154. ITexture *GetSmallBufferHDR1( void )
  155. {
  156. if ( !s_pSmallBufferHDR1 )
  157. {
  158. s_pSmallBufferHDR1.Init( materials->FindTexture( "_rt_SmallHDR1", TEXTURE_GROUP_RENDER_TARGET ) );
  159. Assert( !IsErrorTexture( s_pSmallBufferHDR1 ) );
  160. AddReleaseFunc();
  161. }
  162. return s_pSmallBufferHDR1;
  163. }
  164. //=============================================================================
  165. // Quarter Sized FB0
  166. //=============================================================================
  167. static CTextureReference s_pQuarterSizedFB0;
  168. ITexture *GetSmallBuffer0( void )
  169. {
  170. if ( !s_pQuarterSizedFB0 )
  171. {
  172. s_pQuarterSizedFB0.Init( materials->FindTexture( "_rt_SmallFB0", TEXTURE_GROUP_RENDER_TARGET ) );
  173. Assert( !IsErrorTexture( s_pQuarterSizedFB0 ) );
  174. AddReleaseFunc();
  175. }
  176. return s_pQuarterSizedFB0;
  177. }
  178. //=============================================================================
  179. // Quarter Sized FB1
  180. //=============================================================================
  181. static CTextureReference s_pQuarterSizedFB1;
  182. ITexture *GetSmallBuffer1( void )
  183. {
  184. if ( !s_pQuarterSizedFB1 )
  185. {
  186. s_pQuarterSizedFB1.Init( materials->FindTexture( "_rt_SmallFB1", TEXTURE_GROUP_RENDER_TARGET ) );
  187. Assert( !IsErrorTexture( s_pQuarterSizedFB1 ) );
  188. AddReleaseFunc();
  189. }
  190. return s_pQuarterSizedFB1;
  191. }
  192. //=============================================================================
  193. // Teeny Textures
  194. //=============================================================================
  195. static CTextureReference s_TeenyTextures[MAX_TEENY_TEXTURES];
  196. ITexture *GetTeenyTexture( int which )
  197. {
  198. if ( IsX360() )
  199. {
  200. Assert( 0 );
  201. return NULL;
  202. }
  203. Assert( which < MAX_TEENY_TEXTURES );
  204. if ( !s_TeenyTextures[which] )
  205. {
  206. char nbuf[20];
  207. sprintf( nbuf, "_rt_TeenyFB%d", which );
  208. s_TeenyTextures[which].Init( materials->FindTexture( nbuf, TEXTURE_GROUP_RENDER_TARGET ) );
  209. Assert( !IsErrorTexture( s_TeenyTextures[which] ) );
  210. AddReleaseFunc();
  211. }
  212. return s_TeenyTextures[which];
  213. }
  214. void ReleaseRenderTargets( void )
  215. {
  216. s_pPowerOfTwoFrameBufferTexture.Shutdown();
  217. s_pCameraTexture.Shutdown();
  218. s_pWaterReflectionTexture.Shutdown();
  219. s_pWaterRefractionTexture.Shutdown();
  220. s_pQuarterSizedFB0.Shutdown();
  221. s_pQuarterSizedFB1.Shutdown();
  222. s_pFullFrameDepthTexture.Shutdown();
  223. for (int i=0; i<MAX_FB_TEXTURES; ++i)
  224. s_pFullFrameFrameBufferTexture[i].Shutdown();
  225. }