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.

502 lines
26 KiB

  1. //===== Copyright © 1996-2008, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef SHADERAPIDX8_H
  9. #define SHADERAPIDX8_H
  10. #include "shaderapibase.h"
  11. #include "shaderapi/ishadershadow.h"
  12. #include "materialsystem/IShader.h"
  13. #include "locald3dtypes.h"
  14. //-----------------------------------------------------------------------------
  15. // Vendor-specific defines
  16. //-----------------------------------------------------------------------------
  17. #define ATI_FETCH4_ENABLE MAKEFOURCC('G','E','T','4')
  18. #define ATI_FETCH4_DISABLE MAKEFOURCC('G','E','T','1')
  19. #define ATISAMP_FETCH4 D3DSAMP_MIPMAPLODBIAS
  20. //-----------------------------------------------------------------------------
  21. // Forward declarations
  22. //-----------------------------------------------------------------------------
  23. class CMeshBase;
  24. class CMeshBuilder;
  25. struct ShadowState_t;
  26. struct DepthTestState_t;
  27. class IMaterialInternal;
  28. struct MeshInstanceData_t;
  29. //#define _X360_GPU_OWN_RESOURCES
  30. #if defined( _X360_GPU_OWN_RESOURCES )
  31. #define IsGPUOwnSupported() ( true )
  32. #else
  33. #define IsGPUOwnSupported() ( false )
  34. #endif
  35. #if defined( _X360 )
  36. // Define this to link shader compilation code from D3DX9.LIB
  37. //#define X360_LINK_WITH_SHADER_COMPILE 1
  38. #endif
  39. #if defined( X360_LINK_WITH_SHADER_COMPILE ) && defined( _CERT )
  40. #error "Don't ship with X360_LINK_WITH_SHADER_COMPILE defined!! It causes 2MB+ DLL bloat. Only define it while revving XDKs."
  41. #endif
  42. //-----------------------------------------------------------------------------
  43. // State that matters to buffered meshes... (for debugging only)
  44. //-----------------------------------------------------------------------------
  45. struct BufferedState_t
  46. {
  47. D3DXMATRIX m_Transform[3];
  48. D3DVIEWPORT9 m_Viewport;
  49. int m_BoundTexture[16];
  50. void *m_VertexShader;
  51. void *m_PixelShader;
  52. };
  53. //-----------------------------------------------------------------------------
  54. // Compiled lighting state
  55. //-----------------------------------------------------------------------------
  56. struct CompiledLightingState_t
  57. {
  58. Vector4D m_AmbientLightCube[6];
  59. int m_nLocalLightCount;
  60. Vector4D m_PixelShaderLocalLights[6];
  61. Vector4D m_VertexShaderLocalLights[20];
  62. int m_VertexShaderLocalLightLoopControl[4];
  63. int m_VertexShaderLocalLightEnable[VERTEX_SHADER_LIGHT_ENABLE_BOOL_CONST_COUNT];
  64. };
  65. struct InstanceInfo_t
  66. {
  67. // Have we compiled various bits of lighting state?
  68. bool m_bAmbientCubeCompiled : 1;
  69. bool m_bPixelShaderLocalLightsCompiled : 1;
  70. bool m_bVertexShaderLocalLightsCompiled : 1;
  71. // Have we set various shader constants?
  72. bool m_bSetSkinConstants : 1;
  73. bool m_bSetLightVertexShaderConstants : 1;
  74. };
  75. //-----------------------------------------------------------------------------
  76. // The DX8 shader API
  77. //-----------------------------------------------------------------------------
  78. // FIXME: Remove this! Either move them into CShaderAPIBase or CShaderAPIDx8
  79. class IShaderAPIDX8 : public CShaderAPIBase
  80. {
  81. public:
  82. // Draws the mesh
  83. virtual void DrawMesh( CMeshBase *pMesh, int nCount, const MeshInstanceData_t *pInstances, VertexCompressionType_t nCompressionType, CompiledLightingState_t* pCompiledState, InstanceInfo_t *pInfo ) = 0;
  84. // Draw the mesh with the currently bound vertex and index buffers.
  85. virtual void DrawWithVertexAndIndexBuffers( void ) = 0;
  86. // Gets the current buffered state... (debug only)
  87. virtual void GetBufferedState( BufferedState_t &state ) = 0;
  88. // Gets the current backface cull state....
  89. virtual D3DCULL GetCullMode() const = 0;
  90. // Measures fill rate
  91. virtual void ComputeFillRate() = 0;
  92. // Selection mode methods
  93. virtual bool IsInSelectionMode() const = 0;
  94. // We hit somefin in selection mode
  95. virtual void RegisterSelectionHit( float minz, float maxz ) = 0;
  96. // Get the currently bound material
  97. virtual IMaterialInternal* GetBoundMaterial() = 0;
  98. // These methods are called by the transition table
  99. // They depend on dynamic state so can't exist inside the transition table
  100. virtual void ApplyZBias( const DepthTestState_t &shaderState ) = 0;
  101. virtual void ApplyCullEnable( bool bEnable ) = 0;
  102. virtual void ApplyFogMode( ShaderFogMode_t fogMode, bool bVertexFog, bool bSRGBWritesEnabled, bool bDisableGammaCorrection ) = 0;
  103. virtual int GetActualSamplerCount() const = 0;
  104. virtual bool IsRenderingMesh() const = 0;
  105. // Fog methods...
  106. virtual void EnableFixedFunctionFog( bool bFogEnable ) = 0;
  107. virtual int GetCurrentFrameCounter( void ) const = 0;
  108. // Workaround hack for visualization of selection mode
  109. virtual void SetupSelectionModeVisualizationState() = 0;
  110. virtual bool UsingSoftwareVertexProcessing() const = 0;
  111. //notification that the SRGB write state is being changed
  112. virtual void EnabledSRGBWrite( bool bEnabled ) = 0;
  113. virtual void SetSRGBWrite( bool bState ) = 0;
  114. // Alpha to coverage
  115. virtual void ApplyAlphaToCoverage( bool bEnable ) = 0;
  116. virtual void PrintfVA( char *fmt, va_list vargs ) = 0;
  117. virtual void Printf( char *fmt, ... ) = 0;
  118. virtual float Knob( char *knobname, float *setvalue = NULL ) = 0;
  119. virtual void NotifyShaderConstantsChangedInRenderPass() = 0;
  120. virtual void GenerateNonInstanceRenderState( MeshInstanceData_t *pInstance, CompiledLightingState_t** pCompiledState, InstanceInfo_t **pInfo ) = 0;
  121. // Executes the per-instance command buffer
  122. virtual void ExecuteInstanceCommandBuffer( const unsigned char *pCmdBuf, int nInstanceIndex, bool bForceStateSet ) = 0;
  123. // Sets the vertex decl
  124. virtual void SetVertexDecl( VertexFormat_t vertexFormat, bool bHasColorMesh, bool bUsingFlex, bool bUsingMorph, bool bUsingPreTessPatch, VertexStreamSpec_t *pStreamSpec ) = 0;
  125. // Set Tessellation Enable
  126. #if ENABLE_TESSELLATION
  127. virtual void SetTessellationMode( TessellationMode_t mode ) = 0;
  128. #else
  129. void SetTessellationMode( TessellationMode_t mode ) {}
  130. #endif
  131. virtual void AddShaderComboInformation( const ShaderComboSemantics_t *pSemantics ) = 0;
  132. virtual float GetLightMapScaleFactor() const = 0;
  133. };
  134. #ifdef _PS3
  135. //////////////////////////////////////////////////////////////////////////
  136. //
  137. // PS3 non-virtual implementation proxy
  138. //
  139. // cat shaderapidx8.h | nonvirtualscript.pl > shaderapidx8_ps3nonvirt.inl
  140. struct CPs3NonVirt_IShaderAPIDX8
  141. {
  142. //NONVIRTUALSCRIPTBEGIN
  143. //NONVIRTUALSCRIPT/PROXY/CPs3NonVirt_IShaderAPIDX8
  144. //NONVIRTUALSCRIPT/DELEGATE/g_ShaderAPIDX8.CShaderAPIDx8::
  145. static ShaderAPITextureHandle_t GetStandardTextureHandle(StandardTextureId_t id);
  146. //
  147. // IShaderAPI
  148. //
  149. static void SetViewports( int nCount, const ShaderViewport_t* pViewports, bool setImmediately = false );
  150. static int GetViewports( ShaderViewport_t* pViewports, int nMax );
  151. static void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight );
  152. static void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b );
  153. static void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a );
  154. static void BindVertexShader( VertexShaderHandle_t hVertexShader );
  155. static void BindGeometryShader( GeometryShaderHandle_t hGeometryShader );
  156. static void BindPixelShader( PixelShaderHandle_t hPixelShader );
  157. static void SetRasterState( const ShaderRasterState_t& state );
  158. static bool SetMode( void* hwnd, int nAdapter, const ShaderDeviceInfo_t &info );
  159. static void ChangeVideoMode( const ShaderDeviceInfo_t &info );
  160. static StateSnapshot_t TakeSnapshot( );
  161. static void TexMinFilter( ShaderTexFilterMode_t texFilterMode );
  162. static void TexMagFilter( ShaderTexFilterMode_t texFilterMode );
  163. static void TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode );
  164. static void CopyRenderTargetToTexture( ShaderAPITextureHandle_t textureHandle );
  165. static void Bind( IMaterial* pMaterial );
  166. static IMesh* GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool bBuffered = true, IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0);
  167. static IMesh* GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t vertexFormat, int nHWSkinBoneCount, bool bBuffered = true, IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0 );
  168. static bool IsTranslucent( StateSnapshot_t id );
  169. static bool IsAlphaTested( StateSnapshot_t id );
  170. static bool UsesVertexAndPixelShaders( StateSnapshot_t id );
  171. static bool IsDepthWriteEnabled( StateSnapshot_t id );
  172. static VertexFormat_t ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds );
  173. static VertexFormat_t ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds );
  174. static void BeginPass( StateSnapshot_t snapshot );
  175. static void RenderPass( const unsigned char *pInstanceCommandBuffer, int nPass, int nPassCount );
  176. static void SetNumBoneWeights( int numBones );
  177. static void SetLights( int nCount, const LightDesc_t *pDesc );
  178. static void SetLightingOrigin( Vector vLightingOrigin );
  179. static void SetLightingState( const MaterialLightingState_t& state );
  180. static void SetAmbientLightCube( Vector4D cube[6] );
  181. static void ShadeMode( ShaderShadeMode_t mode );
  182. static void CullMode( MaterialCullMode_t cullMode );
  183. static void FlipCullMode();
  184. static void ForceDepthFuncEquals( bool bEnable );
  185. static void OverrideDepthEnable( bool bEnable, bool bDepthWriteEnable, bool bDepthTestEnable = true );
  186. static void SetHeightClipZ( float z );
  187. static void SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode );
  188. static void SetClipPlane( int index, const float *pPlane );
  189. static void EnableClipPlane( int index, bool bEnable );
  190. static ImageFormat GetNearestSupportedFormat( ImageFormat fmt );
  191. static ImageFormat GetNearestRenderTargetFormat( ImageFormat fmt );
  192. static bool DoRenderTargetsNeedSeparateDepthBuffer();
  193. static ShaderAPITextureHandle_t CreateTexture( int width, int height, int depth, ImageFormat dstImageFormat, int numMipLevels, int numCopies, int flags, const char *pDebugName, const char *pTextureGroupName );
  194. static void DeleteTexture( ShaderAPITextureHandle_t textureHandle );
  195. static ShaderAPITextureHandle_t CreateDepthTexture( ImageFormat renderTargetFormat, int width, int height, const char *pDebugName, bool bTexture, bool bAliasDepthSurfaceOverColorX360 = false );
  196. static bool IsTexture( ShaderAPITextureHandle_t textureHandle );
  197. static bool IsTextureResident( ShaderAPITextureHandle_t textureHandle );
  198. static void ModifyTexture( ShaderAPITextureHandle_t textureHandle );
  199. static void TexImage2D( int level, int cubeFaceID, ImageFormat dstFormat, int zOffset, int width, int height, ImageFormat srcFormat, bool bSrcIsTiled, void *imageData );
  200. static void TexSubImage2D( int level, int cubeFaceID, int xOffset, int yOffset, int zOffset, int width, int height, ImageFormat srcFormat, int srcStride, bool bSrcIsTiled, void *imageData );
  201. static bool TexLock( int level, int cubeFaceID, int xOffset, int yOffset, int width, int height, CPixelWriter& writer );
  202. static void TexUnlock( );
  203. static void UpdateTexture( int xOffset, int yOffset, int w, int h, ShaderAPITextureHandle_t hDstTexture, ShaderAPITextureHandle_t hSrcTexture );
  204. static void *LockTex( ShaderAPITextureHandle_t hTexture );
  205. static void UnlockTex( ShaderAPITextureHandle_t hTexture );
  206. static void TexSetPriority( int priority );
  207. static void BindTexture( Sampler_t sampler, TextureBindFlags_t nBindFlags, ShaderAPITextureHandle_t textureHandle );
  208. static void SetRenderTarget( ShaderAPITextureHandle_t colorTextureHandle = SHADER_RENDERTARGET_BACKBUFFER, ShaderAPITextureHandle_t depthTextureHandle = SHADER_RENDERTARGET_DEPTHBUFFER );
  209. static void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth );
  210. static void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat );
  211. static void ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride );
  212. static void FlushHardware();
  213. static void BeginFrame();
  214. static void EndFrame();
  215. static int SelectionMode( bool selectionMode );
  216. static void SelectionBuffer( unsigned int* pBuffer, int size );
  217. static void ClearSelectionNames( );
  218. static void LoadSelectionName( int name );
  219. static void PushSelectionName( int name );
  220. static void PopSelectionName();
  221. static void ForceHardwareSync();
  222. static void ClearSnapshots();
  223. static void FogStart( float fStart );
  224. static void FogEnd( float fEnd );
  225. static void SetFogZ( float fogZ );
  226. static void SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b );
  227. static void GetSceneFogColor( unsigned char *rgb );
  228. static void SceneFogMode( MaterialFogMode_t fogMode );
  229. static bool CanDownloadTextures();
  230. static void ResetRenderState( bool bFullReset = true );
  231. static int GetCurrentDynamicVBSize();
  232. static void DestroyVertexBuffers( bool bExitingLevel = false );
  233. static void EvictManagedResources();
  234. static void GetGPUMemoryStats( GPUMemoryStats &stats );
  235. static void SetAnisotropicLevel( int nAnisotropyLevel );
  236. static void SyncToken( const char *pToken );
  237. static void SetStandardVertexShaderConstants( float fOverbright );
  238. static ShaderAPIOcclusionQuery_t CreateOcclusionQueryObject();
  239. static void DestroyOcclusionQueryObject( ShaderAPIOcclusionQuery_t q );
  240. static void BeginOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t q );
  241. static void EndOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t q );
  242. static int OcclusionQuery_GetNumPixelsRendered( ShaderAPIOcclusionQuery_t hQuery, bool bFlush = false );
  243. static void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture );
  244. static void ClearVertexAndPixelShaderRefCounts();
  245. static void PurgeUnusedVertexAndPixelShaders();
  246. static void DXSupportLevelChanged( int nDXLevel );
  247. static void EnableUserClipTransformOverride( bool bEnable );
  248. static void UserClipTransform( const VMatrix &worldToView );
  249. static void SetRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t colorTextureHandle = SHADER_RENDERTARGET_BACKBUFFER, ShaderAPITextureHandle_t depthTextureHandle = SHADER_RENDERTARGET_DEPTHBUFFER );
  250. static void CopyRenderTargetToTextureEx( ShaderAPITextureHandle_t textureHandle, int nRenderTargetID, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL );
  251. static void HandleDeviceLost();
  252. static void EnableLinearColorSpaceFrameBuffer( bool bEnable );
  253. static void SetFullScreenTextureHandle( ShaderAPITextureHandle_t h );
  254. static void SetFloatRenderingParameter(int parm_number, float value);
  255. static void SetIntRenderingParameter(int parm_number, int value);
  256. static void SetVectorRenderingParameter(int parm_number, Vector const &value);
  257. static float GetFloatRenderingParameter(int parm_number);
  258. static int GetIntRenderingParameter(int parm_number);
  259. static Vector GetVectorRenderingParameter(int parm_number);
  260. static void SetFastClipPlane( const float *pPlane );
  261. static void EnableFastClip( bool bEnable );
  262. static void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices );
  263. static int GetMaxVerticesToRender( IMaterial *pMaterial );
  264. static int GetMaxIndicesToRender( );
  265. static void SetStencilState( const ShaderStencilState_t& state );
  266. static void ClearStencilBufferRectangle(int xmin, int ymin, int xmax, int ymax, int value);
  267. static void DisableAllLocalLights();
  268. static int CompareSnapshots( StateSnapshot_t snapshot0, StateSnapshot_t snapshot1 );
  269. static IMesh *GetFlexMesh();
  270. static void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture );
  271. static void SetCascadedShadowMappingState( const CascadedShadowMappingState_t &state, ITexture *pDepthTextureAtlas );
  272. static const CascadedShadowMappingState_t &GetCascadedShadowMappingState( ITexture **pDepthTextureAtlas, bool bLightMapScale = false );
  273. static bool SupportsMSAAMode( int nMSAAMode );
  274. static bool PostQueuedTexture( const void *pData, int nSize, ShaderAPITextureHandle_t *pHandles, int nHandles, int nWidth, int nHeight, int nDepth, int nMips, int *pRefCount );
  275. static void ReloadZcullMemory( int nStencilRef );
  276. static void AntiAliasingHint( int nHint );
  277. static void FlushTextureCache();
  278. static void InvokeGpuDataTransferCache( uint32 uiDepthBufferCacheOperation );
  279. static bool OwnGPUResources( bool bEnable );
  280. static void GetFogDistances( float *fStart, float *fEnd, float *fFogZ );
  281. static void BeginPIXEvent( unsigned long color, const char *szName );
  282. static void EndPIXEvent();
  283. static void SetPIXMarker( unsigned long color, const char *szName );
  284. static void EnableAlphaToCoverage();
  285. static void DisableAlphaToCoverage();
  286. static void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc );
  287. static int VertexFormatSize( VertexFormat_t vertexFormat );
  288. static void SetDisallowAccess( bool b );
  289. static void EnableShaderShaderMutex( bool b );
  290. static void ShaderLock();
  291. static void ShaderUnlock();
  292. static void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias );
  293. static void BindVertexBuffer( int nStreamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 );
  294. static void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes );
  295. static void Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount );
  296. static void PerformFullScreenStencilOperation();
  297. static void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor );
  298. static bool SupportsCSAAMode( int nNumSamples, int nQualityLevel );
  299. static void InvalidateDelayedShaderConstants();
  300. static float GammaToLinear_HardwareSpecific( float fGamma );
  301. static float LinearToGamma_HardwareSpecific( float fLinear );
  302. static void SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture );
  303. static void BindVertexTexture( VertexTextureSampler_t nSampler, ShaderAPITextureHandle_t textureHandle );
  304. static void EnableHWMorphing( bool bEnable );
  305. static void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights );
  306. static void FogMaxDensity( float flMaxDensity );
  307. static void CreateTextures( ShaderAPITextureHandle_t *pHandles, int count, int width, int height, int depth, ImageFormat dstImageFormat, int numMipLevels, int numCopies, int flags, const char *pDebugName, const char *pTextureGroupName );
  308. static void AcquireThreadOwnership();
  309. static void ReleaseThreadOwnership();
  310. static void EnableBuffer2FramesAhead( bool bEnable );
  311. static void FlipCulling( bool bFlipCulling );
  312. static void SetTextureRenderingParameter(int parm_number, ITexture *pTexture);
  313. static void EnableSinglePassFlashlightMode( bool bEnable );
  314. static void MatrixMode( MaterialMatrixMode_t matrixMode );
  315. static void PushMatrix();
  316. static void PopMatrix();
  317. static void LoadMatrix( float *m );
  318. static void MultMatrix( float *m );
  319. static void MultMatrixLocal( float *m );
  320. static void LoadIdentity();
  321. static void LoadCameraToWorld();
  322. static void Ortho( double left, double right, double bottom, double top, double zNear, double zFar );
  323. static void PerspectiveX( double fovx, double aspect, double zNear, double zFar );
  324. static void PickMatrix( int x, int y, int width, int height );
  325. static void Rotate( float angle, float x, float y, float z );
  326. static void Translate( float x, float y, float z );
  327. static void Scale( float x, float y, float z );
  328. static void ScaleXY( float x, float y );
  329. static void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right );
  330. static void LoadBoneMatrix( int boneIndex, const float *m );
  331. static void SetStandardTextureHandle( StandardTextureId_t nId, ShaderAPITextureHandle_t nHandle );
  332. static void DrawInstances( int nInstanceCount, const MeshInstanceData_t *pInstance );
  333. static void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable );
  334. static void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable );
  335. static void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth );
  336. static void OnPresent();
  337. static void UpdateGameTime( float flTime );
  338. //
  339. // IShaderDynamicAPI
  340. //
  341. static double CurrentTime();
  342. static void GetLightmapDimensions( int *w, int *h );
  343. static MaterialFogMode_t GetSceneFogMode( );
  344. static void SetVertexShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false );
  345. static void SetPixelShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false );
  346. static void SetDefaultState();
  347. static void GetWorldSpaceCameraPosition( float* pPos );
  348. static void GetWorldSpaceCameraDirection( float* pDir );
  349. static int GetCurrentNumBones();
  350. static MaterialFogMode_t GetCurrentFogType();
  351. static void SetVertexShaderIndex( int vshIndex = -1 );
  352. static void SetPixelShaderIndex( int pshIndex = 0 );
  353. static void GetBackBufferDimensions( int& width, int& height );
  354. static const AspectRatioInfo_t &GetAspectRatioInfo( void );
  355. static void GetCurrentRenderTargetDimensions( int& nWidth, int& nHeight );
  356. static void GetCurrentViewport( int& nX, int& nY, int& nWidth, int& nHeight );
  357. static void SetPixelShaderFogParams( int reg );
  358. static bool InFlashlightMode();
  359. static const FlashlightState_t &GetFlashlightState( VMatrix &worldToTexture );
  360. static bool InEditorMode();
  361. static void BindStandardTexture( Sampler_t sampler, TextureBindFlags_t nBindFlags, StandardTextureId_t id );
  362. static ITexture *GetRenderTargetEx( int nRenderTargetID );
  363. static void SetToneMappingScaleLinear( const Vector &scale );
  364. static const Vector &GetToneMappingScaleLinear();
  365. static const FlashlightState_t &GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **pFlashlightDepthTexture );
  366. static void GetDX9LightState( LightState_t *state );
  367. static int GetPixelFogCombo( );
  368. static void BindStandardVertexTexture( VertexTextureSampler_t sampler, StandardTextureId_t id );
  369. static bool IsHWMorphingEnabled( );
  370. static void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id );
  371. static void SetBooleanVertexShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false );
  372. static void SetIntegerVertexShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false );
  373. static void SetBooleanPixelShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false );
  374. static void SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false );
  375. static bool ShouldWriteDepthToDestAlpha();
  376. static void GetMatrix( MaterialMatrixMode_t matrixMode, float *dst );
  377. static void PushDeformation( DeformationBase_t const *Deformation );
  378. static void PopDeformation( );
  379. static int GetNumActiveDeformations();
  380. static int GetPackedDeformationInformation( int nMaskOfUnderstoodDeformations, float *pConstantValuesOut, int nBufferSize, int nMaximumDeformations, int *pNumDefsOut );
  381. static void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords );
  382. static void ExecuteCommandBuffer( uint8 *pCmdBuffer );
  383. #ifdef _PS3
  384. static void ExecuteCommandBufferPPU( uint8 *pCmdBuffer );
  385. #endif
  386. static void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo );
  387. static ITexture *GetTextureRenderingParameter(int parm_number);
  388. static void SetScreenSizeForVPOS( int pshReg = 32 );
  389. static void SetVSNearAndFarZ( int vshReg );
  390. static float GetFarZ();
  391. static bool SinglePassFlashlightModeEnabled();
  392. static void GetActualProjectionMatrix( float *pMatrix );
  393. static void SetDepthFeatheringShaderConstants( int iConstant, float fDepthBlendScale );
  394. static void GetFlashlightShaderInfo( bool *pShadowsEnabled, bool *pUberLight );
  395. static float GetFlashlightAmbientOcclusion( );
  396. static void SetTextureFilterMode( Sampler_t sampler, TextureFilterMode_t nMode );
  397. static TessellationMode_t GetTessellationMode();
  398. static float GetSubDHeight();
  399. static bool IsRenderingPaint();
  400. static bool IsStereoActiveThisFrame();
  401. //
  402. // CShaderAPIBase
  403. //
  404. static bool OnDeviceInit();
  405. static void OnDeviceShutdown();
  406. static void AdvancePIXFrame();
  407. static void ReleaseShaderObjects( bool bReleaseManagedResources = true );
  408. static void RestoreShaderObjects();
  409. static IDirect3DBaseTexture* GetD3DTexture( ShaderAPITextureHandle_t hTexture );
  410. static void GetPs3Texture(void* pPs3tex, ShaderAPITextureHandle_t hTexture );
  411. static void GetPs3Texture(void* pPs3tex, StandardTextureId_t nTextureId );
  412. static void QueueResetRenderState();
  413. //
  414. // IShaderAPIDX8
  415. //
  416. static void DrawMesh( CMeshBase *pMesh, int nCount, const MeshInstanceData_t *pInstances, VertexCompressionType_t nCompressionType, CompiledLightingState_t* pCompiledState, InstanceInfo_t *pInfo );
  417. static void DrawWithVertexAndIndexBuffers();
  418. static void GetBufferedState( BufferedState_t &state );
  419. static D3DCULL GetCullMode();
  420. static void ComputeFillRate();
  421. static bool IsInSelectionMode();
  422. static void RegisterSelectionHit( float minz, float maxz );
  423. static IMaterialInternal* GetBoundMaterial();
  424. static void ApplyZBias( const DepthTestState_t& shaderState );
  425. static void ApplyCullEnable( bool bEnable );
  426. static void ApplyFogMode( ShaderFogMode_t fogMode, bool bVertexFog, bool bSRGBWritesEnabled, bool bDisableGammaCorrection );
  427. static int GetActualSamplerCount();
  428. static bool IsRenderingMesh();
  429. static void EnableFixedFunctionFog( bool bFogEnable );
  430. static int GetCurrentFrameCounter();
  431. static void SetupSelectionModeVisualizationState();
  432. static bool UsingSoftwareVertexProcessing();
  433. static void EnabledSRGBWrite( bool bEnabled );
  434. static void ApplyAlphaToCoverage( bool bEnable );
  435. static void PrintfVA( char *fmt, va_list vargs );
  436. static void Printf( char *fmt, ... ) {}
  437. static float Knob( char *knobname, float *setvalue = NULL );
  438. static void NotifyShaderConstantsChangedInRenderPass();
  439. static void GenerateNonInstanceRenderState( MeshInstanceData_t *pInstance, CompiledLightingState_t** pCompiledState, InstanceInfo_t **pInfo );
  440. static void ExecuteInstanceCommandBuffer( const unsigned char *pCmdBuf, int nInstanceIndex, bool bForceStateSet );
  441. static void SetVertexDecl( VertexFormat_t vertexFormat, bool bHasColorMesh, bool bUsingFlex, bool bUsingMorph, bool bUsingPreTessPatch, VertexStreamSpec_t *pStreamSpec );
  442. static void SetTessellationMode( TessellationMode_t mode );
  443. static IMesh *GetExternalMesh( const ExternalMeshInfo_t& info );
  444. static void SetExternalMeshData( IMesh *pMesh, const ExternalMeshData_t &data );
  445. static IIndexBuffer *GetExternalIndexBuffer( int nIndexCount, uint16 *pIndexData );
  446. static void FlushGPUCache( void *pBaseAddr, size_t nSizeInBytes );
  447. static void AddShaderComboInformation( const ShaderComboSemantics_t *pSemantics );
  448. static void SetSRGBWrite( bool bState );
  449. static void BeginConsoleZPass2( int nNumDynamicIndicesNeeded );
  450. static void EndConsoleZPass();
  451. //NONVIRTUALSCRIPTEND
  452. };
  453. #endif
  454. #endif // SHADERAPIDX8_H