initial
This commit is contained in:
235
public/shaderlib/BaseShader.h
Normal file
235
public/shaderlib/BaseShader.h
Normal file
@@ -0,0 +1,235 @@
|
||||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
// This is what all shaders inherit from.
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef BASESHADER_H
|
||||
#define BASESHADER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "materialsystem/IShader.h"
|
||||
#include "materialsystem/imaterialvar.h"
|
||||
#include "materialsystem/ishaderapi.h"
|
||||
#include "materialsystem/imaterialsystemhardwareconfig.h"
|
||||
#include "shaderlib/baseshader_declarations.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IMaterialVar;
|
||||
class CPerInstanceContextData;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Base class for shaders, contains helper methods.
|
||||
//-----------------------------------------------------------------------------
|
||||
class CBaseShader : public IShader
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
CBaseShader();
|
||||
|
||||
// Methods inherited from IShader
|
||||
virtual char const* GetFallbackShader( IMaterialVar** params ) const { return 0; }
|
||||
virtual int GetParamCount( ) const;
|
||||
virtual const ShaderParamInfo_t& GetParamInfo( int paramIndex ) const;
|
||||
|
||||
virtual void InitShaderParams( IMaterialVar** ppParams, const char *pMaterialName );
|
||||
virtual void InitShaderInstance( IMaterialVar** ppParams, IShaderInit *pShaderInit, const char *pMaterialName, const char *pTextureGroupName );
|
||||
virtual void DrawElements( IMaterialVar **params, int nModulationFlags, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI,
|
||||
VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContext, CBasePerInstanceContextData** pInstanceDataPtr );
|
||||
|
||||
virtual int ComputeModulationFlags( IMaterialVar** params, IShaderDynamicAPI* pShaderAPI );
|
||||
virtual bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame = true ) const;
|
||||
virtual bool NeedsFullFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame = true ) const;
|
||||
virtual bool IsTranslucent( IMaterialVar **params ) const;
|
||||
|
||||
public:
|
||||
// These functions must be implemented by the shader
|
||||
virtual void OnInitShaderParams( IMaterialVar** ppParams, const char *pMaterialName ) {}
|
||||
virtual void OnInitShaderInstance( IMaterialVar** ppParams, IShaderInit *pShaderInit, const char *pMaterialName ) = 0;
|
||||
virtual void OnDrawElements( IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr ) = 0;
|
||||
|
||||
// Sets the default shadow state
|
||||
void SetInitialShadowState( );
|
||||
|
||||
// Draws a snapshot
|
||||
void Draw( bool bMakeActualDrawCall = true );
|
||||
|
||||
// Are we currently taking a snapshot?
|
||||
bool IsSnapshotting() const;
|
||||
|
||||
// Methods related to building per-instance ("PI_") command buffers
|
||||
void PI_BeginCommandBuffer();
|
||||
void PI_EndCommandBuffer();
|
||||
void PI_SetPixelShaderAmbientLightCube( int nFirstRegister );
|
||||
void PI_SetPixelShaderLocalLighting( int nFirstRegister );
|
||||
void PI_SetPixelShaderAmbientLightCubeLuminance( int nFirstRegister );
|
||||
void PI_SetPixelShaderGlintDamping( int nFirstRegister );
|
||||
void PI_SetVertexShaderAmbientLightCube( /*int nFirstRegister*/ );
|
||||
void PI_SetModulationPixelShaderDynamicState( int nRegister );
|
||||
void PI_SetModulationPixelShaderDynamicState_LinearColorSpace_LinearScale( int nRegister, float scale );
|
||||
void PI_SetModulationPixelShaderDynamicState_LinearScale( int nRegister, float scale );
|
||||
void PI_SetModulationPixelShaderDynamicState_LinearScale_ScaleInW( int nRegister, float scale );
|
||||
void PI_SetModulationPixelShaderDynamicState_LinearColorSpace( int nRegister );
|
||||
void PI_SetModulationPixelShaderDynamicState_Identity( int nRegister );
|
||||
void PI_SetModulationVertexShaderDynamicState( void );
|
||||
void PI_SetModulationVertexShaderDynamicState_LinearScale( float flScale );
|
||||
|
||||
// Gets at the current materialvar flags
|
||||
int CurrentMaterialVarFlags() const;
|
||||
|
||||
// Gets at the current materialvar2 flags
|
||||
int CurrentMaterialVarFlags2() const;
|
||||
|
||||
// Finds a particular parameter (works because the lowest parameters match the shader)
|
||||
int FindParamIndex( const char *pName ) const;
|
||||
|
||||
// Are we using graphics?
|
||||
bool IsUsingGraphics();
|
||||
|
||||
// Are we using editor materials?
|
||||
bool CanUseEditorMaterials() const;
|
||||
|
||||
// Loads a texture
|
||||
void LoadTexture( int nTextureVar, int nAdditionalCreationFlags = 0 );
|
||||
|
||||
// Loads a bumpmap
|
||||
void LoadBumpMap( int nTextureVar, int nAdditionalCreationFlags = 0 );
|
||||
|
||||
// Loads a cubemap
|
||||
void LoadCubeMap( int nTextureVar, int nAdditionalCreationFlags = 0 );
|
||||
|
||||
// get the shaderapi handle for a texture. BE CAREFUL WITH THIS.
|
||||
ShaderAPITextureHandle_t GetShaderAPITextureBindHandle( int nTextureVar, int nFrameVar, int nTextureChannel = 0 );
|
||||
ShaderAPITextureHandle_t GetShaderAPITextureBindHandle( ITexture *pTexture, int nFrame, int nTextureChannel = 0 );
|
||||
|
||||
// Binds a texture
|
||||
void BindTexture( Sampler_t sampler1, Sampler_t sampler2, TextureBindFlags_t nBindFlags, int nTextureVar, int nFrameVar = -1 );
|
||||
void BindTexture( Sampler_t sampler1, TextureBindFlags_t nBindFlags, int nTextureVar, int nFrameVar = -1 );
|
||||
void BindTexture( Sampler_t sampler1, TextureBindFlags_t nBindFlags, ITexture *pTexture, int nFrame = 0 );
|
||||
void BindTexture( Sampler_t sampler1, Sampler_t sampler2, TextureBindFlags_t nBindFlags, ITexture *pTexture, int nFrame = 0 );
|
||||
|
||||
// Bind vertex texture
|
||||
void BindVertexTexture( VertexTextureSampler_t vtSampler, int nTextureVar, int nFrame = 0 );
|
||||
|
||||
// Is the texture translucent?
|
||||
bool TextureIsTranslucent( int textureVar, bool isBaseTexture );
|
||||
|
||||
// Is the color var white?
|
||||
bool IsWhite( int colorVar );
|
||||
|
||||
// Helper methods for fog
|
||||
void FogToOOOverbright( void );
|
||||
void FogToWhite( void );
|
||||
void FogToBlack( void );
|
||||
void FogToGrey( void );
|
||||
void FogToFogColor( void );
|
||||
void DisableFog( void );
|
||||
void DefaultFog( void );
|
||||
|
||||
// Helpers for alpha blending
|
||||
void EnableAlphaBlending( ShaderBlendFactor_t src, ShaderBlendFactor_t dst );
|
||||
void DisableAlphaBlending();
|
||||
|
||||
void SetBlendingShadowState( BlendType_t nMode );
|
||||
|
||||
void SetNormalBlendingShadowState( int textureVar = -1, bool isBaseTexture = true );
|
||||
void SetAdditiveBlendingShadowState( int textureVar = -1, bool isBaseTexture = true );
|
||||
void SetDefaultBlendingShadowState( int textureVar = -1, bool isBaseTexture = true );
|
||||
void SingleTextureLightmapBlendMode( );
|
||||
|
||||
// Helpers for color modulation
|
||||
bool IsAlphaModulating();
|
||||
// Helpers for HDR
|
||||
bool IsHDREnabled( void );
|
||||
|
||||
bool UsingFlashlight( IMaterialVar **params ) const;
|
||||
bool UsingEditor( IMaterialVar **params ) const;
|
||||
bool IsRenderingPaint( IMaterialVar **params ) const;
|
||||
|
||||
void ApplyColor2Factor( float *pColorOut, bool isLinearSpace = false ) const; // (*pColorOut) *= COLOR2
|
||||
|
||||
static inline IMaterialVar **GetPPParams();
|
||||
void SetPPParams( IMaterialVar **params ) { s_ppParams = params; }
|
||||
void SetModulationFlags( int modulationFlags ) { s_nModulationFlags = modulationFlags; }
|
||||
|
||||
private:
|
||||
// This is a per-instance state which is handled completely by the system
|
||||
void PI_SetSkinningMatrices();
|
||||
void PI_SetVertexShaderLocalLighting( );
|
||||
|
||||
FORCEINLINE void SetFogMode( ShaderFogMode_t fogMode );
|
||||
|
||||
protected:
|
||||
static IMaterialVar **s_ppParams;
|
||||
static const char *s_pTextureGroupName; // Current material's texture group name.
|
||||
static IShaderShadow *s_pShaderShadow;
|
||||
static IShaderDynamicAPI *s_pShaderAPI;
|
||||
static IShaderInit *s_pShaderInit;
|
||||
private:
|
||||
static int s_nPassCount;
|
||||
static int s_nModulationFlags;
|
||||
static CPerInstanceContextData** s_pInstanceDataPtr;
|
||||
|
||||
template <class T> friend class CBaseCommandBufferBuilder;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets at the current materialvar flags
|
||||
//-----------------------------------------------------------------------------
|
||||
inline int CBaseShader::CurrentMaterialVarFlags() const
|
||||
{
|
||||
return s_ppParams[FLAGS]->GetIntValue();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets at the current materialvar2 flags
|
||||
//-----------------------------------------------------------------------------
|
||||
inline int CBaseShader::CurrentMaterialVarFlags2() const
|
||||
{
|
||||
return s_ppParams[FLAGS2]->GetIntValue();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Are we currently taking a snapshot?
|
||||
//-----------------------------------------------------------------------------
|
||||
inline bool CBaseShader::IsSnapshotting() const
|
||||
{
|
||||
return (s_pShaderShadow != NULL);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Is the color var white?
|
||||
//-----------------------------------------------------------------------------
|
||||
inline bool CBaseShader::IsWhite( int colorVar )
|
||||
{
|
||||
if (colorVar < 0)
|
||||
return true;
|
||||
|
||||
if (!s_ppParams[colorVar]->IsDefined())
|
||||
return true;
|
||||
|
||||
float color[3];
|
||||
s_ppParams[colorVar]->GetVecValue( color, 3 );
|
||||
return (color[0] >= 1.0f) && (color[1] >= 1.0f) && (color[2] >= 1.0f);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the s_ppParams static member variable - for internal use only.
|
||||
//-----------------------------------------------------------------------------
|
||||
inline IMaterialVar **CBaseShader::GetPPParams()
|
||||
{
|
||||
return s_ppParams;
|
||||
}
|
||||
|
||||
#endif // BASESHADER_H
|
||||
53
public/shaderlib/ShaderDLL.h
Normal file
53
public/shaderlib/ShaderDLL.h
Normal file
@@ -0,0 +1,53 @@
|
||||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Header: $
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef SHADERDLL_H
|
||||
#define SHADERDLL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <materialsystem/IShader.h>
|
||||
#include "shaderlib/shadercombosemantics.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IShader;
|
||||
class ICvar;
|
||||
struct ShaderComboInformation_t;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The standard implementation of CShaderDLL
|
||||
//-----------------------------------------------------------------------------
|
||||
class IShaderDLL
|
||||
{
|
||||
public:
|
||||
// Adds a shader to the list of shaders
|
||||
virtual void InsertShader( IShader *pShader ) = 0;
|
||||
|
||||
virtual void AddShaderComboInformation( const ShaderComboSemantics_t *pSemantics ) = 0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton interface
|
||||
//-----------------------------------------------------------------------------
|
||||
IShaderDLL *GetShaderDLL();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton interface for CVars
|
||||
//-----------------------------------------------------------------------------
|
||||
ICvar *GetCVar();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // SHADERDLL_H
|
||||
74
public/shaderlib/baseshader_declarations.h
Normal file
74
public/shaderlib/baseshader_declarations.h
Normal file
@@ -0,0 +1,74 @@
|
||||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose: These are declarations (functions, structs, enums) used in both
|
||||
// SPU and PPU on PS/3, as well as potentially on different processor targets
|
||||
// on future platforms
|
||||
//===========================================================================//
|
||||
#ifndef BASESHADER_SHARED_DECLARATIONS_HDR
|
||||
#define BASESHADER_SHARED_DECLARATIONS_HDR
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Standard material vars
|
||||
//-----------------------------------------------------------------------------
|
||||
// Note: if you add to these, add to s_StandardParams in CBaseShader.cpp
|
||||
enum ShaderMaterialVars_t
|
||||
{
|
||||
FLAGS = 0,
|
||||
FLAGS_DEFINED, // mask indicating if the flag was specified
|
||||
FLAGS2,
|
||||
FLAGS_DEFINED2,
|
||||
COLOR,
|
||||
ALPHA,
|
||||
BASETEXTURE,
|
||||
FRAME,
|
||||
BASETEXTURETRANSFORM,
|
||||
FLASHLIGHTTEXTURE,
|
||||
FLASHLIGHTTEXTUREFRAME,
|
||||
COLOR2,
|
||||
SRGBTINT,
|
||||
|
||||
NUM_SHADER_MATERIAL_VARS
|
||||
};
|
||||
|
||||
// Alpha belnd mode enums. Moved from basevsshader
|
||||
enum BlendType_t
|
||||
{
|
||||
// no alpha blending
|
||||
BT_NONE = 0,
|
||||
|
||||
|
||||
|
||||
// src * srcAlpha + dst * (1-srcAlpha)
|
||||
// two passes for HDR:
|
||||
// pass 1:
|
||||
// color: src * srcAlpha + dst * (1-srcAlpha)
|
||||
// alpha: srcAlpha * zero + dstAlpha * (1-srcAlpha)
|
||||
// pass 2:
|
||||
// color: none
|
||||
// alpha: srcAlpha * one + dstAlpha * one
|
||||
//
|
||||
BT_BLEND,
|
||||
|
||||
|
||||
|
||||
// src * one + dst * one
|
||||
// one pass for HDR
|
||||
BT_ADD,
|
||||
|
||||
|
||||
|
||||
// Why do we ever use this instead of using premultiplied alpha?
|
||||
// src * srcAlpha + dst * one
|
||||
// two passes for HDR
|
||||
// pass 1:
|
||||
// color: src * srcAlpha + dst * one
|
||||
// alpha: srcAlpha * one + dstAlpha * one
|
||||
// pass 2:
|
||||
// color: none
|
||||
// alpha: srcAlpha * one + dstAlpha * one
|
||||
BT_BLENDADD
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
928
public/shaderlib/commandbuilder.h
Normal file
928
public/shaderlib/commandbuilder.h
Normal file
@@ -0,0 +1,928 @@
|
||||
//===== Copyright (c) Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
// Utility class for building command buffers into memory
|
||||
//==================================================================//
|
||||
|
||||
#ifndef COMMANDBUILDER_H
|
||||
#define COMMANDBUILDER_H
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "shaderapi/commandbuffer.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
#include "shaderlib/BaseShader.h"
|
||||
#include "tier1/convar.h"
|
||||
|
||||
#ifdef _PS3
|
||||
#include "ps3gcm\gcmdrawstate.h"
|
||||
#include "ps3gcm\gcmtexture.h"
|
||||
#endif
|
||||
|
||||
#ifdef DBGFLAG_ASSERT
|
||||
#define TRACK_STORAGE 1
|
||||
#else
|
||||
#define TRACK_STORAGE 0
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Buffer for storing commands into
|
||||
//-----------------------------------------------------------------------------
|
||||
template<int N> class CFixedCommandStorageBuffer
|
||||
{
|
||||
public:
|
||||
uint8 m_Data[N];
|
||||
|
||||
uint8 *m_pDataOut;
|
||||
#if TRACK_STORAGE
|
||||
size_t m_nNumBytesRemaining;
|
||||
#endif
|
||||
|
||||
FORCEINLINE CFixedCommandStorageBuffer( void )
|
||||
{
|
||||
m_pDataOut = m_Data;
|
||||
#if TRACK_STORAGE
|
||||
m_nNumBytesRemaining = N;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
FORCEINLINE void EnsureCapacity( size_t sz )
|
||||
{
|
||||
#if TRACK_STORAGE
|
||||
if ( m_nNumBytesRemaining < sz + 32 )
|
||||
Error( "getting scary\n" );
|
||||
#endif
|
||||
Assert( m_nNumBytesRemaining >= sz );
|
||||
}
|
||||
|
||||
template<class T> FORCEINLINE void Put( T const &nValue )
|
||||
{
|
||||
EnsureCapacity( sizeof( T ) );
|
||||
*( reinterpret_cast<T *>( m_pDataOut ) ) = nValue;
|
||||
m_pDataOut += sizeof( nValue );
|
||||
#if TRACK_STORAGE
|
||||
m_nNumBytesRemaining -= sizeof( nValue );
|
||||
#endif
|
||||
}
|
||||
|
||||
FORCEINLINE void PutInt( int nValue )
|
||||
{
|
||||
Put( nValue );
|
||||
}
|
||||
|
||||
FORCEINLINE void PutFloat( float nValue )
|
||||
{
|
||||
Put( nValue );
|
||||
}
|
||||
|
||||
FORCEINLINE void PutPtr( void * pPtr )
|
||||
{
|
||||
Put( pPtr );
|
||||
}
|
||||
|
||||
FORCEINLINE void PutMemory( const void *pMemory, size_t nBytes )
|
||||
{
|
||||
EnsureCapacity( nBytes );
|
||||
memcpy( m_pDataOut, pMemory, nBytes );
|
||||
m_pDataOut += nBytes;
|
||||
#if TRACK_STORAGE
|
||||
m_nNumBytesRemaining -= nBytes;
|
||||
#endif
|
||||
}
|
||||
|
||||
FORCEINLINE uint8 *Base( void )
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
FORCEINLINE void Reset( void )
|
||||
{
|
||||
m_pDataOut = m_Data;
|
||||
#if TRACK_STORAGE
|
||||
m_nNumBytesRemaining = N;
|
||||
#endif
|
||||
}
|
||||
|
||||
FORCEINLINE size_t Size( void ) const
|
||||
{
|
||||
return m_pDataOut - m_Data;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#ifdef _PS3
|
||||
|
||||
class CDynamicCommandStorageBuffer
|
||||
{
|
||||
public:
|
||||
uint8 *m_Data;
|
||||
uint8 *m_pDataOut;
|
||||
#if TRACK_STORAGE_PS3
|
||||
size_t m_nNumBytesRemaining;
|
||||
#endif
|
||||
|
||||
FORCEINLINE CDynamicCommandStorageBuffer()
|
||||
{
|
||||
m_Data = gpGcmDrawState->OpenDynECB();
|
||||
m_pDataOut = m_Data;
|
||||
#if TRACK_STORAGE_PS3
|
||||
m_nNumBytesRemaining = 0x1000;
|
||||
#endif
|
||||
}
|
||||
|
||||
FORCEINLINE void EnsureCapacity( size_t sz )
|
||||
{
|
||||
#if TRACK_STORAGE_PS3
|
||||
if ( m_nNumBytesRemaining < sz + 32 )
|
||||
Error( "getting scary\n" );
|
||||
Assert( m_nNumBytesRemaining >= sz );
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class T> FORCEINLINE void Put( T const &nValue )
|
||||
{
|
||||
EnsureCapacity( sizeof( T ) );
|
||||
*( reinterpret_cast<T *>( m_pDataOut ) ) = nValue;
|
||||
m_pDataOut += sizeof( nValue );
|
||||
#if TRACK_STORAGE_PS3
|
||||
m_nNumBytesRemaining -= sizeof( nValue );
|
||||
#endif
|
||||
}
|
||||
|
||||
FORCEINLINE void PutInt( int nValue )
|
||||
{
|
||||
Put( nValue );
|
||||
}
|
||||
|
||||
FORCEINLINE void PutFloat( float nValue )
|
||||
{
|
||||
Put( nValue );
|
||||
}
|
||||
|
||||
FORCEINLINE void PutPtr( void * pPtr )
|
||||
{
|
||||
Put( pPtr );
|
||||
}
|
||||
|
||||
FORCEINLINE void PutMemory( const void *pMemory, size_t nBytes )
|
||||
{
|
||||
EnsureCapacity( nBytes );
|
||||
memcpy( m_pDataOut, pMemory, nBytes );
|
||||
m_pDataOut += nBytes;
|
||||
#if TRACK_STORAGE_PS3
|
||||
m_nNumBytesRemaining -= nBytes;
|
||||
#endif
|
||||
}
|
||||
|
||||
FORCEINLINE uint8 *Base( void )
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
FORCEINLINE void Reset( void )
|
||||
{
|
||||
m_pDataOut = m_Data;
|
||||
#if TRACK_STORAGE_PS3
|
||||
m_nNumBytesRemaining = N;
|
||||
#endif
|
||||
}
|
||||
|
||||
FORCEINLINE size_t Size( void ) const
|
||||
{
|
||||
return m_pDataOut - m_Data;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Base class used to build up command buffers
|
||||
//-----------------------------------------------------------------------------
|
||||
template<class S> class CBaseCommandBufferBuilder
|
||||
{
|
||||
public:
|
||||
#ifdef _PS3
|
||||
ALIGN16 S m_Storage ALIGN16_POST;
|
||||
#else
|
||||
S m_Storage;
|
||||
#endif
|
||||
|
||||
FORCEINLINE void End( void )
|
||||
{
|
||||
m_Storage.PutInt( CBCMD_END );
|
||||
}
|
||||
|
||||
FORCEINLINE IMaterialVar *Param( int nVar ) const
|
||||
{
|
||||
return CBaseShader::s_ppParams[nVar];
|
||||
}
|
||||
|
||||
FORCEINLINE void Reset( void )
|
||||
{
|
||||
m_Storage.Reset();
|
||||
}
|
||||
|
||||
FORCEINLINE size_t Size( void ) const
|
||||
{
|
||||
return m_Storage.Size();
|
||||
}
|
||||
|
||||
FORCEINLINE uint8 *Base( void )
|
||||
{
|
||||
return m_Storage.Base();
|
||||
}
|
||||
|
||||
FORCEINLINE void OutputConstantData( float const *pSrcData )
|
||||
{
|
||||
m_Storage.PutFloat( pSrcData[0] );
|
||||
m_Storage.PutFloat( pSrcData[1] );
|
||||
m_Storage.PutFloat( pSrcData[2] );
|
||||
m_Storage.PutFloat( pSrcData[3] );
|
||||
}
|
||||
|
||||
FORCEINLINE void OutputConstantData4( float flVal0, float flVal1, float flVal2, float flVal3 )
|
||||
{
|
||||
m_Storage.PutFloat( flVal0 );
|
||||
m_Storage.PutFloat( flVal1 );
|
||||
m_Storage.PutFloat( flVal2 );
|
||||
m_Storage.PutFloat( flVal3 );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used by SetPixelShaderFlashlightState
|
||||
//-----------------------------------------------------------------------------
|
||||
struct CBCmdSetPixelShaderFlashlightState_t
|
||||
{
|
||||
Sampler_t m_LightSampler;
|
||||
Sampler_t m_DepthSampler;
|
||||
Sampler_t m_ShadowNoiseSampler;
|
||||
int m_nColorConstant;
|
||||
int m_nAttenConstant;
|
||||
int m_nOriginConstant;
|
||||
int m_nDepthTweakConstant;
|
||||
int m_nScreenScaleConstant;
|
||||
int m_nWorldToTextureConstant;
|
||||
bool m_bFlashlightNoLambert;
|
||||
bool m_bSinglePassFlashlight;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to build a per-pass command buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
template<class S> class CCommandBufferBuilder : public CBaseCommandBufferBuilder<S>
|
||||
{
|
||||
typedef CBaseCommandBufferBuilder<S> PARENT;
|
||||
|
||||
#ifdef _PS3
|
||||
uint32 m_numPs3Tex;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
#ifdef _PS3
|
||||
FORCEINLINE CCommandBufferBuilder()
|
||||
{
|
||||
// For PS3, command buffers begin with up to four Std textures
|
||||
|
||||
m_numPs3Tex = 0;
|
||||
|
||||
this->m_Storage.PutInt(CBCMD_LENGTH);
|
||||
this->m_Storage.PutInt(0);
|
||||
|
||||
this->m_Storage.PutInt(CBCMD_PS3TEX);
|
||||
for(int i = 0; i < CBCMD_MAX_PS3TEX; i++) this->m_Storage.PutInt(0);
|
||||
|
||||
}
|
||||
|
||||
FORCEINLINE void Reset()
|
||||
{
|
||||
this->m_Storage.Reset();
|
||||
|
||||
m_numPs3Tex = 0;
|
||||
|
||||
this->m_Storage.PutInt(CBCMD_LENGTH);
|
||||
this->m_Storage.PutInt(0);
|
||||
|
||||
this->m_Storage.PutInt(CBCMD_PS3TEX);
|
||||
for(int i = 0; i < CBCMD_MAX_PS3TEX; i++) this->m_Storage.PutInt(0);
|
||||
}
|
||||
|
||||
FORCEINLINE int* GetPs3Textures()
|
||||
{
|
||||
return (int*) (this->m_Storage.Base() + sizeof(int) + 2*sizeof(int));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
FORCEINLINE void End( void )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_END );
|
||||
|
||||
#ifdef _PS3
|
||||
uint32 len = this->m_Storage.Size();
|
||||
|
||||
if ( (this->m_Storage.m_Data >= g_aDynECB) && (this->m_Storage.m_Data < &g_aDynECB[sizeof(g_aDynECB)]) )
|
||||
{
|
||||
gpGcmDrawState->CloseDynECB(len);
|
||||
}
|
||||
|
||||
uint32* pLength = (uint32*)(this->m_Storage.m_Data + 4);
|
||||
if (pLength[-1] != CBCMD_LENGTH) Error("Length missing\n");
|
||||
*pLength = len;
|
||||
#endif
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstants( int nFirstConstant, int nConstants )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_SET_PIXEL_SHADER_FLOAT_CONST );
|
||||
this->m_Storage.PutInt( nFirstConstant );
|
||||
this->m_Storage.PutInt( nConstants );
|
||||
}
|
||||
|
||||
FORCEINLINE void OutputConstantData( float const *pSrcData )
|
||||
{
|
||||
this->m_Storage.PutFloat( pSrcData[0] );
|
||||
this->m_Storage.PutFloat( pSrcData[1] );
|
||||
this->m_Storage.PutFloat( pSrcData[2] );
|
||||
this->m_Storage.PutFloat( pSrcData[3] );
|
||||
}
|
||||
|
||||
FORCEINLINE void OutputConstantData4( float flVal0, float flVal1, float flVal2, float flVal3 )
|
||||
{
|
||||
this->m_Storage.PutFloat( flVal0 );
|
||||
this->m_Storage.PutFloat( flVal1 );
|
||||
this->m_Storage.PutFloat( flVal2 );
|
||||
this->m_Storage.PutFloat( flVal3 );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant( int nFirstConstant, float const *pSrcData, int nNumConstantsToSet )
|
||||
{
|
||||
SetPixelShaderConstants( nFirstConstant, nNumConstantsToSet );
|
||||
this->m_Storage.PutMemory( pSrcData, 4 * sizeof( float ) * nNumConstantsToSet );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant( int nFirstConstant, int nVar )
|
||||
{
|
||||
SetPixelShaderConstant( nFirstConstant, this->Param( nVar )->GetVecValue() );
|
||||
}
|
||||
|
||||
void SetPixelShaderConstantGammaToLinear( int pixelReg, int constantVar )
|
||||
{
|
||||
float val[4];
|
||||
this->Param(constantVar)->GetVecValue( val, 3 );
|
||||
val[0] = val[0] > 1.0f ? val[0] : GammaToLinear( val[0] );
|
||||
val[1] = val[1] > 1.0f ? val[1] : GammaToLinear( val[1] );
|
||||
val[2] = val[2] > 1.0f ? val[2] : GammaToLinear( val[2] );
|
||||
val[3] = 1.0;
|
||||
SetPixelShaderConstant( pixelReg, val );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant( int nFirstConstant, float const *pSrcData )
|
||||
{
|
||||
SetPixelShaderConstants( nFirstConstant, 1 );
|
||||
OutputConstantData( pSrcData );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant4( int nFirstConstant, float flVal0, float flVal1, float flVal2, float flVal3 )
|
||||
{
|
||||
SetPixelShaderConstants( nFirstConstant, 1 );
|
||||
OutputConstantData4( flVal0, flVal1, flVal2, flVal3 );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderConstant_W( int pixelReg, int constantVar, float fWValue )
|
||||
{
|
||||
if ( constantVar != -1 )
|
||||
{
|
||||
float val[3];
|
||||
this->Param(constantVar)->GetVecValue( val, 3);
|
||||
SetPixelShaderConstant4( pixelReg, val[0], val[1], val[2], fWValue );
|
||||
}
|
||||
}
|
||||
|
||||
void SetPixelShaderTextureTransform( int vertexReg, int transformVar )
|
||||
{
|
||||
Vector4D transformation[2];
|
||||
IMaterialVar* pTransformationVar = ( transformVar >= 0 ) ? this->Param( transformVar ) : NULL;
|
||||
if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX))
|
||||
{
|
||||
const VMatrix &mat = pTransformationVar->GetMatrixValue();
|
||||
transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] );
|
||||
transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] );
|
||||
}
|
||||
else
|
||||
{
|
||||
transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f );
|
||||
transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f );
|
||||
}
|
||||
SetPixelShaderConstant( vertexReg, transformation[0].Base(), 2 );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetVertexShaderConstant( int nFirstConstant, float const *pSrcData )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_SET_VERTEX_SHADER_FLOAT_CONST );
|
||||
this->m_Storage.PutInt( nFirstConstant );
|
||||
this->m_Storage.PutInt( 1 );
|
||||
OutputConstantData( pSrcData );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetVertexShaderConstant( int nFirstConstant, float const *pSrcData, int nConsts )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_SET_VERTEX_SHADER_FLOAT_CONST );
|
||||
this->m_Storage.PutInt( nFirstConstant );
|
||||
this->m_Storage.PutInt( nConsts );
|
||||
this->m_Storage.PutMemory( pSrcData, 4 * nConsts * sizeof( float ) );
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE void SetVertexShaderConstant4( int nFirstConstant, float flVal0, float flVal1, float flVal2, float flVal3 )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_SET_VERTEX_SHADER_FLOAT_CONST );
|
||||
this->m_Storage.PutInt( nFirstConstant );
|
||||
this->m_Storage.PutInt( 1 );
|
||||
this->m_Storage.PutFloat( flVal0 );
|
||||
this->m_Storage.PutFloat( flVal1 );
|
||||
this->m_Storage.PutFloat( flVal2 );
|
||||
this->m_Storage.PutFloat( flVal3 );
|
||||
}
|
||||
|
||||
void SetVertexShaderTextureTransform( int vertexReg, int transformVar )
|
||||
{
|
||||
Vector4D transformation[2];
|
||||
IMaterialVar* pTransformationVar = ( transformVar >= 0 ) ? this->Param( transformVar ) : NULL;
|
||||
if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX))
|
||||
{
|
||||
const VMatrix &mat = pTransformationVar->GetMatrixValue();
|
||||
transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] );
|
||||
transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] );
|
||||
}
|
||||
else
|
||||
{
|
||||
transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f );
|
||||
transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f );
|
||||
}
|
||||
SetVertexShaderConstant( vertexReg, transformation[0].Base(), 2 );
|
||||
}
|
||||
|
||||
|
||||
void SetVertexShaderTextureScaledTransformRotate( int vertexReg, int transformVar, int scaleVar, int rotateVar )
|
||||
{
|
||||
Vector2D scale( 1, 1 );
|
||||
IMaterialVar* pScaleVar = this->Param( scaleVar );
|
||||
if (pScaleVar)
|
||||
{
|
||||
if (pScaleVar->GetType() == MATERIAL_VAR_TYPE_VECTOR)
|
||||
pScaleVar->GetVecValue( scale.Base(), 2 );
|
||||
else if (pScaleVar->IsDefined())
|
||||
scale[0] = scale[1] = pScaleVar->GetFloatValue();
|
||||
}
|
||||
|
||||
float flRotateVar = 0.0f;
|
||||
IMaterialVar* pRotateVar = this->Param( rotateVar );
|
||||
if ( pRotateVar && pRotateVar->IsDefined() )
|
||||
{
|
||||
flRotateVar = pRotateVar->GetFloatValue();
|
||||
}
|
||||
|
||||
Vector4D transformation[2];
|
||||
IMaterialVar* pTransformationVar = this->Param( transformVar );
|
||||
if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX))
|
||||
{
|
||||
VMatrix matRot = pTransformationVar->GetMatrixValue();
|
||||
MatrixTranslate( matRot, Vector( 0.5, 0.5, 0 ) );
|
||||
MatrixRotate( matRot, Vector( 0, 0, 1), flRotateVar );
|
||||
MatrixTranslate( matRot, Vector( -0.5 * scale[0], -0.5 * scale[1], 0 ) );
|
||||
matRot = matRot.Scale( Vector(scale[0], scale[1], 1) );
|
||||
|
||||
transformation[0].Init( matRot[0][0], matRot[0][1], matRot[0][2], matRot[0][3] );
|
||||
transformation[1].Init( matRot[1][0], matRot[1][1], matRot[1][2], matRot[1][3] );
|
||||
|
||||
SetVertexShaderConstant( vertexReg, transformation[0].Base(), 2 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SetVertexShaderTextureScaledTransform( int vertexReg, int transformVar, int scaleVar )
|
||||
{
|
||||
Vector4D transformation[2];
|
||||
IMaterialVar* pTransformationVar = this->Param( transformVar );
|
||||
if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX))
|
||||
{
|
||||
const VMatrix &mat = pTransformationVar->GetMatrixValue();
|
||||
transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] );
|
||||
transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] );
|
||||
}
|
||||
else
|
||||
{
|
||||
transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f );
|
||||
transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f );
|
||||
}
|
||||
|
||||
Vector2D scale( 1, 1 );
|
||||
IMaterialVar* pScaleVar = this->Param( scaleVar );
|
||||
if (pScaleVar)
|
||||
{
|
||||
if (pScaleVar->GetType() == MATERIAL_VAR_TYPE_VECTOR)
|
||||
pScaleVar->GetVecValue( scale.Base(), 2 );
|
||||
else if (pScaleVar->IsDefined())
|
||||
scale[0] = scale[1] = pScaleVar->GetFloatValue();
|
||||
}
|
||||
|
||||
// Apply the scaling
|
||||
transformation[0][0] *= scale[0];
|
||||
transformation[0][1] *= scale[1];
|
||||
transformation[1][0] *= scale[0];
|
||||
transformation[1][1] *= scale[1];
|
||||
transformation[0][3] *= scale[0];
|
||||
transformation[1][3] *= scale[1];
|
||||
SetVertexShaderConstant( vertexReg, transformation[0].Base(), 2 );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetEnvMapTintPixelShaderDynamicState( int pixelReg, int tintVar )
|
||||
{
|
||||
if( g_pConfig->bShowSpecular && g_pConfig->nFullbright != 2 )
|
||||
{
|
||||
SetPixelShaderConstant( pixelReg, this->Param( tintVar)->GetVecValue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetPixelShaderConstant4( pixelReg, 0.0, 0.0, 0.0, 0.0 );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void SetEnvMapTintPixelShaderDynamicStateGammaToLinear( int pixelReg, int tintVar, float fAlphaVal = 1.0f )
|
||||
{
|
||||
if( g_pConfig->bShowSpecular && g_pConfig->nFullbright != 2 )
|
||||
{
|
||||
float color[4];
|
||||
color[3] = fAlphaVal;
|
||||
|
||||
//this->Param( tintVar)->GetLinearVecValue( color, 3 );
|
||||
// (wills) converted this line to the following so that envmaptint can be over-driven beyond 0-1 range
|
||||
|
||||
this->Param( tintVar)->GetVecValue( color, 3 );
|
||||
color[0] = GammaToLinearFullRange( color[0] );
|
||||
color[1] = GammaToLinearFullRange( color[1] );
|
||||
color[2] = GammaToLinearFullRange( color[2] );
|
||||
|
||||
SetPixelShaderConstant( pixelReg, color );
|
||||
}
|
||||
else
|
||||
{
|
||||
SetPixelShaderConstant4( pixelReg, 0.0, 0.0, 0.0, fAlphaVal );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void StoreEyePosInPixelShaderConstant( int nConst, float wValue = 1.0f )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_STORE_EYE_POS_IN_PSCONST );
|
||||
this->m_Storage.PutInt( nConst );
|
||||
this->m_Storage.PutFloat( wValue );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderFogParams( int nReg )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_SETPIXELSHADERFOGPARAMS );
|
||||
this->m_Storage.PutInt( nReg );
|
||||
}
|
||||
|
||||
#ifndef _PS3
|
||||
|
||||
FORCEINLINE void BindStandardTexture( Sampler_t nSampler, TextureBindFlags_t nBindFlags, StandardTextureId_t nTextureId )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_BIND_STANDARD_TEXTURE );
|
||||
this->m_Storage.PutInt( nSampler | nBindFlags );
|
||||
this->m_Storage.PutInt( nTextureId );
|
||||
}
|
||||
|
||||
FORCEINLINE void BindTexture( CBaseShader *pShader, Sampler_t nSampler, TextureBindFlags_t nBindFlags, ITexture *pTexture, int nFrame )
|
||||
{
|
||||
ShaderAPITextureHandle_t hTexture = pShader->GetShaderAPITextureBindHandle( pTexture, nFrame );
|
||||
Assert( hTexture != INVALID_SHADERAPI_TEXTURE_HANDLE );
|
||||
this->m_Storage.PutInt( CBCMD_BIND_SHADERAPI_TEXTURE_HANDLE );
|
||||
this->m_Storage.PutInt( nSampler | nBindFlags );
|
||||
this->m_Storage.Put( hTexture );
|
||||
}
|
||||
|
||||
FORCEINLINE void BindTexture( Sampler_t nSampler, TextureBindFlags_t nBindFlags, ShaderAPITextureHandle_t hTexture )
|
||||
{
|
||||
Assert( hTexture != INVALID_SHADERAPI_TEXTURE_HANDLE );
|
||||
this->m_Storage.PutInt( CBCMD_BIND_SHADERAPI_TEXTURE_HANDLE );
|
||||
this->m_Storage.PutInt( nSampler | nBindFlags );
|
||||
this->m_Storage.Put( hTexture );
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
FORCEINLINE void BindTexture( Sampler_t nSampler, TextureBindFlags_t nBindFlags, ShaderAPITextureHandle_t hTexture )
|
||||
{
|
||||
Assert( hTexture != INVALID_SHADERAPI_TEXTURE_HANDLE );
|
||||
|
||||
if (m_numPs3Tex >= CBCMD_MAX_PS3TEX)
|
||||
{
|
||||
Error("Too many textures in single draw ECB\n");
|
||||
}
|
||||
|
||||
int* pOffset = GetPs3Textures() + m_numPs3Tex;
|
||||
|
||||
CPs3BindParams_t tex;
|
||||
tex.m_sampler = nSampler;
|
||||
tex.m_nBindFlags = nBindFlags >> 24; // Top byte only
|
||||
tex.m_hTexture = hTexture;
|
||||
|
||||
tex.m_boundStd = -1;
|
||||
|
||||
tex.m_nBindTexIndex = m_numPs3Tex;
|
||||
|
||||
this->m_Storage.PutInt( CBCMD_BIND_PS3_TEXTURE );
|
||||
*pOffset = (this->m_Storage.m_pDataOut - this->m_Storage.m_Data);
|
||||
this->m_Storage.PutMemory(&tex, sizeof(tex)) ;
|
||||
|
||||
m_numPs3Tex++;
|
||||
|
||||
|
||||
}
|
||||
|
||||
FORCEINLINE void BindStandardTexture( Sampler_t nSampler, TextureBindFlags_t nBindFlags, StandardTextureId_t nTextureId )
|
||||
{
|
||||
if (m_numPs3Tex >= CBCMD_MAX_PS3TEX)
|
||||
{
|
||||
Error("Too many textures in single draw ECB\n");
|
||||
}
|
||||
|
||||
int* pOffset = GetPs3Textures() + m_numPs3Tex;
|
||||
|
||||
CPs3BindParams_t tex;
|
||||
tex.m_sampler = nSampler;
|
||||
tex.m_nBindFlags = nBindFlags >> 24;
|
||||
tex.m_boundStd = nTextureId;
|
||||
|
||||
tex.m_hTexture = -1;
|
||||
|
||||
tex.m_nBindTexIndex = m_numPs3Tex;
|
||||
|
||||
|
||||
this->m_Storage.PutInt( CBCMD_BIND_PS3_STANDARD_TEXTURE );
|
||||
*pOffset = (this->m_Storage.m_pDataOut - this->m_Storage.m_Data);
|
||||
this->m_Storage.PutMemory(&tex, sizeof(tex)) ;
|
||||
|
||||
m_numPs3Tex++;
|
||||
}
|
||||
|
||||
FORCEINLINE void BindTexture( CBaseShader *pShader, Sampler_t nSampler, TextureBindFlags_t nBindFlags, ITexture *pTexture, int nFrame )
|
||||
{
|
||||
ShaderAPITextureHandle_t hTexture = pShader->GetShaderAPITextureBindHandle( pTexture, nFrame );
|
||||
BindTexture(nSampler, nBindFlags, hTexture);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
FORCEINLINE void BindTexture( CBaseShader *pShader, Sampler_t nSampler, TextureBindFlags_t nBindFlags, int nTextureVar, int nFrameVar = -1 )
|
||||
{
|
||||
ShaderAPITextureHandle_t hTexture = pShader->GetShaderAPITextureBindHandle( nTextureVar, nFrameVar );
|
||||
BindTexture( nSampler, nBindFlags, hTexture );
|
||||
}
|
||||
|
||||
// Same as BindTexture, except it checks to see if the texture handle is actually the "internal" env_cubemap. If so, it binds it as a standard texture so the proper texture bind flags are
|
||||
// recorded during instance rendering in CShaderAPIDX8.
|
||||
FORCEINLINE void BindEnvCubemapTexture( CBaseShader *pShader, Sampler_t nSampler, TextureBindFlags_t nBindFlags, int nTextureVar, int nFrameVar = -1 )
|
||||
{
|
||||
Assert( nTextureVar != -1 );
|
||||
Assert( CBaseShader::GetPPParams() );
|
||||
if ( CBaseShader::GetPPParams()[nTextureVar]->IsTextureValueInternalEnvCubemap() )
|
||||
{
|
||||
BindStandardTexture( nSampler, nBindFlags, TEXTURE_LOCAL_ENV_CUBEMAP );
|
||||
}
|
||||
else
|
||||
{
|
||||
ShaderAPITextureHandle_t hTexture = pShader->GetShaderAPITextureBindHandle( nTextureVar, nFrameVar );
|
||||
BindTexture( nSampler, nBindFlags, hTexture );
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void BindMultiTexture( CBaseShader *pShader, Sampler_t nSampler1, Sampler_t nSampler2, TextureBindFlags_t nBindFlags, int nTextureVar, int nFrameVar )
|
||||
{
|
||||
ShaderAPITextureHandle_t hTexture = pShader->GetShaderAPITextureBindHandle( nTextureVar, nFrameVar, 0 );
|
||||
BindTexture( nSampler1, nBindFlags, hTexture );
|
||||
hTexture = pShader->GetShaderAPITextureBindHandle( nTextureVar, nFrameVar, 1 );
|
||||
BindTexture( nSampler2, nBindFlags, hTexture );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderIndex( int nIndex )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_SET_PSHINDEX );
|
||||
this->m_Storage.PutInt( nIndex );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetVertexShaderIndex( int nIndex )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_SET_VSHINDEX );
|
||||
this->m_Storage.PutInt( nIndex );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetDepthFeatheringShaderConstants( int iConstant, float fDepthBlendScale )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_SET_DEPTH_FEATHERING_CONST );
|
||||
this->m_Storage.PutInt( iConstant );
|
||||
this->m_Storage.PutFloat( fDepthBlendScale );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetVertexShaderFlashlightState( int iConstant )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_SET_VERTEX_SHADER_FLASHLIGHT_STATE );
|
||||
this->m_Storage.PutInt( iConstant );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderFlashlightState( const CBCmdSetPixelShaderFlashlightState_t &state )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_SET_PIXEL_SHADER_FLASHLIGHT_STATE );
|
||||
this->m_Storage.PutInt( state.m_LightSampler );
|
||||
this->m_Storage.PutInt( state.m_DepthSampler );
|
||||
this->m_Storage.PutInt( state.m_ShadowNoiseSampler );
|
||||
this->m_Storage.PutInt( state.m_nColorConstant );
|
||||
this->m_Storage.PutInt( state.m_nAttenConstant );
|
||||
this->m_Storage.PutInt( state.m_nOriginConstant );
|
||||
this->m_Storage.PutInt( state.m_nDepthTweakConstant );
|
||||
this->m_Storage.PutInt( state.m_nScreenScaleConstant );
|
||||
this->m_Storage.PutInt( state.m_nWorldToTextureConstant );
|
||||
this->m_Storage.PutInt( state.m_bFlashlightNoLambert );
|
||||
this->m_Storage.PutInt( state.m_bSinglePassFlashlight );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderUberLightState( int iEdge0Const, int iEdge1Const, int iEdgeOOWConst, int iShearRoundConst, int iAABBConst, int iWorldToLightConst )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_SET_PIXEL_SHADER_UBERLIGHT_STATE );
|
||||
this->m_Storage.PutInt( iEdge0Const );
|
||||
this->m_Storage.PutInt( iEdge1Const );
|
||||
this->m_Storage.PutInt( iEdgeOOWConst );
|
||||
this->m_Storage.PutInt( iShearRoundConst );
|
||||
this->m_Storage.PutInt( iAABBConst );
|
||||
this->m_Storage.PutInt( iWorldToLightConst );
|
||||
}
|
||||
|
||||
FORCEINLINE void Goto( uint8 *pCmdBuf )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_JUMP );
|
||||
this->m_Storage.PutPtr( pCmdBuf );
|
||||
}
|
||||
|
||||
FORCEINLINE void Call( uint8 *pCmdBuf )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_JSR );
|
||||
this->m_Storage.PutPtr( pCmdBuf );
|
||||
}
|
||||
|
||||
#ifndef _PS3
|
||||
FORCEINLINE void Reset( void )
|
||||
{
|
||||
this->m_Storage.Reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
FORCEINLINE size_t Size( void ) const
|
||||
{
|
||||
return this->m_Storage.Size();
|
||||
}
|
||||
|
||||
FORCEINLINE uint8 *Base( void )
|
||||
{
|
||||
return this->m_Storage.Base();
|
||||
}
|
||||
|
||||
FORCEINLINE void SetVertexShaderNearAndFarZ( int iRegNum )
|
||||
{
|
||||
this->m_Storage.PutInt( CBCMD_SET_VERTEX_SHADER_NEARZFARZ_STATE );
|
||||
this->m_Storage.PutInt( iRegNum );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Builds a command buffer specifically for per-instance state setting
|
||||
//-----------------------------------------------------------------------------
|
||||
template<class S> class CInstanceCommandBufferBuilder : public CBaseCommandBufferBuilder< S >
|
||||
{
|
||||
typedef CBaseCommandBufferBuilder< S > PARENT;
|
||||
|
||||
public:
|
||||
FORCEINLINE void End( void )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_END );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderLocalLighting( int nConst )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETPIXELSHADERLOCALLIGHTING );
|
||||
this->m_Storage.PutInt( nConst );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderAmbientLightCube( int nConst )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETPIXELSHADERAMBIENTLIGHTCUBE );
|
||||
this->m_Storage.PutInt( nConst );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetVertexShaderLocalLighting( )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETVERTEXSHADERLOCALLIGHTING );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetVertexShaderAmbientLightCube( void )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETVERTEXSHADERAMBIENTLIGHTCUBE );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetSkinningMatrices( void )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETSKINNINGMATRICES );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderAmbientLightCubeLuminance( int nConst )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETPIXELSHADERAMBIENTLIGHTCUBELUMINANCE );
|
||||
this->m_Storage.PutInt( nConst );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetPixelShaderGlintDamping( int nConst )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETPIXELSHADERGLINTDAMPING );
|
||||
this->m_Storage.PutInt( nConst );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetModulationPixelShaderDynamicState_LinearColorSpace_LinearScale( int nConst, const Vector &vecGammaSpaceColor2Factor, float scale )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE_LINEARCOLORSPACE_LINEARSCALE );
|
||||
this->m_Storage.PutInt( nConst );
|
||||
this->m_Storage.Put( vecGammaSpaceColor2Factor );
|
||||
this->m_Storage.PutFloat( 1.0 ); // pad for vector4
|
||||
this->m_Storage.PutFloat( scale );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetModulationPixelShaderDynamicState_LinearScale( int nConst, const Vector &vecGammaSpaceColor2Factor, float scale )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE_LINEARSCALE );
|
||||
this->m_Storage.PutInt( nConst );
|
||||
this->m_Storage.Put( vecGammaSpaceColor2Factor );
|
||||
this->m_Storage.PutFloat( 1.0 ); // alpha modulation wants 1 1.0 here for simd
|
||||
this->m_Storage.PutFloat( scale );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetModulationPixelShaderDynamicState_LinearScale_ScaleInW( int nConst, const Vector &vecGammaSpaceColor2Factor, float scale )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE_LINEARSCALE_SCALEINW );
|
||||
this->m_Storage.PutInt( nConst );
|
||||
this->m_Storage.Put( vecGammaSpaceColor2Factor );
|
||||
this->m_Storage.PutFloat( scale );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetModulationPixelShaderDynamicState_LinearColorSpace( int nConst, const Vector &vecGammaSpaceColor2Factor )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE_LINEARCOLORSPACE );
|
||||
this->m_Storage.PutInt( nConst );
|
||||
this->m_Storage.Put( vecGammaSpaceColor2Factor );
|
||||
this->m_Storage.PutFloat( 1.0 ); // pad with a 1 for vector4d simd access. Important that this be a 1 because alpha is multipled by it.
|
||||
}
|
||||
|
||||
FORCEINLINE void SetModulationPixelShaderDynamicState( int nConst, const Vector &vecGammaSpaceColor2Factor )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE );
|
||||
this->m_Storage.PutInt( nConst );
|
||||
this->m_Storage.Put( vecGammaSpaceColor2Factor );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetModulationPixelShaderDynamicState_Identity( int nConst )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE_IDENTITY );
|
||||
this->m_Storage.PutInt( nConst );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetModulationVertexShaderDynamicState( int nConst, const Vector &vecGammaSpaceColor2Factor )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETMODULATIONVERTEXSHADERDYNAMICSTATE );
|
||||
this->m_Storage.PutInt( nConst );
|
||||
this->m_Storage.Put( vecGammaSpaceColor2Factor );
|
||||
}
|
||||
|
||||
FORCEINLINE void SetModulationVertexShaderDynamicState_LinearScale( int nConst, const Vector &vecGammaSpaceColor2Factor, float flScale )
|
||||
{
|
||||
this->m_Storage.PutInt( CBICMD_SETMODULATIONVERTEXSHADERDYNAMICSTATE_LINEARSCALE );
|
||||
this->m_Storage.PutInt( nConst );
|
||||
this->m_Storage.Put( vecGammaSpaceColor2Factor );
|
||||
this->m_Storage.PutFloat( flScale );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // commandbuilder_h
|
||||
457
public/shaderlib/cshader.h
Normal file
457
public/shaderlib/cshader.h
Normal file
@@ -0,0 +1,457 @@
|
||||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef CSHADER_H
|
||||
#define CSHADER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
// uncomment this if you want to build for nv3x
|
||||
//#define NV3X 1
|
||||
|
||||
// This is what all shaders include.
|
||||
// CBaseShader will become CShader in this file.
|
||||
#include "materialsystem/ishaderapi.h"
|
||||
#include "utlvector.h"
|
||||
#include "materialsystem/imaterialvar.h"
|
||||
#include "materialsystem/imaterial.h"
|
||||
#include "BaseShader.h"
|
||||
#include "shaderlib/shadercombosemantics.h"
|
||||
|
||||
#include "materialsystem/itexture.h"
|
||||
|
||||
// Included for convenience because they are used in a bunch of shaders
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "materialsystem/imaterialsystemhardwareconfig.h"
|
||||
#include "materialsystem/materialsystem_config.h"
|
||||
#include "shaderlib/ShaderDLL.h"
|
||||
|
||||
// make "local variable is initialized but not referenced" warnings errors for combo checking macros
|
||||
#pragma warning ( error : 4189 )
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global interfaces
|
||||
//-----------------------------------------------------------------------------
|
||||
#if defined( _PS3 ) || defined( _OSX )
|
||||
#include "shaderapidx9/hardwareconfig.h"
|
||||
#else
|
||||
extern IMaterialSystemHardwareConfig *g_pHardwareConfig;
|
||||
#endif
|
||||
extern const MaterialSystem_Config_t *g_pConfig;
|
||||
extern bool g_shaderConfigDumpEnable;
|
||||
|
||||
// Helper method
|
||||
bool IsUsingGraphics();
|
||||
|
||||
#define SOFTWARE_VERTEX_SHADER(name) \
|
||||
static void SoftwareVertexShader_ ## name( CMeshBuilder &meshBuilder, IMaterialVar **params, IShaderDynamicAPI* pShaderAPI )
|
||||
|
||||
#define FORWARD_DECLARE_SOFTWARE_VERTEX_SHADER(name)\
|
||||
static void SoftwareVertexShader_ ## name( CMeshBuilder &meshBuilder, IMaterialVar **params, IShaderDynamicAPI* pShaderAPI );
|
||||
|
||||
#define USE_SOFTWARE_VERTEX_SHADER(name) \
|
||||
m_SoftwareVertexShader = SoftwareVertexShader_ ## name
|
||||
|
||||
#define SHADER_INIT_PARAMS() \
|
||||
virtual void OnInitShaderParams( IMaterialVar **params, const char *pMaterialName )
|
||||
|
||||
#define SHADER_FALLBACK \
|
||||
virtual char const* GetFallbackShader( IMaterialVar** params ) const
|
||||
|
||||
// Typesafe flag setting
|
||||
inline void CShader_SetFlags( IMaterialVar **params, MaterialVarFlags_t _flag )
|
||||
{
|
||||
params[FLAGS]->SetIntValue( params[FLAGS]->GetIntValue() | (_flag) );
|
||||
}
|
||||
|
||||
inline bool CShader_IsFlagSet( IMaterialVar **params, MaterialVarFlags_t _flag )
|
||||
{
|
||||
return ((params[FLAGS]->GetIntValue() & (_flag) ) != 0);
|
||||
}
|
||||
|
||||
#define SET_FLAGS( _flag ) CShader_SetFlags( params, _flag )
|
||||
#define CLEAR_FLAGS( _flag ) params[FLAGS]->SetIntValue( params[FLAGS]->GetIntValue() & ~(_flag) )
|
||||
#define IS_FLAG_SET( _flag ) CShader_IsFlagSet( params, _flag )
|
||||
#define IS_FLAG_DEFINED( _flag ) ((params[FLAGS_DEFINED]->GetIntValue() & (_flag) ) != 0)
|
||||
|
||||
#define IS_PARAM_DEFINED( _param ) ( ( ( _param >= 0 ) && ( params[_param]->IsDefined() ) ) )
|
||||
|
||||
#define SET_PARAM_STRING_IF_NOT_DEFINED( nParamIndex, kDefaultValue ) \
|
||||
if ( ( (nParamIndex) != -1 ) && ( !params[nParamIndex]->IsDefined() ) ) \
|
||||
{ \
|
||||
params[nParamIndex]->SetStringValue( kDefaultValue ); \
|
||||
}
|
||||
|
||||
#define SET_PARAM_FLOAT_IF_NOT_DEFINED( nParamIndex, kDefaultValue ) \
|
||||
if ( ( (nParamIndex) != -1 ) && ( !params[nParamIndex]->IsDefined() ) ) \
|
||||
{ \
|
||||
params[nParamIndex]->SetFloatValue( kDefaultValue ); \
|
||||
}
|
||||
|
||||
#define SET_PARAM_VEC_IF_NOT_DEFINED( nParamIndex, kDefaultValue, nSize ) \
|
||||
if ( ( (nParamIndex) != -1 ) && ( !params[nParamIndex]->IsDefined() ) ) \
|
||||
{ \
|
||||
params[nParamIndex]->SetVecValue( kDefaultValue, nSize ); \
|
||||
}
|
||||
|
||||
#define SET_PARAM_INT_IF_NOT_DEFINED( nParamIndex, kDefaultValue ) \
|
||||
if ( ( (nParamIndex) != -1 ) && ( !params[nParamIndex]->IsDefined() ) ) \
|
||||
{ \
|
||||
params[nParamIndex]->SetIntValue( kDefaultValue ); \
|
||||
}
|
||||
|
||||
// Typesafe flag setting
|
||||
inline void CShader_SetFlags2( IMaterialVar **params, MaterialVarFlags2_t _flag )
|
||||
{
|
||||
params[FLAGS2]->SetIntValue( params[FLAGS2]->GetIntValue() | (_flag) );
|
||||
}
|
||||
|
||||
inline bool CShader_IsFlag2Set( IMaterialVar **params, MaterialVarFlags2_t _flag )
|
||||
{
|
||||
return ((params[FLAGS2]->GetIntValue() & (_flag) ) != 0);
|
||||
}
|
||||
|
||||
#define SET_FLAGS2( _flag ) CShader_SetFlags2( params, _flag )
|
||||
#define CLEAR_FLAGS2( _flag ) params[FLAGS2]->SetIntValue( params[FLAGS2]->GetIntValue() & ~(_flag) )
|
||||
#define IS_FLAG2_SET( _flag ) CShader_IsFlag2Set( params, _flag )
|
||||
#define IS_FLAG2_DEFINED( _flag ) ((params[FLAGS_DEFINED2]->GetIntValue() & (_flag) ) != 0)
|
||||
|
||||
#define __BEGIN_SHADER_INTERNAL(_baseclass, name, help, flags) \
|
||||
namespace name \
|
||||
{\
|
||||
typedef _baseclass CBaseClass;\
|
||||
static const char *s_HelpString = help; \
|
||||
static const char *s_Name = #name; \
|
||||
static int s_nFlags = flags; \
|
||||
class CShaderParam;\
|
||||
static CUtlVector<CShaderParam *> s_ShaderParams;\
|
||||
static CShaderParam *s_pShaderParamOverrides[NUM_SHADER_MATERIAL_VARS];\
|
||||
class CShaderParam\
|
||||
{\
|
||||
public:\
|
||||
CShaderParam( ShaderMaterialVars_t var, ShaderParamType_t type, const char *pDefaultParam, const char *pHelp, int nFlags )\
|
||||
{\
|
||||
m_Info.m_pName = "override";\
|
||||
m_Info.m_Type = type;\
|
||||
m_Info.m_pDefaultValue = pDefaultParam;\
|
||||
m_Info.m_pHelp = pHelp;\
|
||||
m_Info.m_nFlags = nFlags;\
|
||||
AssertMsg( !s_pShaderParamOverrides[var], ( "Shader parameter override duplicately defined!" ) );\
|
||||
s_pShaderParamOverrides[var] = this;\
|
||||
m_Index = var;\
|
||||
}\
|
||||
CShaderParam( const char *pName, ShaderParamType_t type, const char *pDefaultParam, const char *pHelp, int nFlags )\
|
||||
{\
|
||||
m_Info.m_pName = pName;\
|
||||
m_Info.m_Type = type;\
|
||||
m_Info.m_pDefaultValue = pDefaultParam;\
|
||||
m_Info.m_pHelp = pHelp;\
|
||||
m_Info.m_nFlags = nFlags;\
|
||||
m_Index = NUM_SHADER_MATERIAL_VARS + s_ShaderParams.Count();\
|
||||
s_ShaderParams.AddToTail( this );\
|
||||
}\
|
||||
operator int() \
|
||||
{\
|
||||
return m_Index;\
|
||||
}\
|
||||
const ShaderParamInfo_t &GetInfo() const\
|
||||
{\
|
||||
return m_Info;\
|
||||
}\
|
||||
private:\
|
||||
ShaderParamInfo_t m_Info; \
|
||||
int m_Index;\
|
||||
};\
|
||||
|
||||
#define BEGIN_SHADER(name,help) __BEGIN_SHADER_INTERNAL( CBaseShader, name, help, 0 )
|
||||
#define BEGIN_SHADER_FLAGS(name,help,flags) __BEGIN_SHADER_INTERNAL( CBaseShader, name, help, flags )
|
||||
|
||||
#define BEGIN_SHADER_PARAMS
|
||||
|
||||
#define SHADER_PARAM( param, paramtype, paramdefault, paramhelp ) \
|
||||
static CShaderParam param( "$" #param, paramtype, paramdefault, paramhelp, 0 );
|
||||
|
||||
#define SHADER_PARAM_FLAGS( param, paramtype, paramdefault, paramhelp, flags ) \
|
||||
static CShaderParam param( "$" #param, paramtype, paramdefault, paramhelp, flags );
|
||||
|
||||
#define SHADER_PARAM_OVERRIDE( param, paramtype, paramdefault, paramhelp, flags ) \
|
||||
static CShaderParam param( (ShaderMaterialVars_t) ::param, paramtype, paramdefault, paramhelp, flags );
|
||||
|
||||
// regarding the macro above: the "::" was added to the first argument in order to disambiguate it for GCC.
|
||||
// for example, in cloak.cpp, this usage appears:
|
||||
// SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE )
|
||||
// which in turn tries to ask the compiler to instantiate an object like so:
|
||||
// static CShaderParam COLOR( (ShaderMaterialVars_t)COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE )
|
||||
// and GCC thinks that the reference to COLOR in the arg list is actually a reference to the object we're in the middle of making.
|
||||
// and you get --> error: invalid cast from type ‘Cloak_DX90::CShaderParam’ to type ‘ShaderMaterialVars_t’
|
||||
// Resolved: add the "::" so compiler knows that reference is to the enum, not to the name of the object being made.
|
||||
|
||||
|
||||
#define END_SHADER_PARAMS \
|
||||
class CShader : public CBaseClass\
|
||||
{\
|
||||
public:
|
||||
|
||||
#define END_SHADER }; \
|
||||
static CShader s_ShaderInstance;\
|
||||
} // namespace
|
||||
|
||||
|
||||
#define SHADER_INIT \
|
||||
char const* GetName() const \
|
||||
{ \
|
||||
return s_Name; \
|
||||
} \
|
||||
int GetFlags() const \
|
||||
{ \
|
||||
return s_nFlags; \
|
||||
} \
|
||||
int GetParamCount() const \
|
||||
{\
|
||||
return CBaseClass::GetParamCount() + s_ShaderParams.Count();\
|
||||
}\
|
||||
const ShaderParamInfo_t& GetParamInfo( int param ) const \
|
||||
{\
|
||||
int nBaseClassParamCount = CBaseClass::GetParamCount( ); \
|
||||
if (param < nBaseClassParamCount) \
|
||||
return CBaseClass::GetParamInfo( param ); \
|
||||
else \
|
||||
return s_ShaderParams[param - nBaseClassParamCount]->GetInfo(); \
|
||||
}\
|
||||
void OnInitShaderInstance( IMaterialVar **params, IShaderInit *pShaderInit, const char *pMaterialName )
|
||||
|
||||
#define SHADER_DRAW \
|
||||
void OnDrawElements( IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr )
|
||||
|
||||
#define SHADOW_STATE if (pShaderShadow)
|
||||
#define DYNAMIC_STATE if (pShaderAPI)
|
||||
|
||||
#define ShaderWarning if (pShaderShadow) Warning
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to easily define a shader which *always* falls back
|
||||
//-----------------------------------------------------------------------------
|
||||
#define DEFINE_FALLBACK_SHADER( _shadername, _fallbackshadername ) \
|
||||
BEGIN_SHADER( _shadername, "" ) \
|
||||
BEGIN_SHADER_PARAMS \
|
||||
END_SHADER_PARAMS \
|
||||
SHADER_FALLBACK { return #_fallbackshadername; } \
|
||||
SHADER_INIT {} \
|
||||
SHADER_DRAW {} \
|
||||
END_SHADER
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to easily define a shader which inherits from another shader
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// FIXME: There's a compiler bug preventing this from working.
|
||||
// Maybe it'll work under VC7!
|
||||
|
||||
//#define BEGIN_INHERITED_SHADER( name, _baseclass, help ) \
|
||||
// namespace _baseclass \
|
||||
// {\
|
||||
// __BEGIN_SHADER_INTERNAL( _baseclass::CShader, name, help )
|
||||
|
||||
//#define END_INHERITED_SHADER END_SHADER }
|
||||
|
||||
//#define CHAIN_SHADER_INIT_PARAMS() CBaseClass::OnInitShaderParams( params, pMaterialName )
|
||||
//#define CHAIN_SHADER_FALLBACK() CBaseClass::GetFallbackShader( params )
|
||||
//#define CHAIN_SHADER_INIT() CBaseClass::OnInitShaderInstance( params, pShaderInit, pMaterialName )
|
||||
//#define CHAIN_SHADER_DRAW() CBaseClass::OnDrawElements( params, pShaderShadow, pShaderAPI )
|
||||
|
||||
// A dumbed-down version which does what I need now which works
|
||||
// This version doesn't allow you to do chain *anything* down to the base class
|
||||
#define BEGIN_INHERITED_SHADER_FLAGS( _name, _base, _help, _flags ) \
|
||||
namespace _base\
|
||||
{\
|
||||
namespace _name\
|
||||
{\
|
||||
static const char *s_Name = #_name; \
|
||||
static const char *s_HelpString = _help;\
|
||||
static int s_nFlags = _flags;\
|
||||
class CShader : public _base::CShader\
|
||||
{\
|
||||
public:\
|
||||
char const* GetName() const \
|
||||
{ \
|
||||
return s_Name; \
|
||||
} \
|
||||
int GetFlags() const \
|
||||
{ \
|
||||
return s_nFlags; \
|
||||
}
|
||||
|
||||
#define BEGIN_INHERITED_SHADER( _name, _base, _help ) BEGIN_INHERITED_SHADER_FLAGS( _name, _base, _help, 0 )
|
||||
#define END_INHERITED_SHADER END_SHADER }
|
||||
|
||||
// psh ## shader is used here to generate a warning if you don't ever call SET_DYNAMIC_PIXEL_SHADER
|
||||
#define DECLARE_DYNAMIC_PIXEL_SHADER( shader ) \
|
||||
int declaredynpixshader_ ## shader ## _missingcurlybraces = 0; \
|
||||
declaredynpixshader_ ## shader ## _missingcurlybraces = declaredynpixshader_ ## shader ## _missingcurlybraces; \
|
||||
shader ## _Dynamic_Index _pshIndex( pShaderAPI ); \
|
||||
int psh ## shader = 0
|
||||
|
||||
// vsh ## shader is used here to generate a warning if you don't ever call SET_DYNAMIC_VERTEX_SHADER
|
||||
#define DECLARE_DYNAMIC_VERTEX_SHADER( shader ) \
|
||||
int declaredynvertshader_ ## shader ## _missingcurlybraces = 0; \
|
||||
declaredynvertshader_ ## shader ## _missingcurlybraces = declaredynvertshader_ ## shader ## _missingcurlybraces; \
|
||||
shader ## _Dynamic_Index _vshIndex( pShaderAPI ); \
|
||||
int vsh ## shader = 0
|
||||
|
||||
|
||||
// psh ## shader is used here to generate a warning if you don't ever call SET_STATIC_PIXEL_SHADER
|
||||
#define DECLARE_STATIC_PIXEL_SHADER( shader ) \
|
||||
int declarestaticpixshader_ ## shader ## _missingcurlybraces = 0; \
|
||||
declarestaticpixshader_ ## shader ## _missingcurlybraces = declarestaticpixshader_ ## shader ## _missingcurlybraces; \
|
||||
shader ## _Static_Index _pshIndex( pShaderShadow, params ); \
|
||||
int psh ## shader = 0
|
||||
|
||||
// vsh ## shader is used here to generate a warning if you don't ever call SET_STATIC_VERTEX_SHADER
|
||||
#define DECLARE_STATIC_VERTEX_SHADER( shader ) \
|
||||
int declarestaticvertshader_ ## shader ## _missingcurlybraces = 0; \
|
||||
declarestaticvertshader_ ## shader ## _missingcurlybraces = declarestaticvertshader_ ## shader ## _missingcurlybraces; \
|
||||
shader ## _Static_Index _vshIndex( pShaderShadow, params ); \
|
||||
int vsh ## shader = 0
|
||||
|
||||
|
||||
// psh_forgot_to_set_dynamic_ ## var is used to make sure that you set all
|
||||
// all combos. If you don't, you will get an undefined variable used error
|
||||
// in the SET_DYNAMIC_PIXEL_SHADER block.
|
||||
#define SET_DYNAMIC_PIXEL_SHADER_COMBO( var, val ) \
|
||||
int dynpixshadercombo_ ## var ## _missingcurlybraces = 0; \
|
||||
dynpixshadercombo_ ## var ## _missingcurlybraces = dynpixshadercombo_ ## var ## _missingcurlybraces; \
|
||||
_pshIndex.Set ## var( ( val ) ); if(g_shaderConfigDumpEnable){printf("\n PS dyn var %s = %d (%s)", #var, (int) val, #val );}; \
|
||||
int psh_forgot_to_set_dynamic_ ## var = 0
|
||||
|
||||
// Same as SET_DYNAMIC_PIXEL_SHADER_COMBO, except doesn't set "psh_forgot_to_set_dynamic_*" since
|
||||
// it isn't required to set a default variable, and we don't want an error when we do set it.
|
||||
#define SET_DYNAMIC_PIXEL_SHADER_COMBO_OVERRIDE_DEFAULT( var, val ) \
|
||||
int dynpixshadercombo_ ## var ## _missingcurlybraces = 0; \
|
||||
dynpixshadercombo_ ## var ## _missingcurlybraces = dynpixshadercombo_ ## var ## _missingcurlybraces; \
|
||||
_pshIndex.Set ## var( ( val ) );
|
||||
|
||||
// vsh_forgot_to_set_dynamic_ ## var is used to make sure that you set all
|
||||
// all combos. If you don't, you will get an undefined variable used error
|
||||
// in the SET_DYNAMIC_VERTEX_SHADER block.
|
||||
#define SET_DYNAMIC_VERTEX_SHADER_COMBO( var, val ) \
|
||||
int dynvertshadercombo_ ## var ## _missingcurlybraces = 0; \
|
||||
dynvertshadercombo_ ## var ## _missingcurlybraces = dynvertshadercombo_ ## var ## _missingcurlybraces; \
|
||||
_vshIndex.Set ## var( ( val ) ); if(g_shaderConfigDumpEnable){printf("\n VS dyn var %s = %d (%s)", #var, (int) val, #val );}; \
|
||||
int vsh_forgot_to_set_dynamic_ ## var = 0
|
||||
|
||||
|
||||
// psh_forgot_to_set_static_ ## var is used to make sure that you set all
|
||||
// all combos. If you don't, you will get an undefined variable used error
|
||||
// in the SET_STATIC_PIXEL_SHADER block.
|
||||
#define SET_STATIC_PIXEL_SHADER_COMBO( var, val ) \
|
||||
int staticpixshadercombo_ ## var ## _missingcurlybraces = 0; \
|
||||
staticpixshadercombo_ ## var ## _missingcurlybraces = staticpixshadercombo_ ## var ## _missingcurlybraces; \
|
||||
_pshIndex.Set ## var( ( val ) ); if(g_shaderConfigDumpEnable){printf("\n PS stat var %s = %d (%s)", #var, (int) val, #val );}; \
|
||||
int psh_forgot_to_set_static_ ## var = 0
|
||||
|
||||
// vsh_forgot_to_set_static_ ## var is used to make sure that you set all
|
||||
// all combos. If you don't, you will get an undefined variable used error
|
||||
// in the SET_STATIC_VERTEX_SHADER block.
|
||||
#define SET_STATIC_VERTEX_SHADER_COMBO( var, val ) \
|
||||
int staticvertshadercombo_ ## var ## _missingcurlybraces = 0; \
|
||||
staticvertshadercombo_ ## var ## _missingcurlybraces = staticvertshadercombo_ ## var ## _missingcurlybraces; \
|
||||
_vshIndex.Set ## var( ( val ) ); if(g_shaderConfigDumpEnable){printf("\n VS stat var %s = %d (%s)", #var, (int) val, #val );}; \
|
||||
int vsh_forgot_to_set_static_ ## var = 0
|
||||
|
||||
#define SET_STATIC_VERTEX_SHADER_COMBO_HAS_DEFAULT( var, val ) \
|
||||
int staticvertshadercombo_ ## var ## _missingcurlybraces = 0; \
|
||||
staticvertshadercombo_ ## var ## _missingcurlybraces = staticvertshadercombo_ ## var ## _missingcurlybraces; \
|
||||
_vshIndex.Set ## var( ( val ) );
|
||||
|
||||
|
||||
// psh_testAllCombos adds up all of the psh_forgot_to_set_dynamic_ ## var's from
|
||||
// SET_DYNAMIC_PIXEL_SHADER_COMBO so that an error is generated if they aren't set.
|
||||
// psh_testAllCombos is set to itself to avoid an unused variable warning.
|
||||
// psh ## shader being set to itself ensures that DECLARE_DYNAMIC_PIXEL_SHADER
|
||||
// was called for this particular shader.
|
||||
#define SET_DYNAMIC_PIXEL_SHADER( shader ) \
|
||||
int dynamicpixshader_ ## shader ## _missingcurlybraces = 0; \
|
||||
dynamicpixshader_ ## shader ## _missingcurlybraces = dynamicpixshader_ ## shader ## _missingcurlybraces; \
|
||||
int psh_testAllCombos = shaderDynamicTest_ ## shader; \
|
||||
psh_testAllCombos = psh_testAllCombos; \
|
||||
psh ## shader = psh ## shader; \
|
||||
pShaderAPI->SetPixelShaderIndex( _pshIndex.GetIndex() )
|
||||
|
||||
#ifdef _PS3
|
||||
|
||||
#define SET_DYNAMIC_PIXEL_SHADER_CMD( cmdstream, shader ) SET_DYNAMIC_PIXEL_SHADER( shader )
|
||||
|
||||
#else
|
||||
|
||||
#define SET_DYNAMIC_PIXEL_SHADER_CMD( cmdstream, shader ) \
|
||||
int dynamicpixshader_ ## shader ## _missingcurlybraces = 0; \
|
||||
dynamicpixshader_ ## shader ## _missingcurlybraces = dynamicpixshader_ ## shader ## _missingcurlybraces; \
|
||||
int psh_testAllCombos = shaderDynamicTest_ ## shader; \
|
||||
psh_testAllCombos = psh_testAllCombos; \
|
||||
psh ## shader = psh ## shader; \
|
||||
cmdstream.SetPixelShaderIndex( _pshIndex.GetIndex() )
|
||||
|
||||
#endif
|
||||
|
||||
// vsh_testAllCombos adds up all of the vsh_forgot_to_set_dynamic_ ## var's from
|
||||
// SET_DYNAMIC_VERTEX_SHADER_COMBO so that an error is generated if they aren't set.
|
||||
// vsh_testAllCombos is set to itself to avoid an unused variable warning.
|
||||
// vsh ## shader being set to itself ensures that DECLARE_DYNAMIC_VERTEX_SHADER
|
||||
// was called for this particular shader.
|
||||
#define SET_DYNAMIC_VERTEX_SHADER( shader ) \
|
||||
int dynamicvertshader_ ## shader ## _missingcurlybraces = 0; \
|
||||
dynamicvertshader_ ## shader ## _missingcurlybraces = dynamicvertshader_ ## shader ## _missingcurlybraces; \
|
||||
int vsh_testAllCombos = shaderDynamicTest_ ## shader; \
|
||||
vsh_testAllCombos = vsh_testAllCombos; \
|
||||
vsh ## shader = vsh ## shader; \
|
||||
pShaderAPI->SetVertexShaderIndex( _vshIndex.GetIndex() )
|
||||
|
||||
#ifdef _PS3
|
||||
|
||||
#define SET_DYNAMIC_VERTEX_SHADER_CMD( cmdstream, shader ) SET_DYNAMIC_VERTEX_SHADER( shader )
|
||||
|
||||
#else
|
||||
|
||||
#define SET_DYNAMIC_VERTEX_SHADER_CMD( cmdstream, shader ) \
|
||||
int dynamicvertshader_ ## shader ## _missingcurlybraces = 0; \
|
||||
dynamicvertshader_ ## shader ## _missingcurlybraces = dynamicvertshader_ ## shader ## _missingcurlybraces; \
|
||||
int vsh_testAllCombos = shaderDynamicTest_ ## shader; \
|
||||
vsh_testAllCombos = vsh_testAllCombos; \
|
||||
vsh ## shader = vsh ## shader; \
|
||||
cmdstream.SetVertexShaderIndex( _vshIndex.GetIndex() )
|
||||
#endif
|
||||
|
||||
// psh_testAllCombos adds up all of the psh_forgot_to_set_static_ ## var's from
|
||||
// SET_STATIC_PIXEL_SHADER_COMBO so that an error is generated if they aren't set.
|
||||
// psh_testAllCombos is set to itself to avoid an unused variable warning.
|
||||
// psh ## shader being set to itself ensures that DECLARE_STATIC_PIXEL_SHADER
|
||||
// was called for this particular shader.
|
||||
#define SET_STATIC_PIXEL_SHADER( shader ) \
|
||||
int staticpixshader_ ## shader ## _missingcurlybraces = 0; \
|
||||
staticpixshader_ ## shader ## _missingcurlybraces = staticpixshader_ ## shader ## _missingcurlybraces; \
|
||||
int psh_testAllCombos = shaderStaticTest_ ## shader; \
|
||||
psh_testAllCombos = psh_testAllCombos; \
|
||||
psh ## shader = psh ## shader; \
|
||||
pShaderShadow->SetPixelShader( #shader, _pshIndex.GetIndex() )
|
||||
|
||||
// vsh_testAllCombos adds up all of the vsh_forgot_to_set_static_ ## var's from
|
||||
// SET_STATIC_VERTEX_SHADER_COMBO so that an error is generated if they aren't set.
|
||||
// vsh_testAllCombos is set to itself to avoid an unused variable warning.
|
||||
// vsh ## shader being set to itself ensures that DECLARE_STATIC_VERTEX_SHADER
|
||||
// was called for this particular shader.
|
||||
#define SET_STATIC_VERTEX_SHADER( shader ) \
|
||||
int staticvertshader_ ## shader ## _missingcurlybraces = 0; \
|
||||
staticvertshader_ ## shader ## _missingcurlybraces = staticvertshader_ ## shader ## _missingcurlybraces; \
|
||||
int vsh_testAllCombos = shaderStaticTest_ ## shader; \
|
||||
vsh_testAllCombos = vsh_testAllCombos; \
|
||||
vsh ## shader = vsh ## shader; \
|
||||
pShaderShadow->SetVertexShader( #shader, _vshIndex.GetIndex() )
|
||||
|
||||
#endif // CSHADER_H
|
||||
30
public/shaderlib/shadercombosemantics.h
Normal file
30
public/shaderlib/shadercombosemantics.h
Normal file
@@ -0,0 +1,30 @@
|
||||
//==== Copyright (c) Valve Corporation, All rights reserved. =======//
|
||||
//
|
||||
// Vertex/Pixel Shaders
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERCOMBOSEMANTICS_H
|
||||
#define SHADERCOMBOSEMANTICS_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
struct ShaderComboInformation_t
|
||||
{
|
||||
const char *m_pComboName;
|
||||
int m_nComboMin;
|
||||
int m_nComboMax;
|
||||
};
|
||||
|
||||
struct ShaderComboSemantics_t
|
||||
{
|
||||
const char *pShaderName;
|
||||
const ShaderComboInformation_t *pDynamicShaderComboArray;
|
||||
int nDynamicShaderComboArrayCount;
|
||||
const ShaderComboInformation_t *pStaticShaderComboArray;
|
||||
int nStaticShaderComboArrayCount;
|
||||
};
|
||||
|
||||
#endif // SHADERCOMBOSEMANTICS_H
|
||||
Reference in New Issue
Block a user