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.

869 lines
27 KiB

  1. //===== Copyright © 1996-2008, 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. virtual void OnPresent( void );
  114. virtual void UpdateGameTime( float ) {}
  115. // Methods of IShaderDynamicAPI
  116. public:
  117. virtual void GetBackBufferDimensions( int& nWidth, int& nHeight ) const;
  118. virtual void GetCurrentRenderTargetDimensions( int& nWidth, int& nHeight ) const;
  119. virtual void GetCurrentViewport( int& nX, int& nY, int& nWidth, int& nHeight ) const;
  120. virtual void SetScreenSizeForVPOS( int pshReg = 32 );
  121. virtual void SetVSNearAndFarZ( int vshReg );
  122. virtual float GetFarZ();
  123. public:
  124. // Methods of CShaderAPIBase
  125. virtual bool OnDeviceInit() { ResetRenderState(); return true; }
  126. virtual void OnDeviceShutdown() {}
  127. virtual void ReleaseShaderObjects( bool bReleaseManagedResources = true );
  128. virtual void RestoreShaderObjects();
  129. virtual void BeginPIXEvent( unsigned long color, const char *szName ) {}
  130. virtual void EndPIXEvent() {}
  131. virtual void AdvancePIXFrame() {}
  132. // NOTE: These methods have not been ported over.
  133. // IDebugTextureInfo implementation.
  134. public:
  135. virtual bool IsDebugTextureListFresh( int numFramesAllowed = 1 ) { return false; }
  136. virtual void EnableDebugTextureList( bool bEnable ) {}
  137. virtual void EnableGetAllTextures( bool bEnable ) {}
  138. virtual KeyValues* GetDebugTextureList() { return NULL; }
  139. virtual int GetTextureMemoryUsed( TextureMemoryType eTextureMemory ) { return 0; }
  140. virtual bool SetDebugTextureRendering( bool bEnable ) { return false; }
  141. public:
  142. // Other public methods
  143. void Unbind( VertexShaderHandle_t hShader );
  144. void Unbind( GeometryShaderHandle_t hShader );
  145. void Unbind( PixelShaderHandle_t hShader );
  146. void UnbindVertexBuffer( ID3D10Buffer *pBuffer );
  147. void UnbindIndexBuffer( ID3D10Buffer *pBuffer );
  148. void PrintfVA( char *fmt, va_list vargs ) {}
  149. void Printf( char *fmt, ... ) {}
  150. float Knob( char *knobname, float *setvalue = NULL ) { return 0.0f;}
  151. private:
  152. // Returns a d3d texture associated with a texture handle
  153. virtual IDirect3DBaseTexture* GetD3DTexture( ShaderAPITextureHandle_t hTexture ) { Assert(0); return NULL; }
  154. virtual void QueueResetRenderState() {}
  155. void SetTopology( MaterialPrimitiveType_t topology );
  156. virtual bool DoRenderTargetsNeedSeparateDepthBuffer() const;
  157. void SetHardwareGammaRamp( float fGamma )
  158. {
  159. }
  160. // Used to clear the transition table when we know it's become invalid.
  161. void ClearSnapshots();
  162. // Sets the mode...
  163. bool SetMode( void* hwnd, int nAdapter, const ShaderDeviceInfo_t &info )
  164. {
  165. return true;
  166. }
  167. void ChangeVideoMode( const ShaderDeviceInfo_t &info )
  168. {
  169. }
  170. // Called when the dx support level has changed
  171. virtual void DXSupportLevelChanged( int nDXLevel ) {}
  172. virtual void EnableUserClipTransformOverride( bool bEnable ) {}
  173. virtual void UserClipTransform( const VMatrix &worldToView ) {}
  174. virtual bool GetUserClipTransform( VMatrix &worldToView ) { return false; }
  175. // Sets the default *dynamic* state
  176. void SetDefaultState( );
  177. // Returns the snapshot id for the shader state
  178. StateSnapshot_t TakeSnapshot( );
  179. // Returns true if the state snapshot is transparent
  180. bool IsTranslucent( StateSnapshot_t id ) const;
  181. bool IsAlphaTested( StateSnapshot_t id ) const;
  182. bool UsesVertexAndPixelShaders( StateSnapshot_t id ) const;
  183. virtual bool IsDepthWriteEnabled( StateSnapshot_t id ) const;
  184. // Gets the vertex format for a set of snapshot ids
  185. VertexFormat_t ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds ) const;
  186. // Gets the vertex format for a set of snapshot ids
  187. VertexFormat_t ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds ) const;
  188. // Begins a rendering pass that uses a state snapshot
  189. void BeginPass( StateSnapshot_t snapshot );
  190. // Uses a state snapshot
  191. void UseSnapshot( StateSnapshot_t snapshot );
  192. // Sets the lights
  193. void SetLights( int lightNum, const LightDesc_t* pDesc );
  194. void SetLightingState( const MaterialLightingState_t &state );
  195. void SetAmbientLightCube( Vector4D cube[6] );
  196. virtual void SetLightingOrigin( Vector vLightingOrigin ) {}
  197. // Render state for the ambient light cube (vertex shaders)
  198. virtual void GetDX9LightState( LightState_t *state ) const {}
  199. void CopyRenderTargetToTexture( ShaderAPITextureHandle_t texID )
  200. {
  201. }
  202. void CopyRenderTargetToTextureEx( ShaderAPITextureHandle_t texID, int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect )
  203. {
  204. }
  205. // Set the number of bone weights
  206. void SetNumBoneWeights( int numBones );
  207. // Flushes any primitives that are buffered
  208. void FlushBufferedPrimitives();
  209. // Creates/destroys Mesh
  210. IMesh* CreateStaticMesh( VertexFormat_t fmt, const char *pTextureBudgetGroup, IMaterial * pMaterial = NULL, VertexStreamSpec_t *pStreamSpec = NULL );
  211. void DestroyStaticMesh( IMesh* mesh );
  212. // Gets the dynamic mesh; note that you've got to render the mesh
  213. // before calling this function a second time. Clients should *not*
  214. // call DestroyStaticMesh on the mesh returned by this call.
  215. IMesh* GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride );
  216. IMesh* GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t fmt, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride );
  217. IVertexBuffer *GetDynamicVertexBuffer( IMaterial* pMaterial, bool buffered )
  218. {
  219. Assert( 0 );
  220. return NULL;
  221. }
  222. IMesh* GetFlexMesh();
  223. // Renders a single pass of a material
  224. void RenderPass( const unsigned char *pInstanceCommandBuffer, int nPass, int nPassCount );
  225. // stuff related to matrix stacks
  226. void MatrixMode( MaterialMatrixMode_t matrixMode );
  227. void PushMatrix();
  228. void PopMatrix();
  229. void LoadMatrix( float *m );
  230. void LoadBoneMatrix( int boneIndex, const float *m ) {}
  231. void MultMatrix( float *m );
  232. void MultMatrixLocal( float *m );
  233. void GetMatrix( MaterialMatrixMode_t matrixMode, float *dst );
  234. void LoadIdentity( void );
  235. void LoadCameraToWorld( void );
  236. void Ortho( double left, double top, double right, double bottom, double zNear, double zFar );
  237. void PerspectiveX( double fovx, double aspect, double zNear, double zFar );
  238. void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right );
  239. void PickMatrix( int x, int y, int width, int height );
  240. void Rotate( float angle, float x, float y, float z );
  241. void Translate( float x, float y, float z );
  242. void Scale( float x, float y, float z );
  243. void ScaleXY( float x, float y );
  244. void Viewport( int x, int y, int width, int height );
  245. void GetViewport( int& x, int& y, int& width, int& height ) const;
  246. // Fog methods...
  247. void FogMode( MaterialFogMode_t fogMode );
  248. void FogStart( float fStart );
  249. void FogEnd( float fEnd );
  250. void SetFogZ( float fogZ );
  251. void FogMaxDensity( float flMaxDensity );
  252. void GetFogDistances( float *fStart, float *fEnd, float *fFogZ );
  253. void FogColor3f( float r, float g, float b );
  254. void FogColor3fv( float const* rgb );
  255. void FogColor3ub( unsigned char r, unsigned char g, unsigned char b );
  256. void FogColor3ubv( unsigned char const* rgb );
  257. virtual void SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b );
  258. virtual void SceneFogMode( MaterialFogMode_t fogMode );
  259. virtual void GetSceneFogColor( unsigned char *rgb );
  260. virtual MaterialFogMode_t GetSceneFogMode( );
  261. virtual int GetPixelFogCombo( ); // deprecated. . don't use.
  262. void SetHeightClipZ( float z );
  263. void SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode );
  264. void SetClipPlane( int index, const float *pPlane );
  265. void EnableClipPlane( int index, bool bEnable );
  266. void SetFastClipPlane( const float *pPlane );
  267. void EnableFastClip( bool bEnable );
  268. // We use smaller dynamic VBs during level transitions, to free up memory
  269. virtual int GetCurrentDynamicVBSize( void );
  270. virtual void DestroyVertexBuffers( bool bExitingLevel = false );
  271. // Sets the vertex and pixel shaders
  272. void SetVertexShaderIndex( int vshIndex );
  273. void SetPixelShaderIndex( int pshIndex );
  274. // Sets the constant register for vertex and pixel shaders
  275. void SetVertexShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false );
  276. void SetPixelShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false );
  277. void SetBooleanVertexShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false )
  278. {
  279. Assert(0);
  280. }
  281. void SetIntegerVertexShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false )
  282. {
  283. Assert(0);
  284. }
  285. void SetBooleanPixelShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false )
  286. {
  287. Assert(0);
  288. }
  289. void SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false )
  290. {
  291. Assert(0);
  292. }
  293. bool ShouldWriteDepthToDestAlpha( void ) const
  294. {
  295. Assert(0);
  296. return false;
  297. }
  298. void InvalidateDelayedShaderConstants( void );
  299. // Gamma<->Linear conversions according to the video hardware we're running on
  300. float GammaToLinear_HardwareSpecific( float fGamma ) const
  301. {
  302. return 0.;
  303. }
  304. float LinearToGamma_HardwareSpecific( float fLinear ) const
  305. {
  306. return 0.;
  307. }
  308. //Set's the linear->gamma conversion textures to use for this hardware for both srgb writes enabled and disabled(identity)
  309. void SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture );
  310. // Cull mode
  311. void CullMode( MaterialCullMode_t cullMode );
  312. void FlipCullMode( void );
  313. // Force writes only when z matches. . . useful for stenciling things out
  314. // by rendering the desired Z values ahead of time.
  315. void ForceDepthFuncEquals( bool bEnable );
  316. // Forces Z buffering on or off
  317. void OverrideDepthEnable( bool bEnable, bool bDepthEnable );
  318. // Forces alpha writes on or off
  319. void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable );
  320. //forces color writes on or off
  321. void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable );
  322. // Sets the shade mode
  323. void ShadeMode( ShaderShadeMode_t mode );
  324. // Binds a particular material to render with
  325. void Bind( IMaterial* pMaterial );
  326. // Returns the nearest supported format
  327. ImageFormat GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired = true ) const;
  328. ImageFormat GetNearestRenderTargetFormat( ImageFormat fmt ) const;
  329. // Sets the texture state
  330. void BindTexture( Sampler_t stage, ShaderAPITextureHandle_t textureHandle );
  331. void BindVertexTexture( VertexTextureSampler_t vtSampler, ShaderAPITextureHandle_t textureHandle );
  332. void SetRenderTarget( ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle )
  333. {
  334. }
  335. void SetRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle )
  336. {
  337. }
  338. // Indicates we're going to be modifying this texture
  339. // TexImage2D, TexSubImage2D, TexWrap, TexMinFilter, and TexMagFilter
  340. // all use the texture specified by this function.
  341. void ModifyTexture( ShaderAPITextureHandle_t textureHandle );
  342. // Texture management methods
  343. void TexImage2D( int level, int cubeFace, ImageFormat dstFormat, int zOffset, int width, int height,
  344. ImageFormat srcFormat, bool bSrcIsTiled, void *imageData );
  345. void TexSubImage2D( int level, int cubeFace, int xOffset, int yOffset, int zOffset, int width, int height,
  346. ImageFormat srcFormat, int srcStride, bool bSrcIsTiled, void *imageData );
  347. bool TexLock( int level, int cubeFaceID, int xOffset, int yOffset,
  348. int width, int height, CPixelWriter& writer );
  349. void TexUnlock( );
  350. void UpdateTexture( int xOffset, int yOffset, int w, int h, ShaderAPITextureHandle_t hDstTexture, ShaderAPITextureHandle_t hSrcTexture );
  351. void *LockTex( ShaderAPITextureHandle_t hTexture );
  352. void UnlockTex( ShaderAPITextureHandle_t hTexture );
  353. // These are bound to the texture, not the texture environment
  354. void TexMinFilter( ShaderTexFilterMode_t texFilterMode );
  355. void TexMagFilter( ShaderTexFilterMode_t texFilterMode );
  356. void TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode );
  357. void TexSetPriority( int priority );
  358. ShaderAPITextureHandle_t CreateTexture(
  359. int width,
  360. int height,
  361. int depth,
  362. ImageFormat dstImageFormat,
  363. int numMipLevels,
  364. int numCopies,
  365. int flags,
  366. const char *pDebugName,
  367. const char *pTextureGroupName );
  368. void CreateTextures(
  369. ShaderAPITextureHandle_t *pHandles,
  370. int count,
  371. int width,
  372. int height,
  373. int depth,
  374. ImageFormat dstImageFormat,
  375. int numMipLevels,
  376. int numCopies,
  377. int flags,
  378. const char *pDebugName,
  379. const char *pTextureGroupName );
  380. ShaderAPITextureHandle_t CreateDepthTexture( ImageFormat renderFormat, int width, int height, const char *pDebugName, bool bTexture );
  381. void DeleteTexture( ShaderAPITextureHandle_t textureHandle );
  382. bool IsTexture( ShaderAPITextureHandle_t textureHandle );
  383. bool IsTextureResident( ShaderAPITextureHandle_t textureHandle );
  384. // stuff that isn't to be used from within a shader
  385. void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth );
  386. void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth );
  387. void PerformFullScreenStencilOperation( void );
  388. void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat );
  389. virtual void ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride );
  390. // Selection mode methods
  391. int SelectionMode( bool selectionMode );
  392. void SelectionBuffer( unsigned int* pBuffer, int size );
  393. void ClearSelectionNames( );
  394. void LoadSelectionName( int name );
  395. void PushSelectionName( int name );
  396. void PopSelectionName();
  397. void FlushHardware();
  398. void ResetRenderState( bool bFullReset = true );
  399. // Can we download textures?
  400. virtual bool CanDownloadTextures() const;
  401. // Board-independent calls, here to unify how shaders set state
  402. // Implementations should chain back to IShaderUtil->BindTexture(), etc.
  403. // Use this to begin and end the frame
  404. void BeginFrame();
  405. void EndFrame();
  406. // returns current time
  407. double CurrentTime() const;
  408. // Get the current camera position in world space.
  409. void GetWorldSpaceCameraPosition( float * pPos ) const;
  410. void GetWorldSpaceCameraDirection( float* pDir ) const;
  411. void ForceHardwareSync( void );
  412. int GetCurrentNumBones( void ) const;
  413. bool IsHWMorphingEnabled( ) const;
  414. TessellationMode_t GetTessellationMode( ) const;
  415. int GetCurrentLightCombo( void ) const;
  416. int MapLightComboToPSLightCombo( int nLightCombo ) const;
  417. MaterialFogMode_t GetCurrentFogType( void ) const; // deprecated. don't use.
  418. void RecordString( const char *pStr );
  419. void EvictManagedResources();
  420. // Get stats on GPU memory usage
  421. void GetGPUMemoryStats( GPUMemoryStats &stats );
  422. // Gets the lightmap dimensions
  423. virtual void GetLightmapDimensions( int *w, int *h );
  424. virtual void SyncToken( const char *pToken );
  425. // Setup standard vertex shader constants (that don't change)
  426. // This needs to be called anytime that overbright changes.
  427. virtual void SetStandardVertexShaderConstants( float fOverbright )
  428. {
  429. }
  430. // Scissor Rect
  431. virtual void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ) {}
  432. // Reports support for a given CSAA mode
  433. bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ) { return false; }
  434. // Level of anisotropic filtering
  435. virtual void SetAnisotropicLevel( int nAnisotropyLevel )
  436. {
  437. }
  438. void SetDefaultDynamicState()
  439. {
  440. }
  441. virtual void CommitPixelShaderLighting( int pshReg )
  442. {
  443. }
  444. virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords )
  445. {
  446. }
  447. ShaderAPIOcclusionQuery_t CreateOcclusionQueryObject( void )
  448. {
  449. return INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE;
  450. }
  451. void DestroyOcclusionQueryObject( ShaderAPIOcclusionQuery_t handle )
  452. {
  453. }
  454. void BeginOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle )
  455. {
  456. }
  457. void EndOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle )
  458. {
  459. }
  460. int OcclusionQuery_GetNumPixelsRendered( ShaderAPIOcclusionQuery_t handle, bool bFlush )
  461. {
  462. return 0;
  463. }
  464. virtual void AcquireThreadOwnership() {}
  465. virtual void ReleaseThreadOwnership() {}
  466. virtual bool SupportsBorderColor() const { return false; }
  467. virtual bool SupportsFetch4() const { return false; }
  468. virtual void EnableBuffer2FramesAhead( bool bEnable ) {}
  469. virtual void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) {}
  470. void SetPixelShaderFogParams( int reg )
  471. {
  472. }
  473. virtual bool InFlashlightMode() const
  474. {
  475. return false;
  476. }
  477. virtual bool InEditorMode() const
  478. {
  479. return false;
  480. }
  481. void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id );
  482. float GetSubDHeight();
  483. // Binds a standard texture
  484. virtual void BindStandardTexture( Sampler_t stage, StandardTextureId_t id )
  485. {
  486. }
  487. virtual void BindStandardVertexTexture( VertexTextureSampler_t stage, StandardTextureId_t id )
  488. {
  489. }
  490. virtual void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture )
  491. {
  492. }
  493. virtual void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture )
  494. {
  495. }
  496. virtual const FlashlightState_t &GetFlashlightState( VMatrix &worldToTexture ) const
  497. {
  498. static FlashlightState_t blah;
  499. return blah;
  500. }
  501. virtual const FlashlightState_t &GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **pFlashlightDepthTexture ) const
  502. {
  503. static FlashlightState_t blah;
  504. return blah;
  505. }
  506. virtual void GetFlashlightShaderInfo( bool *pShadowsEnabled, bool *pUberLight ) const
  507. {
  508. *pShadowsEnabled = false;
  509. *pUberLight = false;
  510. }
  511. virtual float GetFlashlightAmbientOcclusion( ) const { return 1.0f; }
  512. virtual void SetModeChangeCallback( ModeChangeCallbackFunc_t func )
  513. {
  514. }
  515. virtual void ClearVertexAndPixelShaderRefCounts()
  516. {
  517. }
  518. virtual void PurgeUnusedVertexAndPixelShaders()
  519. {
  520. }
  521. // Sets morph target factors
  522. virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights )
  523. {
  524. }
  525. // NOTE: Stuff after this is added after shipping HL2.
  526. ITexture *GetRenderTargetEx( int nRenderTargetID ) const
  527. {
  528. return NULL;
  529. }
  530. void SetToneMappingScaleLinear( const Vector &scale )
  531. {
  532. }
  533. const Vector &GetToneMappingScaleLinear( void ) const
  534. {
  535. static Vector dummy;
  536. return dummy;
  537. }
  538. // For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer)
  539. virtual void HandleDeviceLost()
  540. {
  541. }
  542. virtual void EnableLinearColorSpaceFrameBuffer( bool bEnable )
  543. {
  544. }
  545. // Lets the shader know about the full-screen texture so it can
  546. virtual void SetFullScreenTextureHandle( ShaderAPITextureHandle_t h )
  547. {
  548. }
  549. void SetFloatRenderingParameter(int parm_number, float value)
  550. {
  551. }
  552. void SetIntRenderingParameter(int parm_number, int value)
  553. {
  554. }
  555. void SetTextureRenderingParameter(int parm_number, ITexture *pTexture)
  556. {
  557. }
  558. void SetVectorRenderingParameter(int parm_number, Vector const &value)
  559. {
  560. }
  561. float GetFloatRenderingParameter(int parm_number) const
  562. {
  563. return 0;
  564. }
  565. int GetIntRenderingParameter(int parm_number) const
  566. {
  567. return 0;
  568. }
  569. ITexture *GetTextureRenderingParameter(int parm_number) const
  570. {
  571. return NULL;
  572. }
  573. Vector GetVectorRenderingParameter(int parm_number) const
  574. {
  575. return Vector(0,0,0);
  576. }
  577. // Methods related to stencil
  578. virtual void SetStencilState( const ShaderStencilState_t &state ) {}
  579. void ClearStencilBufferRectangle( int xmin, int ymin, int xmax, int ymax,int value)
  580. {
  581. }
  582. virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices )
  583. {
  584. *pMaxVerts = 32768;
  585. *pMaxIndices = 32768;
  586. }
  587. // Returns the max possible vertices + indices to render in a single draw call
  588. virtual int GetMaxVerticesToRender( IMaterial *pMaterial )
  589. {
  590. return 32768;
  591. }
  592. virtual int GetMaxIndicesToRender( )
  593. {
  594. return 32768;
  595. }
  596. virtual int CompareSnapshots( StateSnapshot_t snapshot0, StateSnapshot_t snapshot1 ) { return 0; }
  597. virtual void DisableAllLocalLights() {}
  598. virtual bool SupportsMSAAMode( int nMSAAMode ) { return false; }
  599. // Hooks for firing PIX events from outside the Material System...
  600. virtual void SetPIXMarker( unsigned long color, const char *szName ) {}
  601. virtual void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc ) const {}
  602. virtual bool SupportsShadowDepthTextures() { return false; }
  603. virtual int NeedsShaderSRGBConversion(void) const { return 1; }
  604. virtual bool SupportsFetch4() { return false; }
  605. virtual void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) {}
  606. virtual void SetDisallowAccess( bool ) {}
  607. virtual void EnableShaderShaderMutex( bool ) {}
  608. virtual void ShaderLock() {}
  609. virtual void ShaderUnlock() {}
  610. virtual void EnableHWMorphing( bool bEnable ) {}
  611. ImageFormat GetNullTextureFormat( void ) { return IMAGE_FORMAT_ABGR8888; } // stub
  612. virtual void PushDeformation( DeformationBase_t const *Deformation )
  613. {
  614. }
  615. virtual void PopDeformation( )
  616. {
  617. }
  618. virtual int GetNumActiveDeformations() const
  619. {
  620. return 0;
  621. }
  622. virtual void ExecuteCommandBuffer( uint8 *pBuf )
  623. {
  624. }
  625. virtual void DrawInstances( int nInstanceCount, const MeshInstanceData_t *pInstances )
  626. {
  627. }
  628. void SetStandardTextureHandle(StandardTextureId_t,ShaderAPITextureHandle_t)
  629. {
  630. }
  631. int GetPackedDeformationInformation( int nMaskOfUnderstoodDeformations,
  632. float *pConstantValuesOut,
  633. int nBufferSize,
  634. int nMaximumDeformations,
  635. int *pNumDefsOut ) const
  636. {
  637. *pNumDefsOut = 0;
  638. return 0;
  639. }
  640. virtual bool OwnGPUResources( bool bEnable )
  641. {
  642. return false;
  643. }
  644. virtual void FlipCulling( bool bFlipCulling ) {}
  645. virtual void EnableSinglePassFlashlightMode( bool bEnable ) {}
  646. virtual bool SinglePassFlashlightModeEnabled( void ) { return false; }
  647. virtual void SetTextureFilterMode( Sampler_t sampler, TextureFilterMode_t nMode )
  648. {
  649. }
  650. private:
  651. enum
  652. {
  653. TRANSLUCENT = 0x1,
  654. ALPHATESTED = 0x2,
  655. VERTEX_AND_PIXEL_SHADERS = 0x4,
  656. DEPTHWRITE = 0x8,
  657. };
  658. void EnableAlphaToCoverage() {} ;
  659. void DisableAlphaToCoverage() {} ;
  660. ImageFormat GetShadowDepthTextureFormat() { return IMAGE_FORMAT_UNKNOWN; };
  661. //
  662. // NOTE: Under here are real methods being used by dx10 implementation
  663. // above is stuff I still have to port over.
  664. //
  665. private:
  666. void ClearShaderState( ShaderStateDx10_t* pState );
  667. void CommitStateChanges( bool bForce = false );
  668. private:
  669. CMeshDx10 m_Mesh;
  670. bool m_bResettingRenderState : 1;
  671. CFunctionCommit m_Commit;
  672. ShaderStateDx10_t m_DesiredState;
  673. ShaderStateDx10_t m_CurrentState;
  674. };
  675. //-----------------------------------------------------------------------------
  676. // Singleton global
  677. //-----------------------------------------------------------------------------
  678. extern CShaderAPIDx10* g_pShaderAPIDx10;
  679. #endif // SHADERAPIDX10_H