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.

940 lines
28 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef SHADERAPIDX10_H
  9. #define SHADERAPIDX10_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include <d3d10.h>
  14. #include "shaderapibase.h"
  15. #include "materialsystem/idebugtextureinfo.h"
  16. #include "meshdx10.h"
  17. //-----------------------------------------------------------------------------
  18. // Forward declarations
  19. //-----------------------------------------------------------------------------
  20. struct MaterialSystemHardwareIdentifier_t;
  21. //-----------------------------------------------------------------------------
  22. // DX10 enumerations that don't appear to exist
  23. //-----------------------------------------------------------------------------
  24. #define MAX_DX10_VIEWPORTS 16
  25. #define MAX_DX10_STREAMS 16
  26. //-----------------------------------------------------------------------------
  27. // A record describing the state on the board
  28. //-----------------------------------------------------------------------------
  29. struct ShaderIndexBufferStateDx10_t
  30. {
  31. ID3D10Buffer *m_pBuffer;
  32. DXGI_FORMAT m_Format;
  33. UINT m_nOffset;
  34. bool operator!=( const ShaderIndexBufferStateDx10_t& src ) const
  35. {
  36. return memcmp( this, &src, sizeof(ShaderIndexBufferStateDx10_t) ) != 0;
  37. }
  38. };
  39. struct ShaderVertexBufferStateDx10_t
  40. {
  41. ID3D10Buffer *m_pBuffer;
  42. UINT m_nStride;
  43. UINT m_nOffset;
  44. };
  45. struct ShaderInputLayoutStateDx10_t
  46. {
  47. VertexShaderHandle_t m_hVertexShader;
  48. VertexFormat_t m_pVertexDecl[ MAX_DX10_STREAMS ];
  49. };
  50. struct ShaderStateDx10_t
  51. {
  52. int m_nViewportCount;
  53. D3D10_VIEWPORT m_pViewports[ MAX_DX10_VIEWPORTS ];
  54. FLOAT m_ClearColor[4];
  55. ShaderRasterState_t m_RasterState;
  56. ID3D10RasterizerState *m_pRasterState;
  57. ID3D10VertexShader *m_pVertexShader;
  58. ID3D10GeometryShader *m_pGeometryShader;
  59. ID3D10PixelShader *m_pPixelShader;
  60. ShaderVertexBufferStateDx10_t m_pVertexBuffer[ MAX_DX10_STREAMS ];
  61. ShaderIndexBufferStateDx10_t m_IndexBuffer;
  62. ShaderInputLayoutStateDx10_t m_InputLayout;
  63. D3D10_PRIMITIVE_TOPOLOGY m_Topology;
  64. };
  65. //-----------------------------------------------------------------------------
  66. // Commit function helper class
  67. //-----------------------------------------------------------------------------
  68. typedef void (*StateCommitFunc_t)( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t &currentState, bool bForce );
  69. class CFunctionCommit
  70. {
  71. public:
  72. CFunctionCommit();
  73. ~CFunctionCommit();
  74. void Init( int nFunctionCount );
  75. // Methods related to queuing functions to be called per-(pMesh->Draw call) or per-pass
  76. void ClearAllCommitFuncs( );
  77. void CallCommitFuncs( bool bForce );
  78. bool IsCommitFuncInUse( int nFunc ) const;
  79. void MarkCommitFuncInUse( int nFunc );
  80. void AddCommitFunc( StateCommitFunc_t f );
  81. void CallCommitFuncs( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t &currentState, bool bForce = false );
  82. private:
  83. // A list of state commit functions to run as per-draw call commit time
  84. unsigned char* m_pCommitFlags;
  85. int m_nCommitBufferSize;
  86. CUtlVector< StateCommitFunc_t > m_CommitFuncs;
  87. };
  88. //-----------------------------------------------------------------------------
  89. // The Dx10 implementation of the shader API
  90. //-----------------------------------------------------------------------------
  91. class CShaderAPIDx10 : public CShaderAPIBase, public IDebugTextureInfo
  92. {
  93. typedef CShaderAPIBase BaseClass;
  94. public:
  95. // constructor, destructor
  96. CShaderAPIDx10( );
  97. virtual ~CShaderAPIDx10();
  98. // Methods of IShaderAPI
  99. // NOTE: These methods have been ported over
  100. public:
  101. virtual void SetViewports( int nCount, const ShaderViewport_t* pViewports );
  102. virtual int GetViewports( ShaderViewport_t* pViewports, int nMax ) const;
  103. virtual void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight );
  104. virtual void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b );
  105. virtual void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a );
  106. virtual void SetRasterState( const ShaderRasterState_t& state );
  107. virtual void BindVertexShader( VertexShaderHandle_t hVertexShader );
  108. virtual void BindGeometryShader( GeometryShaderHandle_t hGeometryShader );
  109. virtual void BindPixelShader( PixelShaderHandle_t hPixelShader );
  110. virtual void BindVertexBuffer( int nStreamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 );
  111. virtual void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes );
  112. virtual void Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount );
  113. // Methods of IShaderDynamicAPI
  114. public:
  115. virtual void GetBackBufferDimensions( int& nWidth, int& nHeight ) const;
  116. public:
  117. // Methods of CShaderAPIBase
  118. virtual bool OnDeviceInit() { ResetRenderState(); return true; }
  119. virtual void OnDeviceShutdown() {}
  120. virtual void ReleaseShaderObjects();
  121. virtual void RestoreShaderObjects();
  122. virtual void BeginPIXEvent( unsigned long color, const char *szName ) {}
  123. virtual void EndPIXEvent() {}
  124. virtual void AdvancePIXFrame() {}
  125. // NOTE: These methods have not been ported over.
  126. // IDebugTextureInfo implementation.
  127. public:
  128. virtual bool IsDebugTextureListFresh( int numFramesAllowed = 1 ) { return false; }
  129. virtual void EnableDebugTextureList( bool bEnable ) {}
  130. virtual void EnableGetAllTextures( bool bEnable ) {}
  131. virtual KeyValues* GetDebugTextureList() { return NULL; }
  132. virtual int GetTextureMemoryUsed( TextureMemoryType eTextureMemory ) { return 0; }
  133. virtual bool SetDebugTextureRendering( bool bEnable ) { return false; }
  134. public:
  135. // Other public methods
  136. void Unbind( VertexShaderHandle_t hShader );
  137. void Unbind( GeometryShaderHandle_t hShader );
  138. void Unbind( PixelShaderHandle_t hShader );
  139. void UnbindVertexBuffer( ID3D10Buffer *pBuffer );
  140. void UnbindIndexBuffer( ID3D10Buffer *pBuffer );
  141. void PrintfVA( char *fmt, va_list vargs ) {}
  142. void Printf( PRINTF_FORMAT_STRING const char *fmt, ... ) {}
  143. float Knob( char *knobname, float *setvalue = NULL ) { return 0.0f;}
  144. private:
  145. // Returns a d3d texture associated with a texture handle
  146. virtual IDirect3DBaseTexture* GetD3DTexture( ShaderAPITextureHandle_t hTexture ) { Assert(0); return NULL; }
  147. virtual void QueueResetRenderState() {}
  148. void SetTopology( MaterialPrimitiveType_t topology );
  149. virtual bool DoRenderTargetsNeedSeparateDepthBuffer() const;
  150. void SetHardwareGammaRamp( float fGamma )
  151. {
  152. }
  153. // Used to clear the transition table when we know it's become invalid.
  154. void ClearSnapshots();
  155. // Sets the mode...
  156. bool SetMode( void* hwnd, int nAdapter, const ShaderDeviceInfo_t &info )
  157. {
  158. return true;
  159. }
  160. void ChangeVideoMode( const ShaderDeviceInfo_t &info )
  161. {
  162. }
  163. // Called when the dx support level has changed
  164. virtual void DXSupportLevelChanged() {}
  165. virtual void EnableUserClipTransformOverride( bool bEnable ) {}
  166. virtual void UserClipTransform( const VMatrix &worldToView ) {}
  167. virtual bool GetUserClipTransform( VMatrix &worldToView ) { return false; }
  168. // Sets the default *dynamic* state
  169. void SetDefaultState( );
  170. // Returns the snapshot id for the shader state
  171. StateSnapshot_t TakeSnapshot( );
  172. // Returns true if the state snapshot is transparent
  173. bool IsTranslucent( StateSnapshot_t id ) const;
  174. bool IsAlphaTested( StateSnapshot_t id ) const;
  175. bool UsesVertexAndPixelShaders( StateSnapshot_t id ) const;
  176. virtual bool IsDepthWriteEnabled( StateSnapshot_t id ) const;
  177. // Gets the vertex format for a set of snapshot ids
  178. VertexFormat_t ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds ) const;
  179. // Gets the vertex format for a set of snapshot ids
  180. VertexFormat_t ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds ) const;
  181. // Begins a rendering pass that uses a state snapshot
  182. void BeginPass( StateSnapshot_t snapshot );
  183. // Uses a state snapshot
  184. void UseSnapshot( StateSnapshot_t snapshot );
  185. // Use this to get the mesh builder that allows us to modify vertex data
  186. CMeshBuilder* GetVertexModifyBuilder();
  187. // Sets the color to modulate by
  188. void Color3f( float r, float g, float b );
  189. void Color3fv( float const* pColor );
  190. void Color4f( float r, float g, float b, float a );
  191. void Color4fv( float const* pColor );
  192. // Faster versions of color
  193. void Color3ub( unsigned char r, unsigned char g, unsigned char b );
  194. void Color3ubv( unsigned char const* rgb );
  195. void Color4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a );
  196. void Color4ubv( unsigned char const* rgba );
  197. // Sets the lights
  198. void SetLight( int lightNum, const LightDesc_t& desc );
  199. void SetAmbientLight( float r, float g, float b );
  200. void SetAmbientLightCube( Vector4D cube[6] );
  201. virtual void SetLightingOrigin( Vector vLightingOrigin ) {}
  202. // Get the lights
  203. int GetMaxLights( void ) const;
  204. const LightDesc_t& GetLight( int lightNum ) const;
  205. // Render state for the ambient light cube (vertex shaders)
  206. void SetVertexShaderStateAmbientLightCube();
  207. virtual void SetPixelShaderStateAmbientLightCube( int pshReg, bool bForceToBlack = false ) {}
  208. void SetPixelShaderStateAmbientLightCube( int pshReg )
  209. {
  210. }
  211. virtual void GetDX9LightState( LightState_t *state ) const {}
  212. float GetAmbientLightCubeLuminance(void)
  213. {
  214. return 0.0f;
  215. }
  216. void SetSkinningMatrices();
  217. // Lightmap texture binding
  218. void BindLightmap( TextureStage_t stage );
  219. void BindLightmapAlpha( TextureStage_t stage )
  220. {
  221. }
  222. void BindBumpLightmap( TextureStage_t stage );
  223. void BindFullbrightLightmap( TextureStage_t stage );
  224. void BindWhite( TextureStage_t stage );
  225. void BindBlack( TextureStage_t stage );
  226. void BindGrey( TextureStage_t stage );
  227. void BindFBTexture( TextureStage_t stage, int textureIdex );
  228. void CopyRenderTargetToTexture( ShaderAPITextureHandle_t texID )
  229. {
  230. }
  231. void CopyRenderTargetToTextureEx( ShaderAPITextureHandle_t texID, int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect )
  232. {
  233. }
  234. void CopyTextureToRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t textureHandle, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL )
  235. {
  236. }
  237. // Special system flat normal map binding.
  238. void BindFlatNormalMap( TextureStage_t stage );
  239. void BindNormalizationCubeMap( TextureStage_t stage );
  240. void BindSignedNormalizationCubeMap( TextureStage_t stage );
  241. // Set the number of bone weights
  242. void SetNumBoneWeights( int numBones );
  243. // Flushes any primitives that are buffered
  244. void FlushBufferedPrimitives();
  245. // Creates/destroys Mesh
  246. IMesh* CreateStaticMesh( VertexFormat_t fmt, const char *pTextureBudgetGroup, IMaterial * pMaterial = NULL );
  247. void DestroyStaticMesh( IMesh* mesh );
  248. // Gets the dynamic mesh; note that you've got to render the mesh
  249. // before calling this function a second time. Clients should *not*
  250. // call DestroyStaticMesh on the mesh returned by this call.
  251. IMesh* GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride );
  252. IMesh* GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t fmt, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride );
  253. IVertexBuffer *GetDynamicVertexBuffer( IMaterial* pMaterial, bool buffered )
  254. {
  255. Assert( 0 );
  256. return NULL;
  257. }
  258. IIndexBuffer *GetDynamicIndexBuffer( IMaterial* pMaterial, bool buffered )
  259. {
  260. Assert( 0 );
  261. return NULL;
  262. }
  263. IMesh* GetFlexMesh();
  264. // Renders a single pass of a material
  265. void RenderPass( int nPass, int nPassCount );
  266. // stuff related to matrix stacks
  267. void MatrixMode( MaterialMatrixMode_t matrixMode );
  268. void PushMatrix();
  269. void PopMatrix();
  270. void LoadMatrix( float *m );
  271. void LoadBoneMatrix( int boneIndex, const float *m ) {}
  272. void MultMatrix( float *m );
  273. void MultMatrixLocal( float *m );
  274. void GetMatrix( MaterialMatrixMode_t matrixMode, float *dst );
  275. void LoadIdentity( void );
  276. void LoadCameraToWorld( void );
  277. void Ortho( double left, double top, double right, double bottom, double zNear, double zFar );
  278. void PerspectiveX( double fovx, double aspect, double zNear, double zFar );
  279. void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right );
  280. void PickMatrix( int x, int y, int width, int height );
  281. void Rotate( float angle, float x, float y, float z );
  282. void Translate( float x, float y, float z );
  283. void Scale( float x, float y, float z );
  284. void ScaleXY( float x, float y );
  285. void Viewport( int x, int y, int width, int height );
  286. void GetViewport( int& x, int& y, int& width, int& height ) const;
  287. // Fog methods...
  288. void FogMode( MaterialFogMode_t fogMode );
  289. void FogStart( float fStart );
  290. void FogEnd( float fEnd );
  291. void SetFogZ( float fogZ );
  292. void FogMaxDensity( float flMaxDensity );
  293. void GetFogDistances( float *fStart, float *fEnd, float *fFogZ );
  294. void FogColor3f( float r, float g, float b );
  295. void FogColor3fv( float const* rgb );
  296. void FogColor3ub( unsigned char r, unsigned char g, unsigned char b );
  297. void FogColor3ubv( unsigned char const* rgb );
  298. virtual void SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b );
  299. virtual void SceneFogMode( MaterialFogMode_t fogMode );
  300. virtual void GetSceneFogColor( unsigned char *rgb );
  301. virtual MaterialFogMode_t GetSceneFogMode( );
  302. virtual int GetPixelFogCombo( );
  303. void SetHeightClipZ( float z );
  304. void SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode );
  305. void SetClipPlane( int index, const float *pPlane );
  306. void EnableClipPlane( int index, bool bEnable );
  307. void SetFastClipPlane( const float *pPlane );
  308. void EnableFastClip( bool bEnable );
  309. // We use smaller dynamic VBs during level transitions, to free up memory
  310. virtual int GetCurrentDynamicVBSize( void );
  311. virtual void DestroyVertexBuffers( bool bExitingLevel = false );
  312. // Sets the vertex and pixel shaders
  313. void SetVertexShaderIndex( int vshIndex );
  314. void SetPixelShaderIndex( int pshIndex );
  315. // Sets the constant register for vertex and pixel shaders
  316. void SetVertexShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false );
  317. void SetPixelShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false );
  318. void SetBooleanVertexShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false )
  319. {
  320. Assert(0);
  321. }
  322. void SetIntegerVertexShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false )
  323. {
  324. Assert(0);
  325. }
  326. void SetBooleanPixelShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false )
  327. {
  328. Assert(0);
  329. }
  330. void SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false )
  331. {
  332. Assert(0);
  333. }
  334. bool ShouldWriteDepthToDestAlpha( void ) const
  335. {
  336. Assert(0);
  337. return false;
  338. }
  339. void InvalidateDelayedShaderConstants( void );
  340. // Gamma<->Linear conversions according to the video hardware we're running on
  341. float GammaToLinear_HardwareSpecific( float fGamma ) const
  342. {
  343. return 0.;
  344. }
  345. float LinearToGamma_HardwareSpecific( float fLinear ) const
  346. {
  347. return 0.;
  348. }
  349. //Set's the linear->gamma conversion textures to use for this hardware for both srgb writes enabled and disabled(identity)
  350. void SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture );
  351. // Cull mode
  352. void CullMode( MaterialCullMode_t cullMode );
  353. // Force writes only when z matches. . . useful for stenciling things out
  354. // by rendering the desired Z values ahead of time.
  355. void ForceDepthFuncEquals( bool bEnable );
  356. // Forces Z buffering on or off
  357. void OverrideDepthEnable( bool bEnable, bool bDepthEnable );
  358. // Forces alpha writes on or off
  359. void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable );
  360. //forces color writes on or off
  361. void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable );
  362. // Sets the shade mode
  363. void ShadeMode( ShaderShadeMode_t mode );
  364. // Binds a particular material to render with
  365. void Bind( IMaterial* pMaterial );
  366. // Returns the nearest supported format
  367. ImageFormat GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired = true ) const;
  368. ImageFormat GetNearestRenderTargetFormat( ImageFormat fmt ) const;
  369. // Sets the texture state
  370. void BindTexture( Sampler_t stage, ShaderAPITextureHandle_t textureHandle );
  371. void SetRenderTarget( ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle )
  372. {
  373. }
  374. void SetRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle )
  375. {
  376. }
  377. // Indicates we're going to be modifying this texture
  378. // TexImage2D, TexSubImage2D, TexWrap, TexMinFilter, and TexMagFilter
  379. // all use the texture specified by this function.
  380. void ModifyTexture( ShaderAPITextureHandle_t textureHandle );
  381. // Texture management methods
  382. void TexImage2D( int level, int cubeFace, ImageFormat dstFormat, int zOffset, int width, int height,
  383. ImageFormat srcFormat, bool bSrcIsTiled, void *imageData );
  384. void TexSubImage2D( int level, int cubeFace, int xOffset, int yOffset, int zOffset, int width, int height,
  385. ImageFormat srcFormat, int srcStride, bool bSrcIsTiled, void *imageData );
  386. void TexImageFromVTF( IVTFTexture *pVTF, int iVTFFrame );
  387. bool TexLock( int level, int cubeFaceID, int xOffset, int yOffset,
  388. int width, int height, CPixelWriter& writer );
  389. void TexUnlock( );
  390. // These are bound to the texture, not the texture environment
  391. void TexMinFilter( ShaderTexFilterMode_t texFilterMode );
  392. void TexMagFilter( ShaderTexFilterMode_t texFilterMode );
  393. void TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode );
  394. void TexSetPriority( int priority );
  395. ShaderAPITextureHandle_t CreateTexture(
  396. int width,
  397. int height,
  398. int depth,
  399. ImageFormat dstImageFormat,
  400. int numMipLevels,
  401. int numCopies,
  402. int flags,
  403. const char *pDebugName,
  404. const char *pTextureGroupName );
  405. void CreateTextures(
  406. ShaderAPITextureHandle_t *pHandles,
  407. int count,
  408. int width,
  409. int height,
  410. int depth,
  411. ImageFormat dstImageFormat,
  412. int numMipLevels,
  413. int numCopies,
  414. int flags,
  415. const char *pDebugName,
  416. const char *pTextureGroupName );
  417. ShaderAPITextureHandle_t CreateDepthTexture( ImageFormat renderFormat, int width, int height, const char *pDebugName, bool bTexture );
  418. void DeleteTexture( ShaderAPITextureHandle_t textureHandle );
  419. bool IsTexture( ShaderAPITextureHandle_t textureHandle );
  420. bool IsTextureResident( ShaderAPITextureHandle_t textureHandle );
  421. // stuff that isn't to be used from within a shader
  422. void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth );
  423. void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth );
  424. void PerformFullScreenStencilOperation( void );
  425. void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat );
  426. virtual void ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride );
  427. // Selection mode methods
  428. int SelectionMode( bool selectionMode );
  429. void SelectionBuffer( unsigned int* pBuffer, int size );
  430. void ClearSelectionNames( );
  431. void LoadSelectionName( int name );
  432. void PushSelectionName( int name );
  433. void PopSelectionName();
  434. void FlushHardware();
  435. void ResetRenderState( bool bFullReset = true );
  436. // Can we download textures?
  437. virtual bool CanDownloadTextures() const;
  438. // Board-independent calls, here to unify how shaders set state
  439. // Implementations should chain back to IShaderUtil->BindTexture(), etc.
  440. // Use this to begin and end the frame
  441. void BeginFrame();
  442. void EndFrame();
  443. // returns current time
  444. double CurrentTime() const;
  445. // Get the current camera position in world space.
  446. void GetWorldSpaceCameraPosition( float * pPos ) const;
  447. void ForceHardwareSync( void );
  448. int GetCurrentNumBones( void ) const;
  449. bool IsHWMorphingEnabled( ) const;
  450. int GetCurrentLightCombo( void ) const;
  451. int MapLightComboToPSLightCombo( int nLightCombo ) const;
  452. MaterialFogMode_t GetCurrentFogType( void ) const;
  453. void RecordString( const char *pStr );
  454. void EvictManagedResources();
  455. void SetTextureTransformDimension( TextureStage_t textureStage, int dimension, bool projected );
  456. void DisableTextureTransform( TextureStage_t textureStage )
  457. {
  458. }
  459. void SetBumpEnvMatrix( TextureStage_t textureStage, float m00, float m01, float m10, float m11 );
  460. // Gets the lightmap dimensions
  461. virtual void GetLightmapDimensions( int *w, int *h );
  462. virtual void SyncToken( const char *pToken );
  463. // Setup standard vertex shader constants (that don't change)
  464. // This needs to be called anytime that overbright changes.
  465. virtual void SetStandardVertexShaderConstants( float fOverbright )
  466. {
  467. }
  468. // Scissor Rect
  469. virtual void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ) {}
  470. // Reports support for a given CSAA mode
  471. bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ) { return false; }
  472. // Level of anisotropic filtering
  473. virtual void SetAnisotropicLevel( int nAnisotropyLevel )
  474. {
  475. }
  476. void SetDefaultDynamicState()
  477. {
  478. }
  479. virtual void CommitPixelShaderLighting( int pshReg )
  480. {
  481. }
  482. virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords )
  483. {
  484. }
  485. ShaderAPIOcclusionQuery_t CreateOcclusionQueryObject( void )
  486. {
  487. return INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE;
  488. }
  489. void DestroyOcclusionQueryObject( ShaderAPIOcclusionQuery_t handle )
  490. {
  491. }
  492. void BeginOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle )
  493. {
  494. }
  495. void EndOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle )
  496. {
  497. }
  498. int OcclusionQuery_GetNumPixelsRendered( ShaderAPIOcclusionQuery_t handle, bool bFlush )
  499. {
  500. return 0;
  501. }
  502. virtual void AcquireThreadOwnership() {}
  503. virtual void ReleaseThreadOwnership() {}
  504. virtual bool SupportsBorderColor() const { return false; }
  505. virtual bool SupportsFetch4() const { return false; }
  506. virtual void EnableBuffer2FramesAhead( bool bEnable ) {}
  507. virtual void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) {}
  508. void SetPixelShaderFogParams( int reg )
  509. {
  510. }
  511. virtual bool InFlashlightMode() const
  512. {
  513. return false;
  514. }
  515. virtual bool InEditorMode() const
  516. {
  517. return false;
  518. }
  519. // What fields in the morph do we actually use?
  520. virtual MorphFormat_t ComputeMorphFormat( int numSnapshots, StateSnapshot_t* pIds ) const
  521. {
  522. return 0;
  523. }
  524. // Gets the bound morph's vertex format; returns 0 if no morph is bound
  525. virtual MorphFormat_t GetBoundMorphFormat()
  526. {
  527. return 0;
  528. }
  529. void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id );
  530. // Binds a standard texture
  531. virtual void BindStandardTexture( Sampler_t stage, StandardTextureId_t id )
  532. {
  533. }
  534. virtual void BindStandardVertexTexture( VertexTextureSampler_t stage, StandardTextureId_t id )
  535. {
  536. }
  537. virtual void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture )
  538. {
  539. }
  540. virtual void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture )
  541. {
  542. }
  543. virtual const FlashlightState_t &GetFlashlightState( VMatrix &worldToTexture ) const
  544. {
  545. static FlashlightState_t blah;
  546. return blah;
  547. }
  548. virtual const FlashlightState_t &GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **pFlashlightDepthTexture ) const
  549. {
  550. static FlashlightState_t blah;
  551. return blah;
  552. }
  553. virtual void SetModeChangeCallback( ModeChangeCallbackFunc_t func )
  554. {
  555. }
  556. virtual void ClearVertexAndPixelShaderRefCounts()
  557. {
  558. }
  559. virtual void PurgeUnusedVertexAndPixelShaders()
  560. {
  561. }
  562. // Binds a vertex texture to a particular texture stage in the vertex pipe
  563. virtual void BindVertexTexture( VertexTextureSampler_t nStage, ShaderAPITextureHandle_t hTexture )
  564. {
  565. }
  566. // Sets morph target factors
  567. virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights )
  568. {
  569. }
  570. // NOTE: Stuff after this is added after shipping HL2.
  571. ITexture *GetRenderTargetEx( int nRenderTargetID )
  572. {
  573. return NULL;
  574. }
  575. void SetToneMappingScaleLinear( const Vector &scale )
  576. {
  577. }
  578. const Vector &GetToneMappingScaleLinear( void ) const
  579. {
  580. static Vector dummy;
  581. return dummy;
  582. }
  583. virtual float GetLightMapScaleFactor( void ) const
  584. {
  585. return 1.0;
  586. }
  587. // For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer)
  588. virtual void HandleDeviceLost()
  589. {
  590. }
  591. virtual void EnableLinearColorSpaceFrameBuffer( bool bEnable )
  592. {
  593. }
  594. // Lets the shader know about the full-screen texture so it can
  595. virtual void SetFullScreenTextureHandle( ShaderAPITextureHandle_t h )
  596. {
  597. }
  598. void SetFloatRenderingParameter(int parm_number, float value)
  599. {
  600. }
  601. void SetIntRenderingParameter(int parm_number, int value)
  602. {
  603. }
  604. void SetVectorRenderingParameter(int parm_number, Vector const &value)
  605. {
  606. }
  607. float GetFloatRenderingParameter(int parm_number) const
  608. {
  609. return 0;
  610. }
  611. int GetIntRenderingParameter(int parm_number) const
  612. {
  613. return 0;
  614. }
  615. Vector GetVectorRenderingParameter(int parm_number) const
  616. {
  617. return Vector(0,0,0);
  618. }
  619. // Methods related to stencil
  620. void SetStencilEnable(bool onoff)
  621. {
  622. }
  623. void SetStencilFailOperation(StencilOperation_t op)
  624. {
  625. }
  626. void SetStencilZFailOperation(StencilOperation_t op)
  627. {
  628. }
  629. void SetStencilPassOperation(StencilOperation_t op)
  630. {
  631. }
  632. void SetStencilCompareFunction(StencilComparisonFunction_t cmpfn)
  633. {
  634. }
  635. void SetStencilReferenceValue(int ref)
  636. {
  637. }
  638. void SetStencilTestMask(uint32 msk)
  639. {
  640. }
  641. void SetStencilWriteMask(uint32 msk)
  642. {
  643. }
  644. void ClearStencilBufferRectangle( int xmin, int ymin, int xmax, int ymax,int value)
  645. {
  646. }
  647. virtual void GetDXLevelDefaults(uint &max_dxlevel,uint &recommended_dxlevel)
  648. {
  649. max_dxlevel=recommended_dxlevel=90;
  650. }
  651. virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices )
  652. {
  653. *pMaxVerts = 32768;
  654. *pMaxIndices = 32768;
  655. }
  656. // Returns the max possible vertices + indices to render in a single draw call
  657. virtual int GetMaxVerticesToRender( IMaterial *pMaterial )
  658. {
  659. return 32768;
  660. }
  661. virtual int GetMaxIndicesToRender( )
  662. {
  663. return 32768;
  664. }
  665. virtual int CompareSnapshots( StateSnapshot_t snapshot0, StateSnapshot_t snapshot1 ) { return 0; }
  666. virtual void DisableAllLocalLights() {}
  667. virtual bool SupportsMSAAMode( int nMSAAMode ) { return false; }
  668. // Hooks for firing PIX events from outside the Material System...
  669. virtual void SetPIXMarker( unsigned long color, const char *szName ) {}
  670. virtual void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc ) const {}
  671. virtual bool SupportsShadowDepthTextures() { return false; }
  672. virtual int NeedsShaderSRGBConversion(void) const { return 1; }
  673. virtual bool SupportsFetch4() { return false; }
  674. virtual void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) {}
  675. virtual void SetDisallowAccess( bool ) {}
  676. virtual void EnableShaderShaderMutex( bool ) {}
  677. virtual void ShaderLock() {}
  678. virtual void ShaderUnlock() {}
  679. virtual void EnableHWMorphing( bool bEnable ) {}
  680. ImageFormat GetNullTextureFormat( void ) { return IMAGE_FORMAT_ABGR8888; } // stub
  681. virtual void PushDeformation( DeformationBase_t const *Deformation )
  682. {
  683. }
  684. virtual void PopDeformation( )
  685. {
  686. }
  687. virtual int GetNumActiveDeformations() const
  688. {
  689. return 0;
  690. }
  691. virtual void ExecuteCommandBuffer( uint8 *pBuf )
  692. {
  693. }
  694. void SetStandardTextureHandle(StandardTextureId_t,ShaderAPITextureHandle_t)
  695. {
  696. }
  697. virtual void SetPSNearAndFarZ( int pshReg )
  698. {
  699. }
  700. int GetPackedDeformationInformation( int nMaskOfUnderstoodDeformations,
  701. float *pConstantValuesOut,
  702. int nBufferSize,
  703. int nMaximumDeformations,
  704. int *pNumDefsOut ) const
  705. {
  706. *pNumDefsOut = 0;
  707. return 0;
  708. }
  709. virtual bool OwnGPUResources( bool bEnable )
  710. {
  711. return false;
  712. }
  713. private:
  714. enum
  715. {
  716. TRANSLUCENT = 0x1,
  717. ALPHATESTED = 0x2,
  718. VERTEX_AND_PIXEL_SHADERS = 0x4,
  719. DEPTHWRITE = 0x8,
  720. };
  721. void EnableAlphaToCoverage() {} ;
  722. void DisableAlphaToCoverage() {} ;
  723. ImageFormat GetShadowDepthTextureFormat() { return IMAGE_FORMAT_UNKNOWN; };
  724. //
  725. // NOTE: Under here are real methods being used by dx10 implementation
  726. // above is stuff I still have to port over.
  727. //
  728. private:
  729. void ClearShaderState( ShaderStateDx10_t* pState );
  730. void CommitStateChanges( bool bForce = false );
  731. private:
  732. CMeshDx10 m_Mesh;
  733. bool m_bResettingRenderState : 1;
  734. CFunctionCommit m_Commit;
  735. ShaderStateDx10_t m_DesiredState;
  736. ShaderStateDx10_t m_CurrentState;
  737. };
  738. //-----------------------------------------------------------------------------
  739. // Singleton global
  740. //-----------------------------------------------------------------------------
  741. extern CShaderAPIDx10* g_pShaderAPIDx10;
  742. #endif // SHADERAPIDX10_H