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.

2603 lines
71 KiB

  1. //========= Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=====================================================================================//
  6. #include "materialsystem/imesh.h"
  7. #include "materialsystem/imaterialsystemhardwareconfig.h"
  8. #include "materialsystem/imorph.h"
  9. #include "materialsystem/imaterialsystemstub.h"
  10. #include "materialsystem/imaterial.h"
  11. #include "materialsystem/itexture.h"
  12. #include "materialsystem/imaterialvar.h"
  13. #include "bitmap/imageformat.h"
  14. #include "mathlib/vmatrix.h"
  15. #include "utlvector.h"
  16. // GR
  17. #include "imaterialinternal.h"
  18. #include "materialsystem/materialsystem_config.h"
  19. // memdbgon must be the last include file in a .cpp file!!!
  20. #include "tier0/memdbgon.h"
  21. // ---------------------------------------------------------------------------------------- //
  22. // IMaterialSystem and IMesh stub classes.
  23. // ---------------------------------------------------------------------------------------- //
  24. CUtlVector<unsigned short> g_DummyIndices;
  25. class CDummyMesh : public IMesh
  26. {
  27. public:
  28. // Locks/ unlocks the mesh, providing space for nVertexCount and nIndexCount.
  29. // nIndexCount of -1 means don't lock the index buffer...
  30. virtual void LockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc, MeshBuffersAllocationSettings_t *pSettings = 0 )
  31. {
  32. Lock( nVertexCount, false, *static_cast< VertexDesc_t* >( &desc ) );
  33. Lock( nIndexCount, false, *static_cast< IndexDesc_t* >( &desc ) );
  34. }
  35. virtual void UnlockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc )
  36. {
  37. }
  38. virtual void ModifyBeginEx( bool bReadOnly, int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc )
  39. {
  40. ModifyBegin( bReadOnly, nFirstIndex, nIndexCount, *static_cast< IndexDesc_t* >( &desc ) );
  41. }
  42. virtual void ModifyBegin( int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc )
  43. {
  44. ModifyBegin( false, nFirstIndex, nIndexCount, *static_cast< IndexDesc_t* >( &desc ) );
  45. }
  46. virtual void ModifyEnd( MeshDesc_t &desc )
  47. {
  48. }
  49. // FIXME: Make this work! Unsupported methods of IIndexBuffer
  50. virtual bool Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t& desc )
  51. {
  52. static unsigned short dummyIndex;
  53. desc.m_pIndices = &dummyIndex;
  54. desc.m_nIndexSize = 0;
  55. desc.m_nFirstIndex = 0;
  56. desc.m_nOffset = 0;
  57. return true;
  58. }
  59. virtual void Unlock( int nWrittenIndexCount, IndexDesc_t& desc ) {}
  60. virtual void ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc )
  61. {
  62. static unsigned short dummyIndex;
  63. desc.m_pIndices = &dummyIndex;
  64. desc.m_nIndexSize = 0;
  65. desc.m_nFirstIndex = 0;
  66. desc.m_nOffset = 0;
  67. }
  68. virtual void ModifyEnd( IndexDesc_t &desc ) {}
  69. virtual void Spew( int nIndexCount, const IndexDesc_t & desc ) {}
  70. virtual void ValidateData( int nIndexCount, const IndexDesc_t &desc ) {}
  71. virtual bool IsDynamic() const
  72. {
  73. return false;
  74. }
  75. virtual void BeginCastBuffer( MaterialIndexFormat_t format ) {}
  76. virtual void BeginCastBuffer( VertexFormat_t format ) {}
  77. virtual void EndCastBuffer( ) {}
  78. // Returns the number of vertices that can still be written into the buffer
  79. virtual int GetRoomRemaining() const { return 0; }
  80. virtual int IndexCount() const
  81. {
  82. return 0;
  83. }
  84. // returns the # of vertices (static meshes only)
  85. virtual int VertexCount() const
  86. {
  87. return 0;
  88. }
  89. // returns the vertex format
  90. virtual bool Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc )
  91. {
  92. static float dummyFloat[32];
  93. static unsigned char dummyChar[32];
  94. memset( &desc, 0, sizeof( desc ) );
  95. // Pointers to our current vertex data
  96. desc.m_pPosition = dummyFloat;
  97. desc.m_pBoneWeight = dummyFloat;
  98. #ifdef NEW_SKINNING
  99. desc.m_pBoneMatrixIndex = dummyFloat;
  100. #else
  101. desc.m_pBoneMatrixIndex = dummyChar;
  102. #endif
  103. desc.m_pNormal = dummyFloat;
  104. desc.m_pColor = dummyChar;
  105. desc.m_pSpecular = dummyChar;
  106. for( int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ )
  107. {
  108. desc.m_pTexCoord[i] = dummyFloat;
  109. }
  110. desc.m_pTangentS = dummyFloat;
  111. desc.m_pTangentT = dummyFloat;
  112. desc.m_pWrinkle = dummyFloat;
  113. // user data
  114. desc.m_pUserData = dummyFloat;
  115. desc.m_nFirstVertex = 0;
  116. desc.m_nOffset = 0;
  117. return true;
  118. }
  119. virtual void Unlock( int nVertexCount, VertexDesc_t &desc ) {}
  120. virtual void Spew( int nVertexCount, const VertexDesc_t &desc ) {}
  121. virtual void ValidateData( int nVertexCount, const VertexDesc_t & desc ) {}
  122. // Sets/gets the primitive type
  123. virtual void SetPrimitiveType( MaterialPrimitiveType_t type )
  124. {
  125. }
  126. // Draws the mesh
  127. virtual void Draw( int nFirstIndex = -1, int nIndexCount = 0 )
  128. {
  129. }
  130. void DrawInstances( int nCount, const MeshInstanceData_t *pInstanceData )
  131. {
  132. }
  133. virtual void DrawModulated( const Vector4D &vecDiffuseModulation, int nFirstIndex = -1, int nIndexCount = 0 )
  134. {
  135. }
  136. virtual void SetColorMesh( IMesh *pColorMesh, int nVertexOffset )
  137. {
  138. }
  139. virtual void SetFlexMesh( IMesh *pMesh, int nVertexOffset )
  140. {
  141. }
  142. virtual void DisableFlexMesh( )
  143. {
  144. }
  145. // Draw a list of (lists of) primitives. Batching your lists together that use
  146. // the same lightmap, material, vertex and index buffers with multipass shaders
  147. // can drastically reduce state-switching overhead.
  148. // NOTE: this only works with STATIC meshes.
  149. virtual void Draw( CPrimList *pLists, int nLists )
  150. {
  151. }
  152. // Copy verts and/or indices to a mesh builder. This only works for temp meshes!
  153. virtual void CopyToMeshBuilder(
  154. int iStartVert, // Which vertices to copy.
  155. int nVerts,
  156. int iStartIndex, // Which indices to copy.
  157. int nIndices,
  158. int indexOffset, // This is added to each index.
  159. CMeshBuilder &builder )
  160. {
  161. }
  162. // Spews the mesh data
  163. virtual void Spew( int nVertexCount, int nIndexCount, const MeshDesc_t& desc )
  164. {
  165. }
  166. // Call this in debug mode to make sure our data is good.
  167. virtual void ValidateData( int nVertexCount, int nIndexCount, const MeshDesc_t& desc )
  168. {
  169. }
  170. virtual void MarkAsDrawn() {}
  171. virtual unsigned int ComputeMemoryUsed() { return 0; }
  172. virtual VertexFormat_t GetVertexFormat() const
  173. {
  174. return VERTEX_POSITION;
  175. }
  176. virtual MaterialIndexFormat_t IndexFormat() const
  177. {
  178. return MATERIAL_INDEX_FORMAT_16BIT;
  179. }
  180. virtual IMesh *GetMesh()
  181. {
  182. return this;
  183. }
  184. virtual void * AccessRawHardwareDataStream( uint8 nRawStreamIndex, uint32 numBytes, uint32 uiFlags, void *pvContext ) { return NULL; }
  185. virtual ICachedPerFrameMeshData *GetCachedPerFrameMeshData() { return NULL; }
  186. virtual void ReconstructFromCachedPerFrameMeshData( ICachedPerFrameMeshData *pData ) {}
  187. };
  188. // We allocate this dynamically because it uses a bunch of memory and we don't want to
  189. // waste the memory unless we need to.
  190. CDummyMesh *g_pDummyMesh = NULL;
  191. CDummyMesh* GetDummyMesh()
  192. {
  193. if ( !g_pDummyMesh )
  194. {
  195. g_pDummyMesh = new CDummyMesh;
  196. }
  197. return g_pDummyMesh;
  198. }
  199. // ---------------------------------------------------------------------------------------- //
  200. // ITexture dummy implementation.
  201. // ---------------------------------------------------------------------------------------- //
  202. class CDummyTexture : public ITexture
  203. {
  204. public:
  205. // Various texture polling methods
  206. virtual const char *GetName( void ) const { return "DummyTexture"; }
  207. virtual int GetMappingWidth() const { return 512; }
  208. virtual int GetMappingHeight() const { return 512; }
  209. virtual int GetActualWidth() const { return 512; }
  210. virtual int GetActualHeight() const { return 512; }
  211. virtual int GetNumAnimationFrames() const { return 0; }
  212. virtual bool IsTranslucent() const { return false; }
  213. virtual bool IsMipmapped() const { return false; }
  214. virtual void GetLowResColorSample( float s, float t, float *color ) const {}
  215. // Gets texture resource data of the specified type.
  216. // Params:
  217. // eDataType type of resource to retrieve.
  218. // pnumBytes on return is the number of bytes available in the read-only data buffer or is undefined
  219. // Returns:
  220. // pointer to the resource data, or NULL
  221. virtual void *GetResourceData( uint32 eDataType, size_t *pNumBytes ) const
  222. {
  223. return NULL;
  224. }
  225. // Methods associated with reference count
  226. virtual void IncrementReferenceCount( void ) {}
  227. virtual void DecrementReferenceCount( void ) {}
  228. // Used to modify the texture bits (procedural textures only)
  229. virtual void SetTextureRegenerator( ITextureRegenerator *pTextureRegen, bool releaseExisting = true ) {}
  230. // Reconstruct the texture bits in HW memory
  231. // If rect is not specified, reconstruct all bits, otherwise just reconstruct a subrect.
  232. virtual void Download( Rect_t *pRect = 0, int nAdditionalCreationFlags = 0 ) {}
  233. // Fast download without intermediate vtf texture copy
  234. virtual void Download( int nXOffset, int nYOffset, unsigned char *pData, int nWidth, int nHeight, ImageFormat srcFormat ) {}
  235. // Uses for stats. . .get the approximate size of the texture in it's current format.
  236. virtual int GetApproximateVidMemBytes( void ) const { return 64; }
  237. virtual bool IsError() const { return false; }
  238. virtual ITexture *GetEmbeddedTexture( int nIndex ) { return NULL; }
  239. // For volume textures
  240. virtual bool IsVolumeTexture() const { return false; }
  241. virtual int GetMappingDepth() const { return 1; }
  242. virtual int GetActualDepth() const { return 1; }
  243. virtual ImageFormat GetImageFormat() const { return IMAGE_FORMAT_RGBA8888; }
  244. // Various information about the texture
  245. virtual bool IsRenderTarget() const { return false; }
  246. virtual bool IsCubeMap() const { return false; }
  247. virtual bool IsNormalMap() const { return false; }
  248. virtual bool IsProcedural() const { return false; }
  249. virtual void DeleteIfUnreferenced() {}
  250. virtual bool IsDefaultPool() const { return false; }
  251. virtual void SwapContents( ITexture *pOther ) {}
  252. virtual unsigned int GetFlags( void ) const { return 0; }
  253. virtual void ForceLODOverride( int iNumLodsOverrideUpOrDown ) { NULL; }
  254. virtual void ForceExcludeOverride( int iExcludeOverride ) { NULL; }
  255. virtual void AddDownsizedSubTarget( const char *szName, int iDownsizePow2, MaterialRenderTargetDepth_t depth ) { NULL; }
  256. virtual void SetActiveSubTarget( const char *szName ) { NULL; }
  257. #if defined( _X360 )
  258. virtual bool ClearTexture( int r, int g, int b, int a ) { return true; }
  259. virtual bool CreateRenderTargetSurface( int width, int height, ImageFormat format, bool bSameAsTexture, RTMultiSampleCount360_t multiSampleCount = RT_MULTISAMPLE_NONE ) { return true; }
  260. #endif
  261. virtual int GetReferenceCount() const { return 0; }
  262. virtual bool IsTempExcluded() const { return false; }
  263. virtual bool CanBeTempExcluded() const { return false; }
  264. virtual bool FinishAsyncDownload( AsyncTextureContext_t *pContext, void *pData, int nNumReadBytes, bool bAbort, float flMaxTimeMs ) { return true; }
  265. virtual bool IsForceExcluded() const { return false; }
  266. virtual bool ClearForceExclusion() { return false; }
  267. };
  268. CDummyTexture g_DummyTexture;
  269. // ---------------------------------------------------------------------------------------- //
  270. // Dummy implementation of IMaterialVar.
  271. // ---------------------------------------------------------------------------------------- //
  272. static VMatrix g_DummyMatrix( 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 );
  273. class CDummyMaterialVar : public IMaterialVar
  274. {
  275. public:
  276. virtual char const * GetName( void ) const { return "DummyMaterialVar"; }
  277. virtual MaterialVarSym_t GetNameAsSymbol() const { return 0; }
  278. virtual void SetFloatValue( float val ) {}
  279. virtual float GetFloatValueInternal( void ) const { return 1; }
  280. virtual void SetIntValue( int val ) {}
  281. virtual int GetIntValueInternal( void ) const { return 1; }
  282. virtual void SetStringValue( char const *val ) {}
  283. virtual char const * GetStringValue( void ) const { return ""; }
  284. // Use FourCC values to pass app-defined data structures between
  285. // the proxy and the shader. The shader should ignore the data if
  286. // its FourCC type not correct.
  287. virtual void SetFourCCValue( FourCC type, void *pData ) {}
  288. virtual void GetFourCCValue( FourCC *type, void **ppData ) {}
  289. // Vec (dim 2-4)
  290. virtual void SetVecValue( float const* val, int numcomps ) {}
  291. virtual void SetVecValue( float x, float y ) {}
  292. virtual void SetVecValue( float x, float y, float z ) {}
  293. virtual void SetVecValue( float x, float y, float z, float w ) {}
  294. virtual void SetVecComponentValue( float fVal, int nComponent ) {}
  295. virtual void GetVecValueInternal( float *val, int numcomps ) const
  296. {
  297. for ( int i=0; i < numcomps; i++ )
  298. val[i] = 1;
  299. }
  300. virtual void GetLinearVecValue( float *val, int numcomps ) const
  301. {
  302. for ( int i=0; i < numcomps; i++ )
  303. val[i] = 1;
  304. }
  305. virtual float const* GetVecValueInternal( ) const
  306. {
  307. static float val[4] = {1,1,1,1};
  308. return val;
  309. }
  310. virtual int VectorSizeInternal() const
  311. {
  312. return 3;
  313. }
  314. // revisit: is this a good interface for textures?
  315. virtual ITexture * GetTextureValue( void )
  316. {
  317. return &g_DummyTexture;
  318. }
  319. virtual bool IsTextureValueInternalEnvCubemap( void ) const
  320. {
  321. return false;
  322. }
  323. virtual void SetTextureValue( ITexture * ) {}
  324. virtual operator ITexture*()
  325. {
  326. return GetTextureValue();
  327. }
  328. virtual IMaterial * GetMaterialValue( void )
  329. {
  330. extern IMaterial *g_pDummyMaterial;
  331. return g_pDummyMaterial;
  332. }
  333. virtual void SetMaterialValue( IMaterial * ) {}
  334. virtual MaterialVarType_t GetType() const { return MATERIAL_VAR_TYPE_INT; }
  335. virtual bool IsDefined() const { return true; }
  336. virtual void SetUndefined() {}
  337. // Matrix
  338. virtual void SetMatrixValue( VMatrix const& matrix ) {}
  339. virtual const VMatrix &GetMatrixValue( )
  340. {
  341. return g_DummyMatrix;
  342. }
  343. virtual bool MatrixIsIdentity() const
  344. {
  345. return false;
  346. }
  347. // Copy....
  348. virtual void CopyFrom( IMaterialVar *pMaterialVar ) {}
  349. virtual void SetValueAutodetectType( char const *val ) {}
  350. virtual IMaterial * GetOwningMaterial()
  351. {
  352. extern IMaterial *g_pDummyMaterial;
  353. return g_pDummyMaterial;
  354. }
  355. };
  356. CDummyMaterialVar g_DummyMaterialVar;
  357. // ---------------------------------------------------------------------------------------- //
  358. // Dummy implementation of IMaterialSystemHardwareConfig
  359. // ---------------------------------------------------------------------------------------- //
  360. class CDummyHardwareConfig : public IMaterialSystemHardwareConfig
  361. {
  362. public:
  363. virtual bool HasDestAlphaBuffer() const { return false; }
  364. virtual bool HasStencilBuffer() const { return false; }
  365. virtual int StencilBufferBits() const { return 0; }
  366. virtual int GetFrameBufferColorDepth() const { return 0; }
  367. virtual int GetVertexSamplerCount() const { return 0; }
  368. virtual int GetSamplerCount() const { return 0; }
  369. virtual bool HasSetDeviceGammaRamp() const { return false; }
  370. virtual bool SupportsCompressedTextures() const { return false; }
  371. virtual bool SupportsStaticControlFlow() const { return false; }
  372. virtual VertexCompressionType_t SupportsCompressedVertices() const { return VERTEX_COMPRESSION_NONE; }
  373. virtual int MaximumAnisotropicLevel() const { return 1; }
  374. virtual int MaxTextureWidth() const { return 0; }
  375. virtual int MaxTextureHeight() const { return 0; }
  376. virtual int MaxTextureDepth() const { return 0; }
  377. virtual int TextureMemorySize() const { return 0; }
  378. virtual bool SupportsMipmappedCubemaps() const { return 0; }
  379. // The number of texture stages represents the number of computations
  380. // we can do in the pixel pipeline, it is *not* related to the
  381. // simultaneous number of textures we can use
  382. virtual int NumVertexShaderConstants() const { return 0; }
  383. virtual int NumBooleanVertexShaderConstants() const { return 0; }
  384. virtual int NumIntegerVertexShaderConstants() const { return 0; }
  385. virtual int NumPixelShaderConstants() const { return 0; }
  386. virtual int MaxNumLights() const { return 0; }
  387. virtual int MaxTextureAspectRatio() const { return 0; }
  388. virtual int MaxVertexShaderBlendMatrices() const { return 0; }
  389. virtual int MaxUserClipPlanes() const { return 0; }
  390. virtual bool UseFastClipping() const { return false; }
  391. // This here should be the major item looked at when checking for compat
  392. // from anywhere other than the material system shaders
  393. virtual int GetDXSupportLevel() const { return 90; }
  394. virtual const char *GetShaderDLLName() const { return NULL; }
  395. virtual bool ReadPixelsFromFrontBuffer() const { return false; }
  396. // Are dx dynamic textures preferred?
  397. virtual bool PreferDynamicTextures() const { return false; }
  398. #ifdef _GAMECONSOLE
  399. // Vitaliy: need HDR to run with -noshaderapi on console
  400. virtual bool SupportsHDR() const { return true; }
  401. virtual HDRType_t GetHDRType() const { return HDR_TYPE_INTEGER; }
  402. virtual HDRType_t GetHardwareHDRType() const { return HDR_TYPE_INTEGER; }
  403. #else
  404. virtual bool SupportsHDR() const { return false; }
  405. virtual HDRType_t GetHDRType() const { return HDR_TYPE_NONE; }
  406. virtual HDRType_t GetHardwareHDRType() const { return HDR_TYPE_NONE; }
  407. #endif
  408. virtual bool NeedsAAClamp() const { return false; }
  409. virtual bool NeedsATICentroidHack() const { return false; }
  410. virtual bool SupportsStreamOffset() const { return false; }
  411. virtual int GetMaxDXSupportLevel() const { return 90; }
  412. virtual bool SpecifiesFogColorInLinearSpace() const { return false; }
  413. virtual bool SupportsSRGB() const { return false; }
  414. virtual bool FakeSRGBWrite() const { return false; }
  415. virtual bool CanDoSRGBReadFromRTs() const { return true; }
  416. virtual bool SupportsGLMixedSizeTargets() const { return false; }
  417. virtual bool IsAAEnabled() const { return false; }
  418. virtual int GetMaxVertexTextureDimension() const { return 0; }
  419. virtual int MaxViewports() const { return 1; }
  420. virtual void OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport ) {}
  421. virtual ShadowFilterMode_t GetShadowFilterMode( bool bForceLowQualityShadows, bool bPS30 ) const { bForceLowQualityShadows; bPS30; return SHADOWFILTERMODE_DEFAULT; }
  422. virtual int NeedsShaderSRGBConversion() const { return 0; }
  423. bool UsesSRGBCorrectBlending() const { return false; }
  424. virtual bool HasFastVertexTextures() const { return false; }
  425. virtual bool ActualHasFastVertexTextures() const { return false; }
  426. virtual int MaxHWMorphBatchCount() const { return 0; }
  427. #ifdef _GAMECONSOLE
  428. // Vitaliy: need HDR to run with -noshaderapi on console
  429. virtual bool SupportsHDRMode( HDRType_t nMode ) const { return nMode == HDR_TYPE_NONE || nMode == HDR_TYPE_INTEGER; }
  430. #else
  431. virtual bool SupportsHDRMode( HDRType_t nMode ) const { return 0; }
  432. #endif
  433. virtual bool IsDX10Card() const { return 0; }
  434. virtual bool GetHDREnabled( void ) const { return true; }
  435. virtual void SetHDREnabled( bool bEnable ) {}
  436. virtual bool SupportsBorderColor( void ) const { return true; }
  437. virtual bool SupportsFetch4( void ) const { return false; }
  438. virtual float GetShadowDepthBias() const { return 0.0f; }
  439. virtual float GetShadowSlopeScaleDepthBias() const { return 0.0f; }
  440. virtual bool PreferZPrepass( void ) const { return false; }
  441. virtual bool SuppressPixelShaderCentroidHackFixup() const { return true; }
  442. virtual bool PreferTexturesInHWMemory() const { return false; }
  443. virtual bool PreferHardwareSync() const { return false; }
  444. virtual bool SupportsShadowDepthTextures( void ) const { return false; }
  445. virtual ImageFormat GetShadowDepthTextureFormat( void ) const { return IMAGE_FORMAT_D16_SHADOW; }
  446. virtual ImageFormat GetHighPrecisionShadowDepthTextureFormat( void ) const { return IMAGE_FORMAT_D24X8_SHADOW; }
  447. virtual ImageFormat GetNullTextureFormat( void ) const { return IMAGE_FORMAT_RGBA8888; }
  448. virtual int GetMinDXSupportLevel() const { return 90; }
  449. virtual bool IsUnsupported() const { return false; }
  450. virtual float GetLightMapScaleFactor() const { return 1.0f; }
  451. virtual bool SupportsCascadedShadowMapping() const { return false; }
  452. virtual CSMQualityMode_t GetCSMQuality() const { return CSMQUALITY_VERY_LOW; }
  453. virtual bool SupportsBilinearPCFSampling() const { return true; }
  454. virtual CSMShaderMode_t GetCSMShaderMode( CSMQualityMode_t nQualityLevel ) const { nQualityLevel; return CSMSHADERMODE_LOW_OR_VERY_LOW; }
  455. virtual void SetCSMAccurateBlending( bool bEnable ) {}
  456. virtual bool GetCSMAccurateBlending( void ) const { return true; }
  457. virtual bool SupportsResolveDepth() const { return false; }
  458. virtual bool HasFullResolutionDepthTexture() const { return false; }
  459. };
  460. CDummyHardwareConfig g_DummyHardwareConfig;
  461. // ---------------------------------------------------------------------------------------- //
  462. // CDummyMaterial.
  463. // ---------------------------------------------------------------------------------------- //
  464. class CDummyMaterial : public IMaterial
  465. {
  466. public:
  467. virtual const char * GetName() const { return "dummy material"; }
  468. virtual const char * GetTextureGroupName() const { return "dummy group"; }
  469. virtual PreviewImageRetVal_t GetPreviewImageProperties( int *width, int *height,
  470. ImageFormat *imageFormat, bool* isTranslucent ) const
  471. {
  472. if ( width )
  473. *width = 4;
  474. if ( height )
  475. *height = 4;
  476. if ( imageFormat )
  477. *imageFormat = IMAGE_FORMAT_RGBA8888;
  478. if ( isTranslucent )
  479. *isTranslucent = false;
  480. return MATERIAL_PREVIEW_IMAGE_OK;
  481. }
  482. virtual PreviewImageRetVal_t GetPreviewImage( unsigned char *data,
  483. int width, int height,
  484. ImageFormat imageFormat ) const
  485. {
  486. return MATERIAL_PREVIEW_IMAGE_OK;
  487. }
  488. //
  489. virtual int GetMappingWidth( )
  490. {
  491. return 512;
  492. }
  493. virtual int GetMappingHeight( )
  494. {
  495. return 512;
  496. }
  497. virtual int GetNumAnimationFrames( )
  498. {
  499. return 0;
  500. }
  501. virtual bool InMaterialPage( void )
  502. {
  503. return false;
  504. }
  505. virtual void GetMaterialOffset( float *pOffset )
  506. {
  507. pOffset[0] = 0.0f;
  508. pOffset[1] = 0.0f;
  509. }
  510. virtual void GetMaterialScale( float *pScale )
  511. {
  512. pScale[0] = 1.0f;
  513. pScale[1] = 1.0f;
  514. }
  515. virtual IMaterial *GetMaterialPage( void )
  516. {
  517. return NULL;
  518. }
  519. virtual IMaterialVar * FindVar( const char *varName, bool *found, bool complain = true )
  520. {
  521. if ( found )
  522. *found = true;
  523. return &g_DummyMaterialVar;
  524. }
  525. virtual IMaterialVar * FindVarFast( const char *varName, unsigned int *pToken )
  526. {
  527. return NULL;
  528. }
  529. virtual void IncrementReferenceCount( void )
  530. {
  531. }
  532. virtual void DecrementReferenceCount( void )
  533. {
  534. }
  535. virtual int GetEnumerationID( void ) const
  536. {
  537. return 0;
  538. }
  539. virtual void GetLowResColorSample( float s, float t, float *color ) const
  540. {
  541. }
  542. virtual void RecomputeStateSnapshots()
  543. {
  544. }
  545. // Are we translucent?
  546. virtual bool IsTranslucent()
  547. {
  548. return false;
  549. }
  550. virtual bool IsTranslucentUnderModulation( float flAlphaModulation ) const { return false; }
  551. // Are we alphatested?
  552. virtual bool IsAlphaTested()
  553. {
  554. return false;
  555. }
  556. // Are we vertex lit?
  557. virtual bool IsVertexLit()
  558. {
  559. return false;
  560. }
  561. // Gets the vertex format
  562. virtual VertexFormat_t GetVertexFormat() const
  563. {
  564. return 0;
  565. }
  566. // returns true if this material uses a material proxy
  567. virtual bool HasProxy( void ) const
  568. {
  569. return false;
  570. }
  571. virtual void CallBindProxy( void*, ICallQueue * ) {}
  572. virtual bool UsesEnvCubemap( void )
  573. {
  574. return false;
  575. }
  576. virtual bool NeedsTangentSpace( void )
  577. {
  578. return false;
  579. }
  580. virtual bool NeedsPowerOfTwoFrameBufferTexture( bool bCheckSpecificToThisFrame )
  581. {
  582. return false;
  583. }
  584. virtual bool NeedsFullFrameBufferTexture( bool bCheckSpecificToThisFrame )
  585. {
  586. return false;
  587. }
  588. virtual bool NeedsSoftwareSkinning( void )
  589. {
  590. return false;
  591. }
  592. // Apply constant color or alpha modulation
  593. virtual void AlphaModulate( float alpha )
  594. {
  595. }
  596. virtual void ColorModulate( float r, float g, float b )
  597. {
  598. }
  599. float GetAlphaModulation( )
  600. {
  601. return 1;
  602. }
  603. void GetColorModulation( float *r, float *g, float *b )
  604. {
  605. *r = *g = *b = 1;
  606. }
  607. // Material Var flags...
  608. virtual void SetMaterialVarFlag( MaterialVarFlags_t flag, bool on )
  609. {
  610. }
  611. virtual bool GetMaterialVarFlag( MaterialVarFlags_t flag ) const
  612. {
  613. return true;
  614. }
  615. // Gets material reflectivity
  616. virtual void GetReflectivity( Vector& reflect )
  617. {
  618. reflect.Init(1,0,0);
  619. }
  620. // Gets material property flags
  621. virtual bool GetPropertyFlag( MaterialPropertyTypes_t type )
  622. {
  623. return true;
  624. }
  625. // Is the material visible from both sides?
  626. virtual bool IsTwoSided()
  627. {
  628. return false;
  629. }
  630. // Sets the shader associated with the material
  631. virtual void SetShader( const char *pShaderName )
  632. {
  633. }
  634. // Can't be const because the material might have to precache itself.
  635. virtual int GetNumPasses( void )
  636. {
  637. return 1;
  638. }
  639. // Can't be const because the material might have to precache itself.
  640. virtual int GetTextureMemoryBytes( void )
  641. {
  642. return 64;
  643. }
  644. // Meant to be used with materials created using CreateMaterial
  645. // It updates the materials to reflect the current values stored in the material vars
  646. virtual void Refresh()
  647. {
  648. }
  649. // GR - returns true is material uses lightmap alpha for blending
  650. virtual bool NeedsLightmapBlendAlpha( void )
  651. {
  652. return false;
  653. }
  654. // returns true if the shader doesn't do lighting itself and requires
  655. // the data that is sent to it to be prelighted
  656. virtual bool NeedsSoftwareLighting( void )
  657. {
  658. return false;
  659. }
  660. // Gets at the shader parameters
  661. virtual int ShaderParamCount() const
  662. {
  663. return 0;
  664. }
  665. virtual IMaterialVar **GetShaderParams( void )
  666. {
  667. return 0;
  668. }
  669. virtual bool IsErrorMaterial() const
  670. {
  671. return false;
  672. }
  673. virtual MorphFormat_t GetMorphFormat() const
  674. {
  675. return 0;
  676. }
  677. virtual void SetShaderAndParams( KeyValues *pKeyValues )
  678. {
  679. }
  680. virtual const char *GetShaderName() const { return "Wireframe"; }
  681. virtual void DeleteIfUnreferenced() {}
  682. virtual bool IsSpriteCard() { return false; }
  683. virtual void RefreshPreservingMaterialVars() {};
  684. virtual bool WasReloadedFromWhitelist() {return false;}
  685. virtual bool SetTempExcluded( bool bSet, int nExcludedDimensionLimit ) { return false; }
  686. virtual int GetReferenceCount() const { return 0; }
  687. };
  688. CDummyMaterial g_DummyMaterial;
  689. IMaterial *g_pDummyMaterial = &g_DummyMaterial;
  690. void* DummyMaterialSystemFactory( const char *pName, int *pReturnCode )
  691. {
  692. if ( stricmp( pName, MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION ) == 0 )
  693. return &g_DummyHardwareConfig;
  694. else
  695. return NULL;
  696. }
  697. // ---------------------------------------------------------------------------------------- //
  698. // Dummy morph
  699. // ---------------------------------------------------------------------------------------- //
  700. class CDummyMorph : public IMorph
  701. {
  702. public:
  703. virtual void Lock( float flFloatToFixedScale ) {}
  704. virtual void AddMorph( const MorphVertexInfo_t &info ) {}
  705. virtual void Unlock( ) {}
  706. virtual void AccumulateMorph( int nWeightCount, const MorphWeight_t* pWeights ) {}
  707. };
  708. // ---------------------------------------------------------------------------------------- //
  709. // CDummyMaterialSystem.
  710. // ---------------------------------------------------------------------------------------- //
  711. class CDummyMaterialSystem : public IMaterialSystemStub, public CRefCounted1<IMatRenderContext, CRefCountServiceNull>
  712. {
  713. private:
  714. IMaterialSystem *m_pRealMaterialSystem;
  715. public:
  716. CDummyMaterialSystem()
  717. {
  718. m_pRealMaterialSystem = 0;
  719. }
  720. virtual void SetRealMaterialSystem( IMaterialSystem *pSys )
  721. {
  722. m_pRealMaterialSystem = pSys;
  723. }
  724. // Call this to initialize the material system
  725. // returns a method to create interfaces in the shader dll
  726. virtual CreateInterfaceFn Init( char const* pShaderDLL,
  727. IMaterialProxyFactory *pMaterialProxyFactory,
  728. CreateInterfaceFn fileSystemFactory,
  729. CreateInterfaceFn cvarFactory )
  730. {
  731. return DummyMaterialSystemFactory;
  732. }
  733. virtual void Shutdown( )
  734. {
  735. }
  736. virtual IMaterialSystemHardwareConfig *GetHardwareConfig( const char *pVersion, int *returnCode )
  737. {
  738. if ( returnCode )
  739. *returnCode = 1;
  740. return &g_DummyHardwareConfig;
  741. }
  742. // Gets the number of adapters...
  743. virtual int GetDisplayAdapterCount() const
  744. {
  745. return 0;
  746. }
  747. // Returns info about each adapter
  748. virtual void GetDisplayAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const
  749. {
  750. }
  751. // Returns the number of modes
  752. virtual int GetModeCount( int adapter ) const
  753. {
  754. return 0;
  755. }
  756. // Returns mode information..
  757. virtual void GetModeInfo( int adapter, int mode, MaterialVideoMode_t& info ) const
  758. {
  759. }
  760. // Returns the mode info for the current display device
  761. virtual void GetDisplayMode( MaterialVideoMode_t& mode ) const
  762. {
  763. }
  764. // Sets the mode...
  765. virtual bool SetMode( void* hwnd, const MaterialSystem_Config_t &config )
  766. {
  767. return true;
  768. }
  769. // Creates/ destroys a child window
  770. virtual bool AddView( void* hwnd )
  771. {
  772. return false;
  773. }
  774. virtual void RemoveView( void* hwnd )
  775. {
  776. }
  777. // Sets the view
  778. virtual void SetView( void* hwnd )
  779. {
  780. }
  781. // return true if lightmaps need to be redownloaded
  782. // Call this before rendering each frame with the current config
  783. // for the material system.
  784. // Will do whatever is necessary to get the material system into the correct state
  785. // upon configuration change. .doesn't much else otherwise.
  786. virtual bool UpdateConfig( bool forceUpdate )
  787. {
  788. return false;
  789. }
  790. virtual bool OverrideConfig( const MaterialSystem_Config_t &config, bool bForceUpdate )
  791. {
  792. return false;
  793. }
  794. // This is the interface for knowing what materials are available
  795. // is to use the following functions to get a list of materials. The
  796. // material names will have the full path to the material, and that is the
  797. // only way that the directory structure of the materials will be seen through this
  798. // interface.
  799. // NOTE: This is mostly for worldcraft to get a list of materials to put
  800. // in the "texture" browser.in Worldcraft
  801. virtual MaterialHandle_t FirstMaterial() const
  802. {
  803. return 0;
  804. }
  805. // returns InvalidMaterial if there isn't another material.
  806. // WARNING: you must call GetNextMaterial until it returns NULL,
  807. // otherwise there will be a memory leak.
  808. virtual MaterialHandle_t NextMaterial( MaterialHandle_t h ) const
  809. {
  810. return 0;
  811. }
  812. // This is the invalid material
  813. virtual MaterialHandle_t InvalidMaterial() const
  814. {
  815. if ( m_pRealMaterialSystem )
  816. return m_pRealMaterialSystem->InvalidMaterial();
  817. else
  818. return 0;
  819. }
  820. // Returns a particular material
  821. virtual IMaterial* GetMaterial( MaterialHandle_t h ) const
  822. {
  823. if ( m_pRealMaterialSystem )
  824. return m_pRealMaterialSystem->GetMaterial( h );
  825. else
  826. return &g_DummyMaterial;
  827. }
  828. // Find a material by name.
  829. // The name of a material is a full path to
  830. // the vmt file starting from "hl2/materials" (or equivalent) without
  831. // a file extension.
  832. // eg. "dev/dev_bumptest" refers to somethign similar to:
  833. // "d:/hl2/hl2/materials/dev/dev_bumptest.vmt"
  834. virtual IMaterial *FindMaterial( char const* pMaterialName, const char *pTextureGroupName, bool complain = true, const char *pComplainPrefix = NULL )
  835. {
  836. if ( m_pRealMaterialSystem )
  837. return m_pRealMaterialSystem->FindMaterial( pMaterialName, pTextureGroupName, complain, pComplainPrefix );
  838. return &g_DummyMaterial;
  839. }
  840. virtual IMaterial *FindProceduralMaterial( const char *pMaterialName, const char *pTextureGroupName, KeyValues *pVMTKeyValues )
  841. {
  842. if ( m_pRealMaterialSystem )
  843. return m_pRealMaterialSystem->FindProceduralMaterial( pMaterialName, pTextureGroupName, pVMTKeyValues );
  844. return &g_DummyMaterial;
  845. }
  846. virtual bool LoadKeyValuesFromVMTFile( KeyValues &vmtKeyValues, const char *pMaterialName, bool bUsesUNCFilename )
  847. {
  848. if ( m_pRealMaterialSystem )
  849. return m_pRealMaterialSystem->LoadKeyValuesFromVMTFile( vmtKeyValues, pMaterialName, bUsesUNCFilename );
  850. return true;
  851. }
  852. virtual ITexture *FindTexture( char const* pTextureName, const char *pTextureGroupName, bool complain = true, int nAdditionalCreationFlags = 0)
  853. {
  854. if ( m_pRealMaterialSystem )
  855. return m_pRealMaterialSystem->FindTexture( pTextureName, pTextureGroupName, complain, nAdditionalCreationFlags );
  856. return &g_DummyTexture;
  857. }
  858. virtual void BindLocalCubemap( ITexture *pTexture )
  859. {
  860. }
  861. virtual ITexture *GetLocalCubemap( )
  862. {
  863. return &g_DummyTexture;
  864. }
  865. // pass in an ITexture (that is build with "rendertarget" "1") or
  866. // pass in NULL for the regular backbuffer.
  867. virtual void SetRenderTarget( ITexture *pTexture )
  868. {
  869. }
  870. virtual ITexture * GetRenderTarget( void )
  871. {
  872. return &g_DummyTexture;
  873. }
  874. virtual void SetRenderTargetEx( int nRenderTargetID, ITexture *pTexture )
  875. {
  876. }
  877. virtual ITexture * GetRenderTargetEx( int nRenderTargetID )
  878. {
  879. return &g_DummyTexture;
  880. }
  881. virtual void GetRenderTargetDimensions( int &width, int &height) const
  882. {
  883. width = 256;
  884. height = 256;
  885. }
  886. // Get the total number of materials in the system. These aren't just the used
  887. // materials, but the complete collection.
  888. virtual int GetNumMaterials( ) const
  889. {
  890. return m_pRealMaterialSystem->GetNumMaterials();
  891. }
  892. // Remove any materials from memory that aren't in use as determined
  893. // by the IMaterial's reference count.
  894. virtual void UncacheUnusedMaterials( bool bRecomputeStateSnapshots )
  895. {
  896. if ( m_pRealMaterialSystem )
  897. {
  898. m_pRealMaterialSystem->UncacheUnusedMaterials( bRecomputeStateSnapshots );
  899. }
  900. }
  901. // uncache all materials. . good for forcing reload of materials.
  902. virtual void UncacheAllMaterials( )
  903. {
  904. if ( m_pRealMaterialSystem )
  905. m_pRealMaterialSystem->UncacheAllMaterials();
  906. }
  907. // Load any materials into memory that are to be used as determined
  908. // by the IMaterial's reference count.
  909. virtual void CacheUsedMaterials( )
  910. {
  911. if ( m_pRealMaterialSystem )
  912. m_pRealMaterialSystem->CacheUsedMaterials( );
  913. }
  914. // Force all textures to be reloaded from disk.
  915. virtual void ReloadTextures( )
  916. {
  917. }
  918. // Allows us to override the depth buffer setting of a material
  919. virtual void OverrideDepthEnable( bool bEnable, bool bDepthWriteEnable, bool bDepthTestEnable = true )
  920. {
  921. }
  922. virtual void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable )
  923. {
  924. }
  925. virtual void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable )
  926. {
  927. }
  928. //
  929. // lightmap allocation stuff
  930. //
  931. // To allocate lightmaps, sort the whole world by material twice.
  932. // The first time through, call AllocateLightmap for every surface.
  933. // that has a lightmap.
  934. // The second time through, call AllocateWhiteLightmap for every
  935. // surface that expects to use shaders that expect lightmaps.
  936. virtual void BeginLightmapAllocation( )
  937. {
  938. }
  939. // returns the sorting id for this surface
  940. virtual int AllocateLightmap( int width, int height,
  941. int offsetIntoLightmapPage[2],
  942. IMaterial *pMaterial )
  943. {
  944. return 0;
  945. }
  946. // returns a lightmap page ID for this allocation, -1 if none available
  947. virtual int AllocateDynamicLightmap( int lightmapSize[2], int *pOutOffsetIntoPage, int frameID )
  948. {
  949. return -1;
  950. }
  951. // returns the sorting id for this surface
  952. virtual int AllocateWhiteLightmap( IMaterial *pMaterial )
  953. {
  954. return 0;
  955. }
  956. virtual void EndLightmapAllocation( )
  957. {
  958. }
  959. virtual void CleanupLightmaps()
  960. {
  961. }
  962. // lightmaps are in linear color space
  963. // lightmapPageID is returned by GetLightmapPageIDForSortID
  964. // lightmapSize and offsetIntoLightmapPage are returned by AllocateLightmap.
  965. // You should never call UpdateLightmap for a lightmap allocated through
  966. // AllocateWhiteLightmap.
  967. virtual void UpdateLightmap( int lightmapPageID, int lightmapSize[2],
  968. int offsetIntoLightmapPage[2],
  969. float *pFloatImage, float *pFloatImageBump1,
  970. float *pFloatImageBump2, float *pFloatImageBump3 )
  971. {
  972. }
  973. // Force the lightmaps updated with UpdateLightmap to be sent to the hardware.
  974. virtual void FlushLightmaps( )
  975. {
  976. }
  977. // fixme: could just be an array of ints for lightmapPageIDs since the material
  978. // for a surface is already known.
  979. virtual int GetNumSortIDs( )
  980. {
  981. return 10;
  982. }
  983. // virtual int GetLightmapPageIDForSortID( int sortID ) = 0;
  984. virtual void GetSortInfo( MaterialSystem_SortInfo_t *pSortInfoArray )
  985. {
  986. }
  987. virtual void BeginFrame( float )
  988. {
  989. }
  990. virtual void EndFrame( )
  991. {
  992. }
  993. virtual bool IsInFrame() const { return false; }
  994. virtual uint32 GetCurrentFrameCount() { return 0; }
  995. // Bind a material is current for rendering.
  996. virtual void Bind( IMaterial *material, void *proxyData = 0 )
  997. {
  998. }
  999. // Bind a lightmap page current for rendering. You only have to
  1000. // do this for materials that require lightmaps.
  1001. virtual void BindLightmapPage( int lightmapPageID )
  1002. {
  1003. }
  1004. // inputs are between 0 and 1
  1005. virtual void DepthRange( float zNear, float zFar )
  1006. {
  1007. }
  1008. virtual void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil )
  1009. {
  1010. }
  1011. virtual void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth )
  1012. {
  1013. }
  1014. virtual void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth )
  1015. {
  1016. }
  1017. virtual void PerformFullScreenStencilOperation( void )
  1018. {
  1019. }
  1020. // read to a unsigned char rgb image.
  1021. virtual void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat, ITexture *pRenderTargetTexture = NULL )
  1022. {
  1023. }
  1024. virtual void ReadPixelsAsync( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat, ITexture *pRenderTargetTexture = NULL, CThreadEvent *pPixelsReadEvent = NULL )
  1025. {
  1026. }
  1027. virtual void ReadPixelsAsyncGetResult( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat, CThreadEvent *pGetResultEvent = NULL )
  1028. {
  1029. }
  1030. // Read w/ stretch to a host-memory buffer
  1031. virtual void ReadPixelsAndStretch( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *pBuffer, ImageFormat dstFormat, int nDstStride )
  1032. {
  1033. }
  1034. // Sets lighting
  1035. virtual void SetLightingState( const MaterialLightingState_t &state )
  1036. {
  1037. }
  1038. virtual void SetLights( int nCount, const LightDesc_t *pDesc )
  1039. {
  1040. }
  1041. virtual void SetLightingOrigin( Vector vLightingOrigin )
  1042. {
  1043. }
  1044. // The faces of the cube are specified in the same order as cubemap textures
  1045. virtual void SetAmbientLightCube( Vector4D cube[6] )
  1046. {
  1047. }
  1048. // Blit the backbuffer to the framebuffer texture
  1049. virtual void CopyRenderTargetToTexture( ITexture * )
  1050. {
  1051. }
  1052. virtual void SetFrameBufferCopyTexture( ITexture *pTexture, int textureIndex )
  1053. {
  1054. }
  1055. virtual ITexture * GetFrameBufferCopyTexture( int textureIndex )
  1056. {
  1057. return &g_DummyTexture;
  1058. }
  1059. // do we need this?
  1060. virtual void Flush( bool flushHardware = false )
  1061. {
  1062. }
  1063. //
  1064. // end vertex array api
  1065. //
  1066. //
  1067. // Debugging tools
  1068. //
  1069. virtual void DebugPrintUsedMaterials( const char *pSearchSubString, bool bVerbose )
  1070. {
  1071. }
  1072. virtual void DebugPrintAspectRatioInfo( const char *pSearchSubString, bool bVerbose )
  1073. {
  1074. }
  1075. virtual void DebugPrintUsedTextures( void )
  1076. {
  1077. }
  1078. virtual void ToggleSuppressMaterial( char const* pMaterialName )
  1079. {
  1080. }
  1081. virtual void ToggleDebugMaterial( char const* pMaterialName )
  1082. {
  1083. }
  1084. // matrix api
  1085. virtual void MatrixMode( MaterialMatrixMode_t matrixMode )
  1086. {
  1087. }
  1088. virtual void PushMatrix( void )
  1089. {
  1090. }
  1091. virtual void PopMatrix( void )
  1092. {
  1093. }
  1094. /*
  1095. virtual void LoadMatrix( float * )
  1096. {
  1097. }
  1098. */
  1099. // Methods that use VMatrix
  1100. virtual void LoadMatrix( const VMatrix& matrix )
  1101. {
  1102. }
  1103. virtual void LoadMatrix( const matrix3x4_t& matrix )
  1104. {
  1105. }
  1106. virtual void LoadBoneMatrix( int boneIndex, const matrix3x4_t& matrix )
  1107. {
  1108. }
  1109. virtual void MultMatrix( const VMatrix& matrix )
  1110. {
  1111. }
  1112. virtual void MultMatrix( const matrix3x4_t& matrix )
  1113. {
  1114. }
  1115. virtual void MultMatrixLocal( const VMatrix& matrix )
  1116. {
  1117. }
  1118. virtual void MultMatrixLocal( const matrix3x4_t& matrix )
  1119. {
  1120. }
  1121. virtual void GetMatrix( MaterialMatrixMode_t matrixMode, VMatrix *pMatrix )
  1122. {
  1123. pMatrix->Identity();
  1124. }
  1125. virtual void GetMatrix( MaterialMatrixMode_t matrixMode, matrix3x4_t *pMatrix )
  1126. {
  1127. SetIdentityMatrix( *pMatrix );
  1128. }
  1129. virtual void LoadIdentity( void )
  1130. {
  1131. }
  1132. virtual void Ortho( double left, double top, double right, double bottom, double zNear, double zFar )
  1133. {
  1134. }
  1135. virtual void PerspectiveX( double fovx, double aspect, double zNear, double zFar )
  1136. {
  1137. }
  1138. virtual void PickMatrix( int x, int y, int width, int height )
  1139. {
  1140. }
  1141. virtual void Rotate( float angle, float x, float y, float z )
  1142. {
  1143. }
  1144. virtual void Translate( float x, float y, float z )
  1145. {
  1146. }
  1147. virtual void Scale( float x, float y, float z )
  1148. {
  1149. }
  1150. // end matrix api
  1151. // Sets/gets the viewport
  1152. virtual void Viewport( int x, int y, int width, int height )
  1153. {
  1154. }
  1155. virtual void GetViewport( int& x, int& y, int& width, int& height ) const
  1156. {
  1157. x = y = 0;
  1158. width = height = 640;
  1159. }
  1160. // The cull mode
  1161. virtual void CullMode( MaterialCullMode_t cullMode )
  1162. {
  1163. }
  1164. virtual void FlipCullMode( void )
  1165. {
  1166. }
  1167. virtual void BeginGeneratingCSMs()
  1168. {
  1169. }
  1170. virtual void EndGeneratingCSMs()
  1171. {
  1172. }
  1173. virtual void PerpareForCascadeDraw( int cascade, float fShadowSlopeScaleDepthBias, float fShadowDepthBias )
  1174. {
  1175. }
  1176. // end matrix api
  1177. // Force writes only when z matches. . . useful for stenciling things out
  1178. // by rendering the desired Z values ahead of time.
  1179. // virtual void ForceDepthFuncEquals( bool bEnable ) = 0;
  1180. // virtual void RenderZOnlyWithHeightClip( bool bEnable ) = 0;
  1181. // This could easily be extended to a general user clip plane
  1182. virtual void SetHeightClipMode( MaterialHeightClipMode_t nClipMode )
  1183. {
  1184. }
  1185. virtual MaterialHeightClipMode_t GetHeightClipMode( )
  1186. {
  1187. return MATERIAL_HEIGHTCLIPMODE_DISABLE;
  1188. }
  1189. // garymcthack : fog z is always used for heightclipz for now.
  1190. virtual void SetHeightClipZ( float z )
  1191. {
  1192. }
  1193. // Fog methods...
  1194. virtual void FogMode( MaterialFogMode_t fogMode )
  1195. {
  1196. }
  1197. MaterialFogMode_t GetFogMode( void )
  1198. {
  1199. return MATERIAL_FOG_NONE;
  1200. }
  1201. virtual void FogStart( float fStart )
  1202. {
  1203. }
  1204. virtual void FogEnd( float fEnd )
  1205. {
  1206. }
  1207. virtual void FogMaxDensity( float flMaxDensity )
  1208. {
  1209. }
  1210. virtual void SetFogZ( float fogZ )
  1211. {
  1212. }
  1213. virtual void GetFogDistances( float *fStart, float *fEnd, float *fFogZ )
  1214. {
  1215. }
  1216. virtual void FogColor3f( float r, float g, float b )
  1217. {
  1218. }
  1219. virtual void FogColor3fv( float const* rgb )
  1220. {
  1221. }
  1222. virtual void FogColor3ub( unsigned char r, unsigned char g, unsigned char b )
  1223. {
  1224. }
  1225. virtual void FogColor3ubv( unsigned char const* rgb )
  1226. {
  1227. }
  1228. virtual void GetFogColor( unsigned char *rgb )
  1229. {
  1230. }
  1231. // Sets the number of bones for skinning
  1232. virtual void SetNumBoneWeights( int numBones )
  1233. {
  1234. }
  1235. virtual IMaterialProxyFactory *GetMaterialProxyFactory()
  1236. {
  1237. return NULL;
  1238. }
  1239. virtual void SetMaterialProxyFactory( IMaterialProxyFactory* pFactory )
  1240. {
  1241. }
  1242. virtual IClientMaterialSystem* GetClientMaterialSystemInterface()
  1243. {
  1244. return NULL;
  1245. }
  1246. // Read the page size of an existing lightmap by sort id (returned from AllocateLightmap())
  1247. virtual void GetLightmapPageSize( int lightmap, int *width, int *height ) const
  1248. {
  1249. if ( m_pRealMaterialSystem )
  1250. m_pRealMaterialSystem->GetLightmapPageSize( lightmap, width, height );
  1251. else
  1252. *width = *height = 32;
  1253. }
  1254. virtual int GetNumLightmapPages() const
  1255. {
  1256. return 0;
  1257. }
  1258. /// FIXME: This stuff needs to be cleaned up and abstracted.
  1259. // Stuff that gets exported to the launcher through the engine
  1260. virtual void SwapBuffers( )
  1261. {
  1262. }
  1263. // Use this to spew information about the 3D layer
  1264. virtual void SpewDriverInfo() const
  1265. {
  1266. }
  1267. // Creates/destroys Mesh
  1268. virtual IMesh* CreateStaticMesh( VertexFormat_t fmt, const char *pTextureBudgetGroup, IMaterial * pMaterial, VertexStreamSpec_t *pStreamSpec )
  1269. {
  1270. return GetDummyMesh();
  1271. }
  1272. virtual void DestroyStaticMesh( IMesh* mesh )
  1273. {
  1274. }
  1275. // Gets the dynamic mesh associated with the currently bound material
  1276. // note that you've got to render the mesh before calling this function
  1277. // a second time. Clients should *not* call DestroyStaticMesh on the mesh
  1278. // returned by this call.
  1279. // Use buffered = false if you want to not have the mesh be buffered,
  1280. // but use it instead in the following pattern:
  1281. // meshBuilder.Begin
  1282. // meshBuilder.End
  1283. // Draw partial
  1284. // Draw partial
  1285. // Draw partial
  1286. // meshBuilder.Begin
  1287. // meshBuilder.End
  1288. // etc
  1289. // Use Vertex or Index Override to supply a static vertex or index buffer
  1290. // to use in place of the dynamic buffers.
  1291. //
  1292. // If you pass in a material in pAutoBind, it will automatically bind the
  1293. // material. This can be helpful since you must bind the material you're
  1294. // going to use BEFORE calling GetDynamicMesh.
  1295. virtual IMesh* GetDynamicMesh( bool bBuffered = true, IMesh* pVertexOverride = 0,
  1296. IMesh* pIndexOverride = 0, IMaterial *pAutoBind = 0 )
  1297. {
  1298. return GetDummyMesh();
  1299. }
  1300. virtual IMesh* GetDynamicMeshEx( VertexFormat_t vertexFormat, bool bBuffered = true,
  1301. IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0, IMaterial *pAutoBind = 0 )
  1302. {
  1303. return GetDummyMesh();
  1304. }
  1305. virtual IMesh *GetFlexMesh()
  1306. {
  1307. return GetDummyMesh();
  1308. }
  1309. // Selection mode methods
  1310. virtual int SelectionMode( bool selectionMode )
  1311. {
  1312. return 0;
  1313. }
  1314. virtual void SelectionBuffer( unsigned int* pBuffer, int size )
  1315. {
  1316. }
  1317. virtual void ClearSelectionNames( )
  1318. {
  1319. }
  1320. virtual void LoadSelectionName( int name )
  1321. {
  1322. }
  1323. virtual void PushSelectionName( int name )
  1324. {
  1325. }
  1326. virtual void PopSelectionName()
  1327. {
  1328. }
  1329. // Installs a function to be called when we need to release vertex buffers + textures
  1330. virtual void AddReleaseFunc( MaterialBufferReleaseFunc_t func )
  1331. {
  1332. }
  1333. virtual void RemoveReleaseFunc( MaterialBufferReleaseFunc_t func )
  1334. {
  1335. }
  1336. // Installs a function to be called when we need to restore vertex buffers
  1337. virtual void AddRestoreFunc( MaterialBufferRestoreFunc_t func )
  1338. {
  1339. }
  1340. virtual void RemoveRestoreFunc( MaterialBufferRestoreFunc_t func )
  1341. {
  1342. }
  1343. // Installs a function to be called when we need to delete objects at the end of the render frame
  1344. virtual void AddEndFrameCleanupFunc( EndFrameCleanupFunc_t func )
  1345. {
  1346. }
  1347. virtual void RemoveEndFrameCleanupFunc( EndFrameCleanupFunc_t func )
  1348. {
  1349. }
  1350. // Gets called when the level is shuts down, will call the registered callback
  1351. virtual void OnLevelShutdown()
  1352. {
  1353. }
  1354. // Installs a function to be called when the level is shuts down
  1355. virtual bool AddOnLevelShutdownFunc( OnLevelShutdownFunc_t func, void * pUserData )
  1356. {
  1357. return false;
  1358. }
  1359. virtual bool RemoveOnLevelShutdownFunc( OnLevelShutdownFunc_t func, void * pUserData )
  1360. {
  1361. return false;
  1362. }
  1363. virtual void OnLevelLoadingComplete()
  1364. {
  1365. }
  1366. virtual void AddEndFramePriorToNextContextFunc( EndFramePriorToNextContextFunc_t func )
  1367. {
  1368. }
  1369. virtual void RemoveEndFramePriorToNextContextFunc( EndFramePriorToNextContextFunc_t func )
  1370. {
  1371. }
  1372. // Stuff for probing properties of shaders.
  1373. virtual int GetNumShaders( void ) const
  1374. {
  1375. return 0;
  1376. }
  1377. virtual const char * GetShaderName( int shaderID ) const
  1378. {
  1379. return NULL;
  1380. }
  1381. virtual int GetNumShaderParams( int shaderID ) const
  1382. {
  1383. return 0;
  1384. }
  1385. virtual const char * GetShaderParamName( int shaderID, int paramID ) const
  1386. {
  1387. return NULL;
  1388. }
  1389. virtual const char * GetShaderParamHelp( int shaderID, int paramID ) const
  1390. {
  1391. return NULL;
  1392. }
  1393. virtual ShaderParamType_t GetShaderParamType( int shaderID, int paramID ) const
  1394. {
  1395. return ( enum ShaderParamType_t )0;
  1396. }
  1397. virtual const char * GetShaderParamDefault( int shaderID, int paramID ) const
  1398. {
  1399. return NULL;
  1400. }
  1401. // Reloads materials
  1402. virtual void ReloadMaterials( const char *pSubString = NULL )
  1403. {
  1404. }
  1405. virtual void ResetMaterialLightmapPageInfo()
  1406. {
  1407. }
  1408. // -----------------------------------------------------------
  1409. // Stereo
  1410. // -----------------------------------------------------------
  1411. virtual bool IsStereoSupported()
  1412. {
  1413. return false;
  1414. }
  1415. virtual bool IsStereoActiveThisFrame() const
  1416. {
  1417. return false;
  1418. }
  1419. virtual void NVStereoUpdate()
  1420. {
  1421. }
  1422. virtual ITexture* CreateRenderTargetTexture(
  1423. int w,
  1424. int h,
  1425. RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change).
  1426. ImageFormat format,
  1427. MaterialRenderTargetDepth_t depth )
  1428. {
  1429. return &g_DummyTexture;
  1430. }
  1431. virtual ITexture *CreateProceduralTexture(
  1432. const char *pTextureName,
  1433. const char *pTextureGroupName,
  1434. int w,
  1435. int h,
  1436. ImageFormat fmt,
  1437. int nFlags )
  1438. {
  1439. return &g_DummyTexture;
  1440. }
  1441. virtual ICustomMaterialManager *GetCustomMaterialManager()
  1442. {
  1443. return m_pRealMaterialSystem->GetCustomMaterialManager();
  1444. }
  1445. virtual ICompositeTextureGenerator *GetCompositeTextureGenerator()
  1446. {
  1447. return m_pRealMaterialSystem->GetCompositeTextureGenerator();
  1448. }
  1449. #if defined( _X360 )
  1450. virtual ITexture *CreateGamerpicTexture(
  1451. const char *pTextureName,
  1452. const char *pTextureGroupName,
  1453. int nFlags )
  1454. {
  1455. return &g_DummyTexture;
  1456. }
  1457. virtual bool UpdateLocalGamerpicTexture(
  1458. ITexture *pTexture,
  1459. DWORD userIndex )
  1460. {
  1461. return true;
  1462. }
  1463. virtual bool UpdateRemoteGamerpicTexture(
  1464. ITexture *pTexture,
  1465. XUID xuid )
  1466. {
  1467. return true;
  1468. }
  1469. #endif // _X360
  1470. // Sets the Clear Color for ClearBuffer....
  1471. virtual void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b )
  1472. {
  1473. }
  1474. virtual void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a )
  1475. {
  1476. }
  1477. virtual void SetInStubMode( bool b )
  1478. {
  1479. }
  1480. // Create new materials
  1481. virtual IMaterial *CreateMaterial( const char *pMaterialName, KeyValues *pVMTKeyValues )
  1482. {
  1483. return &g_DummyMaterial;
  1484. }
  1485. void GetBackBufferDimensions( int &w, int &h ) const
  1486. {
  1487. if ( IsPC() )
  1488. {
  1489. w = 1024;
  1490. h = 768;
  1491. }
  1492. else
  1493. {
  1494. w = 640;
  1495. h = 480;
  1496. }
  1497. }
  1498. ImageFormat GetBackBufferFormat( void ) const
  1499. {
  1500. return IMAGE_FORMAT_RGBA8888;
  1501. }
  1502. virtual const AspectRatioInfo_t &GetAspectRatioInfo( void ) const
  1503. {
  1504. static AspectRatioInfo_t dummy;
  1505. return dummy;
  1506. }
  1507. // FIXME: This is a hack required for NVidia/XBox, can they fix in drivers?
  1508. virtual void DrawScreenSpaceQuad( IMaterial* pMaterial ) {}
  1509. // FIXME: Test interface
  1510. virtual bool Connect( CreateInterfaceFn factory ) { return true; }
  1511. virtual void Disconnect() {}
  1512. virtual void *QueryInterface( const char *pInterfaceName ) { return NULL; }
  1513. virtual const AppSystemInfo_t *GetDependencies( ) { return NULL; }
  1514. virtual AppSystemTier_t GetTier() { return APP_SYSTEM_TIER2; }
  1515. virtual InitReturnVal_t Init() { return INIT_OK; }
  1516. virtual void Reconnect( CreateInterfaceFn factory, const char *pInterfaceName ) {}
  1517. virtual void SetShaderAPI( const char *pShaderAPIDLL ) {}
  1518. virtual void SetAdapter( int nAdapter, int nFlags ) {}
  1519. // Release temporary HW memory...
  1520. virtual void ResetTempHWMemory( bool bExitingLevel ) {}
  1521. virtual ITexture* CreateNamedRenderTargetTextureEx(
  1522. const char *pRTName, // Pass in NULL here for an unnamed render target.
  1523. int w,
  1524. int h,
  1525. RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change).
  1526. ImageFormat format,
  1527. MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED,
  1528. unsigned int textureFlags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
  1529. unsigned int renderTargetFlags = 0
  1530. )
  1531. {
  1532. return &g_DummyTexture;
  1533. }
  1534. virtual ITexture* CreateNamedRenderTargetTexture(
  1535. const char *pRTName,
  1536. int w,
  1537. int h,
  1538. RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change).
  1539. ImageFormat format,
  1540. MaterialRenderTargetDepth_t depth,
  1541. bool bClampTexCoords,
  1542. bool bAutoMipMap
  1543. )
  1544. {
  1545. return &g_DummyTexture;
  1546. }
  1547. virtual void SyncToken( const char *pToken ) {}
  1548. virtual float ComputePixelWidthOfSphere( const Vector& origin, float flRadius )
  1549. {
  1550. return 1.0f;
  1551. }
  1552. virtual float ComputePixelDiameterOfSphere( const Vector& origin, float flRadius )
  1553. {
  1554. return 1.0f;
  1555. }
  1556. OcclusionQueryObjectHandle_t CreateOcclusionQueryObject( void )
  1557. {
  1558. return INVALID_OCCLUSION_QUERY_OBJECT_HANDLE;
  1559. }
  1560. void DestroyOcclusionQueryObject( OcclusionQueryObjectHandle_t handle )
  1561. {
  1562. }
  1563. void ResetOcclusionQueryObject( OcclusionQueryObjectHandle_t hOcclusionQuery ) {}
  1564. void BeginOcclusionQueryDrawing( OcclusionQueryObjectHandle_t handle )
  1565. {
  1566. }
  1567. void EndOcclusionQueryDrawing( OcclusionQueryObjectHandle_t handle )
  1568. {
  1569. }
  1570. int OcclusionQuery_GetNumPixelsRendered( OcclusionQueryObjectHandle_t handle )
  1571. {
  1572. return 0;
  1573. }
  1574. virtual void SetFlashlightMode( bool )
  1575. {
  1576. }
  1577. virtual void SetRenderingPaint( bool bEnable ) {}
  1578. virtual bool IsRenderingPaint() const { return false; }
  1579. virtual bool GetFlashlightMode( void ) const
  1580. {
  1581. return false;
  1582. }
  1583. virtual bool IsCullingEnabledForSinglePassFlashlight() const
  1584. {
  1585. return false;
  1586. }
  1587. virtual void EnableCullingForSinglePassFlashlight( bool bEnable ) {}
  1588. virtual bool InFlashlightMode( void ) const
  1589. {
  1590. return false;
  1591. }
  1592. virtual void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture )
  1593. {
  1594. }
  1595. virtual void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture )
  1596. {
  1597. }
  1598. virtual bool IsCascadedShadowMapping() const
  1599. {
  1600. return false;
  1601. }
  1602. virtual void SetCascadedShadowMapping( bool bEnable )
  1603. {
  1604. bEnable;
  1605. }
  1606. virtual void SetCascadedShadowMappingState( const CascadedShadowMappingState_t &state, ITexture *pDepthTextureAtlas )
  1607. {
  1608. state, pDepthTextureAtlas;
  1609. }
  1610. virtual void PushScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom )
  1611. {
  1612. }
  1613. virtual void PopScissorRect()
  1614. {
  1615. }
  1616. virtual void PushDeformation( DeformationBase_t const *Deformation )
  1617. {
  1618. }
  1619. virtual void PopDeformation( )
  1620. {
  1621. }
  1622. virtual int GetNumActiveDeformations() const
  1623. {
  1624. return 0;
  1625. }
  1626. // Get the current config for this video card (as last set by control panel or the default if not)
  1627. virtual const MaterialSystem_Config_t &GetCurrentConfigForVideoCard() const
  1628. {
  1629. static MaterialSystem_Config_t dummy;
  1630. return dummy;
  1631. }
  1632. // Get video card identitier
  1633. virtual const MaterialSystemHardwareIdentifier_t &GetVideoCardIdentifier( void ) const
  1634. {
  1635. static MaterialSystemHardwareIdentifier_t dummy;
  1636. return dummy;
  1637. }
  1638. virtual void AddModeChangeCallBack( ModeChangeCallbackFunc_t func )
  1639. {
  1640. }
  1641. virtual void RemoveModeChangeCallBack( ModeChangeCallbackFunc_t func )
  1642. {
  1643. }
  1644. virtual bool GetRecommendedVideoConfig( KeyValues *pKeyValues )
  1645. {
  1646. return false;
  1647. }
  1648. virtual bool GetRecommendedConfigurationInfo( int nDxLevel, KeyValues *pKeyValues )
  1649. {
  1650. return false;
  1651. }
  1652. virtual void EnableUserClipTransformOverride( bool bEnable )
  1653. {
  1654. }
  1655. virtual void UserClipTransform( const VMatrix &worldToProjection )
  1656. {
  1657. }
  1658. // Used to iterate over all shaders for editing purposes
  1659. virtual int ShaderCount() const
  1660. {
  1661. return 0;
  1662. }
  1663. virtual int GetShaders( int nFirstShader, int nCount, IShader **ppShaderList ) const
  1664. {
  1665. return 0;
  1666. }
  1667. // Used to enable editor materials. Must be called before Init.
  1668. virtual void EnableEditorMaterials()
  1669. {
  1670. }
  1671. virtual void EnableGBuffers()
  1672. {
  1673. }
  1674. // Used to enable editor materials. Must be called before Init.
  1675. virtual int GetCurrentAdapter() const
  1676. {
  1677. return 0;
  1678. }
  1679. // Creates/destroys morph data associated w/ a particular material
  1680. IMorph *CreateMorph( MorphFormat_t, const char *pDebugName )
  1681. {
  1682. static CDummyMorph s_DummyMorph;
  1683. return &s_DummyMorph;
  1684. }
  1685. void DestroyMorph( IMorph *pMorph )
  1686. {
  1687. }
  1688. void BindMorph( IMorph *pMorph )
  1689. {
  1690. }
  1691. // Sets morph target factors
  1692. virtual void SetMorphTargetFactors( int nTargetId, float *pValue, int nCount )
  1693. {
  1694. }
  1695. virtual void SetToneMappingScaleLinear( const Vector &scale )
  1696. {
  1697. }
  1698. virtual void EvictManagedResources()
  1699. {
  1700. }
  1701. // Gets the window size
  1702. virtual void GetWindowSize( int &width, int &height ) const
  1703. {
  1704. width = height = 0;
  1705. if ( m_pRealMaterialSystem )
  1706. {
  1707. CMatRenderContextPtr pRenderContext( m_pRealMaterialSystem );
  1708. pRenderContext->GetWindowSize(width, height);
  1709. }
  1710. }
  1711. // For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer)
  1712. virtual void HandleDeviceLost()
  1713. {
  1714. }
  1715. virtual void AppUsesRenderTargets()
  1716. {
  1717. }
  1718. virtual void DrawScreenSpaceRectangle(
  1719. IMaterial *pMaterial,
  1720. int destx, int desty,
  1721. int width, int height,
  1722. float src_texture_x0, float src_texture_y0,
  1723. float src_texture_x1, float src_texture_y1,
  1724. int src_texture_width, int src_texture_height,
  1725. void *pClientRenderable = NULL,
  1726. int nXDice = 1,
  1727. int nYDice = 1 )
  1728. {
  1729. }
  1730. virtual void BeginRenderTargetAllocation()
  1731. {
  1732. }
  1733. // Simulate an Alt-Tab in here, which causes a release/restore of all resources
  1734. virtual void EndRenderTargetAllocation()
  1735. {
  1736. }
  1737. void FinishRenderTargetAllocation( void )
  1738. {
  1739. }
  1740. void ReEnableRenderTargetAllocation_IRealizeIfICallThisAllTexturesWillBeUnloadedAndLoadTimeWillSufferHorribly( void )
  1741. {
  1742. }
  1743. ITexture *CreateNamedRenderTargetTextureEx2(
  1744. const char *pRTName, // Pass in NULL here for an unnamed render target.
  1745. int w,
  1746. int h,
  1747. RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change).
  1748. ImageFormat format,
  1749. MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED,
  1750. unsigned int textureFlags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
  1751. unsigned int renderTargetFlags = 0
  1752. )
  1753. {
  1754. return NULL;
  1755. };
  1756. ITexture *CreateNamedMultiRenderTargetTexture(
  1757. const char *pRTName, // Pass in NULL here for an unnamed render target.
  1758. int w,
  1759. int h,
  1760. RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change).
  1761. ImageFormat format,
  1762. MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED,
  1763. unsigned int textureFlags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
  1764. unsigned int renderTargetFlags = 0
  1765. )
  1766. {
  1767. return NULL;
  1768. };
  1769. void PushRenderTargetAndViewport( )
  1770. {
  1771. }
  1772. void PushRenderTargetAndViewport( ITexture *pTexture )
  1773. {
  1774. }
  1775. void PushRenderTargetAndViewport( ITexture *pTexture, int nViewX, int nViewY, int nViewW, int nViewH )
  1776. {
  1777. }
  1778. void PushRenderTargetAndViewport( ITexture *pTexture, ITexture *pDepthTexture, int nViewX, int nViewY, int nViewW, int nViewH )
  1779. {
  1780. }
  1781. void PopRenderTargetAndViewport( void )
  1782. {
  1783. }
  1784. virtual int ShaderFlagCount() const
  1785. {
  1786. return 0;
  1787. }
  1788. virtual const char *ShaderFlagName( int nIndex ) const
  1789. {
  1790. return "";
  1791. }
  1792. virtual void BindLightmapTexture( ITexture *pLightmapTexture )
  1793. {
  1794. }
  1795. // Returns the currently active shader fallback for a particular shader
  1796. virtual void GetShaderFallback( const char *pShaderName, char *pFallbackShader, int nFallbackLength )
  1797. {
  1798. pFallbackShader[0] = 0;
  1799. }
  1800. #if defined( DX_TO_GL_ABSTRACTION ) && !defined( _GAMECONSOLE )
  1801. virtual void DoStartupShaderPreloading( void )
  1802. {
  1803. }
  1804. #endif
  1805. // Blit a subrect of the current render target to another texture
  1806. virtual void CopyRenderTargetToTextureEx( ITexture *pTexture, int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect = NULL )
  1807. {
  1808. }
  1809. virtual void CopyTextureToRenderTargetEx( int nRenderTargetID, ITexture *pTexture, Rect_t *pSrcRect, Rect_t *pDstRect = NULL )
  1810. {
  1811. }
  1812. bool IsTextureLoaded( char const* pTextureName ) const
  1813. {
  1814. return false;
  1815. }
  1816. bool GetTextureInformation( char const *szTextureName, MaterialTextureInfo_t &info ) const
  1817. {
  1818. return false;
  1819. }
  1820. void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right )
  1821. {
  1822. }
  1823. void SetFloatRenderingParameter(int parm_number, float value)
  1824. {
  1825. }
  1826. void SetIntRenderingParameter(int parm_number, int value)
  1827. {
  1828. }
  1829. void SetTextureRenderingParameter(int parm_number, ITexture *pTexture)
  1830. {
  1831. }
  1832. void SetVectorRenderingParameter(int parm_number, Vector const &value)
  1833. {
  1834. }
  1835. float GetFloatRenderingParameter(int parm_number) const
  1836. {
  1837. return 0;
  1838. }
  1839. int GetIntRenderingParameter(int parm_number) const
  1840. {
  1841. return 0;
  1842. }
  1843. ITexture *GetTextureRenderingParameter(int parm_number) const
  1844. {
  1845. return NULL;
  1846. }
  1847. Vector GetVectorRenderingParameter(int parm_number) const
  1848. {
  1849. return Vector(0,0,0);
  1850. }
  1851. void ReleaseResources(void)
  1852. {
  1853. }
  1854. void ReacquireResources(void)
  1855. {
  1856. }
  1857. Vector GetToneMappingScaleLinear( void )
  1858. {
  1859. return Vector(1,1,1);
  1860. }
  1861. virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices )
  1862. {
  1863. *pMaxVerts = 32768;
  1864. *pMaxIndices = 32768;
  1865. }
  1866. // Returns the max possible vertices + indices to render in a single draw call
  1867. virtual int GetMaxVerticesToRender( IMaterial *pMaterial )
  1868. {
  1869. return 32768;
  1870. }
  1871. virtual int GetMaxIndicesToRender( )
  1872. {
  1873. return 32768;
  1874. }
  1875. // stencil buffer operations.
  1876. virtual void SetStencilState( const ShaderStencilState_t &state )
  1877. {
  1878. }
  1879. virtual void ClearStencilBufferRectangle(int xmin, int ymin, int xmax, int ymax, int value)
  1880. {
  1881. }
  1882. virtual void ModInit()
  1883. {
  1884. }
  1885. virtual void ModShutdown()
  1886. {
  1887. }
  1888. virtual void EnableColorCorrection( bool bEnable ) {}
  1889. virtual ColorCorrectionHandle_t AddLookup( const char *pName ) { return 0; }
  1890. virtual ColorCorrectionHandle_t FindLookup( const char *pName ) { return 0; }
  1891. virtual bool RemoveLookup( ColorCorrectionHandle_t handle ) { return true; }
  1892. virtual void LockLookup( ColorCorrectionHandle_t handle ) {}
  1893. virtual void LoadLookup( ColorCorrectionHandle_t handle, const char *pLookupName ) {}
  1894. virtual void UnlockLookup( ColorCorrectionHandle_t handle ) {}
  1895. virtual void SetLookupWeight( ColorCorrectionHandle_t handle, float flWeight ) {}
  1896. virtual void ResetLookupWeights( ) {}
  1897. virtual void SetResetable( ColorCorrectionHandle_t handle, bool bResetable ) {}
  1898. virtual void PushCustomClipPlane( const float *pPlane )
  1899. {
  1900. }
  1901. virtual void PopCustomClipPlane( void )
  1902. {
  1903. }
  1904. virtual bool EnableClipping( bool bEnable )
  1905. {
  1906. return true;
  1907. }
  1908. virtual void PushHeightClipPlane( void )
  1909. {
  1910. }
  1911. virtual bool UsingFastClipping( void )
  1912. {
  1913. return true; //true for "crappier" hardware, so true is safer than false
  1914. }
  1915. virtual int StencilBufferBits( void )
  1916. {
  1917. return 0;
  1918. }
  1919. virtual void DisableAllLocalLights() {}
  1920. virtual int CompareMaterialCombos( IMaterial *pMaterial1, IMaterial *pMaterial2, int lightmapID1, int lightmapID2 ) { return 0; }
  1921. virtual bool SupportsMSAAMode( int nMSAAMode ) { return false; }
  1922. virtual bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ) { return false; }
  1923. #ifdef _GAMECONSOLE
  1924. // Vitaliy: need HDR to run with -noshaderapi on console
  1925. virtual bool SupportsHDRMode( HDRType_t nMode ) { return nMode == HDR_TYPE_NONE || nMode == HDR_TYPE_INTEGER; }
  1926. #else
  1927. virtual bool SupportsHDRMode( HDRType_t nMode ) { return 0; }
  1928. #endif
  1929. virtual bool IsDX10Card() { return false; }
  1930. // Hooks for firing PIX events from outside the Material System...
  1931. virtual void BeginPIXEvent( unsigned long color, const char *szName ) {};
  1932. virtual void EndPIXEvent() {};
  1933. virtual void SetPIXMarker( unsigned long color, const char *szName ) {};
  1934. virtual IMatRenderContext *GetRenderContext() { return this; }
  1935. void BeginRender() {}
  1936. void BeginRender( float ) {}
  1937. void EndRender() {}
  1938. virtual void SetThreadMode( MaterialThreadMode_t, int ) {}
  1939. virtual MaterialThreadMode_t GetThreadMode(){ return MATERIAL_SINGLE_THREADED; }
  1940. virtual bool IsRenderThreadSafe( ) { return true; }
  1941. virtual bool AllowThreading( bool bAllow, int nServiceThread ) { return false; }
  1942. virtual void ExecuteQueued() {}
  1943. virtual void BeginBatch( IMesh* pIndices ) {}
  1944. virtual void BindBatch( IMesh* pVertices, IMaterial *pAutoBind = NULL ) {}
  1945. virtual void DrawBatch( MaterialPrimitiveType_t primType, int nFirstIndex, int nIndexCount ) {}
  1946. virtual void EndBatch() {}
  1947. virtual bool SupportsShadowDepthTextures( void ) { return false; }
  1948. virtual bool SupportsFetch4( void ) { return false; }
  1949. virtual void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) {}
  1950. virtual ICallQueue *GetCallQueue() { return NULL; }
  1951. virtual void GetWorldSpaceCameraPosition( Vector *pCameraPos )
  1952. {
  1953. pCameraPos->Init();
  1954. }
  1955. virtual void GetWorldSpaceCameraVectors( Vector *pVecForward, Vector *pVecRight, Vector *pVecUp )
  1956. {
  1957. if ( pVecForward )
  1958. {
  1959. pVecForward->Init( 1, 0, 0 );
  1960. }
  1961. if ( pVecRight )
  1962. {
  1963. pVecRight->Init( 0, -1, 0 );
  1964. }
  1965. if ( pVecUp )
  1966. {
  1967. pVecUp->Init( 0, 0, 1 );
  1968. }
  1969. }
  1970. virtual void BeginUpdateLightmaps() {}
  1971. virtual void EndUpdateLightmaps() {}
  1972. virtual MaterialLock_t Lock() { return NULL; }
  1973. virtual void Unlock( MaterialLock_t ) {}
  1974. virtual ImageFormat GetShadowDepthTextureFormat() { return IMAGE_FORMAT_UNKNOWN; }
  1975. virtual ImageFormat GetHighPrecisionShadowDepthTextureFormat() { return IMAGE_FORMAT_UNKNOWN; }
  1976. virtual IMatRenderContext *CreateRenderContext( MaterialContextType_t type )
  1977. {
  1978. return RetAddRef( (IMatRenderContext *)this );
  1979. }
  1980. virtual IMatRenderContext *SetRenderContext( IMatRenderContext *pContext )
  1981. {
  1982. SafeRelease( pContext );
  1983. return RetAddRef( this );
  1984. }
  1985. virtual IVertexBuffer * GetDynamicVertexBuffer( /*VertexFormat_t vertexFormat, */bool buffered = true )
  1986. {
  1987. Assert( 0 );
  1988. return NULL;
  1989. // return GetDummyMesh();
  1990. }
  1991. virtual IIndexBuffer * GetDynamicIndexBuffer( )
  1992. {
  1993. Assert( 0 );
  1994. return NULL;
  1995. // return GetDummyMesh();
  1996. }
  1997. // ------------ New Vertex/Index Buffer interface ----------------------------
  1998. virtual IVertexBuffer *CreateStaticVertexBuffer( VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup )
  1999. {
  2000. Assert( 0 );
  2001. return NULL;
  2002. }
  2003. virtual IIndexBuffer *CreateStaticIndexBuffer( MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup )
  2004. {
  2005. Assert( 0 );
  2006. return NULL;
  2007. }
  2008. virtual void DestroyVertexBuffer( IVertexBuffer * )
  2009. {
  2010. }
  2011. virtual void DestroyIndexBuffer( IIndexBuffer * )
  2012. {
  2013. }
  2014. // Do we need to specify the stream here in the case of locking multiple dynamic VBs on different streams?
  2015. virtual IVertexBuffer *GetDynamicVertexBuffer( int streamID, VertexFormat_t vertexFormat, bool bBuffered = true )
  2016. {
  2017. Assert( 0 );
  2018. return NULL;
  2019. }
  2020. virtual void BindVertexBuffer( int streamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 )
  2021. {
  2022. }
  2023. virtual void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes )
  2024. {
  2025. }
  2026. virtual void Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount )
  2027. {
  2028. }
  2029. virtual void BeginMorphAccumulation()
  2030. {
  2031. }
  2032. virtual void EndMorphAccumulation()
  2033. {
  2034. }
  2035. virtual void AccumulateMorph( IMorph* pMorph, int nMorphCount, const MorphWeight_t* pWeights )
  2036. {
  2037. }
  2038. virtual bool GetMorphAccumulatorTexCoord( Vector2D *pTexCoord, IMorph *pMorph, int nVertex )
  2039. {
  2040. pTexCoord->Init();
  2041. return false;
  2042. }
  2043. virtual int GetSubDBufferWidth()
  2044. {
  2045. return 0;
  2046. }
  2047. virtual float* LockSubDBuffer( int nNumRows )
  2048. {
  2049. return NULL;
  2050. }
  2051. virtual void UnlockSubDBuffer()
  2052. {
  2053. }
  2054. // ------------ End ----------------------------
  2055. virtual ImageFormat GetNullTextureFormat() { return IMAGE_FORMAT_UNKNOWN; }
  2056. virtual void AddTextureAlias( const char *pAlias, const char *pRealName ) {}
  2057. virtual void RemoveTextureAlias( const char *pAlias ) {}
  2058. virtual void SetExcludedTextures( const char *pScriptName, bool bUsingWeaponModelCache ) {}
  2059. virtual void UpdateExcludedTextures( void ) {}
  2060. virtual void ClearForceExcludes( void ) {}
  2061. virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights ) {}
  2062. virtual bool SupportsBorderColor() { return false; }
  2063. virtual IMaterial *GetCurrentMaterial() { return NULL; }
  2064. virtual int GetCurrentNumBones() const { return 0; }
  2065. virtual void *GetCurrentProxy() { return NULL; }
  2066. virtual void SetFullScreenDepthTextureValidityFlag( bool bIsValid ) {}
  2067. // A special path used to tick the front buffer while loading on the 360
  2068. virtual void SetNonInteractiveLogoTexture( ITexture *pTexture, float flNormalizedX, float flNormalizedY, float flNormalizedW, float flNormalizedH ) {}
  2069. virtual void SetNonInteractivePacifierTexture( ITexture *pTexture, float flNormalizedX, float flNormalizedY, float flNormalizedSize ) {}
  2070. virtual void SetNonInteractiveTempFullscreenBuffer( ITexture *pTexture, MaterialNonInteractiveMode_t mode ) {}
  2071. virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode ) {}
  2072. virtual void RefreshFrontBufferNonInteractive() {}
  2073. virtual uint32 GetFrameTimestamps( ApplicationPerformanceCountersInfo_t &apci, ApplicationInstantCountersInfo_t & aici ) { return 0; }
  2074. virtual void FlipCulling( bool bFlipCulling ) {}
  2075. virtual void EnableSinglePassFlashlightMode( bool bEnable ) {}
  2076. virtual bool SinglePassFlashlightModeEnabled() const
  2077. {
  2078. return false;
  2079. }
  2080. virtual void DrawInstances( int nInstanceCount, const MeshInstanceData_t *pInstance ) {}
  2081. virtual void * LockRenderData( int nSizeInBytes ) { return NULL; }
  2082. virtual void UnlockRenderData( void *pData ) {}
  2083. virtual bool IsRenderData( const void *pData ) const { return false; }
  2084. virtual void AddRefRenderData() {}
  2085. virtual void ReleaseRenderData() {}
  2086. #if defined( _X360 )
  2087. virtual void ListUsedMaterials( void ) {}
  2088. virtual HXUIFONT OpenTrueTypeFont( const char *pFontname, int tall, int style )
  2089. {
  2090. return (HXUIFONT)0;
  2091. }
  2092. virtual void CloseTrueTypeFont( HXUIFONT hFont ) {}
  2093. virtual bool GetTrueTypeFontMetrics( HXUIFONT hFont, wchar_t wchFirst, wchar_t wchLast, XUIFontMetrics *pFontMetrics, XUICharMetrics *pCharMetrics )
  2094. {
  2095. pFontMetrics->fLineHeight = 0.0f;
  2096. pFontMetrics->fMaxAscent = 0.0f;
  2097. pFontMetrics->fMaxDescent = 0.0f;
  2098. pFontMetrics->fMaxWidth = 0.0f;
  2099. pFontMetrics->fMaxHeight = 0.0f;
  2100. pFontMetrics->fMaxAdvance = 0.0f;
  2101. return true;
  2102. }
  2103. virtual bool GetTrueTypeGlyphs( HXUIFONT hFont, int numChars, wchar_t *pWch, int *pOffsetX, int *pOffsetY, int *pWidth, int *pHeight, unsigned char *pRGBA, int *pRGBAOffset )
  2104. {
  2105. return false;
  2106. }
  2107. virtual void PersistDisplay() {}
  2108. virtual void *GetD3DDevice() { return NULL; }
  2109. virtual void PushVertexShaderGPRAllocation( int iVertexShaderCount = 64 ) { };
  2110. virtual void PopVertexShaderGPRAllocation( void ) { };
  2111. virtual bool OwnGPUResources( bool bEnable ) { return false; }
  2112. virtual void FlushHiStencil() {}
  2113. #elif defined( _PS3 )
  2114. virtual void ListUsedMaterials( void ) {}
  2115. virtual HPS3FONT OpenTrueTypeFont( const char *pFontname, int tall, int style ){ return NULL; }
  2116. virtual void CloseTrueTypeFont( HPS3FONT hFont ){};
  2117. virtual bool GetTrueTypeFontMetrics( HPS3FONT hFont, int nFallbackTall, wchar_t wchFirst, wchar_t wchLast, CPS3FontMetrics *pFontMetrics, CPS3CharMetrics *pCharMetrics ){return false;}
  2118. // Render a sequence of characters and extract the data into a buffer
  2119. // For each character, provide the width+height of the font texture subrect,
  2120. // an offset to apply when rendering the glyph, and an offset into a buffer to receive the RGBA data
  2121. virtual bool GetTrueTypeGlyphs( HPS3FONT hFont, int nFallbackTall, int numChars, wchar_t *pWch, int *pOffsetX, int *pOffsetY, int *pWidth, int *pHeight, unsigned char *pRGBA, int *pRGBAOffset ){return false;}
  2122. virtual void TransmitScreenshotToVX() {};
  2123. virtual void CompactRsxLocalMemory( char const *szReason ) {}
  2124. virtual void SetFlipPresentFrequency( int nNumVBlanks ) {}
  2125. #endif
  2126. virtual void SpinPresent( uint nFrames ){}
  2127. #if defined( _GAMECONSOLE )
  2128. virtual void BeginConsoleZPass( const WorldListIndicesInfo_t &indicesInfo ) {}
  2129. virtual void BeginConsoleZPass2( int nSlack ) {}
  2130. virtual void EndConsoleZPass() {}
  2131. #endif
  2132. #if defined( INCLUDE_SCALEFORM )
  2133. virtual void SetScaleformSlotViewport( int slot, int x, int y, int w, int h ) {}
  2134. virtual void RenderScaleformSlot( int slot ) {}
  2135. virtual void ForkRenderScaleformSlot( int slot ) {}
  2136. virtual void JoinRenderScaleformSlot( int slot ) {}
  2137. virtual void SetScaleformCursorViewport( int x, int y, int w, int h ) {}
  2138. virtual void RenderScaleformCursor() {}
  2139. virtual void AdvanceAndRenderScaleformSlot( int slot ) {}
  2140. virtual void AdvanceAndRenderScaleformCursor() {}
  2141. #endif // INCLUDE_SCALEFORM
  2142. #if defined( _PS3 )
  2143. virtual void FlushTextureCache() { }
  2144. #endif
  2145. virtual void AntiAliasingHint( int ) {}
  2146. virtual void CompactMemory() {}
  2147. virtual void GetGPUMemoryStats( GPUMemoryStats &stats ) {}
  2148. // For sv_pure mode. The filesystem figures out which files the client needs to reload to be "pure" ala the server's preferences.
  2149. virtual void ReloadFilesInList( IFileList *pFilesToReload )
  2150. {
  2151. }
  2152. void UpdateGameTime( float flTime ) {}
  2153. virtual bool CanDownloadTextures() const { return false; }
  2154. virtual void BindPaintTexture( ITexture *pTexture )
  2155. {
  2156. }
  2157. //--------------------------------------------------------
  2158. // debug logging - no-op in queued context
  2159. //--------------------------------------------------------
  2160. virtual void Printf( char *fmt, ... ) {};
  2161. virtual void PrintfVA( char *fmt, va_list vargs ){};
  2162. virtual float Knob( char *knobname, float *setvalue=NULL ) { return 0.0f; };
  2163. virtual void RegisterPaintmapDataManager( IPaintmapDataManager *pDataManager ) {}
  2164. virtual void BeginUpdatePaintmaps( void ) {}
  2165. virtual void EndUpdatePaintmaps( void ) {}
  2166. virtual void UpdatePaintmap( int paintmap, BYTE* pPaintData, int numRects, Rect_t* pRects ) {}
  2167. };
  2168. static CDummyMaterialSystem g_DummyMaterialSystem;
  2169. EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CDummyMaterialSystem, IMaterialSystemStub,
  2170. MATERIAL_SYSTEM_STUB_INTERFACE_VERSION, g_DummyMaterialSystem );