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.

971 lines
26 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // SHOW_TEXTURES.CPP
  4. //
  5. // Show Textures Display.
  6. //=====================================================================================//
  7. #include "vxconsole.h"
  8. #define ID_SHOWTEXTURES_LISTVIEW 100
  9. // column id
  10. #define ID_ST_NAME 0
  11. #define ID_ST_SIZE 1
  12. #define ID_ST_GROUP 2
  13. #define ID_ST_FORMAT 3
  14. #define ID_ST_WIDTH 4
  15. #define ID_ST_HEIGHT 5
  16. #define ID_ST_DEPTH 6
  17. #define ID_ST_NUMLEVELS 7
  18. #define ID_ST_BINDS 8
  19. #define ID_ST_REFCOUNT 9
  20. #define ID_ST_LOAD 10
  21. typedef enum
  22. {
  23. LS_STATIC, // surface
  24. LS_PROCEDURAL, // lacks disk based bits
  25. LS_SYNCHRONOUS, // loaded synchronously
  26. LS_FALLBACK, // fallback version, queued hires
  27. LS_HIRES, // finalized at hires
  28. LS_FAILED, // failed to load
  29. LS_MAX
  30. } loadState_e;
  31. typedef struct
  32. {
  33. int listIndex;
  34. char *pLongName;
  35. char *pShortName;
  36. char *pGroupName;
  37. char *pFormatName;
  38. int size;
  39. char sizeBuff[16];
  40. int width;
  41. char widthBuff[16];
  42. int height;
  43. char heightBuff[16];
  44. int depth;
  45. char depthBuff[16];
  46. int numLevels;
  47. char numLevelsBuff[16];
  48. int binds;
  49. char bindsBuff[16];
  50. int refCount;
  51. char refCountBuff[16];
  52. int loadState;
  53. int edram;
  54. } texture_t;
  55. typedef struct
  56. {
  57. const CHAR* name;
  58. int width;
  59. int subItemIndex;
  60. CHAR nameBuff[32];
  61. } label_t;
  62. HWND g_showTextures_hWnd;
  63. HWND g_showTextures_hWndListView;
  64. RECT g_showTextures_windowRect;
  65. int g_showTextures_sortColumn;
  66. int g_showTextures_sortDescending;
  67. texture_t *g_showTextures_pTextures;
  68. int g_showTextures_numTextures;
  69. int g_showTextures_currentFrame;
  70. int g_showTextures_fullPath;
  71. char g_showTextures_drawTextureName[MAX_PATH];
  72. char *g_showTextures_loadStrings[LS_MAX] =
  73. {
  74. "Static",
  75. "Procedural",
  76. "Synchronous",
  77. "Fallback",
  78. "",
  79. "Failed",
  80. };
  81. label_t g_showTextures_Labels[] =
  82. {
  83. {"Name", 150, ID_ST_NAME},
  84. {"D3D Size", 80, ID_ST_SIZE},
  85. {"Group", 150, ID_ST_GROUP},
  86. {"Format", 120, ID_ST_FORMAT},
  87. {"Width", 80, ID_ST_WIDTH},
  88. {"Height", 80, ID_ST_HEIGHT},
  89. {"Depth", 80, ID_ST_DEPTH},
  90. {"NumLevels", 80, ID_ST_NUMLEVELS},
  91. {"Binds", 80, ID_ST_BINDS},
  92. {"RefCount", 80, ID_ST_REFCOUNT},
  93. {"Load State", 120, ID_ST_LOAD},
  94. };
  95. //-----------------------------------------------------------------------------
  96. // ShowTextures_SaveConfig
  97. //
  98. //-----------------------------------------------------------------------------
  99. void ShowTextures_SaveConfig()
  100. {
  101. char buff[256];
  102. Sys_SetRegistryInteger( "showTexturesFullPath", g_showTextures_fullPath );
  103. Sys_SetRegistryInteger( "showTexturesCurrentFrame", g_showTextures_currentFrame );
  104. Sys_SetRegistryInteger( "showTexturesSortColumn", g_showTextures_sortColumn );
  105. Sys_SetRegistryInteger( "showTexturesSortDescending", g_showTextures_sortDescending );
  106. WINDOWPLACEMENT wp;
  107. memset( &wp, 0, sizeof( wp ) );
  108. wp.length = sizeof( WINDOWPLACEMENT );
  109. GetWindowPlacement( g_showTextures_hWnd, &wp );
  110. g_showTextures_windowRect = wp.rcNormalPosition;
  111. sprintf( buff, "%d %d %d %d", g_showTextures_windowRect.left, g_showTextures_windowRect.top, g_showTextures_windowRect.right, g_showTextures_windowRect.bottom );
  112. Sys_SetRegistryString( "showTexturesWindowRect", buff );
  113. }
  114. //-----------------------------------------------------------------------------
  115. // ShowTextures_LoadConfig
  116. //
  117. //-----------------------------------------------------------------------------
  118. void ShowTextures_LoadConfig()
  119. {
  120. int numArgs;
  121. char buff[256];
  122. Sys_GetRegistryInteger( "showTexturesFullPath", true, g_showTextures_fullPath );
  123. Sys_GetRegistryInteger( "showTexturesCurrentFrame", false, g_showTextures_currentFrame );
  124. Sys_GetRegistryInteger( "showTexturesSortColumn", ID_ST_NAME, g_showTextures_sortColumn );
  125. Sys_GetRegistryInteger( "showTexturesSortDescending", false, g_showTextures_sortDescending );
  126. Sys_GetRegistryString( "showTexturesWindowRect", buff, "", sizeof( buff ) );
  127. numArgs = sscanf( buff, "%d %d %d %d", &g_showTextures_windowRect.left, &g_showTextures_windowRect.top, &g_showTextures_windowRect.right, &g_showTextures_windowRect.bottom );
  128. if ( numArgs != 4 || g_showTextures_windowRect.left < 0 || g_showTextures_windowRect.top < 0 || g_showTextures_windowRect.right < 0 || g_showTextures_windowRect.bottom < 0 )
  129. {
  130. memset( &g_showTextures_windowRect, 0, sizeof( g_showTextures_windowRect ) );
  131. }
  132. }
  133. //-----------------------------------------------------------------------------
  134. // ShowTextures_Clear
  135. //
  136. //-----------------------------------------------------------------------------
  137. void ShowTextures_Clear()
  138. {
  139. // delete all the list view entries
  140. if ( g_showTextures_hWnd )
  141. {
  142. ListView_DeleteAllItems( g_showTextures_hWndListView );
  143. }
  144. if ( !g_showTextures_pTextures )
  145. {
  146. return;
  147. }
  148. for ( int i=0; i<g_showTextures_numTextures; i++ )
  149. {
  150. free( g_showTextures_pTextures[i].pLongName );
  151. free( g_showTextures_pTextures[i].pShortName );
  152. free( g_showTextures_pTextures[i].pGroupName );
  153. free( g_showTextures_pTextures[i].pFormatName );
  154. }
  155. g_showTextures_pTextures = NULL;
  156. g_showTextures_numTextures = 0;
  157. }
  158. //-----------------------------------------------------------------------------
  159. // ShowTextures_Export
  160. //
  161. //-----------------------------------------------------------------------------
  162. void ShowTextures_Export()
  163. {
  164. OPENFILENAME ofn;
  165. char logFilename[MAX_PATH];
  166. int retval;
  167. FILE* fp;
  168. int i;
  169. int count;
  170. memset( &ofn, 0, sizeof( ofn ) );
  171. ofn.lStructSize = sizeof( ofn );
  172. ofn.hwndOwner = g_showTextures_hWnd;
  173. ofn.lpstrFile = logFilename;
  174. ofn.lpstrFile[0] = '\0';
  175. ofn.nMaxFile = sizeof( logFilename );
  176. ofn.lpstrFilter = "Excel CSV\0*.CSV\0All Files\0*.*\0";
  177. ofn.nFilterIndex = 1;
  178. ofn.lpstrFileTitle = NULL;
  179. ofn.nMaxFileTitle = 0;
  180. ofn.lpstrInitialDir = "c:\\";
  181. ofn.Flags = OFN_PATHMUSTEXIST;
  182. // display the Open dialog box.
  183. retval = GetOpenFileName( &ofn );
  184. if ( !retval )
  185. {
  186. return;
  187. }
  188. Sys_AddExtension( ".csv", logFilename, sizeof( logFilename ) );
  189. fp = fopen( logFilename, "wt+" );
  190. if ( !fp )
  191. {
  192. return;
  193. }
  194. // labels
  195. count = sizeof( g_showTextures_Labels )/sizeof( g_showTextures_Labels[0] );
  196. for ( i=0; i<count; i++ )
  197. {
  198. fprintf( fp, "\"%s\"", g_showTextures_Labels[i].name );
  199. if ( i != count-1 )
  200. {
  201. fprintf( fp, "," );
  202. }
  203. }
  204. fprintf( fp, "\n" );
  205. // dump to the log
  206. for ( i=0; i<g_showTextures_numTextures; i++ )
  207. {
  208. if ( g_showTextures_fullPath )
  209. {
  210. fprintf( fp, "\"%s\"", g_showTextures_pTextures[i].pLongName );
  211. }
  212. else
  213. {
  214. fprintf( fp, "\"%s\"", g_showTextures_pTextures[i].pShortName );
  215. }
  216. fprintf( fp, ",\"%s\"", g_showTextures_pTextures[i].sizeBuff );
  217. fprintf( fp, ",\"%s\"", g_showTextures_pTextures[i].pGroupName );
  218. fprintf( fp, ",\"%s\"", g_showTextures_pTextures[i].pFormatName );
  219. fprintf( fp, ",\"%s\"", g_showTextures_pTextures[i].widthBuff );
  220. fprintf( fp, ",\"%s\"", g_showTextures_pTextures[i].heightBuff );
  221. fprintf( fp, ",\"%s\"", g_showTextures_pTextures[i].depthBuff );
  222. fprintf( fp, ",\"%s\"", g_showTextures_pTextures[i].numLevelsBuff );
  223. fprintf( fp, ",\"%s\"", g_showTextures_pTextures[i].bindsBuff );
  224. fprintf( fp, ",\"%s\"", g_showTextures_pTextures[i].refCountBuff );
  225. fprintf( fp, ",\"%s\"", g_showTextures_loadStrings[g_showTextures_pTextures[i].loadState] );
  226. fprintf( fp, "\n" );
  227. }
  228. fclose( fp );
  229. }
  230. //-----------------------------------------------------------------------------
  231. // ShowTextures_Summary
  232. //
  233. //-----------------------------------------------------------------------------
  234. void ShowTextures_Summary()
  235. {
  236. char buff[1024];
  237. // tally the totals
  238. int total = 0;
  239. for ( int i=0; i<g_showTextures_numTextures; i++ )
  240. {
  241. if ( g_showTextures_pTextures[i].edram )
  242. {
  243. // edram is does not affect system memory total
  244. continue;
  245. }
  246. total += g_showTextures_pTextures[i].size;
  247. }
  248. sprintf(
  249. buff,
  250. "Entries:\t\t\t%d\n"
  251. "System D3D Memory:\t%.2f MB\n",
  252. g_showTextures_numTextures,
  253. ( float )total/( 1024.0F*1024.0F ) );
  254. MessageBox( g_showTextures_hWnd, buff, "Texture Summary", MB_OK|MB_APPLMODAL );
  255. }
  256. //-----------------------------------------------------------------------------
  257. // ShowTextures_DrawTexture
  258. //
  259. //-----------------------------------------------------------------------------
  260. void ShowTextures_DrawTexture()
  261. {
  262. char command[256];
  263. texture_t* pTexture;
  264. int selection;
  265. LVITEM lvitem;
  266. if ( !g_connectedToApp )
  267. return;
  268. selection = ListView_GetSelectionMark( g_showTextures_hWndListView );
  269. if ( selection == -1 )
  270. return;
  271. memset( &lvitem, 0, sizeof( lvitem ) );
  272. lvitem.mask = LVIF_PARAM;
  273. lvitem.iItem = selection;
  274. ListView_GetItem( g_showTextures_hWndListView, &lvitem );
  275. pTexture = ( texture_t* )lvitem.lParam;
  276. if ( !V_stricmp( g_showTextures_drawTextureName, pTexture->pLongName ) )
  277. {
  278. // hide
  279. sprintf( command, "mat_drawTexture \"\"" );
  280. g_showTextures_drawTextureName[0] = '\0';
  281. }
  282. else
  283. {
  284. // show
  285. sprintf( command, "mat_drawTexture %s", pTexture->pLongName );
  286. V_strncpy( g_showTextures_drawTextureName, pTexture->pLongName, sizeof( g_showTextures_drawTextureName ) );
  287. }
  288. // send the command to application
  289. ProcessCommand( command );
  290. }
  291. //-----------------------------------------------------------------------------
  292. // ShowTextures_SetTitle
  293. //
  294. //-----------------------------------------------------------------------------
  295. void ShowTextures_SetTitle()
  296. {
  297. char titleBuff[128];
  298. if ( g_showTextures_hWnd )
  299. {
  300. strcpy( titleBuff, "Textures " );
  301. if ( g_showTextures_currentFrame )
  302. {
  303. strcat( titleBuff, " [FRAME]" );
  304. }
  305. if ( g_showTextures_fullPath )
  306. {
  307. strcat( titleBuff, " [FULL PATH]" );
  308. }
  309. SetWindowText( g_showTextures_hWnd, titleBuff );
  310. }
  311. }
  312. //-----------------------------------------------------------------------------
  313. // ShowTextures_CompareFunc
  314. //
  315. //-----------------------------------------------------------------------------
  316. int CALLBACK ShowTextures_CompareFunc( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort )
  317. {
  318. texture_t* pTextureA = ( texture_t* )lParam1;
  319. texture_t* pTextureB = ( texture_t* )lParam2;
  320. int sort = 0;
  321. switch ( g_showTextures_sortColumn )
  322. {
  323. case ID_ST_NAME:
  324. if ( g_showTextures_fullPath )
  325. {
  326. sort = stricmp( pTextureA->pLongName, pTextureB->pLongName );
  327. }
  328. else
  329. {
  330. sort = stricmp( pTextureA->pShortName, pTextureB->pShortName );
  331. }
  332. break;
  333. case ID_ST_GROUP:
  334. sort = stricmp( pTextureA->pGroupName, pTextureB->pGroupName );
  335. break;
  336. case ID_ST_FORMAT:
  337. sort = stricmp( pTextureA->pFormatName, pTextureB->pFormatName );
  338. break;
  339. case ID_ST_SIZE:
  340. sort = pTextureA->size - pTextureB->size;
  341. break;
  342. case ID_ST_WIDTH:
  343. sort = pTextureA->width - pTextureB->width;
  344. break;
  345. case ID_ST_HEIGHT:
  346. sort = pTextureA->height - pTextureB->height;
  347. break;
  348. case ID_ST_DEPTH:
  349. sort = pTextureA->depth - pTextureB->depth;
  350. break;
  351. case ID_ST_NUMLEVELS:
  352. sort = pTextureA->numLevels - pTextureB->numLevels;
  353. break;
  354. case ID_ST_BINDS:
  355. sort = pTextureA->binds - pTextureB->binds;
  356. break;
  357. case ID_ST_REFCOUNT:
  358. sort = pTextureA->refCount - pTextureB->refCount;
  359. break;
  360. case ID_ST_LOAD:
  361. sort = stricmp( g_showTextures_loadStrings[pTextureA->loadState], g_showTextures_loadStrings[pTextureB->loadState] );
  362. break;
  363. }
  364. // flip the sort order
  365. if ( g_showTextures_sortDescending )
  366. {
  367. sort *= -1;
  368. }
  369. return ( sort );
  370. }
  371. //-----------------------------------------------------------------------------
  372. // ShowTextures_SortItems
  373. //
  374. //-----------------------------------------------------------------------------
  375. void ShowTextures_SortItems()
  376. {
  377. LVITEM lvitem;
  378. texture_t *pTexture;
  379. int i;
  380. if ( !g_showTextures_hWnd )
  381. {
  382. // only sort if window is visible
  383. return;
  384. }
  385. ListView_SortItems( g_showTextures_hWndListView, ShowTextures_CompareFunc, 0 );
  386. memset( &lvitem, 0, sizeof( lvitem ) );
  387. lvitem.mask = LVIF_PARAM;
  388. // get each item and reset its list index
  389. int itemCount = ListView_GetItemCount( g_showTextures_hWndListView );
  390. for ( i=0; i<itemCount; i++ )
  391. {
  392. lvitem.iItem = i;
  393. ListView_GetItem( g_showTextures_hWndListView, &lvitem );
  394. pTexture = ( texture_t* )lvitem.lParam;
  395. pTexture->listIndex = i;
  396. }
  397. // update list view columns with sort key
  398. for ( i=0; i<sizeof( g_showTextures_Labels )/sizeof( g_showTextures_Labels[0] ); i++ )
  399. {
  400. char symbol;
  401. LVCOLUMN lvc;
  402. if ( i == g_showTextures_sortColumn )
  403. {
  404. symbol = g_showTextures_sortDescending ? '<' : '>';
  405. }
  406. else
  407. {
  408. symbol = ' ';
  409. }
  410. sprintf( g_showTextures_Labels[i].nameBuff, "%s %c", g_showTextures_Labels[i].name, symbol );
  411. memset( &lvc, 0, sizeof( lvc ) );
  412. lvc.mask = LVCF_TEXT;
  413. lvc.pszText = ( LPSTR )g_showTextures_Labels[i].nameBuff;
  414. ListView_SetColumn( g_showTextures_hWndListView, i, &lvc );
  415. }
  416. }
  417. //-----------------------------------------------------------------------------
  418. // ShowTextures_AddViewItem
  419. //
  420. //-----------------------------------------------------------------------------
  421. void ShowTextures_AddViewItem( texture_t* pTexture )
  422. {
  423. LVITEM lvi;
  424. if ( !g_showTextures_hWnd )
  425. {
  426. // only valid if log window is visible
  427. return;
  428. }
  429. // update the text callback buffers
  430. sprintf( pTexture->sizeBuff, "%d", pTexture->size );
  431. sprintf( pTexture->widthBuff, "%d", pTexture->width );
  432. sprintf( pTexture->heightBuff, "%d", pTexture->height );
  433. sprintf( pTexture->depthBuff, "%d", pTexture->depth );
  434. sprintf( pTexture->numLevelsBuff, "%d", pTexture->numLevels );
  435. sprintf( pTexture->bindsBuff, "%d", pTexture->binds );
  436. sprintf( pTexture->refCountBuff, "%d", pTexture->refCount );
  437. int itemCount = ListView_GetItemCount( g_showTextures_hWndListView );
  438. // setup and insert at end of list
  439. memset( &lvi, 0, sizeof( lvi ) );
  440. lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
  441. lvi.iItem = itemCount;
  442. lvi.iSubItem = 0;
  443. lvi.state = 0;
  444. lvi.stateMask = 0;
  445. lvi.pszText = LPSTR_TEXTCALLBACK;
  446. lvi.lParam = ( LPARAM )pTexture;
  447. // insert and set the real index
  448. pTexture->listIndex = ListView_InsertItem( g_showTextures_hWndListView, &lvi );
  449. }
  450. //-----------------------------------------------------------------------------
  451. // ShowTextures_Refresh
  452. //
  453. //-----------------------------------------------------------------------------
  454. void ShowTextures_Refresh()
  455. {
  456. char command[256];
  457. strcpy( command, "mat_get_textures" );
  458. if ( !g_showTextures_currentFrame )
  459. {
  460. strcat( command, " all" );
  461. }
  462. // send the command to application which replies with list data
  463. if ( g_connectedToApp )
  464. {
  465. ProcessCommand( command );
  466. }
  467. }
  468. //-----------------------------------------------------------------------------
  469. // ShowTextures_SizeWindow
  470. //
  471. //-----------------------------------------------------------------------------
  472. void ShowTextures_SizeWindow( HWND hwnd, int cx, int cy )
  473. {
  474. if ( cx==0 || cy==0 )
  475. {
  476. RECT rcClient;
  477. GetClientRect( hwnd, &rcClient );
  478. cx = rcClient.right;
  479. cy = rcClient.bottom;
  480. }
  481. // position the ListView
  482. SetWindowPos( g_showTextures_hWndListView, NULL, 0, 0, cx, cy, SWP_NOZORDER );
  483. }
  484. //-----------------------------------------------------------------------------
  485. // ShowTextures_WndProc
  486. //
  487. //-----------------------------------------------------------------------------
  488. LRESULT CALLBACK ShowTextures_WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
  489. {
  490. WORD wID = LOWORD( wParam );
  491. texture_t* pTexture;
  492. switch ( message )
  493. {
  494. case WM_CREATE:
  495. return 0L;
  496. case WM_DESTROY:
  497. ShowTextures_SaveConfig();
  498. g_showTextures_hWnd = NULL;
  499. return 0L;
  500. case WM_INITMENU:
  501. CheckMenuItem( ( HMENU )wParam, IDM_OPTIONS_CURRENTFRAME, MF_BYCOMMAND | ( g_showTextures_currentFrame ? MF_CHECKED : MF_UNCHECKED ) );
  502. CheckMenuItem( ( HMENU )wParam, IDM_OPTIONS_FULLPATH, MF_BYCOMMAND | ( g_showTextures_fullPath ? MF_CHECKED : MF_UNCHECKED ) );
  503. return 0L;
  504. case WM_SIZE:
  505. ShowTextures_SizeWindow( hwnd, LOWORD( lParam ), HIWORD( lParam ) );
  506. return 0L;
  507. case WM_NOTIFY:
  508. switch ( ( ( LPNMHDR )lParam )->code )
  509. {
  510. case LVN_COLUMNCLICK:
  511. NMLISTVIEW* pnmlv;
  512. pnmlv = ( NMLISTVIEW* )lParam;
  513. if ( g_showTextures_sortColumn == pnmlv->iSubItem )
  514. {
  515. // user has clicked on same column - flip the sort
  516. g_showTextures_sortDescending ^= 1;
  517. }
  518. else
  519. {
  520. // sort by new column
  521. g_showTextures_sortColumn = pnmlv->iSubItem;
  522. }
  523. ShowTextures_SortItems();
  524. return 0L;
  525. case LVN_GETDISPINFO:
  526. NMLVDISPINFO* plvdi;
  527. plvdi = ( NMLVDISPINFO* )lParam;
  528. pTexture = ( texture_t* )plvdi->item.lParam;
  529. switch ( plvdi->item.iSubItem )
  530. {
  531. case ID_ST_NAME:
  532. if ( g_showTextures_fullPath )
  533. plvdi->item.pszText = pTexture->pLongName;
  534. else
  535. plvdi->item.pszText = pTexture->pShortName;
  536. return 0L;
  537. case ID_ST_GROUP:
  538. plvdi->item.pszText = pTexture->pGroupName;
  539. return 0L;
  540. case ID_ST_FORMAT:
  541. plvdi->item.pszText = pTexture->pFormatName;
  542. return 0L;
  543. case ID_ST_SIZE:
  544. plvdi->item.pszText = pTexture->sizeBuff;
  545. return 0L;
  546. case ID_ST_WIDTH:
  547. plvdi->item.pszText = pTexture->widthBuff;
  548. return 0L;
  549. case ID_ST_HEIGHT:
  550. plvdi->item.pszText = pTexture->heightBuff;
  551. return 0L;
  552. case ID_ST_DEPTH:
  553. plvdi->item.pszText = pTexture->depthBuff;
  554. return 0L;
  555. case ID_ST_NUMLEVELS:
  556. plvdi->item.pszText = pTexture->numLevelsBuff;
  557. return 0L;
  558. case ID_ST_BINDS:
  559. plvdi->item.pszText = pTexture->bindsBuff;
  560. return 0L;
  561. case ID_ST_LOAD:
  562. plvdi->item.pszText = g_showTextures_loadStrings[pTexture->loadState];
  563. return 0L;
  564. case ID_ST_REFCOUNT:
  565. plvdi->item.pszText = pTexture->refCountBuff;
  566. return 0L;
  567. default:
  568. break;
  569. }
  570. break;
  571. }
  572. break;
  573. case WM_COMMAND:
  574. switch ( wID )
  575. {
  576. case IDM_OPTIONS_SUMMARY:
  577. ShowTextures_Summary();
  578. return 0L;
  579. case IDM_OPTIONS_REFRESH:
  580. ShowTextures_Refresh();
  581. return 0L;
  582. case IDM_OPTIONS_EXPORT:
  583. ShowTextures_Export();
  584. return 0L;
  585. case IDM_OPTIONS_CURRENTFRAME:
  586. g_showTextures_currentFrame ^= 1;
  587. ShowTextures_SetTitle();
  588. ShowTextures_Refresh();
  589. return 0L;
  590. case IDM_OPTIONS_FULLPATH:
  591. g_showTextures_fullPath ^= 1;
  592. ShowTextures_SetTitle();
  593. ShowTextures_SortItems();
  594. return 0L;
  595. case IDM_OPTIONS_DRAWTEXTURE:
  596. ShowTextures_DrawTexture();
  597. return 0L;
  598. }
  599. break;
  600. }
  601. return ( DefWindowProc( hwnd, message, wParam, lParam ) );
  602. }
  603. //-----------------------------------------------------------------------------
  604. // ShowTextures_Init
  605. //
  606. //-----------------------------------------------------------------------------
  607. bool ShowTextures_Init()
  608. {
  609. // set up our window class
  610. WNDCLASS wndclass;
  611. memset( &wndclass, 0, sizeof( wndclass ) );
  612. wndclass.style = 0;
  613. wndclass.lpfnWndProc = ShowTextures_WndProc;
  614. wndclass.cbClsExtra = 0;
  615. wndclass.cbWndExtra = 0;
  616. wndclass.hInstance = g_hInstance;
  617. wndclass.hIcon = g_hIcons[ICON_APPLICATION];
  618. wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
  619. wndclass.hbrBackground = g_hBackgroundBrush;
  620. wndclass.lpszMenuName = MAKEINTRESOURCE( MENU_SHOWTEXTURES );
  621. wndclass.lpszClassName = "SHOWTEXTURESCLASS";
  622. if ( !RegisterClass( &wndclass ) )
  623. return false;
  624. ShowTextures_LoadConfig();
  625. return true;
  626. }
  627. //-----------------------------------------------------------------------------
  628. // ShowTextures_Open
  629. //
  630. //-----------------------------------------------------------------------------
  631. void ShowTextures_Open()
  632. {
  633. RECT clientRect;
  634. HWND hWnd;
  635. int i;
  636. if ( g_showTextures_hWnd )
  637. {
  638. // only one instance
  639. if ( IsIconic( g_showTextures_hWnd ) )
  640. {
  641. ShowWindow( g_showTextures_hWnd, SW_RESTORE );
  642. }
  643. SetForegroundWindow( g_showTextures_hWnd );
  644. return;
  645. }
  646. hWnd = CreateWindowEx(
  647. WS_EX_CLIENTEDGE,
  648. "SHOWTEXTURESCLASS",
  649. "",
  650. WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_SIZEBOX|WS_MINIMIZEBOX|WS_MAXIMIZEBOX,
  651. 0,
  652. 0,
  653. 700,
  654. 400,
  655. g_hDlgMain,
  656. NULL,
  657. g_hInstance,
  658. NULL );
  659. g_showTextures_hWnd = hWnd;
  660. GetClientRect( g_showTextures_hWnd, &clientRect );
  661. hWnd = CreateWindow(
  662. WC_LISTVIEW,
  663. "",
  664. WS_VISIBLE|WS_CHILD|LVS_REPORT,
  665. 0,
  666. 0,
  667. clientRect.right-clientRect.left,
  668. clientRect.bottom-clientRect.top,
  669. g_showTextures_hWnd,
  670. ( HMENU )ID_SHOWTEXTURES_LISTVIEW,
  671. g_hInstance,
  672. NULL );
  673. g_showTextures_hWndListView = hWnd;
  674. // init list view columns
  675. for ( i=0; i<sizeof( g_showTextures_Labels )/sizeof( g_showTextures_Labels[0] ); i++ )
  676. {
  677. LVCOLUMN lvc;
  678. memset( &lvc, 0, sizeof( lvc ) );
  679. lvc.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
  680. lvc.iSubItem = 0;
  681. lvc.cx = g_showTextures_Labels[i].width;
  682. lvc.fmt = LVCFMT_LEFT;
  683. lvc.pszText = ( LPSTR )g_showTextures_Labels[i].name;
  684. ListView_InsertColumn( g_showTextures_hWndListView, i, &lvc );
  685. }
  686. ListView_SetBkColor( g_showTextures_hWndListView, g_backgroundColor );
  687. ListView_SetTextBkColor( g_showTextures_hWndListView, g_backgroundColor );
  688. DWORD style = LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP;
  689. ListView_SetExtendedListViewStyleEx( g_showTextures_hWndListView, style, style );
  690. // populate list view
  691. for ( i=0; i<g_showTextures_numTextures; i++ )
  692. {
  693. ShowTextures_AddViewItem( &g_showTextures_pTextures[i] );
  694. }
  695. ShowTextures_SortItems();
  696. ShowTextures_SetTitle();
  697. if ( g_showTextures_windowRect.right && g_showTextures_windowRect.bottom )
  698. {
  699. MoveWindow( g_showTextures_hWnd, g_showTextures_windowRect.left, g_showTextures_windowRect.top, g_showTextures_windowRect.right-g_showTextures_windowRect.left, g_showTextures_windowRect.bottom-g_showTextures_windowRect.top, FALSE );
  700. }
  701. ShowWindow( g_showTextures_hWnd, SHOW_OPENWINDOW );
  702. // get data from application
  703. ShowTextures_Refresh();
  704. }
  705. //-----------------------------------------------------------------------------
  706. // rc_TextureList
  707. //
  708. // Sent from application with texture list
  709. //-----------------------------------------------------------------------------
  710. int rc_TextureList( char* commandPtr )
  711. {
  712. int errCode = -1;
  713. char* cmdToken;
  714. int numTextures;
  715. int textureList;
  716. int retAddr;
  717. int retVal;
  718. xrTexture_t* pLocalList;
  719. // remove old entries
  720. ShowTextures_Clear();
  721. // get number of textures
  722. cmdToken = GetToken( &commandPtr );
  723. if ( !cmdToken[0] )
  724. goto cleanUp;
  725. sscanf( cmdToken, "%x", &numTextures );
  726. // get texture list
  727. cmdToken = GetToken( &commandPtr );
  728. if ( !cmdToken[0] )
  729. goto cleanUp;
  730. sscanf( cmdToken, "%x", &textureList );
  731. // get retAddr
  732. cmdToken = GetToken( &commandPtr );
  733. if ( !cmdToken[0] )
  734. goto cleanUp;
  735. sscanf( cmdToken, "%x", &retAddr );
  736. pLocalList = new xrTexture_t[numTextures];
  737. memset( pLocalList, 0, numTextures*sizeof( xrTexture_t ) );
  738. g_showTextures_numTextures = numTextures;
  739. g_showTextures_pTextures = new texture_t[numTextures];
  740. memset( g_showTextures_pTextures, 0, numTextures*sizeof( texture_t ) );
  741. // get the caller's command list
  742. DmGetMemory( ( void* )textureList, numTextures*sizeof( xrTexture_t ), pLocalList, NULL );
  743. // build out the resident list
  744. for ( int i=0; i<numTextures; i++ )
  745. {
  746. // swap the structure
  747. pLocalList[i].size = BigDWord( pLocalList[i].size );
  748. pLocalList[i].width = BigDWord( pLocalList[i].width );
  749. pLocalList[i].height = BigDWord( pLocalList[i].height );
  750. pLocalList[i].depth = BigDWord( pLocalList[i].depth );
  751. pLocalList[i].numLevels = BigDWord( pLocalList[i].numLevels );
  752. pLocalList[i].binds = BigDWord( pLocalList[i].binds );
  753. pLocalList[i].refCount = BigDWord( pLocalList[i].refCount );
  754. pLocalList[i].sRGB = BigDWord( pLocalList[i].sRGB );
  755. pLocalList[i].edram = BigDWord( pLocalList[i].edram );
  756. pLocalList[i].procedural = BigDWord( pLocalList[i].procedural );
  757. pLocalList[i].fallback = BigDWord( pLocalList[i].fallback );
  758. pLocalList[i].final = BigDWord( pLocalList[i].final );
  759. pLocalList[i].failed = BigDWord( pLocalList[i].failed );
  760. // get the name
  761. g_showTextures_pTextures[i].pLongName = strdup( pLocalList[i].nameString );
  762. CHAR shortName[MAX_PATH];
  763. Sys_StripPath( g_showTextures_pTextures[i].pLongName, shortName, sizeof( shortName ) );
  764. g_showTextures_pTextures[i].pShortName = strdup( shortName );
  765. // get the group name
  766. g_showTextures_pTextures[i].pGroupName = strdup( pLocalList[i].groupString );
  767. // get the format name
  768. const char *pFormatName = pLocalList[i].formatString;
  769. if ( !strnicmp( pFormatName, "D3DFMT_", 7 ) )
  770. {
  771. // strip D3DFMT_
  772. pFormatName += 7;
  773. }
  774. char tempName[MAX_PATH];
  775. if ( pLocalList[i].sRGB )
  776. {
  777. strcpy( tempName, pFormatName );
  778. strcat( tempName, " (SRGB)" );
  779. pFormatName = tempName;
  780. }
  781. g_showTextures_pTextures[i].pFormatName = strdup( pFormatName );
  782. g_showTextures_pTextures[i].size = pLocalList[i].size;
  783. g_showTextures_pTextures[i].width = pLocalList[i].width;
  784. g_showTextures_pTextures[i].height = pLocalList[i].height;
  785. g_showTextures_pTextures[i].depth = pLocalList[i].depth;
  786. g_showTextures_pTextures[i].numLevels = pLocalList[i].numLevels;
  787. g_showTextures_pTextures[i].binds = pLocalList[i].binds;
  788. g_showTextures_pTextures[i].refCount = pLocalList[i].refCount;
  789. g_showTextures_pTextures[i].edram = pLocalList[i].edram;
  790. loadState_e loadState;
  791. if ( pLocalList[i].edram || V_stristr( g_showTextures_pTextures[i].pGroupName, "RenderTarget" ) )
  792. {
  793. loadState = LS_STATIC;
  794. }
  795. else if ( pLocalList[i].procedural )
  796. {
  797. loadState = LS_PROCEDURAL;
  798. }
  799. else if ( pLocalList[i].final )
  800. {
  801. loadState = LS_HIRES;
  802. }
  803. else if ( pLocalList[i].failed )
  804. {
  805. loadState = LS_FAILED;
  806. }
  807. else if ( pLocalList[i].fallback )
  808. {
  809. loadState = LS_FALLBACK;
  810. }
  811. else
  812. {
  813. loadState = LS_SYNCHRONOUS;
  814. }
  815. g_showTextures_pTextures[i].loadState = loadState;
  816. // add to list view
  817. ShowTextures_AddViewItem( &g_showTextures_pTextures[i] );
  818. }
  819. // return the result
  820. retVal = numTextures;
  821. int xboxRetVal = BigDWord( retVal );
  822. DmSetMemory( ( void* )retAddr, sizeof( int ), &xboxRetVal, NULL );
  823. DebugCommand( "0x%8.8x = TextureList( 0x%8.8x, 0x%8.8x )\n", retVal, numTextures, textureList );
  824. delete [] pLocalList;
  825. // update
  826. ShowTextures_SortItems();
  827. // success
  828. errCode = 0;
  829. cleanUp:
  830. return errCode;
  831. }