1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 03:56:10 +08:00

First version of the SOurce SDK 2013

This commit is contained in:
Joe Ludwig
2013-06-26 15:22:04 -07:00
commit e7d6f4c174
3682 changed files with 1624327 additions and 0 deletions

View File

@ -0,0 +1,73 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#ifndef ICOLORCORRECTION_H
#define ICOLORCORRECTION_H
#ifdef _WIN32
#pragma once
#endif
#include "tier1/interface.h"
#include "bitmap/imageformat.h"
typedef unsigned int ColorCorrectionHandle_t;
struct ShaderColorCorrectionInfo_t;
#define COLORCORRECTION_INTERFACE_VERSION "COLORCORRECTION_VERSION_1"
abstract_class IColorCorrectionSystem
{
public:
virtual void Init() = 0;
virtual void Shutdown() = 0;
virtual ColorCorrectionHandle_t AddLookup( const char *pName ) = 0;
virtual bool RemoveLookup( ColorCorrectionHandle_t handle ) = 0;
virtual void SetLookupWeight( ColorCorrectionHandle_t handle, float flWeight ) = 0;
virtual float GetLookupWeight( ColorCorrectionHandle_t handle ) = 0;
virtual float GetLookupWeight( int i ) = 0;
virtual void LockLookup() = 0;
virtual void LockLookup( ColorCorrectionHandle_t handle ) = 0;
virtual void UnlockLookup() = 0;
virtual void UnlockLookup( ColorCorrectionHandle_t handle ) = 0;
virtual void SetLookup( RGBX5551_t inColor, color24 outColor ) = 0;
virtual void SetLookup( ColorCorrectionHandle_t handle, RGBX5551_t inColor, color24 outColor ) = 0;
virtual color24 GetLookup( RGBX5551_t inColor ) = 0;
virtual color24 GetLookup( ColorCorrectionHandle_t handle, RGBX5551_t inColor ) = 0;
virtual void LoadLookup( const char *pLookupName ) = 0;
virtual void LoadLookup( ColorCorrectionHandle_t handle, const char *pLookupName ) = 0;
virtual void CopyLookup( const color24 *pSrcColorCorrection ) = 0;
virtual void CopyLookup( ColorCorrectionHandle_t handle, const color24 *pSrcColorCorrection ) = 0;
virtual void ResetLookup( ColorCorrectionHandle_t handle ) = 0;
virtual void ResetLookup( ) = 0;
virtual void ReleaseTextures( ) = 0;
virtual void RestoreTextures( ) = 0;
virtual void ResetLookupWeights( ) = 0;
virtual int GetNumLookups( ) = 0;
virtual color24 ConvertToColor24( RGBX5551_t inColor ) = 0;
virtual void SetResetable( ColorCorrectionHandle_t handle, bool bResetable ) = 0;
virtual void EnableColorCorrection( bool bEnable ) = 0;
// FIXME: Move this to a private interface only the material system can see?
virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo ) = 0;
};
#endif

View File

@ -0,0 +1,205 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#ifndef ISHADER_H
#define ISHADER_H
#ifdef _WIN32
#pragma once
#endif
//==================================================================================================
// **this goes into both platforms which run the translator, either the real Mac client or
// the Windows client running with r_emulategl mode **
//
// size of the VS register bank in ARB / GLSL we expose
// it's not 256, because you can't use all 256 slots in 10.5.x.
// use this constant everywhere you might normally use "256" in reference to a parameter array size.
// The highest shader constant is c218, plus we allocate c219 and c220 for two clip planes
#define DXABSTRACT_VS_PARAM_SLOTS 219
#define DXABSTRACT_VS_FIRST_BONE_SLOT VERTEX_SHADER_MODEL
// user clip plane 0 goes in DXABSTRACT_VS_CLIP_PLANE_BASE... plane 1 goes in the slot after that
// dxabstract uses these constants to check plane index limit and to deliver planes to shader for DP4 -> oCLP[n]
#define DXABSTRACT_VS_CLIP_PLANE_BASE (DXABSTRACT_VS_PARAM_SLOTS-2)
//==================================================================================================
#include "materialsystem/imaterialsystem.h"
#include "materialsystem/ishaderapi.h"
//-----------------------------------------------------------------------------
// forward declarations
//-----------------------------------------------------------------------------
class IMaterialVar;
class IShaderShadow;
class IShaderDynamicAPI;
class IShaderInit;
class CBasePerMaterialContextData;
//-----------------------------------------------------------------------------
// Shader flags
//-----------------------------------------------------------------------------
enum ShaderFlags_t
{
SHADER_NOT_EDITABLE = 0x1
};
//-----------------------------------------------------------------------------
// Shader parameter flags
//-----------------------------------------------------------------------------
enum ShaderParamFlags_t
{
SHADER_PARAM_NOT_EDITABLE = 0x1
};
//-----------------------------------------------------------------------------
// Information about each shader parameter
//-----------------------------------------------------------------------------
struct ShaderParamInfo_t
{
const char *m_pName;
const char *m_pHelp;
ShaderParamType_t m_Type;
const char *m_pDefaultValue;
int m_nFlags;
};
//-----------------------------------------------------------------------------
// Standard vertex shader constants
//-----------------------------------------------------------------------------
enum
{
// Standard vertex shader constants
VERTEX_SHADER_MATH_CONSTANTS0 = 0,
VERTEX_SHADER_MATH_CONSTANTS1 = 1,
VERTEX_SHADER_CAMERA_POS = 2,
VERTEX_SHADER_FLEXSCALE = 3, // used by DX9 only!
VERTEX_SHADER_LIGHT_INDEX = 3, // used by DX8 only!
VERTEX_SHADER_MODELVIEWPROJ = 4,
VERTEX_SHADER_VIEWPROJ = 8,
VERTEX_SHADER_MODELVIEWPROJ_THIRD_ROW = 12,
VERTEX_SHADER_VIEWPROJ_THIRD_ROW = 13,
VERTEX_SHADER_SHADER_SPECIFIC_CONST_10 = 14,
VERTEX_SHADER_SHADER_SPECIFIC_CONST_11 = 15,
VERTEX_SHADER_FOG_PARAMS = 16,
VERTEX_SHADER_VIEWMODEL = 17,
VERTEX_SHADER_AMBIENT_LIGHT = 21,
VERTEX_SHADER_LIGHTS = 27,
VERTEX_SHADER_LIGHT0_POSITION = 29,
VERTEX_SHADER_MODULATION_COLOR = 47,
VERTEX_SHADER_SHADER_SPECIFIC_CONST_0 = 48,
VERTEX_SHADER_SHADER_SPECIFIC_CONST_1 = 49,
VERTEX_SHADER_SHADER_SPECIFIC_CONST_2 = 50,
VERTEX_SHADER_SHADER_SPECIFIC_CONST_3 = 51,
VERTEX_SHADER_SHADER_SPECIFIC_CONST_4 = 52,
VERTEX_SHADER_SHADER_SPECIFIC_CONST_5 = 53,
VERTEX_SHADER_SHADER_SPECIFIC_CONST_6 = 54,
VERTEX_SHADER_SHADER_SPECIFIC_CONST_7 = 55,
VERTEX_SHADER_SHADER_SPECIFIC_CONST_8 = 56,
VERTEX_SHADER_SHADER_SPECIFIC_CONST_9 = 57,
VERTEX_SHADER_MODEL = 58,
//
// We reserve up through 216 for the 53 bones
//
// 219 ClipPlane0 |------ OpenGL will jam clip planes into these two
// 220 ClipPlane1 |
VERTEX_SHADER_FLEX_WEIGHTS = 1024,
VERTEX_SHADER_MAX_FLEX_WEIGHT_COUNT = 512,
};
#define VERTEX_SHADER_BONE_TRANSFORM( k ) ( VERTEX_SHADER_MODEL + 3 * (k) )
//-----------------------------------------------------------------------------
// Standard vertex shader constants
//-----------------------------------------------------------------------------
enum
{
// Standard vertex shader constants
VERTEX_SHADER_LIGHT_ENABLE_BOOL_CONST = 0,
VERTEX_SHADER_LIGHT_ENABLE_BOOL_CONST_COUNT = 4,
VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_0 = 4,
VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_1 = 5,
VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_2 = 6,
VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_3 = 7,
VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_4 = 8,
VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_5 = 9,
VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_6 = 10,
VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_7 = 11,
};
// The public methods exposed by each shader
//-----------------------------------------------------------------------------
abstract_class IShader
{
public:
// Returns the shader name
virtual char const* GetName( ) const = 0;
// returns the shader fallbacks
virtual char const* GetFallbackShader( IMaterialVar** params ) const = 0;
// Shader parameters
virtual int GetNumParams( ) const = 0;
// These functions must be implemented by the shader
virtual void InitShaderParams( IMaterialVar** ppParams, const char *pMaterialName ) = 0;
virtual void InitShaderInstance( IMaterialVar** ppParams, IShaderInit *pShaderInit, const char *pMaterialName, const char *pTextureGroupName ) = 0;
virtual void DrawElements( IMaterialVar **params, int nModulationFlags,
IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr ) = 0;
virtual char const* GetParamName( int paramIndex ) const = 0;
virtual char const* GetParamHelp( int paramIndex ) const = 0;
virtual ShaderParamType_t GetParamType( int paramIndex ) const = 0;
virtual char const* GetParamDefault( int paramIndex ) const = 0;
// FIXME: Figure out a better way to do this?
virtual int ComputeModulationFlags( IMaterialVar** params, IShaderDynamicAPI* pShaderAPI ) = 0;
virtual bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame = true ) const = 0;
virtual bool NeedsFullFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const = 0;
virtual bool IsTranslucent( IMaterialVar **params ) const = 0;
virtual int GetParamFlags( int paramIndex ) const = 0;
virtual int GetFlags() const = 0;
// FIXME: Remove GetParamName, etc. above
// virtual const ShaderParamInfo_t& GetParamInfo( int paramIndex ) const = 0;
};
//-----------------------------------------------------------------------------
// Shader dictionaries defined in DLLs
//-----------------------------------------------------------------------------
enum PrecompiledShaderType_t
{
PRECOMPILED_VERTEX_SHADER = 0,
PRECOMPILED_PIXEL_SHADER,
PRECOMPILED_SHADER_TYPE_COUNT,
};
//-----------------------------------------------------------------------------
// Flags field of PrecompiledShader_t
//-----------------------------------------------------------------------------
enum
{
// runtime flags
SHADER_DYNAMIC_COMPILE_IS_HLSL = 0x1,
SHADER_FAILED_LOAD = 0x2,
};
#endif // ISHADER_H

View File

@ -0,0 +1,255 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $Workfile: $
// $NoKeywords: $
//===========================================================================//
#include "materialsystem/MaterialSystemUtil.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/itexture.h"
#include "materialsystem/imaterialsystem.h"
#include "tier1/KeyValues.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Little utility class to deal with material references
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// constructor, destructor
//-----------------------------------------------------------------------------
CMaterialReference::CMaterialReference( char const* pMaterialName, const char *pTextureGroupName, bool bComplain ) : m_pMaterial( 0 )
{
if ( pMaterialName )
{
Assert( pTextureGroupName );
Init( pMaterialName, pTextureGroupName, bComplain );
}
}
CMaterialReference::~CMaterialReference()
{
Shutdown();
}
//-----------------------------------------------------------------------------
// Attach to a material
//-----------------------------------------------------------------------------
void CMaterialReference::Init( char const* pMaterialName, const char *pTextureGroupName, bool bComplain )
{
IMaterial *pMaterial = materials->FindMaterial( pMaterialName, pTextureGroupName, bComplain);
if( IsErrorMaterial( pMaterial ) )
{
if (IsOSX())
{
printf("\n ##### CMaterialReference::Init got error material for %s in tex group %s", pMaterialName, pTextureGroupName );
}
}
Assert( pMaterial );
Init( pMaterial );
}
void CMaterialReference::Init( const char *pMaterialName, KeyValues *pVMTKeyValues )
{
// CreateMaterial has a refcount of 1
Shutdown();
m_pMaterial = materials->CreateMaterial( pMaterialName, pVMTKeyValues );
}
void CMaterialReference::Init( const char *pMaterialName, const char *pTextureGroupName, KeyValues *pVMTKeyValues )
{
IMaterial *pMaterial = materials->FindProceduralMaterial( pMaterialName, pTextureGroupName, pVMTKeyValues );
Assert( pMaterial );
Init( pMaterial );
}
void CMaterialReference::Init( IMaterial* pMaterial )
{
if ( m_pMaterial != pMaterial )
{
Shutdown();
m_pMaterial = pMaterial;
if ( m_pMaterial )
{
m_pMaterial->IncrementReferenceCount();
}
}
}
void CMaterialReference::Init( CMaterialReference& ref )
{
if ( m_pMaterial != ref.m_pMaterial )
{
Shutdown();
m_pMaterial = ref.m_pMaterial;
if (m_pMaterial)
{
m_pMaterial->IncrementReferenceCount();
}
}
}
//-----------------------------------------------------------------------------
// Detach from a material
//-----------------------------------------------------------------------------
void CMaterialReference::Shutdown( )
{
if ( m_pMaterial && materials )
{
m_pMaterial->DecrementReferenceCount();
m_pMaterial = NULL;
}
}
//-----------------------------------------------------------------------------
// Little utility class to deal with texture references
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// constructor, destructor
//-----------------------------------------------------------------------------
CTextureReference::CTextureReference( ) : m_pTexture(NULL)
{
}
CTextureReference::CTextureReference( const CTextureReference &ref )
{
m_pTexture = ref.m_pTexture;
if ( m_pTexture )
{
m_pTexture->IncrementReferenceCount();
}
}
void CTextureReference::operator=( CTextureReference &ref )
{
m_pTexture = ref.m_pTexture;
if ( m_pTexture )
{
m_pTexture->IncrementReferenceCount();
}
}
CTextureReference::~CTextureReference( )
{
Shutdown();
}
//-----------------------------------------------------------------------------
// Attach to a texture
//-----------------------------------------------------------------------------
void CTextureReference::Init( char const* pTextureName, const char *pTextureGroupName, bool bComplain )
{
Shutdown();
m_pTexture = materials->FindTexture( pTextureName, pTextureGroupName, bComplain );
if ( m_pTexture )
{
m_pTexture->IncrementReferenceCount();
}
}
void CTextureReference::Init( ITexture* pTexture )
{
Shutdown();
m_pTexture = pTexture;
if (m_pTexture)
{
m_pTexture->IncrementReferenceCount();
}
}
void CTextureReference::InitProceduralTexture( const char *pTextureName, const char *pTextureGroupName, int w, int h, ImageFormat fmt, int nFlags )
{
Shutdown();
m_pTexture = materials->CreateProceduralTexture( pTextureName, pTextureGroupName, w, h, fmt, nFlags );
// NOTE: The texture reference is already incremented internally above!
/*
if ( m_pTexture )
{
m_pTexture->IncrementReferenceCount();
}
*/
}
void CTextureReference::InitRenderTarget( int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat fmt, MaterialRenderTargetDepth_t depth, bool bHDR, char *pStrOptionalName /* = NULL */ )
{
Shutdown();
int textureFlags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT;
if ( depth == MATERIAL_RT_DEPTH_ONLY )
textureFlags |= TEXTUREFLAGS_POINTSAMPLE;
int renderTargetFlags = bHDR ? CREATERENDERTARGETFLAGS_HDR : 0;
// NOTE: Refcount returned by CreateRenderTargetTexture is 1
m_pTexture = materials->CreateNamedRenderTargetTextureEx( pStrOptionalName, w, h, sizeMode, fmt,
depth, textureFlags, renderTargetFlags );
Assert( m_pTexture );
}
//-----------------------------------------------------------------------------
// Detach from a texture
//-----------------------------------------------------------------------------
void CTextureReference::Shutdown( bool bDeleteIfUnReferenced )
{
if ( m_pTexture && materials )
{
m_pTexture->DecrementReferenceCount();
if ( bDeleteIfUnReferenced )
{
m_pTexture->DeleteIfUnreferenced();
}
m_pTexture = NULL;
}
}
//-----------------------------------------------------------------------------
// Builds ONLY the system ram render target. Used when caller is explicitly managing.
// The paired EDRAM surface can be built in an alternate format.
//-----------------------------------------------------------------------------
#if defined( _X360 )
void CTextureReference::InitRenderTargetTexture( int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat fmt, MaterialRenderTargetDepth_t depth, bool bHDR, char *pStrOptionalName )
{
// other variants not implemented yet
Assert( depth == MATERIAL_RT_DEPTH_NONE || depth == MATERIAL_RT_DEPTH_SHARED );
Assert( !bHDR );
int renderTargetFlags = CREATERENDERTARGETFLAGS_NOEDRAM;
m_pTexture = materials->CreateNamedRenderTargetTextureEx(
pStrOptionalName,
w,
h,
sizeMode,
fmt,
depth,
TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
renderTargetFlags );
Assert( m_pTexture );
}
#endif
//-----------------------------------------------------------------------------
// Builds ONLY the EDRAM render target surface. Used when caller is explicitly managing.
// The paired system memory texture can be built in an alternate format.
//-----------------------------------------------------------------------------
#if defined( _X360 )
void CTextureReference::InitRenderTargetSurface( int width, int height, ImageFormat fmt, bool bSameAsTexture )
{
// texture has to be created first
Assert( m_pTexture && m_pTexture->IsRenderTarget() );
m_pTexture->CreateRenderTargetSurface( width, height, fmt, bSameAsTexture );
}
#endif

View File

@ -0,0 +1,99 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $Workfile: $
// $Date: $
// $NoKeywords: $
//===========================================================================//
#ifndef MATERIALSYSTEMUTIL_H
#define MATERIALSYSTEMUTIL_H
#ifdef _WIN32
#pragma once
#endif
#include "bitmap/imageformat.h" //ImageFormat enum definition
#include "materialsystem/imaterialsystem.h" // RenderTargetSizeMode_t and MaterialRenderTargetDepth_t definition
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class IMaterial;
class ITexture;
class KeyValues;
class KeyValues;
//-----------------------------------------------------------------------------
// Little utility class to deal with material references
//-----------------------------------------------------------------------------
class CMaterialReference
{
public:
// constructor, destructor
CMaterialReference( char const* pMaterialName = 0, const char *pTextureGroupName = 0, bool bComplain = true );
~CMaterialReference();
// Attach to a material
void Init( const char* pMaterialName, const char *pTextureGroupName, bool bComplain = true );
void Init( const char *pMaterialName, KeyValues *pVMTKeyValues );
void Init( IMaterial* pMaterial );
void Init( CMaterialReference& ref );
void Init( const char *pMaterialName, const char *pTextureGroupName, KeyValues *pVMTKeyValues );
// Detach from a material
void Shutdown();
bool IsValid() { return m_pMaterial != 0; }
// Automatic casts to IMaterial
operator IMaterial*() { return m_pMaterial; }
operator IMaterial*() const { return m_pMaterial; }
operator IMaterial const*() const { return m_pMaterial; }
IMaterial* operator->() { return m_pMaterial; }
private:
IMaterial* m_pMaterial;
};
//-----------------------------------------------------------------------------
// Little utility class to deal with texture references
//-----------------------------------------------------------------------------
class CTextureReference
{
public:
// constructor, destructor
CTextureReference( );
CTextureReference( const CTextureReference &ref );
~CTextureReference();
// Attach to a texture
void Init( char const* pTexture, const char *pTextureGroupName, bool bComplain = true );
void InitProceduralTexture( const char *pTextureName, const char *pTextureGroupName, int w, int h, ImageFormat fmt, int nFlags );
void InitRenderTarget( int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat fmt, MaterialRenderTargetDepth_t depth, bool bHDR, char *pStrOptionalName = NULL );
#if defined( _X360 )
// used when RT coupling is disparate (texture is DDR based, surface is EDRAM based)
void InitRenderTargetTexture( int width, int height, RenderTargetSizeMode_t sizeMode, ImageFormat fmt, MaterialRenderTargetDepth_t depth, bool bHDR, char *pStrOptionalName = NULL );
void InitRenderTargetSurface( int width, int height, ImageFormat fmt, bool bSameAsTexture );
#endif
void Init( ITexture* pTexture );
// Detach from a texture
void Shutdown( bool bDeleteIfUnReferenced = false );
bool IsValid() { return m_pTexture != 0; }
// Automatic casts to ITexture
operator ITexture*() { return m_pTexture; }
operator ITexture const*() const { return m_pTexture; }
ITexture* operator->() { return m_pTexture; }
// Assignment operator
void operator=( CTextureReference &ref );
private:
ITexture* m_pTexture;
};
#endif // !MATERIALSYSTEMUTIL_H

View File

@ -0,0 +1,58 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#ifndef DEFORMATIONS_H
#define DEFORMATIONS_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/platform.h"
// nonlinear transformations which may be applied to model vertices when rendering. must be powers of two
enum DeformationType_t
{
DEFORMATION_CLAMP_TO_BOX_IN_WORLDSPACE = 1, // minxyz.minsoftness / maxxyz.maxsoftness
};
struct DeformationBase_t // base class. don't use this
{
DeformationType_t m_eType;
};
struct BoxDeformation_t : DeformationBase_t
{
// don't change the layout without changing code in shaderapidx8!!!!
Vector m_SourceMins; // cube to clamp within
float m_flPad0;
Vector m_SourceMaxes;
float m_flPad1;
Vector m_ClampMins;
float m_flPad2;
Vector m_ClampMaxes;
float m_flPad3;
FORCEINLINE BoxDeformation_t( void )
{
m_eType = DEFORMATION_CLAMP_TO_BOX_IN_WORLDSPACE;
// invalid cube
m_SourceMins.Init( 0,0,0 );
m_SourceMaxes.Init( -1, -1, -1 );
// no clamp
m_ClampMins.Init( -FLT_MAX, -FLT_MAX, -FLT_MAX );
m_ClampMaxes.Init( FLT_MAX, FLT_MAX, FLT_MAX );
}
};
#endif

View File

@ -0,0 +1,86 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Hardware Verts
//
// Contains data purposely formatted for a dma copy into a D3D Vertex Buffer.
// The file is divided into two partitions, the foremost contains the static
// portion (header), the latter contains the streamable compliant portion.
// The streamable component starts and ends on a sector (512) aligned boundary.
// The header identifies the vertex format of the data and the atomic sizes of each component.
// The hierarchial mesh is flattened for dma but the vertex counts are available
// per mesh to transfer each mesh individually.
//=============================================================================//
#ifndef HARDWAREVERTS_H
#define HARDWAREVERTS_H
#ifdef _WIN32
#pragma once
#endif
#include "datamap.h"
// valve hardware vertexes
#define VHV_VERSION 2
namespace HardwareVerts
{
#pragma pack(1)
struct MeshHeader_t
{
DECLARE_BYTESWAP_DATADESC();
// this mesh is part of this lod
unsigned int m_nLod;
// this mesh has this many vertexes
unsigned int m_nVertexes;
// starting at this offset
unsigned int m_nOffset;
unsigned int m_nUnused[4];
};
struct FileHeader_t
{
DECLARE_BYTESWAP_DATADESC();
// file version as defined by VHV_VERSION
int m_nVersion;
// must match checkSum in the .mdl header
unsigned int m_nChecksum;
// a vertex consists of these components
uint32 m_nVertexFlags;
// the byte size of a single vertex
// this won't be adequate, need some concept of byte format i.e. rgbexp32 vs rgba8888
unsigned int m_nVertexSize;
// total number of vertexes
unsigned int m_nVertexes;
int m_nMeshes;
inline MeshHeader_t *pMesh( int nMesh ) const
{
return (MeshHeader_t *)(((byte *)this) + sizeof(FileHeader_t)) + nMesh;
};
inline void *pVertexBase( int nMesh ) const
{
return (void *)((byte *)this + pMesh( nMesh )->m_nOffset);
};
unsigned int m_nUnused[4];
};
#pragma pack()
}; // end namespace
#endif // HARDWAREVERTS_H

View File

@ -0,0 +1,69 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#ifndef IDEBUGTEXTUREINFO_H
#define IDEBUGTEXTUREINFO_H
#ifdef _WIN32
#pragma once
#endif
class KeyValues;
// This interface is actually exported by the shader API DLL.
#define DEBUG_TEXTURE_INFO_VERSION "DebugTextureInfo001"
abstract_class IDebugTextureInfo
{
public:
// Use this to turn on the mode where it builds the debug texture list.
// At the end of the next frame, GetDebugTextureList() will return a valid list of the textures.
virtual void EnableDebugTextureList( bool bEnable ) = 0;
// If this is on, then it will return all textures that exist, not just the ones that were bound in the last frame.
// It is required to enable debug texture list to get this.
virtual void EnableGetAllTextures( bool bEnable ) = 0;
// Use this to get the results of the texture list.
// Do NOT release the KeyValues after using them.
// There will be a bunch of subkeys, each with these values:
// Name - the texture's filename
// Binds - how many times the texture was bound
// Format - ImageFormat of the texture
// Width - Width of the texture
// Height - Height of the texture
// It is required to enable debug texture list to get this.
virtual KeyValues* GetDebugTextureList() = 0;
// Texture memory usage
enum TextureMemoryType
{
MEMORY_RESERVED_MIN = 0,
MEMORY_BOUND_LAST_FRAME, // sums up textures bound last frame
MEMORY_TOTAL_LOADED, // total texture memory used
MEMORY_ESTIMATE_PICMIP_1, // estimate of running with "picmip 1"
MEMORY_ESTIMATE_PICMIP_2, // estimate of running with "picmip 2"
MEMORY_RESERVED_MAX
};
// This returns how much memory was used.
virtual int GetTextureMemoryUsed( TextureMemoryType eTextureMemory ) = 0;
// Use this to determine if texture debug info was computed within last numFramesAllowed frames.
virtual bool IsDebugTextureListFresh( int numFramesAllowed = 1 ) = 0;
// Enable debug texture rendering when texture binds should not count towards textures
// used during a frame. Returns the old state of debug texture rendering flag to use
// it for restoring the mode.
virtual bool SetDebugTextureRendering( bool bEnable ) = 0;
};
#endif // IDEBUGTEXTUREINFO_H

View File

@ -0,0 +1,612 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef IMATERIAL_H
#define IMATERIAL_H
#ifdef _WIN32
#pragma once
#endif
#include "bitmap/imageformat.h"
#include "materialsystem/imaterialsystem.h"
//-----------------------------------------------------------------------------
// forward declaraions
//-----------------------------------------------------------------------------
class IMaterialVar;
class ITexture;
class IMaterialProxy;
class Vector;
//-----------------------------------------------------------------------------
// Flags for GetVertexFormat
//-----------------------------------------------------------------------------
#define VERTEX_POSITION 0x0001
#define VERTEX_NORMAL 0x0002
#define VERTEX_COLOR 0x0004
#define VERTEX_SPECULAR 0x0008
#define VERTEX_TANGENT_S 0x0010
#define VERTEX_TANGENT_T 0x0020
#define VERTEX_TANGENT_SPACE ( VERTEX_TANGENT_S | VERTEX_TANGENT_T )
// Indicates we're using wrinkle
#define VERTEX_WRINKLE 0x0040
// Indicates we're using bone indices
#define VERTEX_BONE_INDEX 0x0080
// Indicates this is a vertex shader
#define VERTEX_FORMAT_VERTEX_SHADER 0x0100
// Indicates this format shouldn't be bloated to cache align it
// (only used for VertexUsage)
#define VERTEX_FORMAT_USE_EXACT_FORMAT 0x0200
// Indicates that compressed vertex elements are to be used (see also VertexCompressionType_t)
#define VERTEX_FORMAT_COMPRESSED 0x400
// Update this if you add or remove bits...
#define VERTEX_LAST_BIT 10
#define VERTEX_BONE_WEIGHT_BIT (VERTEX_LAST_BIT + 1)
#define USER_DATA_SIZE_BIT (VERTEX_LAST_BIT + 4)
#define TEX_COORD_SIZE_BIT (VERTEX_LAST_BIT + 7)
#define VERTEX_BONE_WEIGHT_MASK ( 0x7 << VERTEX_BONE_WEIGHT_BIT )
#define USER_DATA_SIZE_MASK ( 0x7 << USER_DATA_SIZE_BIT )
#define VERTEX_FORMAT_FIELD_MASK 0x0FF
// If everything is off, it's an unknown vertex format
#define VERTEX_FORMAT_UNKNOWN 0
//-----------------------------------------------------------------------------
// Macros for construction..
//-----------------------------------------------------------------------------
#define VERTEX_BONEWEIGHT( _n ) ((_n) << VERTEX_BONE_WEIGHT_BIT)
#define VERTEX_USERDATA_SIZE( _n ) ((_n) << USER_DATA_SIZE_BIT)
#define VERTEX_TEXCOORD_MASK( _coord ) (( 0x7ULL ) << ( TEX_COORD_SIZE_BIT + 3 * (_coord) ))
inline VertexFormat_t VERTEX_TEXCOORD_SIZE( int nIndex, int nNumCoords )
{
uint64 n64=nNumCoords;
uint64 nShift=TEX_COORD_SIZE_BIT + (3*nIndex);
return n64 << nShift;
}
//-----------------------------------------------------------------------------
// Gets at various vertex format info...
//-----------------------------------------------------------------------------
inline int VertexFlags( VertexFormat_t vertexFormat )
{
return static_cast<int> ( vertexFormat & ( (1 << (VERTEX_LAST_BIT+1)) - 1 ) );
}
inline int NumBoneWeights( VertexFormat_t vertexFormat )
{
return static_cast<int> ( (vertexFormat >> VERTEX_BONE_WEIGHT_BIT) & 0x7 );
}
inline int UserDataSize( VertexFormat_t vertexFormat )
{
return static_cast<int> ( (vertexFormat >> USER_DATA_SIZE_BIT) & 0x7 );
}
inline int TexCoordSize( int nTexCoordIndex, VertexFormat_t vertexFormat )
{
return static_cast<int> ( (vertexFormat >> (TEX_COORD_SIZE_BIT + 3*nTexCoordIndex) ) & 0x7 );
}
inline bool UsesVertexShader( VertexFormat_t vertexFormat )
{
return (vertexFormat & VERTEX_FORMAT_VERTEX_SHADER) != 0;
}
inline VertexCompressionType_t CompressionType( VertexFormat_t vertexFormat )
{
// This is trivial now, but we may add multiple flavours of compressed vertex later on
if ( vertexFormat & VERTEX_FORMAT_COMPRESSED )
return VERTEX_COMPRESSION_ON;
else
return VERTEX_COMPRESSION_NONE;
}
//-----------------------------------------------------------------------------
// VertexElement_t (enumerates all usable vertex elements)
//-----------------------------------------------------------------------------
// FIXME: unify this with VertexFormat_t (i.e. construct the lower bits of VertexFormat_t with "1 << (VertexElement_t)element")
enum VertexElement_t
{
VERTEX_ELEMENT_NONE = -1,
// Deliberately explicitly numbered so it's a pain in the ass to change, so you read this:
// #!#!#NOTE#!#!# update GetVertexElementSize, VertexElementToDeclType and
// CVBAllocTracker (elementTable) when you update this!
VERTEX_ELEMENT_POSITION = 0,
VERTEX_ELEMENT_NORMAL = 1,
VERTEX_ELEMENT_COLOR = 2,
VERTEX_ELEMENT_SPECULAR = 3,
VERTEX_ELEMENT_TANGENT_S = 4,
VERTEX_ELEMENT_TANGENT_T = 5,
VERTEX_ELEMENT_WRINKLE = 6,
VERTEX_ELEMENT_BONEINDEX = 7,
VERTEX_ELEMENT_BONEWEIGHTS1 = 8,
VERTEX_ELEMENT_BONEWEIGHTS2 = 9,
VERTEX_ELEMENT_BONEWEIGHTS3 = 10,
VERTEX_ELEMENT_BONEWEIGHTS4 = 11,
VERTEX_ELEMENT_USERDATA1 = 12,
VERTEX_ELEMENT_USERDATA2 = 13,
VERTEX_ELEMENT_USERDATA3 = 14,
VERTEX_ELEMENT_USERDATA4 = 15,
VERTEX_ELEMENT_TEXCOORD1D_0 = 16,
VERTEX_ELEMENT_TEXCOORD1D_1 = 17,
VERTEX_ELEMENT_TEXCOORD1D_2 = 18,
VERTEX_ELEMENT_TEXCOORD1D_3 = 19,
VERTEX_ELEMENT_TEXCOORD1D_4 = 20,
VERTEX_ELEMENT_TEXCOORD1D_5 = 21,
VERTEX_ELEMENT_TEXCOORD1D_6 = 22,
VERTEX_ELEMENT_TEXCOORD1D_7 = 23,
VERTEX_ELEMENT_TEXCOORD2D_0 = 24,
VERTEX_ELEMENT_TEXCOORD2D_1 = 25,
VERTEX_ELEMENT_TEXCOORD2D_2 = 26,
VERTEX_ELEMENT_TEXCOORD2D_3 = 27,
VERTEX_ELEMENT_TEXCOORD2D_4 = 28,
VERTEX_ELEMENT_TEXCOORD2D_5 = 29,
VERTEX_ELEMENT_TEXCOORD2D_6 = 30,
VERTEX_ELEMENT_TEXCOORD2D_7 = 31,
VERTEX_ELEMENT_TEXCOORD3D_0 = 32,
VERTEX_ELEMENT_TEXCOORD3D_1 = 33,
VERTEX_ELEMENT_TEXCOORD3D_2 = 34,
VERTEX_ELEMENT_TEXCOORD3D_3 = 35,
VERTEX_ELEMENT_TEXCOORD3D_4 = 36,
VERTEX_ELEMENT_TEXCOORD3D_5 = 37,
VERTEX_ELEMENT_TEXCOORD3D_6 = 38,
VERTEX_ELEMENT_TEXCOORD3D_7 = 39,
VERTEX_ELEMENT_TEXCOORD4D_0 = 40,
VERTEX_ELEMENT_TEXCOORD4D_1 = 41,
VERTEX_ELEMENT_TEXCOORD4D_2 = 42,
VERTEX_ELEMENT_TEXCOORD4D_3 = 43,
VERTEX_ELEMENT_TEXCOORD4D_4 = 44,
VERTEX_ELEMENT_TEXCOORD4D_5 = 45,
VERTEX_ELEMENT_TEXCOORD4D_6 = 46,
VERTEX_ELEMENT_TEXCOORD4D_7 = 47,
VERTEX_ELEMENT_NUMELEMENTS = 48
};
inline void Detect_VertexElement_t_Changes( VertexElement_t element ) // GREPs for VertexElement_t will hit this
{
// Make it harder for someone to change VertexElement_t without noticing that dependent code
// (GetVertexElementSize, VertexElementToDeclType, CVBAllocTracker) needs updating
Assert( VERTEX_ELEMENT_NUMELEMENTS == 48 );
switch ( element )
{
case VERTEX_ELEMENT_POSITION: Assert( VERTEX_ELEMENT_POSITION == 0 ); break;
case VERTEX_ELEMENT_NORMAL: Assert( VERTEX_ELEMENT_NORMAL == 1 ); break;
case VERTEX_ELEMENT_COLOR: Assert( VERTEX_ELEMENT_COLOR == 2 ); break;
case VERTEX_ELEMENT_SPECULAR: Assert( VERTEX_ELEMENT_SPECULAR == 3 ); break;
case VERTEX_ELEMENT_TANGENT_S: Assert( VERTEX_ELEMENT_TANGENT_S == 4 ); break;
case VERTEX_ELEMENT_TANGENT_T: Assert( VERTEX_ELEMENT_TANGENT_T == 5 ); break;
case VERTEX_ELEMENT_WRINKLE: Assert( VERTEX_ELEMENT_WRINKLE == 6 ); break;
case VERTEX_ELEMENT_BONEINDEX: Assert( VERTEX_ELEMENT_BONEINDEX == 7 ); break;
case VERTEX_ELEMENT_BONEWEIGHTS1: Assert( VERTEX_ELEMENT_BONEWEIGHTS1 == 8 ); break;
case VERTEX_ELEMENT_BONEWEIGHTS2: Assert( VERTEX_ELEMENT_BONEWEIGHTS2 == 9 ); break;
case VERTEX_ELEMENT_BONEWEIGHTS3: Assert( VERTEX_ELEMENT_BONEWEIGHTS3 == 10 ); break;
case VERTEX_ELEMENT_BONEWEIGHTS4: Assert( VERTEX_ELEMENT_BONEWEIGHTS4 == 11 ); break;
case VERTEX_ELEMENT_USERDATA1: Assert( VERTEX_ELEMENT_USERDATA1 == 12 ); break;
case VERTEX_ELEMENT_USERDATA2: Assert( VERTEX_ELEMENT_USERDATA2 == 13 ); break;
case VERTEX_ELEMENT_USERDATA3: Assert( VERTEX_ELEMENT_USERDATA3 == 14 ); break;
case VERTEX_ELEMENT_USERDATA4: Assert( VERTEX_ELEMENT_USERDATA4 == 15 ); break;
case VERTEX_ELEMENT_TEXCOORD1D_0: Assert( VERTEX_ELEMENT_TEXCOORD1D_0 == 16 ); break;
case VERTEX_ELEMENT_TEXCOORD1D_1: Assert( VERTEX_ELEMENT_TEXCOORD1D_1 == 17 ); break;
case VERTEX_ELEMENT_TEXCOORD1D_2: Assert( VERTEX_ELEMENT_TEXCOORD1D_2 == 18 ); break;
case VERTEX_ELEMENT_TEXCOORD1D_3: Assert( VERTEX_ELEMENT_TEXCOORD1D_3 == 19 ); break;
case VERTEX_ELEMENT_TEXCOORD1D_4: Assert( VERTEX_ELEMENT_TEXCOORD1D_4 == 20 ); break;
case VERTEX_ELEMENT_TEXCOORD1D_5: Assert( VERTEX_ELEMENT_TEXCOORD1D_5 == 21 ); break;
case VERTEX_ELEMENT_TEXCOORD1D_6: Assert( VERTEX_ELEMENT_TEXCOORD1D_6 == 22 ); break;
case VERTEX_ELEMENT_TEXCOORD1D_7: Assert( VERTEX_ELEMENT_TEXCOORD1D_7 == 23 ); break;
case VERTEX_ELEMENT_TEXCOORD2D_0: Assert( VERTEX_ELEMENT_TEXCOORD2D_0 == 24 ); break;
case VERTEX_ELEMENT_TEXCOORD2D_1: Assert( VERTEX_ELEMENT_TEXCOORD2D_1 == 25 ); break;
case VERTEX_ELEMENT_TEXCOORD2D_2: Assert( VERTEX_ELEMENT_TEXCOORD2D_2 == 26 ); break;
case VERTEX_ELEMENT_TEXCOORD2D_3: Assert( VERTEX_ELEMENT_TEXCOORD2D_3 == 27 ); break;
case VERTEX_ELEMENT_TEXCOORD2D_4: Assert( VERTEX_ELEMENT_TEXCOORD2D_4 == 28 ); break;
case VERTEX_ELEMENT_TEXCOORD2D_5: Assert( VERTEX_ELEMENT_TEXCOORD2D_5 == 29 ); break;
case VERTEX_ELEMENT_TEXCOORD2D_6: Assert( VERTEX_ELEMENT_TEXCOORD2D_6 == 30 ); break;
case VERTEX_ELEMENT_TEXCOORD2D_7: Assert( VERTEX_ELEMENT_TEXCOORD2D_7 == 31 ); break;
case VERTEX_ELEMENT_TEXCOORD3D_0: Assert( VERTEX_ELEMENT_TEXCOORD3D_0 == 32 ); break;
case VERTEX_ELEMENT_TEXCOORD3D_1: Assert( VERTEX_ELEMENT_TEXCOORD3D_1 == 33 ); break;
case VERTEX_ELEMENT_TEXCOORD3D_2: Assert( VERTEX_ELEMENT_TEXCOORD3D_2 == 34 ); break;
case VERTEX_ELEMENT_TEXCOORD3D_3: Assert( VERTEX_ELEMENT_TEXCOORD3D_3 == 35 ); break;
case VERTEX_ELEMENT_TEXCOORD3D_4: Assert( VERTEX_ELEMENT_TEXCOORD3D_4 == 36 ); break;
case VERTEX_ELEMENT_TEXCOORD3D_5: Assert( VERTEX_ELEMENT_TEXCOORD3D_5 == 37 ); break;
case VERTEX_ELEMENT_TEXCOORD3D_6: Assert( VERTEX_ELEMENT_TEXCOORD3D_6 == 38 ); break;
case VERTEX_ELEMENT_TEXCOORD3D_7: Assert( VERTEX_ELEMENT_TEXCOORD3D_7 == 39 ); break;
case VERTEX_ELEMENT_TEXCOORD4D_0: Assert( VERTEX_ELEMENT_TEXCOORD4D_0 == 40 ); break;
case VERTEX_ELEMENT_TEXCOORD4D_1: Assert( VERTEX_ELEMENT_TEXCOORD4D_1 == 41 ); break;
case VERTEX_ELEMENT_TEXCOORD4D_2: Assert( VERTEX_ELEMENT_TEXCOORD4D_2 == 42 ); break;
case VERTEX_ELEMENT_TEXCOORD4D_3: Assert( VERTEX_ELEMENT_TEXCOORD4D_3 == 43 ); break;
case VERTEX_ELEMENT_TEXCOORD4D_4: Assert( VERTEX_ELEMENT_TEXCOORD4D_4 == 44 ); break;
case VERTEX_ELEMENT_TEXCOORD4D_5: Assert( VERTEX_ELEMENT_TEXCOORD4D_5 == 45 ); break;
case VERTEX_ELEMENT_TEXCOORD4D_6: Assert( VERTEX_ELEMENT_TEXCOORD4D_6 == 46 ); break;
case VERTEX_ELEMENT_TEXCOORD4D_7: Assert( VERTEX_ELEMENT_TEXCOORD4D_7 == 47 ); break;
default:
Assert( 0 ); // Invalid input or VertexElement_t has definitely changed
break;
}
}
// We're testing 2 normal compression methods
// One compressed normals+tangents into a SHORT2 each (8 bytes total)
// The other compresses them together, into a single UBYTE4 (4 bytes total)
// FIXME: pick one or the other, compare lighting quality in important cases
#define COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 0
#define COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 1
//#define COMPRESSED_NORMALS_TYPE COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2
#define COMPRESSED_NORMALS_TYPE COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4
inline int GetVertexElementSize( VertexElement_t element, VertexCompressionType_t compressionType )
{
Detect_VertexElement_t_Changes( element );
if ( compressionType == VERTEX_COMPRESSION_ON )
{
// Compressed-vertex element sizes
switch ( element )
{
#if ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 )
case VERTEX_ELEMENT_NORMAL:
return ( 2 * sizeof( short ) );
case VERTEX_ELEMENT_USERDATA4:
return ( 2 * sizeof( short ) );
#else //( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 )
// Normals and tangents (userdata4) are combined into a single UBYTE4 vertex element
case VERTEX_ELEMENT_NORMAL:
return ( 4 * sizeof( unsigned char ) );
case VERTEX_ELEMENT_USERDATA4:
return ( 0 );
#endif
// Compressed bone weights use a SHORT2 vertex element:
case VERTEX_ELEMENT_BONEWEIGHTS1:
case VERTEX_ELEMENT_BONEWEIGHTS2:
return ( 2 * sizeof( short ) );
default:
break;
}
}
// Uncompressed-vertex element sizes
switch ( element )
{
case VERTEX_ELEMENT_POSITION: return ( 3 * sizeof( float ) );
case VERTEX_ELEMENT_NORMAL: return ( 3 * sizeof( float ) );
case VERTEX_ELEMENT_COLOR: return ( 4 * sizeof( unsigned char ) );
case VERTEX_ELEMENT_SPECULAR: return ( 4 * sizeof( unsigned char ) );
case VERTEX_ELEMENT_TANGENT_S: return ( 3 * sizeof( float ) );
case VERTEX_ELEMENT_TANGENT_T: return ( 3 * sizeof( float ) );
case VERTEX_ELEMENT_WRINKLE: return ( 1 * sizeof( float ) ); // Packed into Position.W
case VERTEX_ELEMENT_BONEINDEX: return ( 4 * sizeof( unsigned char ) );
case VERTEX_ELEMENT_BONEWEIGHTS1: return ( 1 * sizeof( float ) );
case VERTEX_ELEMENT_BONEWEIGHTS2: return ( 2 * sizeof( float ) );
case VERTEX_ELEMENT_BONEWEIGHTS3: return ( 3 * sizeof( float ) );
case VERTEX_ELEMENT_BONEWEIGHTS4: return ( 4 * sizeof( float ) );
case VERTEX_ELEMENT_USERDATA1: return ( 1 * sizeof( float ) );
case VERTEX_ELEMENT_USERDATA2: return ( 2 * sizeof( float ) );
case VERTEX_ELEMENT_USERDATA3: return ( 3 * sizeof( float ) );
case VERTEX_ELEMENT_USERDATA4: return ( 4 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD1D_0: return ( 1 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD1D_1: return ( 1 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD1D_2: return ( 1 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD1D_3: return ( 1 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD1D_4: return ( 1 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD1D_5: return ( 1 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD1D_6: return ( 1 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD1D_7: return ( 1 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD2D_0: return ( 2 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD2D_1: return ( 2 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD2D_2: return ( 2 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD2D_3: return ( 2 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD2D_4: return ( 2 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD2D_5: return ( 2 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD2D_6: return ( 2 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD2D_7: return ( 2 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD3D_0: return ( 3 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD3D_1: return ( 3 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD3D_2: return ( 3 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD3D_3: return ( 3 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD3D_4: return ( 3 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD3D_5: return ( 3 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD3D_6: return ( 3 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD3D_7: return ( 3 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD4D_0: return ( 4 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD4D_1: return ( 4 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD4D_2: return ( 4 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD4D_3: return ( 4 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD4D_4: return ( 4 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD4D_5: return ( 4 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD4D_6: return ( 4 * sizeof( float ) );
case VERTEX_ELEMENT_TEXCOORD4D_7: return ( 4 * sizeof( float ) );
default:
Assert(0);
return 0;
};
}
//-----------------------------------------------------------------------------
// Shader state flags can be read from the FLAGS materialvar
// Also can be read or written to with the Set/GetMaterialVarFlags() call
// Also make sure you add/remove a string associated with each flag below to CShaderSystem::ShaderStateString in ShaderSystem.cpp
//-----------------------------------------------------------------------------
enum MaterialVarFlags_t
{
MATERIAL_VAR_DEBUG = (1 << 0),
MATERIAL_VAR_NO_DEBUG_OVERRIDE = (1 << 1),
MATERIAL_VAR_NO_DRAW = (1 << 2),
MATERIAL_VAR_USE_IN_FILLRATE_MODE = (1 << 3),
MATERIAL_VAR_VERTEXCOLOR = (1 << 4),
MATERIAL_VAR_VERTEXALPHA = (1 << 5),
MATERIAL_VAR_SELFILLUM = (1 << 6),
MATERIAL_VAR_ADDITIVE = (1 << 7),
MATERIAL_VAR_ALPHATEST = (1 << 8),
MATERIAL_VAR_MULTIPASS = (1 << 9),
MATERIAL_VAR_ZNEARER = (1 << 10),
MATERIAL_VAR_MODEL = (1 << 11),
MATERIAL_VAR_FLAT = (1 << 12),
MATERIAL_VAR_NOCULL = (1 << 13),
MATERIAL_VAR_NOFOG = (1 << 14),
MATERIAL_VAR_IGNOREZ = (1 << 15),
MATERIAL_VAR_DECAL = (1 << 16),
MATERIAL_VAR_ENVMAPSPHERE = (1 << 17),
MATERIAL_VAR_NOALPHAMOD = (1 << 18),
MATERIAL_VAR_ENVMAPCAMERASPACE = (1 << 19),
MATERIAL_VAR_BASEALPHAENVMAPMASK = (1 << 20),
MATERIAL_VAR_TRANSLUCENT = (1 << 21),
MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK = (1 << 22),
MATERIAL_VAR_NEEDS_SOFTWARE_SKINNING = (1 << 23),
MATERIAL_VAR_OPAQUETEXTURE = (1 << 24),
MATERIAL_VAR_ENVMAPMODE = (1 << 25),
MATERIAL_VAR_SUPPRESS_DECALS = (1 << 26),
MATERIAL_VAR_HALFLAMBERT = (1 << 27),
MATERIAL_VAR_WIREFRAME = (1 << 28),
MATERIAL_VAR_ALLOWALPHATOCOVERAGE = (1 << 29),
MATERIAL_VAR_IGNORE_ALPHA_MODULATION = (1 << 30),
// NOTE: Only add flags here that either should be read from
// .vmts or can be set directly from client code. Other, internal
// flags should to into the flag enum in imaterialinternal.h
};
//-----------------------------------------------------------------------------
// Internal flags not accessible from outside the material system. Stored in Flags2
//-----------------------------------------------------------------------------
enum MaterialVarFlags2_t
{
// NOTE: These are for $flags2!!!!!
// UNUSED = (1 << 0),
MATERIAL_VAR2_LIGHTING_UNLIT = 0,
MATERIAL_VAR2_LIGHTING_VERTEX_LIT = (1 << 1),
MATERIAL_VAR2_LIGHTING_LIGHTMAP = (1 << 2),
MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP = (1 << 3),
MATERIAL_VAR2_LIGHTING_MASK =
( MATERIAL_VAR2_LIGHTING_VERTEX_LIT |
MATERIAL_VAR2_LIGHTING_LIGHTMAP |
MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP ),
// FIXME: Should this be a part of the above lighting enums?
MATERIAL_VAR2_DIFFUSE_BUMPMAPPED_MODEL = (1 << 4),
MATERIAL_VAR2_USES_ENV_CUBEMAP = (1 << 5),
MATERIAL_VAR2_NEEDS_TANGENT_SPACES = (1 << 6),
MATERIAL_VAR2_NEEDS_SOFTWARE_LIGHTING = (1 << 7),
// GR - HDR path puts lightmap alpha in separate texture...
MATERIAL_VAR2_BLEND_WITH_LIGHTMAP_ALPHA = (1 << 8),
MATERIAL_VAR2_NEEDS_BAKED_LIGHTING_SNAPSHOTS = (1 << 9),
MATERIAL_VAR2_USE_FLASHLIGHT = (1 << 10),
MATERIAL_VAR2_USE_FIXED_FUNCTION_BAKED_LIGHTING = (1 << 11),
MATERIAL_VAR2_NEEDS_FIXED_FUNCTION_FLASHLIGHT = (1 << 12),
MATERIAL_VAR2_USE_EDITOR = (1 << 13),
MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE = (1 << 14),
MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE = (1 << 15),
MATERIAL_VAR2_IS_SPRITECARD = (1 << 16),
MATERIAL_VAR2_USES_VERTEXID = (1 << 17),
MATERIAL_VAR2_SUPPORTS_HW_SKINNING = (1 << 18),
MATERIAL_VAR2_SUPPORTS_FLASHLIGHT = (1 << 19),
};
//-----------------------------------------------------------------------------
// Preview image return values
//-----------------------------------------------------------------------------
enum PreviewImageRetVal_t
{
MATERIAL_PREVIEW_IMAGE_BAD = 0,
MATERIAL_PREVIEW_IMAGE_OK,
MATERIAL_NO_PREVIEW_IMAGE,
};
//-----------------------------------------------------------------------------
// material interface
//-----------------------------------------------------------------------------
abstract_class IMaterial
{
public:
// Get the name of the material. This is a full path to
// the vmt file starting from "hl2/materials" (or equivalent) without
// a file extension.
virtual const char * GetName() const = 0;
virtual const char * GetTextureGroupName() const = 0;
// Get the preferred size/bitDepth of a preview image of a material.
// This is the sort of image that you would use for a thumbnail view
// of a material, or in WorldCraft until it uses materials to render.
// separate this for the tools maybe
virtual PreviewImageRetVal_t GetPreviewImageProperties( int *width, int *height,
ImageFormat *imageFormat, bool* isTranslucent ) const = 0;
// Get a preview image at the specified width/height and bitDepth.
// Will do resampling if necessary.(not yet!!! :) )
// Will do color format conversion. (works now.)
virtual PreviewImageRetVal_t GetPreviewImage( unsigned char *data,
int width, int height,
ImageFormat imageFormat ) const = 0;
//
virtual int GetMappingWidth( ) = 0;
virtual int GetMappingHeight( ) = 0;
virtual int GetNumAnimationFrames( ) = 0;
// For material subrects (material pages). Offset(u,v) and scale(u,v) are normalized to texture.
virtual bool InMaterialPage( void ) = 0;
virtual void GetMaterialOffset( float *pOffset ) = 0;
virtual void GetMaterialScale( float *pScale ) = 0;
virtual IMaterial *GetMaterialPage( void ) = 0;
// find a vmt variable.
// This is how game code affects how a material is rendered.
// The game code must know about the params that are used by
// the shader for the material that it is trying to affect.
virtual IMaterialVar * FindVar( const char *varName, bool *found, bool complain = true ) = 0;
// The user never allocates or deallocates materials. Reference counting is
// used instead. Garbage collection is done upon a call to
// IMaterialSystem::UncacheUnusedMaterials.
virtual void IncrementReferenceCount( void ) = 0;
virtual void DecrementReferenceCount( void ) = 0;
inline void AddRef() { IncrementReferenceCount(); }
inline void Release() { DecrementReferenceCount(); }
// Each material is assigned a number that groups it with like materials
// for sorting in the application.
virtual int GetEnumerationID( void ) const = 0;
virtual void GetLowResColorSample( float s, float t, float *color ) const = 0;
// This computes the state snapshots for this material
virtual void RecomputeStateSnapshots() = 0;
// Are we translucent?
virtual bool IsTranslucent() = 0;
// Are we alphatested?
virtual bool IsAlphaTested() = 0;
// Are we vertex lit?
virtual bool IsVertexLit() = 0;
// Gets the vertex format
virtual VertexFormat_t GetVertexFormat() const = 0;
// returns true if this material uses a material proxy
virtual bool HasProxy( void ) const = 0;
virtual bool UsesEnvCubemap( void ) = 0;
virtual bool NeedsTangentSpace( void ) = 0;
virtual bool NeedsPowerOfTwoFrameBufferTexture( bool bCheckSpecificToThisFrame = true ) = 0;
virtual bool NeedsFullFrameBufferTexture( bool bCheckSpecificToThisFrame = true ) = 0;
// returns true if the shader doesn't do skinning itself and requires
// the data that is sent to it to be preskinned.
virtual bool NeedsSoftwareSkinning( void ) = 0;
// Apply constant color or alpha modulation
virtual void AlphaModulate( float alpha ) = 0;
virtual void ColorModulate( float r, float g, float b ) = 0;
// Material Var flags...
virtual void SetMaterialVarFlag( MaterialVarFlags_t flag, bool on ) = 0;
virtual bool GetMaterialVarFlag( MaterialVarFlags_t flag ) const = 0;
// Gets material reflectivity
virtual void GetReflectivity( Vector& reflect ) = 0;
// Gets material property flags
virtual bool GetPropertyFlag( MaterialPropertyTypes_t type ) = 0;
// Is the material visible from both sides?
virtual bool IsTwoSided() = 0;
// Sets the shader associated with the material
virtual void SetShader( const char *pShaderName ) = 0;
// Can't be const because the material might have to precache itself.
virtual int GetNumPasses( void ) = 0;
// Can't be const because the material might have to precache itself.
virtual int GetTextureMemoryBytes( void ) = 0;
// 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() = 0;
// GR - returns true is material uses lightmap alpha for blending
virtual bool NeedsLightmapBlendAlpha( void ) = 0;
// 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 ) = 0;
// Gets at the shader parameters
virtual int ShaderParamCount() const = 0;
virtual IMaterialVar **GetShaderParams( void ) = 0;
// Returns true if this is the error material you get back from IMaterialSystem::FindMaterial if
// the material can't be found.
virtual bool IsErrorMaterial() const = 0;
virtual void SetUseFixedFunctionBakedLighting( bool bEnable ) = 0;
// Gets the current alpha modulation
virtual float GetAlphaModulation() = 0;
virtual void GetColorModulation( float *r, float *g, float *b ) = 0;
// Gets the morph format
virtual MorphFormat_t GetMorphFormat() const = 0;
// fast find that stores the index of the found var in the string table in local cache
virtual IMaterialVar * FindVarFast( char const *pVarName, unsigned int *pToken ) = 0;
// Sets new VMT shader parameters for the material
virtual void SetShaderAndParams( KeyValues *pKeyValues ) = 0;
virtual const char * GetShaderName() const = 0;
virtual void DeleteIfUnreferenced() = 0;
virtual bool IsSpriteCard() = 0;
virtual void CallBindProxy( void *proxyData ) = 0;
virtual IMaterial *CheckProxyReplacement( void *proxyData ) = 0;
virtual void RefreshPreservingMaterialVars() = 0;
virtual bool WasReloadedFromWhitelist() = 0;
virtual bool IsPrecached() const = 0;
};
inline bool IsErrorMaterial( IMaterial *pMat )
{
return !pMat || pMat->IsErrorMaterial();
}
#endif // IMATERIAL_H

View File

@ -0,0 +1,32 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef IMATERIALPROXY_H
#define IMATERIALPROXY_H
#pragma once
#include "interface.h"
#define IMATERIAL_PROXY_INTERFACE_VERSION "_IMaterialProxy003"
class IMaterial;
class KeyValues;
abstract_class IMaterialProxy
{
public:
virtual bool Init( IMaterial* pMaterial, KeyValues *pKeyValues ) = 0;
virtual void OnBind( void * ) = 0;
virtual void Release() = 0;
virtual IMaterial * GetMaterial() = 0;
protected:
// no one should call this directly
virtual ~IMaterialProxy() {}
};
#endif // IMATERIALPROXY_H

View File

@ -0,0 +1,25 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef IMATERIALPROXYFACTORY_H
#define IMATERIALPROXYFACTORY_H
#pragma once
#include "interface.h"
#define IMATERIAL_PROXY_FACTOR_INTERFACE_VERSION "IMaterialProxyFactory001"
class IMaterialProxy;
abstract_class IMaterialProxyFactory
{
public:
virtual IMaterialProxy *CreateProxy( const char *proxyName ) = 0;
virtual void DeleteProxy( IMaterialProxy *pProxy ) = 0;
};
#endif // IMATERIALPROXYFACTORY_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,212 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $Header: $
// $NoKeywords: $
//===========================================================================//
#ifndef IMATERIALSYSTEMHARDWARECONFIG_H
#define IMATERIALSYSTEMHARDWARECONFIG_H
#ifdef _WIN32
#pragma once
#endif
#include "tier1/interface.h"
//-----------------------------------------------------------------------------
// GL helpers
//-----------------------------------------------------------------------------
FORCEINLINE bool IsEmulatingGL()
{
static bool bIsEmulatingGL = ( Plat_GetCommandLineA() ) ? ( strstr( Plat_GetCommandLineA(), "-r_emulate_gl" ) != NULL ) : false;
return bIsEmulatingGL;
}
FORCEINLINE bool IsOpenGL( void )
{
return IsPlatformOpenGL() || IsEmulatingGL();
}
//-----------------------------------------------------------------------------
// Material system interface version
//-----------------------------------------------------------------------------
#define MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION "MaterialSystemHardwareConfig012"
// HDRFIXME NOTE: must match common_ps_fxc.h
enum HDRType_t
{
HDR_TYPE_NONE,
HDR_TYPE_INTEGER,
HDR_TYPE_FLOAT,
};
// For now, vertex compression is simply "on or off" (for the sake of simplicity
// and MeshBuilder perf.), but later we may support multiple flavours.
enum VertexCompressionType_t
{
// This indicates an uninitialized VertexCompressionType_t value
VERTEX_COMPRESSION_INVALID = 0xFFFFFFFF,
// 'VERTEX_COMPRESSION_NONE' means that no elements of a vertex are compressed
VERTEX_COMPRESSION_NONE = 0,
// Currently (more stuff may be added as needed), 'VERTEX_COMPRESSION_ON' means:
// - if a vertex contains VERTEX_ELEMENT_NORMAL, this is compressed
// (see CVertexBuilder::CompressedNormal3f)
// - if a vertex contains VERTEX_ELEMENT_USERDATA4 (and a normal - together defining a tangent
// frame, with the binormal reconstructed in the vertex shader), this is compressed
// (see CVertexBuilder::CompressedUserData)
// - if a vertex contains VERTEX_ELEMENT_BONEWEIGHTSx, this is compressed
// (see CVertexBuilder::CompressedBoneWeight3fv)
VERTEX_COMPRESSION_ON = 1
};
// use DEFCONFIGMETHOD to define time-critical methods that we want to make just return constants
// on the 360, so that the checks will happen at compile time. Not all methods are defined this way
// - just the ones that I perceive as being called often in the frame interval.
#ifdef _X360
#define DEFCONFIGMETHOD( ret_type, method, xbox_return_value ) \
FORCEINLINE ret_type method const \
{ \
return xbox_return_value; \
}
#else
#define DEFCONFIGMETHOD( ret_type, method, xbox_return_value ) \
virtual ret_type method const = 0;
#endif
//-----------------------------------------------------------------------------
// Material system configuration
//-----------------------------------------------------------------------------
class IMaterialSystemHardwareConfig
{
public:
// on xbox, some methods are inlined to return constants
DEFCONFIGMETHOD( bool, HasDestAlphaBuffer(), true );
DEFCONFIGMETHOD( bool, HasStencilBuffer(), true );
virtual int GetFrameBufferColorDepth() const = 0;
virtual int GetSamplerCount() const = 0;
virtual bool HasSetDeviceGammaRamp() const = 0;
DEFCONFIGMETHOD( bool, SupportsCompressedTextures(), true );
virtual VertexCompressionType_t SupportsCompressedVertices() const = 0;
DEFCONFIGMETHOD( bool, SupportsNormalMapCompression(), true );
DEFCONFIGMETHOD( bool, SupportsVertexAndPixelShaders(), true );
DEFCONFIGMETHOD( bool, SupportsPixelShaders_1_4(), true );
DEFCONFIGMETHOD( bool, SupportsStaticControlFlow(), true );
DEFCONFIGMETHOD( bool, SupportsPixelShaders_2_0(), true );
DEFCONFIGMETHOD( bool, SupportsVertexShaders_2_0(), true );
virtual int MaximumAnisotropicLevel() const = 0; // 0 means no anisotropic filtering
virtual int MaxTextureWidth() const = 0;
virtual int MaxTextureHeight() const = 0;
virtual int TextureMemorySize() const = 0;
virtual bool SupportsOverbright() const = 0;
virtual bool SupportsCubeMaps() const = 0;
virtual bool SupportsMipmappedCubemaps() const = 0;
virtual bool SupportsNonPow2Textures() const = 0;
// The number of texture stages represents the number of computations
// we can do in the fixed-function pipeline, it is *not* related to the
// simultaneous number of textures we can use
virtual int GetTextureStageCount() const = 0;
virtual int NumVertexShaderConstants() const = 0;
virtual int NumPixelShaderConstants() const = 0;
virtual int MaxNumLights() const = 0;
virtual bool SupportsHardwareLighting() const = 0;
virtual int MaxBlendMatrices() const = 0;
virtual int MaxBlendMatrixIndices() const = 0;
virtual int MaxTextureAspectRatio() const = 0;
virtual int MaxVertexShaderBlendMatrices() const = 0;
virtual int MaxUserClipPlanes() const = 0;
virtual bool UseFastClipping() const = 0;
// This here should be the major item looked at when checking for compat
// from anywhere other than the material system shaders
DEFCONFIGMETHOD( int, GetDXSupportLevel(), 98 );
virtual const char *GetShaderDLLName() const = 0;
virtual bool ReadPixelsFromFrontBuffer() const = 0;
// Are dx dynamic textures preferred?
virtual bool PreferDynamicTextures() const = 0;
DEFCONFIGMETHOD( bool, SupportsHDR(), true );
virtual bool HasProjectedBumpEnv() const = 0;
virtual bool SupportsSpheremapping() const = 0;
virtual bool NeedsAAClamp() const = 0;
virtual bool NeedsATICentroidHack() const = 0;
virtual bool SupportsColorOnSecondStream() const = 0;
virtual bool SupportsStaticPlusDynamicLighting() const = 0;
// Does our card have a hard time with fillrate
// relative to other cards w/ the same dx level?
virtual bool PreferReducedFillrate() const = 0;
// This is the max dx support level supported by the card
virtual int GetMaxDXSupportLevel() const = 0;
// Does the card specify fog color in linear space when sRGBWrites are enabled?
virtual bool SpecifiesFogColorInLinearSpace() const = 0;
// Does the card support sRGB reads/writes?
DEFCONFIGMETHOD( bool, SupportsSRGB(), true );
DEFCONFIGMETHOD( bool, FakeSRGBWrite(), false );
DEFCONFIGMETHOD( bool, CanDoSRGBReadFromRTs(), true );
virtual bool SupportsGLMixedSizeTargets() const = 0;
virtual bool IsAAEnabled() const = 0; // Is antialiasing being used?
// NOTE: Anything after this was added after shipping HL2.
virtual int GetVertexTextureCount() const = 0;
virtual int GetMaxVertexTextureDimension() const = 0;
virtual int MaxTextureDepth() const = 0;
virtual HDRType_t GetHDRType() const = 0;
virtual HDRType_t GetHardwareHDRType() const = 0;
DEFCONFIGMETHOD( bool, SupportsPixelShaders_2_b(), true );
virtual bool SupportsStreamOffset() const = 0;
virtual int StencilBufferBits() const = 0;
virtual int MaxViewports() const = 0;
virtual void OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport ) = 0;
virtual int GetShadowFilterMode() const = 0;
virtual int NeedsShaderSRGBConversion() const = 0;
DEFCONFIGMETHOD( bool, UsesSRGBCorrectBlending(), true );
virtual bool SupportsShaderModel_3_0() const = 0;
virtual bool HasFastVertexTextures() const = 0;
virtual int MaxHWMorphBatchCount() const = 0;
// Does the board actually support this?
DEFCONFIGMETHOD( bool, ActuallySupportsPixelShaders_2_b(), true );
virtual bool SupportsHDRMode( HDRType_t nHDRMode ) const = 0;
virtual bool GetHDREnabled( void ) const = 0;
virtual void SetHDREnabled( bool bEnable ) = 0;
virtual bool SupportsBorderColor( void ) const = 0;
virtual bool SupportsFetch4( void ) const = 0;
inline bool ShouldAlwaysUseShaderModel2bShaders() const { return IsOpenGL(); }
inline bool PlatformRequiresNonNullPixelShaders() const { return IsOpenGL(); }
};
#endif // IMATERIALSYSTEMHARDWARECONFIG_H

View File

@ -0,0 +1,31 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#ifndef IMATERIALSYSTEMSTUB_H
#define IMATERIALSYSTEMSTUB_H
#ifdef _WIN32
#pragma once
#endif
#include "materialsystem/imaterialsystem.h"
// If you get this interface out of the material system, it'll return an IMaterialSystem
// with everything stubbed. This is used for running the client in text mode.
#define MATERIAL_SYSTEM_STUB_INTERFACE_VERSION "VMaterialSystemStub001"
class IMaterialSystemStub : public IMaterialSystem
{
public:
// If this is called, then the stub will call through to the real material
// system in some functions.
virtual void SetRealMaterialSystem( IMaterialSystem *pSys ) = 0;
};
#endif // IMATERIALSYSTEMSTUB_H

View File

@ -0,0 +1,245 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef IMATERIALVAR_H
#define IMATERIALVAR_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/platform.h"
#include "tier1/utlsymbol.h"
#include "mathlib/vector4d.h"
class IMaterial;
class VMatrix;
class ITexture;
#define MAKE_MATERIALVAR_FOURCC(ch0, ch1, ch2, ch3) \
((unsigned long)(ch0) | ((unsigned long)(ch1) << 8) | \
((unsigned long)(ch2) << 16) | ((unsigned long)(ch3) << 24 ))
// This fourcc is reserved.
#define FOURCC_UNKNOWN MAKE_MATERIALVAR_FOURCC('U','N','K','N')
//-----------------------------------------------------------------------------
// Various material var types
//-----------------------------------------------------------------------------
enum MaterialVarType_t
{
MATERIAL_VAR_TYPE_FLOAT = 0,
MATERIAL_VAR_TYPE_STRING,
MATERIAL_VAR_TYPE_VECTOR,
MATERIAL_VAR_TYPE_TEXTURE,
MATERIAL_VAR_TYPE_INT,
MATERIAL_VAR_TYPE_FOURCC,
MATERIAL_VAR_TYPE_UNDEFINED,
MATERIAL_VAR_TYPE_MATRIX,
MATERIAL_VAR_TYPE_MATERIAL,
};
typedef unsigned short MaterialVarSym_t;
class IMaterialVar
{
public:
typedef unsigned long FourCC;
protected:
// base data and accessors
char* m_pStringVal;
int m_intVal;
Vector4D m_VecVal;
// member data. total = 4 bytes
uint8 m_Type : 4;
uint8 m_nNumVectorComps : 3;
uint8 m_bFakeMaterialVar : 1;
uint8 m_nTempIndex;
CUtlSymbol m_Name;
public:
// class factory methods
static IMaterialVar* Create( IMaterial* pMaterial, char const* pKey, VMatrix const& matrix );
static IMaterialVar* Create( IMaterial* pMaterial, char const* pKey, char const* pVal );
static IMaterialVar* Create( IMaterial* pMaterial, char const* pKey, float* pVal, int numcomps );
static IMaterialVar* Create( IMaterial* pMaterial, char const* pKey, float val );
static IMaterialVar* Create( IMaterial* pMaterial, char const* pKey, int val );
static IMaterialVar* Create( IMaterial* pMaterial, char const* pKey );
static void Destroy( IMaterialVar* pVar );
static MaterialVarSym_t GetSymbol( char const* pName );
static MaterialVarSym_t FindSymbol( char const* pName );
static bool SymbolMatches( char const* pName, MaterialVarSym_t symbol );
static void DeleteUnreferencedTextures( bool enable );
virtual ITexture *GetTextureValue( void ) = 0;
virtual char const * GetName( void ) const = 0;
virtual MaterialVarSym_t GetNameAsSymbol() const = 0;
virtual void SetFloatValue( float val ) = 0;
virtual void SetIntValue( int val ) = 0;
virtual void SetStringValue( char const *val ) = 0;
virtual char const * GetStringValue( void ) const = 0;
// 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 ) = 0;
virtual void GetFourCCValue( FourCC *type, void **ppData ) = 0;
// Vec (dim 2-4)
virtual void SetVecValue( float const* val, int numcomps ) = 0;
virtual void SetVecValue( float x, float y ) = 0;
virtual void SetVecValue( float x, float y, float z ) = 0;
virtual void SetVecValue( float x, float y, float z, float w ) = 0;
virtual void GetLinearVecValue( float *val, int numcomps ) const = 0;
// revisit: is this a good interface for textures?
virtual void SetTextureValue( ITexture * ) = 0;
virtual IMaterial * GetMaterialValue( void ) = 0;
virtual void SetMaterialValue( IMaterial * ) = 0;
virtual bool IsDefined() const = 0;
virtual void SetUndefined() = 0;
// Matrix
virtual void SetMatrixValue( VMatrix const& matrix ) = 0;
virtual const VMatrix &GetMatrixValue( ) = 0;
virtual bool MatrixIsIdentity() const = 0;
// Copy....
virtual void CopyFrom( IMaterialVar *pMaterialVar ) = 0;
virtual void SetValueAutodetectType( char const *val ) = 0;
virtual IMaterial * GetOwningMaterial() = 0;
//set just 1 component
virtual void SetVecComponentValue( float fVal, int nComponent ) = 0;
protected:
virtual int GetIntValueInternal( void ) const = 0;
virtual float GetFloatValueInternal( void ) const = 0;
virtual float const* GetVecValueInternal( ) const = 0;
virtual void GetVecValueInternal( float *val, int numcomps ) const = 0;
virtual int VectorSizeInternal() const = 0;
public:
FORCEINLINE MaterialVarType_t GetType( void ) const
{
return ( MaterialVarType_t )m_Type;
}
FORCEINLINE bool IsTexture() const
{
return m_Type == MATERIAL_VAR_TYPE_TEXTURE;
}
FORCEINLINE operator ITexture*()
{
return GetTextureValue();
}
// NOTE: Fast methods should only be called in thread-safe situations
FORCEINLINE int GetIntValueFast( void ) const
{
// Set methods for float and vector update this
return m_intVal;
}
FORCEINLINE float GetFloatValueFast( void ) const
{
return m_VecVal[0];
}
FORCEINLINE float const* GetVecValueFast( ) const
{
return m_VecVal.Base();
}
FORCEINLINE void GetVecValueFast( float *val, int numcomps ) const
{
Assert( ( numcomps >0 ) && ( numcomps <= 4 ) );
for( int i=0 ; i < numcomps; i++ )
{
val[i] = m_VecVal[ i ];
}
}
FORCEINLINE int VectorSizeFast() const
{
return m_nNumVectorComps;
}
#ifdef FAST_MATERIALVAR_ACCESS
FORCEINLINE int GetIntValue( void ) const
{
return GetIntValueFast();
}
FORCEINLINE float GetFloatValue( void ) const
{
return GetFloatValueFast();
}
FORCEINLINE float const* GetVecValue( ) const
{
return GetVecValueFast();
}
FORCEINLINE void GetVecValue( float *val, int numcomps ) const
{
GetVecValueFast( val, numcomps );
}
FORCEINLINE int VectorSize() const
{
return VectorSizeFast();
}
#else // !FAST_MATERIALVAR_ACCESS
FORCEINLINE int GetIntValue( void ) const
{
return GetIntValueInternal();
}
FORCEINLINE float GetFloatValue( void ) const
{
return GetFloatValueInternal();
}
FORCEINLINE float const* GetVecValue( ) const
{
return GetVecValueInternal();
}
FORCEINLINE void GetVecValue( float *val, int numcomps ) const
{
return GetVecValueInternal( val, numcomps );
}
FORCEINLINE int VectorSize() const
{
return VectorSizeInternal();
}
#endif
private:
FORCEINLINE void SetTempIndex( int nIndex )
{
m_nTempIndex = nIndex;
}
friend void EnableThreadedMaterialVarAccess( bool bEnable, IMaterialVar **ppParams, int nVarCount );
};
#endif // IMATERIALVAR_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,251 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// The copyright to the contents herein is the property of Valve, L.L.C.
// The contents may be used and/or copied only with the written permission of
// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
// the agreement/contract under which the contents have been supplied.
//
// $Header: $
// $NoKeywords: $
//
// Interface used to construct morph buffers
//=============================================================================
#ifndef IMORPH_H
#define IMORPH_H
#ifdef _WIN32
#pragma once
#endif
#include "mathlib/vector.h"
#include <float.h>
#include "tier0/dbg.h"
#include "materialsystem/imaterial.h"
//-----------------------------------------------------------------------------
// Single morph data
//-----------------------------------------------------------------------------
struct MorphVertexInfo_t
{
int m_nVertexId; // What vertex is this going to affect?
int m_nMorphTargetId; // What morph did it come from?
Vector m_PositionDelta; // Positional morph delta
Vector m_NormalDelta; // Normal morph delta
float m_flWrinkleDelta; // Wrinkle morph delta
float m_flSpeed;
float m_flSide;
};
//-----------------------------------------------------------------------------
// Morph weight data
//-----------------------------------------------------------------------------
enum MorphWeightType_t
{
MORPH_WEIGHT = 0,
MORPH_WEIGHT_LAGGED,
MORPH_WEIGHT_STEREO,
MORPH_WEIGHT_STEREO_LAGGED,
MORPH_WEIGHT_COUNT,
};
struct MorphWeight_t
{
float m_pWeight[MORPH_WEIGHT_COUNT];
};
//-----------------------------------------------------------------------------
// Interface to the morph
//-----------------------------------------------------------------------------
abstract_class IMorph
{
public:
// Locks the morph, destroys any existing contents
virtual void Lock( float flFloatToFixedScale = 1.0f ) = 0;
// Adds a morph
virtual void AddMorph( const MorphVertexInfo_t &info ) = 0;
// Unlocks the morph
virtual void Unlock( ) = 0;
};
//-----------------------------------------------------------------------------
// Morph builders
//-----------------------------------------------------------------------------
class CMorphBuilder
{
public:
CMorphBuilder();
~CMorphBuilder();
// Start building the morph
void Begin( IMorph *pMorph, float flFloatToFixedScale = 1.0f );
// End building the morph
void End();
void PositionDelta3fv( const float *pDelta );
void PositionDelta3f( float dx, float dy, float dz );
void PositionDelta3( const Vector &vec );
void NormalDelta3fv( const float *pDelta );
void NormalDelta3f( float dx, float dy, float dz );
void NormalDelta3( const Vector &vec );
void WrinkleDelta1f( float flWrinkle );
// Both are 0-1 values indicating which morph target to use (for stereo morph targets)
// and how much to blend between using lagged weights vs actual weights
// Speed: 0 - use lagged, 1 - use actual
void Speed1f( float flSpeed );
void Side1f( float flSide );
void AdvanceMorph( int nSourceVertex, int nMorphTargetId );
private:
MorphVertexInfo_t m_Info;
IMorph *m_pMorph;
};
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
inline CMorphBuilder::CMorphBuilder()
{
m_pMorph = NULL;
}
inline CMorphBuilder::~CMorphBuilder()
{
// You forgot to call End()!
Assert( !m_pMorph );
}
//-----------------------------------------------------------------------------
// Start building the morph
//-----------------------------------------------------------------------------
inline void CMorphBuilder::Begin( IMorph *pMorph, float flFloatToFixedScale )
{
Assert( pMorph && !m_pMorph );
m_pMorph = pMorph;
m_pMorph->Lock( flFloatToFixedScale );
#ifdef _DEBUG
m_Info.m_PositionDelta.Init( VEC_T_NAN, VEC_T_NAN, VEC_T_NAN );
m_Info.m_NormalDelta.Init( VEC_T_NAN, VEC_T_NAN, VEC_T_NAN );
m_Info.m_flWrinkleDelta = VEC_T_NAN;
m_Info.m_flSpeed = VEC_T_NAN;
m_Info.m_flSide = VEC_T_NAN;
#endif
}
// End building the morph
inline void CMorphBuilder::End()
{
Assert( m_pMorph );
m_pMorph->Unlock();
m_pMorph = NULL;
}
//-----------------------------------------------------------------------------
// Set position delta
//-----------------------------------------------------------------------------
inline void CMorphBuilder::PositionDelta3fv( const float *pDelta )
{
Assert( m_pMorph );
m_Info.m_PositionDelta.Init( pDelta[0], pDelta[1], pDelta[2] );
}
inline void CMorphBuilder::PositionDelta3f( float dx, float dy, float dz )
{
Assert( m_pMorph );
m_Info.m_PositionDelta.Init( dx, dy, dz );
}
inline void CMorphBuilder::PositionDelta3( const Vector &vec )
{
Assert( m_pMorph );
m_Info.m_PositionDelta = vec;
}
//-----------------------------------------------------------------------------
// Set normal delta
//-----------------------------------------------------------------------------
inline void CMorphBuilder::NormalDelta3fv( const float *pDelta )
{
Assert( m_pMorph );
m_Info.m_NormalDelta.Init( pDelta[0], pDelta[1], pDelta[2] );
}
inline void CMorphBuilder::NormalDelta3f( float dx, float dy, float dz )
{
Assert( m_pMorph );
m_Info.m_NormalDelta.Init( dx, dy, dz );
}
inline void CMorphBuilder::NormalDelta3( const Vector &vec )
{
Assert( m_pMorph );
m_Info.m_NormalDelta = vec;
}
//-----------------------------------------------------------------------------
// Set wrinkle delta
//-----------------------------------------------------------------------------
inline void CMorphBuilder::WrinkleDelta1f( float flWrinkle )
{
Assert( m_pMorph );
m_Info.m_flWrinkleDelta = flWrinkle;
}
//-----------------------------------------------------------------------------
// Set speed,side data
//-----------------------------------------------------------------------------
inline void CMorphBuilder::Speed1f( float flSpeed )
{
Assert( m_pMorph );
m_Info.m_flSpeed = flSpeed;
}
inline void CMorphBuilder::Side1f( float flSide )
{
Assert( m_pMorph );
m_Info.m_flSide = flSide;
}
//-----------------------------------------------------------------------------
// Advance morph
//-----------------------------------------------------------------------------
inline void CMorphBuilder::AdvanceMorph( int nSourceVertex, int nMorphTargetId )
{
Assert( m_pMorph );
m_Info.m_nVertexId = nSourceVertex;
m_Info.m_nMorphTargetId = nMorphTargetId;
m_pMorph->AddMorph( m_Info );
#ifdef _DEBUG
m_Info.m_PositionDelta.Init( VEC_T_NAN, VEC_T_NAN, VEC_T_NAN );
m_Info.m_NormalDelta.Init( VEC_T_NAN, VEC_T_NAN, VEC_T_NAN );
m_Info.m_flWrinkleDelta = VEC_T_NAN;
m_Info.m_flSpeed = VEC_T_NAN;
m_Info.m_flSide = VEC_T_NAN;
#endif
}
#endif // IMORPH_H

View File

@ -0,0 +1,43 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: NOTE: This file is for backward compat!
// We'll get rid of it soon. Most of the contents of this file were moved
// into shaderpi/ishadershadow.h, shaderapi/ishaderdynamic.h, or
// shaderapi/shareddefs.h
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef ISHADERAPI_MS_H
#define ISHADERAPI_MS_H
#ifdef _WIN32
#pragma once
#endif
#include <shaderapi/shareddefs.h>
#include <shaderapi/ishadershadow.h>
#include <shaderapi/ishaderdynamic.h>
//-----------------------------------------------------------------------------
// forward declarations
//-----------------------------------------------------------------------------
class IMaterialVar;
//-----------------------------------------------------------------------------
// Methods that can be called from the SHADER_INIT blocks of shaders
//-----------------------------------------------------------------------------
abstract_class IShaderInit
{
public:
// Loads up a texture
virtual void LoadTexture( IMaterialVar *pTextureVar, const char *pTextureGroupName, int nAdditionalCreationFlags = 0 ) = 0;
virtual void LoadBumpMap( IMaterialVar *pTextureVar, const char *pTextureGroupName ) = 0;
virtual void LoadCubeMap( IMaterialVar **ppParams, IMaterialVar *pTextureVar, int nAdditionalCreationFlags = 0 ) = 0;
};
#endif // ISHADERAPI_MS_H

View File

@ -0,0 +1,132 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef ITEXTURE_H
#define ITEXTURE_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/platform.h"
#include "bitmap/imageformat.h" // ImageFormat defn.
class IVTFTexture;
class ITexture;
struct Rect_t;
//-----------------------------------------------------------------------------
// This will get called on procedural textures to re-fill the textures
// with the appropriate bit pattern. Calling Download() will also
// cause this interface to be called. It will also be called upon
// mode switch, or on other occasions where the bits are discarded.
//-----------------------------------------------------------------------------
abstract_class ITextureRegenerator
{
public:
// This will be called when the texture bits need to be regenerated.
// Use the VTFTexture interface, which has been set up with the
// appropriate texture size + format
// The rect specifies which part of the texture needs to be updated
// You can choose to update all of the bits if you prefer
virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pRect ) = 0;
// This will be called when the regenerator needs to be deleted
// which will happen when the texture is destroyed
virtual void Release() = 0;
};
abstract_class ITexture
{
public:
// Various texture polling methods
virtual const char *GetName( void ) const = 0;
virtual int GetMappingWidth() const = 0;
virtual int GetMappingHeight() const = 0;
virtual int GetActualWidth() const = 0;
virtual int GetActualHeight() const = 0;
virtual int GetNumAnimationFrames() const = 0;
virtual bool IsTranslucent() const = 0;
virtual bool IsMipmapped() const = 0;
virtual void GetLowResColorSample( float s, float t, float *color ) const = 0;
// Gets texture resource data of the specified type.
// Params:
// eDataType type of resource to retrieve.
// pnumBytes on return is the number of bytes available in the read-only data buffer or is undefined
// Returns:
// pointer to the resource data, or NULL
virtual void *GetResourceData( uint32 eDataType, size_t *pNumBytes ) const = 0;
// Methods associated with reference count
virtual void IncrementReferenceCount( void ) = 0;
virtual void DecrementReferenceCount( void ) = 0;
inline void AddRef() { IncrementReferenceCount(); }
inline void Release() { DecrementReferenceCount(); }
// Used to modify the texture bits (procedural textures only)
virtual void SetTextureRegenerator( ITextureRegenerator *pTextureRegen ) = 0;
// Reconstruct the texture bits in HW memory
// If rect is not specified, reconstruct all bits, otherwise just
// reconstruct a subrect.
virtual void Download( Rect_t *pRect = 0, int nAdditionalCreationFlags = 0 ) = 0;
// Uses for stats. . .get the approximate size of the texture in it's current format.
virtual int GetApproximateVidMemBytes( void ) const = 0;
// Returns true if the texture data couldn't be loaded.
virtual bool IsError() const = 0;
// NOTE: Stuff after this is added after shipping HL2.
// For volume textures
virtual bool IsVolumeTexture() const = 0;
virtual int GetMappingDepth() const = 0;
virtual int GetActualDepth() const = 0;
virtual ImageFormat GetImageFormat() const = 0;
virtual NormalDecodeMode_t GetNormalDecodeMode() const = 0;
// Various information about the texture
virtual bool IsRenderTarget() const = 0;
virtual bool IsCubeMap() const = 0;
virtual bool IsNormalMap() const = 0;
virtual bool IsProcedural() const = 0;
virtual void DeleteIfUnreferenced() = 0;
#if defined( _X360 )
virtual bool ClearTexture( int r, int g, int b, int a ) = 0;
virtual bool CreateRenderTargetSurface( int width, int height, ImageFormat format, bool bSameAsTexture ) = 0;
#endif
// swap everything except the name with another texture
virtual void SwapContents( ITexture *pOther ) = 0;
// Retrieve the vtf flags mask
virtual unsigned int GetFlags( void ) const = 0;
// Force LOD override (automatically downloads the texture)
virtual void ForceLODOverride( int iNumLodsOverrideUpOrDown ) = 0;
// Save texture to a file.
virtual bool SaveToFile( const char *fileName ) = 0;
};
inline bool IsErrorTexture( ITexture *pTex )
{
return !pTex || pTex->IsError();
}
#endif // ITEXTURE_H

View File

@ -0,0 +1,35 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: tracks VB allocations (and compressed/uncompressed vertex memory usage)
//
//===========================================================================//
#ifndef IVBALLOCTRACKER_H
#define IVBALLOCTRACKER_H
#include "materialsystem/imaterialsystem.h"
// By default, only enable this alloc tracking for a debug shaderapidx*.dll
// (it uses about 0.25MB to track ~7000 allocations)
#if defined(_DEBUG)
#define ENABLE_VB_ALLOC_TRACKER 1
#else
#define ENABLE_VB_ALLOC_TRACKER 0
#endif
// This interface is actually exported by the shader API DLL.
#define VB_ALLOC_TRACKER_INTERFACE_VERSION "VBAllocTracker001"
// Interface to the VB mem alloc tracker
abstract_class IVBAllocTracker
{
public:
// This should be called wherever VertexBuffers are allocated
virtual void CountVB( void * buffer, bool isDynamic, int bufferSize, int vertexSize, VertexFormat_t fmt ) = 0;
// This should be called wherever VertexBuffers are freed
virtual void UnCountVB( void * buffer ) = 0;
// Track mesh allocations (set this before an allocation, clear it after)
virtual bool TrackMeshAllocations( const char * allocatorName ) = 0;
};
#endif // IVBALLOCTRACKER_H

View File

@ -0,0 +1,219 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#ifndef MATERIALSYSTEM_CONFIG_H
#define MATERIALSYSTEM_CONFIG_H
#ifdef _WIN32
#pragma once
#endif
#include "materialsystem/imaterialsystem.h"
#define MATERIALSYSTEM_CONFIG_VERSION "VMaterialSystemConfig002"
enum MaterialSystem_Config_Flags_t
{
MATSYS_VIDCFG_FLAGS_WINDOWED = ( 1 << 0 ),
MATSYS_VIDCFG_FLAGS_RESIZING = ( 1 << 1 ),
MATSYS_VIDCFG_FLAGS_NO_WAIT_FOR_VSYNC = ( 1 << 3 ),
MATSYS_VIDCFG_FLAGS_STENCIL = ( 1 << 4 ),
MATSYS_VIDCFG_FLAGS_FORCE_TRILINEAR = ( 1 << 5 ),
MATSYS_VIDCFG_FLAGS_FORCE_HWSYNC = ( 1 << 6 ),
MATSYS_VIDCFG_FLAGS_DISABLE_SPECULAR = ( 1 << 7 ),
MATSYS_VIDCFG_FLAGS_DISABLE_BUMPMAP = ( 1 << 8 ),
MATSYS_VIDCFG_FLAGS_ENABLE_PARALLAX_MAPPING = ( 1 << 9 ),
MATSYS_VIDCFG_FLAGS_USE_Z_PREFILL = ( 1 << 10 ),
MATSYS_VIDCFG_FLAGS_REDUCE_FILLRATE = ( 1 << 11 ),
MATSYS_VIDCFG_FLAGS_ENABLE_HDR = ( 1 << 12 ),
MATSYS_VIDCFG_FLAGS_LIMIT_WINDOWED_SIZE = ( 1 << 13 ),
MATSYS_VIDCFG_FLAGS_SCALE_TO_OUTPUT_RESOLUTION = ( 1 << 14 ),
MATSYS_VIDCFG_FLAGS_USING_MULTIPLE_WINDOWS = ( 1 << 15 ),
};
struct MaterialSystemHardwareIdentifier_t
{
char *m_pCardName;
unsigned int m_nVendorID;
unsigned int m_nDeviceID;
};
struct MaterialSystem_Config_t
{
bool Windowed() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_WINDOWED ) != 0; }
bool Resizing() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_RESIZING ) != 0; }
#ifdef CSS_PERF_TEST
bool WaitForVSync() const { return false; }//( m_Flags & MATSYS_VIDCFG_FLAGS_NO_WAIT_FOR_VSYNC ) == 0; }
#else
bool WaitForVSync() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_NO_WAIT_FOR_VSYNC ) == 0; }
#endif
bool Stencil() const { return (m_Flags & MATSYS_VIDCFG_FLAGS_STENCIL ) != 0; }
bool ForceTrilinear() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_FORCE_TRILINEAR ) != 0; }
bool ForceHWSync() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_FORCE_HWSYNC ) != 0; }
bool UseSpecular() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_DISABLE_SPECULAR ) == 0; }
bool UseBumpmapping() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_DISABLE_BUMPMAP ) == 0; }
bool UseParallaxMapping() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_ENABLE_PARALLAX_MAPPING ) != 0; }
bool UseZPrefill() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_USE_Z_PREFILL ) != 0; }
bool ReduceFillrate() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_REDUCE_FILLRATE ) != 0; }
bool HDREnabled() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_ENABLE_HDR ) != 0; }
bool LimitWindowedSize() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_LIMIT_WINDOWED_SIZE ) != 0; }
bool ScaleToOutputResolution() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_SCALE_TO_OUTPUT_RESOLUTION ) != 0; }
bool UsingMultipleWindows() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_USING_MULTIPLE_WINDOWS ) != 0; }
bool ShadowDepthTexture() const { return m_bShadowDepthTexture; }
bool MotionBlur() const { return m_bMotionBlur; }
bool SupportFlashlight() const { return m_bSupportFlashlight; }
void SetFlag( unsigned int flag, bool val )
{
if( val )
{
m_Flags |= flag;
}
else
{
m_Flags &= ~flag;
}
}
// control panel stuff
MaterialVideoMode_t m_VideoMode;
float m_fMonitorGamma;
float m_fGammaTVRangeMin;
float m_fGammaTVRangeMax;
float m_fGammaTVExponent;
bool m_bGammaTVEnabled;
int m_nAASamples;
int m_nForceAnisotropicLevel;
int skipMipLevels;
int dxSupportLevel;
unsigned int m_Flags;
bool bEditMode; // true if in Hammer.
unsigned char proxiesTestMode; // 0 = normal, 1 = no proxies, 2 = alpha test all, 3 = color mod all
bool bCompressedTextures;
bool bFilterLightmaps;
bool bFilterTextures;
bool bReverseDepth;
bool bBufferPrimitives;
bool bDrawFlat;
bool bMeasureFillRate;
bool bVisualizeFillRate;
bool bNoTransparency;
bool bSoftwareLighting;
bool bAllowCheats;
char nShowMipLevels;
bool bShowLowResImage;
bool bShowNormalMap;
bool bMipMapTextures;
unsigned char nFullbright;
bool m_bFastNoBump;
bool m_bSuppressRendering;
// debug modes
bool bShowSpecular; // This is the fast version that doesn't require reloading materials
bool bShowDiffuse; // This is the fast version that doesn't require reloading materials
// misc
int m_nReserved; // Currently unused
// No depth bias
float m_SlopeScaleDepthBias_Normal;
float m_DepthBias_Normal;
// Depth bias for rendering decals closer to the camera
float m_SlopeScaleDepthBias_Decal;
float m_DepthBias_Decal;
// Depth bias for biasing shadow depth map rendering away from the camera
float m_SlopeScaleDepthBias_ShadowMap;
float m_DepthBias_ShadowMap;
uint m_WindowedSizeLimitWidth;
uint m_WindowedSizeLimitHeight;
int m_nAAQuality;
bool m_bShadowDepthTexture;
bool m_bMotionBlur;
bool m_bSupportFlashlight;
MaterialSystem_Config_t()
{
memset( this, 0, sizeof( *this ) );
// video config defaults
SetFlag( MATSYS_VIDCFG_FLAGS_WINDOWED, false );
SetFlag( MATSYS_VIDCFG_FLAGS_RESIZING, false );
SetFlag( MATSYS_VIDCFG_FLAGS_NO_WAIT_FOR_VSYNC, true );
SetFlag( MATSYS_VIDCFG_FLAGS_STENCIL, false );
SetFlag( MATSYS_VIDCFG_FLAGS_FORCE_TRILINEAR, true );
SetFlag( MATSYS_VIDCFG_FLAGS_FORCE_HWSYNC, true );
SetFlag( MATSYS_VIDCFG_FLAGS_DISABLE_SPECULAR, false );
SetFlag( MATSYS_VIDCFG_FLAGS_DISABLE_BUMPMAP, false );
SetFlag( MATSYS_VIDCFG_FLAGS_ENABLE_PARALLAX_MAPPING, true );
SetFlag( MATSYS_VIDCFG_FLAGS_USE_Z_PREFILL, false );
SetFlag( MATSYS_VIDCFG_FLAGS_REDUCE_FILLRATE, false );
SetFlag( MATSYS_VIDCFG_FLAGS_LIMIT_WINDOWED_SIZE, false );
SetFlag( MATSYS_VIDCFG_FLAGS_SCALE_TO_OUTPUT_RESOLUTION, false );
SetFlag( MATSYS_VIDCFG_FLAGS_USING_MULTIPLE_WINDOWS, false );
m_VideoMode.m_Width = 640;
m_VideoMode.m_Height = 480;
m_VideoMode.m_RefreshRate = 60;
dxSupportLevel = 0;
bCompressedTextures = true;
bFilterTextures = true;
bFilterLightmaps = true;
bMipMapTextures = true;
bBufferPrimitives = true;
m_fMonitorGamma = 2.2f;
m_fGammaTVRangeMin = 16.0f;
m_fGammaTVRangeMax = 255.0f;
m_fGammaTVExponent = 2.5;
m_bGammaTVEnabled = IsX360();
m_nAASamples = 1;
m_bShadowDepthTexture = false;
m_bMotionBlur = false;
m_bSupportFlashlight = true;
// misc defaults
bAllowCheats = false;
bCompressedTextures = true;
bEditMode = false;
// debug modes
bShowSpecular = true;
bShowDiffuse = true;
nFullbright = 0;
bShowNormalMap = false;
bFilterLightmaps = true;
bFilterTextures = true;
bMipMapTextures = true;
nShowMipLevels = 0;
bShowLowResImage = false;
bReverseDepth = false;
bBufferPrimitives = true;
bDrawFlat = false;
bMeasureFillRate = false;
bVisualizeFillRate = false;
bSoftwareLighting = false;
bNoTransparency = false;
proxiesTestMode = 0;
m_bFastNoBump = false;
m_bSuppressRendering = false;
m_SlopeScaleDepthBias_Decal = -0.5f;
m_SlopeScaleDepthBias_Normal = 0.0f;
m_SlopeScaleDepthBias_ShadowMap = 0.5f;
m_DepthBias_Decal = -262144;
m_DepthBias_Normal = 0.0f;
m_DepthBias_ShadowMap = 262144;
m_WindowedSizeLimitWidth = 1280;
m_WindowedSizeLimitHeight = 1024;
}
};
#endif // MATERIALSYSTEM_CONFIG_H

View File

@ -0,0 +1,268 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=====================================================================================//
#ifndef MESHREADER_H
#define MESHREADER_H
#ifdef _WIN32
#pragma once
#endif
//-----------------------------------------------------------------------------
// This is used to read vertex and index data out of already-created meshes.
// xbox uses this a lot so it doesn't have to store sysmem backups of the
// vertex data.
//-----------------------------------------------------------------------------
class CBaseMeshReader : protected MeshDesc_t
{
// Initialization.
public:
CBaseMeshReader();
~CBaseMeshReader();
// Use BeginRead/EndRead to initialize the mesh reader.
void BeginRead(
IMesh* pMesh,
int firstVertex = 0,
int numVertices = 0,
int firstIndex = 0,
int numIndices = 0 );
void EndRead();
// PC can use this if it stores its own copy of meshes around, in case
// locking static buffers is too costly.
void BeginRead_Direct( const MeshDesc_t &desc, int numVertices, int nIndices );
// Resets the mesh builder so it points to the start of everything again
void Reset();
protected:
IMesh *m_pMesh;
int m_MaxVertices;
int m_MaxIndices;
};
// A bunch of accessors for the data that CBaseMeshReader sets up.
class CMeshReader : public CBaseMeshReader
{
public:
// Access to vertex data.
public:
int NumIndices() const;
unsigned short Index( int index ) const;
const Vector& Position( int iVertex ) const;
unsigned int Color( int iVertex ) const;
const float *TexCoord( int iVertex, int stage ) const;
void TexCoord2f( int iVertex, int stage, float &s, float &t ) const;
const Vector2D& TexCoordVector2D( int iVertex, int stage ) const;
int NumBoneWeights() const;
float Wrinkle( int iVertex ) const;
const Vector &Normal( int iVertex ) const;
void Normal( int iVertex, Vector &vNormal ) const;
const Vector &TangentS( int iVertex ) const;
const Vector &TangentT( int iVertex ) const;
float BoneWeight( int iVertex ) const;
#ifdef NEW_SKINNING
float* BoneMatrix( int iVertex ) const;
#else
unsigned char* BoneMatrix( int iVertex ) const;
#endif
};
//-----------------------------------------------------------------------------
// CBaseMeshReader implementation.
//-----------------------------------------------------------------------------
inline CBaseMeshReader::CBaseMeshReader()
{
m_pMesh = NULL;
}
inline CBaseMeshReader::~CBaseMeshReader()
{
Assert( !m_pMesh );
}
inline void CBaseMeshReader::BeginRead(
IMesh* pMesh,
int firstVertex,
int numVertices,
int firstIndex,
int numIndices )
{
Assert( pMesh && (!m_pMesh) );
if ( numVertices < 0 )
{
numVertices = pMesh->VertexCount();
}
if ( numIndices < 0 )
{
numIndices = pMesh->IndexCount();
}
m_pMesh = pMesh;
m_MaxVertices = numVertices;
m_MaxIndices = numIndices;
// UNDONE: support reading from compressed VBs if needed
VertexCompressionType_t compressionType = CompressionType( pMesh->GetVertexFormat() );
Assert( compressionType == VERTEX_COMPRESSION_NONE );
if ( compressionType != VERTEX_COMPRESSION_NONE )
{
Warning( "Cannot use CBaseMeshReader with compressed vertices! Will get junk data or a crash.\n" );
}
// Locks mesh for modifying
pMesh->ModifyBeginEx( true, firstVertex, numVertices, firstIndex, numIndices, *this );
// Point to the start of the buffers..
Reset();
}
inline void CBaseMeshReader::EndRead()
{
Assert( m_pMesh );
m_pMesh->ModifyEnd( *this );
m_pMesh = NULL;
}
inline void CBaseMeshReader::BeginRead_Direct( const MeshDesc_t &desc, int nVertices, int nIndices )
{
MeshDesc_t *pThis = this;
*pThis = desc;
m_MaxVertices = nVertices;
m_MaxIndices = nIndices;
// UNDONE: support reading from compressed verts if necessary
Assert( desc.m_CompressionType == VERTEX_COMPRESSION_NONE );
if ( desc.m_CompressionType != VERTEX_COMPRESSION_NONE )
{
Warning( "Cannot use CBaseMeshReader with compressed vertices!\n" );
}
}
inline void CBaseMeshReader::Reset()
{
}
// -------------------------------------------------------------------------------------- //
// CMeshReader implementation.
// -------------------------------------------------------------------------------------- //
inline int CMeshReader::NumIndices() const
{
return m_MaxIndices;
}
inline unsigned short CMeshReader::Index( int index ) const
{
Assert( (index >= 0) && (index < m_MaxIndices) );
return m_pIndices[index * m_nIndexSize];
}
inline const Vector& CMeshReader::Position( int iVertex ) const
{
Assert( iVertex >= 0 && iVertex < m_MaxVertices );
return *(Vector*)((char*)m_pPosition + iVertex * m_VertexSize_Position);
}
inline unsigned int CMeshReader::Color( int iVertex ) const
{
Assert( iVertex >= 0 && iVertex < m_MaxVertices );
unsigned char *pColor = m_pColor + iVertex * m_VertexSize_Color;
return (pColor[0] << 16) | (pColor[1] << 8) | (pColor[2]) | (pColor[3] << 24);
}
inline const float *CMeshReader::TexCoord( int iVertex, int iStage ) const
{
Assert( iVertex >= 0 && iVertex < m_MaxVertices );
return (float*)( (char*)m_pTexCoord[iStage] + iVertex * m_VertexSize_TexCoord[iStage] );
}
inline void CMeshReader::TexCoord2f( int iVertex, int iStage, float &s, float &t ) const
{
Assert( iVertex >= 0 && iVertex < m_MaxVertices );
float *p = (float*)( (char*)m_pTexCoord[iStage] + iVertex * m_VertexSize_TexCoord[iStage] );
s = p[0];
t = p[1];
}
inline const Vector2D& CMeshReader::TexCoordVector2D( int iVertex, int iStage ) const
{
Assert( iVertex >= 0 && iVertex < m_MaxVertices );
Vector2D *p = (Vector2D*)( (char*)m_pTexCoord[iStage] + iVertex * m_VertexSize_TexCoord[iStage] );
return *p;
}
inline float CMeshReader::Wrinkle( int iVertex ) const
{
Assert( iVertex >= 0 && iVertex < m_MaxVertices );
return *(float*)( (char*)m_pWrinkle + iVertex * m_VertexSize_Wrinkle );
}
inline int CMeshReader::NumBoneWeights() const
{
return m_NumBoneWeights;
}
inline const Vector &CMeshReader::Normal( int iVertex ) const
{
Assert( iVertex >= 0 && iVertex < m_MaxVertices );
return *(const Vector *)(const float*)( (char*)m_pNormal + iVertex * m_VertexSize_Normal );
}
inline void CMeshReader::Normal( int iVertex, Vector &vNormal ) const
{
Assert( iVertex >= 0 && iVertex < m_MaxVertices );
const float *p = (const float*)( (char*)m_pNormal + iVertex * m_VertexSize_Normal );
vNormal.Init( p[0], p[1], p[2] );
}
inline const Vector &CMeshReader::TangentS( int iVertex ) const
{
Assert( iVertex >= 0 && iVertex < m_MaxVertices );
return *(const Vector*)( (char*)m_pTangentS + iVertex * m_VertexSize_TangentS );
}
inline const Vector &CMeshReader::TangentT( int iVertex ) const
{
Assert( iVertex >= 0 && iVertex < m_MaxVertices );
return *(const Vector*)( (char*)m_pTangentT + iVertex * m_VertexSize_TangentT );
}
inline float CMeshReader::BoneWeight( int iVertex ) const
{
Assert( iVertex >= 0 && iVertex < m_MaxVertices );
float *p = (float*)( (char*)m_pBoneWeight + iVertex * m_VertexSize_BoneWeight );
return *p;
}
#endif // MESHREADER_H

View File

@ -0,0 +1,75 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#ifndef SHADER_VCS_VERSION_H
#define SHADER_VCS_VERSION_H
#ifdef _WIN32
#pragma once
#endif
// 1 = hl2 shipped
// 2 = compressed with diffs version (lostcoast)
// 3 = compressed with bzip
// 4 = v2 + crc32
// 5 = v3 + crc32
// 6 = v5 + duplicate static combo records
#define SHADER_VCS_VERSION_NUMBER 6
#define MAX_SHADER_UNPACKED_BLOCK_SIZE (1<<17)
#define MAX_SHADER_PACKED_SIZE (1+MAX_SHADER_UNPACKED_BLOCK_SIZE)
#pragma pack(1)
struct ShaderHeader_t
{
int32 m_nVersion;
int32 m_nTotalCombos;
int32 m_nDynamicCombos;
uint32 m_nFlags;
uint32 m_nCentroidMask;
uint32 m_nNumStaticCombos; // includes sentinal key
uint32 m_nSourceCRC32; // NOTE: If you move this, update copyshaders.pl, *_prep.pl, updateshaders.pl
};
#pragma pack()
#pragma pack(1)
struct ShaderHeader_t_v4 // still used for assembly shaders
{
int32 m_nVersion;
int32 m_nTotalCombos;
int32 m_nDynamicCombos;
uint32 m_nFlags;
uint32 m_nCentroidMask;
uint32 m_nDiffReferenceSize;
uint32 m_nSourceCRC32; // NOTE: If you move this, update copyshaders.pl, *_prep.pl, updateshaders.pl
};
#pragma pack()
// for old format files
struct ShaderDictionaryEntry_t
{
int m_Offset;
int m_Size;
};
// record for one static combo
struct StaticComboRecord_t
{
uint32 m_nStaticComboID;
uint32 m_nFileOffset;
};
struct StaticComboAliasRecord_t // for duplicate static combos
{
uint32 m_nStaticComboID; // this combo
uint32 m_nSourceStaticCombo; // the combo it is the same as
};
#endif // SHADER_VCS_VERSION_H