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.

2373 lines
63 KiB

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