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.

633 lines
20 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "gameuidynamictextures.h"
  8. #include "gamelayer.h"
  9. #include "gamerect.h"
  10. #include "tier1/utlstring.h"
  11. #include "tier1/utlstringmap.h"
  12. #include "tier1/utlbuffer.h"
  13. #include "gameuisystemmgr.h"
  14. #include "tier1/fmtstr.h"
  15. #include "materialsystem/imaterial.h"
  16. #include "materialsystem/imaterialvar.h"
  17. #include "materialsystem/imaterialsystem.h"
  18. #include "materialsystem/imesh.h"
  19. #include "rendersystem/irenderdevice.h"
  20. #include "rendersystem/irendercontext.h"
  21. #include "tier1/keyvalues.h"
  22. #include "materialsystem/IMaterialProxy.h"
  23. #include "materialsystem/imaterialproxyfactory.h"
  24. #include "gameuisystemmgr.h"
  25. // memdbgon must be the last include file in a .cpp file!!!
  26. #include "tier0/memdbgon.h"
  27. #define GAMEUI_DYNAMIC_TEXTURE_SHEET_WIDTH 2048
  28. #define GAMEUI_DYNAMIC_TEXTURE_SHEET_HEIGHT 2048
  29. //-----------------------------------------------------------------------------
  30. // A material proxy that resets the base texture to use the dynamic texture
  31. //-----------------------------------------------------------------------------
  32. class CGameControlsProxy : public IMaterialProxy
  33. {
  34. public:
  35. CGameControlsProxy();
  36. virtual ~CGameControlsProxy(){};
  37. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  38. virtual void OnBind( void *pProxyData );
  39. virtual void Release( void )
  40. {
  41. delete this;
  42. }
  43. virtual IMaterial *GetMaterial();
  44. private:
  45. IMaterialVar* m_BaseTextureVar;
  46. };
  47. CGameControlsProxy::CGameControlsProxy(): m_BaseTextureVar( NULL )
  48. {
  49. }
  50. bool CGameControlsProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  51. {
  52. bool bFoundVar;
  53. m_BaseTextureVar = pMaterial->FindVar( "$basetexture", &bFoundVar, false );
  54. return bFoundVar;
  55. }
  56. void CGameControlsProxy::OnBind( void *pProxyData )
  57. {
  58. const char *pBaseTextureName = ( const char * )pProxyData;
  59. ITexture *pTexture = g_pMaterialSystem->FindTexture( pBaseTextureName, TEXTURE_GROUP_OTHER, true );
  60. m_BaseTextureVar->SetTextureValue( pTexture );
  61. }
  62. IMaterial *CGameControlsProxy::GetMaterial()
  63. {
  64. return m_BaseTextureVar->GetOwningMaterial();
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Factory to create dynamic material. ( Return in this case. )
  68. //-----------------------------------------------------------------------------
  69. class CMaterialProxyFactory : public IMaterialProxyFactory
  70. {
  71. public:
  72. IMaterialProxy *CreateProxy( const char *proxyName );
  73. void DeleteProxy( IMaterialProxy *pProxy );
  74. CreateInterfaceFn GetFactory();
  75. };
  76. static CMaterialProxyFactory s_DynamicMaterialProxyFactory;
  77. IMaterialProxy *CMaterialProxyFactory::CreateProxy( const char *proxyName )
  78. {
  79. if ( Q_strcmp( proxyName, "GameControlsProxy" ) == NULL )
  80. {
  81. return static_cast< IMaterialProxy * >( new CGameControlsProxy );
  82. }
  83. return NULL;
  84. }
  85. void CMaterialProxyFactory::DeleteProxy( IMaterialProxy *pProxy )
  86. {
  87. }
  88. CreateInterfaceFn CMaterialProxyFactory::GetFactory()
  89. {
  90. return Sys_GetFactoryThis();
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Constructor / Destructor.
  94. //-----------------------------------------------------------------------------
  95. CGameUIDynamicTextures::CGameUIDynamicTextures()
  96. {
  97. m_pDynamicTexturePacker = NULL;
  98. m_RenderMaterial = NULL;
  99. m_bRegenerate = false;
  100. }
  101. CGameUIDynamicTextures::~CGameUIDynamicTextures()
  102. {
  103. Shutdown();
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Init any render targets needed by the UI.
  107. //-----------------------------------------------------------------------------
  108. void CGameUIDynamicTextures::InitRenderTargets()
  109. {
  110. if ( !m_TexturePage.IsValid() )
  111. {
  112. m_TexturePage.InitRenderTarget( GAMEUI_DYNAMIC_TEXTURE_SHEET_WIDTH, GAMEUI_DYNAMIC_TEXTURE_SHEET_HEIGHT,
  113. RT_SIZE_NO_CHANGE, IMAGE_FORMAT_ARGB8888,
  114. MATERIAL_RT_DEPTH_NONE, false, "_rt_DynamicUI" );
  115. }
  116. if ( m_TexturePage.IsValid() )
  117. {
  118. int nSheetWidth = m_TexturePage->GetActualWidth();
  119. int nSheetHeight = m_TexturePage->GetActualHeight();
  120. m_pDynamicTexturePacker = new CTexturePacker( nSheetWidth, nSheetHeight, IsGameConsole() ? 0 : 1 );
  121. KeyValues *pVMTKeyValues = new KeyValues( "GameControls" );
  122. pVMTKeyValues->SetString( "$basetexture", "_rt_DynamicUI" );
  123. CMaterialReference material;
  124. // Material names must be different
  125. CFmtStr materialName;
  126. materialName.sprintf( "dynamictx_%s", "_rt_DynamicUI" );
  127. material.Init( materialName, TEXTURE_GROUP_OTHER, pVMTKeyValues );
  128. material->Refresh();
  129. {
  130. ImageAliasData_t imageData;
  131. imageData.m_Width = nSheetWidth;
  132. imageData.m_Height = nSheetHeight;
  133. imageData.m_Material = material;
  134. m_ImageAliasMap[ "_rt_DynamicUI" ] = imageData;
  135. }
  136. {
  137. CTextureReference pErrorTexture;
  138. pErrorTexture.Init( "error", TEXTURE_GROUP_OTHER, true );
  139. ImageAliasData_t imageData;
  140. imageData.m_Width = pErrorTexture->GetActualWidth();
  141. imageData.m_Height = pErrorTexture->GetActualHeight();
  142. imageData.m_szBaseTextureName = "error";
  143. imageData.m_Material = NULL;
  144. m_ImageAliasMap[ "errorImageAlias" ] = imageData;
  145. }
  146. pVMTKeyValues = new KeyValues( "GameControls" );
  147. pVMTKeyValues->SetInt( "$ignorez", 1 );
  148. KeyValues *pProxies = new KeyValues( "Proxies" );
  149. pProxies->AddSubKey( new KeyValues( "GameControlsProxy" ) );
  150. pVMTKeyValues->AddSubKey( pProxies );
  151. m_RenderMaterial.Init( "dynamic_render_texture", TEXTURE_GROUP_OTHER, pVMTKeyValues );
  152. m_RenderMaterial->Refresh();
  153. g_pGameUISystemMgrImpl->InitImageAlias( "defaultImageAlias" );
  154. g_pGameUISystemMgrImpl->LoadImageAliasTexture( "defaultImageAlias", "vguiedit/pixel" );
  155. }
  156. }
  157. IMaterialProxy *CGameUIDynamicTextures::CreateProxy( const char *proxyName )
  158. {
  159. return s_DynamicMaterialProxyFactory.CreateProxy( proxyName );
  160. }
  161. //-----------------------------------------------------------------------------
  162. //
  163. //-----------------------------------------------------------------------------
  164. void CGameUIDynamicTextures::Shutdown()
  165. {
  166. m_RenderMaterial.Shutdown();
  167. m_TexturePage.Shutdown();
  168. if ( m_pDynamicTexturePacker )
  169. {
  170. delete m_pDynamicTexturePacker;
  171. }
  172. m_pDynamicTexturePacker = NULL;
  173. m_RenderMaterial = NULL;
  174. m_bRegenerate = false;
  175. }
  176. void CGameUIDynamicTextures::SetImageEntry( const char *pEntryName, ImageAliasData_t &imageData )
  177. {
  178. m_ImageAliasMap[ pEntryName ] = imageData;
  179. }
  180. //-----------------------------------------------------------------------------
  181. // Associate this image alias name with a .vtf texture.
  182. //-----------------------------------------------------------------------------
  183. void CGameUIDynamicTextures::LoadImageAlias( const char *pAlias, const char *pBaseTextureName )
  184. {
  185. if ( !pAlias || !*pAlias )
  186. return;
  187. if ( !pBaseTextureName || !*pBaseTextureName )
  188. return;
  189. CFmtStr texturePath;
  190. texturePath.sprintf( "materials\\%s.vtf", pBaseTextureName );
  191. if ( !g_pFullFileSystem->FileExists( texturePath.Access(), IsGameConsole() ? "MOD" : "GAME" ) )
  192. {
  193. Warning( "Unable to find game ui dynamic texture \"%s\"\n", texturePath.Access() );
  194. }
  195. if ( Q_strcmp( pBaseTextureName, "" ) == 0 )
  196. {
  197. ImageAliasData_t *pImageData = GetImageAliasData( "errorImageAlias" );
  198. ImageAliasData_t imageData;
  199. imageData.Init();
  200. imageData.m_XPos = pImageData->m_XPos;
  201. imageData.m_YPos = pImageData->m_YPos;
  202. imageData.m_Width = pImageData->m_Width;
  203. imageData.m_Height = pImageData->m_Height;
  204. imageData.m_szBaseTextureName = pImageData->m_szBaseTextureName;
  205. imageData.m_Material = pImageData->m_Material;
  206. imageData.m_bIsInSheet = pImageData->m_bIsInSheet;
  207. imageData.m_nNodeIndex = pImageData->m_nNodeIndex;
  208. SetImageEntry( pAlias, imageData );
  209. return;
  210. }
  211. Msg( "Loading Alias %s Texture %s\n", pAlias, pBaseTextureName );
  212. CTextureReference pTexture;
  213. pTexture.Init( pBaseTextureName, TEXTURE_GROUP_OTHER, true );
  214. ImageAliasData_t *pImageData = GetImageAliasData( pAlias );
  215. int nodeIndex = -1;
  216. if ( m_pDynamicTexturePacker )
  217. {
  218. if ( !IsErrorImageAliasData( pImageData ) )
  219. {
  220. if ( pImageData->m_nNodeIndex != -1 )
  221. {
  222. // We already had something packed in there for this alias.
  223. // Remove the old alias texture
  224. m_pDynamicTexturePacker->RemoveRect( pImageData->m_nNodeIndex );
  225. }
  226. // Set up new imagedata values
  227. pImageData->m_Width = pTexture->GetActualWidth();
  228. pImageData->m_Height = pTexture->GetActualHeight();
  229. pImageData->m_szBaseTextureName = pBaseTextureName;
  230. }
  231. else
  232. {
  233. ImageAliasData_t imageData;
  234. imageData.m_Width = pTexture->GetActualWidth();
  235. imageData.m_Height = pTexture->GetActualHeight();
  236. imageData.m_szBaseTextureName = pBaseTextureName;
  237. imageData.m_nRefCount = pImageData->m_nRefCount;
  238. SetImageEntry( pAlias, imageData );
  239. pImageData = GetImageAliasData( pAlias );
  240. Assert( !IsErrorImageAliasData( pImageData ) );
  241. }
  242. int nSheetWidth = 0;
  243. int nSheetHeight = 0;
  244. GetDynamicSheetSize( nSheetWidth, nSheetHeight );
  245. Assert( nSheetWidth != 0 );
  246. Assert( nSheetHeight != 0 );
  247. // If our texture is huge in some way, don't bother putting it in the packed texture.
  248. if ( ( pTexture->GetActualWidth() << 1 ) < nSheetWidth || ( pTexture->GetActualHeight() << 1 ) < nSheetHeight )
  249. {
  250. // Put this texture into the packed render target texture.
  251. Rect_t texRect;
  252. texRect.x = 0;
  253. texRect.y = 0;
  254. texRect.width = pTexture->GetActualWidth();
  255. texRect.height = pTexture->GetActualHeight();
  256. nodeIndex = m_pDynamicTexturePacker->InsertRect( texRect );
  257. }
  258. }
  259. // For debugging this will make no packing happen. Each texture is one draw call
  260. //nodeIndex = -1;
  261. pImageData->m_nNodeIndex = nodeIndex;
  262. LoadImageAliasTexture( pAlias, pBaseTextureName );
  263. }
  264. //-----------------------------------------------------------------------------
  265. // Release the entry for this alias in the packer.
  266. //-----------------------------------------------------------------------------
  267. void CGameUIDynamicTextures::ReleaseImageAlias( const char *pAlias )
  268. {
  269. if ( Q_strcmp( pAlias, "_rt_DynamicUI" ) == 0 )
  270. return;
  271. if ( Q_strcmp( pAlias, "errorImageAlias" ) == 0 )
  272. return;
  273. if ( Q_strcmp( pAlias, "defaultImageAlias" ) == 0 )
  274. return;
  275. ImageAliasData_t *pImageData = GetImageAliasData( pAlias );
  276. if ( pImageData )
  277. {
  278. Assert( pImageData->m_nRefCount > 0 );
  279. pImageData->m_nRefCount--;
  280. if ( pImageData->m_nRefCount == 0 )
  281. {
  282. if ( pImageData->m_bIsInSheet )
  283. {
  284. Msg( "Releasing Alias %s\n", pAlias );
  285. m_pDynamicTexturePacker->RemoveRect( pImageData->m_nNodeIndex );
  286. }
  287. pImageData->Init();
  288. }
  289. }
  290. }
  291. //-----------------------------------------------------------------------------
  292. // Associate this image alias name with a .vtf texture.
  293. // This fxn loads the texture into the GameControls shader and makes a material
  294. // for you
  295. //-----------------------------------------------------------------------------
  296. void CGameUIDynamicTextures::LoadImageAliasTexture( const char *pAlias, const char *pBaseTextureName )
  297. {
  298. if ( !pBaseTextureName || !*pBaseTextureName )
  299. return;
  300. CTextureReference pTexture;
  301. pTexture.Init( pBaseTextureName, TEXTURE_GROUP_OTHER, true );
  302. ImageAliasData_t *pImageData = GetImageAliasData( pAlias );
  303. // Now set up the material for the new imagedata.
  304. if ( pImageData->m_nNodeIndex == -1 )// it won't fit in the map, give it its own material, it is its own draw call.
  305. {
  306. // Material names must be different
  307. CUtlVector<char *> words;
  308. V_SplitString( pImageData->m_szBaseTextureName, "/", words );
  309. CFmtStr materialName;
  310. materialName.sprintf( "dynamictx_%s", words[words.Count()-1] );
  311. KeyValues *pVMTKeyValues = new KeyValues( "GameControls" );
  312. pVMTKeyValues->SetString( "$basetexture", pImageData->m_szBaseTextureName );
  313. CMaterialReference material;
  314. material.Init( materialName, TEXTURE_GROUP_OTHER, pVMTKeyValues );
  315. material->Refresh();
  316. pImageData->m_Material = material;
  317. pImageData->m_bIsInSheet = false;
  318. }
  319. else // Do this if it fit in the packed texture.
  320. {
  321. if ( !m_RenderMaterial )
  322. return;
  323. pImageData->m_Material.Init( GetImageAliasMaterial( "_rt_DynamicUI" ) );
  324. Assert( pImageData->m_Material );
  325. pImageData->m_bIsInSheet = true;
  326. const CTexturePacker::TreeEntry_t &newEntry = m_pDynamicTexturePacker->GetEntry( pImageData->m_nNodeIndex );
  327. Assert( newEntry.rc.width == pImageData->m_Width );
  328. Assert( newEntry.rc.height == pImageData->m_Height );
  329. pImageData->m_XPos = newEntry.rc.x;
  330. pImageData->m_YPos = newEntry.rc.y;
  331. CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
  332. pRenderContext->PushRenderTargetAndViewport( m_TexturePage, NULL, pImageData->m_XPos, pImageData->m_YPos, pImageData->m_Width, pImageData->m_Height );
  333. pRenderContext->MatrixMode( MATERIAL_PROJECTION );
  334. pRenderContext->PushMatrix();
  335. pRenderContext->LoadIdentity();
  336. pRenderContext->Scale( 1, -1, 1 );
  337. float flPixelOffsetX = 0.5f;
  338. float flPixelOffsetY = 0.5f;
  339. pRenderContext->Ortho( flPixelOffsetX, flPixelOffsetY, pImageData->m_Width + flPixelOffsetX, pImageData->m_Height + flPixelOffsetY, -1.0f, 1.0f );
  340. //pRenderContext->Ortho( 0, 0, pImageData->m_Width, pImageData->m_Height, -1.0f, 1.0f );
  341. // Clear to random color. Useful for testing.
  342. //pRenderContext->ClearColor3ub( rand()%256, rand()%256, rand()%256 );
  343. pRenderContext->ClearColor4ub( 0, 0, 0, 255 );
  344. pRenderContext->ClearBuffers( true, false );
  345. // make sure there is no translation and rotation laying around
  346. pRenderContext->MatrixMode( MATERIAL_MODEL );
  347. pRenderContext->PushMatrix();
  348. pRenderContext->LoadIdentity();
  349. pRenderContext->MatrixMode( MATERIAL_VIEW );
  350. pRenderContext->PushMatrix();
  351. pRenderContext->LoadIdentity();
  352. pRenderContext->Bind( m_RenderMaterial, (void *)pImageData->m_szBaseTextureName.Get() );
  353. int x = 0;
  354. int y = 0;
  355. int wide = pImageData->m_Width;
  356. int tall = pImageData->m_Height;
  357. unsigned char drawcolor[4];
  358. drawcolor[0] = 255;
  359. drawcolor[1] = 255;
  360. drawcolor[2] = 255;
  361. drawcolor[3] = 255;
  362. IMesh *pMesh = pRenderContext->GetDynamicMesh( true );
  363. if ( pMesh )
  364. {
  365. CMeshBuilder meshBuilder;
  366. meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
  367. meshBuilder.Position3f( x, y, 0 );
  368. meshBuilder.Color4ubv( drawcolor );
  369. meshBuilder.TexCoord2f( 0, 0, 0 );
  370. meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
  371. meshBuilder.Position3f( wide, y, 0 );
  372. meshBuilder.Color4ubv( drawcolor );
  373. meshBuilder.TexCoord2f( 0, 1, 0 );
  374. meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
  375. meshBuilder.Position3f( wide, tall, 0 );
  376. meshBuilder.Color4ubv( drawcolor );
  377. meshBuilder.TexCoord2f( 0, 1, 1 );
  378. meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
  379. meshBuilder.Position3f( x, tall, 0 );
  380. meshBuilder.Color4ubv( drawcolor );
  381. meshBuilder.TexCoord2f( 0, 0, 1 );
  382. meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
  383. meshBuilder.End();
  384. pMesh->Draw();
  385. }
  386. // Restore the matrices
  387. pRenderContext->MatrixMode( MATERIAL_PROJECTION );
  388. pRenderContext->PopMatrix();
  389. pRenderContext->MatrixMode( MATERIAL_MODEL );
  390. pRenderContext->PopMatrix();
  391. pRenderContext->MatrixMode( MATERIAL_VIEW );
  392. pRenderContext->PopMatrix();
  393. pRenderContext->PopRenderTargetAndViewport();
  394. }
  395. }
  396. //-----------------------------------------------------------------------------
  397. // Return the material bound to this image alias.
  398. // If the texture was not found you will see the purple and black checkerboard
  399. // error texture.
  400. //-----------------------------------------------------------------------------
  401. IMaterial *CGameUIDynamicTextures::GetImageAliasMaterial( const char *pAlias )
  402. {
  403. if ( m_ImageAliasMap.Defined( pAlias ) )
  404. {
  405. return m_ImageAliasMap[pAlias].m_Material;
  406. }
  407. return m_ImageAliasMap[ "errorImageAlias" ].m_Material;
  408. }
  409. //-----------------------------------------------------------------------------
  410. // Return the data bound to this image alias.
  411. // If the alias was not found you will see the purple and black checkerboard
  412. // error texture.
  413. //-----------------------------------------------------------------------------
  414. ImageAliasData_t *CGameUIDynamicTextures::GetImageAliasData( const char *pAlias )
  415. {
  416. if ( m_ImageAliasMap.Defined( pAlias ) )
  417. {
  418. return &m_ImageAliasMap[pAlias];
  419. }
  420. return &m_ImageAliasMap[ "errorImageAlias" ];
  421. }
  422. //-----------------------------------------------------------------------------
  423. // Return true if this data is the error alias
  424. //-----------------------------------------------------------------------------
  425. bool CGameUIDynamicTextures::IsErrorImageAliasData( ImageAliasData_t *pData )
  426. {
  427. return ( &m_ImageAliasMap[ "errorImageAlias" ] ) == pData;
  428. }
  429. //-----------------------------------------------------------------------------
  430. //
  431. //-----------------------------------------------------------------------------
  432. void CGameUIDynamicTextures::GetDynamicSheetSize( int &nWidth, int &nHeight )
  433. {
  434. nWidth = m_TexturePage->GetActualWidth();
  435. nHeight = m_TexturePage->GetActualHeight();
  436. }
  437. //-----------------------------------------------------------------------------
  438. // Draw the dynamic texture associated with this alias at x, y
  439. // It is drawn full size. This fxn is modeled off of CGameUISystemSurface::DrawFontTexture()
  440. //-----------------------------------------------------------------------------
  441. void CGameUIDynamicTextures::DrawDynamicTexture( const char *pAlias, int x, int y )
  442. {
  443. if ( !pAlias || !*pAlias )
  444. return;
  445. ImageAliasData_t *pImageData = GetImageAliasData( pAlias );
  446. int wide = 0;
  447. int tall = 0;
  448. if ( !pImageData->m_bIsInSheet )
  449. {
  450. wide = pImageData->m_Width;
  451. tall = pImageData->m_Height;
  452. }
  453. else
  454. {
  455. GetDynamicSheetSize( wide, tall );
  456. }
  457. color32 drawcolor;
  458. drawcolor.r = 255;
  459. drawcolor.g = 255;
  460. drawcolor.b = 255;
  461. drawcolor.a = 255;
  462. CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
  463. IMesh *pMesh = pRenderContext->GetDynamicMesh( true, NULL, NULL, pImageData->m_Material );
  464. if ( !pMesh )
  465. return;
  466. CMeshBuilder meshBuilder;
  467. meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
  468. meshBuilder.Position3f( x, y, 0 );
  469. meshBuilder.Color4ub( drawcolor.r, drawcolor.g, drawcolor.b, drawcolor.a );
  470. meshBuilder.TexCoord3f( 0, 0, 0, 0 );
  471. meshBuilder.AdvanceVertex();
  472. meshBuilder.Position3f( x + wide, y, 0 );
  473. meshBuilder.Color4ub( drawcolor.r, drawcolor.g, drawcolor.b, drawcolor.a );
  474. meshBuilder.TexCoord3f( 0, 1, 0, 0 );
  475. meshBuilder.AdvanceVertex();
  476. meshBuilder.Position3f( x + wide, y + tall, 0 );
  477. meshBuilder.Color4ub( drawcolor.r, drawcolor.g, drawcolor.b, drawcolor.a );
  478. meshBuilder.TexCoord3f( 0, 1, 1, 0 );
  479. meshBuilder.AdvanceVertex();
  480. meshBuilder.Position3f( x, y + tall, 0 );
  481. meshBuilder.Color4ub( drawcolor.r, drawcolor.g, drawcolor.b, drawcolor.a );
  482. meshBuilder.TexCoord3f( 0, 0, 1, 0 );
  483. meshBuilder.AdvanceVertex();
  484. meshBuilder.End();
  485. pMesh->Draw();
  486. }
  487. //-----------------------------------------------------------------------------
  488. // Reload all textures into the rendertarget.
  489. //-----------------------------------------------------------------------------
  490. void CGameUIDynamicTextures::OnRestore( int nChangeFlags )
  491. {
  492. m_bRegenerate = true;
  493. }
  494. //-----------------------------------------------------------------------------
  495. // Reload all textures into the rendertarget.
  496. //-----------------------------------------------------------------------------
  497. void CGameUIDynamicTextures::RegenerateTexture( int nChangeFlags )
  498. {
  499. if ( !m_bRegenerate )
  500. return;
  501. int numEntries = m_ImageAliasMap.GetNumStrings();
  502. for ( int i = 0; i < numEntries; ++i )
  503. {
  504. const char *pAlias = m_ImageAliasMap.String( i );
  505. ImageAliasData_t *pImageData = GetImageAliasData( pAlias );
  506. if ( IsErrorImageAliasData( pImageData ) )
  507. continue;
  508. if ( Q_strcmp( pAlias, "_rt_DynamicUI") == 0 )
  509. continue;
  510. if ( !pImageData->m_szBaseTextureName || !*pImageData->m_szBaseTextureName )
  511. continue;
  512. ITexture *pTexture = g_pMaterialSystem->FindTexture( pImageData->m_szBaseTextureName.Get(), TEXTURE_GROUP_OTHER, true );
  513. Assert( pTexture );
  514. pTexture->Download();
  515. LoadImageAliasTexture( pAlias, pImageData->m_szBaseTextureName );
  516. }
  517. }