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.

1445 lines
38 KiB

  1. //===== Copyright © 1996-2008, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #include "shaderapidx10.h"
  9. #include "shaderapibase.h"
  10. #include "shaderapi/ishaderutil.h"
  11. #include "materialsystem/idebugtextureinfo.h"
  12. #include "materialsystem/materialsystem_config.h"
  13. #include "materialsystem/ITexture.h"
  14. #include "meshdx10.h"
  15. #include "shadershadowdx10.h"
  16. #include "shaderdevicedx10.h"
  17. #include "shaderapidx10_global.h"
  18. #include "imaterialinternal.h"
  19. #include "shaderapi/gpumemorystats.h"
  20. // NOTE: This has to be the last file included!
  21. #include "tier0/memdbgon.h"
  22. //-----------------------------------------------------------------------------
  23. // Methods related to queuing functions to be called prior to rendering
  24. //-----------------------------------------------------------------------------
  25. CFunctionCommit::CFunctionCommit()
  26. {
  27. m_pCommitFlags = NULL;
  28. m_nCommitBufferSize = 0;
  29. }
  30. CFunctionCommit::~CFunctionCommit()
  31. {
  32. if ( m_pCommitFlags )
  33. {
  34. delete[] m_pCommitFlags;
  35. m_pCommitFlags = NULL;
  36. }
  37. }
  38. void CFunctionCommit::Init( int nFunctionCount )
  39. {
  40. m_nCommitBufferSize = ( nFunctionCount + 7 ) >> 3;
  41. Assert( !m_pCommitFlags );
  42. m_pCommitFlags = new unsigned char[ m_nCommitBufferSize ];
  43. memset( m_pCommitFlags, 0, m_nCommitBufferSize );
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Methods related to queuing functions to be called per-(pMesh->Draw call) or per-pass
  47. //-----------------------------------------------------------------------------
  48. inline bool CFunctionCommit::IsCommitFuncInUse( int nFunc ) const
  49. {
  50. Assert( nFunc >> 3 < m_nCommitBufferSize );
  51. return ( m_pCommitFlags[ nFunc >> 3 ] & ( 1 << ( nFunc & 0x7 ) ) ) != 0;
  52. }
  53. inline void CFunctionCommit::MarkCommitFuncInUse( int nFunc )
  54. {
  55. Assert( nFunc >> 3 < m_nCommitBufferSize );
  56. m_pCommitFlags[ nFunc >> 3 ] |= 1 << ( nFunc & 0x7 );
  57. }
  58. inline void CFunctionCommit::AddCommitFunc( StateCommitFunc_t f )
  59. {
  60. m_CommitFuncs.AddToTail( f );
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Clears all commit functions
  64. //-----------------------------------------------------------------------------
  65. inline void CFunctionCommit::ClearAllCommitFuncs( )
  66. {
  67. memset( m_pCommitFlags, 0, m_nCommitBufferSize );
  68. m_CommitFuncs.RemoveAll();
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Calls all commit functions in a particular list
  72. //-----------------------------------------------------------------------------
  73. void CFunctionCommit::CallCommitFuncs( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t &currentState, bool bForce )
  74. {
  75. int nCount = m_CommitFuncs.Count();
  76. for ( int i = 0; i < nCount; ++i )
  77. {
  78. m_CommitFuncs[i]( pDevice, desiredState, currentState, bForce );
  79. }
  80. ClearAllCommitFuncs( );
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Helpers for commit functions
  84. //-----------------------------------------------------------------------------
  85. #define ADD_COMMIT_FUNC( _func_name ) \
  86. if ( !m_Commit.IsCommitFuncInUse( COMMIT_FUNC_ ## _func_name ) ) \
  87. { \
  88. m_Commit.AddCommitFunc( _func_name ); \
  89. m_Commit.MarkCommitFuncInUse( COMMIT_FUNC_ ## _func_name ); \
  90. }
  91. #define ADD_RENDERSTATE_FUNC( _func_name, _state, _val ) \
  92. if ( m_bResettingRenderState || ( m_DesiredState. ## _state != _val ) ) \
  93. { \
  94. m_DesiredState. ## _state = _val; \
  95. ADD_COMMIT_FUNC( _func_name ) \
  96. }
  97. #define IMPLEMENT_RENDERSTATE_FUNC( _func_name, _state, _d3dFunc ) \
  98. static void _func_name( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t &currentState, bool bForce ) \
  99. { \
  100. if ( bForce || ( desiredState. ## _state != currentState. ## _state ) ) \
  101. { \
  102. pDevice->_d3dFunc( desiredState. ## _state ); \
  103. currentState. ## _state = desiredState. ## _state; \
  104. } \
  105. }
  106. //-----------------------------------------------------------------------------
  107. // D3D state setting methods
  108. //-----------------------------------------------------------------------------
  109. // NOTE: For each commit func you create, add to this enumeration.
  110. enum CommitFunc_t
  111. {
  112. COMMIT_FUNC_CommitSetViewports = 0,
  113. COMMIT_FUNC_CommitSetVertexShader,
  114. COMMIT_FUNC_CommitSetGeometryShader,
  115. COMMIT_FUNC_CommitSetPixelShader,
  116. COMMIT_FUNC_CommitSetVertexBuffer,
  117. COMMIT_FUNC_CommitSetIndexBuffer,
  118. COMMIT_FUNC_CommitSetInputLayout,
  119. COMMIT_FUNC_CommitSetTopology,
  120. COMMIT_FUNC_CommitSetRasterState,
  121. COMMIT_FUNC_COUNT,
  122. };
  123. IMPLEMENT_RENDERSTATE_FUNC( CommitSetTopology, m_Topology, IASetPrimitiveTopology )
  124. IMPLEMENT_RENDERSTATE_FUNC( CommitSetVertexShader, m_pVertexShader, VSSetShader )
  125. IMPLEMENT_RENDERSTATE_FUNC( CommitSetGeometryShader, m_pGeometryShader, GSSetShader )
  126. IMPLEMENT_RENDERSTATE_FUNC( CommitSetPixelShader, m_pPixelShader, PSSetShader )
  127. static void CommitSetInputLayout( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t &currentState, bool bForce )
  128. {
  129. const ShaderInputLayoutStateDx10_t& newState = desiredState.m_InputLayout;
  130. if ( bForce || memcmp( &newState, &currentState.m_InputLayout, sizeof(ShaderInputLayoutStateDx10_t) ) )
  131. {
  132. // FIXME: Deal with multiple streams
  133. ID3D10InputLayout *pInputLayout = g_pShaderDeviceDx10->GetInputLayout(
  134. newState.m_hVertexShader, newState.m_pVertexDecl[0] );
  135. pDevice->IASetInputLayout( pInputLayout );
  136. currentState.m_InputLayout = newState;
  137. }
  138. }
  139. static void CommitSetViewports( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t &currentState, bool bForce )
  140. {
  141. bool bChanged = bForce || ( desiredState.m_nViewportCount != currentState.m_nViewportCount );
  142. if ( !bChanged && desiredState.m_nViewportCount > 0 )
  143. {
  144. bChanged = memcmp( desiredState.m_pViewports, currentState.m_pViewports,
  145. desiredState.m_nViewportCount * sizeof( D3D10_VIEWPORT ) ) != 0;
  146. }
  147. if ( !bChanged )
  148. return;
  149. pDevice->RSSetViewports( desiredState.m_nViewportCount, desiredState.m_pViewports );
  150. currentState.m_nViewportCount = desiredState.m_nViewportCount;
  151. #ifdef _DEBUG
  152. memset( currentState.m_pViewports, 0xDD, sizeof( currentState.m_pViewports ) );
  153. #endif
  154. memcpy( currentState.m_pViewports, desiredState.m_pViewports,
  155. desiredState.m_nViewportCount * sizeof( D3D10_VIEWPORT ) );
  156. }
  157. static void CommitSetIndexBuffer( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t &currentState, bool bForce )
  158. {
  159. const ShaderIndexBufferStateDx10_t &newState = desiredState.m_IndexBuffer;
  160. bool bChanged = bForce || memcmp( &newState, &currentState.m_IndexBuffer, sizeof(ShaderIndexBufferStateDx10_t) );
  161. if ( !bChanged )
  162. return;
  163. pDevice->IASetIndexBuffer( newState.m_pBuffer, newState.m_Format, newState.m_nOffset );
  164. memcpy( &currentState.m_IndexBuffer, &newState, sizeof( ShaderIndexBufferStateDx10_t ) );
  165. }
  166. static void CommitSetVertexBuffer( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t &currentState, bool bForce )
  167. {
  168. ID3D10Buffer *ppVertexBuffers[ MAX_DX10_STREAMS ];
  169. UINT pStrides[ MAX_DX10_STREAMS ];
  170. UINT pOffsets[ MAX_DX10_STREAMS ];
  171. UINT nFirstBuffer = 0;
  172. UINT nBufferCount = 0;
  173. bool bInMatch = true;
  174. for ( int i = 0; i < MAX_DX10_STREAMS; ++i )
  175. {
  176. const ShaderVertexBufferStateDx10_t &newState = desiredState.m_pVertexBuffer[i];
  177. bool bMatch = !bForce && !memcmp( &newState, &currentState.m_pVertexBuffer[i], sizeof(ShaderVertexBufferStateDx10_t) );
  178. if ( !bMatch )
  179. {
  180. ppVertexBuffers[i] = newState.m_pBuffer;
  181. pStrides[i] = newState.m_nStride;
  182. pOffsets[i] = newState.m_nOffset;
  183. ++nBufferCount;
  184. memcpy( &currentState.m_pVertexBuffer[i], &newState, sizeof( ShaderVertexBufferStateDx10_t ) );
  185. }
  186. if ( bInMatch )
  187. {
  188. if ( !bMatch )
  189. {
  190. bInMatch = false;
  191. nFirstBuffer = i;
  192. }
  193. continue;
  194. }
  195. if ( bMatch )
  196. {
  197. bInMatch = true;
  198. pDevice->IASetVertexBuffers( nFirstBuffer, nBufferCount,
  199. &ppVertexBuffers[nFirstBuffer], &pStrides[nFirstBuffer], &pOffsets[nFirstBuffer] );
  200. nBufferCount = 0;
  201. }
  202. }
  203. if ( !bInMatch )
  204. {
  205. pDevice->IASetVertexBuffers( nFirstBuffer, nBufferCount,
  206. &ppVertexBuffers[nFirstBuffer], &pStrides[nFirstBuffer], &pOffsets[nFirstBuffer] );
  207. }
  208. }
  209. static void GenerateRasterizerDesc( D3D10_RASTERIZER_DESC* pDesc, const ShaderRasterState_t& state )
  210. {
  211. pDesc->FillMode = ( state.m_FillMode == SHADER_FILL_WIREFRAME ) ? D3D10_FILL_WIREFRAME : D3D10_FILL_SOLID;
  212. // Cull state
  213. if ( state.m_bCullEnable )
  214. {
  215. pDesc->CullMode = D3D10_CULL_NONE;
  216. }
  217. else
  218. {
  219. pDesc->CullMode = ( state.m_CullMode == MATERIAL_CULLMODE_CW ) ? D3D10_CULL_BACK : D3D10_CULL_FRONT;
  220. }
  221. pDesc->FrontCounterClockwise = TRUE;
  222. // Depth bias state
  223. if ( !state.m_bDepthBias )
  224. {
  225. pDesc->DepthBias = 0;
  226. pDesc->DepthBiasClamp = 0.0f;
  227. pDesc->SlopeScaledDepthBias = 0.0f;
  228. pDesc->DepthClipEnable = FALSE;
  229. }
  230. else
  231. {
  232. // FIXME: Implement! Read ConVars
  233. }
  234. pDesc->ScissorEnable = state.m_bScissorEnable ? TRUE : FALSE;
  235. pDesc->MultisampleEnable = state.m_bMultisampleEnable ? TRUE : FALSE;
  236. pDesc->AntialiasedLineEnable = FALSE;
  237. }
  238. static void CommitSetRasterState( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t &currentState, bool bForce )
  239. {
  240. const ShaderRasterState_t& newState = desiredState.m_RasterState;
  241. if ( bForce || memcmp( &newState, &currentState.m_RasterState, sizeof(ShaderRasterState_t) ) )
  242. {
  243. // Clear out the existing state
  244. if ( currentState.m_pRasterState )
  245. {
  246. currentState.m_pRasterState->Release();
  247. }
  248. D3D10_RASTERIZER_DESC desc;
  249. GenerateRasterizerDesc( &desc, newState );
  250. // NOTE: This does a search for existing matching state objects
  251. ID3D10RasterizerState *pState = NULL;
  252. HRESULT hr = pDevice->CreateRasterizerState( &desc, &pState );
  253. if ( !FAILED(hr) )
  254. {
  255. Warning( "Unable to create rasterizer state object!\n" );
  256. }
  257. pDevice->RSSetState( pState );
  258. currentState.m_pRasterState = pState;
  259. memcpy( &currentState.m_RasterState, &newState, sizeof( ShaderRasterState_t ) );
  260. }
  261. }
  262. //-----------------------------------------------------------------------------
  263. //
  264. // Shader API Dx10
  265. //
  266. //-----------------------------------------------------------------------------
  267. //-----------------------------------------------------------------------------
  268. // Class Factory
  269. //-----------------------------------------------------------------------------
  270. static CShaderAPIDx10 s_ShaderAPIDx10;
  271. CShaderAPIDx10* g_pShaderAPIDx10 = &s_ShaderAPIDx10;
  272. EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIDx10, IShaderAPI,
  273. SHADERAPI_INTERFACE_VERSION, s_ShaderAPIDx10 )
  274. EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIDx10, IDebugTextureInfo,
  275. DEBUG_TEXTURE_INFO_VERSION, s_ShaderAPIDx10 )
  276. //-----------------------------------------------------------------------------
  277. // Constructor, destructor
  278. //-----------------------------------------------------------------------------
  279. CShaderAPIDx10::CShaderAPIDx10()
  280. {
  281. m_bResettingRenderState = false;
  282. m_Commit.Init( COMMIT_FUNC_COUNT );
  283. ClearShaderState( &m_DesiredState );
  284. ClearShaderState( &m_CurrentState );
  285. }
  286. CShaderAPIDx10::~CShaderAPIDx10()
  287. {
  288. }
  289. //-----------------------------------------------------------------------------
  290. // Clears the shader state to a well-defined value
  291. //-----------------------------------------------------------------------------
  292. void CShaderAPIDx10::ClearShaderState( ShaderStateDx10_t* pState )
  293. {
  294. memset( pState, 0, sizeof( ShaderStateDx10_t ) );
  295. }
  296. //-----------------------------------------------------------------------------
  297. // Resets the render state
  298. //-----------------------------------------------------------------------------
  299. void CShaderAPIDx10::ResetRenderState( bool bFullReset )
  300. {
  301. D3D10_RASTERIZER_DESC rDesc;
  302. memset( &rDesc, 0, sizeof(rDesc) );
  303. rDesc.FillMode = D3D10_FILL_SOLID;
  304. rDesc.CullMode = D3D10_CULL_NONE;
  305. rDesc.FrontCounterClockwise = TRUE; // right-hand rule
  306. ID3D10RasterizerState *pRasterizerState;
  307. HRESULT hr = D3D10Device()->CreateRasterizerState( &rDesc, &pRasterizerState );
  308. Assert( !FAILED(hr) );
  309. D3D10Device()->RSSetState( pRasterizerState );
  310. D3D10_DEPTH_STENCIL_DESC dsDesc;
  311. memset( &dsDesc, 0, sizeof(dsDesc) );
  312. ID3D10DepthStencilState *pDepthStencilState;
  313. hr = D3D10Device()->CreateDepthStencilState( &dsDesc, &pDepthStencilState );
  314. Assert( !FAILED(hr) );
  315. D3D10Device()->OMSetDepthStencilState( pDepthStencilState, 0 );
  316. D3D10_BLEND_DESC bDesc;
  317. memset( &bDesc, 0, sizeof(bDesc) );
  318. bDesc.SrcBlend = D3D10_BLEND_ONE;
  319. bDesc.DestBlend = D3D10_BLEND_ZERO;
  320. bDesc.BlendOp = D3D10_BLEND_OP_ADD;
  321. bDesc.SrcBlendAlpha = D3D10_BLEND_ONE;
  322. bDesc.DestBlendAlpha = D3D10_BLEND_ZERO;
  323. bDesc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
  324. bDesc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
  325. FLOAT pBlendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
  326. ID3D10BlendState *pBlendState;
  327. hr = D3D10Device()->CreateBlendState( &bDesc, &pBlendState );
  328. Assert( !FAILED(hr) );
  329. D3D10Device()->OMSetBlendState( pBlendState, pBlendFactor, 0xFFFFFFFF );
  330. }
  331. //-----------------------------------------------------------------------------
  332. // Commits queued-up state change requests
  333. //-----------------------------------------------------------------------------
  334. void CShaderAPIDx10::CommitStateChanges( bool bForce )
  335. {
  336. // Don't bother committing anything if we're deactivated
  337. if ( g_pShaderDevice->IsDeactivated() )
  338. return;
  339. m_Commit.CallCommitFuncs( D3D10Device(), m_DesiredState, m_CurrentState, bForce );
  340. }
  341. //-----------------------------------------------------------------------------
  342. // Methods of IShaderDynamicAPI
  343. //-----------------------------------------------------------------------------
  344. void CShaderAPIDx10::GetBackBufferDimensions( int& nWidth, int& nHeight ) const
  345. {
  346. g_pShaderDeviceDx10->GetBackBufferDimensions( nWidth, nHeight );
  347. }
  348. // Get the dimensions of the current render target
  349. void CShaderAPIDx10::GetCurrentRenderTargetDimensions( int& nWidth, int& nHeight ) const
  350. {
  351. ITexture *pTexture = GetRenderTargetEx( 0 );
  352. if ( pTexture == NULL )
  353. {
  354. GetBackBufferDimensions( nWidth, nHeight );
  355. }
  356. else
  357. {
  358. nWidth = pTexture->GetActualWidth();
  359. nHeight = pTexture->GetActualHeight();
  360. }
  361. }
  362. // Get the current viewport
  363. void CShaderAPIDx10::GetCurrentViewport( int& nX, int& nY, int& nWidth, int& nHeight ) const
  364. {
  365. ShaderViewport_t viewport;
  366. GetViewports( &viewport, 1 );
  367. nX = viewport.m_nTopLeftX;
  368. nY = viewport.m_nTopLeftY;
  369. nWidth = viewport.m_nWidth;
  370. nHeight = viewport.m_nHeight;
  371. }
  372. inline void CShaderAPIDx10::SetScreenSizeForVPOS( int pshReg /* = 32 */)
  373. {
  374. }
  375. inline void CShaderAPIDx10::SetVSNearAndFarZ( int vshReg )
  376. {
  377. }
  378. inline float CShaderAPIDx10::GetFarZ( void )
  379. {
  380. return 1000.0f; // dummy default value
  381. }
  382. //-----------------------------------------------------------------------------
  383. // Viewport-related methods
  384. //-----------------------------------------------------------------------------
  385. void CShaderAPIDx10::SetViewports( int nCount, const ShaderViewport_t* pViewports )
  386. {
  387. nCount = min( nCount, MAX_DX10_VIEWPORTS );
  388. m_DesiredState.m_nViewportCount = nCount;
  389. for ( int i = 0; i < nCount; ++i )
  390. {
  391. Assert( pViewports[i].m_nVersion == SHADER_VIEWPORT_VERSION );
  392. D3D10_VIEWPORT& viewport = m_DesiredState.m_pViewports[i];
  393. viewport.TopLeftX = pViewports[i].m_nTopLeftX;
  394. viewport.TopLeftY = pViewports[i].m_nTopLeftY;
  395. viewport.Width = pViewports[i].m_nWidth;
  396. viewport.Height = pViewports[i].m_nHeight;
  397. viewport.MinDepth = pViewports[i].m_flMinZ;
  398. viewport.MaxDepth = pViewports[i].m_flMaxZ;
  399. }
  400. ADD_COMMIT_FUNC( CommitSetViewports );
  401. }
  402. int CShaderAPIDx10::GetViewports( ShaderViewport_t* pViewports, int nMax ) const
  403. {
  404. int nCount = m_DesiredState.m_nViewportCount;
  405. if ( pViewports && nMax )
  406. {
  407. nCount = min( nCount, nMax );
  408. memcpy( pViewports, m_DesiredState.m_pViewports, nCount * sizeof( ShaderViewport_t ) );
  409. }
  410. return nCount;
  411. }
  412. //-----------------------------------------------------------------------------
  413. // Methods related to state objects
  414. //-----------------------------------------------------------------------------
  415. void CShaderAPIDx10::SetRasterState( const ShaderRasterState_t& state )
  416. {
  417. if ( memcmp( &state, &m_DesiredState.m_RasterState, sizeof(ShaderRasterState_t) ) )
  418. {
  419. memcpy( &m_DesiredState.m_RasterState, &state, sizeof(ShaderRasterState_t) );
  420. ADD_COMMIT_FUNC( CommitSetRasterState );
  421. }
  422. }
  423. //-----------------------------------------------------------------------------
  424. // Methods related to clearing buffers
  425. //-----------------------------------------------------------------------------
  426. void CShaderAPIDx10::ClearColor3ub( unsigned char r, unsigned char g, unsigned char b )
  427. {
  428. m_DesiredState.m_ClearColor[0] = r / 255.0f;
  429. m_DesiredState.m_ClearColor[1] = g / 255.0f;
  430. m_DesiredState.m_ClearColor[2] = b / 255.0f;
  431. m_DesiredState.m_ClearColor[3] = 1.0f;
  432. }
  433. void CShaderAPIDx10::ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a )
  434. {
  435. m_DesiredState.m_ClearColor[0] = r / 255.0f;
  436. m_DesiredState.m_ClearColor[1] = g / 255.0f;
  437. m_DesiredState.m_ClearColor[2] = b / 255.0f;
  438. m_DesiredState.m_ClearColor[3] = a / 255.0f;
  439. }
  440. void CShaderAPIDx10::ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight )
  441. {
  442. // NOTE: State change commit isn't necessary since clearing doesn't use state
  443. // CommitStateChanges();
  444. // FIXME: This implementation is totally bust0red [doesn't guarantee exact color specified]
  445. if ( bClearColor )
  446. {
  447. D3D10Device()->ClearRenderTargetView( D3D10RenderTargetView(), m_DesiredState.m_ClearColor );
  448. }
  449. }
  450. //-----------------------------------------------------------------------------
  451. // Methods related to binding shaders
  452. //-----------------------------------------------------------------------------
  453. void CShaderAPIDx10::BindVertexShader( VertexShaderHandle_t hVertexShader )
  454. {
  455. ID3D10VertexShader *pVertexShader = g_pShaderDeviceDx10->GetVertexShader( hVertexShader );
  456. ADD_RENDERSTATE_FUNC( CommitSetVertexShader, m_pVertexShader, pVertexShader );
  457. if ( m_bResettingRenderState || ( m_DesiredState.m_InputLayout.m_hVertexShader != hVertexShader ) )
  458. {
  459. m_DesiredState.m_InputLayout.m_hVertexShader = hVertexShader;
  460. ADD_COMMIT_FUNC( CommitSetInputLayout );
  461. }
  462. }
  463. void CShaderAPIDx10::BindGeometryShader( GeometryShaderHandle_t hGeometryShader )
  464. {
  465. ID3D10GeometryShader *pGeometryShader = g_pShaderDeviceDx10->GetGeometryShader( hGeometryShader );
  466. ADD_RENDERSTATE_FUNC( CommitSetGeometryShader, m_pGeometryShader, pGeometryShader );
  467. }
  468. void CShaderAPIDx10::BindPixelShader( PixelShaderHandle_t hPixelShader )
  469. {
  470. ID3D10PixelShader *pPixelShader = g_pShaderDeviceDx10->GetPixelShader( hPixelShader );
  471. ADD_RENDERSTATE_FUNC( CommitSetPixelShader, m_pPixelShader, pPixelShader );
  472. }
  473. void CShaderAPIDx10::BindVertexBuffer( int nStreamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions )
  474. {
  475. // FIXME: What to do about repetitions?
  476. CVertexBufferDx10 *pVertexBufferDx10 = static_cast<CVertexBufferDx10 *>( pVertexBuffer );
  477. ShaderVertexBufferStateDx10_t state;
  478. if ( pVertexBufferDx10 )
  479. {
  480. state.m_pBuffer = pVertexBufferDx10->GetDx10Buffer();
  481. state.m_nStride = pVertexBufferDx10->VertexSize();
  482. }
  483. else
  484. {
  485. state.m_pBuffer = NULL;
  486. state.m_nStride = 0;
  487. }
  488. state.m_nOffset = nOffsetInBytes;
  489. if ( m_bResettingRenderState || memcmp( &m_DesiredState.m_pVertexBuffer[ nStreamID ], &state, sizeof( ShaderVertexBufferStateDx10_t ) ) )
  490. {
  491. m_DesiredState.m_pVertexBuffer[ nStreamID ] = state;
  492. ADD_COMMIT_FUNC( CommitSetVertexBuffer );
  493. }
  494. if ( m_bResettingRenderState || ( m_DesiredState.m_InputLayout.m_pVertexDecl[ nStreamID ] != fmt ) )
  495. {
  496. m_DesiredState.m_InputLayout.m_pVertexDecl[ nStreamID ] = fmt;
  497. ADD_COMMIT_FUNC( CommitSetInputLayout );
  498. }
  499. }
  500. void CShaderAPIDx10::BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes )
  501. {
  502. CIndexBufferDx10 *pIndexBufferDx10 = static_cast<CIndexBufferDx10 *>( pIndexBuffer );
  503. ShaderIndexBufferStateDx10_t state;
  504. if ( pIndexBufferDx10 )
  505. {
  506. state.m_pBuffer = pIndexBufferDx10->GetDx10Buffer();
  507. state.m_Format = ( pIndexBufferDx10->GetIndexFormat() == MATERIAL_INDEX_FORMAT_16BIT ) ?
  508. DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT;
  509. }
  510. else
  511. {
  512. state.m_pBuffer = NULL;
  513. state.m_Format = DXGI_FORMAT_R16_UINT;
  514. }
  515. state.m_nOffset = nOffsetInBytes;
  516. ADD_RENDERSTATE_FUNC( CommitSetIndexBuffer, m_IndexBuffer, state );
  517. }
  518. //-----------------------------------------------------------------------------
  519. // Unbinds resources because they are about to be deleted
  520. //-----------------------------------------------------------------------------
  521. void CShaderAPIDx10::Unbind( VertexShaderHandle_t hShader )
  522. {
  523. ID3D10VertexShader* pShader = g_pShaderDeviceDx10->GetVertexShader( hShader );
  524. Assert ( pShader );
  525. if ( m_DesiredState.m_pVertexShader == pShader )
  526. {
  527. BindVertexShader( VERTEX_SHADER_HANDLE_INVALID );
  528. }
  529. if ( m_CurrentState.m_pVertexShader == pShader )
  530. {
  531. CommitStateChanges();
  532. }
  533. }
  534. void CShaderAPIDx10::Unbind( GeometryShaderHandle_t hShader )
  535. {
  536. ID3D10GeometryShader* pShader = g_pShaderDeviceDx10->GetGeometryShader( hShader );
  537. Assert ( pShader );
  538. if ( m_DesiredState.m_pGeometryShader == pShader )
  539. {
  540. BindGeometryShader( GEOMETRY_SHADER_HANDLE_INVALID );
  541. }
  542. if ( m_CurrentState.m_pGeometryShader == pShader )
  543. {
  544. CommitStateChanges();
  545. }
  546. }
  547. void CShaderAPIDx10::Unbind( PixelShaderHandle_t hShader )
  548. {
  549. ID3D10PixelShader* pShader = g_pShaderDeviceDx10->GetPixelShader( hShader );
  550. Assert ( pShader );
  551. if ( m_DesiredState.m_pPixelShader == pShader )
  552. {
  553. BindPixelShader( PIXEL_SHADER_HANDLE_INVALID );
  554. }
  555. if ( m_CurrentState.m_pPixelShader == pShader )
  556. {
  557. CommitStateChanges();
  558. }
  559. }
  560. void CShaderAPIDx10::UnbindVertexBuffer( ID3D10Buffer *pBuffer )
  561. {
  562. Assert ( pBuffer );
  563. for ( int i = 0; i < MAX_DX10_STREAMS; ++i )
  564. {
  565. if ( m_DesiredState.m_pVertexBuffer[i].m_pBuffer == pBuffer )
  566. {
  567. BindVertexBuffer( i, NULL, 0, 0, 0, VERTEX_POSITION, 0 );
  568. }
  569. }
  570. for ( int i = 0; i < MAX_DX10_STREAMS; ++i )
  571. {
  572. if ( m_CurrentState.m_pVertexBuffer[i].m_pBuffer == pBuffer )
  573. {
  574. CommitStateChanges();
  575. break;
  576. }
  577. }
  578. }
  579. void CShaderAPIDx10::UnbindIndexBuffer( ID3D10Buffer *pBuffer )
  580. {
  581. Assert ( pBuffer );
  582. if ( m_DesiredState.m_IndexBuffer.m_pBuffer == pBuffer )
  583. {
  584. BindIndexBuffer( NULL, 0 );
  585. }
  586. if ( m_CurrentState.m_IndexBuffer.m_pBuffer == pBuffer )
  587. {
  588. CommitStateChanges();
  589. }
  590. }
  591. //-----------------------------------------------------------------------------
  592. // Sets the topology state
  593. //-----------------------------------------------------------------------------
  594. void CShaderAPIDx10::SetTopology( MaterialPrimitiveType_t topology )
  595. {
  596. D3D10_PRIMITIVE_TOPOLOGY d3dTopology;
  597. switch( topology )
  598. {
  599. case MATERIAL_POINTS:
  600. d3dTopology = D3D10_PRIMITIVE_TOPOLOGY_POINTLIST;
  601. break;
  602. case MATERIAL_LINES:
  603. d3dTopology = D3D10_PRIMITIVE_TOPOLOGY_LINELIST;
  604. break;
  605. case MATERIAL_TRIANGLES:
  606. d3dTopology = D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
  607. break;
  608. case MATERIAL_TRIANGLE_STRIP:
  609. d3dTopology = D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
  610. break;
  611. case MATERIAL_LINE_STRIP:
  612. d3dTopology = D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP;
  613. break;
  614. default:
  615. case MATERIAL_LINE_LOOP:
  616. case MATERIAL_POLYGON:
  617. case MATERIAL_QUADS:
  618. Assert( 0 );
  619. d3dTopology = D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED;
  620. break;
  621. }
  622. ADD_RENDERSTATE_FUNC( CommitSetTopology, m_Topology, d3dTopology );
  623. }
  624. //-----------------------------------------------------------------------------
  625. // Main entry point for rendering
  626. //-----------------------------------------------------------------------------
  627. void CShaderAPIDx10::Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount )
  628. {
  629. SetTopology( primitiveType );
  630. CommitStateChanges();
  631. // FIXME: How do I set the base vertex location!?
  632. D3D10Device()->DrawIndexed( (UINT)nIndexCount, (UINT)nFirstIndex, 0 );
  633. }
  634. //-----------------------------------------------------------------------------
  635. //
  636. // Abandon all hope below this point
  637. //
  638. //-----------------------------------------------------------------------------
  639. bool CShaderAPIDx10::DoRenderTargetsNeedSeparateDepthBuffer() const
  640. {
  641. return false;
  642. }
  643. // Can we download textures?
  644. bool CShaderAPIDx10::CanDownloadTextures() const
  645. {
  646. return false;
  647. }
  648. // Used to clear the transition table when we know it's become invalid.
  649. void CShaderAPIDx10::ClearSnapshots()
  650. {
  651. }
  652. // Sets the default *dynamic* state
  653. void CShaderAPIDx10::SetDefaultState()
  654. {
  655. }
  656. // Returns the snapshot id for the shader state
  657. StateSnapshot_t CShaderAPIDx10::TakeSnapshot( )
  658. {
  659. StateSnapshot_t id = 0;
  660. if (g_pShaderShadowDx10->m_IsTranslucent)
  661. id |= TRANSLUCENT;
  662. if (g_pShaderShadowDx10->m_IsAlphaTested)
  663. id |= ALPHATESTED;
  664. if (g_pShaderShadowDx10->m_bUsesVertexAndPixelShaders)
  665. id |= VERTEX_AND_PIXEL_SHADERS;
  666. if (g_pShaderShadowDx10->m_bIsDepthWriteEnabled)
  667. id |= DEPTHWRITE;
  668. return id;
  669. }
  670. // Returns true if the state snapshot is transparent
  671. bool CShaderAPIDx10::IsTranslucent( StateSnapshot_t id ) const
  672. {
  673. return (id & TRANSLUCENT) != 0;
  674. }
  675. bool CShaderAPIDx10::IsAlphaTested( StateSnapshot_t id ) const
  676. {
  677. return (id & ALPHATESTED) != 0;
  678. }
  679. bool CShaderAPIDx10::IsDepthWriteEnabled( StateSnapshot_t id ) const
  680. {
  681. return (id & DEPTHWRITE) != 0;
  682. }
  683. bool CShaderAPIDx10::UsesVertexAndPixelShaders( StateSnapshot_t id ) const
  684. {
  685. return (id & VERTEX_AND_PIXEL_SHADERS) != 0;
  686. }
  687. // Gets the vertex format for a set of snapshot ids
  688. VertexFormat_t CShaderAPIDx10::ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds ) const
  689. {
  690. return 0;
  691. }
  692. // Gets the vertex format for a set of snapshot ids
  693. VertexFormat_t CShaderAPIDx10::ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds ) const
  694. {
  695. return 0;
  696. }
  697. // Uses a state snapshot
  698. void CShaderAPIDx10::UseSnapshot( StateSnapshot_t snapshot )
  699. {
  700. }
  701. void CShaderAPIDx10::GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id )
  702. {
  703. ShaderUtil()->GetStandardTextureDimensions( pWidth, pHeight, id );
  704. }
  705. float CShaderAPIDx10::GetSubDHeight()
  706. {
  707. return ShaderUtil()->GetSubDHeight();
  708. }
  709. // The shade mode
  710. void CShaderAPIDx10::ShadeMode( ShaderShadeMode_t mode )
  711. {
  712. }
  713. // Binds a particular material to render with
  714. void CShaderAPIDx10::Bind( IMaterial* pMaterial )
  715. {
  716. }
  717. // Cull mode
  718. void CShaderAPIDx10::CullMode( MaterialCullMode_t cullMode )
  719. {
  720. }
  721. void CShaderAPIDx10::FlipCullMode( void )
  722. {
  723. }
  724. void CShaderAPIDx10::ForceDepthFuncEquals( bool bEnable )
  725. {
  726. }
  727. // Forces Z buffering on or off
  728. void CShaderAPIDx10::OverrideDepthEnable( bool bEnable, bool bDepthEnable )
  729. {
  730. }
  731. void CShaderAPIDx10::OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable )
  732. {
  733. }
  734. void CShaderAPIDx10::OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable )
  735. {
  736. }
  737. //legacy fast clipping linkage
  738. void CShaderAPIDx10::SetHeightClipZ( float z )
  739. {
  740. }
  741. void CShaderAPIDx10::SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode )
  742. {
  743. }
  744. // Sets the lights
  745. void CShaderAPIDx10::SetLights( int lightNum, const LightDesc_t* pDesc )
  746. {
  747. }
  748. void CShaderAPIDx10::SetLightingState( const MaterialLightingState_t &state )
  749. {
  750. }
  751. void CShaderAPIDx10::SetAmbientLightCube( Vector4D cube[6] )
  752. {
  753. }
  754. // Gets the lightmap dimensions
  755. void CShaderAPIDx10::GetLightmapDimensions( int *w, int *h )
  756. {
  757. g_pShaderUtil->GetLightmapDimensions( w, h );
  758. }
  759. // Flushes any primitives that are buffered
  760. void CShaderAPIDx10::FlushBufferedPrimitives()
  761. {
  762. }
  763. // Creates/destroys Mesh
  764. IMesh* CShaderAPIDx10::CreateStaticMesh( VertexFormat_t fmt, const char *pTextureBudgetGroup, IMaterial * pMaterial, VertexStreamSpec_t *pStreamSpec )
  765. {
  766. return &m_Mesh;
  767. }
  768. void CShaderAPIDx10::DestroyStaticMesh( IMesh* mesh )
  769. {
  770. }
  771. // Gets the dynamic mesh; note that you've got to render the mesh
  772. // before calling this function a second time. Clients should *not*
  773. // call DestroyStaticMesh on the mesh returned by this call.
  774. IMesh* CShaderAPIDx10::GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride )
  775. {
  776. Assert( (pMaterial == NULL) || ((IMaterialInternal *)pMaterial)->IsRealTimeVersion() );
  777. return &m_Mesh;
  778. }
  779. IMesh* CShaderAPIDx10::GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t fmt, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride )
  780. {
  781. // UNDONE: support compressed dynamic meshes if needed (pro: less VB memory, con: time spent compressing)
  782. Assert( CompressionType( pVertexOverride->GetVertexFormat() ) != VERTEX_COMPRESSION_NONE );
  783. Assert( (pMaterial == NULL) || ((IMaterialInternal *)pMaterial)->IsRealTimeVersion() );
  784. return &m_Mesh;
  785. }
  786. IMesh* CShaderAPIDx10::GetFlexMesh()
  787. {
  788. return &m_Mesh;
  789. }
  790. // Begins a rendering pass that uses a state snapshot
  791. void CShaderAPIDx10::BeginPass( StateSnapshot_t snapshot )
  792. {
  793. }
  794. // Renders a single pass of a material
  795. void CShaderAPIDx10::RenderPass( const unsigned char *pInstanceCommandBuffer, int nPass, int nPassCount )
  796. {
  797. }
  798. // stuff related to matrix stacks
  799. void CShaderAPIDx10::MatrixMode( MaterialMatrixMode_t matrixMode )
  800. {
  801. }
  802. void CShaderAPIDx10::PushMatrix()
  803. {
  804. }
  805. void CShaderAPIDx10::PopMatrix()
  806. {
  807. }
  808. void CShaderAPIDx10::LoadMatrix( float *m )
  809. {
  810. }
  811. void CShaderAPIDx10::MultMatrix( float *m )
  812. {
  813. }
  814. void CShaderAPIDx10::MultMatrixLocal( float *m )
  815. {
  816. }
  817. void CShaderAPIDx10::GetMatrix( MaterialMatrixMode_t matrixMode, float *dst )
  818. {
  819. }
  820. void CShaderAPIDx10::LoadIdentity( void )
  821. {
  822. }
  823. void CShaderAPIDx10::LoadCameraToWorld( void )
  824. {
  825. }
  826. void CShaderAPIDx10::Ortho( double left, double top, double right, double bottom, double zNear, double zFar )
  827. {
  828. }
  829. void CShaderAPIDx10::PerspectiveX( double fovx, double aspect, double zNear, double zFar )
  830. {
  831. }
  832. void CShaderAPIDx10::PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right )
  833. {
  834. }
  835. void CShaderAPIDx10::PickMatrix( int x, int y, int width, int height )
  836. {
  837. }
  838. void CShaderAPIDx10::Rotate( float angle, float x, float y, float z )
  839. {
  840. }
  841. void CShaderAPIDx10::Translate( float x, float y, float z )
  842. {
  843. }
  844. void CShaderAPIDx10::Scale( float x, float y, float z )
  845. {
  846. }
  847. void CShaderAPIDx10::ScaleXY( float x, float y )
  848. {
  849. }
  850. // Fog methods...
  851. void CShaderAPIDx10::FogMode( MaterialFogMode_t fogMode )
  852. {
  853. }
  854. void CShaderAPIDx10::FogStart( float fStart )
  855. {
  856. }
  857. void CShaderAPIDx10::FogEnd( float fEnd )
  858. {
  859. }
  860. void CShaderAPIDx10::SetFogZ( float fogZ )
  861. {
  862. }
  863. void CShaderAPIDx10::FogMaxDensity( float flMaxDensity )
  864. {
  865. }
  866. void CShaderAPIDx10::GetFogDistances( float *fStart, float *fEnd, float *fFogZ )
  867. {
  868. }
  869. void CShaderAPIDx10::SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b )
  870. {
  871. }
  872. void CShaderAPIDx10::SceneFogMode( MaterialFogMode_t fogMode )
  873. {
  874. }
  875. void CShaderAPIDx10::GetSceneFogColor( unsigned char *rgb )
  876. {
  877. }
  878. MaterialFogMode_t CShaderAPIDx10::GetSceneFogMode( )
  879. {
  880. return MATERIAL_FOG_NONE;
  881. }
  882. int CShaderAPIDx10::GetPixelFogCombo( )
  883. {
  884. Assert( 0 ); // deprecated
  885. return 0; //FIXME
  886. }
  887. void CShaderAPIDx10::FogColor3f( float r, float g, float b )
  888. {
  889. }
  890. void CShaderAPIDx10::FogColor3fv( float const* rgb )
  891. {
  892. }
  893. void CShaderAPIDx10::FogColor3ub( unsigned char r, unsigned char g, unsigned char b )
  894. {
  895. }
  896. void CShaderAPIDx10::FogColor3ubv( unsigned char const* rgb )
  897. {
  898. }
  899. void CShaderAPIDx10::Viewport( int x, int y, int width, int height )
  900. {
  901. }
  902. void CShaderAPIDx10::GetViewport( int& x, int& y, int& width, int& height ) const
  903. {
  904. }
  905. // Sets the vertex and pixel shaders
  906. void CShaderAPIDx10::SetVertexShaderIndex( int vshIndex )
  907. {
  908. }
  909. void CShaderAPIDx10::SetPixelShaderIndex( int pshIndex )
  910. {
  911. }
  912. // Sets the constant register for vertex and pixel shaders
  913. void CShaderAPIDx10::SetVertexShaderConstant( int var, float const* pVec, int numConst, bool bForce )
  914. {
  915. }
  916. void CShaderAPIDx10::SetPixelShaderConstant( int var, float const* pVec, int numConst, bool bForce )
  917. {
  918. }
  919. void CShaderAPIDx10::InvalidateDelayedShaderConstants( void )
  920. {
  921. }
  922. //Set's the linear->gamma conversion textures to use for this hardware for both srgb writes enabled and disabled(identity)
  923. void CShaderAPIDx10::SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture )
  924. {
  925. }
  926. // Returns the nearest supported format
  927. ImageFormat CShaderAPIDx10::GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired /* = true */ ) const
  928. {
  929. return fmt;
  930. }
  931. ImageFormat CShaderAPIDx10::GetNearestRenderTargetFormat( ImageFormat fmt ) const
  932. {
  933. return fmt;
  934. }
  935. // Sets the texture state
  936. void CShaderAPIDx10::BindTexture( Sampler_t stage, ShaderAPITextureHandle_t textureHandle )
  937. {
  938. }
  939. // Sets the texture state
  940. void CShaderAPIDx10::BindVertexTexture( VertexTextureSampler_t vtSampler, ShaderAPITextureHandle_t textureHandle )
  941. {
  942. }
  943. // Indicates we're going to be modifying this texture
  944. // TexImage2D, TexSubImage2D, TexWrap, TexMinFilter, and TexMagFilter
  945. // all use the texture specified by this function.
  946. void CShaderAPIDx10::ModifyTexture( ShaderAPITextureHandle_t textureHandle )
  947. {
  948. }
  949. // Texture management methods
  950. void CShaderAPIDx10::TexImage2D( int level, int cubeFace, ImageFormat dstFormat, int zOffset, int width, int height,
  951. ImageFormat srcFormat, bool bSrcIsTiled, void *imageData )
  952. {
  953. }
  954. void CShaderAPIDx10::TexSubImage2D( int level, int cubeFace, int xOffset, int yOffset, int zOffset, int width, int height,
  955. ImageFormat srcFormat, int srcStride, bool bSrcIsTiled, void *imageData )
  956. {
  957. }
  958. bool CShaderAPIDx10::TexLock( int level, int cubeFaceID, int xOffset, int yOffset,
  959. int width, int height, CPixelWriter& writer )
  960. {
  961. return false;
  962. }
  963. void CShaderAPIDx10::TexUnlock( )
  964. {
  965. }
  966. void CShaderAPIDx10::UpdateTexture( int xOffset, int yOffset, int w, int h, ShaderAPITextureHandle_t hDstTexture, ShaderAPITextureHandle_t hSrcTexture )
  967. {
  968. }
  969. void *CShaderAPIDx10::LockTex( ShaderAPITextureHandle_t hTexture )
  970. {
  971. return NULL;
  972. }
  973. void CShaderAPIDx10::UnlockTex( ShaderAPITextureHandle_t hTexture )
  974. {
  975. }
  976. // These are bound to the texture, not the texture environment
  977. void CShaderAPIDx10::TexMinFilter( ShaderTexFilterMode_t texFilterMode )
  978. {
  979. }
  980. void CShaderAPIDx10::TexMagFilter( ShaderTexFilterMode_t texFilterMode )
  981. {
  982. }
  983. void CShaderAPIDx10::TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode )
  984. {
  985. }
  986. void CShaderAPIDx10::TexSetPriority( int priority )
  987. {
  988. }
  989. ShaderAPITextureHandle_t CShaderAPIDx10::CreateTexture(
  990. int width,
  991. int height,
  992. int depth,
  993. ImageFormat dstImageFormat,
  994. int numMipLevels,
  995. int numCopies,
  996. int flags,
  997. const char *pDebugName,
  998. const char *pTextureGroupName )
  999. {
  1000. ShaderAPITextureHandle_t handle;
  1001. CreateTextures( &handle, 1, width, height, depth, dstImageFormat, numMipLevels, numCopies, flags, pDebugName, pTextureGroupName );
  1002. return handle;
  1003. }
  1004. void CShaderAPIDx10::CreateTextures(
  1005. ShaderAPITextureHandle_t *pHandles,
  1006. int count,
  1007. int width,
  1008. int height,
  1009. int depth,
  1010. ImageFormat dstImageFormat,
  1011. int numMipLevels,
  1012. int numCopies,
  1013. int flags,
  1014. const char *pDebugName,
  1015. const char *pTextureGroupName )
  1016. {
  1017. for ( int k = 0; k < count; ++ k )
  1018. {
  1019. pHandles[ k ] = 0;
  1020. }
  1021. }
  1022. ShaderAPITextureHandle_t CShaderAPIDx10::CreateDepthTexture( ImageFormat renderFormat, int width, int height, const char *pDebugName, bool bTexture )
  1023. {
  1024. return 0;
  1025. }
  1026. void CShaderAPIDx10::DeleteTexture( ShaderAPITextureHandle_t textureHandle )
  1027. {
  1028. }
  1029. bool CShaderAPIDx10::IsTexture( ShaderAPITextureHandle_t textureHandle )
  1030. {
  1031. return true;
  1032. }
  1033. bool CShaderAPIDx10::IsTextureResident( ShaderAPITextureHandle_t textureHandle )
  1034. {
  1035. return false;
  1036. }
  1037. // stuff that isn't to be used from within a shader
  1038. void CShaderAPIDx10::ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth )
  1039. {
  1040. }
  1041. void CShaderAPIDx10::ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth )
  1042. {
  1043. }
  1044. void CShaderAPIDx10::PerformFullScreenStencilOperation( void )
  1045. {
  1046. }
  1047. void CShaderAPIDx10::ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat )
  1048. {
  1049. }
  1050. void CShaderAPIDx10::ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride )
  1051. {
  1052. }
  1053. void CShaderAPIDx10::FlushHardware()
  1054. {
  1055. }
  1056. // Set the number of bone weights
  1057. void CShaderAPIDx10::SetNumBoneWeights( int numBones )
  1058. {
  1059. }
  1060. // Selection mode methods
  1061. int CShaderAPIDx10::SelectionMode( bool selectionMode )
  1062. {
  1063. return 0;
  1064. }
  1065. void CShaderAPIDx10::SelectionBuffer( unsigned int* pBuffer, int size )
  1066. {
  1067. }
  1068. void CShaderAPIDx10::ClearSelectionNames( )
  1069. {
  1070. }
  1071. void CShaderAPIDx10::LoadSelectionName( int name )
  1072. {
  1073. }
  1074. void CShaderAPIDx10::PushSelectionName( int name )
  1075. {
  1076. }
  1077. void CShaderAPIDx10::PopSelectionName()
  1078. {
  1079. }
  1080. // Board-independent calls, here to unify how shaders set state
  1081. // Implementations should chain back to IShaderUtil->BindTexture(), etc.
  1082. // Use this to begin and end the frame
  1083. void CShaderAPIDx10::BeginFrame()
  1084. {
  1085. }
  1086. void CShaderAPIDx10::EndFrame()
  1087. {
  1088. }
  1089. // returns the current time in seconds....
  1090. double CShaderAPIDx10::CurrentTime() const
  1091. {
  1092. return Sys_FloatTime();
  1093. }
  1094. // Get the current camera position in world space.
  1095. void CShaderAPIDx10::GetWorldSpaceCameraPosition( float* pPos ) const
  1096. {
  1097. }
  1098. // Get the current camera position in world space.
  1099. void CShaderAPIDx10::GetWorldSpaceCameraDirection( float* pDir ) const
  1100. {
  1101. }
  1102. void CShaderAPIDx10::ForceHardwareSync( void )
  1103. {
  1104. }
  1105. void CShaderAPIDx10::SetClipPlane( int index, const float *pPlane )
  1106. {
  1107. }
  1108. void CShaderAPIDx10::EnableClipPlane( int index, bool bEnable )
  1109. {
  1110. }
  1111. void CShaderAPIDx10::SetFastClipPlane( const float *pPlane )
  1112. {
  1113. }
  1114. void CShaderAPIDx10::EnableFastClip( bool bEnable )
  1115. {
  1116. }
  1117. int CShaderAPIDx10::GetCurrentNumBones( void ) const
  1118. {
  1119. return 0;
  1120. }
  1121. // Is hardware morphing enabled?
  1122. bool CShaderAPIDx10::IsHWMorphingEnabled( ) const
  1123. {
  1124. return false;
  1125. }
  1126. TessellationMode_t CShaderAPIDx10::GetTessellationMode( ) const
  1127. {
  1128. return TESSELLATION_MODE_DISABLED;
  1129. }
  1130. int CShaderAPIDx10::GetCurrentLightCombo( void ) const
  1131. {
  1132. return 0;
  1133. }
  1134. int CShaderAPIDx10::MapLightComboToPSLightCombo( int nLightCombo ) const
  1135. {
  1136. return 0;
  1137. }
  1138. MaterialFogMode_t CShaderAPIDx10::GetCurrentFogType( void ) const
  1139. {
  1140. Assert( 0 ); // deprecated
  1141. return MATERIAL_FOG_NONE;
  1142. }
  1143. void CShaderAPIDx10::RecordString( const char *pStr )
  1144. {
  1145. }
  1146. void CShaderAPIDx10::DestroyVertexBuffers( bool bExitingLevel )
  1147. {
  1148. }
  1149. int CShaderAPIDx10::GetCurrentDynamicVBSize( void )
  1150. {
  1151. return 0;
  1152. }
  1153. void CShaderAPIDx10::EvictManagedResources()
  1154. {
  1155. }
  1156. void CShaderAPIDx10::GetGPUMemoryStats( GPUMemoryStats &stats )
  1157. {
  1158. // stub (let's face it, DX10 ain't happenin)
  1159. memset( &stats, 0, sizeof( stats ) );
  1160. }
  1161. void CShaderAPIDx10::ReleaseShaderObjects( bool bReleaseManagedResources /*= true*/ )
  1162. {
  1163. }
  1164. void CShaderAPIDx10::RestoreShaderObjects()
  1165. {
  1166. }
  1167. void CShaderAPIDx10::SyncToken( const char *pToken )
  1168. {
  1169. }
  1170. void CShaderAPIDx10::OnPresent( void )
  1171. {
  1172. // not implemented
  1173. Assert( 0 );
  1174. }