forked from nillerusr/source-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mat_stub.cpp
2288 lines (1924 loc) · 60 KB
/
mat_stub.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=====================================================================================//
#include "materialsystem/imesh.h"
#include "materialsystem/imaterialsystemhardwareconfig.h"
#include "materialsystem/imorph.h"
#include "materialsystem/imaterialsystemstub.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/itexture.h"
#include "materialsystem/imaterialvar.h"
#include "bitmap/imageformat.h"
#include "mathlib/vmatrix.h"
#include "utlvector.h"
// GR
#include "imaterialinternal.h"
#include "materialsystem/materialsystem_config.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#include "mat_stub.h"
CDummyTexture g_DummyTexture;
// ---------------------------------------------------------------------------------------- //
// IMaterialSystem and IMesh stub classes.
// ---------------------------------------------------------------------------------------- //
static unsigned short g_DummyIndices[6];
class CDummyMesh : public IMesh
{
public:
// Locks/ unlocks the mesh, providing space for nVertexCount and nIndexCount.
// nIndexCount of -1 means don't lock the index buffer...
virtual void LockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc )
{
Lock( nVertexCount, false, *static_cast< VertexDesc_t* >( &desc ) );
Lock( nIndexCount, false, *static_cast< IndexDesc_t* >( &desc ) );
}
virtual void UnlockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc )
{
}
virtual void ModifyBeginEx( bool bReadOnly, int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc )
{
ModifyBegin( bReadOnly, nFirstIndex, nIndexCount, *static_cast< IndexDesc_t* >( &desc ) );
}
virtual void ModifyBegin( int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc )
{
ModifyBegin( false, nFirstIndex, nIndexCount, *static_cast< IndexDesc_t* >( &desc ) );
}
virtual void ModifyEnd( MeshDesc_t &desc )
{
}
// FIXME: Make this work! Unsupported methods of IIndexBuffer
virtual bool Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t& desc )
{
desc.m_pIndices = g_DummyIndices;
desc.m_nIndexSize = 0;
desc.m_nFirstIndex = 0;
desc.m_nOffset = 0;
return true;
}
virtual void Unlock( int nWrittenIndexCount, IndexDesc_t& desc ) {}
virtual void ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc )
{
desc.m_pIndices = g_DummyIndices;
desc.m_nIndexSize = 0;
desc.m_nFirstIndex = 0;
desc.m_nOffset = 0;
}
virtual void ModifyEnd( IndexDesc_t &desc ) {}
virtual void Spew( int nIndexCount, const IndexDesc_t & desc ) {}
virtual void ValidateData( int nIndexCount, const IndexDesc_t &desc ) {}
virtual bool IsDynamic() const
{
return false;
}
virtual void BeginCastBuffer( MaterialIndexFormat_t format ) {}
virtual void BeginCastBuffer( VertexFormat_t format ) {}
virtual void EndCastBuffer( ) {}
// Returns the number of vertices that can still be written into the buffer
virtual int GetRoomRemaining() const { return 0; }
virtual int IndexCount() const
{
return 0;
}
// returns the # of vertices (static meshes only)
virtual int VertexCount() const
{
return 0;
}
// returns the vertex format
virtual bool Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc )
{
static float dummyFloat[32];
static unsigned char dummyChar[32];
memset( &desc, 0, sizeof( desc ) );
// Pointers to our current vertex data
desc.m_pPosition = dummyFloat;
desc.m_pBoneWeight = dummyFloat;
#ifdef NEW_SKINNING
desc.m_pBoneMatrixIndex = dummyFloat;
#else
desc.m_pBoneMatrixIndex = dummyChar;
#endif
desc.m_pNormal = dummyFloat;
desc.m_pColor = dummyChar;
desc.m_pSpecular = dummyChar;
for( int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ )
{
desc.m_pTexCoord[i] = dummyFloat;
}
desc.m_pTangentS = dummyFloat;
desc.m_pTangentT = dummyFloat;
desc.m_pWrinkle = dummyFloat;
// user data
desc.m_pUserData = dummyFloat;
desc.m_nFirstVertex = 0;
desc.m_nOffset = 0;
return true;
}
virtual void Unlock( int nVertexCount, VertexDesc_t &desc ) {}
virtual void Spew( int nVertexCount, const VertexDesc_t &desc ) {}
virtual void ValidateData( int nVertexCount, const VertexDesc_t & desc ) {}
// Sets/gets the primitive type
virtual void SetPrimitiveType( MaterialPrimitiveType_t type )
{
}
// Draws the mesh
virtual void Draw( int nFirstIndex = -1, int nIndexCount = 0 )
{
}
virtual void SetColorMesh( IMesh *pColorMesh, int nVertexOffset )
{
}
virtual void SetFlexMesh( IMesh *pMesh, int nVertexOffset )
{
}
virtual void DisableFlexMesh( )
{
}
// Draw a list of (lists of) primitives. Batching your lists together that use
// the same lightmap, material, vertex and index buffers with multipass shaders
// can drastically reduce state-switching overhead.
// NOTE: this only works with STATIC meshes.
virtual void Draw( CPrimList *pLists, int nLists )
{
}
// Copy verts and/or indices to a mesh builder. This only works for temp meshes!
virtual void CopyToMeshBuilder(
int iStartVert, // Which vertices to copy.
int nVerts,
int iStartIndex, // Which indices to copy.
int nIndices,
int indexOffset, // This is added to each index.
CMeshBuilder &builder )
{
}
// Spews the mesh data
virtual void Spew( int nVertexCount, int nIndexCount, const MeshDesc_t& desc )
{
}
// Call this in debug mode to make sure our data is good.
virtual void ValidateData( int nVertexCount, int nIndexCount, const MeshDesc_t& desc )
{
}
virtual void MarkAsDrawn() {}
virtual unsigned ComputeMemoryUsed() { return 0; }
virtual VertexFormat_t GetVertexFormat() const
{
return VERTEX_POSITION;
}
virtual MaterialIndexFormat_t IndexFormat() const
{
return MATERIAL_INDEX_FORMAT_16BIT;
}
virtual IMesh *GetMesh()
{
return this;
}
};
// We allocate this dynamically because it uses a bunch of memory and we don't want to
// waste the memory unless we need to.
CDummyMesh *g_pDummyMesh = NULL;
CDummyMesh* GetDummyMesh()
{
if ( !g_pDummyMesh )
{
g_pDummyMesh = new CDummyMesh;
}
return g_pDummyMesh;
}
// ---------------------------------------------------------------------------------------- //
// Dummy implementation of IMaterialVar.
// ---------------------------------------------------------------------------------------- //
static VMatrix g_DummyMatrix( 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 );
class CDummyMaterialVar : public IMaterialVar
{
public:
virtual char const * GetName( void ) const { return "DummyMaterialVar"; }
virtual MaterialVarSym_t GetNameAsSymbol() const { return 0; }
virtual void SetFloatValue( float val ) {}
virtual float GetFloatValueInternal( void ) const { return 1; }
virtual void SetIntValue( int val ) {}
virtual int GetIntValueInternal( void ) const { return 1; }
virtual void SetStringValue( char const *val ) {}
virtual char const * GetStringValue( void ) const { return ""; }
// Use FourCC values to pass app-defined data structures between
// the proxy and the shader. The shader should ignore the data if
// its FourCC type not correct.
virtual void SetFourCCValue( FourCC type, void *pData ) {}
virtual void GetFourCCValue( FourCC *type, void **ppData ) {}
// Vec (dim 2-4)
virtual void SetVecValue( float const* val, int numcomps ) {}
virtual void SetVecValue( float x, float y ) {}
virtual void SetVecValue( float x, float y, float z ) {}
virtual void SetVecValue( float x, float y, float z, float w ) {}
virtual void SetVecComponentValue( float fVal, int nComponent ) {}
virtual void GetVecValueInternal( float *val, int numcomps ) const
{
for ( int i=0; i < numcomps; i++ )
val[i] = 1;
}
virtual void GetLinearVecValue( float *val, int numcomps ) const
{
for ( int i=0; i < numcomps; i++ )
val[i] = 1;
}
virtual float const* GetVecValueInternal( ) const
{
static float val[4] = {1,1,1,1};
return val;
}
virtual int VectorSizeInternal() const
{
return 3;
}
// revisit: is this a good interface for textures?
virtual ITexture * GetTextureValue( void )
{
return &g_DummyTexture;
}
virtual void SetTextureValue( ITexture * ) {}
virtual operator ITexture*()
{
return GetTextureValue();
}
virtual IMaterial * GetMaterialValue( void )
{
extern IMaterial *g_pDummyMaterial;
return g_pDummyMaterial;
}
virtual void SetMaterialValue( IMaterial * ) {}
virtual MaterialVarType_t GetType() const { return MATERIAL_VAR_TYPE_INT; }
virtual bool IsDefined() const { return true; }
virtual void SetUndefined() {}
// Matrix
virtual void SetMatrixValue( VMatrix const& matrix ) {}
virtual const VMatrix &GetMatrixValue( )
{
return g_DummyMatrix;
}
virtual bool MatrixIsIdentity() const
{
return false;
}
// Copy....
virtual void CopyFrom( IMaterialVar *pMaterialVar ) {}
virtual void SetValueAutodetectType( char const *val ) {}
virtual IMaterial * GetOwningMaterial()
{
extern IMaterial *g_pDummyMaterial;
return g_pDummyMaterial;
}
};
CDummyMaterialVar g_DummyMaterialVar;
// ---------------------------------------------------------------------------------------- //
// Dummy implementation of IMaterialSystemHardwareConfig
// ---------------------------------------------------------------------------------------- //
class CDummyHardwareConfig : public IMaterialSystemHardwareConfig
{
public:
virtual bool HasDestAlphaBuffer() const { return false; }
virtual bool HasStencilBuffer() const { return false; }
virtual int StencilBufferBits() const { return 0; }
virtual int GetFrameBufferColorDepth() const { return 0; }
virtual int GetSamplerCount() const { return 0; }
virtual bool HasSetDeviceGammaRamp() const { return false; }
virtual bool SupportsCompressedTextures() const { return false; }
virtual VertexCompressionType_t SupportsCompressedVertices() const { return VERTEX_COMPRESSION_NONE; }
virtual bool SupportsVertexAndPixelShaders() const { return false; }
virtual bool SupportsPixelShaders_1_4() const { return false; }
virtual bool SupportsPixelShaders_2_0() const { return false; }
virtual bool SupportsPixelShaders_2_b() const { return false; }
virtual bool ActuallySupportsPixelShaders_2_b() const { return false; }
virtual bool SupportsStaticControlFlow() const { return false; }
virtual bool SupportsVertexShaders_2_0() const { return false; }
virtual bool SupportsShaderModel_3_0() const { return false; }
virtual int MaximumAnisotropicLevel() const { return 1; }
virtual int MaxTextureWidth() const { return 0; }
virtual int MaxTextureHeight() const { return 0; }
virtual int MaxTextureDepth() const { return 0; }
virtual int TextureMemorySize() const { return 0; }
virtual bool SupportsOverbright() const { return false; }
virtual bool SupportsCubeMaps() const { return false; }
virtual bool SupportsMipmappedCubemaps() const { return false; }
virtual bool SupportsNonPow2Textures() const { return false; }
// The number of texture stages represents the number of computations
// we can do in the pixel pipeline, it is *not* related to the
// simultaneous number of textures we can use
virtual int GetTextureStageCount() const { return 0; }
virtual int NumVertexShaderConstants() const { return 0; }
virtual int NumBooleanVertexShaderConstants() const { return 0; }
virtual int NumIntegerVertexShaderConstants() const { return 0; }
virtual int NumPixelShaderConstants() const { return 0; }
virtual int MaxNumLights() const { return 0; }
virtual bool SupportsHardwareLighting() const { return false; }
virtual int MaxBlendMatrices() const { return 0; }
virtual int MaxBlendMatrixIndices() const { return 0; }
virtual int MaxTextureAspectRatio() const { return 0; }
virtual int MaxVertexShaderBlendMatrices() const { return 0; }
virtual int MaxUserClipPlanes() const { return 0; }
virtual bool UseFastClipping() const { return false; }
virtual bool UseFastZReject() const { return false; }
virtual bool PreferReducedFillrate() const { return false; }
// This here should be the major item looked at when checking for compat
// from anywhere other than the material system shaders
virtual int GetDXSupportLevel() const { return 90; }
virtual const char *GetShaderDLLName() const { return NULL; }
virtual bool ReadPixelsFromFrontBuffer() const { return false; }
// Are dx dynamic textures preferred?
virtual bool PreferDynamicTextures() const { return false; }
virtual bool SupportsHDR() const { return false; }
virtual HDRType_t GetHDRType() const { return HDR_TYPE_NONE; }
virtual HDRType_t GetHardwareHDRType() const { return HDR_TYPE_NONE; }
virtual bool HasProjectedBumpEnv() const { return false; }
virtual bool SupportsSpheremapping() const { return false; }
virtual bool NeedsAAClamp() const { return false; }
virtual bool HasFastZReject() const { return false; }
virtual bool NeedsATICentroidHack() const { return false; }
virtual bool SupportsColorOnSecondStream() const{ return false; }
virtual bool SupportsStaticPlusDynamicLighting() const{ return false; }
virtual bool SupportsStreamOffset() const { return false; }
virtual int GetMaxDXSupportLevel() const { return 90; }
virtual bool SpecifiesFogColorInLinearSpace() const { return false; }
virtual bool SupportsSRGB() const { return false; }
virtual bool FakeSRGBWrite() const { return false; }
virtual bool CanDoSRGBReadFromRTs() const { return true; }
virtual bool SupportsGLMixedSizeTargets() const { return false; }
virtual bool IsAAEnabled() const { return false; }
virtual int GetVertexTextureCount() const { return 0; }
virtual int GetMaxVertexTextureDimension() const { return 0; }
virtual int MaxViewports() const { return 1; }
virtual void OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport ) {}
virtual int GetShadowFilterMode() const { return 0; }
virtual int NeedsShaderSRGBConversion() const { return 0; }
bool UsesSRGBCorrectBlending() const { return false; }
virtual bool HasFastVertexTextures() const { return false; }
virtual int MaxHWMorphBatchCount() const { return 0; }
virtual bool SupportsHDRMode( HDRType_t nMode ) const { return 0; }
virtual bool IsDX10Card() const { return 0; }
virtual bool GetHDREnabled( void ) const { return true; }
virtual void SetHDREnabled( bool bEnable ) {}
virtual bool SupportsBorderColor( void ) const { return true; }
virtual bool SupportsFetch4( void ) const { return false; }
virtual bool CanStretchRectFromTextures() const { return false; }
};
CDummyHardwareConfig g_DummyHardwareConfig;
// ---------------------------------------------------------------------------------------- //
// CDummyMaterial.
// ---------------------------------------------------------------------------------------- //
class CDummyMaterial : public IMaterial
{
public:
virtual const char * GetName() const { return "dummy material"; }
virtual const char * GetTextureGroupName() const { return "dummy group"; }
virtual PreviewImageRetVal_t GetPreviewImageProperties( int *width, int *height,
ImageFormat *imageFormat, bool* isTranslucent ) const
{
if ( width )
*width = 4;
if ( height )
*height = 4;
if ( imageFormat )
*imageFormat = IMAGE_FORMAT_RGBA8888;
if ( isTranslucent )
*isTranslucent = false;
return MATERIAL_PREVIEW_IMAGE_OK;
}
virtual PreviewImageRetVal_t GetPreviewImage( unsigned char *data,
int width, int height,
ImageFormat imageFormat ) const
{
return MATERIAL_PREVIEW_IMAGE_OK;
}
//
virtual int GetMappingWidth( )
{
return 512;
}
virtual int GetMappingHeight( )
{
return 512;
}
virtual int GetNumAnimationFrames( )
{
return 0;
}
virtual bool InMaterialPage( void )
{
return false;
}
virtual void GetMaterialOffset( float *pOffset )
{
pOffset[0] = 0.0f;
pOffset[1] = 0.0f;
}
virtual void GetMaterialScale( float *pScale )
{
pScale[0] = 1.0f;
pScale[1] = 1.0f;
}
virtual IMaterial *GetMaterialPage( void )
{
return NULL;
}
virtual IMaterialVar * FindVar( const char *varName, bool *found, bool complain = true )
{
if ( found )
*found = true;
return &g_DummyMaterialVar;
}
virtual IMaterialVar * FindVarFast( const char *varName, unsigned int *pToken )
{
return NULL;
}
virtual void IncrementReferenceCount( void )
{
}
virtual void DecrementReferenceCount( void )
{
}
virtual int GetEnumerationID( void ) const
{
return 0;
}
virtual void GetLowResColorSample( float s, float t, float *color ) const
{
}
virtual void RecomputeStateSnapshots()
{
}
// Are we translucent?
virtual bool IsTranslucent()
{
return false;
}
// Are we alphatested?
virtual bool IsAlphaTested()
{
return false;
}
// Are we vertex lit?
virtual bool IsVertexLit()
{
return false;
}
// Gets the vertex format
virtual VertexFormat_t GetVertexFormat() const
{
return 0;
}
// returns true if this material uses a material proxy
virtual bool HasProxy( void ) const
{
return false;
}
virtual void CallBindProxy( void* ) {}
virtual IMaterial *CheckProxyReplacement( void *proxyData )
{
return this;
}
virtual bool UsesEnvCubemap( void )
{
return false;
}
virtual bool NeedsTangentSpace( void )
{
return false;
}
virtual bool NeedsPowerOfTwoFrameBufferTexture( bool bCheckSpecificToThisFrame )
{
return false;
}
virtual bool NeedsFullFrameBufferTexture( bool bCheckSpecificToThisFrame )
{
return false;
}
virtual bool NeedsSoftwareSkinning( void )
{
return false;
}
// Apply constant color or alpha modulation
virtual void AlphaModulate( float alpha )
{
}
virtual void ColorModulate( float r, float g, float b )
{
}
float GetAlphaModulation( )
{
return 1;
}
void GetColorModulation( float *r, float *g, float *b )
{
*r = *g = *b = 1;
}
// Material Var flags...
virtual void SetMaterialVarFlag( MaterialVarFlags_t flag, bool on )
{
}
virtual bool GetMaterialVarFlag( MaterialVarFlags_t flag ) const
{
return true;
}
// Gets material reflectivity
virtual void GetReflectivity( Vector& reflect )
{
reflect.Init(1,0,0);
}
// Gets material property flags
virtual bool GetPropertyFlag( MaterialPropertyTypes_t type )
{
return true;
}
// Is the material visible from both sides?
virtual bool IsTwoSided()
{
return false;
}
// Sets the shader associated with the material
virtual void SetShader( const char *pShaderName )
{
}
// Can't be const because the material might have to precache itself.
virtual int GetNumPasses( void )
{
return 1;
}
// Can't be const because the material might have to precache itself.
virtual int GetTextureMemoryBytes( void )
{
return 64;
}
// Meant to be used with materials created using CreateMaterial
// It updates the materials to reflect the current values stored in the material vars
virtual void Refresh()
{
}
// GR - returns true is material uses lightmap alpha for blending
virtual bool NeedsLightmapBlendAlpha( void )
{
return false;
}
// returns true if the shader doesn't do lighting itself and requires
// the data that is sent to it to be prelighted
virtual bool NeedsSoftwareLighting( void )
{
return false;
}
// Gets at the shader parameters
virtual int ShaderParamCount() const
{
return 0;
}
virtual IMaterialVar **GetShaderParams( void )
{
return 0;
}
virtual bool IsErrorMaterial() const
{
return false;
}
virtual void SetUseFixedFunctionBakedLighting( bool bEnable )
{
}
virtual MorphFormat_t GetMorphFormat() const
{
return 0;
}
virtual void SetShaderAndParams( KeyValues *pKeyValues )
{
}
virtual const char *GetShaderName() const { return "Wireframe"; }
virtual void DeleteIfUnreferenced() {}
virtual bool IsSpriteCard() { return false; }
virtual void RefreshPreservingMaterialVars() {};
virtual bool WasReloadedFromWhitelist() {return false;}
virtual bool IsPrecached() const {return true;}
};
CDummyMaterial g_DummyMaterial;
IMaterial *g_pDummyMaterial = &g_DummyMaterial;
void* DummyMaterialSystemFactory( const char *pName, int *pReturnCode )
{
if ( stricmp( pName, MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION ) == 0 )
return &g_DummyHardwareConfig;
else
return NULL;
}
// ---------------------------------------------------------------------------------------- //
// Dummy morph
// ---------------------------------------------------------------------------------------- //
class CDummyMorph : public IMorph
{
public:
virtual void Lock( float flFloatToFixedScale ) {}
virtual void AddMorph( const MorphVertexInfo_t &info ) {}
virtual void Unlock( ) {}
virtual void AccumulateMorph( int nWeightCount, const MorphWeight_t* pWeights ) {}
};
// ---------------------------------------------------------------------------------------- //
// CDummyMaterialSystem.
// ---------------------------------------------------------------------------------------- //
class CDummyMaterialSystem : public IMaterialSystemStub, public CRefCounted1<IMatRenderContext, CRefCountServiceNull>
{
private:
IMaterialSystem *m_pRealMaterialSystem;
public:
CDummyMaterialSystem()
{
m_pRealMaterialSystem = 0;
}
virtual void SetRealMaterialSystem( IMaterialSystem *pSys )
{
m_pRealMaterialSystem = pSys;
}
// Call this to initialize the material system
// returns a method to create interfaces in the shader dll
virtual CreateInterfaceFn Init( char const* pShaderDLL,
IMaterialProxyFactory *pMaterialProxyFactory,
CreateInterfaceFn fileSystemFactory,
CreateInterfaceFn cvarFactory )
{
return DummyMaterialSystemFactory;
}
virtual void Shutdown( )
{
}
virtual IMaterialSystemHardwareConfig *GetHardwareConfig( const char *pVersion, int *returnCode )
{
if ( returnCode )
*returnCode = 1;
return &g_DummyHardwareConfig;
}
// Gets the number of adapters...
virtual int GetDisplayAdapterCount() const
{
return 0;
}
// Returns info about each adapter
virtual void GetDisplayAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const
{
}
// Returns the number of modes
virtual int GetModeCount( int adapter ) const
{
return 0;
}
// Returns mode information..
virtual void GetModeInfo( int adapter, int mode, MaterialVideoMode_t& info ) const
{
}
// Returns the mode info for the current display device
virtual void GetDisplayMode( MaterialVideoMode_t& mode ) const
{
}
// Sets the mode...
virtual bool SetMode( void* hwnd, const MaterialSystem_Config_t &config )
{
return true;
}
// Creates/ destroys a child window
virtual bool AddView( void* hwnd )
{
return false;
}
virtual void RemoveView( void* hwnd )
{
}
// Sets the view
virtual void SetView( void* hwnd )
{
}
// return true if lightmaps need to be redownloaded
// Call this before rendering each frame with the current config
// for the material system.
// Will do whatever is necessary to get the material system into the correct state
// upon configuration change. .doesn't much else otherwise.
virtual bool UpdateConfig( bool forceUpdate )
{
return false;
}
virtual bool OverrideConfig( const MaterialSystem_Config_t &config, bool bForceUpdate )
{
return false;
}
// This is the interface for knowing what materials are available
// is to use the following functions to get a list of materials. The
// material names will have the full path to the material, and that is the
// only way that the directory structure of the materials will be seen through this
// interface.
// NOTE: This is mostly for worldcraft to get a list of materials to put
// in the "texture" browser.in Worldcraft
virtual MaterialHandle_t FirstMaterial() const
{
return 0;
}
// returns InvalidMaterial if there isn't another material.
// WARNING: you must call GetNextMaterial until it returns NULL,
// otherwise there will be a memory leak.
virtual MaterialHandle_t NextMaterial( MaterialHandle_t h ) const
{
return 0;
}
// This is the invalid material
virtual MaterialHandle_t InvalidMaterial() const
{
if ( m_pRealMaterialSystem )
return m_pRealMaterialSystem->InvalidMaterial();
else
return 0;
}
// Returns a particular material
virtual IMaterial* GetMaterial( MaterialHandle_t h ) const
{
if ( m_pRealMaterialSystem )
return m_pRealMaterialSystem->GetMaterial( h );
else
return &g_DummyMaterial;
}
// Find a material by name.
// The name of a material is a full path to
// the vmt file starting from "hl2/materials" (or equivalent) without
// a file extension.
// eg. "dev/dev_bumptest" refers to somethign similar to:
// "d:/hl2/hl2/materials/dev/dev_bumptest.vmt"
virtual IMaterial *FindMaterial( char const* pMaterialName, const char *pTextureGroupName, bool complain = true, const char *pComplainPrefix = NULL )
{
if ( m_pRealMaterialSystem )
return m_pRealMaterialSystem->FindMaterial( pMaterialName, pTextureGroupName, complain, pComplainPrefix );
return &g_DummyMaterial;
}
virtual bool IsMaterialLoaded( char const* pMaterialName )
{
if ( m_pRealMaterialSystem )
return m_pRealMaterialSystem->IsMaterialLoaded( pMaterialName );
return true;
}
virtual IMaterial *FindMaterialEx( char const* pMaterialName, const char *pTextureGroupName, int nContext, bool complain = true, const char *pComplainPrefix = NULL )
{
if ( m_pRealMaterialSystem )
return m_pRealMaterialSystem->FindMaterialEx( pMaterialName, pTextureGroupName, nContext, complain, pComplainPrefix );
return &g_DummyMaterial;
}
virtual IMaterial *FindProceduralMaterial( const char *pMaterialName, const char *pTextureGroupName, KeyValues *pVMTKeyValues )
{
if ( m_pRealMaterialSystem )
return m_pRealMaterialSystem->FindProceduralMaterial( pMaterialName, pTextureGroupName, pVMTKeyValues );
return &g_DummyMaterial;
}
virtual ITexture *FindTexture( char const* pTextureName, const char *pTextureGroupName, bool complain = true, int nAdditionalCreationFlags = 0)
{
if ( m_pRealMaterialSystem )
return m_pRealMaterialSystem->FindTexture( pTextureName, pTextureGroupName, complain, nAdditionalCreationFlags );
return &g_DummyTexture;
}
virtual void SetAsyncTextureLoadCache( FileCacheHandle_t hFileCache )
{
}
virtual void BindLocalCubemap( ITexture *pTexture )
{
}
virtual ITexture *GetLocalCubemap( )
{
return &g_DummyTexture;
}
// pass in an ITexture (that is build with "rendertarget" "1") or
// pass in NULL for the regular backbuffer.
virtual void SetRenderTarget( ITexture *pTexture )
{
}
virtual ITexture * GetRenderTarget( void )
{
return &g_DummyTexture;
}
virtual void SetRenderTargetEx( int nRenderTargetID, ITexture *pTexture )
{
}
virtual ITexture * GetRenderTargetEx( int nRenderTargetID )
{
return &g_DummyTexture;
}
virtual void GetRenderTargetDimensions( int &width, int &height) const
{
width = 256;
height = 256;
}
// Get the total number of materials in the system. These aren't just the used
// materials, but the complete collection.
virtual int GetNumMaterials( ) const
{
return m_pRealMaterialSystem->GetNumMaterials();
}
// Remove any materials from memory that aren't in use as determined
// by the IMaterial's reference count.
virtual void UncacheUnusedMaterials( bool bRecomputeStateSnapshots )
{
if ( m_pRealMaterialSystem )
{
m_pRealMaterialSystem->UncacheUnusedMaterials( bRecomputeStateSnapshots );
}
}
virtual void SuspendTextureStreaming( )
{
if ( m_pRealMaterialSystem )
m_pRealMaterialSystem->SuspendTextureStreaming();
}
virtual void ResumeTextureStreaming( )
{
if ( m_pRealMaterialSystem )
m_pRealMaterialSystem->ResumeTextureStreaming();
}
// uncache all materials. . good for forcing reload of materials.
virtual void UncacheAllMaterials( )
{