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.

633 lines
26 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef ISHADERAPI_H
  9. #define ISHADERAPI_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "mathlib/vector4d.h"
  14. #include "shaderapi/ishaderdynamic.h"
  15. #include "shaderapi/IShaderDevice.h"
  16. #include "materialsystem/deformations.h"
  17. //-----------------------------------------------------------------------------
  18. // forward declarations
  19. //-----------------------------------------------------------------------------
  20. class IShaderUtil;
  21. class IFileSystem;
  22. class CPixelWriter;
  23. class CMeshBuilder;
  24. struct MaterialVideoMode_t;
  25. class IMesh;
  26. class IVertexBuffer;
  27. class IIndexBuffer;
  28. struct MeshDesc_t;
  29. enum MaterialCullMode_t;
  30. class IDataCache;
  31. struct MorphWeight_t;
  32. class IVTFTexture;
  33. //-----------------------------------------------------------------------------
  34. // This must match the definition in playback.cpp!
  35. //-----------------------------------------------------------------------------
  36. enum ShaderRenderTarget_t
  37. {
  38. SHADER_RENDERTARGET_BACKBUFFER = -1,
  39. SHADER_RENDERTARGET_DEPTHBUFFER = -1,
  40. // GR - no RT, used to disable depth buffer
  41. SHADER_RENDERTARGET_NONE = -2,
  42. };
  43. //-----------------------------------------------------------------------------
  44. // This must match the definition in playback.cpp!
  45. //-----------------------------------------------------------------------------
  46. typedef int ShaderAPITextureHandle_t;
  47. #define INVALID_SHADERAPI_TEXTURE_HANDLE 0
  48. //-----------------------------------------------------------------------------
  49. // The state snapshot handle
  50. //-----------------------------------------------------------------------------
  51. typedef short StateSnapshot_t;
  52. //-----------------------------------------------------------------------------
  53. // The state snapshot handle
  54. //-----------------------------------------------------------------------------
  55. typedef int ShaderDLL_t;
  56. //-----------------------------------------------------------------------------
  57. // Texture creation
  58. //-----------------------------------------------------------------------------
  59. enum CreateTextureFlags_t
  60. {
  61. TEXTURE_CREATE_CUBEMAP = 0x0001,
  62. TEXTURE_CREATE_RENDERTARGET = 0x0002,
  63. TEXTURE_CREATE_MANAGED = 0x0004,
  64. TEXTURE_CREATE_DEPTHBUFFER = 0x0008,
  65. TEXTURE_CREATE_DYNAMIC = 0x0010,
  66. TEXTURE_CREATE_AUTOMIPMAP = 0x0020,
  67. TEXTURE_CREATE_VERTEXTEXTURE = 0x0040, // for internal use only
  68. TEXTURE_CREATE_FALLBACK = 0x0080, // 360 only
  69. TEXTURE_CREATE_NOD3DMEMORY = 0x0100, // 360 only
  70. TEXTURE_CREATE_SYSMEM = 0x0200, // This texture should be alloc'd in the sysmem pool
  71. TEXTURE_CREATE_UNUSED4 = 0x0400, // Dead
  72. TEXTURE_CREATE_UNUSED5 = 0x0800, // Dead
  73. TEXTURE_CREATE_UNFILTERABLE_OK = 0x1000,
  74. TEXTURE_CREATE_CANCONVERTFORMAT = 0x2000, // 360 only, allow format conversions at load
  75. TEXTURE_CREATE_SRGB = 0x4000, // Posix/GL only, for textures which are SRGB-readable
  76. };
  77. //-----------------------------------------------------------------------------
  78. // Fill modes
  79. //-----------------------------------------------------------------------------
  80. enum ShaderFillMode_t
  81. {
  82. SHADER_FILL_SOLID = 0,
  83. SHADER_FILL_WIREFRAME,
  84. };
  85. //-----------------------------------------------------------------------------
  86. // Rasterization state object
  87. //-----------------------------------------------------------------------------
  88. struct ShaderRasterState_t
  89. {
  90. ShaderFillMode_t m_FillMode;
  91. MaterialCullMode_t m_CullMode;
  92. bool m_bCullEnable : 1;
  93. bool m_bDepthBias : 1;
  94. bool m_bScissorEnable : 1;
  95. bool m_bMultisampleEnable : 1;
  96. };
  97. //-----------------------------------------------------------------------------
  98. // Used for occlusion queries
  99. //-----------------------------------------------------------------------------
  100. DECLARE_POINTER_HANDLE( ShaderAPIOcclusionQuery_t );
  101. #define INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE ( (ShaderAPIOcclusionQuery_t)0 )
  102. enum ShaderAPIOcclusionQueryResult_t
  103. {
  104. OCCLUSION_QUERY_RESULT_PENDING = -1,
  105. OCCLUSION_QUERY_RESULT_ERROR = -2
  106. };
  107. #define OCCLUSION_QUERY_FINISHED( iQueryResult ) ( ( iQueryResult ) != OCCLUSION_QUERY_RESULT_PENDING )
  108. //-----------------------------------------------------------------------------
  109. // This is what the material system gets to see.
  110. //-----------------------------------------------------------------------------
  111. #define SHADERAPI_INTERFACE_VERSION "ShaderApi030"
  112. abstract_class IShaderAPI : public IShaderDynamicAPI
  113. {
  114. public:
  115. //
  116. // NOTE: These methods have been ported to DX10
  117. //
  118. // Viewport methods
  119. virtual void SetViewports( int nCount, const ShaderViewport_t* pViewports ) = 0;
  120. virtual int GetViewports( ShaderViewport_t* pViewports, int nMax ) const = 0;
  121. // Buffer clearing
  122. virtual void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight ) = 0;
  123. virtual void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b ) = 0;
  124. virtual void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ) = 0;
  125. // Methods related to binding shaders
  126. virtual void BindVertexShader( VertexShaderHandle_t hVertexShader ) = 0;
  127. virtual void BindGeometryShader( GeometryShaderHandle_t hGeometryShader ) = 0;
  128. virtual void BindPixelShader( PixelShaderHandle_t hPixelShader ) = 0;
  129. // Methods related to state objects
  130. virtual void SetRasterState( const ShaderRasterState_t& state ) = 0;
  131. //
  132. // NOTE: These methods have not yet been ported to DX10
  133. //
  134. // Sets the mode...
  135. virtual bool SetMode( void* hwnd, int nAdapter, const ShaderDeviceInfo_t &info ) = 0;
  136. virtual void ChangeVideoMode( const ShaderDeviceInfo_t &info ) = 0;
  137. // Returns the snapshot id for the shader state
  138. virtual StateSnapshot_t TakeSnapshot( ) = 0;
  139. virtual void TexMinFilter( ShaderTexFilterMode_t texFilterMode ) = 0;
  140. virtual void TexMagFilter( ShaderTexFilterMode_t texFilterMode ) = 0;
  141. virtual void TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode ) = 0;
  142. virtual void CopyRenderTargetToTexture( ShaderAPITextureHandle_t textureHandle ) = 0;
  143. // Binds a particular material to render with
  144. virtual void Bind( IMaterial* pMaterial ) = 0;
  145. // Flushes any primitives that are buffered
  146. virtual void FlushBufferedPrimitives() = 0;
  147. // Gets the dynamic mesh; note that you've got to render the mesh
  148. // before calling this function a second time. Clients should *not*
  149. // call DestroyStaticMesh on the mesh returned by this call.
  150. virtual IMesh* GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool bBuffered = true,
  151. IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0) = 0;
  152. virtual IMesh* GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t vertexFormat, int nHWSkinBoneCount,
  153. bool bBuffered = true, IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0 ) = 0;
  154. // Methods to ask about particular state snapshots
  155. virtual bool IsTranslucent( StateSnapshot_t id ) const = 0;
  156. virtual bool IsAlphaTested( StateSnapshot_t id ) const = 0;
  157. virtual bool UsesVertexAndPixelShaders( StateSnapshot_t id ) const = 0;
  158. virtual bool IsDepthWriteEnabled( StateSnapshot_t id ) const = 0;
  159. // Gets the vertex format for a set of snapshot ids
  160. virtual VertexFormat_t ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds ) const = 0;
  161. // What fields in the vertex do we actually use?
  162. virtual VertexFormat_t ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds ) const = 0;
  163. // Begins a rendering pass
  164. virtual void BeginPass( StateSnapshot_t snapshot ) = 0;
  165. // Renders a single pass of a material
  166. virtual void RenderPass( int nPass, int nPassCount ) = 0;
  167. // Set the number of bone weights
  168. virtual void SetNumBoneWeights( int numBones ) = 0;
  169. // Sets the lights
  170. virtual void SetLight( int lightNum, const LightDesc_t& desc ) = 0;
  171. // Lighting origin for the current model
  172. virtual void SetLightingOrigin( Vector vLightingOrigin ) = 0;
  173. virtual void SetAmbientLight( float r, float g, float b ) = 0;
  174. virtual void SetAmbientLightCube( Vector4D cube[6] ) = 0;
  175. // The shade mode
  176. virtual void ShadeMode( ShaderShadeMode_t mode ) = 0;
  177. // The cull mode
  178. virtual void CullMode( MaterialCullMode_t cullMode ) = 0;
  179. // Force writes only when z matches. . . useful for stenciling things out
  180. // by rendering the desired Z values ahead of time.
  181. virtual void ForceDepthFuncEquals( bool bEnable ) = 0;
  182. // Forces Z buffering to be on or off
  183. virtual void OverrideDepthEnable( bool bEnable, bool bDepthEnable ) = 0;
  184. virtual void SetHeightClipZ( float z ) = 0;
  185. virtual void SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode ) = 0;
  186. virtual void SetClipPlane( int index, const float *pPlane ) = 0;
  187. virtual void EnableClipPlane( int index, bool bEnable ) = 0;
  188. // Put all the model matrices into vertex shader constants.
  189. virtual void SetSkinningMatrices() = 0;
  190. // Returns the nearest supported format
  191. virtual ImageFormat GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired = true ) const = 0;
  192. virtual ImageFormat GetNearestRenderTargetFormat( ImageFormat fmt ) const = 0;
  193. // When AA is enabled, render targets are not AA and require a separate
  194. // depth buffer.
  195. virtual bool DoRenderTargetsNeedSeparateDepthBuffer() const = 0;
  196. // Texture management methods
  197. // For CreateTexture also see CreateTextures below
  198. virtual ShaderAPITextureHandle_t CreateTexture(
  199. int width,
  200. int height,
  201. int depth,
  202. ImageFormat dstImageFormat,
  203. int numMipLevels,
  204. int numCopies,
  205. int flags,
  206. const char *pDebugName,
  207. const char *pTextureGroupName ) = 0;
  208. virtual void DeleteTexture( ShaderAPITextureHandle_t textureHandle ) = 0;
  209. virtual ShaderAPITextureHandle_t CreateDepthTexture(
  210. ImageFormat renderTargetFormat,
  211. int width,
  212. int height,
  213. const char *pDebugName,
  214. bool bTexture ) = 0;
  215. virtual bool IsTexture( ShaderAPITextureHandle_t textureHandle ) = 0;
  216. virtual bool IsTextureResident( ShaderAPITextureHandle_t textureHandle ) = 0;
  217. // Indicates we're going to be modifying this texture
  218. // TexImage2D, TexSubImage2D, TexWrap, TexMinFilter, and TexMagFilter
  219. // all use the texture specified by this function.
  220. virtual void ModifyTexture( ShaderAPITextureHandle_t textureHandle ) = 0;
  221. virtual void TexImage2D(
  222. int level,
  223. int cubeFaceID,
  224. ImageFormat dstFormat,
  225. int zOffset,
  226. int width,
  227. int height,
  228. ImageFormat srcFormat,
  229. bool bSrcIsTiled, // NOTE: for X360 only
  230. void *imageData ) = 0;
  231. virtual void TexSubImage2D(
  232. int level,
  233. int cubeFaceID,
  234. int xOffset,
  235. int yOffset,
  236. int zOffset,
  237. int width,
  238. int height,
  239. ImageFormat srcFormat,
  240. int srcStride,
  241. bool bSrcIsTiled, // NOTE: for X360 only
  242. void *imageData ) = 0;
  243. virtual void TexImageFromVTF( IVTFTexture* pVTF, int iVTFFrame ) = 0;
  244. // An alternate (and faster) way of writing image data
  245. // (locks the current Modify Texture). Use the pixel writer to write the data
  246. // after Lock is called
  247. // Doesn't work for compressed textures
  248. virtual bool TexLock( int level, int cubeFaceID, int xOffset, int yOffset,
  249. int width, int height, CPixelWriter& writer ) = 0;
  250. virtual void TexUnlock( ) = 0;
  251. // These are bound to the texture
  252. virtual void TexSetPriority( int priority ) = 0;
  253. // Sets the texture state
  254. virtual void BindTexture( Sampler_t sampler, ShaderAPITextureHandle_t textureHandle ) = 0;
  255. // Set the render target to a texID.
  256. // Set to SHADER_RENDERTARGET_BACKBUFFER if you want to use the regular framebuffer.
  257. // Set to SHADER_RENDERTARGET_DEPTHBUFFER if you want to use the regular z buffer.
  258. virtual void SetRenderTarget( ShaderAPITextureHandle_t colorTextureHandle = SHADER_RENDERTARGET_BACKBUFFER,
  259. ShaderAPITextureHandle_t depthTextureHandle = SHADER_RENDERTARGET_DEPTHBUFFER ) = 0;
  260. // stuff that isn't to be used from within a shader
  261. virtual void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth ) = 0;
  262. virtual void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat ) = 0;
  263. virtual void ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride ) = 0;
  264. virtual void FlushHardware() = 0;
  265. // Use this to begin and end the frame
  266. virtual void BeginFrame() = 0;
  267. virtual void EndFrame() = 0;
  268. // Selection mode methods
  269. virtual int SelectionMode( bool selectionMode ) = 0;
  270. virtual void SelectionBuffer( unsigned int* pBuffer, int size ) = 0;
  271. virtual void ClearSelectionNames( ) = 0;
  272. virtual void LoadSelectionName( int name ) = 0;
  273. virtual void PushSelectionName( int name ) = 0;
  274. virtual void PopSelectionName() = 0;
  275. // Force the hardware to finish whatever it's doing
  276. virtual void ForceHardwareSync() = 0;
  277. // Used to clear the transition table when we know it's become invalid.
  278. virtual void ClearSnapshots() = 0;
  279. virtual void FogStart( float fStart ) = 0;
  280. virtual void FogEnd( float fEnd ) = 0;
  281. virtual void SetFogZ( float fogZ ) = 0;
  282. // Scene fog state.
  283. virtual void SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b ) = 0;
  284. virtual void GetSceneFogColor( unsigned char *rgb ) = 0;
  285. virtual void SceneFogMode( MaterialFogMode_t fogMode ) = 0;
  286. // Can we download textures?
  287. virtual bool CanDownloadTextures() const = 0;
  288. virtual void ResetRenderState( bool bFullReset = true ) = 0;
  289. // We use smaller dynamic VBs during level transitions, to free up memory
  290. virtual int GetCurrentDynamicVBSize( void ) = 0;
  291. virtual void DestroyVertexBuffers( bool bExitingLevel = false ) = 0;
  292. virtual void EvictManagedResources() = 0;
  293. // Level of anisotropic filtering
  294. virtual void SetAnisotropicLevel( int nAnisotropyLevel ) = 0;
  295. // For debugging and building recording files. This will stuff a token into the recording file,
  296. // then someone doing a playback can watch for the token.
  297. virtual void SyncToken( const char *pToken ) = 0;
  298. // Setup standard vertex shader constants (that don't change)
  299. // This needs to be called anytime that overbright changes.
  300. virtual void SetStandardVertexShaderConstants( float fOverbright ) = 0;
  301. //
  302. // Occlusion query support
  303. //
  304. // Allocate and delete query objects.
  305. virtual ShaderAPIOcclusionQuery_t CreateOcclusionQueryObject( void ) = 0;
  306. virtual void DestroyOcclusionQueryObject( ShaderAPIOcclusionQuery_t ) = 0;
  307. // Bracket drawing with begin and end so that we can get counts next frame.
  308. virtual void BeginOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t ) = 0;
  309. virtual void EndOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t ) = 0;
  310. // OcclusionQuery_GetNumPixelsRendered
  311. // Get the number of pixels rendered between begin and end on an earlier frame.
  312. // Calling this in the same frame is a huge perf hit!
  313. // Returns iQueryResult:
  314. // iQueryResult >= 0 - iQueryResult is the number of pixels rendered
  315. // OCCLUSION_QUERY_RESULT_PENDING - query results are not available yet
  316. // OCCLUSION_QUERY_RESULT_ERROR - query failed
  317. // Use OCCLUSION_QUERY_FINISHED( iQueryResult ) to test if query finished.
  318. virtual int OcclusionQuery_GetNumPixelsRendered( ShaderAPIOcclusionQuery_t hQuery, bool bFlush = false ) = 0;
  319. virtual void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture ) = 0;
  320. virtual void ClearVertexAndPixelShaderRefCounts() = 0;
  321. virtual void PurgeUnusedVertexAndPixelShaders() = 0;
  322. // Called when the dx support level has changed
  323. virtual void DXSupportLevelChanged() = 0;
  324. // By default, the material system applies the VIEW and PROJECTION matrices to the user clip
  325. // planes (which are specified in world space) to generate projection-space user clip planes
  326. // Occasionally (for the particle system in hl2, for example), we want to override that
  327. // behavior and explictly specify a View transform for user clip planes. The PROJECTION
  328. // will be mutliplied against this instead of the normal VIEW matrix.
  329. virtual void EnableUserClipTransformOverride( bool bEnable ) = 0;
  330. virtual void UserClipTransform( const VMatrix &worldToView ) = 0;
  331. // ----------------------------------------------------------------------------------
  332. // Everything after this point added after HL2 shipped.
  333. // ----------------------------------------------------------------------------------
  334. // What fields in the morph do we actually use?
  335. virtual MorphFormat_t ComputeMorphFormat( int numSnapshots, StateSnapshot_t* pIds ) const = 0;
  336. // Set the render target to a texID.
  337. // Set to SHADER_RENDERTARGET_BACKBUFFER if you want to use the regular framebuffer.
  338. // Set to SHADER_RENDERTARGET_DEPTHBUFFER if you want to use the regular z buffer.
  339. virtual void SetRenderTargetEx( int nRenderTargetID,
  340. ShaderAPITextureHandle_t colorTextureHandle = SHADER_RENDERTARGET_BACKBUFFER,
  341. ShaderAPITextureHandle_t depthTextureHandle = SHADER_RENDERTARGET_DEPTHBUFFER ) = 0;
  342. virtual void CopyRenderTargetToTextureEx( ShaderAPITextureHandle_t textureHandle, int nRenderTargetID, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) = 0;
  343. virtual void CopyTextureToRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t textureHandle, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) = 0;
  344. // For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer)
  345. virtual void HandleDeviceLost() = 0;
  346. virtual void EnableLinearColorSpaceFrameBuffer( bool bEnable ) = 0;
  347. // Lets the shader know about the full-screen texture so it can
  348. virtual void SetFullScreenTextureHandle( ShaderAPITextureHandle_t h ) = 0;
  349. // Rendering parameters control special drawing modes withing the material system, shader
  350. // system, shaders, and engine. renderparm.h has their definitions.
  351. virtual void SetFloatRenderingParameter(int parm_number, float value) = 0;
  352. virtual void SetIntRenderingParameter(int parm_number, int value) = 0;
  353. virtual void SetVectorRenderingParameter(int parm_number, Vector const &value) = 0;
  354. virtual float GetFloatRenderingParameter(int parm_number) const = 0;
  355. virtual int GetIntRenderingParameter(int parm_number) const = 0;
  356. virtual Vector GetVectorRenderingParameter(int parm_number) const = 0;
  357. virtual void SetFastClipPlane( const float *pPlane ) = 0;
  358. virtual void EnableFastClip( bool bEnable ) = 0;
  359. // Returns the number of vertices + indices we can render using the dynamic mesh
  360. // Passing true in the second parameter will return the max # of vertices + indices
  361. // we can use before a flush is provoked and may return different values
  362. // if called multiple times in succession.
  363. // Passing false into the second parameter will return
  364. // the maximum possible vertices + indices that can be rendered in a single batch
  365. virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices ) = 0;
  366. // Returns the max number of vertices we can render for a given material
  367. virtual int GetMaxVerticesToRender( IMaterial *pMaterial ) = 0;
  368. virtual int GetMaxIndicesToRender( ) = 0;
  369. // stencil methods
  370. virtual void SetStencilEnable(bool onoff) = 0;
  371. virtual void SetStencilFailOperation(StencilOperation_t op) = 0;
  372. virtual void SetStencilZFailOperation(StencilOperation_t op) = 0;
  373. virtual void SetStencilPassOperation(StencilOperation_t op) = 0;
  374. virtual void SetStencilCompareFunction(StencilComparisonFunction_t cmpfn) = 0;
  375. virtual void SetStencilReferenceValue(int ref) = 0;
  376. virtual void SetStencilTestMask(uint32 msk) = 0;
  377. virtual void SetStencilWriteMask(uint32 msk) = 0;
  378. virtual void ClearStencilBufferRectangle(int xmin, int ymin, int xmax, int ymax, int value) = 0;
  379. // disables all local lights
  380. virtual void DisableAllLocalLights() = 0;
  381. virtual int CompareSnapshots( StateSnapshot_t snapshot0, StateSnapshot_t snapshot1 ) = 0;
  382. virtual IMesh *GetFlexMesh() = 0;
  383. virtual void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture ) = 0;
  384. virtual bool SupportsMSAAMode( int nMSAAMode ) = 0;
  385. #if defined( _X360 )
  386. virtual HXUIFONT OpenTrueTypeFont( const char *pFontname, int tall, int style ) = 0;
  387. virtual void CloseTrueTypeFont( HXUIFONT hFont ) = 0;
  388. virtual bool GetTrueTypeFontMetrics( HXUIFONT hFont, XUIFontMetrics *pFontMetrics, XUICharMetrics charMetrics[256] ) = 0;
  389. // Render a sequence of characters and extract the data into a buffer
  390. // For each character, provide the width+height of the font texture subrect,
  391. // an offset to apply when rendering the glyph, and an offset into a buffer to receive the RGBA data
  392. virtual bool GetTrueTypeGlyphs( HXUIFONT hFont, int numChars, wchar_t *pWch, int *pOffsetX, int *pOffsetY, int *pWidth, int *pHeight, unsigned char *pRGBA, int *pRGBAOffset ) = 0;
  393. virtual ShaderAPITextureHandle_t CreateRenderTargetSurface( int width, int height, ImageFormat format, const char *pDebugName, const char *pTextureGroupName ) = 0;
  394. virtual void PersistDisplay() = 0;
  395. virtual bool PostQueuedTexture( const void *pData, int nSize, ShaderAPITextureHandle_t *pHandles, int nHandles, int nWidth, int nHeight, int nDepth, int nMips, int *pRefCount ) = 0;
  396. virtual void *GetD3DDevice() = 0;
  397. virtual void PushVertexShaderGPRAllocation( int iVertexShaderCount = 64 ) = 0;
  398. virtual void PopVertexShaderGPRAllocation( void ) = 0;
  399. virtual void EnableVSync_360( bool bEnable ) = 0; //360 allows us to bypass vsync blocking up to 60 fps without creating a new device
  400. #endif
  401. virtual bool OwnGPUResources( bool bEnable ) = 0;
  402. //get fog distances entered with FogStart(), FogEnd(), and SetFogZ()
  403. virtual void GetFogDistances( float *fStart, float *fEnd, float *fFogZ ) = 0;
  404. // Hooks for firing PIX events from outside the Material System...
  405. virtual void BeginPIXEvent( unsigned long color, const char *szName ) = 0;
  406. virtual void EndPIXEvent() = 0;
  407. virtual void SetPIXMarker( unsigned long color, const char *szName ) = 0;
  408. // Enables and disables for Alpha To Coverage
  409. virtual void EnableAlphaToCoverage() = 0;
  410. virtual void DisableAlphaToCoverage() = 0;
  411. // Computes the vertex buffer pointers
  412. virtual void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc ) const = 0;
  413. virtual bool SupportsShadowDepthTextures( void ) = 0;
  414. virtual void SetDisallowAccess( bool ) = 0;
  415. virtual void EnableShaderShaderMutex( bool ) = 0;
  416. virtual void ShaderLock() = 0;
  417. virtual void ShaderUnlock() = 0;
  418. virtual ImageFormat GetShadowDepthTextureFormat( void ) = 0;
  419. virtual bool SupportsFetch4( void ) = 0;
  420. virtual void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) = 0;
  421. // ------------ New Vertex/Index Buffer interface ----------------------------
  422. virtual void BindVertexBuffer( int nStreamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 ) = 0;
  423. virtual void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes ) = 0;
  424. virtual void Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount ) = 0;
  425. // ------------ End ----------------------------
  426. // Apply stencil operations to every pixel on the screen without disturbing depth or color buffers
  427. virtual void PerformFullScreenStencilOperation( void ) = 0;
  428. virtual void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ) = 0;
  429. // nVidia CSAA modes, different from SupportsMSAAMode()
  430. virtual bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ) = 0;
  431. //Notifies the shaderapi to invalidate the current set of delayed constants because we just finished a draw pass. Either actual or not.
  432. virtual void InvalidateDelayedShaderConstants( void ) = 0;
  433. // Gamma<->Linear conversions according to the video hardware we're running on
  434. virtual float GammaToLinear_HardwareSpecific( float fGamma ) const =0;
  435. virtual float LinearToGamma_HardwareSpecific( float fLinear ) const =0;
  436. //Set's the linear->gamma conversion textures to use for this hardware for both srgb writes enabled and disabled(identity)
  437. virtual void SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture ) = 0;
  438. virtual ImageFormat GetNullTextureFormat( void ) = 0;
  439. virtual void BindVertexTexture( VertexTextureSampler_t nSampler, ShaderAPITextureHandle_t textureHandle ) = 0;
  440. // Enables hardware morphing
  441. virtual void EnableHWMorphing( bool bEnable ) = 0;
  442. // Sets flexweights for rendering
  443. virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights ) = 0;
  444. virtual void FogMaxDensity( float flMaxDensity ) = 0;
  445. // Create a multi-frame texture (equivalent to calling "CreateTexture" multiple times, but more efficient)
  446. virtual void CreateTextures(
  447. ShaderAPITextureHandle_t *pHandles,
  448. int count,
  449. int width,
  450. int height,
  451. int depth,
  452. ImageFormat dstImageFormat,
  453. int numMipLevels,
  454. int numCopies,
  455. int flags,
  456. const char *pDebugName,
  457. const char *pTextureGroupName ) = 0;
  458. virtual void AcquireThreadOwnership() = 0;
  459. virtual void ReleaseThreadOwnership() = 0;
  460. virtual bool SupportsNormalMapCompression() const { Assert( !"This has all been removed." ); return false; }
  461. // Only does anything on XBox360. This is useful to eliminate stalls
  462. virtual void EnableBuffer2FramesAhead( bool bEnable ) = 0;
  463. virtual void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) = 0;
  464. // debug logging
  465. // only implemented in some subclasses
  466. virtual void PrintfVA( char *fmt, va_list vargs ) = 0;
  467. virtual void Printf( PRINTF_FORMAT_STRING const char *fmt, ... ) = 0;
  468. virtual float Knob( char *knobname, float *setvalue = NULL ) = 0;
  469. // Allows us to override the alpha write setting of a material
  470. virtual void OverrideAlphaWriteEnable( bool bEnable, bool bAlphaWriteEnable ) = 0;
  471. virtual void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable ) = 0;
  472. //extended clear buffers function with alpha independent from color
  473. virtual void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth ) = 0;
  474. // Allows copying a render target to another texture by specifying them both.
  475. virtual void CopyRenderTargetToScratchTexture( ShaderAPITextureHandle_t srcRt, ShaderAPITextureHandle_t dstTex, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) = 0;
  476. // Allows locking and unlocking of very specific surface types.
  477. virtual void LockRect( void** pOutBits, int* pOutPitch, ShaderAPITextureHandle_t texHandle, int mipmap, int x, int y, int w, int h, bool bWrite, bool bRead ) = 0;
  478. virtual void UnlockRect( ShaderAPITextureHandle_t texHandle, int mipmap ) = 0;
  479. // Set the finest mipmap that can be used for the texture which is currently being modified.
  480. virtual void TexLodClamp( int finest ) = 0;
  481. // Set the Lod Bias for the texture which is currently being modified.
  482. virtual void TexLodBias( float bias ) = 0;
  483. virtual void CopyTextureToTexture( ShaderAPITextureHandle_t srcTex, ShaderAPITextureHandle_t dstTex ) = 0;
  484. };
  485. #endif // ISHADERAPI_H