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.

778 lines
22 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #include <d3d10.h>
  9. #undef GetCommandLine
  10. #include "meshdx10.h"
  11. #include "utlvector.h"
  12. #include "materialsystem/imaterialsystem.h"
  13. #include "IHardwareConfigInternal.h"
  14. #include "shaderapi_global.h"
  15. #include "shaderapi/ishaderutil.h"
  16. #include "shaderapi/ishaderapi.h"
  17. #include "shaderdevicedx10.h"
  18. #include "materialsystem/imesh.h"
  19. #include "tier0/vprof.h"
  20. #include "tier0/dbg.h"
  21. #include "materialsystem/idebugtextureinfo.h"
  22. #include "materialsystem/ivballoctracker.h"
  23. #include "tier2/tier2.h"
  24. // NOTE: This has to be the last file included!
  25. #include "tier0/memdbgon.h"
  26. //-----------------------------------------------------------------------------
  27. //
  28. // Dx10 implementation of a vertex buffer
  29. //
  30. //-----------------------------------------------------------------------------
  31. //-----------------------------------------------------------------------------
  32. // globals
  33. //-----------------------------------------------------------------------------
  34. #ifdef _DEBUG
  35. int CVertexBufferDx10::s_nBufferCount = 0;
  36. #endif
  37. //-----------------------------------------------------------------------------
  38. // constructor, destructor
  39. //-----------------------------------------------------------------------------
  40. CVertexBufferDx10::CVertexBufferDx10( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroupName ) :
  41. BaseClass( pBudgetGroupName )
  42. {
  43. Assert( nVertexCount != 0 );
  44. m_pVertexBuffer = NULL;
  45. m_VertexFormat = fmt;
  46. m_nVertexCount = ( fmt == VERTEX_FORMAT_UNKNOWN ) ? 0 : nVertexCount;
  47. m_nBufferSize = ( fmt == VERTEX_FORMAT_UNKNOWN ) ? nVertexCount : nVertexCount * VertexSize();
  48. m_nFirstUnwrittenOffset = 0;
  49. m_bIsLocked = false;
  50. m_bIsDynamic = ( type == SHADER_BUFFER_TYPE_DYNAMIC ) || ( type == SHADER_BUFFER_TYPE_DYNAMIC_TEMP );
  51. m_bFlush = false;
  52. }
  53. CVertexBufferDx10::~CVertexBufferDx10()
  54. {
  55. Free();
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Creates, destroys the vertex buffer
  59. //-----------------------------------------------------------------------------
  60. bool CVertexBufferDx10::Allocate( )
  61. {
  62. Assert( !m_pVertexBuffer );
  63. m_nFirstUnwrittenOffset = 0;
  64. D3D10_BUFFER_DESC bd;
  65. bd.Usage = D3D10_USAGE_DYNAMIC;
  66. bd.ByteWidth = m_nBufferSize;
  67. bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
  68. bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
  69. bd.MiscFlags = 0;
  70. HRESULT hr = D3D10Device()->CreateBuffer( &bd, NULL, &m_pVertexBuffer );
  71. bool bOk = !FAILED( hr ) && ( m_pVertexBuffer != 0 );
  72. if ( bOk )
  73. {
  74. // Track VB allocations
  75. g_VBAllocTracker->CountVB( m_pVertexBuffer, m_bIsDynamic, m_nBufferSize, VertexSize(), GetVertexFormat() );
  76. if ( !m_bIsDynamic )
  77. {
  78. VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER,
  79. COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize );
  80. }
  81. else
  82. {
  83. VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER,
  84. COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize );
  85. // Dynamic meshes should never be compressed (slows down writing to them)
  86. Assert( CompressionType( GetVertexFormat() ) == VERTEX_COMPRESSION_NONE );
  87. }
  88. #ifdef _DEBUG
  89. ++s_nBufferCount;
  90. #endif
  91. }
  92. return bOk;
  93. }
  94. void CVertexBufferDx10::Free()
  95. {
  96. if ( m_pVertexBuffer )
  97. {
  98. #ifdef _DEBUG
  99. --s_nBufferCount;
  100. #endif
  101. // Track VB allocations
  102. g_VBAllocTracker->UnCountVB( m_pVertexBuffer );
  103. m_pVertexBuffer->Release();
  104. m_pVertexBuffer = NULL;
  105. if ( !m_bIsDynamic )
  106. {
  107. VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER,
  108. COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize );
  109. }
  110. else
  111. {
  112. VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER,
  113. COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize );
  114. }
  115. }
  116. }
  117. //-----------------------------------------------------------------------------
  118. // Vertex Buffer info
  119. //-----------------------------------------------------------------------------
  120. int CVertexBufferDx10::VertexCount() const
  121. {
  122. Assert( !m_bIsDynamic );
  123. return m_nVertexCount;
  124. }
  125. //-----------------------------------------------------------------------------
  126. // Returns the buffer format (only valid for static index buffers)
  127. //-----------------------------------------------------------------------------
  128. VertexFormat_t CVertexBufferDx10::GetVertexFormat() const
  129. {
  130. Assert( !m_bIsDynamic );
  131. return m_VertexFormat;
  132. }
  133. //-----------------------------------------------------------------------------
  134. // Returns true if the buffer is dynamic
  135. //-----------------------------------------------------------------------------
  136. bool CVertexBufferDx10::IsDynamic() const
  137. {
  138. return m_bIsDynamic;
  139. }
  140. //-----------------------------------------------------------------------------
  141. // Only used by dynamic buffers, indicates the next lock should perform a discard.
  142. //-----------------------------------------------------------------------------
  143. void CVertexBufferDx10::Flush()
  144. {
  145. // This strange-looking line makes a flush only occur if the buffer is dynamic.
  146. m_bFlush = m_bIsDynamic;
  147. }
  148. //-----------------------------------------------------------------------------
  149. // Casts a dynamic buffer to be a particular vertex type
  150. //-----------------------------------------------------------------------------
  151. void CVertexBufferDx10::BeginCastBuffer( VertexFormat_t format )
  152. {
  153. Assert( format != MATERIAL_INDEX_FORMAT_UNKNOWN );
  154. Assert( m_bIsDynamic && ( m_VertexFormat == 0 || m_VertexFormat == format ) );
  155. if ( !m_bIsDynamic )
  156. return;
  157. m_VertexFormat = format;
  158. m_nVertexCount = m_nBufferSize / VertexSize();
  159. }
  160. void CVertexBufferDx10::EndCastBuffer( )
  161. {
  162. Assert( m_bIsDynamic && m_VertexFormat != 0 );
  163. if ( !m_bIsDynamic )
  164. return;
  165. m_VertexFormat = 0;
  166. m_nVertexCount = 0;
  167. }
  168. //-----------------------------------------------------------------------------
  169. // Returns the number of indices that can be written into the buffer
  170. //-----------------------------------------------------------------------------
  171. int CVertexBufferDx10::GetRoomRemaining() const
  172. {
  173. return ( m_nBufferSize - m_nFirstUnwrittenOffset ) / VertexSize();
  174. }
  175. //-----------------------------------------------------------------------------
  176. // Lock, unlock
  177. //-----------------------------------------------------------------------------
  178. bool CVertexBufferDx10::Lock( int nMaxVertexCount, bool bAppend, VertexDesc_t &desc )
  179. {
  180. Assert( !m_bIsLocked && ( nMaxVertexCount != 0 ) && ( nMaxVertexCount <= m_nVertexCount ) );
  181. Assert( m_VertexFormat != 0 );
  182. // FIXME: Why do we need to sync matrices now?
  183. ShaderUtil()->SyncMatrices();
  184. g_ShaderMutex.Lock();
  185. void *pLockedData = NULL;
  186. HRESULT hr;
  187. // This can happen if the buffer was locked but a type wasn't bound
  188. if ( m_VertexFormat == 0 )
  189. goto vertexBufferLockFailed;
  190. // Just give the app crap buffers to fill up while we're suppressed...
  191. if ( g_pShaderDevice->IsDeactivated() || ( nMaxVertexCount == 0 ) )
  192. goto vertexBufferLockFailed;
  193. // Did we ask for something too large?
  194. if ( nMaxVertexCount > m_nVertexCount )
  195. {
  196. Warning( "Too many vertices for vertex buffer. . tell a programmer (%d>%d)\n", nMaxVertexCount, m_nVertexCount );
  197. goto vertexBufferLockFailed;
  198. }
  199. // We might not have a buffer owing to alt-tab type stuff
  200. if ( !m_pVertexBuffer )
  201. {
  202. if ( !Allocate() )
  203. goto vertexBufferLockFailed;
  204. }
  205. // Check to see if we have enough memory
  206. int nMemoryRequired = nMaxVertexCount * VertexSize();
  207. bool bHasEnoughMemory = ( m_nFirstUnwrittenOffset + nMemoryRequired <= m_nBufferSize );
  208. D3D10_MAP map;
  209. if ( bAppend )
  210. {
  211. // Can't have the first lock after a flush be an appending lock
  212. Assert( !m_bFlush );
  213. // If we're appending and we don't have enough room, then puke!
  214. if ( !bHasEnoughMemory || m_bFlush )
  215. goto vertexBufferLockFailed;
  216. map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE;
  217. }
  218. else
  219. {
  220. // If we're not appending, no overwrite unless we don't have enough room
  221. // If we're a static buffer, always discard if we're not appending
  222. if ( !m_bFlush && bHasEnoughMemory && m_bIsDynamic )
  223. {
  224. map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE;
  225. }
  226. else
  227. {
  228. map = D3D10_MAP_WRITE_DISCARD;
  229. m_nFirstUnwrittenOffset = 0;
  230. m_bFlush = false;
  231. }
  232. }
  233. hr = m_pVertexBuffer->Map( map, 0, &pLockedData );
  234. if ( FAILED( hr ) )
  235. {
  236. Warning( "Failed to lock vertex buffer in CVertexBufferDx10::Lock\n" );
  237. goto vertexBufferLockFailed;
  238. }
  239. ComputeVertexDescription( (unsigned char*)pLockedData + m_nFirstUnwrittenOffset, m_VertexFormat, desc );
  240. desc.m_nFirstVertex = 0;
  241. desc.m_nOffset = m_nFirstUnwrittenOffset;
  242. m_bIsLocked = true;
  243. return true;
  244. vertexBufferLockFailed:
  245. g_ShaderMutex.Unlock();
  246. // Set up a bogus index descriptor
  247. ComputeVertexDescription( 0, 0, desc );
  248. desc.m_nFirstVertex = 0;
  249. desc.m_nOffset = 0;
  250. return false;
  251. }
  252. void CVertexBufferDx10::Unlock( int nWrittenVertexCount, VertexDesc_t &desc )
  253. {
  254. Assert( nWrittenVertexCount <= m_nVertexCount );
  255. // NOTE: This can happen if the lock occurs during alt-tab
  256. // or if another application is initializing
  257. if ( !m_bIsLocked )
  258. return;
  259. if ( m_pVertexBuffer )
  260. {
  261. m_pVertexBuffer->Unmap();
  262. }
  263. m_nFirstUnwrittenOffset += nWrittenVertexCount * VertexSize();
  264. m_bIsLocked = false;
  265. g_ShaderMutex.Unlock();
  266. }
  267. //-----------------------------------------------------------------------------
  268. //
  269. // Dx10 implementation of an index buffer
  270. //
  271. //-----------------------------------------------------------------------------
  272. //-----------------------------------------------------------------------------
  273. // globals
  274. //-----------------------------------------------------------------------------
  275. // shove indices into this if you don't actually want indices
  276. static unsigned int s_nScratchIndexBuffer = 0;
  277. #ifdef _DEBUG
  278. int CIndexBufferDx10::s_nBufferCount = 0;
  279. #endif
  280. //-----------------------------------------------------------------------------
  281. // constructor, destructor
  282. //-----------------------------------------------------------------------------
  283. CIndexBufferDx10::CIndexBufferDx10( ShaderBufferType_t type, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroupName ) :
  284. BaseClass( pBudgetGroupName )
  285. {
  286. Assert( nIndexCount != 0 );
  287. Assert( IsDynamicBufferType( type ) || ( fmt != MATERIAL_INDEX_FORMAT_UNKNOWN ) );
  288. m_pIndexBuffer = NULL;
  289. m_IndexFormat = fmt;
  290. m_nIndexCount = ( fmt == MATERIAL_INDEX_FORMAT_UNKNOWN ) ? 0 : nIndexCount;
  291. m_nBufferSize = ( fmt == MATERIAL_INDEX_FORMAT_UNKNOWN ) ? nIndexCount : nIndexCount * IndexSize();
  292. m_nFirstUnwrittenOffset = 0;
  293. m_bIsLocked = false;
  294. m_bIsDynamic = IsDynamicBufferType( type );
  295. m_bFlush = false;
  296. // NOTE: This has to happen at the end since m_IndexFormat must be valid for IndexSize() to work
  297. if ( m_bIsDynamic )
  298. {
  299. m_IndexFormat = MATERIAL_INDEX_FORMAT_UNKNOWN;
  300. m_nIndexCount = 0;
  301. }
  302. }
  303. CIndexBufferDx10::~CIndexBufferDx10()
  304. {
  305. Free();
  306. }
  307. //-----------------------------------------------------------------------------
  308. // Creates, destroys the index buffer
  309. //-----------------------------------------------------------------------------
  310. bool CIndexBufferDx10::Allocate( )
  311. {
  312. Assert( !m_pIndexBuffer );
  313. m_nFirstUnwrittenOffset = 0;
  314. D3D10_BUFFER_DESC bd;
  315. bd.Usage = D3D10_USAGE_DYNAMIC;
  316. bd.ByteWidth = m_nBufferSize;
  317. bd.BindFlags = D3D10_BIND_INDEX_BUFFER;
  318. bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
  319. bd.MiscFlags = 0;
  320. HRESULT hr = D3D10Device()->CreateBuffer( &bd, NULL, &m_pIndexBuffer );
  321. bool bOk = !FAILED( hr ) && ( m_pIndexBuffer != NULL );
  322. if ( bOk )
  323. {
  324. if ( !m_bIsDynamic )
  325. {
  326. VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER,
  327. COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize );
  328. }
  329. else
  330. {
  331. VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER,
  332. COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize );
  333. }
  334. #ifdef _DEBUG
  335. ++s_nBufferCount;
  336. #endif
  337. }
  338. return bOk;
  339. }
  340. void CIndexBufferDx10::Free()
  341. {
  342. if ( m_pIndexBuffer )
  343. {
  344. #ifdef _DEBUG
  345. --s_nBufferCount;
  346. #endif
  347. m_pIndexBuffer->Release();
  348. m_pIndexBuffer = NULL;
  349. if ( !m_bIsDynamic )
  350. {
  351. VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER,
  352. COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize );
  353. }
  354. else
  355. {
  356. VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER,
  357. COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize );
  358. }
  359. }
  360. }
  361. //-----------------------------------------------------------------------------
  362. // Returns the buffer size (only valid for static index buffers)
  363. //-----------------------------------------------------------------------------
  364. int CIndexBufferDx10::IndexCount() const
  365. {
  366. Assert( !m_bIsDynamic );
  367. return m_nIndexCount;
  368. }
  369. //-----------------------------------------------------------------------------
  370. // Returns the buffer format (only valid for static index buffers)
  371. //-----------------------------------------------------------------------------
  372. MaterialIndexFormat_t CIndexBufferDx10::IndexFormat() const
  373. {
  374. Assert( !m_bIsDynamic );
  375. return m_IndexFormat;
  376. }
  377. //-----------------------------------------------------------------------------
  378. // Returns true if the buffer is dynamic
  379. //-----------------------------------------------------------------------------
  380. bool CIndexBufferDx10::IsDynamic() const
  381. {
  382. return m_bIsDynamic;
  383. }
  384. //-----------------------------------------------------------------------------
  385. // Only used by dynamic buffers, indicates the next lock should perform a discard.
  386. //-----------------------------------------------------------------------------
  387. void CIndexBufferDx10::Flush()
  388. {
  389. // This strange-looking line makes a flush only occur if the buffer is dynamic.
  390. m_bFlush = m_bIsDynamic;
  391. }
  392. //-----------------------------------------------------------------------------
  393. // Casts a dynamic buffer to be a particular index type
  394. //-----------------------------------------------------------------------------
  395. void CIndexBufferDx10::BeginCastBuffer( MaterialIndexFormat_t format )
  396. {
  397. Assert( format != MATERIAL_INDEX_FORMAT_UNKNOWN );
  398. Assert( m_bIsDynamic && ( m_IndexFormat == MATERIAL_INDEX_FORMAT_UNKNOWN || m_IndexFormat == format ) );
  399. if ( !m_bIsDynamic )
  400. return;
  401. m_IndexFormat = format;
  402. m_nIndexCount = m_nBufferSize / IndexSize();
  403. }
  404. void CIndexBufferDx10::EndCastBuffer( )
  405. {
  406. Assert( m_bIsDynamic && m_IndexFormat != MATERIAL_INDEX_FORMAT_UNKNOWN );
  407. if ( !m_bIsDynamic )
  408. return;
  409. m_IndexFormat = MATERIAL_INDEX_FORMAT_UNKNOWN;
  410. m_nIndexCount = 0;
  411. }
  412. //-----------------------------------------------------------------------------
  413. // Returns the number of indices that can be written into the buffer
  414. //-----------------------------------------------------------------------------
  415. int CIndexBufferDx10::GetRoomRemaining() const
  416. {
  417. return ( m_nBufferSize - m_nFirstUnwrittenOffset ) / IndexSize();
  418. }
  419. //-----------------------------------------------------------------------------
  420. // Locks, unlocks the mesh
  421. //-----------------------------------------------------------------------------
  422. bool CIndexBufferDx10::Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t &desc )
  423. {
  424. Assert( !m_bIsLocked && ( nMaxIndexCount != 0 ) && ( nMaxIndexCount <= m_nIndexCount ) );
  425. Assert( m_IndexFormat != MATERIAL_INDEX_FORMAT_UNKNOWN );
  426. // FIXME: Why do we need to sync matrices now?
  427. ShaderUtil()->SyncMatrices();
  428. g_ShaderMutex.Lock();
  429. void *pLockedData = NULL;
  430. HRESULT hr;
  431. // This can happen if the buffer was locked but a type wasn't bound
  432. if ( m_IndexFormat == MATERIAL_INDEX_FORMAT_UNKNOWN )
  433. goto indexBufferLockFailed;
  434. // Just give the app crap buffers to fill up while we're suppressed...
  435. if ( g_pShaderDevice->IsDeactivated() || ( nMaxIndexCount == 0 ) )
  436. goto indexBufferLockFailed;
  437. // Did we ask for something too large?
  438. if ( nMaxIndexCount > m_nIndexCount )
  439. {
  440. Warning( "Too many indices for index buffer. . tell a programmer (%d>%d)\n", nMaxIndexCount, m_nIndexCount );
  441. goto indexBufferLockFailed;
  442. }
  443. // We might not have a buffer owing to alt-tab type stuff
  444. if ( !m_pIndexBuffer )
  445. {
  446. if ( !Allocate() )
  447. goto indexBufferLockFailed;
  448. }
  449. // Check to see if we have enough memory
  450. int nMemoryRequired = nMaxIndexCount * IndexSize();
  451. bool bHasEnoughMemory = ( m_nFirstUnwrittenOffset + nMemoryRequired <= m_nBufferSize );
  452. D3D10_MAP map;
  453. if ( bAppend )
  454. {
  455. // Can't have the first lock after a flush be an appending lock
  456. Assert( !m_bFlush );
  457. // If we're appending and we don't have enough room, then puke!
  458. if ( !bHasEnoughMemory || m_bFlush )
  459. goto indexBufferLockFailed;
  460. map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE;
  461. }
  462. else
  463. {
  464. // If we're not appending, no overwrite unless we don't have enough room
  465. if ( !m_bFlush && bHasEnoughMemory && m_bIsDynamic )
  466. {
  467. map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE;
  468. }
  469. else
  470. {
  471. map = D3D10_MAP_WRITE_DISCARD;
  472. m_nFirstUnwrittenOffset = 0;
  473. m_bFlush = false;
  474. }
  475. }
  476. hr = m_pIndexBuffer->Map( map, 0, &pLockedData );
  477. if ( FAILED( hr ) )
  478. {
  479. Warning( "Failed to lock index buffer in CIndexBufferDx10::Lock\n" );
  480. goto indexBufferLockFailed;
  481. }
  482. desc.m_pIndices = (unsigned short*)( (unsigned char*)pLockedData + m_nFirstUnwrittenOffset );
  483. desc.m_nIndexSize = IndexSize() >> 1;
  484. desc.m_nFirstIndex = 0;
  485. desc.m_nOffset = m_nFirstUnwrittenOffset;
  486. m_bIsLocked = true;
  487. return true;
  488. indexBufferLockFailed:
  489. g_ShaderMutex.Unlock();
  490. // Set up a bogus index descriptor
  491. desc.m_pIndices = (unsigned short*)( &s_nScratchIndexBuffer );
  492. desc.m_nFirstIndex = 0;
  493. desc.m_nIndexSize = 0;
  494. desc.m_nOffset = 0;
  495. return false;
  496. }
  497. void CIndexBufferDx10::Unlock( int nWrittenIndexCount, IndexDesc_t &desc )
  498. {
  499. Assert( nWrittenIndexCount <= m_nIndexCount );
  500. // NOTE: This can happen if the lock occurs during alt-tab
  501. // or if another application is initializing
  502. if ( !m_bIsLocked )
  503. return;
  504. if ( m_pIndexBuffer )
  505. {
  506. m_pIndexBuffer->Unmap();
  507. }
  508. m_nFirstUnwrittenOffset += nWrittenIndexCount * IndexSize();
  509. m_bIsLocked = false;
  510. g_ShaderMutex.Unlock();
  511. }
  512. //-----------------------------------------------------------------------------
  513. // Locks, unlocks an existing mesh
  514. //-----------------------------------------------------------------------------
  515. void CIndexBufferDx10::ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc )
  516. {
  517. Assert( 0 );
  518. }
  519. void CIndexBufferDx10::ModifyEnd( IndexDesc_t& desc )
  520. {
  521. }
  522. //-----------------------------------------------------------------------------
  523. //
  524. // The empty mesh...
  525. //
  526. //-----------------------------------------------------------------------------
  527. CMeshDx10::CMeshDx10()
  528. {
  529. m_pVertexMemory = new unsigned char[VERTEX_BUFFER_SIZE];
  530. }
  531. CMeshDx10::~CMeshDx10()
  532. {
  533. delete[] m_pVertexMemory;
  534. }
  535. void CMeshDx10::LockMesh( int numVerts, int numIndices, MeshDesc_t& desc )
  536. {
  537. // Who cares about the data?
  538. desc.m_pPosition = (float*)m_pVertexMemory;
  539. desc.m_pNormal = (float*)m_pVertexMemory;
  540. desc.m_pColor = m_pVertexMemory;
  541. int i;
  542. for ( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i)
  543. desc.m_pTexCoord[i] = (float*)m_pVertexMemory;
  544. desc.m_pIndices = (unsigned short*)m_pVertexMemory;
  545. desc.m_pBoneWeight = (float*)m_pVertexMemory;
  546. desc.m_pBoneMatrixIndex = (unsigned char*)m_pVertexMemory;
  547. desc.m_pTangentS = (float*)m_pVertexMemory;
  548. desc.m_pTangentT = (float*)m_pVertexMemory;
  549. desc.m_pUserData = (float*)m_pVertexMemory;
  550. desc.m_NumBoneWeights = 2;
  551. desc.m_VertexSize_Position = 0;
  552. desc.m_VertexSize_BoneWeight = 0;
  553. desc.m_VertexSize_BoneMatrixIndex = 0;
  554. desc.m_VertexSize_Normal = 0;
  555. desc.m_VertexSize_Color = 0;
  556. for( i=0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ )
  557. desc.m_VertexSize_TexCoord[i] = 0;
  558. desc.m_VertexSize_TangentS = 0;
  559. desc.m_VertexSize_TangentT = 0;
  560. desc.m_VertexSize_UserData = 0;
  561. desc.m_ActualVertexSize = 0; // Size of the vertices.. Some of the m_VertexSize_ elements above
  562. desc.m_nFirstVertex = 0;
  563. desc.m_nIndexSize = 0;
  564. }
  565. void CMeshDx10::UnlockMesh( int numVerts, int numIndices, MeshDesc_t& desc )
  566. {
  567. }
  568. void CMeshDx10::ModifyBeginEx( bool bReadOnly, int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc )
  569. {
  570. // Who cares about the data?
  571. desc.m_pPosition = (float*)m_pVertexMemory;
  572. desc.m_pNormal = (float*)m_pVertexMemory;
  573. desc.m_pColor = m_pVertexMemory;
  574. int i;
  575. for ( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i)
  576. desc.m_pTexCoord[i] = (float*)m_pVertexMemory;
  577. desc.m_pIndices = (unsigned short*)m_pVertexMemory;
  578. desc.m_pBoneWeight = (float*)m_pVertexMemory;
  579. desc.m_pBoneMatrixIndex = (unsigned char*)m_pVertexMemory;
  580. desc.m_pTangentS = (float*)m_pVertexMemory;
  581. desc.m_pTangentT = (float*)m_pVertexMemory;
  582. desc.m_pUserData = (float*)m_pVertexMemory;
  583. desc.m_NumBoneWeights = 2;
  584. desc.m_VertexSize_Position = 0;
  585. desc.m_VertexSize_BoneWeight = 0;
  586. desc.m_VertexSize_BoneMatrixIndex = 0;
  587. desc.m_VertexSize_Normal = 0;
  588. desc.m_VertexSize_Color = 0;
  589. for( i=0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ )
  590. desc.m_VertexSize_TexCoord[i] = 0;
  591. desc.m_VertexSize_TangentS = 0;
  592. desc.m_VertexSize_TangentT = 0;
  593. desc.m_VertexSize_UserData = 0;
  594. desc.m_ActualVertexSize = 0; // Size of the vertices.. Some of the m_VertexSize_ elements above
  595. desc.m_nFirstVertex = 0;
  596. desc.m_nIndexSize = 0;
  597. }
  598. void CMeshDx10::ModifyBegin( int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc )
  599. {
  600. ModifyBeginEx( false, firstVertex, numVerts, firstIndex, numIndices, desc );
  601. }
  602. void CMeshDx10::ModifyEnd( MeshDesc_t& desc )
  603. {
  604. }
  605. // returns the # of vertices (static meshes only)
  606. int CMeshDx10::VertexCount() const
  607. {
  608. return 0;
  609. }
  610. // Sets the primitive type
  611. void CMeshDx10::SetPrimitiveType( MaterialPrimitiveType_t type )
  612. {
  613. }
  614. // Draws the entire mesh
  615. void CMeshDx10::Draw( int firstIndex, int numIndices )
  616. {
  617. }
  618. void CMeshDx10::Draw(CPrimList *pPrims, int nPrims)
  619. {
  620. }
  621. // Copy verts and/or indices to a mesh builder. This only works for temp meshes!
  622. void CMeshDx10::CopyToMeshBuilder(
  623. int iStartVert, // Which vertices to copy.
  624. int nVerts,
  625. int iStartIndex, // Which indices to copy.
  626. int nIndices,
  627. int indexOffset, // This is added to each index.
  628. CMeshBuilder &builder )
  629. {
  630. }
  631. // Spews the mesh data
  632. void CMeshDx10::Spew( int numVerts, int numIndices, const MeshDesc_t & desc )
  633. {
  634. }
  635. void CMeshDx10::ValidateData( int numVerts, int numIndices, const MeshDesc_t & desc )
  636. {
  637. }
  638. // gets the associated material
  639. IMaterial* CMeshDx10::GetMaterial()
  640. {
  641. // umm. this don't work none
  642. Assert(0);
  643. return 0;
  644. }