Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2128 lines
80 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef IMATERIALSYSTEM_H
  9. #define IMATERIALSYSTEM_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #define OVERBRIGHT 2.0f
  14. #define OO_OVERBRIGHT ( 1.0f / 2.0f )
  15. #define GAMMA 2.2f
  16. #define TEXGAMMA 2.2f
  17. #include "tier1/interface.h"
  18. #include "tier1/refcount.h"
  19. #include "mathlib/vector.h"
  20. #include "mathlib/vector4d.h"
  21. #include "mathlib/vmatrix.h"
  22. #include "appframework/iappsystem.h"
  23. #include "bitmap/imageformat.h"
  24. #include "texture_group_names.h"
  25. #include "vtf/vtf.h"
  26. #include "materialsystem/deformations.h"
  27. // HDRFIXME NOTE: must match common_ps_fxc.h
  28. enum HDRType_t
  29. {
  30. HDR_TYPE_NONE,
  31. HDR_TYPE_INTEGER,
  32. HDR_TYPE_FLOAT,
  33. };
  34. #include "materialsystem/imaterialsystemhardwareconfig.h"
  35. #include "materialsystem/IColorCorrection.h"
  36. #if !defined( _GAMECONSOLE )
  37. // NOTE: Disable this for l4d2 in general!!! It allocates 4mb of rendertargets and causes Release/Reallocation of rendertargets.
  38. // PORTAL2: Turning this off in the portal 2 branch because we don't use it and it appears to leak each mapload.
  39. // We don't currently expect to merge this code back to main so this may not matter, but if we do we'll have to resolve weeding this
  40. // out of portal2 builds.
  41. //#define FEATURE_SUBD_SUPPORT
  42. #endif
  43. #if defined(_PS3)
  44. typedef void * HPS3FONT ; // see also ps3font.h
  45. class CPS3FontMetrics;
  46. class CPS3CharMetrics;
  47. enum GpuDataTransferCache_t
  48. {
  49. PS3GPU_DATA_TRANSFER_CREATECACHELINK = 0x80000000,
  50. PS3GPU_DATA_TRANSFER_CACHE2REAL = 0x01000000,
  51. PS3GPU_DATA_TRANSFER_REAL2CACHE = 0x02000000,
  52. PS3GPU_DATA_TRANSFER_MASK = 0xFF000000,
  53. };
  54. #endif
  55. //-----------------------------------------------------------------------------
  56. // forward declarations
  57. //-----------------------------------------------------------------------------
  58. class IMaterial;
  59. class IMesh;
  60. class IVertexBuffer;
  61. class IIndexBuffer;
  62. struct MaterialSystem_Config_t;
  63. class VMatrix;
  64. struct matrix3x4_t;
  65. class ITexture;
  66. struct MaterialSystemHardwareIdentifier_t;
  67. class KeyValues;
  68. class IShader;
  69. class IVertexTexture;
  70. class IMorph;
  71. class IMatRenderContext;
  72. class ICallQueue;
  73. struct MorphWeight_t;
  74. class IFileList;
  75. struct VertexStreamSpec_t;
  76. struct ShaderStencilState_t;
  77. struct MeshInstanceData_t;
  78. class IClientMaterialSystem;
  79. class CPaintMaterial;
  80. class IPaintmapDataManager;
  81. class IPaintmapTextureManager;
  82. struct GPUMemoryStats;
  83. class ICustomMaterialManager;
  84. class ICompositeTextureGenerator;
  85. //-----------------------------------------------------------------------------
  86. // The vertex format type
  87. //-----------------------------------------------------------------------------
  88. typedef uint64 VertexFormat_t;
  89. //-----------------------------------------------------------------------------
  90. // important enumeration
  91. //-----------------------------------------------------------------------------
  92. enum ShaderParamType_t
  93. {
  94. SHADER_PARAM_TYPE_TEXTURE,
  95. SHADER_PARAM_TYPE_INTEGER,
  96. SHADER_PARAM_TYPE_COLOR,
  97. SHADER_PARAM_TYPE_VEC2,
  98. SHADER_PARAM_TYPE_VEC3,
  99. SHADER_PARAM_TYPE_VEC4,
  100. SHADER_PARAM_TYPE_ENVMAP, // obsolete
  101. SHADER_PARAM_TYPE_FLOAT,
  102. SHADER_PARAM_TYPE_BOOL,
  103. SHADER_PARAM_TYPE_FOURCC,
  104. SHADER_PARAM_TYPE_MATRIX,
  105. SHADER_PARAM_TYPE_MATERIAL,
  106. SHADER_PARAM_TYPE_STRING,
  107. };
  108. enum MaterialMatrixMode_t
  109. {
  110. MATERIAL_VIEW = 0,
  111. MATERIAL_PROJECTION,
  112. MATERIAL_MATRIX_UNUSED0,
  113. MATERIAL_MATRIX_UNUSED1,
  114. MATERIAL_MATRIX_UNUSED2,
  115. MATERIAL_MATRIX_UNUSED3,
  116. MATERIAL_MATRIX_UNUSED4,
  117. MATERIAL_MATRIX_UNUSED5,
  118. MATERIAL_MATRIX_UNUSED6,
  119. MATERIAL_MATRIX_UNUSED7,
  120. MATERIAL_MODEL,
  121. // Total number of matrices
  122. NUM_MATRIX_MODES = MATERIAL_MODEL+1,
  123. };
  124. // FIXME: How do I specify the actual number of matrix modes?
  125. const int NUM_MODEL_TRANSFORMS = 53;
  126. const int MATERIAL_MODEL_MAX = MATERIAL_MODEL + NUM_MODEL_TRANSFORMS;
  127. enum MaterialPrimitiveType_t
  128. {
  129. MATERIAL_POINTS = 0x0,
  130. MATERIAL_LINES,
  131. MATERIAL_TRIANGLES,
  132. MATERIAL_TRIANGLE_STRIP,
  133. MATERIAL_LINE_STRIP,
  134. MATERIAL_LINE_LOOP, // a single line loop
  135. MATERIAL_POLYGON, // this is a *single* polygon
  136. MATERIAL_QUADS,
  137. MATERIAL_SUBD_QUADS_EXTRA, // Extraordinary sub-d quads
  138. MATERIAL_SUBD_QUADS_REG, // Regular sub-d quads
  139. MATERIAL_INSTANCED_QUADS, // (X360) like MATERIAL_QUADS, but uses vertex instancing
  140. // This is used for static meshes that contain multiple types of
  141. // primitive types. When calling draw, you'll need to specify
  142. // a primitive type.
  143. MATERIAL_HETEROGENOUS
  144. };
  145. enum TessellationMode_t
  146. {
  147. TESSELLATION_MODE_DISABLED = 0,
  148. TESSELLATION_MODE_ACC_PATCHES_EXTRA,
  149. TESSELLATION_MODE_ACC_PATCHES_REG
  150. };
  151. enum MaterialPropertyTypes_t
  152. {
  153. MATERIAL_PROPERTY_NEEDS_LIGHTMAP = 0, // bool
  154. MATERIAL_PROPERTY_OPACITY, // int (enum MaterialPropertyOpacityTypes_t)
  155. MATERIAL_PROPERTY_REFLECTIVITY, // vec3_t
  156. MATERIAL_PROPERTY_NEEDS_BUMPED_LIGHTMAPS // bool
  157. };
  158. // acceptable property values for MATERIAL_PROPERTY_OPACITY
  159. enum MaterialPropertyOpacityTypes_t
  160. {
  161. MATERIAL_ALPHATEST = 0,
  162. MATERIAL_OPAQUE,
  163. MATERIAL_TRANSLUCENT
  164. };
  165. enum MaterialBufferTypes_t
  166. {
  167. MATERIAL_FRONT = 0,
  168. MATERIAL_BACK
  169. };
  170. enum MaterialCullMode_t
  171. {
  172. MATERIAL_CULLMODE_CCW, // this culls polygons with counterclockwise winding
  173. MATERIAL_CULLMODE_CW, // this culls polygons with clockwise winding
  174. MATERIAL_CULLMODE_NONE // cull nothing
  175. };
  176. enum MaterialIndexFormat_t
  177. {
  178. MATERIAL_INDEX_FORMAT_UNKNOWN = -1,
  179. MATERIAL_INDEX_FORMAT_16BIT = 0,
  180. MATERIAL_INDEX_FORMAT_32BIT,
  181. };
  182. enum MaterialFogMode_t
  183. {
  184. MATERIAL_FOG_NONE,
  185. MATERIAL_FOG_LINEAR,
  186. MATERIAL_FOG_LINEAR_BELOW_FOG_Z,
  187. };
  188. enum MaterialHeightClipMode_t
  189. {
  190. MATERIAL_HEIGHTCLIPMODE_DISABLE,
  191. MATERIAL_HEIGHTCLIPMODE_RENDER_ABOVE_HEIGHT,
  192. MATERIAL_HEIGHTCLIPMODE_RENDER_BELOW_HEIGHT
  193. };
  194. enum MaterialNonInteractiveMode_t
  195. {
  196. MATERIAL_NON_INTERACTIVE_MODE_NONE = -1,
  197. MATERIAL_NON_INTERACTIVE_MODE_STARTUP = 0,
  198. MATERIAL_NON_INTERACTIVE_MODE_LEVEL_LOAD,
  199. MATERIAL_NON_INTERACTIVE_MODE_COUNT,
  200. };
  201. //-----------------------------------------------------------------------------
  202. // Special morph used in decalling pass
  203. //-----------------------------------------------------------------------------
  204. #define MATERIAL_MORPH_DECAL ( (IMorph*)1 )
  205. //-----------------------------------------------------------------------------
  206. //
  207. //-----------------------------------------------------------------------------
  208. enum MaterialThreadMode_t
  209. {
  210. MATERIAL_SINGLE_THREADED,
  211. MATERIAL_QUEUED_SINGLE_THREADED,
  212. MATERIAL_QUEUED_THREADED
  213. };
  214. //-----------------------------------------------------------------------------
  215. //
  216. //-----------------------------------------------------------------------------
  217. enum MaterialContextType_t
  218. {
  219. MATERIAL_HARDWARE_CONTEXT,
  220. MATERIAL_QUEUED_CONTEXT,
  221. MATERIAL_NULL_CONTEXT
  222. };
  223. //-----------------------------------------------------------------------------
  224. // Light structure
  225. //-----------------------------------------------------------------------------
  226. #include "mathlib/lightdesc.h"
  227. enum
  228. {
  229. MATERIAL_MAX_LIGHT_COUNT = 4,
  230. };
  231. struct MaterialLightingState_t
  232. {
  233. Vector m_vecAmbientCube[6]; // ambient, and lights that aren't in locallight[]
  234. Vector m_vecLightingOrigin; // The position from which lighting state was computed
  235. int m_nLocalLightCount;
  236. LightDesc_t m_pLocalLightDesc[MATERIAL_MAX_LIGHT_COUNT];
  237. MaterialLightingState_t &operator=( const MaterialLightingState_t &src )
  238. {
  239. memcpy( this, &src, sizeof(MaterialLightingState_t) - MATERIAL_MAX_LIGHT_COUNT * sizeof(LightDesc_t) );
  240. size_t byteCount = src.m_nLocalLightCount * sizeof(LightDesc_t);
  241. Assert( byteCount <= sizeof(m_pLocalLightDesc) );
  242. memcpy( m_pLocalLightDesc, &src.m_pLocalLightDesc, byteCount );
  243. return *this;
  244. }
  245. };
  246. #define CREATERENDERTARGETFLAGS_HDR 0x00000001
  247. #define CREATERENDERTARGETFLAGS_AUTOMIPMAP 0x00000002
  248. #define CREATERENDERTARGETFLAGS_UNFILTERABLE_OK 0x00000004
  249. // XBOX ONLY:
  250. #define CREATERENDERTARGETFLAGS_NOEDRAM 0x00000008 // inhibit allocation in 360 EDRAM
  251. #define CREATERENDERTARGETFLAGS_TEMP 0x00000010 // only allocates memory upon first resolve, destroyed at level end
  252. #define CREATERENDERTARGETFLAGS_ALIASCOLORANDDEPTHSURFACES 0x00000020 // force the depth surface to be aliased overtop of the color surface in EDRAM, for the special case of depth-only rendering
  253. //-----------------------------------------------------------------------------
  254. // Used to describe a material batch
  255. //-----------------------------------------------------------------------------
  256. struct MaterialBatchData_t
  257. {
  258. IMaterial * m_pMaterial;
  259. matrix3x4_t * m_pModelToWorld;
  260. const ITexture * m_pEnvCubemap;
  261. int m_nLightmapPageId;
  262. MaterialPrimitiveType_t m_nPrimType;
  263. int m_nIndexOffset;
  264. int m_nIndexCount;
  265. int m_nVertexOffsetInBytes;
  266. const IIndexBuffer * m_pIndexBuffer;
  267. const IVertexBuffer * m_pVertexBuffer;
  268. };
  269. //-----------------------------------------------------------------------------
  270. // Enumeration for the various fields capable of being morphed
  271. //-----------------------------------------------------------------------------
  272. enum MorphFormatFlags_t
  273. {
  274. MORPH_POSITION = 0x0001, // 3D
  275. MORPH_NORMAL = 0x0002, // 3D
  276. MORPH_WRINKLE = 0x0004, // 1D
  277. MORPH_SPEED = 0x0008, // 1D
  278. MORPH_SIDE = 0x0010, // 1D
  279. };
  280. //-----------------------------------------------------------------------------
  281. // The morph format type
  282. //-----------------------------------------------------------------------------
  283. typedef unsigned int MorphFormat_t;
  284. //-----------------------------------------------------------------------------
  285. // Standard lightmaps
  286. //-----------------------------------------------------------------------------
  287. enum StandardLightmap_t
  288. {
  289. MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE = -1,
  290. MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE_BUMP = -2,
  291. MATERIAL_SYSTEM_LIGHTMAP_PAGE_USER_DEFINED = -3,
  292. MATERIAL_SYSTEM_LIGHTMAP_PAGE_INVALID = -4,
  293. };
  294. struct MaterialSystem_SortInfo_t
  295. {
  296. IMaterial *material;
  297. int lightmapPageID;
  298. };
  299. #define MAX_FB_TEXTURES 4
  300. //-----------------------------------------------------------------------------
  301. // Information about each adapter
  302. //-----------------------------------------------------------------------------
  303. enum
  304. {
  305. MATERIAL_ADAPTER_NAME_LENGTH = 512
  306. };
  307. struct MaterialAdapterInfo_t
  308. {
  309. char m_pDriverName[MATERIAL_ADAPTER_NAME_LENGTH];
  310. unsigned int m_VendorID;
  311. unsigned int m_DeviceID;
  312. unsigned int m_SubSysID;
  313. unsigned int m_Revision;
  314. int m_nDXSupportLevel; // This is the *preferred* dx support level
  315. int m_nMinDXSupportLevel;
  316. int m_nMaxDXSupportLevel;
  317. unsigned int m_nDriverVersionHigh;
  318. unsigned int m_nDriverVersionLow;
  319. };
  320. //-----------------------------------------------------------------------------
  321. // Video mode info..
  322. //-----------------------------------------------------------------------------
  323. struct MaterialVideoMode_t
  324. {
  325. int m_Width; // if width and height are 0 and you select
  326. int m_Height; // windowed mode, it'll use the window size
  327. ImageFormat m_Format; // use ImageFormats (ignored for windowed mode)
  328. int m_RefreshRate; // 0 == default (ignored for windowed mode)
  329. };
  330. //--------------------------------------------------------------------------------
  331. // Uberlight parameters
  332. //--------------------------------------------------------------------------------
  333. struct UberlightState_t
  334. {
  335. UberlightState_t()
  336. {
  337. m_fNearEdge = 2.0f;
  338. m_fFarEdge = 100.0f;
  339. m_fCutOn = 10.0f;
  340. m_fCutOff = 650.0f;
  341. m_fShearx = 0.0f;
  342. m_fSheary = 0.0f;
  343. m_fWidth = 0.3f;
  344. m_fWedge = 0.05f;
  345. m_fHeight = 0.3f;
  346. m_fHedge = 0.05f;
  347. m_fRoundness = 0.8f;
  348. }
  349. float m_fNearEdge;
  350. float m_fFarEdge;
  351. float m_fCutOn;
  352. float m_fCutOff;
  353. float m_fShearx;
  354. float m_fSheary;
  355. float m_fWidth;
  356. float m_fWedge;
  357. float m_fHeight;
  358. float m_fHedge;
  359. float m_fRoundness;
  360. IMPLEMENT_OPERATOR_EQUAL( UberlightState_t );
  361. };
  362. // fixme: should move this into something else.
  363. struct FlashlightState_t
  364. {
  365. FlashlightState_t()
  366. {
  367. m_bEnableShadows = false; // Provide reasonable defaults for shadow depth mapping parameters
  368. m_bDrawShadowFrustum = false;
  369. m_flShadowMapResolution = 1024.0f;
  370. m_flShadowFilterSize = 3.0f;
  371. m_flShadowSlopeScaleDepthBias = 16.0f;
  372. m_flShadowDepthBias = 0.0005f;
  373. m_flShadowJitterSeed = 0.0f;
  374. m_flShadowAtten = 0.0f;
  375. m_flAmbientOcclusion = 0.0f;
  376. m_nShadowQuality = 0;
  377. m_bShadowHighRes = false;
  378. m_bScissor = false;
  379. m_nLeft = -1;
  380. m_nTop = -1;
  381. m_nRight = -1;
  382. m_nBottom = -1;
  383. m_bUberlight = false;
  384. m_bVolumetric = false;
  385. m_flNoiseStrength = 0.8f;
  386. m_flFlashlightTime = 0.0f;
  387. m_nNumPlanes = 64;
  388. m_flPlaneOffset = 0.0f;
  389. m_flVolumetricIntensity = 1.0f;
  390. m_bOrtho = false;
  391. m_fOrthoLeft = -1.0f;
  392. m_fOrthoRight = 1.0f;
  393. m_fOrthoTop = -1.0f;
  394. m_fOrthoBottom = 1.0f;
  395. m_fBrightnessScale = 1.0f;
  396. m_pSpotlightTexture = NULL;
  397. m_pProjectedMaterial = NULL;
  398. m_bShareBetweenSplitscreenPlayers = false;
  399. }
  400. Vector m_vecLightOrigin;
  401. Quaternion m_quatOrientation;
  402. float m_NearZ;
  403. float m_FarZ;
  404. float m_fHorizontalFOVDegrees;
  405. float m_fVerticalFOVDegrees;
  406. bool m_bOrtho;
  407. float m_fOrthoLeft;
  408. float m_fOrthoRight;
  409. float m_fOrthoTop;
  410. float m_fOrthoBottom;
  411. float m_fQuadraticAtten;
  412. float m_fLinearAtten;
  413. float m_fConstantAtten;
  414. float m_FarZAtten;
  415. float m_Color[4];
  416. float m_fBrightnessScale;
  417. ITexture *m_pSpotlightTexture;
  418. IMaterial *m_pProjectedMaterial;
  419. int m_nSpotlightTextureFrame;
  420. // Shadow depth mapping parameters
  421. bool m_bEnableShadows;
  422. bool m_bDrawShadowFrustum;
  423. float m_flShadowMapResolution;
  424. float m_flShadowFilterSize;
  425. float m_flShadowSlopeScaleDepthBias;
  426. float m_flShadowDepthBias;
  427. float m_flShadowJitterSeed;
  428. float m_flShadowAtten;
  429. float m_flAmbientOcclusion;
  430. int m_nShadowQuality;
  431. bool m_bShadowHighRes;
  432. // simple projection
  433. float m_flProjectionSize;
  434. float m_flProjectionRotation;
  435. // Uberlight parameters
  436. bool m_bUberlight;
  437. UberlightState_t m_uberlightState;
  438. bool m_bVolumetric;
  439. float m_flNoiseStrength;
  440. float m_flFlashlightTime;
  441. int m_nNumPlanes;
  442. float m_flPlaneOffset;
  443. float m_flVolumetricIntensity;
  444. bool m_bShareBetweenSplitscreenPlayers; // When true, this flashlight will render for all splitscreen players
  445. // Getters for scissor members
  446. bool DoScissor() const { return m_bScissor; }
  447. int GetLeft() const { return m_nLeft; }
  448. int GetTop() const { return m_nTop; }
  449. int GetRight() const { return m_nRight; }
  450. int GetBottom() const { return m_nBottom; }
  451. private:
  452. friend class CShadowMgr;
  453. bool m_bScissor;
  454. int m_nLeft;
  455. int m_nTop;
  456. int m_nRight;
  457. int m_nBottom;
  458. IMPLEMENT_OPERATOR_EQUAL( FlashlightState_t );
  459. };
  460. #define MAX_CASCADED_SHADOW_MAPPING_CASCADES (4)
  461. // The number of float4's in the CascadedShadowMappingState_t (starting at m_vLightColor)
  462. #define CASCADED_SHADOW_MAPPING_CONSTANT_BUFFER_SIZE (26)
  463. // Note: This struct is sent as-is as an array of pixel shader constants (starting at m_vLightColor). If you modify it, be sure to update CASCADED_SHADOW_MAPPING_CONSTANT_BUFFER_SIZE.
  464. struct CascadedShadowMappingState_t
  465. {
  466. uint m_nNumCascades;
  467. bool m_bIsRenderingViewModels;
  468. Vector4D m_vLightColor;
  469. Vector m_vLightDir;
  470. float m_flPadding1;
  471. struct
  472. {
  473. float m_flInvShadowTextureWidth;
  474. float m_flInvShadowTextureHeight;
  475. float m_flHalfInvShadowTextureWidth;
  476. float m_flHalfInvShadowTextureHeight;
  477. } m_TexParams;
  478. struct
  479. {
  480. float m_flShadowTextureWidth;
  481. float m_flShadowTextureHeight;
  482. float m_flSplitLerpFactorBase;
  483. float m_flSplitLerpFactorInvRange;
  484. } m_TexParams2;
  485. struct
  486. {
  487. float m_flDistLerpFactorBase;
  488. float m_flDistLerpFactorInvRange;
  489. float m_flUnused0;
  490. float m_flUnused1;
  491. } m_TexParams3;
  492. VMatrix m_matWorldToShadowTexMatrices[ MAX_CASCADED_SHADOW_MAPPING_CASCADES ];
  493. Vector4D m_vCascadeAtlasUVOffsets[ MAX_CASCADED_SHADOW_MAPPING_CASCADES ];
  494. Vector4D m_vCamPosition;
  495. };
  496. //-----------------------------------------------------------------------------
  497. // Flags to be used with the Init call
  498. //-----------------------------------------------------------------------------
  499. enum MaterialInitFlags_t
  500. {
  501. MATERIAL_INIT_ALLOCATE_FULLSCREEN_TEXTURE = 0x2,
  502. MATERIAL_INIT_REFERENCE_RASTERIZER = 0x4,
  503. };
  504. //-----------------------------------------------------------------------------
  505. // Flags to specify type of depth buffer used with RT
  506. //-----------------------------------------------------------------------------
  507. // GR - this is to add RT with no depth buffer bound
  508. enum MaterialRenderTargetDepth_t
  509. {
  510. MATERIAL_RT_DEPTH_SHARED = 0x0,
  511. MATERIAL_RT_DEPTH_SEPARATE = 0x1,
  512. MATERIAL_RT_DEPTH_NONE = 0x2,
  513. MATERIAL_RT_DEPTH_ONLY = 0x3,
  514. };
  515. //-----------------------------------------------------------------------------
  516. // A function to be called when we need to release all vertex buffers
  517. // NOTE: The restore function will tell the caller if all the vertex formats
  518. // changed so that it can flush caches, etc. if it needs to (for dxlevel support)
  519. //-----------------------------------------------------------------------------
  520. enum RestoreChangeFlags_t
  521. {
  522. MATERIAL_RESTORE_VERTEX_FORMAT_CHANGED = 0x1,
  523. MATERIAL_RESTORE_RELEASE_MANAGED_RESOURCES = 0x2,
  524. };
  525. // NOTE: All size modes will force the render target to be smaller than or equal to
  526. // the size of the framebuffer.
  527. enum RenderTargetSizeMode_t
  528. {
  529. RT_SIZE_NO_CHANGE=0, // Only allowed for render targets that don't want a depth buffer
  530. // (because if they have a depth buffer, the render target must be less than or equal to the size of the framebuffer).
  531. RT_SIZE_DEFAULT=1, // Don't play with the specified width and height other than making sure it fits in the framebuffer.
  532. RT_SIZE_PICMIP=2, // Apply picmip to the render target's width and height.
  533. RT_SIZE_HDR=3, // frame_buffer_width / 4
  534. RT_SIZE_FULL_FRAME_BUFFER=4, // Same size as frame buffer, or next lower power of 2 if we can't do that.
  535. RT_SIZE_OFFSCREEN=5, // Target of specified size, don't mess with dimensions
  536. RT_SIZE_FULL_FRAME_BUFFER_ROUNDED_UP=6 // Same size as the frame buffer, rounded up if necessary for systems that can't do non-power of two textures.
  537. };
  538. enum AntiAliasingHintEnum_t
  539. {
  540. AA_HINT_MESHES,
  541. AA_HINT_TEXT,
  542. AA_HINT_DEBUG_TEXT,
  543. AA_HINT_HEAVY_UI_OVERLAY,
  544. AA_HINT_ALIASING_PUSH,
  545. AA_HINT_ALIASING_POP,
  546. AA_HINT_POSTPROCESS,
  547. AA_HINT_MOVIE,
  548. AA_HINT_MENU
  549. };
  550. typedef void (*MaterialBufferReleaseFunc_t)( int nChangeFlags ); // see RestoreChangeFlags_t
  551. typedef void (*MaterialBufferRestoreFunc_t)( int nChangeFlags ); // see RestoreChangeFlags_t
  552. typedef void (*ModeChangeCallbackFunc_t)( void );
  553. typedef void (*EndFrameCleanupFunc_t)( void );
  554. typedef void (*OnLevelShutdownFunc_t)( void * pUserData );
  555. typedef bool (*EndFramePriorToNextContextFunc_t)( void );
  556. //typedef int VertexBufferHandle_t;
  557. typedef unsigned short MaterialHandle_t;
  558. DECLARE_POINTER_HANDLE( OcclusionQueryObjectHandle_t );
  559. #define INVALID_OCCLUSION_QUERY_OBJECT_HANDLE ( (OcclusionQueryObjectHandle_t)0 )
  560. class IMaterialProxyFactory;
  561. class ITexture;
  562. class IMaterialSystemHardwareConfig;
  563. class CShadowMgr;
  564. DECLARE_POINTER_HANDLE( MaterialLock_t );
  565. //-----------------------------------------------------------------------------
  566. // Information about a material texture
  567. //-----------------------------------------------------------------------------
  568. struct MaterialTextureInfo_t
  569. {
  570. // Exclude information:
  571. // -1 texture is not subject to exclude-handling
  572. // 0 texture is completely excluded
  573. // >0 texture is clamped according to exclude-instruction
  574. int iExcludeInformation;
  575. };
  576. struct ApplicationPerformanceCountersInfo_t
  577. {
  578. float msMain;
  579. float msMST;
  580. float msGPU;
  581. float msFlip;
  582. float msTotal;
  583. };
  584. struct ApplicationInstantCountersInfo_t
  585. {
  586. uint m_nCpuActivityMask;
  587. uint m_nDeferredWordsAllocated;
  588. };
  589. struct WorldListIndicesInfo_t
  590. {
  591. uint m_nTotalIndices; // how many indices the world needs to render
  592. uint m_nMaxBatchIndices; // how many indices there are in the largest batch
  593. };
  594. struct AspectRatioInfo_t
  595. {
  596. bool m_bIsWidescreen;
  597. bool m_bIsHidef;
  598. float m_flFrameBufferAspectRatio; // width / height of framebuffer in pixels
  599. float m_flPhysicalAspectRatio; // width / height of the physical display in real-life units
  600. float m_flFrameBuffertoPhysicalScalar; // m_flPhysicalAspectRatio / m_flFrameBufferAspectRatio
  601. float m_flPhysicalToFrameBufferScalar; // m_flFrameBufferAspectRatio / m_flPhysicalAspectRatio
  602. bool m_bInitialized;
  603. AspectRatioInfo_t() :
  604. m_bIsWidescreen( false ),
  605. m_bIsHidef( false ),
  606. m_flFrameBufferAspectRatio( 4.0f / 3.0f ),
  607. m_flPhysicalAspectRatio( 4.0f / 3.0f ),
  608. m_flFrameBuffertoPhysicalScalar( 1.0f ),
  609. m_flPhysicalToFrameBufferScalar( 1.0f ),
  610. m_bInitialized( false )
  611. {
  612. }
  613. };
  614. //-----------------------------------------------------------------------------
  615. //
  616. //-----------------------------------------------------------------------------
  617. abstract_class IMaterialSystem : public IAppSystem
  618. {
  619. public:
  620. // Placeholder for API revision
  621. virtual bool Connect( CreateInterfaceFn factory ) = 0;
  622. virtual void Disconnect() = 0;
  623. virtual void *QueryInterface( const char *pInterfaceName ) = 0;
  624. virtual InitReturnVal_t Init() = 0;
  625. virtual void Shutdown() = 0;
  626. //---------------------------------------------------------
  627. // Initialization and shutdown
  628. //---------------------------------------------------------
  629. // Call this to initialize the material system
  630. // returns a method to create interfaces in the shader dll
  631. virtual CreateInterfaceFn Init( char const* pShaderAPIDLL,
  632. IMaterialProxyFactory *pMaterialProxyFactory,
  633. CreateInterfaceFn fileSystemFactory,
  634. CreateInterfaceFn cvarFactory=NULL ) = 0;
  635. // Call this to set an explicit shader version to use
  636. // Must be called before Init().
  637. virtual void SetShaderAPI( char const *pShaderAPIDLL ) = 0;
  638. // Must be called before Init(), if you're going to call it at all...
  639. virtual void SetAdapter( int nAdapter, int nFlags ) = 0;
  640. // Call this when the mod has been set up, which may occur after init
  641. // At this point, the game + gamebin paths have been set up
  642. virtual void ModInit() = 0;
  643. virtual void ModShutdown() = 0;
  644. //---------------------------------------------------------
  645. //
  646. //---------------------------------------------------------
  647. virtual void SetThreadMode( MaterialThreadMode_t mode, int nServiceThread = -1 ) = 0;
  648. virtual MaterialThreadMode_t GetThreadMode() = 0;
  649. virtual bool IsRenderThreadSafe( ) = 0;
  650. virtual void ExecuteQueued() = 0;
  651. #ifdef _CERT
  652. static
  653. #else
  654. virtual
  655. #endif
  656. void OnDebugEvent( const char * pEvent = "" ){}
  657. //---------------------------------------------------------
  658. // Config management
  659. //---------------------------------------------------------
  660. virtual IMaterialSystemHardwareConfig *GetHardwareConfig( const char *pVersion, int *returnCode ) = 0;
  661. // Call this before rendering each frame with the current config
  662. // for the material system.
  663. // Will do whatever is necessary to get the material system into the correct state
  664. // upon configuration change. .doesn't much else otherwise.
  665. virtual bool UpdateConfig( bool bForceUpdate ) = 0;
  666. // Force this to be the config; update all material system convars to match the state
  667. // return true if lightmaps need to be redownloaded
  668. virtual bool OverrideConfig( const MaterialSystem_Config_t &config, bool bForceUpdate ) = 0;
  669. // Get the current config for this video card (as last set by UpdateConfig)
  670. virtual const MaterialSystem_Config_t &GetCurrentConfigForVideoCard() const = 0;
  671. // Gets *recommended* configuration information associated with the display card,
  672. // given a particular dx level to run under.
  673. // Use dxlevel 0 to use the recommended dx level.
  674. // The function returns false if an invalid dxlevel was specified
  675. // UNDONE: To find out all convars affected by configuration, we'll need to change
  676. // the dxsupport.pl program to output all column headers into a single keyvalue block
  677. // and then we would read that in, and send it back to the client
  678. virtual bool GetRecommendedConfigurationInfo( int nDXLevel, KeyValues * pKeyValues ) = 0;
  679. // -----------------------------------------------------------
  680. // Device methods
  681. // -----------------------------------------------------------
  682. // Gets the number of adapters...
  683. virtual int GetDisplayAdapterCount() const = 0;
  684. // Returns the current adapter in use
  685. virtual int GetCurrentAdapter() const = 0;
  686. // Returns info about each adapter
  687. virtual void GetDisplayAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const = 0;
  688. // Returns the number of modes
  689. virtual int GetModeCount( int adapter ) const = 0;
  690. // Returns mode information..
  691. virtual void GetModeInfo( int adapter, int mode, MaterialVideoMode_t& info ) const = 0;
  692. virtual void AddModeChangeCallBack( ModeChangeCallbackFunc_t func ) = 0;
  693. // Returns the mode info for the current display device
  694. virtual void GetDisplayMode( MaterialVideoMode_t& mode ) const = 0;
  695. // Sets the mode...
  696. virtual bool SetMode( void* hwnd, const MaterialSystem_Config_t &config ) = 0;
  697. virtual bool SupportsMSAAMode( int nMSAAMode ) = 0;
  698. // FIXME: REMOVE! Get video card identitier
  699. virtual const MaterialSystemHardwareIdentifier_t &GetVideoCardIdentifier( void ) const = 0;
  700. // Use this to spew information about the 3D layer
  701. virtual void SpewDriverInfo() const = 0;
  702. // Get the image format of the back buffer. . useful when creating render targets, etc.
  703. virtual void GetBackBufferDimensions( int &width, int &height) const = 0;
  704. virtual ImageFormat GetBackBufferFormat() const = 0;
  705. virtual const AspectRatioInfo_t &GetAspectRatioInfo() const = 0;
  706. virtual bool SupportsHDRMode( HDRType_t nHDRModede ) = 0;
  707. // -----------------------------------------------------------
  708. // Window methods
  709. // -----------------------------------------------------------
  710. // Creates/ destroys a child window
  711. virtual bool AddView( void* hwnd ) = 0;
  712. virtual void RemoveView( void* hwnd ) = 0;
  713. // Sets the view
  714. virtual void SetView( void* hwnd ) = 0;
  715. // -----------------------------------------------------------
  716. // Control flow
  717. // -----------------------------------------------------------
  718. virtual void BeginFrame( float frameTime ) = 0;
  719. virtual void EndFrame( ) = 0;
  720. virtual void Flush( bool flushHardware = false ) = 0;
  721. virtual uint32 GetCurrentFrameCount() = 0;
  722. /// FIXME: This stuff needs to be cleaned up and abstracted.
  723. // Stuff that gets exported to the launcher through the engine
  724. virtual void SwapBuffers( ) = 0;
  725. // Flushes managed textures from the texture cacher
  726. virtual void EvictManagedResources() = 0;
  727. virtual void ReleaseResources(void) = 0;
  728. virtual void ReacquireResources(void ) = 0;
  729. // -----------------------------------------------------------
  730. // Device loss/restore
  731. // -----------------------------------------------------------
  732. // Installs a function to be called when we need to release vertex buffers + textures
  733. virtual void AddReleaseFunc( MaterialBufferReleaseFunc_t func ) = 0;
  734. virtual void RemoveReleaseFunc( MaterialBufferReleaseFunc_t func ) = 0;
  735. // Installs a function to be called when we need to restore vertex buffers
  736. virtual void AddRestoreFunc( MaterialBufferRestoreFunc_t func ) = 0;
  737. virtual void RemoveRestoreFunc( MaterialBufferRestoreFunc_t func ) = 0;
  738. // Installs a function to be called when we need to delete objects at the end of the render frame
  739. virtual void AddEndFrameCleanupFunc( EndFrameCleanupFunc_t func ) = 0;
  740. virtual void RemoveEndFrameCleanupFunc( EndFrameCleanupFunc_t func ) = 0;
  741. // Gets called when the level is shuts down, will call the registered callback
  742. virtual void OnLevelShutdown() = 0;
  743. // Installs a function to be called when the level is shuts down
  744. virtual bool AddOnLevelShutdownFunc( OnLevelShutdownFunc_t func, void * pUserData ) = 0;
  745. virtual bool RemoveOnLevelShutdownFunc( OnLevelShutdownFunc_t func, void * pUserData ) = 0;
  746. virtual void OnLevelLoadingComplete() = 0;
  747. // Release temporary HW memory...
  748. virtual void ResetTempHWMemory( bool bExitingLevel = false ) = 0;
  749. // For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer)
  750. virtual void HandleDeviceLost() = 0;
  751. // -----------------------------------------------------------
  752. // Shaders
  753. // -----------------------------------------------------------
  754. // Used to iterate over all shaders for editing purposes
  755. // GetShaders returns the number of shaders it actually found
  756. virtual int ShaderCount() const = 0;
  757. virtual int GetShaders( int nFirstShader, int nMaxCount, IShader **ppShaderList ) const = 0;
  758. // FIXME: Is there a better way of doing this?
  759. // Returns shader flag names for editors to be able to edit them
  760. virtual int ShaderFlagCount() const = 0;
  761. virtual const char * ShaderFlagName( int nIndex ) const = 0;
  762. // Gets the actual shader fallback for a particular shader
  763. virtual void GetShaderFallback( const char *pShaderName, char *pFallbackShader, int nFallbackLength ) = 0;
  764. // -----------------------------------------------------------
  765. // Material proxies
  766. // -----------------------------------------------------------
  767. virtual IMaterialProxyFactory *GetMaterialProxyFactory() = 0;
  768. // Sets the material proxy factory. Calling this causes all materials to be uncached.
  769. virtual void SetMaterialProxyFactory( IMaterialProxyFactory* pFactory ) = 0;
  770. // -----------------------------------------------------------
  771. // Editor mode
  772. // -----------------------------------------------------------
  773. // Used to enable editor materials. Must be called before Init.
  774. virtual void EnableEditorMaterials() = 0;
  775. virtual void EnableGBuffers() = 0;
  776. // -----------------------------------------------------------
  777. // Stub mode mode
  778. // -----------------------------------------------------------
  779. // Force it to ignore Draw calls.
  780. virtual void SetInStubMode( bool bInStubMode ) = 0;
  781. //---------------------------------------------------------
  782. // Debug support
  783. //---------------------------------------------------------
  784. virtual void DebugPrintUsedMaterials( const char *pSearchSubString, bool bVerbose ) = 0;
  785. virtual void DebugPrintUsedTextures( void ) = 0;
  786. virtual void ToggleSuppressMaterial( char const* pMaterialName ) = 0;
  787. virtual void ToggleDebugMaterial( char const* pMaterialName ) = 0;
  788. //---------------------------------------------------------
  789. // Misc features
  790. //---------------------------------------------------------
  791. //returns whether fast clipping is being used or not - needed to be exposed for better per-object clip behavior
  792. virtual bool UsingFastClipping( void ) = 0;
  793. virtual int StencilBufferBits( void ) = 0; //number of bits per pixel in the stencil buffer
  794. //---------------------------------------------------------
  795. // Material and texture management
  796. //---------------------------------------------------------
  797. // uncache all materials. . good for forcing reload of materials.
  798. virtual void UncacheAllMaterials( ) = 0;
  799. // Remove any materials from memory that aren't in use as determined
  800. // by the IMaterial's reference count.
  801. virtual void UncacheUnusedMaterials( bool bRecomputeStateSnapshots = false ) = 0;
  802. // Load any materials into memory that are to be used as determined
  803. // by the IMaterial's reference count.
  804. virtual void CacheUsedMaterials( ) = 0;
  805. // Force all textures to be reloaded from disk.
  806. virtual void ReloadTextures( ) = 0;
  807. // Reloads materials
  808. virtual void ReloadMaterials( const char *pSubString = NULL ) = 0;
  809. // Create a procedural material. The keyvalues looks like a VMT file
  810. virtual IMaterial * CreateMaterial( const char *pMaterialName, KeyValues *pVMTKeyValues ) = 0;
  811. // Find a material by name.
  812. // The name of a material is a full path to
  813. // the vmt file starting from "hl2/materials" (or equivalent) without
  814. // a file extension.
  815. // eg. "dev/dev_bumptest" refers to somethign similar to:
  816. // "d:/hl2/hl2/materials/dev/dev_bumptest.vmt"
  817. //
  818. // Most of the texture groups for pTextureGroupName are listed in texture_group_names.h.
  819. //
  820. // Note: if the material can't be found, this returns a checkerboard material. You can
  821. // find out if you have that material by calling IMaterial::IsErrorMaterial().
  822. // (Or use the global IsErrorMaterial function, which checks if it's null too).
  823. virtual IMaterial * FindMaterial( char const* pMaterialName, const char *pTextureGroupName, bool complain = true, const char *pComplainPrefix = NULL ) = 0;
  824. virtual bool LoadKeyValuesFromVMTFile( KeyValues &vmtKeyValues, const char *pMaterialName, bool bUsesUNCFilename ) = 0;
  825. //---------------------------------
  826. // This is the interface for knowing what materials are available
  827. // is to use the following functions to get a list of materials. The
  828. // material names will have the full path to the material, and that is the
  829. // only way that the directory structure of the materials will be seen through this
  830. // interface.
  831. // NOTE: This is mostly for worldcraft to get a list of materials to put
  832. // in the "texture" browser.in Worldcraft
  833. virtual MaterialHandle_t FirstMaterial() const = 0;
  834. // returns InvalidMaterial if there isn't another material.
  835. // WARNING: you must call GetNextMaterial until it returns NULL,
  836. // otherwise there will be a memory leak.
  837. virtual MaterialHandle_t NextMaterial( MaterialHandle_t h ) const = 0;
  838. // This is the invalid material
  839. virtual MaterialHandle_t InvalidMaterial() const = 0;
  840. // Returns a particular material
  841. virtual IMaterial* GetMaterial( MaterialHandle_t h ) const = 0;
  842. // Get the total number of materials in the system. These aren't just the used
  843. // materials, but the complete collection.
  844. virtual int GetNumMaterials( ) const = 0;
  845. //---------------------------------
  846. virtual ITexture * FindTexture( char const* pTextureName, const char *pTextureGroupName, bool complain = true, int nAdditionalCreationFlags = 0 ) = 0;
  847. // Checks to see if a particular texture is loaded
  848. virtual bool IsTextureLoaded( char const* pTextureName ) const = 0;
  849. // Creates a procedural texture
  850. virtual ITexture * CreateProceduralTexture( const char *pTextureName,
  851. const char *pTextureGroupName,
  852. int w,
  853. int h,
  854. ImageFormat fmt,
  855. int nFlags ) = 0;
  856. #if defined( _X360 )
  857. // Create a texture for displaying gamerpics.
  858. // This function allocates the texture in the correct gamerpic format, but it does not fill in the gamerpic data.
  859. virtual ITexture * CreateGamerpicTexture( const char *pTextureName,
  860. const char *pTextureGroupName,
  861. int nFlags ) = 0;
  862. // Update the given texture with the player gamerpic for the local player at the given index.
  863. // Note: this texture must be the correct size and format. Use CreateGamerpicTexture.
  864. virtual bool UpdateLocalGamerpicTexture( ITexture *pTexture, DWORD userIndex ) = 0;
  865. // Update the given texture with a remote player's gamerpic.
  866. // Note: this texture must be the correct size and format. Use CreateGamerpicTexture.
  867. virtual bool UpdateRemoteGamerpicTexture( ITexture *pTexture, XUID xuid ) = 0;
  868. #endif // _X360
  869. //
  870. // Render targets
  871. //
  872. virtual void BeginRenderTargetAllocation() = 0;
  873. virtual void EndRenderTargetAllocation() = 0; // Simulate an Alt-Tab in here, which causes a release/restore of all resources
  874. // Creates a render target
  875. // If depth == true, a depth buffer is also allocated. If not, then
  876. // the screen's depth buffer is used.
  877. // Creates a texture for use as a render target
  878. virtual ITexture * CreateRenderTargetTexture( int w,
  879. int h,
  880. RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change).
  881. ImageFormat format,
  882. MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED ) = 0;
  883. virtual ITexture * CreateNamedRenderTargetTextureEx( const char *pRTName, // Pass in NULL here for an unnamed render target.
  884. int w,
  885. int h,
  886. RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change).
  887. ImageFormat format,
  888. MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED,
  889. unsigned int textureFlags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
  890. unsigned int renderTargetFlags = 0 ) = 0;
  891. virtual ITexture * CreateNamedRenderTargetTexture( const char *pRTName,
  892. int w,
  893. int h,
  894. RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change).
  895. ImageFormat format,
  896. MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED,
  897. bool bClampTexCoords = true,
  898. bool bAutoMipMap = false ) = 0;
  899. // Must be called between the above Begin-End calls!
  900. virtual ITexture * CreateNamedRenderTargetTextureEx2( const char *pRTName, // Pass in NULL here for an unnamed render target.
  901. int w,
  902. int h,
  903. RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change).
  904. ImageFormat format,
  905. MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED,
  906. unsigned int textureFlags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
  907. unsigned int renderTargetFlags = 0 ) = 0;
  908. // -----------------------------------------------------------
  909. // Lightmaps
  910. // -----------------------------------------------------------
  911. // To allocate lightmaps, sort the whole world by material twice.
  912. // The first time through, call AllocateLightmap for every surface.
  913. // that has a lightmap.
  914. // The second time through, call AllocateWhiteLightmap for every
  915. // surface that expects to use shaders that expect lightmaps.
  916. virtual void BeginLightmapAllocation( ) = 0;
  917. virtual void EndLightmapAllocation( ) = 0;
  918. // To clean up lightmaps, we exposed this so we can call this function in queueloader before it loads the next map data
  919. virtual void CleanupLightmaps() = 0;
  920. // returns the sorting id for this surface
  921. virtual int AllocateLightmap( int width, int height,
  922. int offsetIntoLightmapPage[2],
  923. IMaterial *pMaterial ) = 0;
  924. // returns the sorting id for this surface
  925. virtual int AllocateWhiteLightmap( IMaterial *pMaterial ) = 0;
  926. // lightmaps are in linear color space
  927. // lightmapPageID is returned by GetLightmapPageIDForSortID
  928. // lightmapSize and offsetIntoLightmapPage are returned by AllocateLightmap.
  929. // You should never call UpdateLightmap for a lightmap allocated through
  930. // AllocateWhiteLightmap.
  931. virtual void UpdateLightmap( int lightmapPageID, int lightmapSize[2],
  932. int offsetIntoLightmapPage[2],
  933. float *pFloatImage, float *pFloatImageBump1,
  934. float *pFloatImageBump2, float *pFloatImageBump3 ) = 0;
  935. // fixme: could just be an array of ints for lightmapPageIDs since the material
  936. // for a surface is already known.
  937. virtual int GetNumSortIDs( ) = 0;
  938. virtual void GetSortInfo( MaterialSystem_SortInfo_t *sortInfoArray ) = 0;
  939. // Read the page size of an existing lightmap by sort id (returned from AllocateLightmap())
  940. virtual void GetLightmapPageSize( int lightmap, int *width, int *height ) const = 0;
  941. virtual void ResetMaterialLightmapPageInfo() = 0;
  942. // -----------------------------------------------------------
  943. // Stereo
  944. // -----------------------------------------------------------
  945. virtual bool IsStereoSupported() = 0;
  946. virtual bool IsStereoActiveThisFrame() const = 0;
  947. virtual void NVStereoUpdate() = 0;
  948. virtual void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil = false ) = 0;
  949. // -----------------------------------------------------------
  950. // X360 specifics
  951. // -----------------------------------------------------------
  952. #if defined( _X360 )
  953. virtual void ListUsedMaterials( void ) = 0;
  954. virtual HXUIFONT OpenTrueTypeFont( const char *pFontname, int tall, int style ) = 0;
  955. virtual void CloseTrueTypeFont( HXUIFONT hFont ) = 0;
  956. virtual bool GetTrueTypeFontMetrics( HXUIFONT hFont, wchar_t wchFirst, wchar_t wchLast, XUIFontMetrics *pFontMetrics, XUICharMetrics *pCharMetrics ) = 0;
  957. // Render a sequence of characters and extract the data into a buffer
  958. // For each character, provide the width+height of the font texture subrect,
  959. // an offset to apply when rendering the glyph, and an offset into a buffer to receive the RGBA data
  960. virtual bool GetTrueTypeGlyphs( HXUIFONT hFont, int numChars, wchar_t *pWch, int *pOffsetX, int *pOffsetY, int *pWidth, int *pHeight, unsigned char *pRGBA, int *pRGBAOffset ) = 0;
  961. virtual void PersistDisplay() = 0;
  962. virtual void *GetD3DDevice() = 0;
  963. virtual bool OwnGPUResources( bool bEnable ) = 0;
  964. #elif defined(_PS3)
  965. virtual void ListUsedMaterials( void ) = 0;
  966. virtual HPS3FONT OpenTrueTypeFont( const char *pFontname, int tall, int style ) = 0;
  967. virtual void CloseTrueTypeFont( HPS3FONT hFont ) = 0;
  968. virtual bool GetTrueTypeFontMetrics( HPS3FONT hFont, int nFallbackTall, wchar_t wchFirst, wchar_t wchLast, CPS3FontMetrics *pFontMetrics, CPS3CharMetrics *pCharMetrics ) = 0;
  969. // Render a sequence of characters and extract the data into a buffer
  970. // For each character, provide the width+height of the font texture subrect,
  971. // an offset to apply when rendering the glyph, and an offset into a buffer to receive the RGBA data
  972. virtual bool GetTrueTypeGlyphs( HPS3FONT hFont, int nFallbackTall, int numChars, wchar_t *pWch, int *pOffsetX, int *pOffsetY, int *pWidth, int *pHeight, unsigned char *pRGBA, int *pRGBAOffset ) = 0;
  973. // these have a default empty implementation
  974. virtual bool PS3InitFontLibrary( unsigned fontFileCacheSizeInBytes, unsigned maxNumFonts ){return false;};
  975. virtual void PS3DumpFontLibrary(){return;}
  976. virtual void *PS3GetFontLibPtr() { return NULL; }
  977. #if 0 // This is disabled for now -- apparently we render font characters ad hoc
  978. // every frame, and so for the moment we're forced to keep the font library in
  979. // memory forever. sigh.
  980. // and for some convenient stack semantics
  981. struct PS3FontLibraryRAII
  982. {
  983. PS3FontLibraryRAII( IMaterialSystem *imatsys,
  984. unsigned int fontFileCacheSizeInBytes = 256 * 1024, unsigned int maxNumFonts = 64 ) : m_pmatsys(imatsys)
  985. { imatsys->PS3InitFontLibrary( fontFileCacheSizeInBytes, maxNumFonts ); }
  986. ~PS3FontLibraryRAII()
  987. { m_pmatsys->PS3DumpFontLibrary(); }
  988. IMaterialSystem *m_pmatsys;
  989. };
  990. #endif
  991. // debug info for screenshots
  992. enum VRAMScreenShotInfoColorFormat_t
  993. { kX8R8G8B8 = 0, kX8B8G8R8 = 1, kR16G16B16X16 = 2} ;
  994. virtual void TransmitScreenshotToVX() = 0;
  995. virtual void CompactRsxLocalMemory( char const *szReason ) = 0;
  996. virtual void SetFlipPresentFrequency( int nNumVBlanks ) = 0;
  997. #endif // defined _PS3
  998. virtual void SpinPresent( uint nFrames ) = 0;
  999. // -----------------------------------------------------------
  1000. // Access the render contexts
  1001. // -----------------------------------------------------------
  1002. virtual IMatRenderContext * GetRenderContext() = 0;
  1003. virtual void BeginUpdateLightmaps( void ) = 0;
  1004. virtual void EndUpdateLightmaps( void ) = 0;
  1005. // -----------------------------------------------------------
  1006. // Methods to force the material system into non-threaded, non-queued mode
  1007. // -----------------------------------------------------------
  1008. virtual MaterialLock_t Lock() = 0;
  1009. virtual void Unlock( MaterialLock_t ) = 0;
  1010. // Create a custom render context. Cannot be used to create MATERIAL_HARDWARE_CONTEXT
  1011. virtual IMatRenderContext *CreateRenderContext( MaterialContextType_t type ) = 0;
  1012. // Set a specified render context to be the global context for the thread. Returns the prior context.
  1013. virtual IMatRenderContext *SetRenderContext( IMatRenderContext * ) = 0;
  1014. virtual bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ) = 0;
  1015. virtual void RemoveModeChangeCallBack( ModeChangeCallbackFunc_t func ) = 0;
  1016. // Finds or create a procedural material.
  1017. virtual IMaterial * FindProceduralMaterial( const char *pMaterialName, const char *pTextureGroupName, KeyValues *pVMTKeyValues = NULL ) = 0;
  1018. virtual void AddTextureAlias( const char *pAlias, const char *pRealName ) = 0;
  1019. virtual void RemoveTextureAlias( const char *pAlias ) = 0;
  1020. // returns a lightmap page ID for this allocation, -1 if none available
  1021. // frameID is a number that should be changed every frame to prevent locking any textures that are
  1022. // being used to draw in the previous frame
  1023. virtual int AllocateDynamicLightmap( int lightmapSize[2], int *pOutOffsetIntoPage, int frameID ) = 0;
  1024. virtual void SetExcludedTextures( const char *pScriptName, bool bUsingWeaponModelCache ) = 0;
  1025. virtual void UpdateExcludedTextures( void ) = 0;
  1026. virtual void ClearForceExcludes( void ) = 0;
  1027. virtual bool IsInFrame( ) const = 0;
  1028. virtual void CompactMemory() = 0;
  1029. // Get stats on GPU memory usage
  1030. virtual void GetGPUMemoryStats( GPUMemoryStats &stats ) = 0;
  1031. // For sv_pure mode. The filesystem figures out which files the client needs to reload to be "pure" ala the server's preferences.
  1032. virtual void ReloadFilesInList( IFileList *pFilesToReload ) = 0;
  1033. // Get information about the texture for texture management tools
  1034. virtual bool GetTextureInformation( char const *szTextureName, MaterialTextureInfo_t &info ) const = 0;
  1035. // call this once the render targets are allocated permanently at the beginning of the game
  1036. virtual void FinishRenderTargetAllocation( void ) = 0;
  1037. virtual void ReEnableRenderTargetAllocation_IRealizeIfICallThisAllTexturesWillBeUnloadedAndLoadTimeWillSufferHorribly( void ) = 0;
  1038. virtual bool AllowThreading( bool bAllow, int nServiceThread ) = 0;
  1039. virtual bool GetRecommendedVideoConfig( KeyValues *pKeyValues ) = 0;
  1040. virtual IClientMaterialSystem* GetClientMaterialSystemInterface() = 0;
  1041. virtual bool CanDownloadTextures() const = 0;
  1042. virtual int GetNumLightmapPages() const = 0;
  1043. virtual void RegisterPaintmapDataManager( IPaintmapDataManager *pDataManager ) = 0; //You supply an interface we can query for bits, it gives back an interface you can use to drive updates
  1044. virtual void BeginUpdatePaintmaps( void ) = 0;
  1045. virtual void EndUpdatePaintmaps( void ) = 0;
  1046. virtual void UpdatePaintmap( int paintmap, BYTE* pPaintData, int numRects, Rect_t* pRects ) = 0;
  1047. // Must be called between the BeginRenderTargetAllocation-EndRenderTargetAllocation calls!
  1048. //Creates a render target capable of having multiple, swappable, textures while using the same name
  1049. virtual ITexture * CreateNamedMultiRenderTargetTexture( const char *pRTName, // Pass in NULL here for an unnamed render target.
  1050. int w,
  1051. int h,
  1052. RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change).
  1053. ImageFormat format,
  1054. MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED,
  1055. unsigned int textureFlags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
  1056. unsigned int renderTargetFlags = 0 ) = 0;
  1057. virtual void RefreshFrontBufferNonInteractive() = 0;
  1058. virtual uint32 GetFrameTimestamps( ApplicationPerformanceCountersInfo_t &apci, ApplicationInstantCountersInfo_t & aici ) = 0;
  1059. #if defined( DX_TO_GL_ABSTRACTION ) && !defined( _GAMECONSOLE )
  1060. virtual void DoStartupShaderPreloading( void ) = 0;
  1061. #endif
  1062. // Installs a function to be called when we need to perform operation before new rendering context is started
  1063. virtual void AddEndFramePriorToNextContextFunc( EndFramePriorToNextContextFunc_t func ) = 0;
  1064. virtual void RemoveEndFramePriorToNextContextFunc( EndFramePriorToNextContextFunc_t func ) = 0;
  1065. virtual ICustomMaterialManager *GetCustomMaterialManager() = 0;
  1066. virtual ICompositeTextureGenerator *GetCompositeTextureGenerator() = 0;
  1067. };
  1068. //-----------------------------------------------------------------------------
  1069. //
  1070. //-----------------------------------------------------------------------------
  1071. abstract_class IMatRenderContext : public IRefCounted
  1072. {
  1073. public:
  1074. virtual void BeginRender() = 0;
  1075. virtual void EndRender() = 0;
  1076. virtual void Flush( bool flushHardware = false ) = 0;
  1077. virtual void BindLocalCubemap( ITexture *pTexture ) = 0;
  1078. // pass in an ITexture (that is build with "rendertarget" "1") or
  1079. // pass in NULL for the regular backbuffer.
  1080. virtual void SetRenderTarget( ITexture *pTexture ) = 0;
  1081. virtual ITexture * GetRenderTarget( void ) = 0;
  1082. virtual void GetRenderTargetDimensions( int &width, int &height) const = 0;
  1083. // Bind a material is current for rendering.
  1084. virtual void Bind( IMaterial *material, void *proxyData = 0 ) = 0;
  1085. // Bind a lightmap page current for rendering. You only have to
  1086. // do this for materials that require lightmaps.
  1087. virtual void BindLightmapPage( int lightmapPageID ) = 0;
  1088. // inputs are between 0 and 1
  1089. virtual void DepthRange( float zNear, float zFar ) = 0;
  1090. virtual void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil = false ) = 0;
  1091. // read to a unsigned char rgb image.
  1092. virtual void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat, ITexture *pRenderTargetTexture = NULL ) = 0;
  1093. virtual void ReadPixelsAsync( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat, ITexture *pRenderTargetTexture = NULL, CThreadEvent *pPixelsReadEvent = NULL ) = 0;
  1094. virtual void ReadPixelsAsyncGetResult( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat, CThreadEvent *pGetResultEvent = NULL ) = 0;
  1095. // Sets lighting
  1096. virtual void SetLightingState( const MaterialLightingState_t& state ) = 0;
  1097. virtual void SetLights( int nCount, const LightDesc_t *pLights ) = 0;
  1098. // The faces of the cube are specified in the same order as cubemap textures
  1099. virtual void SetAmbientLightCube( Vector4D cube[6] ) = 0;
  1100. // Blit the backbuffer to the framebuffer texture
  1101. virtual void CopyRenderTargetToTexture( ITexture *pTexture ) = 0;
  1102. // Set the current texture that is a copy of the framebuffer.
  1103. virtual void SetFrameBufferCopyTexture( ITexture *pTexture, int textureIndex = 0 ) = 0;
  1104. virtual ITexture *GetFrameBufferCopyTexture( int textureIndex ) = 0;
  1105. //
  1106. // end vertex array api
  1107. //
  1108. // matrix api
  1109. virtual void MatrixMode( MaterialMatrixMode_t matrixMode ) = 0;
  1110. virtual void PushMatrix( void ) = 0;
  1111. virtual void PopMatrix( void ) = 0;
  1112. virtual void LoadMatrix( VMatrix const& matrix ) = 0;
  1113. virtual void LoadMatrix( matrix3x4_t const& matrix ) = 0;
  1114. virtual void MultMatrix( VMatrix const& matrix ) = 0;
  1115. virtual void MultMatrix( matrix3x4_t const& matrix ) = 0;
  1116. virtual void MultMatrixLocal( VMatrix const& matrix ) = 0;
  1117. virtual void MultMatrixLocal( matrix3x4_t const& matrix ) = 0;
  1118. virtual void GetMatrix( MaterialMatrixMode_t matrixMode, VMatrix *matrix ) = 0;
  1119. virtual void GetMatrix( MaterialMatrixMode_t matrixMode, matrix3x4_t *matrix ) = 0;
  1120. virtual void LoadIdentity( void ) = 0;
  1121. virtual void Ortho( double left, double top, double right, double bottom, double zNear, double zFar ) = 0;
  1122. virtual void PerspectiveX( double fovx, double aspect, double zNear, double zFar ) = 0;
  1123. virtual void PickMatrix( int x, int y, int width, int height ) = 0;
  1124. virtual void Rotate( float angle, float x, float y, float z ) = 0;
  1125. virtual void Translate( float x, float y, float z ) = 0;
  1126. virtual void Scale( float x, float y, float z ) = 0;
  1127. // end matrix api
  1128. // Sets/gets the viewport
  1129. virtual void Viewport( int x, int y, int width, int height ) = 0;
  1130. virtual void GetViewport( int& x, int& y, int& width, int& height ) const = 0;
  1131. // The cull mode
  1132. virtual void CullMode( MaterialCullMode_t cullMode ) = 0;
  1133. virtual void FlipCullMode( void ) = 0; //CW->CCW or CCW->CW, intended for mirror support where the view matrix is flipped horizontally
  1134. // Shadow buffer generation
  1135. virtual void BeginGeneratingCSMs() = 0;
  1136. virtual void EndGeneratingCSMs() = 0;
  1137. virtual void PerpareForCascadeDraw( int cascade, float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) = 0;
  1138. // end matrix api
  1139. // This could easily be extended to a general user clip plane
  1140. virtual void SetHeightClipMode( MaterialHeightClipMode_t nHeightClipMode ) = 0;
  1141. // garymcthack : fog z is always used for heightclipz for now.
  1142. virtual void SetHeightClipZ( float z ) = 0;
  1143. // Fog methods...
  1144. virtual void FogMode( MaterialFogMode_t fogMode ) = 0;
  1145. virtual void FogStart( float fStart ) = 0;
  1146. virtual void FogEnd( float fEnd ) = 0;
  1147. virtual void SetFogZ( float fogZ ) = 0;
  1148. virtual MaterialFogMode_t GetFogMode( void ) = 0;
  1149. virtual void FogColor3f( float r, float g, float b ) = 0;
  1150. virtual void FogColor3fv( float const* rgb ) = 0;
  1151. virtual void FogColor3ub( unsigned char r, unsigned char g, unsigned char b ) = 0;
  1152. virtual void FogColor3ubv( unsigned char const* rgb ) = 0;
  1153. virtual void GetFogColor( unsigned char *rgb ) = 0;
  1154. // Sets the number of bones for skinning
  1155. virtual void SetNumBoneWeights( int numBones ) = 0;
  1156. // Creates/destroys Mesh
  1157. virtual IMesh* CreateStaticMesh( VertexFormat_t fmt, const char *pTextureBudgetGroup, IMaterial * pMaterial = NULL, VertexStreamSpec_t *pStreamSpec = NULL ) = 0;
  1158. virtual void DestroyStaticMesh( IMesh* mesh ) = 0;
  1159. // Gets the dynamic mesh associated with the currently bound material
  1160. // note that you've got to render the mesh before calling this function
  1161. // a second time. Clients should *not* call DestroyStaticMesh on the mesh
  1162. // returned by this call.
  1163. // Use buffered = false if you want to not have the mesh be buffered,
  1164. // but use it instead in the following pattern:
  1165. // meshBuilder.Begin
  1166. // meshBuilder.End
  1167. // Draw partial
  1168. // Draw partial
  1169. // Draw partial
  1170. // meshBuilder.Begin
  1171. // meshBuilder.End
  1172. // etc
  1173. // Use Vertex or Index Override to supply a static vertex or index buffer
  1174. // to use in place of the dynamic buffers.
  1175. //
  1176. // If you pass in a material in pAutoBind, it will automatically bind the
  1177. // material. This can be helpful since you must bind the material you're
  1178. // going to use BEFORE calling GetDynamicMesh.
  1179. virtual IMesh* GetDynamicMesh(
  1180. bool buffered = true,
  1181. IMesh* pVertexOverride = 0,
  1182. IMesh* pIndexOverride = 0,
  1183. IMaterial *pAutoBind = 0 ) = 0;
  1184. // ------------ New Vertex/Index Buffer interface ----------------------------
  1185. // Do we need support for bForceTempMesh and bSoftwareVertexShader?
  1186. // I don't think we use bSoftwareVertexShader anymore. .need to look into bForceTempMesh.
  1187. virtual IVertexBuffer *CreateStaticVertexBuffer( VertexFormat_t fmt, int nVertexCount, const char *pTextureBudgetGroup ) = 0;
  1188. virtual IIndexBuffer *CreateStaticIndexBuffer( MaterialIndexFormat_t fmt, int nIndexCount, const char *pTextureBudgetGroup ) = 0;
  1189. virtual void DestroyVertexBuffer( IVertexBuffer * ) = 0;
  1190. virtual void DestroyIndexBuffer( IIndexBuffer * ) = 0;
  1191. // Do we need to specify the stream here in the case of locking multiple dynamic VBs on different streams?
  1192. virtual IVertexBuffer *GetDynamicVertexBuffer( int streamID, VertexFormat_t vertexFormat, bool bBuffered = true ) = 0;
  1193. virtual IIndexBuffer *GetDynamicIndexBuffer() = 0;
  1194. virtual void BindVertexBuffer( int streamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 ) = 0;
  1195. virtual void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes ) = 0;
  1196. virtual void Draw( MaterialPrimitiveType_t primitiveType, int firstIndex, int numIndices ) = 0;
  1197. // ------------ End ----------------------------
  1198. // Selection mode methods
  1199. virtual int SelectionMode( bool selectionMode ) = 0;
  1200. virtual void SelectionBuffer( unsigned int* pBuffer, int size ) = 0;
  1201. virtual void ClearSelectionNames( ) = 0;
  1202. virtual void LoadSelectionName( int name ) = 0;
  1203. virtual void PushSelectionName( int name ) = 0;
  1204. virtual void PopSelectionName() = 0;
  1205. // Sets the Clear Color for ClearBuffer....
  1206. virtual void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b ) = 0;
  1207. virtual void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ) = 0;
  1208. // Allows us to override the depth buffer setting of a material
  1209. virtual void OverrideDepthEnable( bool bEnable, bool bDepthWriteEnable, bool bDepthTestEnable = true ) = 0;
  1210. // FIXME: This is a hack required for NVidia/XBox, can they fix in drivers?
  1211. virtual void DrawScreenSpaceQuad( IMaterial* pMaterial ) = 0;
  1212. // For debugging and building recording files. This will stuff a token into the recording file,
  1213. // then someone doing a playback can watch for the token.
  1214. virtual void SyncToken( const char *pToken ) = 0;
  1215. // FIXME: REMOVE THIS FUNCTION!
  1216. // The only reason why it's not gone is because we're a week from ship when I found the bug in it
  1217. // and everything's tuned to use it.
  1218. // It's returning values which are 2x too big (it's returning sphere diameter x2)
  1219. // Use ComputePixelDiameterOfSphere below in all new code instead.
  1220. virtual float ComputePixelWidthOfSphere( const Vector& origin, float flRadius ) = 0;
  1221. //
  1222. // Occlusion query support
  1223. //
  1224. // Allocate and delete query objects.
  1225. virtual OcclusionQueryObjectHandle_t CreateOcclusionQueryObject( void ) = 0;
  1226. virtual void DestroyOcclusionQueryObject( OcclusionQueryObjectHandle_t ) = 0;
  1227. // Bracket drawing with begin and end so that we can get counts next frame.
  1228. virtual void BeginOcclusionQueryDrawing( OcclusionQueryObjectHandle_t ) = 0;
  1229. virtual void EndOcclusionQueryDrawing( OcclusionQueryObjectHandle_t ) = 0;
  1230. // Get the number of pixels rendered between begin and end on an earlier frame.
  1231. // Calling this in the same frame is a huge perf hit!
  1232. virtual int OcclusionQuery_GetNumPixelsRendered( OcclusionQueryObjectHandle_t ) = 0;
  1233. virtual void SetFlashlightMode( bool bEnable ) = 0;
  1234. virtual void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture ) = 0;
  1235. virtual bool IsCascadedShadowMapping() const = 0;
  1236. virtual void SetCascadedShadowMapping( bool bEnable ) = 0;
  1237. virtual void SetCascadedShadowMappingState( const CascadedShadowMappingState_t &state, ITexture *pDepthTextureAtlas ) = 0;
  1238. // Gets the current height clip mode
  1239. virtual MaterialHeightClipMode_t GetHeightClipMode( ) = 0;
  1240. // This returns the diameter of the sphere in pixels based on
  1241. // the current model, view, + projection matrices and viewport.
  1242. virtual float ComputePixelDiameterOfSphere( const Vector& vecAbsOrigin, float flRadius ) = 0;
  1243. // By default, the material system applies the VIEW and PROJECTION matrices to the user clip
  1244. // planes (which are specified in world space) to generate projection-space user clip planes
  1245. // Occasionally (for the particle system in hl2, for example), we want to override that
  1246. // behavior and explictly specify a ViewProj transform for user clip planes
  1247. virtual void EnableUserClipTransformOverride( bool bEnable ) = 0;
  1248. virtual void UserClipTransform( const VMatrix &worldToView ) = 0;
  1249. virtual bool GetFlashlightMode() const = 0;
  1250. virtual bool IsCullingEnabledForSinglePassFlashlight() const = 0;
  1251. virtual void EnableCullingForSinglePassFlashlight( bool bEnable ) = 0;
  1252. // Used to make the handle think it's never had a successful query before
  1253. virtual void ResetOcclusionQueryObject( OcclusionQueryObjectHandle_t ) = 0;
  1254. // Creates/destroys morph data associated w/ a particular material
  1255. virtual IMorph *CreateMorph( MorphFormat_t format, const char *pDebugName ) = 0;
  1256. virtual void DestroyMorph( IMorph *pMorph ) = 0;
  1257. // Binds the morph data for use in rendering
  1258. virtual void BindMorph( IMorph *pMorph ) = 0;
  1259. // Sets flexweights for rendering
  1260. virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights ) = 0;
  1261. // Allocates temp render data. Renderdata goes out of scope at frame end in multicore
  1262. // Renderdata goes out of scope after refcount goes to zero in singlecore.
  1263. // Locking/unlocking increases + decreases refcount
  1264. virtual void * LockRenderData( int nSizeInBytes ) = 0;
  1265. virtual void UnlockRenderData( void *pData ) = 0;
  1266. // Typed version. If specified, pSrcData is copied into the locked memory.
  1267. template< class E > E* LockRenderDataTyped( int nCount, const E* pSrcData = NULL );
  1268. // Temp render data gets immediately freed after it's all unlocked in single core.
  1269. // This prevents it from being freed
  1270. virtual void AddRefRenderData() = 0;
  1271. virtual void ReleaseRenderData() = 0;
  1272. // Returns whether a pointer is render data. NOTE: passing NULL returns true
  1273. virtual bool IsRenderData( const void *pData ) const = 0;
  1274. // Read w/ stretch to a host-memory buffer
  1275. virtual void ReadPixelsAndStretch( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *pBuffer, ImageFormat dstFormat, int nDstStride ) = 0;
  1276. // Gets the window size
  1277. virtual void GetWindowSize( int &width, int &height ) const = 0;
  1278. // This function performs a texture map from one texture map to the render destination, doing
  1279. // all the necessary pixel/texel coordinate fix ups. fractional values can be used for the
  1280. // src_texture coordinates to get linear sampling - integer values should produce 1:1 mappings
  1281. // for non-scaled operations.
  1282. virtual void DrawScreenSpaceRectangle(
  1283. IMaterial *pMaterial,
  1284. int destx, int desty,
  1285. int width, int height,
  1286. float src_texture_x0, float src_texture_y0, // which texel you want to appear at
  1287. // destx/y
  1288. float src_texture_x1, float src_texture_y1, // which texel you want to appear at
  1289. // destx+width-1, desty+height-1
  1290. int src_texture_width, int src_texture_height, // needed for fixup
  1291. void *pClientRenderable = NULL,
  1292. int nXDice = 1,
  1293. int nYDice = 1 )=0;
  1294. virtual void LoadBoneMatrix( int boneIndex, const matrix3x4_t& matrix ) = 0;
  1295. // This version will push the current rendertarget + current viewport onto the stack
  1296. virtual void PushRenderTargetAndViewport( ) = 0;
  1297. // This version will push a new rendertarget + a maximal viewport for that rendertarget onto the stack
  1298. virtual void PushRenderTargetAndViewport( ITexture *pTexture ) = 0;
  1299. // This version will push a new rendertarget + a specified viewport onto the stack
  1300. virtual void PushRenderTargetAndViewport( ITexture *pTexture, int nViewX, int nViewY, int nViewW, int nViewH ) = 0;
  1301. // This version will push a new rendertarget + a specified viewport onto the stack
  1302. virtual void PushRenderTargetAndViewport( ITexture *pTexture, ITexture *pDepthTexture, int nViewX, int nViewY, int nViewW, int nViewH ) = 0;
  1303. // This will pop a rendertarget + viewport
  1304. virtual void PopRenderTargetAndViewport( void ) = 0;
  1305. // Binds a particular texture as the current lightmap
  1306. virtual void BindLightmapTexture( ITexture *pLightmapTexture ) = 0;
  1307. // Blit a subrect of the current render target to another texture
  1308. virtual void CopyRenderTargetToTextureEx( ITexture *pTexture, int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect = NULL ) = 0;
  1309. virtual void CopyTextureToRenderTargetEx( int nRenderTargetID, ITexture *pTexture, Rect_t *pSrcRect, Rect_t *pDstRect = NULL ) = 0;
  1310. // Special off-center perspective matrix for DoF, MSAA jitter and poster rendering
  1311. virtual void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right ) = 0;
  1312. // Rendering parameters control special drawing modes withing the material system, shader
  1313. // system, shaders, and engine. renderparm.h has their definitions.
  1314. virtual void SetFloatRenderingParameter(int parm_number, float value) = 0;
  1315. virtual void SetIntRenderingParameter(int parm_number, int value) = 0;
  1316. virtual void SetVectorRenderingParameter(int parm_number, Vector const &value) = 0;
  1317. // stencil buffer operations.
  1318. virtual void SetStencilState( const ShaderStencilState_t &state ) = 0;
  1319. virtual void ClearStencilBufferRectangle(int xmin, int ymin, int xmax, int ymax,int value) =0;
  1320. virtual void SetRenderTargetEx( int nRenderTargetID, ITexture *pTexture ) = 0;
  1321. // rendering clip planes, beware that only the most recently pushed plane will actually be used in a sizeable chunk of hardware configurations
  1322. // and that changes to the clip planes mid-frame while UsingFastClipping() is true will result unresolvable depth inconsistencies
  1323. virtual void PushCustomClipPlane( const float *pPlane ) = 0;
  1324. virtual void PopCustomClipPlane( void ) = 0;
  1325. // Returns the number of vertices + indices we can render using the dynamic mesh
  1326. // Passing true in the second parameter will return the max # of vertices + indices
  1327. // we can use before a flush is provoked and may return different values
  1328. // if called multiple times in succession.
  1329. // Passing false into the second parameter will return
  1330. // the maximum possible vertices + indices that can be rendered in a single batch
  1331. virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices ) = 0;
  1332. // Returns the max possible vertices + indices to render in a single draw call
  1333. virtual int GetMaxVerticesToRender( IMaterial *pMaterial ) = 0;
  1334. virtual int GetMaxIndicesToRender( ) = 0;
  1335. virtual void DisableAllLocalLights() = 0;
  1336. virtual int CompareMaterialCombos( IMaterial *pMaterial1, IMaterial *pMaterial2, int lightMapID1, int lightMapID2 ) = 0;
  1337. virtual IMesh *GetFlexMesh() = 0;
  1338. virtual void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture ) = 0;
  1339. // Returns the currently bound local cubemap
  1340. virtual ITexture *GetLocalCubemap( ) = 0;
  1341. // This is a version of clear buffers which will only clear the buffer at pixels which pass the stencil test
  1342. virtual void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth ) = 0;
  1343. //enables/disables all entered clipping planes, returns the input from the last time it was called.
  1344. virtual bool EnableClipping( bool bEnable ) = 0;
  1345. //get fog distances entered with FogStart(), FogEnd(), and SetFogZ()
  1346. virtual void GetFogDistances( float *fStart, float *fEnd, float *fFogZ ) = 0;
  1347. // Hooks for firing PIX events from outside the Material System...
  1348. virtual void BeginPIXEvent( unsigned long color, const char *szName ) = 0;
  1349. virtual void EndPIXEvent() = 0;
  1350. virtual void SetPIXMarker( unsigned long color, const char *szName ) = 0;
  1351. // Batch API
  1352. // from changelist 166623:
  1353. // - replaced obtuse material system batch usage with an explicit and easier to thread API
  1354. virtual void BeginBatch( IMesh* pIndices ) = 0;
  1355. virtual void BindBatch( IMesh* pVertices, IMaterial *pAutoBind = NULL ) = 0;
  1356. virtual void DrawBatch( MaterialPrimitiveType_t primType, int firstIndex, int numIndices ) = 0;
  1357. virtual void EndBatch() = 0;
  1358. // Raw access to the call queue, which can be NULL if not in a queued mode
  1359. virtual ICallQueue *GetCallQueue() = 0;
  1360. // Returns the world-space camera position
  1361. virtual void GetWorldSpaceCameraPosition( Vector *pCameraPos ) = 0;
  1362. virtual void GetWorldSpaceCameraVectors( Vector *pVecForward, Vector *pVecRight, Vector *pVecUp ) = 0;
  1363. // Set a linear vector color scale for all 3D rendering.
  1364. // A value of [1.0f, 1.0f, 1.0f] should match non-tone-mapped rendering.
  1365. virtual void SetToneMappingScaleLinear( const Vector &scale ) = 0;
  1366. virtual Vector GetToneMappingScaleLinear( void ) = 0;
  1367. virtual void SetShadowDepthBiasFactors( float fSlopeScaleDepthBias, float fDepthBias ) = 0;
  1368. // Apply stencil operations to every pixel on the screen without disturbing depth or color buffers
  1369. virtual void PerformFullScreenStencilOperation( void ) = 0;
  1370. // Sets lighting origin for the current model (needed to convert directional lights to points)
  1371. virtual void SetLightingOrigin( Vector vLightingOrigin ) = 0;
  1372. // Set scissor rect for rendering
  1373. virtual void PushScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom ) = 0;
  1374. virtual void PopScissorRect() = 0;
  1375. // Methods used to build the morph accumulator that is read from when HW morphing is enabled.
  1376. virtual void BeginMorphAccumulation() = 0;
  1377. virtual void EndMorphAccumulation() = 0;
  1378. virtual void AccumulateMorph( IMorph* pMorph, int nMorphCount, const MorphWeight_t* pWeights ) = 0;
  1379. virtual void PushDeformation( DeformationBase_t const *Deformation ) = 0;
  1380. virtual void PopDeformation( ) = 0;
  1381. virtual int GetNumActiveDeformations() const = 0;
  1382. virtual bool GetMorphAccumulatorTexCoord( Vector2D *pTexCoord, IMorph *pMorph, int nVertex ) = 0;
  1383. // Version of get dynamic mesh that specifies a specific vertex format
  1384. virtual IMesh* GetDynamicMeshEx( VertexFormat_t vertexFormat, bool bBuffered = true,
  1385. IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0, IMaterial *pAutoBind = 0 ) = 0;
  1386. virtual void FogMaxDensity( float flMaxDensity ) = 0;
  1387. #if defined( _X360 )
  1388. //Seems best to expose GPR allocation to scene rendering code. 128 total to split between vertex/pixel shaders (pixel will be set to 128 - vertex). Minimum value of 16. More GPR's = more threads.
  1389. virtual void PushVertexShaderGPRAllocation( int iVertexShaderCount = 64 ) = 0;
  1390. virtual void PopVertexShaderGPRAllocation( void ) = 0;
  1391. virtual void FlushHiStencil() = 0;
  1392. #endif
  1393. #if defined( _GAMECONSOLE )
  1394. virtual void BeginConsoleZPass( const WorldListIndicesInfo_t &indicesInfo ) = 0;
  1395. virtual void BeginConsoleZPass2( int nSlack ) = 0;
  1396. virtual void EndConsoleZPass() = 0;
  1397. #endif
  1398. #if defined( _PS3 )
  1399. virtual void FlushTextureCache() = 0;
  1400. #endif
  1401. virtual void AntiAliasingHint( int nHint ) = 0;
  1402. virtual IMaterial *GetCurrentMaterial() = 0;
  1403. virtual int GetCurrentNumBones() const = 0;
  1404. virtual void *GetCurrentProxy() = 0;
  1405. // Color correction related methods..
  1406. // Client cannot call IColorCorrectionSystem directly because it is not thread-safe
  1407. // FIXME: Make IColorCorrectionSystem threadsafe?
  1408. virtual void EnableColorCorrection( bool bEnable ) = 0;
  1409. virtual ColorCorrectionHandle_t AddLookup( const char *pName ) = 0;
  1410. virtual bool RemoveLookup( ColorCorrectionHandle_t handle ) = 0;
  1411. virtual void LockLookup( ColorCorrectionHandle_t handle ) = 0;
  1412. virtual void LoadLookup( ColorCorrectionHandle_t handle, const char *pLookupName ) = 0;
  1413. virtual void UnlockLookup( ColorCorrectionHandle_t handle ) = 0;
  1414. virtual void SetLookupWeight( ColorCorrectionHandle_t handle, float flWeight ) = 0;
  1415. virtual void ResetLookupWeights( ) = 0;
  1416. virtual void SetResetable( ColorCorrectionHandle_t handle, bool bResetable ) = 0;
  1417. //There are some cases where it's simply not reasonable to update the full screen depth texture (mostly on PC).
  1418. //Use this to mark it as invalid and use a dummy texture for depth reads.
  1419. virtual void SetFullScreenDepthTextureValidityFlag( bool bIsValid ) = 0;
  1420. // A special path used to tick the front buffer while loading on the 360
  1421. virtual void SetNonInteractiveLogoTexture( ITexture *pTexture, float flNormalizedX, float flNormalizedY, float flNormalizedW, float flNormalizedH ) = 0;
  1422. virtual void SetNonInteractivePacifierTexture( ITexture *pTexture, float flNormalizedX, float flNormalizedY, float flNormalizedSize ) = 0;
  1423. virtual void SetNonInteractiveTempFullscreenBuffer( ITexture *pTexture, MaterialNonInteractiveMode_t mode ) = 0;
  1424. virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode ) = 0;
  1425. virtual void RefreshFrontBufferNonInteractive() = 0;
  1426. // Flip culling state (swap CCW <-> CW)
  1427. virtual void FlipCulling( bool bFlipCulling ) = 0;
  1428. virtual void SetTextureRenderingParameter(int parm_number, ITexture *pTexture) = 0;
  1429. //only actually sets a bool that can be read in from shaders, doesn't do any of the legwork
  1430. virtual void EnableSinglePassFlashlightMode( bool bEnable ) = 0;
  1431. // Are we in Single Pass Flashlight Mode?
  1432. virtual bool SinglePassFlashlightModeEnabled() const = 0;
  1433. // Draws instances with different meshes
  1434. virtual void DrawInstances( int nInstanceCount, const MeshInstanceData_t *pInstance ) = 0;
  1435. // Allows us to override the color/alpha write settings of a material
  1436. virtual void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable ) = 0;
  1437. virtual void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable ) = 0;
  1438. virtual void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth ) = 0;
  1439. // Subdivision surface interface
  1440. virtual int GetSubDBufferWidth() = 0;
  1441. virtual float* LockSubDBuffer( int nNumRows ) = 0;
  1442. virtual void UnlockSubDBuffer() = 0;
  1443. // Update current frame's game time for the shader api.
  1444. virtual void UpdateGameTime( float flTime ) = 0;
  1445. virtual void PrintfVA( char *fmt, va_list vargs ) = 0;
  1446. virtual void Printf( char *fmt, ... ) = 0;
  1447. virtual float Knob( char *knobname, float *setvalue = NULL ) = 0;
  1448. // expose scaleform functons
  1449. #if defined( INCLUDE_SCALEFORM )
  1450. virtual void SetScaleformSlotViewport( int slot, int x, int y, int w, int h ) = 0;
  1451. virtual void RenderScaleformSlot( int slot ) = 0;
  1452. virtual void ForkRenderScaleformSlot( int slot ) = 0;
  1453. virtual void JoinRenderScaleformSlot( int slot ) = 0;
  1454. virtual void SetScaleformCursorViewport( int x, int y, int w, int h ) = 0;
  1455. virtual void RenderScaleformCursor() = 0;
  1456. virtual void AdvanceAndRenderScaleformSlot( int slot ) = 0;
  1457. virtual void AdvanceAndRenderScaleformCursor() = 0;
  1458. #endif
  1459. virtual void SetRenderingPaint( bool bEnable ) = 0;
  1460. // Draws batches of different materials using a faster API
  1461. //virtual void DrawBatchedMaterials( int nBatchCount, const MaterialBatchData_t *pBatches ) = 0;
  1462. virtual ColorCorrectionHandle_t FindLookup( const char *pName ) = 0;
  1463. };
  1464. template< class E > inline E* IMatRenderContext::LockRenderDataTyped( int nCount, const E* pSrcData )
  1465. {
  1466. int nSizeInBytes = nCount * sizeof(E);
  1467. E *pDstData = (E*)LockRenderData( nSizeInBytes );
  1468. if ( pSrcData && pDstData )
  1469. {
  1470. memcpy( pDstData, pSrcData, nSizeInBytes );
  1471. }
  1472. return pDstData;
  1473. }
  1474. //-----------------------------------------------------------------------------
  1475. // Purpose: Interface exposed from client back to materialsystem, currently just for recording into tools
  1476. //-----------------------------------------------------------------------------
  1477. abstract_class IClientMaterialSystem
  1478. {
  1479. public:
  1480. virtual unsigned int GetCurrentRecordingEntity() = 0;
  1481. virtual void PostToolMessage( unsigned int hEntity, KeyValues *pMsg ) = 0;
  1482. virtual void SetMaterialProxyData( void *pProxyData ) = 0;
  1483. };
  1484. #define VCLIENTMATERIALSYSTEM_INTERFACE_VERSION "VCLIENTMATERIALSYSTEM001"
  1485. //-----------------------------------------------------------------------------
  1486. // Utility class for addreffing/releasing render data (prevents freeing on single core)
  1487. //-----------------------------------------------------------------------------
  1488. class CMatRenderDataReference
  1489. {
  1490. public:
  1491. CMatRenderDataReference();
  1492. CMatRenderDataReference( IMatRenderContext* pRenderContext );
  1493. ~CMatRenderDataReference();
  1494. void Lock( IMatRenderContext *pRenderContext );
  1495. void Release();
  1496. private:
  1497. IMatRenderContext *m_pRenderContext;
  1498. };
  1499. inline CMatRenderDataReference::CMatRenderDataReference()
  1500. {
  1501. m_pRenderContext = NULL;
  1502. }
  1503. inline CMatRenderDataReference::CMatRenderDataReference( IMatRenderContext* pRenderContext )
  1504. {
  1505. m_pRenderContext = NULL;
  1506. Lock( pRenderContext );
  1507. }
  1508. inline CMatRenderDataReference::~CMatRenderDataReference()
  1509. {
  1510. Release();
  1511. }
  1512. inline void CMatRenderDataReference::Lock( IMatRenderContext* pRenderContext )
  1513. {
  1514. if ( !m_pRenderContext )
  1515. {
  1516. m_pRenderContext = pRenderContext;
  1517. m_pRenderContext->AddRefRenderData( );
  1518. }
  1519. }
  1520. inline void CMatRenderDataReference::Release()
  1521. {
  1522. if ( m_pRenderContext )
  1523. {
  1524. m_pRenderContext->ReleaseRenderData( );
  1525. m_pRenderContext = NULL;
  1526. }
  1527. }
  1528. //-----------------------------------------------------------------------------
  1529. // Utility class for locking/unlocking render data
  1530. //-----------------------------------------------------------------------------
  1531. template< typename E >
  1532. class CMatRenderData
  1533. {
  1534. public:
  1535. CMatRenderData( IMatRenderContext* pRenderContext );
  1536. CMatRenderData( IMatRenderContext* pRenderContext, int nCount, const E *pSrcData = NULL );
  1537. ~CMatRenderData();
  1538. E* Lock( int nCount, const E* pSrcData = NULL );
  1539. void Release();
  1540. bool IsValid() const;
  1541. const E* Base() const;
  1542. E* Base();
  1543. const E& operator[]( int i ) const;
  1544. E& operator[]( int i );
  1545. private:
  1546. IMatRenderContext* m_pRenderContext;
  1547. E *m_pRenderData;
  1548. int m_nCount;
  1549. bool m_bNeedsUnlock;
  1550. };
  1551. template< typename E >
  1552. inline CMatRenderData<E>::CMatRenderData( IMatRenderContext* pRenderContext )
  1553. {
  1554. m_pRenderContext = pRenderContext;
  1555. m_nCount = 0;
  1556. m_pRenderData = 0;
  1557. m_bNeedsUnlock = false;
  1558. }
  1559. template< typename E >
  1560. inline CMatRenderData<E>::CMatRenderData( IMatRenderContext* pRenderContext, int nCount, const E* pSrcData )
  1561. {
  1562. m_pRenderContext = pRenderContext;
  1563. m_nCount = 0;
  1564. m_pRenderData = 0;
  1565. m_bNeedsUnlock = false;
  1566. Lock( nCount, pSrcData );
  1567. }
  1568. template< typename E >
  1569. inline CMatRenderData<E>::~CMatRenderData()
  1570. {
  1571. Release();
  1572. }
  1573. template< typename E >
  1574. inline bool CMatRenderData<E>::IsValid() const
  1575. {
  1576. return m_pRenderData != NULL;
  1577. }
  1578. template< typename E >
  1579. inline E* CMatRenderData<E>::Lock( int nCount, const E* pSrcData )
  1580. {
  1581. m_nCount = nCount;
  1582. if ( pSrcData && m_pRenderContext->IsRenderData( pSrcData ) )
  1583. {
  1584. // Yes, we're const-casting away, but that should be ok since
  1585. // the src data is render data
  1586. m_pRenderData = const_cast<E*>( pSrcData );
  1587. m_pRenderContext->AddRefRenderData();
  1588. m_bNeedsUnlock = false;
  1589. return m_pRenderData;
  1590. }
  1591. m_pRenderData = m_pRenderContext->LockRenderDataTyped<E>( nCount, pSrcData );
  1592. m_bNeedsUnlock = true;
  1593. return m_pRenderData;
  1594. }
  1595. template< typename E >
  1596. inline void CMatRenderData<E>::Release()
  1597. {
  1598. if ( m_pRenderContext && m_pRenderData )
  1599. {
  1600. if ( m_bNeedsUnlock )
  1601. {
  1602. m_pRenderContext->UnlockRenderData( m_pRenderData );
  1603. }
  1604. else
  1605. {
  1606. m_pRenderContext->ReleaseRenderData();
  1607. }
  1608. }
  1609. m_pRenderData = NULL;
  1610. m_nCount = 0;
  1611. m_bNeedsUnlock = false;
  1612. }
  1613. template< typename E >
  1614. inline E* CMatRenderData<E>::Base()
  1615. {
  1616. return m_pRenderData;
  1617. }
  1618. template< typename E >
  1619. inline const E* CMatRenderData<E>::Base() const
  1620. {
  1621. return m_pRenderData;
  1622. }
  1623. template< typename E >
  1624. inline E& CMatRenderData<E>::operator[]( int i )
  1625. {
  1626. Assert( ( i >= 0 ) && ( i < m_nCount ) );
  1627. return m_pRenderData[i];
  1628. }
  1629. template< typename E >
  1630. inline const E& CMatRenderData<E>::operator[]( int i ) const
  1631. {
  1632. Assert( ( i >= 0 ) && ( i < m_nCount ) );
  1633. return m_pRenderData[i];
  1634. }
  1635. //-----------------------------------------------------------------------------
  1636. class CMatRenderContextPtr : public CRefPtr<IMatRenderContext>
  1637. {
  1638. typedef CRefPtr<IMatRenderContext> BaseClass;
  1639. public:
  1640. CMatRenderContextPtr() {}
  1641. CMatRenderContextPtr( IMatRenderContext *pInit ) : BaseClass( pInit ) { if ( BaseClass::m_pObject ) BaseClass::m_pObject->BeginRender(); }
  1642. CMatRenderContextPtr( IMaterialSystem *pFrom ) : BaseClass( pFrom->GetRenderContext() ) { if ( BaseClass::m_pObject ) BaseClass::m_pObject->BeginRender(); }
  1643. ~CMatRenderContextPtr() { if ( BaseClass::m_pObject ) BaseClass::m_pObject->EndRender(); }
  1644. IMatRenderContext *operator=( IMatRenderContext *p ) { if ( p ) p->BeginRender(); return BaseClass::operator=( p ); }
  1645. void SafeRelease() { if ( BaseClass::m_pObject ) BaseClass::m_pObject->EndRender(); BaseClass::SafeRelease(); }
  1646. void AssignAddRef( IMatRenderContext *pFrom ) { if ( BaseClass::m_pObject ) BaseClass::m_pObject->EndRender(); BaseClass::AssignAddRef( pFrom ); BaseClass::m_pObject->BeginRender(); }
  1647. void GetFrom( IMaterialSystem *pFrom ) { AssignAddRef( pFrom->GetRenderContext() ); }
  1648. private:
  1649. CMatRenderContextPtr( const CMatRenderContextPtr &from );
  1650. void operator=( const CMatRenderContextPtr &from );
  1651. };
  1652. //-----------------------------------------------------------------------------
  1653. // Helper class for begin/end of pix event via constructor/destructor
  1654. //-----------------------------------------------------------------------------
  1655. #define PIX_VALVE_ORANGE 0xFFF5940F
  1656. class PIXEvent
  1657. {
  1658. public:
  1659. PIXEvent( IMatRenderContext *pRenderContext, const char *szName, unsigned long color = PIX_VALVE_ORANGE )
  1660. {
  1661. m_pRenderContext = pRenderContext;
  1662. Assert( m_pRenderContext );
  1663. Assert( szName );
  1664. m_pRenderContext->BeginPIXEvent( color, szName );
  1665. }
  1666. ~PIXEvent()
  1667. {
  1668. m_pRenderContext->EndPIXEvent();
  1669. }
  1670. private:
  1671. IMatRenderContext *m_pRenderContext;
  1672. };
  1673. // [mhansen] Enable PIX only in debug and profile builds for Xbox 360
  1674. #if ( defined( _X360 ) && ( defined( PROFILE ) || defined( _DEBUG ) ) )
  1675. #define PIX_ENABLE 1 // set this to 1 and build engine/studiorender to enable pix events in the engine
  1676. #else
  1677. #define PIX_ENABLE 0
  1678. #endif
  1679. #if PIX_ENABLE
  1680. # define PIXEVENT PIXEvent _pixEvent
  1681. #else
  1682. # define PIXEVENT
  1683. #endif
  1684. //-----------------------------------------------------------------------------
  1685. #ifdef MATERIAL_SYSTEM_DEBUG_CALL_QUEUE
  1686. #include "tier1/callqueue.h"
  1687. #include "tier1/fmtstr.h"
  1688. static void DoMatSysQueueMark( IMaterialSystem *pMaterialSystem, const char *psz )
  1689. {
  1690. CMatRenderContextPtr pRenderContext( pMaterialSystem );
  1691. if ( pRenderContext->GetCallQueue() )
  1692. pRenderContext->GetCallQueue()->QueueCall( Plat_DebugString, CUtlEnvelope<const char *>( psz ) );
  1693. }
  1694. #define MatSysQueueMark( pMaterialSystem, ...) DoMatSysQueueMark( pMaterialSystem, CFmtStr( __VA_ARGS__ ) )
  1695. #else
  1696. #define MatSysQueueMark( msg, ...) ((void)0)
  1697. #endif
  1698. #ifdef _GAMECONSOLE
  1699. #define MS_NO_DYNAMIC_BUFFER_COPY 1
  1700. #endif
  1701. //-----------------------------------------------------------------------------
  1702. DECLARE_TIER2_INTERFACE( IMaterialSystem, materials );
  1703. DECLARE_TIER2_INTERFACE( IMaterialSystem, g_pMaterialSystem );
  1704. #endif // IMATERIALSYSTEM_H