initial
This commit is contained in:
119
materialsystem/shaderapidx9/ShaderShadowDx10.h
Normal file
119
materialsystem/shaderapidx9/ShaderShadowDx10.h
Normal file
@@ -0,0 +1,119 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERSHADOWDX10_H
|
||||
#define SHADERSHADOWDX10_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
#include "shaderapi/ishadershadow.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The empty shader shadow
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderShadowDx10 : public IShaderShadow
|
||||
{
|
||||
public:
|
||||
CShaderShadowDx10();
|
||||
virtual ~CShaderShadowDx10();
|
||||
|
||||
// Sets the default *shadow* state
|
||||
void SetDefaultState();
|
||||
|
||||
// Methods related to depth buffering
|
||||
void DepthFunc( ShaderDepthFunc_t depthFunc );
|
||||
void EnableDepthWrites( bool bEnable );
|
||||
void EnableDepthTest( bool bEnable );
|
||||
void EnablePolyOffset( PolygonOffsetMode_t nOffsetMode );
|
||||
|
||||
// Suppresses/activates color writing
|
||||
void EnableColorWrites( bool bEnable );
|
||||
void EnableAlphaWrites( bool bEnable );
|
||||
|
||||
// Methods related to alpha blending
|
||||
void EnableBlending( bool bEnable );
|
||||
void EnableBlendingForceOpaque( bool bEnable );
|
||||
void BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor );
|
||||
|
||||
// Alpha testing
|
||||
void EnableAlphaTest( bool bEnable );
|
||||
void AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ );
|
||||
|
||||
// Wireframe/filled polygons
|
||||
void PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode );
|
||||
|
||||
// Back face culling
|
||||
void EnableCulling( bool bEnable );
|
||||
|
||||
// Indicates the vertex format for use with a vertex shader
|
||||
// The flags to pass in here come from the VertexFormatFlags_t enum
|
||||
// If pTexCoordDimensions is *not* specified, we assume all coordinates
|
||||
// are 2-dimensional
|
||||
void VertexShaderVertexFormat( unsigned int flags,
|
||||
int numTexCoords, int* pTexCoordDimensions,
|
||||
int userDataSize );
|
||||
|
||||
// Per texture unit stuff
|
||||
void EnableTexture( Sampler_t stage, bool bEnable );
|
||||
void EnableVertexTexture( VertexTextureSampler_t stage, bool bEnable );
|
||||
|
||||
// Separate alpha blending
|
||||
void EnableBlendingSeparateAlpha( bool bEnable );
|
||||
void BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor );
|
||||
|
||||
// Sets the vertex and pixel shaders
|
||||
void SetVertexShader( const char *pFileName, int vshIndex );
|
||||
void SetPixelShader( const char *pFileName, int pshIndex );
|
||||
|
||||
// Convert from linear to gamma color space on writes to frame buffer.
|
||||
void EnableSRGBWrite( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
void EnableSRGBRead( Sampler_t stage, bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void DisableFogGammaCorrection( bool bDisable )
|
||||
{
|
||||
//FIXME: empty for now.
|
||||
}
|
||||
virtual void FogMode( ShaderFogMode_t fogMode, bool bVertexFog )
|
||||
{
|
||||
//FIXME: empty for now.
|
||||
}
|
||||
|
||||
// Alpha to coverage
|
||||
void EnableAlphaToCoverage( bool bEnable );
|
||||
|
||||
void SetShadowDepthFiltering( Sampler_t stage );
|
||||
|
||||
// More alpha blending state
|
||||
void BlendOp( ShaderBlendOp_t blendOp );
|
||||
void BlendOpSeparateAlpha( ShaderBlendOp_t blendOp );
|
||||
|
||||
virtual float GetLightMapScaleFactor( void ) const
|
||||
{
|
||||
Assert( 0 );
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
bool m_IsTranslucent;
|
||||
bool m_IsAlphaTested;
|
||||
bool m_bIsDepthWriteEnabled;
|
||||
bool m_bUsesVertexAndPixelShaders;
|
||||
};
|
||||
|
||||
|
||||
extern CShaderShadowDx10* g_pShaderShadowDx10;
|
||||
|
||||
#endif // SHADERSHADOWDX10_H
|
||||
1317
materialsystem/shaderapidx9/TransitionTable.cpp
Normal file
1317
materialsystem/shaderapidx9/TransitionTable.cpp
Normal file
File diff suppressed because it is too large
Load Diff
344
materialsystem/shaderapidx9/TransitionTable.h
Normal file
344
materialsystem/shaderapidx9/TransitionTable.h
Normal file
@@ -0,0 +1,344 @@
|
||||
//========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef TRANSITION_TABLE_H
|
||||
#define TRANSITION_TABLE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "utlvector.h"
|
||||
#include "shadershadowdx8.h"
|
||||
#include "utlsortvector.h"
|
||||
#include "checksum_crc.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
|
||||
// Required for DEBUG_BOARD_STATE
|
||||
#include "shaderapidx8_global.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
struct IDirect3DStateBlock9;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types related to transition table entries
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef void (*ApplyStateFunc_t)( const ShadowState_t& shadowState, int arg );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The DX8 implementation of the transition table
|
||||
//-----------------------------------------------------------------------------
|
||||
class CTransitionTable
|
||||
{
|
||||
public:
|
||||
struct CurrentSamplerState_t
|
||||
{
|
||||
bool m_SRGBReadEnable;
|
||||
bool m_Fetch4Enable;
|
||||
bool m_ShadowFilterEnable;
|
||||
};
|
||||
struct CurrentState_t
|
||||
{
|
||||
// Everything in this 'CurrentState' structure is a state whose value we don't care about
|
||||
// under certain circumstances, (which therefore can diverge from the shadow state),
|
||||
// or states which we override in the dynamic pass.
|
||||
|
||||
// Depth testing states
|
||||
union
|
||||
{
|
||||
DepthTestState_t m_DepthTestState;
|
||||
DepthTestState_t::UIntAlias m_nDepthTestStateAsInt;
|
||||
};
|
||||
|
||||
// alpha testijng and misc state
|
||||
union
|
||||
{
|
||||
AlphaTestAndMiscState_t m_AlphaTestAndMiscState;
|
||||
AlphaTestAndMiscState_t::UIntAlias m_nAlphaTestAndMiscStateAsInt;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
FogAndMiscState_t m_FogAndMiscState;
|
||||
FogAndMiscState_t::UIntAlias m_nFogAndMiscStateAsInt;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
AlphaBlendState_t m_AlphaBlendState;
|
||||
AlphaBlendState_t::UIntAlias m_nAlphaBlendStateAsInt;
|
||||
};
|
||||
|
||||
|
||||
bool m_ForceDepthFuncEquals:1;
|
||||
bool m_bOverrideDepthEnable:1;
|
||||
|
||||
bool m_bOverrideAlphaWriteEnable:1;
|
||||
bool m_bOverrideColorWriteEnable:1;
|
||||
|
||||
bool m_bOverriddenAlphaWriteValue:1;
|
||||
bool m_bOverriddenColorWriteValue:1;
|
||||
|
||||
|
||||
DWORD m_ColorWriteEnable;
|
||||
bool m_OverrideZWriteEnable;
|
||||
bool m_OverrideZTestEnable;
|
||||
|
||||
bool m_bLinearColorSpaceFrameBufferEnable;
|
||||
|
||||
// Texture stage state
|
||||
CurrentSamplerState_t m_SamplerState[MAX_SAMPLERS];
|
||||
};
|
||||
|
||||
public:
|
||||
// constructor, destructor
|
||||
CTransitionTable( );
|
||||
virtual ~CTransitionTable();
|
||||
|
||||
// Initialization, shutdown
|
||||
bool Init( );
|
||||
void Shutdown( );
|
||||
|
||||
// Resets the snapshots...
|
||||
void Reset();
|
||||
|
||||
// Takes a snapshot
|
||||
StateSnapshot_t TakeSnapshot( );
|
||||
|
||||
// Take startup snapshot
|
||||
void TakeDefaultStateSnapshot( );
|
||||
|
||||
ShadowShaderState_t *GetShaderShadowState( StateSnapshot_t snapshotId )
|
||||
{
|
||||
return &m_SnapshotList[snapshotId].m_ShaderState;
|
||||
}
|
||||
|
||||
// Makes the board state match the snapshot
|
||||
void UseSnapshot( StateSnapshot_t snapshotId, bool bApplyShaderState = true );
|
||||
|
||||
// Cause the board to match the default state snapshot
|
||||
void UseDefaultState();
|
||||
|
||||
// Snapshotted state overrides
|
||||
void ForceDepthFuncEquals( bool bEnable );
|
||||
void OverrideDepthEnable( bool bEnable, bool bDepthWriteEnable, bool bDepthTestEnable );
|
||||
void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable );
|
||||
void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable );
|
||||
void EnableLinearColorSpaceFrameBuffer( bool bEnable );
|
||||
|
||||
// Returns a particular snapshot
|
||||
const ShadowState_t &GetSnapshot( StateSnapshot_t snapshotId ) const;
|
||||
const ShadowShaderState_t &GetSnapshotShader( StateSnapshot_t snapshotId ) const;
|
||||
|
||||
// Gets the current shadow state
|
||||
const ShadowState_t *CurrentShadowState() const;
|
||||
const ShadowShaderState_t *CurrentShadowShaderState() const;
|
||||
|
||||
// Return the current shapshot
|
||||
int CurrentSnapshot() const { return m_CurrentSnapshotId; }
|
||||
|
||||
CurrentState_t& CurrentState() { return m_CurrentState; }
|
||||
|
||||
void SetShadowDepthBiasValuesDirty( bool bDirty ) { m_bShadowDepthBiasValuesDirty = bDirty; }
|
||||
|
||||
#ifdef DEBUG_BOARD_STATE
|
||||
ShadowState_t& BoardState() { return m_BoardState; }
|
||||
ShadowShaderState_t& BoardShaderState() { return m_BoardShaderState; }
|
||||
#endif
|
||||
|
||||
// The following are meant to be used by the transition table only
|
||||
public:
|
||||
// Applies alpha blending
|
||||
void ApplyAlphaBlend( const ShadowState_t& state );
|
||||
|
||||
// Separate alpha blend
|
||||
void ApplySeparateAlphaBlend( const ShadowState_t& state );
|
||||
void ApplyAlphaTest( const ShadowState_t& state );
|
||||
void ApplyDepthTest( const ShadowState_t& state );
|
||||
|
||||
// Applies alpha texture op
|
||||
void ApplyColorTextureStage( const ShadowState_t& state, int stage );
|
||||
void ApplyAlphaTextureStage( const ShadowState_t& state, int stage );
|
||||
|
||||
void ApplySRGBWriteEnable( const ShadowState_t& state );
|
||||
private:
|
||||
enum
|
||||
{
|
||||
INVALID_TRANSITION_OP = 0xFFFFFF
|
||||
};
|
||||
|
||||
typedef short ShadowStateId_t;
|
||||
|
||||
// For the transition table
|
||||
struct TransitionList_t
|
||||
{
|
||||
unsigned int m_FirstOperation : 24;
|
||||
unsigned int m_NumOperations : 8;
|
||||
};
|
||||
|
||||
union TransitionOp_t
|
||||
{
|
||||
unsigned char m_nBits;
|
||||
struct
|
||||
{
|
||||
unsigned char m_nOpCode : 7;
|
||||
unsigned char m_bIsTextureCode : 1;
|
||||
} m_nInfo;
|
||||
};
|
||||
|
||||
struct SnapshotShaderState_t
|
||||
{
|
||||
ShadowShaderState_t m_ShaderState;
|
||||
ShadowStateId_t m_ShadowStateId;
|
||||
unsigned short m_nReserved; // Pad to 2 ints
|
||||
unsigned int m_nReserved2;
|
||||
};
|
||||
|
||||
struct ShadowStateDictEntry_t
|
||||
{
|
||||
CRC32_t m_nChecksum;
|
||||
ShadowStateId_t m_nShadowStateId;
|
||||
};
|
||||
|
||||
struct SnapshotDictEntry_t
|
||||
{
|
||||
CRC32_t m_nChecksum;
|
||||
StateSnapshot_t m_nSnapshot;
|
||||
};
|
||||
|
||||
class ShadowStateDictLessFunc
|
||||
{
|
||||
public:
|
||||
bool Less( const ShadowStateDictEntry_t &src1, const ShadowStateDictEntry_t &src2, void *pCtx );
|
||||
};
|
||||
|
||||
class SnapshotDictLessFunc
|
||||
{
|
||||
public:
|
||||
bool Less( const SnapshotDictEntry_t &src1, const SnapshotDictEntry_t &src2, void *pCtx );
|
||||
};
|
||||
|
||||
class UniqueSnapshotLessFunc
|
||||
{
|
||||
public:
|
||||
bool Less( const TransitionList_t &src1, const TransitionList_t &src2, void *pCtx );
|
||||
};
|
||||
|
||||
CurrentSamplerState_t &SamplerState( int stage ) { return m_CurrentState.m_SamplerState[stage]; }
|
||||
const CurrentSamplerState_t &SamplerState( int stage ) const { return m_CurrentState.m_SamplerState[stage]; }
|
||||
|
||||
// creates state snapshots
|
||||
ShadowStateId_t CreateShadowState( const ShadowState_t ¤tState );
|
||||
StateSnapshot_t CreateStateSnapshot( ShadowStateId_t shadowStateId, const ShadowShaderState_t& currentShaderState );
|
||||
|
||||
// finds state snapshots
|
||||
ShadowStateId_t FindShadowState( const ShadowState_t& currentState ) const;
|
||||
StateSnapshot_t FindStateSnapshot( ShadowStateId_t id, const ShadowShaderState_t& currentState ) const;
|
||||
|
||||
// Finds identical transition lists
|
||||
unsigned int FindIdenticalTransitionList( unsigned int firstElem,
|
||||
unsigned short numOps, unsigned int nFirstTest ) const;
|
||||
|
||||
// Checks if a state is valid
|
||||
bool TestShadowState( const ShadowState_t& state, const ShadowShaderState_t &shaderState );
|
||||
|
||||
// Perform state block overrides
|
||||
void PerformShadowStateOverrides( );
|
||||
|
||||
// Apply shader state (stuff that doesn't lie in the transition table)
|
||||
void ApplyShaderState( const ShadowState_t &shadowState, const ShadowShaderState_t &shaderState );
|
||||
|
||||
// State setting methods
|
||||
void SetZEnable( D3DZBUFFERTYPE nEnable );
|
||||
void SetZFunc( D3DCMPFUNC nCmpFunc );
|
||||
|
||||
void SetBoardStateFromShadowState( ShadowState_t const &shadowState );
|
||||
|
||||
private:
|
||||
// Sets up the default state
|
||||
StateSnapshot_t m_DefaultStateSnapshot;
|
||||
TransitionList_t m_DefaultTransition;
|
||||
ShadowState_t m_DefaultShadowState;
|
||||
|
||||
// The current snapshot id
|
||||
ShadowStateId_t m_CurrentShadowId;
|
||||
StateSnapshot_t m_CurrentSnapshotId;
|
||||
|
||||
// Maintains a list of all used snapshot transition states
|
||||
CUtlVector< ShadowState_t > m_ShadowStateList;
|
||||
|
||||
// Lookup table for fast snapshot finding
|
||||
CUtlSortVector< ShadowStateDictEntry_t, ShadowStateDictLessFunc > m_ShadowStateDict;
|
||||
|
||||
// The snapshot transition table
|
||||
CUtlVector< CUtlVector< TransitionList_t > > m_TransitionTable;
|
||||
|
||||
// List of unique transitions
|
||||
CUtlSortVector< TransitionList_t, UniqueSnapshotLessFunc > m_UniqueTransitions;
|
||||
|
||||
// Stores all state transition operations
|
||||
CUtlVector< TransitionOp_t > m_TransitionOps;
|
||||
|
||||
// Stores all state for a particular snapshot
|
||||
CUtlVector< SnapshotShaderState_t > m_SnapshotList;
|
||||
|
||||
// Lookup table for fast snapshot finding
|
||||
CUtlSortVector< SnapshotDictEntry_t, SnapshotDictLessFunc > m_SnapshotDict;
|
||||
|
||||
// The current board state.
|
||||
CurrentState_t m_CurrentState;
|
||||
|
||||
bool m_bShadowDepthBiasValuesDirty;
|
||||
|
||||
#ifdef DEBUG_BOARD_STATE
|
||||
// Maintains the total shadow state
|
||||
ShadowState_t m_BoardState;
|
||||
ShadowShaderState_t m_BoardShaderState;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inline methods
|
||||
//-----------------------------------------------------------------------------
|
||||
inline const ShadowState_t &CTransitionTable::GetSnapshot( StateSnapshot_t snapshotId ) const
|
||||
{
|
||||
Assert( (snapshotId >= 0) && (snapshotId < m_SnapshotList.Count()) );
|
||||
return m_ShadowStateList[m_SnapshotList[snapshotId].m_ShadowStateId];
|
||||
}
|
||||
|
||||
inline const ShadowShaderState_t &CTransitionTable::GetSnapshotShader( StateSnapshot_t snapshotId ) const
|
||||
{
|
||||
Assert( (snapshotId >= 0) && (snapshotId < m_SnapshotList.Count()) );
|
||||
return m_SnapshotList[snapshotId].m_ShaderState;
|
||||
}
|
||||
|
||||
inline const ShadowState_t *CTransitionTable::CurrentShadowState() const
|
||||
{
|
||||
if ( m_CurrentShadowId == -1 )
|
||||
return NULL;
|
||||
|
||||
Assert( (m_CurrentShadowId >= 0) && (m_CurrentShadowId < m_ShadowStateList.Count()) );
|
||||
return &m_ShadowStateList[m_CurrentShadowId];
|
||||
}
|
||||
|
||||
inline const ShadowShaderState_t *CTransitionTable::CurrentShadowShaderState() const
|
||||
{
|
||||
if ( m_CurrentShadowId == -1 )
|
||||
return NULL;
|
||||
|
||||
Assert( (m_CurrentShadowId >= 0) && (m_CurrentShadowId < m_ShadowStateList.Count()) );
|
||||
return &m_SnapshotList[m_CurrentShadowId].m_ShaderState;
|
||||
}
|
||||
|
||||
|
||||
#endif // TRANSITION_TABLE_H
|
||||
302
materialsystem/shaderapidx9/cmatrixstack.cpp
Normal file
302
materialsystem/shaderapidx9/cmatrixstack.cpp
Normal file
@@ -0,0 +1,302 @@
|
||||
//========= Copyright <20> Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//==========================================================================//
|
||||
|
||||
#include "cmatrixstack.h"
|
||||
|
||||
|
||||
// Define RUN_TEST_CODE to validate that CMatrixStack behaves the same as ID3DXMatrixStack
|
||||
//#define RUN_TEST_CODE
|
||||
#if defined( RUN_TEST_CODE )
|
||||
|
||||
#ifndef WIN32
|
||||
#error sorry man
|
||||
#endif
|
||||
#ifdef _X360
|
||||
#include "d3d9.h"
|
||||
#include "d3dx9.h"
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include "../../dx9sdk/include/d3d9.h"
|
||||
#include "../../dx9sdk/include/d3dx9.h"
|
||||
#endif
|
||||
|
||||
#else // RUN_TEST_CODE
|
||||
|
||||
#if !defined( _X360 )
|
||||
struct D3DXMATRIX : public VMatrix{};
|
||||
struct D3DXVECTOR3 : public Vector{};
|
||||
#endif // _X360
|
||||
|
||||
#endif // RUN_TEST_CODE
|
||||
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
|
||||
CMatrixStack::CMatrixStack( void )
|
||||
{
|
||||
m_Stack.AddToTail();
|
||||
m_Stack.Tail().Identity();
|
||||
}
|
||||
|
||||
CMatrixStack::~CMatrixStack( void )
|
||||
{
|
||||
Assert( m_Stack.Count() == 1 ); // Catch push/pop mismatch
|
||||
Assert( m_Stack.Tail().IsIdentity() ); // Modifying the root matrix is probably unintentional
|
||||
}
|
||||
|
||||
D3DXMATRIX *CMatrixStack::GetTop( void )
|
||||
{
|
||||
return (D3DXMATRIX *)&m_Stack.Tail();
|
||||
}
|
||||
|
||||
void CMatrixStack::Push()
|
||||
{
|
||||
AssertMsg( m_Stack.Count() < 100, "CMatrixStack - Push/Pop mismatch!" ); // Catch push/pop mismatch
|
||||
// Duplicate the current 'top' matrix (NOTE: AddToTail can realloc!)
|
||||
m_Stack.AddToTail();
|
||||
VMatrix *top = &m_Stack.Tail();
|
||||
top[0] = top[-1];
|
||||
}
|
||||
|
||||
void CMatrixStack::Pop()
|
||||
{
|
||||
AssertMsg( m_Stack.Count() > 1, "CMatrixStack - Push/Pop mismatch!" ); // Catch push/pop mismatch
|
||||
m_Stack.RemoveMultipleFromTail( 1 );
|
||||
}
|
||||
|
||||
void CMatrixStack::LoadIdentity()
|
||||
{
|
||||
m_Stack.Tail().Identity();
|
||||
}
|
||||
|
||||
void CMatrixStack::LoadMatrix( const D3DXMATRIX *pMat )
|
||||
{
|
||||
COMPILE_TIME_ASSERT( sizeof( VMatrix ) == sizeof( D3DXMATRIX ) );
|
||||
memcpy( &m_Stack.Tail(), pMat, sizeof( VMatrix ) );
|
||||
}
|
||||
|
||||
void CMatrixStack::MultMatrix( const D3DXMATRIX *pMat )
|
||||
{
|
||||
// Right-multiply
|
||||
VMatrix &top = m_Stack.Tail();
|
||||
VMatrix result;
|
||||
MatrixMultiply( top, *(const VMatrix *)pMat, result );
|
||||
top = result;
|
||||
}
|
||||
|
||||
void CMatrixStack::MultMatrixLocal( const D3DXMATRIX *pMat )
|
||||
{
|
||||
// Left-multiply
|
||||
VMatrix &top = m_Stack.Tail();
|
||||
VMatrix result;
|
||||
MatrixMultiply( *(const VMatrix *)pMat, top, result );
|
||||
top = result;
|
||||
}
|
||||
|
||||
bool CMatrixStack::ScaleLocal( float x, float y, float z )
|
||||
{
|
||||
VMatrix scale;
|
||||
MatrixBuildScale( scale, x, y, z );
|
||||
// scale = scale.Transpose(); // A no-op, in this case :)
|
||||
MultMatrixLocal( (D3DXMATRIX *)&scale );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CMatrixStack::RotateAxisLocal( const D3DXVECTOR3 *pV, float angleInRadians )
|
||||
{
|
||||
COMPILE_TIME_ASSERT( sizeof( Vector ) == sizeof( D3DXVECTOR3 ) );
|
||||
const Vector &axis = *(const Vector *)pV;
|
||||
VMatrix rotate;
|
||||
MatrixBuildRotationAboutAxis( rotate, axis, angleInRadians * 180 / M_PI );
|
||||
rotate = rotate.Transpose();
|
||||
MultMatrixLocal( (D3DXMATRIX *)&rotate );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CMatrixStack::TranslateLocal( float x, float y, float z )
|
||||
{
|
||||
VMatrix translate;
|
||||
MatrixBuildTranslation( translate, x, y, z );
|
||||
translate = translate.Transpose();
|
||||
MultMatrixLocal( (D3DXMATRIX *)&translate );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==========================================================================//
|
||||
//
|
||||
// Test code to ensure this produces the same results as ID3DMATRIXStack
|
||||
//
|
||||
//==========================================================================//
|
||||
|
||||
#if defined( RUN_TEST_CODE )
|
||||
|
||||
class CMatrixStack_Test
|
||||
{
|
||||
enum TestOps
|
||||
{
|
||||
LOAD_IDENT = 0,
|
||||
LOAD_MAT = 1,
|
||||
PUSH = 2,
|
||||
POP = 3,
|
||||
MULT = 4,
|
||||
MULT_LOCAL = 5,
|
||||
// Only these local/left-multiply variants are used by ShaderAPI (not the right-multiply ROTATE/TRANSLATE/SCALE versions)
|
||||
SCALE_LOCAL = 6,
|
||||
ROTATE_LOCAL = 7,
|
||||
TRANSLATE_LOCAL = 8,
|
||||
NUM_TEST_OPS
|
||||
};
|
||||
|
||||
public:
|
||||
CMatrixStack *m_pStack;
|
||||
ID3DXMatrixStack *m_pD3DStack;
|
||||
CMatrixStack_Test()
|
||||
{
|
||||
m_pStack = new CMatrixStack();
|
||||
HRESULT result = D3DXCreateMatrixStack( 0, &m_pD3DStack );
|
||||
if ( result == S_OK )
|
||||
{
|
||||
VMatrix testMatrix;
|
||||
testMatrix.Identity();
|
||||
MatrixTranslate( testMatrix, Vector( 1, 2, 3 ) );
|
||||
MatrixRotate( testMatrix, Vector( 1, 0, 0 ), 90 );
|
||||
MatrixTranslate( testMatrix, Vector( 4, 5, 6 ) );
|
||||
// CMatrixStack mimics D3DX's transposed matrix style
|
||||
testMatrix = testMatrix.Transpose();
|
||||
|
||||
// Leave the top matrix unmodified
|
||||
m_pStack->Push();
|
||||
m_pD3DStack->Push();
|
||||
int depth = 2;
|
||||
|
||||
Msg( "CMatrixStack test...\n" );
|
||||
srand(1352469);
|
||||
for ( int i = 0; i < 1000; i++ )
|
||||
{
|
||||
TestOps op = (TestOps)( rand() % NUM_TEST_OPS );
|
||||
switch( op )
|
||||
{
|
||||
case LOAD_IDENT:
|
||||
Msg( "LOAD_IDENT\n" );
|
||||
m_pStack->LoadIdentity();
|
||||
m_pD3DStack->LoadIdentity();
|
||||
break;
|
||||
case LOAD_MAT:
|
||||
Msg( "LOAD_MAT\n" );
|
||||
m_pStack->LoadMatrix( (D3DXMATRIX *) &testMatrix );
|
||||
m_pD3DStack->LoadMatrix( (D3DXMATRIX *) &testMatrix );
|
||||
break;
|
||||
case PUSH:
|
||||
Msg( "PUSH\n" );
|
||||
m_pStack->Push();
|
||||
m_pD3DStack->Push();
|
||||
depth++;
|
||||
break;
|
||||
case POP:
|
||||
if ( depth > 2 ) // Leave the top matrix unmodified
|
||||
{
|
||||
Msg( "POP\n" );
|
||||
m_pStack->Pop();
|
||||
m_pD3DStack->Pop();
|
||||
depth--;
|
||||
}
|
||||
break;
|
||||
case MULT:
|
||||
Msg( "MULT\n" );
|
||||
m_pStack->MultMatrix( (D3DXMATRIX *) &testMatrix );
|
||||
m_pD3DStack->MultMatrix( (D3DXMATRIX *) &testMatrix );
|
||||
break;
|
||||
case MULT_LOCAL:
|
||||
Msg( "MULT_LOCAL\n" );
|
||||
m_pStack->MultMatrixLocal( (D3DXMATRIX *) &testMatrix );
|
||||
m_pD3DStack->MultMatrixLocal( (D3DXMATRIX *) &testMatrix );
|
||||
break;
|
||||
case SCALE_LOCAL:
|
||||
Msg( "SCALE_LOCAL\n" );
|
||||
if ( i & 1 )
|
||||
{
|
||||
m_pStack->ScaleLocal( 2.0f, 2.0f, 2.0f );
|
||||
m_pD3DStack->ScaleLocal( 2.0f, 2.0f, 2.0f );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pStack->ScaleLocal( 0.5f, 0.5f, 0.5f );
|
||||
m_pD3DStack->ScaleLocal( 0.5f, 0.5f, 0.5f );
|
||||
}
|
||||
break;
|
||||
case ROTATE_LOCAL:
|
||||
{
|
||||
Msg( "ROTATE_LOCAL\n" );
|
||||
float angleInRadians = ( (i&1)?+1:-1 )*0.5f*M_PI;
|
||||
D3DXVECTOR3 axis(1,0,0);
|
||||
if ( (i%3) == 1 ) axis = D3DXVECTOR3(0,1,0);
|
||||
if ( (i%3) == 2 ) axis = D3DXVECTOR3(0,0,1);
|
||||
m_pStack->RotateAxisLocal( &axis, angleInRadians );
|
||||
m_pD3DStack->RotateAxisLocal( &axis, angleInRadians );
|
||||
break;
|
||||
}
|
||||
case TRANSLATE_LOCAL:
|
||||
{
|
||||
Msg( "TRANSLATE_LOCAL\n" );
|
||||
Vector delta = RandomVector( -10, +10 );
|
||||
m_pStack->TranslateLocal( delta.x, delta.y, delta.z );
|
||||
m_pD3DStack->TranslateLocal( delta.x, delta.y, delta.z );
|
||||
break;
|
||||
}
|
||||
}
|
||||
CompareTopMatrices( op );
|
||||
}
|
||||
while( depth > 1 )
|
||||
{
|
||||
m_pStack->Pop();
|
||||
m_pD3DStack->Pop();
|
||||
depth--;
|
||||
CompareTopMatrices( POP );
|
||||
}
|
||||
|
||||
m_pD3DStack->Release();
|
||||
}
|
||||
delete m_pStack;
|
||||
}
|
||||
|
||||
void CompareTopMatrices( TestOps op )
|
||||
{
|
||||
// Compare the top matrices
|
||||
float mat[4][4], d3dMat[4][4];
|
||||
COMPILE_TIME_ASSERT( sizeof( D3DXMATRIX ) == 16*sizeof( float ) );
|
||||
memcpy( mat, m_pStack->GetTop(), sizeof( D3DXMATRIX ) );
|
||||
memcpy( d3dMat, m_pD3DStack->GetTop(), sizeof( D3DXMATRIX ) );
|
||||
for ( int y = 0; y < 4; y++ )
|
||||
{
|
||||
for ( int x = 0; x < 4; x++ )
|
||||
{
|
||||
static float absEpsilon = 1.0e-5f, relEpsilon = 1.0e-4f;
|
||||
float absolute = fabsf( mat[y][x] - d3dMat[y][x] );
|
||||
float relative = 0;
|
||||
if ( fabsf( d3dMat[y][x] ) > 0.00001f )
|
||||
{
|
||||
relative = fabsf( ( mat[y][x] / d3dMat[y][x] ) - 1.0f );
|
||||
}
|
||||
AssertMsg9( ( absolute <= absEpsilon ) && ( relative <= relEpsilon ),
|
||||
"DIFFERENCE! CMatrixStack[%d][%d] = %10f, ID3DXMatrixStack[%d][%d] = %10f (OP: %d, Absolute diff: %10e, Relative diff: %10e)\n",
|
||||
y, x, mat[y][x],
|
||||
y, x, d3dMat[y][x],
|
||||
op, absolute, relative );
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the D3D version back onto ours, to negate accumulated numerical differences
|
||||
m_pStack->LoadMatrix( m_pD3DStack->GetTop() );
|
||||
}
|
||||
};
|
||||
static CMatrixStack_Test g_MatrixStackTest;
|
||||
|
||||
#endif // defined( RUN_TEST_CODE )
|
||||
60
materialsystem/shaderapidx9/cmatrixstack.h
Normal file
60
materialsystem/shaderapidx9/cmatrixstack.h
Normal file
@@ -0,0 +1,60 @@
|
||||
//========= Copyright <20> Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//==========================================================================//
|
||||
|
||||
#ifndef CMATRIXSTACK_H
|
||||
#define CMATRIXSTACK_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "utlvector.h"
|
||||
#include "mathlib/vmatrix.h"
|
||||
|
||||
|
||||
// TODO: switch the PS3/OGL shaderapi implementations to use this (replace the incomplete implementation of ID3DXMatrixStack in dxabstract.h)
|
||||
|
||||
|
||||
struct D3DXMATRIX;
|
||||
struct D3DXVECTOR3;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CMatrixStack
|
||||
// A direct replacement for ID3DXMatrixStack, which has bugs
|
||||
// NOTE: it uses *TRANSPOSED* VMatrixes internally, to match D3D conventions
|
||||
class CMatrixStack
|
||||
{
|
||||
public:
|
||||
|
||||
// NOTE: The stack starts with one matrix, initialized to identity
|
||||
CMatrixStack();
|
||||
~CMatrixStack();
|
||||
|
||||
D3DXMATRIX *GetTop();
|
||||
void Push();
|
||||
void Pop();
|
||||
void LoadIdentity();
|
||||
void LoadMatrix( const D3DXMATRIX *pMat );
|
||||
void MultMatrix( const D3DXMATRIX *pMat );
|
||||
void MultMatrixLocal( const D3DXMATRIX *pMat );
|
||||
|
||||
// Left multiply the current matrix with the computed scale matrix
|
||||
// (scaling is about the local origin of the object)
|
||||
bool ScaleLocal( float x, float y, float z );
|
||||
|
||||
// Left multiply the current matrix with the computed rotation
|
||||
// matrix, counterclockwise about the given axis with the given angle.
|
||||
// (rotation is about the local origin of the object)
|
||||
bool RotateAxisLocal( const D3DXVECTOR3 *pV, float angleInRadians );
|
||||
|
||||
// Left multiply the current matrix with the computed translation
|
||||
// matrix. (transformation is about the local origin of the object)
|
||||
bool TranslateLocal( float x, float y, float z );
|
||||
|
||||
private:
|
||||
CUtlVector<VMatrix> m_Stack; // 'Top' of the stack is at m_stack[count-1] (push increases count, pop decreases)
|
||||
};
|
||||
|
||||
#endif // CMATRIXSTACK_H
|
||||
797
materialsystem/shaderapidx9/colorformatdx8.cpp
Normal file
797
materialsystem/shaderapidx9/colorformatdx8.cpp
Normal file
@@ -0,0 +1,797 @@
|
||||
//===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
////#define APIENTRY
|
||||
//#if defined(_WIN32) && !defined(_X360)
|
||||
////#define WIN32_LEAN_AND_MEAN
|
||||
////#define _WIN32_WINNT 0x0500
|
||||
////#include <windows.h>
|
||||
////#include <assert.h>
|
||||
//#endif
|
||||
//#include <GL/gl.h>
|
||||
//#include "tier0/platform.h"
|
||||
////#include <GL/glext.h>
|
||||
////#include "tier0/dynfunction.h"
|
||||
#define DISABLE_PROTECTED_THINGS
|
||||
#include "togl/rendermechanism.h"
|
||||
#include "locald3dtypes.h"
|
||||
#include "colorformatdx8.h"
|
||||
#include "shaderapidx8_global.h"
|
||||
#include "bitmap/imageformat.h"
|
||||
#include "shaderapi/ishaderutil.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "tier1/strtools.h"
|
||||
#include "shaderdevicedx8.h"
|
||||
|
||||
|
||||
// Must be last
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Figures out what texture formats we support
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// globals
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Texture formats supported by DX driver[vertextexture][render target][non filterable]
|
||||
static D3DFORMAT g_D3DColorFormat[NUM_IMAGE_FORMATS][2][2][2];
|
||||
static UINT g_DisplayAdapter;
|
||||
static D3DDEVTYPE g_DeviceType;
|
||||
static ImageFormat g_DeviceFormat;
|
||||
static bool g_bSupportsD24S8;
|
||||
static bool g_bSupportsD24X8;
|
||||
static bool g_bSupportsD16;
|
||||
static bool g_bSupportsD24X4S4;
|
||||
static bool g_bSupportsD15S1;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Determines what formats we actually *do* support
|
||||
//-----------------------------------------------------------------------------
|
||||
static bool TestTextureFormat( D3DFORMAT format, bool bIsRenderTarget,
|
||||
bool bIsVertexTexture, bool bIsFilterableRequired )
|
||||
{
|
||||
int nUsage = bIsRenderTarget ? D3DUSAGE_RENDERTARGET : 0;
|
||||
if ( bIsVertexTexture )
|
||||
{
|
||||
// vertex textures never need filtering
|
||||
nUsage |= D3DUSAGE_QUERY_VERTEXTEXTURE;
|
||||
}
|
||||
if ( bIsFilterableRequired )
|
||||
{
|
||||
nUsage |= D3DUSAGE_QUERY_FILTER;
|
||||
}
|
||||
|
||||
HRESULT hr;
|
||||
|
||||
// IHV depth texture formats require a slightly different check...
|
||||
if ( !IsGameConsole() && bIsRenderTarget && ( ( format == NVFMT_RAWZ ) || ( format == NVFMT_INTZ ) ||
|
||||
( format == D3DFMT_D16 ) || ( format == D3DFMT_D24S8 ) ||
|
||||
( format == ATIFMT_D16 ) || ( format == ATIFMT_D24S8 ) ) )
|
||||
{
|
||||
hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ),
|
||||
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, format );
|
||||
}
|
||||
else if ( IsX360() && bIsRenderTarget )
|
||||
{
|
||||
// 360 can only validate render targets as surface display format
|
||||
hr = D3D()->CheckDeviceFormat( g_DisplayAdapter, g_DeviceType, format, 0, D3DRTYPE_SURFACE, format );
|
||||
}
|
||||
else // general case:
|
||||
{
|
||||
// See if we can do it!
|
||||
hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ),
|
||||
nUsage, D3DRTYPE_TEXTURE, format );
|
||||
}
|
||||
|
||||
#ifdef _PS3
|
||||
// We have a conflict with the SUCCEEDED macro
|
||||
return hr >= 0;
|
||||
#else // _PS3
|
||||
return SUCCEEDED( hr );
|
||||
#endif // !_PS3
|
||||
}
|
||||
|
||||
D3DFORMAT GetNearestD3DColorFormat( ImageFormat fmt,
|
||||
bool isRenderTarget, bool bIsVertexTexture,
|
||||
bool bIsFilterableRequired)
|
||||
{
|
||||
switch(fmt)
|
||||
{
|
||||
case IMAGE_FORMAT_RGBA8888:
|
||||
case IMAGE_FORMAT_ABGR8888:
|
||||
case IMAGE_FORMAT_ARGB8888:
|
||||
case IMAGE_FORMAT_BGRA8888:
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
if (TestTextureFormat(D3DFMT_A4R4G4B4, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A4R4G4B4;
|
||||
break;
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_LINEAR_RGBA8888:
|
||||
case IMAGE_FORMAT_LINEAR_ABGR8888:
|
||||
case IMAGE_FORMAT_LINEAR_ARGB8888:
|
||||
case IMAGE_FORMAT_LINEAR_BGRA8888:
|
||||
// same as above - all xxxx8888 RGBA ordering funnels to d3d a8r8g8b8
|
||||
if ( TestTextureFormat( D3DFMT_LIN_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_LIN_A8R8G8B8;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_LINEAR_BGRX8888:
|
||||
if ( TestTextureFormat( D3DFMT_LIN_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_LIN_X8R8G8B8;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case IMAGE_FORMAT_BGRX8888:
|
||||
// We want this format to return exactly it's equivalent so that
|
||||
// when we create render targets to blit to from the framebuffer,
|
||||
// the CopyRect won't fail due to format mismatches.
|
||||
if (TestTextureFormat(D3DFMT_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_X8R8G8B8;
|
||||
|
||||
// fall through. . . .
|
||||
case IMAGE_FORMAT_RGB888:
|
||||
case IMAGE_FORMAT_BGR888:
|
||||
#if !defined( _GAMECONSOLE )
|
||||
if (TestTextureFormat(D3DFMT_R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_R8G8B8;
|
||||
#endif
|
||||
if (TestTextureFormat(D3DFMT_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_X8R8G8B8;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
if (TestTextureFormat(D3DFMT_R5G6B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_R5G6B5;
|
||||
if (TestTextureFormat(D3DFMT_X1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_X1R5G5B5;
|
||||
if (TestTextureFormat(D3DFMT_A1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A1R5G5B5;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_BGR565:
|
||||
case IMAGE_FORMAT_RGB565:
|
||||
if (TestTextureFormat(D3DFMT_R5G6B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_R5G6B5;
|
||||
if (TestTextureFormat(D3DFMT_X1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_X1R5G5B5;
|
||||
if (TestTextureFormat(D3DFMT_A1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A1R5G5B5;
|
||||
#if !defined( _GAMECONSOLE )
|
||||
if (TestTextureFormat(D3DFMT_R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_R8G8B8;
|
||||
#endif
|
||||
if (TestTextureFormat(D3DFMT_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_X8R8G8B8;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_BGRX5551:
|
||||
if (TestTextureFormat(D3DFMT_X1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_X1R5G5B5;
|
||||
if (TestTextureFormat(D3DFMT_A1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A1R5G5B5;
|
||||
if (TestTextureFormat(D3DFMT_R5G6B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_R5G6B5;
|
||||
#if !defined( _GAMECONSOLE )
|
||||
if (TestTextureFormat(D3DFMT_R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_R8G8B8;
|
||||
#endif
|
||||
if (TestTextureFormat(D3DFMT_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_X8R8G8B8;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_LINEAR_BGRX5551:
|
||||
if ( TestTextureFormat( D3DFMT_LIN_X1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_LIN_X1R5G5B5;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case IMAGE_FORMAT_BGRA5551:
|
||||
if (TestTextureFormat(D3DFMT_A1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A1R5G5B5;
|
||||
if (TestTextureFormat(D3DFMT_A4R4G4B4, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A4R4G4B4;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_BGRA4444:
|
||||
if (TestTextureFormat(D3DFMT_A4R4G4B4, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A4R4G4B4;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_I8:
|
||||
if (TestTextureFormat(D3DFMT_L8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_L8;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_LINEAR_I8:
|
||||
if ( TestTextureFormat( D3DFMT_LIN_L8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_LIN_L8;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case IMAGE_FORMAT_IA88:
|
||||
if (TestTextureFormat(D3DFMT_A8L8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8L8;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_A8:
|
||||
if (TestTextureFormat(D3DFMT_A8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8;
|
||||
if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_LINEAR_A8:
|
||||
if (TestTextureFormat(D3DFMT_LIN_A8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_LIN_A8;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case IMAGE_FORMAT_DXT1:
|
||||
case IMAGE_FORMAT_DXT1_ONEBITALPHA:
|
||||
case IMAGE_FORMAT_DXT1_RUNTIME:
|
||||
if (TestTextureFormat(D3DFMT_DXT1, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_DXT1;
|
||||
break;
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_LINEAR_DXT1:
|
||||
if (TestTextureFormat(D3DFMT_LIN_DXT1, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_LIN_DXT1;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case IMAGE_FORMAT_DXT3:
|
||||
if (TestTextureFormat(D3DFMT_DXT3, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ))
|
||||
return D3DFMT_DXT3;
|
||||
break;
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_LINEAR_DXT3:
|
||||
if (TestTextureFormat(D3DFMT_LIN_DXT3, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_LIN_DXT3;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case IMAGE_FORMAT_DXT5:
|
||||
case IMAGE_FORMAT_DXT5_RUNTIME:
|
||||
if (TestTextureFormat(D3DFMT_DXT5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ))
|
||||
return D3DFMT_DXT5;
|
||||
break;
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_LINEAR_DXT5:
|
||||
if (TestTextureFormat(D3DFMT_LIN_DXT5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired))
|
||||
return D3DFMT_LIN_DXT5;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case IMAGE_FORMAT_UV88:
|
||||
if (TestTextureFormat(D3DFMT_V8U8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ))
|
||||
return D3DFMT_V8U8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_UVWQ8888:
|
||||
if (TestTextureFormat(D3DFMT_Q8W8V8U8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ))
|
||||
return D3DFMT_Q8W8V8U8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_UVLX8888:
|
||||
if (TestTextureFormat(D3DFMT_X8L8V8U8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ))
|
||||
return D3DFMT_X8L8V8U8;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_RGBA16161616F:
|
||||
if ( TestTextureFormat( D3DFMT_A16B16G16R16F, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_A16B16G16R16F;
|
||||
if ( TestTextureFormat( D3DFMT_A16B16G16R16, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_A16B16G16R16;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_RGBA16161616:
|
||||
if ( TestTextureFormat( D3DFMT_A16B16G16R16, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_A16B16G16R16;
|
||||
if ( TestTextureFormat( D3DFMT_A16B16G16R16F, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_A16B16G16R16F;
|
||||
break;
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_LINEAR_RGBA16161616:
|
||||
if ( TestTextureFormat( D3DFMT_LIN_A16B16G16R16, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_LIN_A16B16G16R16;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case IMAGE_FORMAT_R32F:
|
||||
if ( TestTextureFormat( D3DFMT_R32F, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_R32F;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_RGBA32323232F:
|
||||
if ( TestTextureFormat( D3DFMT_A32B32G32R32F, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_A32B32G32R32F;
|
||||
break;
|
||||
|
||||
#if defined( _X360 ) || defined( _PS3 )
|
||||
case IMAGE_FORMAT_D16:
|
||||
return D3DFMT_D16;
|
||||
|
||||
case IMAGE_FORMAT_D24S8:
|
||||
return D3DFMT_D24S8;
|
||||
#endif // _X360 || _PS3
|
||||
|
||||
#if defined( _X360 )
|
||||
case IMAGE_FORMAT_D24FS8:
|
||||
return D3DFMT_D24FS8;
|
||||
|
||||
case IMAGE_FORMAT_LE_BGRX8888:
|
||||
return D3DFMT_LE_X8R8G8B8;
|
||||
|
||||
case IMAGE_FORMAT_LE_BGRA8888:
|
||||
return D3DFMT_LE_A8R8G8B8;
|
||||
#endif // _X360
|
||||
|
||||
#if defined( DX_TO_GL_ABSTRACTION )
|
||||
case IMAGE_FORMAT_D24S8:
|
||||
return D3DFMT_D24S8;
|
||||
|
||||
case IMAGE_FORMAT_D24X8:
|
||||
return D3DFMT_D24X8;
|
||||
#endif
|
||||
|
||||
// nVidia overloads DST formats as texture formats
|
||||
case IMAGE_FORMAT_D16:
|
||||
case IMAGE_FORMAT_D16_SHADOW:
|
||||
|
||||
if ( IsOpenGL() )
|
||||
{
|
||||
return D3DFMT_D16;
|
||||
}
|
||||
|
||||
// Only try ATIFMT_D16 on non-DX10 capable ATI cards (where we use fetch4). On DX10 capable ATI cards we use hardware PCF.
|
||||
if ( g_pHardwareConfig->Caps().m_VendorID == VENDORID_ATI && ( CommandLine()->CheckParm( "-forceatifetch4" ) || !g_pHardwareConfig->Caps().m_bDX10Card ) )
|
||||
{
|
||||
if ( TestTextureFormat( ATIFMT_D16, isRenderTarget, bIsVertexTexture, false ) )
|
||||
return ATIFMT_D16;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( TestTextureFormat( D3DFMT_D16, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_D16;
|
||||
}
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_D24X8_SHADOW:
|
||||
|
||||
if ( IsOSXOpenGL() )
|
||||
{
|
||||
return D3DFMT_D24X8;
|
||||
}
|
||||
|
||||
// Only try ATIFMT_D24S8 on non-DX10 capable ATI cards (where we use fetch4). On DX10 capable ATI cards we use hardware PCF.
|
||||
if ( g_pHardwareConfig->Caps().m_VendorID == VENDORID_ATI && ( CommandLine()->CheckParm( "-forceatifetch4" ) || !g_pHardwareConfig->Caps().m_bDX10Card ) )
|
||||
{
|
||||
if ( TestTextureFormat( ATIFMT_D24S8, isRenderTarget, bIsVertexTexture, false ) )
|
||||
return ATIFMT_D24S8;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( TestTextureFormat( D3DFMT_D24S8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return D3DFMT_D24S8;
|
||||
}
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_NULL:
|
||||
if ( TestTextureFormat( NVFMT_NULL, isRenderTarget, bIsVertexTexture, false ) )
|
||||
return NVFMT_NULL;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_ATI2N:
|
||||
if ( TestTextureFormat( ATIFMT_ATI2N, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return ATIFMT_ATI2N;
|
||||
break;
|
||||
|
||||
case IMAGE_FORMAT_ATI1N:
|
||||
if ( TestTextureFormat( ATIFMT_ATI1N, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return ATIFMT_ATI1N;
|
||||
break;
|
||||
case IMAGE_FORMAT_INTZ:
|
||||
if ( TestTextureFormat( NVFMT_INTZ, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) )
|
||||
return NVFMT_INTZ;
|
||||
break;
|
||||
}
|
||||
|
||||
return D3DFMT_UNKNOWN;
|
||||
}
|
||||
|
||||
void InitializeColorInformation( UINT displayAdapter, D3DDEVTYPE deviceType,
|
||||
ImageFormat displayFormat )
|
||||
{
|
||||
g_DisplayAdapter = displayAdapter;
|
||||
g_DeviceType = deviceType;
|
||||
g_DeviceFormat = displayFormat;
|
||||
|
||||
int fmt = 0;
|
||||
while ( fmt < NUM_IMAGE_FORMATS )
|
||||
{
|
||||
for ( int nVertexTexture = 0; nVertexTexture <= 1; ++nVertexTexture )
|
||||
{
|
||||
for ( int nRenderTarget = 0; nRenderTarget <= 1; ++nRenderTarget )
|
||||
{
|
||||
for ( int nFilterable = 0; nFilterable <= 1; ++nFilterable )
|
||||
{
|
||||
g_D3DColorFormat[fmt][nVertexTexture][nRenderTarget][nFilterable] =
|
||||
GetNearestD3DColorFormat( (ImageFormat)fmt, nRenderTarget != 0, nVertexTexture != 0, nFilterable != 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
++fmt;
|
||||
}
|
||||
|
||||
// Check the depth formats
|
||||
HRESULT hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ),
|
||||
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24S8 );
|
||||
g_bSupportsD24S8 = !FAILED(hr);
|
||||
|
||||
hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ),
|
||||
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8 );
|
||||
g_bSupportsD24X8 = !FAILED(hr);
|
||||
|
||||
hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ),
|
||||
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16 );
|
||||
g_bSupportsD16 = !FAILED(hr);
|
||||
|
||||
#if !defined( _X360 )
|
||||
hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ),
|
||||
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X4S4 );
|
||||
g_bSupportsD24X4S4 = !FAILED(hr);
|
||||
#else
|
||||
g_bSupportsD24X4S4 = false;
|
||||
#endif
|
||||
|
||||
#if !defined( _X360 )
|
||||
hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ),
|
||||
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D15S1 );
|
||||
g_bSupportsD15S1 = !FAILED(hr);
|
||||
#else
|
||||
g_bSupportsD15S1 = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if compressed textures are supported
|
||||
//-----------------------------------------------------------------------------
|
||||
bool D3DSupportsCompressedTextures()
|
||||
{
|
||||
return (g_D3DColorFormat[IMAGE_FORMAT_DXT1][0][0][0] != D3DFMT_UNKNOWN) &&
|
||||
(g_D3DColorFormat[IMAGE_FORMAT_DXT3][0][0][0] != D3DFMT_UNKNOWN) &&
|
||||
(g_D3DColorFormat[IMAGE_FORMAT_DXT5][0][0][0] != D3DFMT_UNKNOWN);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns closest supported format
|
||||
//-----------------------------------------------------------------------------
|
||||
D3DFORMAT FindNearestSupportedFormat( ImageFormat format, bool bIsVertexTexture, bool bIsRenderTarget, bool bFilterableRequired )
|
||||
{
|
||||
return g_D3DColorFormat[format][bIsVertexTexture][bIsRenderTarget][bFilterableRequired];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if compressed textures are supported
|
||||
//-----------------------------------------------------------------------------
|
||||
bool D3DSupportsDepthTexture(D3DFORMAT format)
|
||||
{
|
||||
// See if we can do it!
|
||||
HRESULT hr = D3D()->CheckDeviceFormat(
|
||||
g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat(g_DeviceFormat),
|
||||
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, format);
|
||||
|
||||
return !FAILED(hr);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if the depth format is compatible with the display
|
||||
//-----------------------------------------------------------------------------
|
||||
static inline bool IsDepthFormatCompatible( int nAdapter, ImageFormat displayFormat, ImageFormat renderTargetFormat, D3DFORMAT depthFormat )
|
||||
{
|
||||
D3DFORMAT d3dDisplayFormat = ImageLoader::ImageFormatToD3DFormat( displayFormat );
|
||||
D3DFORMAT d3dRenderTargetFormat = ImageLoader::ImageFormatToD3DFormat( renderTargetFormat );
|
||||
|
||||
// Verify that the depth format is compatible.
|
||||
HRESULT hr = D3D()->CheckDepthStencilMatch( nAdapter, DX8_DEVTYPE,
|
||||
d3dDisplayFormat, d3dRenderTargetFormat, depthFormat);
|
||||
return !FAILED(hr);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds the nearest supported depth buffer format
|
||||
//-----------------------------------------------------------------------------
|
||||
D3DFORMAT FindNearestSupportedDepthFormat( int nAdapter, ImageFormat displayFormat, ImageFormat renderTargetFormat, D3DFORMAT depthFormat )
|
||||
{
|
||||
// This is the default case, used for rendering to the main render target
|
||||
Assert( displayFormat != IMAGE_FORMAT_UNKNOWN && renderTargetFormat != IMAGE_FORMAT_UNKNOWN );
|
||||
|
||||
switch (depthFormat)
|
||||
{
|
||||
#if defined( _X360 )
|
||||
case D3DFMT_D24FS8:
|
||||
return D3DFMT_D24FS8;
|
||||
|
||||
case D3DFMT_LIN_D24S8:
|
||||
if ( g_bSupportsD24S8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_LIN_D24S8 ) )
|
||||
return D3DFMT_LIN_D24S8;
|
||||
#endif
|
||||
case D3DFMT_D24S8:
|
||||
if ( g_bSupportsD24S8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24S8 ) )
|
||||
return D3DFMT_D24S8;
|
||||
#if !defined( _X360 )
|
||||
if ( g_bSupportsD24X4S4 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X4S4 ) )
|
||||
return D3DFMT_D24X4S4;
|
||||
if ( g_bSupportsD15S1 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D15S1 ) )
|
||||
return D3DFMT_D15S1;
|
||||
#endif
|
||||
if ( g_bSupportsD24X8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X8 ) )
|
||||
return D3DFMT_D24X8;
|
||||
if ( g_bSupportsD16 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D16 ) )
|
||||
return D3DFMT_D16;
|
||||
break;
|
||||
|
||||
case D3DFMT_D24X8:
|
||||
if ( g_bSupportsD24X8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X8 ) )
|
||||
return D3DFMT_D24X8;
|
||||
if ( g_bSupportsD24S8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24S8 ) )
|
||||
return D3DFMT_D24S8;
|
||||
#if !defined( _X360 )
|
||||
if ( g_bSupportsD24X4S4 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X4S4 ) )
|
||||
return D3DFMT_D24X4S4;
|
||||
#endif
|
||||
if ( g_bSupportsD16 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D16 ) )
|
||||
return D3DFMT_D16;
|
||||
#if !defined( _X360 )
|
||||
if ( g_bSupportsD15S1 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D15S1 ) )
|
||||
return D3DFMT_D15S1;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case D3DFMT_D16:
|
||||
if ( g_bSupportsD16 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D16 ) )
|
||||
return D3DFMT_D16;
|
||||
#if !defined( _X360 )
|
||||
if ( g_bSupportsD15S1 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D15S1 ) )
|
||||
return D3DFMT_D15S1;
|
||||
#endif
|
||||
if ( g_bSupportsD24X8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X8 ) )
|
||||
return D3DFMT_D24X8;
|
||||
if ( g_bSupportsD24S8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24S8 ) )
|
||||
return D3DFMT_D24S8;
|
||||
#if !defined( _X360 )
|
||||
if ( g_bSupportsD24X4S4 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X4S4 ) )
|
||||
return D3DFMT_D24X4S4;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
Assert( 0 );
|
||||
return D3DFMT_D16;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Is a display buffer valid?
|
||||
//-----------------------------------------------------------------------------
|
||||
static inline bool IsFrameBufferFormatValid( UINT displayAdapter, D3DDEVTYPE deviceType,
|
||||
D3DFORMAT displayFormat, D3DFORMAT backBufferFormat, bool bIsWindowed )
|
||||
{
|
||||
HRESULT hr = D3D()->CheckDeviceType( displayAdapter, deviceType, displayFormat,
|
||||
backBufferFormat, bIsWindowed );
|
||||
return !FAILED(hr);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds the nearest supported frame buffer format
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageFormat FindNearestSupportedBackBufferFormat( UINT displayAdapter,
|
||||
D3DDEVTYPE deviceType, ImageFormat displayFormat, ImageFormat backBufferFormat, bool bIsWindowed )
|
||||
{
|
||||
D3DFORMAT d3dDisplayFormat = ImageLoader::ImageFormatToD3DFormat( displayFormat );
|
||||
switch (backBufferFormat)
|
||||
{
|
||||
case IMAGE_FORMAT_RGBA8888:
|
||||
case IMAGE_FORMAT_ABGR8888:
|
||||
case IMAGE_FORMAT_ARGB8888:
|
||||
case IMAGE_FORMAT_BGRA8888:
|
||||
case IMAGE_FORMAT_BGRA4444: // This is not supported ever; bump up to 32 bit
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA8888;
|
||||
|
||||
// Bye, bye dest alpha
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX8888;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGR565;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX5551;
|
||||
|
||||
return IMAGE_FORMAT_UNKNOWN;
|
||||
|
||||
case IMAGE_FORMAT_RGB888:
|
||||
case IMAGE_FORMAT_BGR888:
|
||||
case IMAGE_FORMAT_RGB888_BLUESCREEN:
|
||||
case IMAGE_FORMAT_BGRX8888:
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX8888;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA8888;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGR565;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX5551;
|
||||
|
||||
return IMAGE_FORMAT_UNKNOWN;
|
||||
|
||||
case IMAGE_FORMAT_RGB565:
|
||||
case IMAGE_FORMAT_BGR565:
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGR565;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX8888;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA8888;
|
||||
|
||||
return IMAGE_FORMAT_UNKNOWN;
|
||||
|
||||
case IMAGE_FORMAT_BGRX5551:
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGR565;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX8888;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA8888;
|
||||
|
||||
return IMAGE_FORMAT_UNKNOWN;
|
||||
|
||||
case IMAGE_FORMAT_BGRA5551:
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX5551;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGR565;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRA8888;
|
||||
|
||||
if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed ))
|
||||
return IMAGE_FORMAT_BGRX8888;
|
||||
|
||||
return IMAGE_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
return IMAGE_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
#if defined( _X360 )
|
||||
const char *D3DFormatName( D3DFORMAT d3dFormat )
|
||||
{
|
||||
if ( IS_D3DFORMAT_SRGB( d3dFormat ) )
|
||||
{
|
||||
// sanitize the format from possible sRGB state for comparison purposes
|
||||
d3dFormat = MAKE_NON_SRGB_FMT( d3dFormat );
|
||||
}
|
||||
|
||||
switch ( d3dFormat )
|
||||
{
|
||||
case D3DFMT_A8R8G8B8:
|
||||
return "D3DFMT_A8R8G8B8";
|
||||
case D3DFMT_LIN_A8R8G8B8:
|
||||
return "D3DFMT_LIN_A8R8G8B8";
|
||||
case D3DFMT_X8R8G8B8:
|
||||
return "D3DFMT_X8R8G8B8";
|
||||
case D3DFMT_LIN_X8R8G8B8:
|
||||
return "D3DFMT_LIN_X8R8G8B8";
|
||||
case D3DFMT_R5G6B5:
|
||||
return "D3DFMT_R5G6B5";
|
||||
case D3DFMT_X1R5G5B5:
|
||||
return "D3DFMT_X1R5G5B5";
|
||||
case D3DFMT_A1R5G5B5:
|
||||
return "D3DFMT_A1R5G5B5";
|
||||
case D3DFMT_A4R4G4B4:
|
||||
return "D3DFMT_A4R4G4B4";
|
||||
case D3DFMT_L8:
|
||||
return "D3DFMT_L8";
|
||||
case D3DFMT_A8L8:
|
||||
return "D3DFMT_A8L8";
|
||||
case D3DFMT_A8:
|
||||
return "D3DFMT_A8";
|
||||
case D3DFMT_DXT1:
|
||||
return "D3DFMT_DXT1";
|
||||
case D3DFMT_DXT3:
|
||||
return "D3DFMT_DXT3";
|
||||
case D3DFMT_DXT5:
|
||||
return "D3DFMT_DXT5";
|
||||
case D3DFMT_V8U8:
|
||||
return "D3DFMT_V8U8";
|
||||
case D3DFMT_Q8W8V8U8:
|
||||
return "D3DFMT_Q8W8V8U8";
|
||||
case D3DFMT_D16:
|
||||
return "D3DFMT_D16";
|
||||
case D3DFMT_D24S8:
|
||||
return "D3DFMT_D24S8";
|
||||
case D3DFMT_D24FS8:
|
||||
return "D3DFMT_D24FS8";
|
||||
case D3DFMT_LIN_D24S8:
|
||||
return "D3DFMT_LIN_D24S8";
|
||||
case D3DFMT_A16B16G16R16:
|
||||
return "D3DFMT_A16B16G16R16";
|
||||
case D3DFMT_LIN_A16B16G16R16:
|
||||
return "D3DFMT_LIN_A16B16G16R16";
|
||||
}
|
||||
return "???";
|
||||
}
|
||||
#endif
|
||||
60
materialsystem/shaderapidx9/colorformatdx8.h
Normal file
60
materialsystem/shaderapidx9/colorformatdx8.h
Normal file
@@ -0,0 +1,60 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ====//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef COLORFORMATDX8_H
|
||||
#define COLORFORMATDX8_H
|
||||
|
||||
#include <pixelwriter.h>
|
||||
#include "togl/rendermechanism.h"
|
||||
|
||||
// FOURCC formats for ATI shadow depth textures
|
||||
#define ATIFMT_D16 ((D3DFORMAT)(MAKEFOURCC('D','F','1','6')))
|
||||
#define ATIFMT_D24S8 ((D3DFORMAT)(MAKEFOURCC('D','F','2','4')))
|
||||
|
||||
// FOURCC formats for ATI2N and ATI1N compressed textures (360 and DX10 parts also do these)
|
||||
#define ATIFMT_ATI2N ((D3DFORMAT) MAKEFOURCC('A', 'T', 'I', '2'))
|
||||
#define ATIFMT_ATI1N ((D3DFORMAT) MAKEFOURCC('A', 'T', 'I', '1'))
|
||||
|
||||
// FOURCC formats for nVidia shadow depth textures
|
||||
#define NVFMT_RAWZ ((D3DFORMAT)(MAKEFOURCC('R','A','W','Z')))
|
||||
#define NVFMT_INTZ ((D3DFORMAT)(MAKEFOURCC('I','N','T','Z')))
|
||||
|
||||
// FOURCC format for nVidia null texture format
|
||||
#define NVFMT_NULL ((D3DFORMAT)(MAKEFOURCC('N','U','L','L')))
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds the nearest supported frame buffer format
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageFormat FindNearestSupportedBackBufferFormat( unsigned int displayAdapter, D3DDEVTYPE deviceType,
|
||||
ImageFormat displayFormat, ImageFormat backBufferFormat, bool bIsWindowed );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Initializes the color format informat; call it every time display mode changes
|
||||
//-----------------------------------------------------------------------------
|
||||
void InitializeColorInformation( unsigned int displayAdapter, D3DDEVTYPE deviceType,
|
||||
ImageFormat displayFormat );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if compressed textures are supported
|
||||
//-----------------------------------------------------------------------------
|
||||
bool D3DSupportsCompressedTextures();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns closest supported format
|
||||
//-----------------------------------------------------------------------------
|
||||
D3DFORMAT FindNearestSupportedFormat( ImageFormat format, bool bIsVertexTexture, bool bIsRenderTarget, bool bFilterableRequired );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Finds the nearest supported depth buffer format
|
||||
//-----------------------------------------------------------------------------
|
||||
D3DFORMAT FindNearestSupportedDepthFormat( int nAdapter, ImageFormat displayFormat, ImageFormat renderTargetFormat, D3DFORMAT depthFormat );
|
||||
|
||||
const char *D3DFormatName( D3DFORMAT d3dFormat );
|
||||
|
||||
#endif // COLORFORMATDX8_H
|
||||
408
materialsystem/shaderapidx9/ctlfont.cpp
Normal file
408
materialsystem/shaderapidx9/ctlfont.cpp
Normal file
@@ -0,0 +1,408 @@
|
||||
// Copyright Electonic Arts(C) 2006 - All Rights Reserved
|
||||
|
||||
#include "filesystem.h"
|
||||
|
||||
#include "CTLFont.h"
|
||||
|
||||
#include "t2k.h"
|
||||
#include "tlfont/fusionrasterizer.h"
|
||||
#include <FontAux/AllocatorAdapters.h>
|
||||
#include "MemMgr/inc/MemMgr.h"
|
||||
|
||||
// CTLFontManager and CTLFont act as a wrapper for Font Fusion. It uses the TLFont
|
||||
// wrapper for rasterizing with Font Fusion. We ignore all the other systems provided
|
||||
// by TLFont (caching, drawlists, rendering, etc).
|
||||
|
||||
// MARLETT:
|
||||
// Marlett causes some problems with Font Fusion. It renders the glyphs correctly,
|
||||
// but can return incorrect metric information. In particular, the descent is always
|
||||
// 0 and ascent is the height of the glyph; the maximum height calculated from
|
||||
// the ascent and descent does not always indicate the highest glyph - it is possible
|
||||
// to render a glyph heigher than (ascent+descent).
|
||||
//
|
||||
// For some reason, you need to offset any marlett character codes by 0xf000 otherwise
|
||||
// Font Fusion will just render invalid glyphs.
|
||||
|
||||
using namespace TLFont;
|
||||
|
||||
//#define DISABLE_FONT
|
||||
|
||||
CTLFontManager::CTLFontManager(IFileSystem *pFileSystem)
|
||||
{
|
||||
#ifndef DISABLE_FONT
|
||||
// The allocator that uses MemMgr
|
||||
static MemMgr_ICoreAllocator_Adapter memMgrAdapter;
|
||||
SetAllocator(&memMgrAdapter);
|
||||
|
||||
FontFusionMemObject::SetAllocatorCallbacks(FontFusionAlloc, FontFusionFree, 0);
|
||||
|
||||
// Load the filesystem
|
||||
m_pFileSystem = pFileSystem;
|
||||
ASSERT(m_pFileSystem);
|
||||
|
||||
// Reset the font data cache
|
||||
for (int i = 0; i < MAX_FONTDATACACHE; ++i)
|
||||
{
|
||||
memset(m_fontDataCache[i].m_dataName, 0, 256);
|
||||
m_fontDataCache[i].m_dataMem = NULL;
|
||||
m_fontDataCache[i].m_dataSize = 0;
|
||||
m_fontDataCache[i].m_refCount = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
CTLFontManager::~CTLFontManager()
|
||||
{
|
||||
// Clean the cache
|
||||
for (int i = 0; i < MAX_FONTDATACACHE; ++i)
|
||||
{
|
||||
if ( m_fontDataCache[i].m_dataMem )
|
||||
{
|
||||
//delete m_fontDataCache[i].m_dataMem;//Now allocated permanently
|
||||
m_fontDataCache[i].m_dataMem = NULL;
|
||||
m_fontDataCache[i].m_refCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char* CTLFontManager::LoadFontFile(const char *pFontPath, unsigned int *pDataSize)
|
||||
{
|
||||
#if 1
|
||||
Assert(!"<Sergiy> - temporarily disabling this");
|
||||
return NULL;
|
||||
#else
|
||||
#ifndef DISABLE_FONT
|
||||
unsigned char *pData = NULL;
|
||||
unsigned int dataSize = 0;
|
||||
|
||||
MEM_ALLOC_CREDIT_("CTLFontManager::LoadFontFile");
|
||||
|
||||
// Load a new font file
|
||||
FileHandle_t hFont = m_pFileSystem->Open(pFontPath, "rb");
|
||||
|
||||
if(hFont == NULL)
|
||||
{
|
||||
ASSERT(hFont);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dataSize = m_pFileSystem->Size(hFont);
|
||||
if(dataSize == 0)
|
||||
{
|
||||
// error getting the file size
|
||||
ASSERT(dataSize > 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//pData = new unsigned char[dataSize];
|
||||
pData= ( unsigned char * )gMemMgr.PermanentAlloc(dataSize);// This is an alloc thats never freed (gives us some flexibility to reuse scraps of memory)
|
||||
ASSERT(pData);
|
||||
//printf("LoadFontFile(%s) allocating %d",pFontPath,dataSize);
|
||||
|
||||
int ret = m_pFileSystem->Read(pData, dataSize, hFont);
|
||||
|
||||
if(pDataSize)
|
||||
{
|
||||
*pDataSize = dataSize;
|
||||
}
|
||||
|
||||
m_pFileSystem->Close(hFont);
|
||||
|
||||
return pData;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
CTLFont *CTLFontManager::CreateFont(const char *pName, const char *pFontPath, int tall, int weight)
|
||||
{
|
||||
#ifndef DISABLE_FONT
|
||||
unsigned int dataSize = 0;
|
||||
unsigned char *pData = NULL;
|
||||
|
||||
// Check the cache if we have already loaded this font
|
||||
for (int i = 0; i < MAX_FONTDATACACHE; ++i)
|
||||
{
|
||||
if ( m_fontDataCache[i].m_dataMem )
|
||||
{
|
||||
if ( strncmp(pName, m_fontDataCache[i].m_dataName, strlen(pName)) == 0 )
|
||||
{
|
||||
//printf("CTLFontManager::CreateFont(%s) - found in cache\n",pName);
|
||||
pData = m_fontDataCache[i].m_dataMem;
|
||||
dataSize = m_fontDataCache[i].m_dataSize;
|
||||
m_fontDataCache[i].m_refCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Load the TTF font from disk
|
||||
//printf("CTLFontManager::CreateFont(%s) - loading from disk\n",pName);
|
||||
m_fontDataCache[i].m_dataMem = LoadFontFile(pFontPath, &m_fontDataCache[i].m_dataSize);
|
||||
pData = m_fontDataCache[i].m_dataMem;
|
||||
dataSize = m_fontDataCache[i].m_dataSize;
|
||||
Q_strncpy(m_fontDataCache[i].m_dataName, pName, strlen(pName)+1);
|
||||
m_fontDataCache[i].m_refCount=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(pData == NULL || dataSize == 0)
|
||||
{
|
||||
Assert(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Simply allocate a new font and return it. One could, potentially, have a more complex way
|
||||
// of handling the fonts memory management.
|
||||
CTLFont *pFont = new CTLFont(pName, pData, dataSize, tall, weight);
|
||||
ASSERT(pFont);
|
||||
|
||||
return pFont;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void CTLFontManager::DestroyFont(CTLFont *pFont)
|
||||
{
|
||||
#ifndef DISABLE_FONT
|
||||
size_t size;
|
||||
void* pData;
|
||||
pData=pFont->GetData(&size);
|
||||
//printf("CTLFontManager::DestroyFont(%s)\n",pFont->GetName());
|
||||
|
||||
//Delete CTLFont
|
||||
delete pFont;
|
||||
|
||||
//Update refcount in m_fontDataCache
|
||||
for (int i = 0; i < MAX_FONTDATACACHE; ++i)
|
||||
{
|
||||
if (pData==m_fontDataCache[i].m_dataMem)
|
||||
{
|
||||
m_fontDataCache[i].m_refCount--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
CTLFont::CTLFont(const char *pName, unsigned char *pData, unsigned int dataSize, int tall, int weight)
|
||||
{
|
||||
// Font name
|
||||
int len = strlen(pName);
|
||||
if(len >= MAX_NAME)
|
||||
{
|
||||
memcpy(m_name, pName, (MAX_NAME-2));
|
||||
m_name[MAX_NAME-1] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// include the null terminator
|
||||
memcpy(m_name, pName, len+1);
|
||||
}
|
||||
|
||||
// Dimensions
|
||||
//note: Point and Logical Size values should be the same, unless you start scaling things.
|
||||
m_tall = tall;
|
||||
m_weight = weight;
|
||||
// empirically derived factor to achieve desired cell height
|
||||
m_pointSize = m_tall * 0.82f;
|
||||
|
||||
// Load the TTF file into memory
|
||||
m_pData = pData;
|
||||
m_dataSize = dataSize;
|
||||
ASSERT(m_pData);
|
||||
ASSERT(m_dataSize > 0);
|
||||
|
||||
// The rasterizer
|
||||
#ifndef DISABLE_FONT
|
||||
m_pRasterizer = new FusionRasterizer(m_pData,
|
||||
m_dataSize,
|
||||
FONTFILE_TTF,
|
||||
NULL,
|
||||
0.0f,
|
||||
1.0f,
|
||||
72, 72,
|
||||
0, // padding must be zero
|
||||
m_weight);
|
||||
ASSERT(m_pRasterizer);
|
||||
#endif
|
||||
|
||||
// Gross marlett hack!
|
||||
m_charOffset = 0;
|
||||
if(stricmp(m_name, "Marlett") == 0)
|
||||
{
|
||||
m_charOffset = 0xf000;
|
||||
}
|
||||
}
|
||||
|
||||
CTLFont::~CTLFont()
|
||||
{
|
||||
delete m_pRasterizer;
|
||||
}
|
||||
|
||||
void CTLFont::RenderToBuffer(int ch, int offsetx, int width, int height, unsigned char *pBuffer)
|
||||
{
|
||||
#ifndef DISABLE_FONT
|
||||
IRasterizer::RasterizationResult res;
|
||||
FixedAngle angle(0.0f);
|
||||
GlyphImage *pImage = m_pRasterizer->Rasterize(ch+m_charOffset, 1.0f, m_pointSize, angle, res);
|
||||
|
||||
// Return if we try and render a character we don't understand. This can include white spaces
|
||||
// and other special control characters.
|
||||
if(pImage == NULL ||
|
||||
pImage->GetFormat() == GlyphImage::GLYPHIMAGE_INVALID ||
|
||||
res == IRasterizer::RASTERIZE_FAILURE)
|
||||
{
|
||||
memset(pBuffer, 0x00, (width*height*4));
|
||||
return;
|
||||
}
|
||||
|
||||
// Image dimensions
|
||||
unsigned int imageWidth, imageHeight;
|
||||
pImage->GetGlyphDimensions(imageWidth, imageHeight);
|
||||
|
||||
// Marlett can be slightly bigger than the maximum height calculated by adding
|
||||
// the ascent and descent values together.
|
||||
if(imageHeight > height)
|
||||
{
|
||||
imageHeight = height;
|
||||
}
|
||||
|
||||
// The offset from the baseline..
|
||||
int xOffset, yOffset;
|
||||
pImage->GetGlyphOffset(xOffset, yOffset);
|
||||
|
||||
// Determine the baseline of the image (using the ascent and descent values)
|
||||
int ascent = (int)ceil(m_pRasterizer->GetAscent(m_pointSize));
|
||||
int descent = (int)ceil(m_pRasterizer->GetDescent(m_pointSize));
|
||||
int maxHeight = (descent + ascent);
|
||||
|
||||
int baseOffset = maxHeight - (descent + yOffset);
|
||||
if(baseOffset < 0)
|
||||
{
|
||||
// Marlett can produce a negative offset, which is BAD, so we correct this.
|
||||
baseOffset = 0;
|
||||
}
|
||||
|
||||
ASSERT((imageHeight+baseOffset) <= height);
|
||||
|
||||
// We only support copying of an alpha-only image
|
||||
ASSERT(pImage->GetFormat() == GlyphImage::GLYPHIMAGE_A8);
|
||||
|
||||
if(pImage->GetFormat() == GlyphImage::GLYPHIMAGE_A8)
|
||||
{
|
||||
// The rasterized image is stored as single bytes; we need to copy
|
||||
// this into a 32-bit image.
|
||||
for(int h = 0; h < imageHeight; h++)
|
||||
{
|
||||
unsigned char *pSrc = (unsigned char *)pImage->GetBitmap() + h*imageWidth;
|
||||
unsigned int *pDst = (unsigned int *)pBuffer + ( (baseOffset+h) * width );
|
||||
|
||||
for(int w = 0; w < imageWidth; w++)
|
||||
{
|
||||
unsigned char val = pSrc[w];
|
||||
|
||||
pDst[w + offsetx] = (0xff << 24) | (0xff << 16) | (0xff << 8) | val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete pImage;
|
||||
#endif
|
||||
}
|
||||
|
||||
// This is a slow function. You should use it with care; possibly implement a basic
|
||||
// caching system to prevent it being called all the time.
|
||||
bool CTLFont::GetCharABCWidth(int ch, int &a, int &b, int &c)
|
||||
{
|
||||
#ifndef DISABLE_FONT
|
||||
IRasterizer::RasterizationResult res;
|
||||
FixedAngle angle(0.0f);
|
||||
GlyphImage *pImage = m_pRasterizer->Rasterize(ch+m_charOffset, 1.0f, m_pointSize, angle, res);
|
||||
|
||||
// Return if we try and render a character we don't understand. This can include white spaces
|
||||
// and other special control characters.
|
||||
if(pImage == NULL ||
|
||||
res == IRasterizer::RASTERIZE_FAILURE)
|
||||
{
|
||||
a = 0;
|
||||
b = 0;
|
||||
c = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int width, height;
|
||||
pImage->GetGlyphDimensions(width, height);
|
||||
|
||||
int offsetX, offsetY;
|
||||
pImage->GetGlyphOffset(offsetX, offsetY);
|
||||
|
||||
int advance = pImage->GetGlyphAdvance();
|
||||
|
||||
ASSERT((int)width >= 0);
|
||||
|
||||
// We simply provide the advance distance as the glyph width, because 'a' and 'c'
|
||||
// have some special meaning to the Source engine..
|
||||
b = width;
|
||||
a = offsetX;
|
||||
c = advance - ((int)width + offsetX);
|
||||
|
||||
// In case the advance value is smaller than the glyph width
|
||||
if(c < 0)
|
||||
{
|
||||
c = 0;
|
||||
}
|
||||
|
||||
delete pImage;
|
||||
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
int CTLFont::GetMaxHeight()
|
||||
{
|
||||
#ifndef DISABLE_FONT
|
||||
float ascent = m_pRasterizer->GetAscent(m_pointSize);
|
||||
float descent = m_pRasterizer->GetDescent(m_pointSize);
|
||||
|
||||
return (int)(ceil(ascent) + ceil(descent));
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int CTLFont::GetMaxWidth()
|
||||
{
|
||||
// Unimplemented
|
||||
//ASSERT(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CTLFont::GetAscent()
|
||||
{
|
||||
#ifndef DISABLE_FONT
|
||||
float ascent = m_pRasterizer->GetAscent(m_pointSize);
|
||||
|
||||
return (int)ceil(ascent);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void* CTLFont::GetData(size_t * pSizeOut)
|
||||
{
|
||||
if (pSizeOut) *pSizeOut=m_dataSize;
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
const char * CTLFont::GetName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
90
materialsystem/shaderapidx9/ctlfont.h
Normal file
90
materialsystem/shaderapidx9/ctlfont.h
Normal file
@@ -0,0 +1,90 @@
|
||||
// Copyright Electonic Arts(C) 2006 - All Rights Reserved
|
||||
|
||||
#ifndef TLFONT_H
|
||||
#define TLFONT_H
|
||||
|
||||
#include "../materialsystem/ifont.h"
|
||||
|
||||
// Forward declerations
|
||||
class IFileSystem;
|
||||
class CTLFont;
|
||||
namespace TLFont
|
||||
{
|
||||
class FusionRasterizer;
|
||||
}
|
||||
namespace TLFontAux
|
||||
{
|
||||
class FontAuxTexture;
|
||||
}
|
||||
|
||||
// Cache TTF font file
|
||||
#define MAX_FONTDATACACHE 20
|
||||
|
||||
struct sFontDataCache
|
||||
{
|
||||
char m_dataName[256];
|
||||
unsigned char * m_dataMem;
|
||||
unsigned int m_dataSize;
|
||||
int m_refCount;
|
||||
};
|
||||
|
||||
// Font manager
|
||||
class CTLFontManager
|
||||
{
|
||||
public:
|
||||
|
||||
CTLFontManager(IFileSystem *pFileSystem);
|
||||
~CTLFontManager();
|
||||
|
||||
CTLFont* CreateFont(const char *pName, const char *pFontPath, int tall, int weight);
|
||||
void DestroyFont(CTLFont *pFont);
|
||||
|
||||
private:
|
||||
|
||||
unsigned char* LoadFontFile(const char *pFontPath, unsigned int *pDataSize);
|
||||
|
||||
IFileSystem *m_pFileSystem;
|
||||
|
||||
sFontDataCache m_fontDataCache[MAX_FONTDATACACHE];
|
||||
};
|
||||
|
||||
// Font instance
|
||||
class CTLFont : public IFont
|
||||
{
|
||||
public:
|
||||
|
||||
CTLFont(const char *pName, unsigned char *pData, unsigned int dataSize, int tall, int weight);
|
||||
~CTLFont();
|
||||
|
||||
virtual void RenderToBuffer(int ch, int offsetx, int width, int height, unsigned char *pBuffer);
|
||||
virtual bool GetCharABCWidth(int ch, int &a, int &b, int &c);
|
||||
virtual int GetMaxHeight();
|
||||
virtual int GetMaxWidth();
|
||||
virtual int GetAscent();
|
||||
virtual void* GetData(size_t * pSizeOut=NULL);
|
||||
virtual const char * GetName();
|
||||
|
||||
private:
|
||||
|
||||
// Convert a logical size to a point size
|
||||
static float LSToPoint(float ls);
|
||||
|
||||
static const int MAX_NAME = 128;
|
||||
char m_name[MAX_NAME];
|
||||
|
||||
int m_tall;
|
||||
int m_weight;
|
||||
float m_pointSize;
|
||||
|
||||
// TLFont variables
|
||||
TLFont::FusionRasterizer *m_pRasterizer;
|
||||
|
||||
// The TTF file
|
||||
unsigned char *m_pData;
|
||||
unsigned int m_dataSize;
|
||||
|
||||
// Required for our Marlett hack
|
||||
wchar_t m_charOffset;
|
||||
};
|
||||
|
||||
#endif
|
||||
778
materialsystem/shaderapidx9/cvballoctracker.cpp
Normal file
778
materialsystem/shaderapidx9/cvballoctracker.cpp
Normal file
@@ -0,0 +1,778 @@
|
||||
//===== Copyright 1996-2007, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose: tracks VB allocations (and compressed/uncompressed vertex memory usage)
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "materialsystem/imaterial.h"
|
||||
#include "imeshdx8.h"
|
||||
#include "convar.h"
|
||||
#include "tier1/utlhash.h"
|
||||
#include "tier1/utlstack.h"
|
||||
|
||||
#include "materialsystem/ivballoctracker.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Types
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
// FIXME: combine this into the lower bits of VertexFormat_t
|
||||
typedef uint64 VertexElementMap_t;
|
||||
|
||||
enum Saving_t
|
||||
{
|
||||
SAVING_COMPRESSION = 0,
|
||||
SAVING_REMOVAL = 1,
|
||||
SAVING_ALIGNMENT = 2
|
||||
};
|
||||
|
||||
struct ElementData
|
||||
{
|
||||
VertexElement_t element;
|
||||
int uncompressed; // uncompressed vertex size
|
||||
int currentCompressed; // current compressed vertex element size
|
||||
int idealCompressed; // ideal future compressed vertex element size
|
||||
const char *name;
|
||||
};
|
||||
|
||||
class CounterData
|
||||
{
|
||||
public:
|
||||
CounterData() : m_memCount( 0 ), m_vertCount( 0 ), m_paddingCount( 0 )
|
||||
{
|
||||
for ( int i = 0; i < VERTEX_ELEMENT_NUMELEMENTS; i++ )
|
||||
{
|
||||
m_elementsCompressed[ i ] = 0;
|
||||
m_elementsUncompressed[ i ] = 0;
|
||||
}
|
||||
m_AllocatorName[ 0 ] = 0;
|
||||
}
|
||||
|
||||
static const int MAX_NAME_SIZE = 128;
|
||||
int m_memCount;
|
||||
int m_vertCount;
|
||||
int m_paddingCount;
|
||||
int m_elementsCompressed[ VERTEX_ELEMENT_NUMELEMENTS ]; // Number of compressed verts using each element
|
||||
int m_elementsUncompressed[ VERTEX_ELEMENT_NUMELEMENTS ]; // Number of uncompressed verts using each element
|
||||
char m_AllocatorName[ MAX_NAME_SIZE ];
|
||||
};
|
||||
|
||||
class AllocData
|
||||
{
|
||||
public:
|
||||
AllocData( void * buffer, int bufferSize, VertexFormat_t fmt, int numVerts, int allocatorHash )
|
||||
: m_buffer( buffer ), m_bufferSize( bufferSize ), m_fmt( fmt ), m_numVerts( numVerts ), m_allocatorHash( allocatorHash ) {}
|
||||
AllocData() : m_buffer( NULL ), m_bufferSize( 0 ), m_fmt( 0 ), m_numVerts( 0 ), m_allocatorHash( 0 ) {}
|
||||
|
||||
VertexFormat_t m_fmt;
|
||||
void * m_buffer;
|
||||
int m_bufferSize;
|
||||
int m_numVerts;
|
||||
short m_allocatorHash;
|
||||
};
|
||||
|
||||
typedef CUtlHashFixed < CounterData, 64 > CCounterTable;
|
||||
typedef CUtlHashFixed < AllocData, 4096 > CAllocTable;
|
||||
typedef CUtlStack < short > CAllocNameHashes;
|
||||
|
||||
#endif // ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
|
||||
class CVBAllocTracker : public IVBAllocTracker
|
||||
{
|
||||
public:
|
||||
virtual void CountVB( void * buffer, bool isDynamic, int bufferSize, int vertexSize, VertexFormat_t fmt );
|
||||
virtual void UnCountVB( void * buffer );
|
||||
virtual bool TrackMeshAllocations( const char * allocatorName );
|
||||
|
||||
void DumpVBAllocs();
|
||||
|
||||
#if ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
public:
|
||||
CVBAllocTracker();
|
||||
|
||||
private:
|
||||
|
||||
UtlHashFixedHandle_t TrackAlloc( void * buffer, int bufferSize, VertexFormat_t fmt, int numVerts, short allocatorHash );
|
||||
bool KillAlloc( void * buffer, int & bufferSize, VertexFormat_t & fmt, int & numVerts, short & allocatorHash );
|
||||
|
||||
UtlHashFixedHandle_t GetCounterHandle( const char * allocatorName, short allocatorHash );
|
||||
|
||||
void SpewElements( const char * allocatorName, short nameHash );
|
||||
int ComputeVertexSize( VertexElementMap_t map, VertexFormat_t fmt, bool compressed );
|
||||
VertexElementMap_t ComputeElementMap( VertexFormat_t fmt, int vertexSize, bool isDynamic );
|
||||
void UpdateElements( CounterData & data, VertexFormat_t fmt, int numVerts, int vertexSize,
|
||||
bool isDynamic, bool isCompressed );
|
||||
|
||||
int ComputeAlignmentWastage( int bufferSize );
|
||||
void AddSaving( int & alreadySaved, int & yetToSave, const char *allocatorName, VertexElement_t element, Saving_t savingType );
|
||||
void SpewExpectedSavings( void );
|
||||
void UpdateData( const char * allocatorName, short allocatorKey, int bufferSize, VertexFormat_t fmt,
|
||||
int numVerts, int vertexSize, bool isDynamic, bool isCompressed );
|
||||
|
||||
const char * GetNameString( int allocatorKey );
|
||||
void SpewData( const char * allocatorName, short nameHash = 0 );
|
||||
void SpewDataSometimes( int inc );
|
||||
|
||||
|
||||
static const int SPEW_RATE = 64;
|
||||
static const int MAX_ALLOCATOR_NAME_SIZE = 128;
|
||||
char m_MeshAllocatorName[ MAX_ALLOCATOR_NAME_SIZE ];
|
||||
bool m_bSuperSpew;
|
||||
|
||||
CCounterTable m_VBCountTable;
|
||||
CAllocTable m_VBAllocTable;
|
||||
CAllocNameHashes m_VBTableNameHashes;
|
||||
|
||||
// We use a mutex since allocation tracking is accessed from multiple loading threads.
|
||||
// CThreadFastMutex is used as contention is expected to be low during loading.
|
||||
CThreadFastMutex m_VBAllocMutex;
|
||||
#endif // ENABLE_VB_ALLOC_TRACKER
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Global data
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
// FIXME: do this in a better way:
|
||||
static const ElementData positionElement = { VERTEX_ELEMENT_POSITION, 12, 12, 8, "POSITION " }; // (UNDONE: need vertex shader to scale, may cause cracking w/ static props)
|
||||
static const ElementData position4DElement = { VERTEX_ELEMENT_POSITION4D, 16, 16, 8, "POSITION4D " }; // Not really a position as used by SubD path
|
||||
static const ElementData normalElement = { VERTEX_ELEMENT_NORMAL, 12, 4, 4, "NORMAL " }; // (UNDONE: PC (2x16-byte Raphael method) or 360 (D3DDECLTYPE_HEND3N))
|
||||
static const ElementData normal4DElement = { VERTEX_ELEMENT_NORMAL4D, 16, 16, 8, "NORMAL4D " }; // Not really a normal as used by SubD path
|
||||
static const ElementData colorElement = { VERTEX_ELEMENT_COLOR, 4, 4, 4, "COLOR " }; // (already minimal)
|
||||
static const ElementData specularElement = { VERTEX_ELEMENT_SPECULAR, 4, 4, 4, "SPECULAR " }; // (already minimal)
|
||||
static const ElementData tangentSElement = { VERTEX_ELEMENT_TANGENT_S, 12, 12, 4, "TANGENT_S " }; // (all-but-unused)
|
||||
static const ElementData tangentTElement = { VERTEX_ELEMENT_TANGENT_T, 12, 12, 4, "TANGENT_T " }; // (all-but-unused)
|
||||
static const ElementData wrinkleElement = { VERTEX_ELEMENT_WRINKLE, 4, 4, 0, "WRINKLE " }; // (UNDONE: compress it as a SHORTN in Position.w - is it [0,1]?)
|
||||
static const ElementData boneIndexElement = { VERTEX_ELEMENT_BONEINDEX, 4, 4, 4, "BONEINDEX " }; // (already minimal)
|
||||
static const ElementData boneWeight1Element = { VERTEX_ELEMENT_BONEWEIGHTS1, 4, 4, 4, "BONEWEIGHT1 " }; // (unused)
|
||||
static const ElementData boneWeight2Element = { VERTEX_ELEMENT_BONEWEIGHTS2, 8, 8, 4, "BONEWEIGHT2 " }; // (UNDONE: take care w.r.t cracking in flex regions)
|
||||
static const ElementData boneWeight3Element = { VERTEX_ELEMENT_BONEWEIGHTS3, 12, 12, 8, "BONEWEIGHT3 " }; // (unused)
|
||||
static const ElementData boneWeight4Element = { VERTEX_ELEMENT_BONEWEIGHTS4, 16, 16, 8, "BONEWEIGHT4 " }; // (unused)
|
||||
static const ElementData userData1Element = { VERTEX_ELEMENT_USERDATA1, 4, 4, 4, "USERDATA1 " }; // (unused)
|
||||
static const ElementData userData2Element = { VERTEX_ELEMENT_USERDATA2, 8, 8, 4, "USERDATA2 " }; // (unused)
|
||||
static const ElementData userData3Element = { VERTEX_ELEMENT_USERDATA3, 12, 12, 4, "USERDATA3 " }; // (unused)
|
||||
#if ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 )
|
||||
static const ElementData userData4Element = { VERTEX_ELEMENT_USERDATA4, 16, 4, 4, "USERDATA4 " }; // (UNDONE: PC (2x16-byte Raphael method) or 360 (D3DDECLTYPE_HEND3N))
|
||||
#else // ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 )
|
||||
static const ElementData userData4Element = { VERTEX_ELEMENT_USERDATA4, 16, 0, 0, "USERDATA4 " }; // (UNDONE: PC (2x16-byte Raphael method) or 360 (D3DDECLTYPE_HEND3N))
|
||||
#endif
|
||||
static const ElementData texCoord1D0Element = { VERTEX_ELEMENT_TEXCOORD1D_0, 4, 4, 4, "TEXCOORD1D_0" }; // (not worth compressing)
|
||||
static const ElementData texCoord1D1Element = { VERTEX_ELEMENT_TEXCOORD1D_1, 4, 4, 4, "TEXCOORD1D_1" }; // (not worth compressing)
|
||||
static const ElementData texCoord1D2Element = { VERTEX_ELEMENT_TEXCOORD1D_2, 4, 4, 4, "TEXCOORD1D_2" }; // (not worth compressing)
|
||||
static const ElementData texCoord1D3Element = { VERTEX_ELEMENT_TEXCOORD1D_3, 4, 4, 4, "TEXCOORD1D_3" }; // (not worth compressing)
|
||||
static const ElementData texCoord1D4Element = { VERTEX_ELEMENT_TEXCOORD1D_4, 4, 4, 4, "TEXCOORD1D_4" }; // (not worth compressing)
|
||||
static const ElementData texCoord1D5Element = { VERTEX_ELEMENT_TEXCOORD1D_5, 4, 4, 4, "TEXCOORD1D_5" }; // (not worth compressing)
|
||||
static const ElementData texCoord1D6Element = { VERTEX_ELEMENT_TEXCOORD1D_6, 4, 4, 4, "TEXCOORD1D_6" }; // (not worth compressing)
|
||||
static const ElementData texCoord1D7Element = { VERTEX_ELEMENT_TEXCOORD1D_7, 4, 4, 4, "TEXCOORD1D_7" }; // (not worth compressing)
|
||||
static const ElementData texCoord2D0Element = { VERTEX_ELEMENT_TEXCOORD2D_0, 8, 8, 4, "TEXCOORD2D_0" }; // (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord2D1Element = { VERTEX_ELEMENT_TEXCOORD2D_1, 8, 8, 4, "TEXCOORD2D_1" }; // (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord2D2Element = { VERTEX_ELEMENT_TEXCOORD2D_2, 8, 8, 4, "TEXCOORD2D_2" }; // (all-but-unused)
|
||||
static const ElementData texCoord2D3Element = { VERTEX_ELEMENT_TEXCOORD2D_3, 8, 8, 4, "TEXCOORD2D_3" }; // (unused)
|
||||
static const ElementData texCoord2D4Element = { VERTEX_ELEMENT_TEXCOORD2D_4, 8, 8, 4, "TEXCOORD2D_4" }; // (unused)
|
||||
static const ElementData texCoord2D5Element = { VERTEX_ELEMENT_TEXCOORD2D_5, 8, 8, 4, "TEXCOORD2D_5" }; // (unused)
|
||||
static const ElementData texCoord2D6Element = { VERTEX_ELEMENT_TEXCOORD2D_6, 8, 8, 4, "TEXCOORD2D_6" }; // (unused)
|
||||
static const ElementData texCoord2D7Element = { VERTEX_ELEMENT_TEXCOORD2D_7, 8, 8, 4, "TEXCOORD2D_7" }; // (unused)
|
||||
static const ElementData texCoord3D0Element = { VERTEX_ELEMENT_TEXCOORD3D_0, 12, 12, 8, "TEXCOORD3D_0" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord3D1Element = { VERTEX_ELEMENT_TEXCOORD3D_1, 12, 12, 8, "TEXCOORD3D_1" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord3D2Element = { VERTEX_ELEMENT_TEXCOORD3D_2, 12, 12, 8, "TEXCOORD3D_2" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord3D3Element = { VERTEX_ELEMENT_TEXCOORD3D_3, 12, 12, 8, "TEXCOORD3D_3" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord3D4Element = { VERTEX_ELEMENT_TEXCOORD3D_4, 12, 12, 8, "TEXCOORD3D_4" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord3D5Element = { VERTEX_ELEMENT_TEXCOORD3D_5, 12, 12, 8, "TEXCOORD3D_5" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord3D6Element = { VERTEX_ELEMENT_TEXCOORD3D_6, 12, 12, 8, "TEXCOORD3D_6" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord3D7Element = { VERTEX_ELEMENT_TEXCOORD3D_7, 12, 12, 8, "TEXCOORD3D_7" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D0Element = { VERTEX_ELEMENT_TEXCOORD4D_0, 16, 16, 8, "TEXCOORD4D_0" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D1Element = { VERTEX_ELEMENT_TEXCOORD4D_1, 16, 16, 8, "TEXCOORD4D_1" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D2Element = { VERTEX_ELEMENT_TEXCOORD4D_2, 16, 16, 8, "TEXCOORD4D_2" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D3Element = { VERTEX_ELEMENT_TEXCOORD4D_3, 16, 16, 8, "TEXCOORD4D_3" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D4Element = { VERTEX_ELEMENT_TEXCOORD4D_4, 16, 16, 8, "TEXCOORD4D_4" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D5Element = { VERTEX_ELEMENT_TEXCOORD4D_5, 16, 16, 8, "TEXCOORD4D_5" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D6Element = { VERTEX_ELEMENT_TEXCOORD4D_6, 16, 16, 8, "TEXCOORD4D_6" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData texCoord4D7Element = { VERTEX_ELEMENT_TEXCOORD4D_7, 16, 16, 8, "TEXCOORD4D_7" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping)
|
||||
static const ElementData elementTable[] = { positionElement,
|
||||
position4DElement,
|
||||
normalElement,
|
||||
normal4DElement,
|
||||
colorElement,
|
||||
specularElement,
|
||||
tangentSElement,
|
||||
tangentTElement,
|
||||
wrinkleElement,
|
||||
boneIndexElement,
|
||||
boneWeight1Element, boneWeight2Element, boneWeight3Element, boneWeight4Element,
|
||||
userData1Element, userData2Element, userData3Element, userData4Element,
|
||||
texCoord1D0Element, texCoord1D1Element, texCoord1D2Element, texCoord1D3Element, texCoord1D4Element, texCoord1D5Element, texCoord1D6Element, texCoord1D7Element,
|
||||
texCoord2D0Element, texCoord2D1Element, texCoord2D2Element, texCoord2D3Element, texCoord2D4Element, texCoord2D5Element, texCoord2D6Element, texCoord2D7Element,
|
||||
texCoord3D0Element, texCoord3D1Element, texCoord3D2Element, texCoord3D3Element, texCoord3D4Element, texCoord3D5Element, texCoord3D6Element, texCoord3D7Element,
|
||||
texCoord4D0Element, texCoord4D1Element, texCoord4D2Element, texCoord4D3Element, texCoord4D4Element, texCoord4D5Element, texCoord4D6Element, texCoord4D7Element,
|
||||
};
|
||||
|
||||
static ConVar mem_vballocspew( "mem_vballocspew", "0", FCVAR_CHEAT, "How often to spew vertex buffer allocation stats - 1: every alloc, 2+: every 2+ allocs, 0: off" );
|
||||
|
||||
#endif // ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton instance exposed to the engine
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static CVBAllocTracker s_VBAllocTracker;
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CVBAllocTracker, IVBAllocTracker,
|
||||
VB_ALLOC_TRACKER_INTERFACE_VERSION, s_VBAllocTracker );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VB alloc-tracking code starts here
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
|
||||
CVBAllocTracker::CVBAllocTracker()
|
||||
{
|
||||
COMPILE_TIME_ASSERT( VERTEX_ELEMENT_NUMELEMENTS == ARRAYSIZE( elementTable ) );
|
||||
m_bSuperSpew = false;
|
||||
m_MeshAllocatorName[0] = 0;
|
||||
}
|
||||
|
||||
UtlHashFixedHandle_t CVBAllocTracker::TrackAlloc( void * buffer, int bufferSize, VertexFormat_t fmt, int numVerts, short allocatorHash )
|
||||
{
|
||||
AllocData newData( buffer, bufferSize, fmt, numVerts, allocatorHash );
|
||||
UtlHashFixedHandle_t handle = m_VBAllocTable.Insert( (intp)buffer, newData );
|
||||
if ( handle == m_VBAllocTable.InvalidHandle() )
|
||||
{
|
||||
Warning( "[VBMEM] VBMemAllocTable hash collision (grow table).\n" );
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
bool CVBAllocTracker::KillAlloc( void * buffer, int & bufferSize, VertexFormat_t & fmt, int & numVerts, short & allocatorHash )
|
||||
{
|
||||
UtlHashFixedHandle_t handle = m_VBAllocTable.Find( (intp)buffer );
|
||||
if ( handle != m_VBAllocTable.InvalidHandle() )
|
||||
{
|
||||
AllocData & data = m_VBAllocTable.Element( handle );
|
||||
bufferSize = data.m_bufferSize;
|
||||
fmt = data.m_fmt;
|
||||
numVerts = data.m_numVerts;
|
||||
allocatorHash = data.m_allocatorHash;
|
||||
m_VBAllocTable.Remove( handle );
|
||||
return true;
|
||||
}
|
||||
Warning( "[VBMEM] VBMemAllocTable failed to find alloc entry...\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
UtlHashFixedHandle_t CVBAllocTracker::GetCounterHandle( const char * allocatorName, short allocatorHash )
|
||||
{
|
||||
UtlHashFixedHandle_t handle = m_VBCountTable.Find( allocatorHash );
|
||||
if ( handle == m_VBCountTable.InvalidHandle() )
|
||||
{
|
||||
CounterData newData;
|
||||
Assert( ( allocatorName != NULL ) && ( allocatorName[0] != 0 ) );
|
||||
V_strncpy( newData.m_AllocatorName, allocatorName, CounterData::MAX_NAME_SIZE );
|
||||
handle = m_VBCountTable.Insert( allocatorHash, newData );
|
||||
m_VBTableNameHashes.Push( allocatorHash );
|
||||
}
|
||||
if ( handle == m_VBCountTable.InvalidHandle() )
|
||||
{
|
||||
Warning( "[VBMEM] CounterData hash collision (grow table).\n" );
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
void CheckForElementTableUpdates( const ElementData & element )
|
||||
{
|
||||
// Ensure that 'elementTable' gets updated if VertexElement_t ever changes:
|
||||
int tableIndex = &element - &( elementTable[0] );
|
||||
Assert( tableIndex == element.element );
|
||||
if ( tableIndex != element.element )
|
||||
{
|
||||
static int timesToSpew = 20;
|
||||
if ( timesToSpew > 0 )
|
||||
{
|
||||
Warning( "VertexElement_t structure has changed, ElementData table in cvballoctracker needs updating!\n" );
|
||||
timesToSpew--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CVBAllocTracker::SpewElements( const char * allocatorName, short nameHash )
|
||||
{
|
||||
short allocatorHash = allocatorName ? HashString( allocatorName ) : nameHash;
|
||||
UtlHashFixedHandle_t handle = GetCounterHandle( allocatorName, allocatorHash );
|
||||
if ( handle != m_VBCountTable.InvalidHandle() )
|
||||
{
|
||||
CounterData & data = m_VBCountTable.Element( handle );
|
||||
int originalSum = 0, currentSum = 0, idealSum = 0;
|
||||
for (int i = 0;i < VERTEX_ELEMENT_NUMELEMENTS;i++)
|
||||
{
|
||||
CheckForElementTableUpdates( elementTable[ i ] );
|
||||
int numCompressed = data.m_elementsCompressed[ i ];
|
||||
int numUncompressed = data.m_elementsUncompressed[ i ];
|
||||
int numVerts = numCompressed + numUncompressed;
|
||||
originalSum += numVerts*elementTable[ i ].uncompressed;
|
||||
currentSum += numCompressed*elementTable[ i ].currentCompressed + numUncompressed*elementTable[ i ].uncompressed;
|
||||
idealSum += numVerts*elementTable[ i ].idealCompressed;
|
||||
}
|
||||
|
||||
if ( originalSum > 0 )
|
||||
{
|
||||
Msg( "[VBMEM] ----elements (%s)----:\n", data.m_AllocatorName);
|
||||
for (int i = 0;i < VERTEX_ELEMENT_NUMELEMENTS;i++)
|
||||
{
|
||||
// We count vertices (converted to bytes via elementTable)
|
||||
int numCompressed = data.m_elementsCompressed[ i ];
|
||||
int numUncompressed = data.m_elementsUncompressed[ i ];
|
||||
int numVerts = numCompressed + numUncompressed;
|
||||
const ElementData & elementData = elementTable[ i ];
|
||||
if ( numVerts > 0 )
|
||||
{
|
||||
Msg( " element: %5.2f MB 'U', %5.2f MB 'C', %5.2f MB 'I', %6.2f MB 'D', %s\n",
|
||||
numVerts*elementData.uncompressed / ( 1024.0f*1024.0f ),
|
||||
( numCompressed*elementData.currentCompressed + numUncompressed*elementData.uncompressed ) / ( 1024.0f*1024.0f ),
|
||||
numVerts*elementData.idealCompressed / ( 1024.0f*1024.0f ),
|
||||
-( numCompressed*elementData.currentCompressed + numUncompressed*elementData.uncompressed - numVerts*elementData.idealCompressed ) / ( 1024.0f*1024.0f ),
|
||||
elementData.name );
|
||||
}
|
||||
}
|
||||
Msg( "[VBMEM] total: %5.2f MB 'U', %5.2f MB 'C', %5.2f MB 'I', %6.2f MB 'D'\n",
|
||||
originalSum / ( 1024.0f*1024.0f ),
|
||||
currentSum / ( 1024.0f*1024.0f ),
|
||||
idealSum / ( 1024.0f*1024.0f ),
|
||||
-( currentSum - idealSum ) / ( 1024.0f*1024.0f ) );
|
||||
Msg( "[VBMEM] ----elements (%s)----:\n", data.m_AllocatorName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CVBAllocTracker::ComputeVertexSize( VertexElementMap_t map, VertexFormat_t fmt, bool compressed )
|
||||
{
|
||||
int vertexSize = 0;
|
||||
for ( int i = 0;i < VERTEX_ELEMENT_NUMELEMENTS;i++ )
|
||||
{
|
||||
const ElementData & element = elementTable[ i ];
|
||||
CheckForElementTableUpdates( element );
|
||||
VertexElementMap_t LSB = 1;
|
||||
if ( map & ( LSB << i ) )
|
||||
{
|
||||
vertexSize += compressed ? element.currentCompressed : element.uncompressed;
|
||||
}
|
||||
}
|
||||
|
||||
// On PC (see CVertexBufferBase::ComputeVertexDescription() in meshbase.cpp)
|
||||
// vertex strides are aligned to 16 bytes:
|
||||
bool bCacheAlign = ( fmt & VERTEX_FORMAT_USE_EXACT_FORMAT ) == 0;
|
||||
if ( bCacheAlign && ( vertexSize > 16 ) && IsPC() )
|
||||
{
|
||||
vertexSize = (vertexSize + 0xF) & (~0xF);
|
||||
}
|
||||
|
||||
return vertexSize;
|
||||
}
|
||||
|
||||
VertexElementMap_t CVBAllocTracker::ComputeElementMap( VertexFormat_t fmt, int vertexSize, bool isDynamic )
|
||||
{
|
||||
VertexElementMap_t map = 0, LSB = 1;
|
||||
if ( fmt & VERTEX_POSITION ) map |= LSB << VERTEX_ELEMENT_POSITION;
|
||||
if ( fmt & VERTEX_NORMAL ) map |= LSB << VERTEX_ELEMENT_NORMAL;
|
||||
if ( fmt & VERTEX_COLOR ) map |= LSB << VERTEX_ELEMENT_COLOR;
|
||||
if ( fmt & VERTEX_SPECULAR ) map |= LSB << VERTEX_ELEMENT_SPECULAR;
|
||||
if ( fmt & VERTEX_TANGENT_S ) map |= LSB << VERTEX_ELEMENT_TANGENT_S;
|
||||
if ( fmt & VERTEX_TANGENT_T ) map |= LSB << VERTEX_ELEMENT_TANGENT_T;
|
||||
if ( fmt & VERTEX_WRINKLE ) map |= LSB << VERTEX_ELEMENT_WRINKLE;
|
||||
if ( fmt & VERTEX_BONE_INDEX) map |= LSB << VERTEX_ELEMENT_BONEINDEX;
|
||||
int numBones = NumBoneWeights( fmt );
|
||||
if ( numBones > 0 ) map |= LSB << ( VERTEX_ELEMENT_BONEWEIGHTS1 + numBones - 1 );
|
||||
int userDataSize = UserDataSize( fmt );
|
||||
if ( userDataSize > 0 ) map |= LSB << ( VERTEX_ELEMENT_USERDATA1 + userDataSize - 1 );
|
||||
for ( int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i )
|
||||
{
|
||||
VertexElement_t texCoordElements[4] = { VERTEX_ELEMENT_TEXCOORD1D_0, VERTEX_ELEMENT_TEXCOORD2D_0, VERTEX_ELEMENT_TEXCOORD3D_0, VERTEX_ELEMENT_TEXCOORD4D_0 };
|
||||
int nCoordSize = TexCoordSize( i, fmt );
|
||||
if ( nCoordSize > 0 )
|
||||
{
|
||||
Assert( nCoordSize <= 4 );
|
||||
if ( nCoordSize <= 4 )
|
||||
{
|
||||
map |= LSB << ( texCoordElements[ nCoordSize - 1 ] + i );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( map == 0 )
|
||||
{
|
||||
if ( !isDynamic )
|
||||
{
|
||||
// We expect all (non-dynamic) VB allocs to specify a vertex format
|
||||
// Warning("[VBMEM] unknown vertex format\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( vertexSize != 0 )
|
||||
{
|
||||
// Make sure elementTable above matches external computations of vertex size
|
||||
// FIXME: make this assert dependent on whether the current VB is compressed or not
|
||||
VertexCompressionType_t compressionType = CompressionType( fmt );
|
||||
bool isCompressedAlloc = ( compressionType == VERTEX_COMPRESSION_ON );
|
||||
// FIXME: once we've finalised which elements we're compressing for ship, update
|
||||
// elementTable to reflect that and re-enable this assert for compressed verts
|
||||
if ( !isCompressedAlloc )
|
||||
{
|
||||
Assert( vertexSize == ComputeVertexSize( map, fmt, isCompressedAlloc ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
void CVBAllocTracker::UpdateElements( CounterData & data, VertexFormat_t fmt, int numVerts, int vertexSize,
|
||||
bool isDynamic, bool isCompressed )
|
||||
{
|
||||
VertexElementMap_t map = ComputeElementMap( fmt, vertexSize, isDynamic );
|
||||
if ( map != 0 )
|
||||
{
|
||||
for (int i = 0;i < VERTEX_ELEMENT_NUMELEMENTS;i++)
|
||||
{
|
||||
// Count vertices (get bytes from our elements table)
|
||||
VertexElementMap_t LSB = 1;
|
||||
if ( map & ( LSB << i ) )
|
||||
{
|
||||
if ( isCompressed )
|
||||
data.m_elementsCompressed[ i ] += numVerts;
|
||||
else
|
||||
data.m_elementsUncompressed[ i ] += numVerts;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CVBAllocTracker::ComputeAlignmentWastage( int bufferSize )
|
||||
{
|
||||
if ( !IsX360() )
|
||||
return 0;
|
||||
|
||||
// VBs are 4KB-aligned on 360, so we waste thiiiiiis much:
|
||||
return ( ( 4096 - (bufferSize & 4095)) & 4095 );
|
||||
}
|
||||
|
||||
void CVBAllocTracker::AddSaving( int & alreadySaved, int & yetToSave, const char *allocatorName, VertexElement_t element, Saving_t savingType )
|
||||
{
|
||||
UtlHashFixedHandle_t handle = GetCounterHandle( allocatorName, HashString( allocatorName ) );
|
||||
if ( handle != m_VBCountTable.InvalidHandle() )
|
||||
{
|
||||
CheckForElementTableUpdates( elementTable[ element ] );
|
||||
CounterData & counterData = m_VBCountTable.Element( handle );
|
||||
const ElementData & elementData = elementTable[ element ];
|
||||
int numVerts = counterData.m_vertCount;
|
||||
int numCompressed = counterData.m_elementsCompressed[ element ];
|
||||
int numUncompressed = counterData.m_elementsUncompressed[ element ];
|
||||
switch( savingType )
|
||||
{
|
||||
case SAVING_COMPRESSION:
|
||||
alreadySaved += numCompressed*( elementData.uncompressed - elementData.currentCompressed );
|
||||
yetToSave += numUncompressed*( elementData.uncompressed - elementData.currentCompressed );
|
||||
break;
|
||||
case SAVING_REMOVAL:
|
||||
alreadySaved += elementData.uncompressed*( numVerts - ( numUncompressed + numCompressed ) );
|
||||
yetToSave += numUncompressed*elementData.uncompressed + numCompressed*elementData.uncompressed;
|
||||
break;
|
||||
case SAVING_ALIGNMENT:
|
||||
yetToSave += counterData.m_paddingCount;
|
||||
break;
|
||||
default:
|
||||
Assert(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CVBAllocTracker::SpewExpectedSavings( void )
|
||||
{
|
||||
int alreadySaved = 0, yetToSave = 0;
|
||||
|
||||
// We have removed bone weights+indices from static props
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_BONEWEIGHTS2, SAVING_REMOVAL );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_BONEINDEX, SAVING_REMOVAL );
|
||||
// We have removed vertex colors from all models (color should only ever be in stream1, for static vertex lighting)
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_COLOR, SAVING_REMOVAL );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_COLOR, SAVING_REMOVAL );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_COLOR, SAVING_REMOVAL );
|
||||
|
||||
// We expect to compress texcoords (DONE: normals+tangents, boneweights) for all studiomdls
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_NORMAL, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_NORMAL, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_NORMAL, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_USERDATA4, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_USERDATA4, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_USERDATA4, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_TEXCOORD2D_0, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_TEXCOORD2D_0, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_TEXCOORD2D_0, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_BONEWEIGHTS1, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_BONEWEIGHTS2, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_BONEWEIGHTS1, SAVING_COMPRESSION );
|
||||
AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_BONEWEIGHTS2, SAVING_COMPRESSION );
|
||||
|
||||
// UNDONE: compress bone weights for studiomdls? (issue: possible flex artifacts, but 2xSHORTN probably ok)
|
||||
// UNDONE: compress positions (+wrinkle) for studiomdls? (issue: possible flex artifacts)
|
||||
// UNDONE: disable tangents for non-bumped models (issue: forcedmaterialoverride support... don't think that needs tangents, though
|
||||
// however, if we use UBYTE4 normal+tangent encoding, removing tangents saves nothing)
|
||||
|
||||
if ( IsX360() )
|
||||
{
|
||||
// We expect to avoid 4-KB-alignment wastage for color meshes, by allocating them
|
||||
// out of a single, shared VB and adding per-mesh offsets in vertex shaders
|
||||
AddSaving( alreadySaved, yetToSave, "CColorMeshData::CreateResource", VERTEX_ELEMENT_USERDATA4, SAVING_ALIGNMENT );
|
||||
}
|
||||
|
||||
Msg("[VBMEM]\n");
|
||||
Msg("[VBMEM] Total expected memory saving by disabling/compressing vertex elements: %6.2f MB\n", yetToSave / ( 1024.0f*1024.0f ) );
|
||||
Msg("[VBMEM] ( total memory already saved: %6.2f MB)\n", alreadySaved / ( 1024.0f*1024.0f ) );
|
||||
Msg("[VBMEM] - compression of model texcoords, [DONE: normals+tangents, bone weights]\n" );
|
||||
Msg("[VBMEM] - avoidance of 4-KB alignment wastage for color meshes (on 360)\n" );
|
||||
Msg("[VBMEM] - [DONE: removal of unneeded bone weights+indices on models]\n" );
|
||||
Msg("[VBMEM]\n");
|
||||
}
|
||||
|
||||
void CVBAllocTracker::UpdateData( const char * allocatorName, short allocatorKey, int bufferSize, VertexFormat_t fmt,
|
||||
int numVerts, int vertexSize, bool isDynamic, bool isCompressed )
|
||||
{
|
||||
UtlHashFixedHandle_t handle = GetCounterHandle( allocatorName, allocatorKey );
|
||||
if ( handle != m_VBCountTable.InvalidHandle() )
|
||||
{
|
||||
CounterData & data = m_VBCountTable.Element( handle );
|
||||
data.m_memCount += bufferSize;
|
||||
Assert( data.m_memCount >= 0 );
|
||||
data.m_vertCount += numVerts;
|
||||
Assert( data.m_vertCount >= 0 );
|
||||
data.m_paddingCount += ( bufferSize < 0 ? -1 : +1 )*ComputeAlignmentWastage( abs( bufferSize ) );
|
||||
UpdateElements( data, fmt, numVerts, vertexSize, isDynamic, isCompressed );
|
||||
}
|
||||
}
|
||||
|
||||
const char * CVBAllocTracker::GetNameString( int allocatorKey )
|
||||
{
|
||||
UtlHashFixedHandle_t handle = GetCounterHandle( NULL, allocatorKey );
|
||||
if ( handle != m_VBCountTable.InvalidHandle() )
|
||||
{
|
||||
CounterData & data = m_VBCountTable.Element( handle );
|
||||
return data.m_AllocatorName;
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
|
||||
void CVBAllocTracker::SpewData( const char * allocatorName, short nameHash )
|
||||
{
|
||||
short allocatorHash = allocatorName ? HashString( allocatorName ) : nameHash;
|
||||
UtlHashFixedHandle_t handle = GetCounterHandle( allocatorName, allocatorHash );
|
||||
if ( handle != m_VBCountTable.InvalidHandle() )
|
||||
{
|
||||
CounterData & data = m_VBCountTable.Element( handle );
|
||||
if ( data.m_memCount > 0 )
|
||||
{
|
||||
Msg("[VBMEM] running mem usage: (%5.2f M-verts) %6.2f MB | '%s'\n",
|
||||
data.m_vertCount / ( 1024.0f*1024.0f ),
|
||||
data.m_memCount / ( 1024.0f*1024.0f ),
|
||||
data.m_AllocatorName );
|
||||
}
|
||||
if ( data.m_paddingCount > 0 )
|
||||
{
|
||||
Msg("[VBMEM] 4KB VB alignment wastage: %6.2f MB | '%s'\n",
|
||||
data.m_paddingCount / ( 1024.0f*1024.0f ),
|
||||
data.m_AllocatorName );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CVBAllocTracker::SpewDataSometimes( int inc )
|
||||
{
|
||||
static int count = 0;
|
||||
|
||||
if ( inc < 0 ) count += inc;
|
||||
Assert( count >= 0 );
|
||||
|
||||
int period = mem_vballocspew.GetInt();
|
||||
if ( period >= 1 )
|
||||
{
|
||||
if ( ( count % period ) == 0 )
|
||||
{
|
||||
Msg( "[VBMEM] Status after %d VB allocs:\n", count );
|
||||
//#define ROUND_UP( _x_ ) ( ( ( _x_ ) + 31 ) & 31 )
|
||||
//Msg( "[VBMEM] Conservative estimate of mem used to track allocs: %d\n", 4096*ROUND_UP( 4 + sizeof( CUtlPtrLinkedList<AllocData> ) ) + count*ROUND_UP( sizeof( AllocData ) + 8 ) );
|
||||
SpewData( "total_static" );
|
||||
SpewData( "unknown" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( inc > 0 ) count += inc;
|
||||
}
|
||||
|
||||
void CVBAllocTracker::DumpVBAllocs()
|
||||
{
|
||||
m_VBAllocMutex.Lock();
|
||||
|
||||
Msg("[VBMEM] ----running totals----\n" );
|
||||
for ( int i = ( m_VBTableNameHashes.Count() - 1 ); i >= 0; i-- )
|
||||
{
|
||||
short nameHash = m_VBTableNameHashes.Element( i );
|
||||
SpewElements( NULL, nameHash );
|
||||
}
|
||||
|
||||
Msg("[VBMEM]\n");
|
||||
Msg("[VBMEM] 'U' - original memory usage (all vertices uncompressed)\n" );
|
||||
Msg("[VBMEM] 'C' - current memory usage (some compression)\n" );
|
||||
Msg("[VBMEM] 'I' - ideal memory usage (all verts maximally compressed)\n" );
|
||||
Msg("[VBMEM] 'D' - difference between C and I (-> how much more compression could save)\n" );
|
||||
Msg("[VBMEM] 'W' - memory wasted due to 4-KB vertex buffer alignment\n" );
|
||||
Msg("[VBMEM]\n");
|
||||
for ( int i = ( m_VBTableNameHashes.Count() - 1 ); i >= 0; i-- )
|
||||
{
|
||||
short nameHash = m_VBTableNameHashes.Element( i );
|
||||
SpewData( NULL, nameHash );
|
||||
}
|
||||
SpewExpectedSavings();
|
||||
Msg("[VBMEM] ----running totals----\n" );
|
||||
|
||||
m_VBAllocMutex.Unlock();
|
||||
}
|
||||
|
||||
#endif // ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
void CVBAllocTracker::CountVB( void * buffer, bool isDynamic, int bufferSize, int vertexSize, VertexFormat_t fmt )
|
||||
{
|
||||
#if ENABLE_VB_ALLOC_TRACKER
|
||||
m_VBAllocMutex.Lock();
|
||||
|
||||
// Update VB memory counts for the relevant allocation type
|
||||
// (NOTE: we have 'unknown', 'dynamic' and 'total' counts)
|
||||
const char * allocatorName = ( m_MeshAllocatorName[0] == 0 ) ? "unknown" : m_MeshAllocatorName;
|
||||
if ( isDynamic ) allocatorName = "total_dynamic";
|
||||
int numVerts = ( vertexSize > 0 ) ? ( bufferSize / vertexSize ) : 0;
|
||||
short totalStaticKey = HashString( "total_static" );
|
||||
short key = HashString( allocatorName );
|
||||
bool isCompressed = ( VERTEX_COMPRESSION_NONE != CompressionType( fmt ) );
|
||||
|
||||
if ( m_MeshAllocatorName[0] == 0 )
|
||||
{
|
||||
Warning("[VBMEM] unknown allocation!\n");
|
||||
}
|
||||
|
||||
// Add to the VB memory counters
|
||||
TrackAlloc( buffer, bufferSize, fmt, numVerts, key );
|
||||
if ( !isDynamic )
|
||||
{
|
||||
// Keep dynamic allocs out of the total (dynamic VBs don't get compressed)
|
||||
UpdateData( "total_static", totalStaticKey, bufferSize, fmt, numVerts, vertexSize, isDynamic, isCompressed );
|
||||
}
|
||||
UpdateData( allocatorName, key, bufferSize, fmt, numVerts, vertexSize, isDynamic, isCompressed );
|
||||
|
||||
if ( m_bSuperSpew )
|
||||
{
|
||||
// Spew every alloc
|
||||
Msg( "[VBMEM] VB-alloc | %6.2f MB | %s | %s\n", bufferSize / ( 1024.0f*1024.0f ), ( isDynamic ? "DYNamic" : " STAtic" ), allocatorName );
|
||||
SpewData( allocatorName );
|
||||
}
|
||||
SpewDataSometimes( +1 );
|
||||
|
||||
m_VBAllocMutex.Unlock();
|
||||
#endif // ENABLE_VB_ALLOC_TRACKER
|
||||
}
|
||||
|
||||
void CVBAllocTracker::UnCountVB( void * buffer )
|
||||
{
|
||||
#if ENABLE_VB_ALLOC_TRACKER
|
||||
m_VBAllocMutex.Lock();
|
||||
|
||||
short totalKey = HashString( "total_static" );
|
||||
short dynamicKey = HashString( "total_dynamic" );
|
||||
int bufferSize;
|
||||
VertexFormat_t fmt;
|
||||
int numVerts;
|
||||
short key;
|
||||
|
||||
// We have to store allocation data because the caller often doesn't know what it alloc'd :o/
|
||||
if ( KillAlloc( buffer, bufferSize, fmt, numVerts, key ) )
|
||||
{
|
||||
bool isCompressed = ( VERTEX_COMPRESSION_NONE != CompressionType( fmt ) );
|
||||
bool isDynamic = ( key == dynamicKey );
|
||||
|
||||
// Subtract from the VB memory counters
|
||||
if ( !isDynamic )
|
||||
{
|
||||
UpdateData( NULL, totalKey, -bufferSize, fmt, -numVerts, 0, isDynamic, isCompressed );
|
||||
}
|
||||
UpdateData( NULL, key, -bufferSize, fmt, -numVerts, 0, isDynamic, isCompressed );
|
||||
|
||||
const char * nameString = GetNameString( key );
|
||||
|
||||
if ( m_bSuperSpew )
|
||||
{
|
||||
Msg( "[VBMEM] VB-free | %6.2f MB | %s | %s\n", bufferSize / ( 1024.0f*1024.0f ), ( isDynamic ? "DYNamic" : " STAtic" ), nameString );
|
||||
SpewData( nameString );
|
||||
}
|
||||
SpewDataSometimes( -1 );
|
||||
}
|
||||
|
||||
m_VBAllocMutex.Unlock();
|
||||
#endif // ENABLE_VB_ALLOC_TRACKER
|
||||
}
|
||||
|
||||
bool CVBAllocTracker::TrackMeshAllocations( const char * allocatorName )
|
||||
{
|
||||
#if ENABLE_VB_ALLOC_TRACKER
|
||||
// Tracks mesh allocations by name (set this before an alloc, clear it after)
|
||||
|
||||
if ( m_MeshAllocatorName[ 0 ] )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
m_VBAllocMutex.Lock();
|
||||
|
||||
if ( allocatorName )
|
||||
{
|
||||
V_strncpy( m_MeshAllocatorName, allocatorName, MAX_ALLOCATOR_NAME_SIZE );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_MeshAllocatorName[0] = 0;
|
||||
}
|
||||
|
||||
m_VBAllocMutex.Unlock();
|
||||
#endif // ENABLE_VB_ALLOC_TRACKER
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef RETAIL
|
||||
|
||||
static void CC_DumpVBMemAllocs()
|
||||
{
|
||||
#if ( ENABLE_VB_ALLOC_TRACKER == 0 )
|
||||
Warning( "ENABLE_VB_ALLOC_TRACKER must be 1 to enable VB mem alloc tracking\n");
|
||||
#else
|
||||
s_VBAllocTracker.DumpVBAllocs();
|
||||
#endif
|
||||
}
|
||||
|
||||
static ConCommand mem_dumpvballocs( "mem_dumpvballocs", CC_DumpVBMemAllocs, "Dump VB memory allocation stats.", FCVAR_CHEAT );
|
||||
|
||||
#endif // RETAIL
|
||||
943
materialsystem/shaderapidx9/d3d_async.cpp
Normal file
943
materialsystem/shaderapidx9/d3d_async.cpp
Normal file
@@ -0,0 +1,943 @@
|
||||
//======Copyright 1996-2006, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// methods for muti-core dx9 threading
|
||||
//===========================================================================//
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
#include "utlsymbol.h"
|
||||
#include "utlvector.h"
|
||||
#include "utldict.h"
|
||||
#include "utlbuffer.h"
|
||||
#include "UtlStringMap.h"
|
||||
#include "locald3dtypes.h"
|
||||
#include "shaderapidx8_global.h"
|
||||
#include "recording.h"
|
||||
#include "tier0/vprof.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "materialsystem/imaterialsystemhardwareconfig.h"
|
||||
#include "shaderapidx8.h"
|
||||
#include "materialsystem/IShader.h"
|
||||
#include "utllinkedlist.h"
|
||||
#include "materialsystem/ishadersystem.h"
|
||||
#include "tier0/fasttimer.h"
|
||||
#include <stdlib.h>
|
||||
#include "convar.h"
|
||||
#include "materialsystem/shader_vcs_version.h"
|
||||
#include "datacache/idatacache.h"
|
||||
#include "winutils.h"
|
||||
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
#if SHADERAPI_USE_SMP
|
||||
|
||||
// Set this to 1 to get vprof nodes for playing back the command stream. This is good for counting calls in a frame, etc.
|
||||
#define SHADERAPI_VPROF_BUFFER_PLAYBACK 1
|
||||
|
||||
#if SHADERAPI_VPROF_BUFFER_PLAYBACK && SHADERAPI_BUFFER_D3DCALLS
|
||||
#define VPROF_BUFFER_PLAYBACK(name) VPROF(name)
|
||||
#else
|
||||
#define VPROF_BUFFER_PLAYBACK(name) ((void)0)
|
||||
#endif
|
||||
|
||||
template<class T, int QSIZE> class FixedWorkQueue
|
||||
{
|
||||
T Data[QSIZE];
|
||||
char pad0[256];
|
||||
volatile int n_added;
|
||||
int write_index;
|
||||
char pad1[256]; // make sure these don't share cache lines
|
||||
volatile int n_removed;
|
||||
int read_index;
|
||||
|
||||
public:
|
||||
FixedWorkQueue(void)
|
||||
{
|
||||
read_index=write_index=0;
|
||||
n_added=n_removed=0;
|
||||
}
|
||||
|
||||
int IsEmpty(void)
|
||||
{
|
||||
return (n_added==n_removed);
|
||||
}
|
||||
|
||||
int IsFull(void)
|
||||
{
|
||||
return (n_added-n_removed)>=QSIZE;
|
||||
}
|
||||
|
||||
T GetWorkUnit(void)
|
||||
{
|
||||
if (IsEmpty())
|
||||
return 0;
|
||||
return Data[read_index];
|
||||
}
|
||||
|
||||
void MarkUnitDone(void)
|
||||
{
|
||||
n_removed++;
|
||||
read_index=(read_index+1) % QSIZE;
|
||||
}
|
||||
|
||||
void AddWorkUnit(T unit)
|
||||
{
|
||||
#if SHADERAPI_BUFFER_D3DCALLS
|
||||
Assert( !IsFull() );
|
||||
#else
|
||||
while (IsFull())
|
||||
Sleep(0);
|
||||
#endif
|
||||
Data[write_index]=unit;
|
||||
n_added++;
|
||||
write_index=(write_index+1) % QSIZE;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#if SHADERAPI_BUFFER_D3DCALLS
|
||||
#define N_PUSH_BUFFERS 5000
|
||||
#else
|
||||
#define N_PUSH_BUFFERS 500
|
||||
#endif
|
||||
static volatile PushBuffer *PushBuffers[N_PUSH_BUFFERS];
|
||||
FixedWorkQueue<PushBuffer *, N_PUSH_BUFFERS> PBQueue;
|
||||
|
||||
|
||||
|
||||
uintp OurThreadInit( void * ourthis )
|
||||
{
|
||||
(( D3DDeviceWrapper *) ourthis )->RunThread();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::RunThread( void )
|
||||
{
|
||||
SetThreadAffinityMask(GetCurrentThread(), 2);
|
||||
for(;;)
|
||||
{
|
||||
PushBuffer *Pbuf=PBQueue.GetWorkUnit();
|
||||
if (! Pbuf)
|
||||
{
|
||||
; //Sleep(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ExecutePushBuffer( Pbuf );
|
||||
PBQueue.MarkUnitDone();
|
||||
Pbuf->m_State = PUSHBUFFER_AVAILABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if SHADERAPI_BUFFER_D3DCALLS
|
||||
void D3DDeviceWrapper::ExecuteAllWork( void )
|
||||
{
|
||||
if( !m_bBufferingD3DCalls )
|
||||
return;
|
||||
VPROF_BUDGET( "ExecuteAllWork", "ExecuteAllWork" );
|
||||
SubmitPushBufferAndGetANewOne();
|
||||
PushBuffer *Pbuf;
|
||||
while( ( Pbuf = PBQueue.GetWorkUnit() ) != NULL )
|
||||
{
|
||||
ExecutePushBuffer( Pbuf );
|
||||
PBQueue.MarkUnitDone();
|
||||
Pbuf->m_State = PUSHBUFFER_AVAILABLE;
|
||||
}
|
||||
m_bBufferingD3DCalls = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SHADERAPI_BUFFER_D3DCALLS
|
||||
#define MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE 1600
|
||||
#else
|
||||
#define MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE 16
|
||||
#endif
|
||||
|
||||
struct RememberedPointer
|
||||
{
|
||||
void *m_pKey;
|
||||
void *m_pRememberedPtr;
|
||||
} RememberedPointerHistory[MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE];
|
||||
|
||||
void D3DDeviceWrapper::SetASyncMode( bool onoff )
|
||||
{
|
||||
#if SHADERAPI_BUFFER_D3DCALLS
|
||||
if ( onoff )
|
||||
{
|
||||
m_bBufferingD3DCalls = true;
|
||||
// allocate push buffers if we need to
|
||||
if ( PushBuffers[0] == NULL )
|
||||
{
|
||||
for(int i=0; i<N_PUSH_BUFFERS; i++)
|
||||
PushBuffers[i]=new PushBuffer;
|
||||
}
|
||||
// create thread and init communications
|
||||
memset( RememberedPointerHistory,0,sizeof(RememberedPointerHistory) );
|
||||
}
|
||||
#else
|
||||
if ( onoff )
|
||||
{
|
||||
if (! m_pASyncThreadHandle )
|
||||
{
|
||||
// allocate push buffers if we need to
|
||||
if ( PushBuffers[0] == NULL )
|
||||
{
|
||||
for(int i=0; i<N_PUSH_BUFFERS; i++)
|
||||
PushBuffers[i]=new PushBuffer;
|
||||
}
|
||||
// create thread and init communications
|
||||
memset( RememberedPointerHistory,0,sizeof(RememberedPointerHistory) );
|
||||
SetThreadAffinityMask(GetCurrentThread(), 1);
|
||||
#ifdef WIN32
|
||||
m_pASyncThreadHandle = CreateSimpleThread( OurThreadInit, this, 128*1024 );
|
||||
#else
|
||||
#warning "D3DDeviceWrapper::SetASyncMode might need a beginthread version"
|
||||
Assert( !"Impl D3DDeviceWrapper::SetASyncMode" );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Synchronize();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
PushBuffer *D3DDeviceWrapper::FindFreePushBuffer( PushBufferState newstate )
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::FindFreePushBuffer" );
|
||||
for(;;)
|
||||
{
|
||||
for(int i=0;i<N_PUSH_BUFFERS;i++)
|
||||
{
|
||||
if (PushBuffers[i]->m_State == PUSHBUFFER_AVAILABLE )
|
||||
{
|
||||
PushBuffers[i]->m_State = newstate;
|
||||
return (PushBuffer *) PushBuffers[i];
|
||||
}
|
||||
}
|
||||
// hmm, out of push buffers. better sleep and try again later
|
||||
SubmitPushBufferAndGetANewOne();
|
||||
Sleep(0);
|
||||
}
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::GetPushBuffer( void )
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::GetPushBuffer" );
|
||||
m_pCurPushBuffer = FindFreePushBuffer( PUSHBUFFER_BEING_FILLED );
|
||||
m_pOutputPtr = m_pCurPushBuffer->m_BufferData;
|
||||
m_PushBufferFreeSlots = PUSHBUFFER_NELEMS - 1; // leave room for end marker
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::SubmitPushBufferAndGetANewOne( void )
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::SubmitPushBufferAndGetANewOne" );
|
||||
|
||||
// submit the current push buffer
|
||||
if ( m_pCurPushBuffer )
|
||||
{
|
||||
if (m_pOutputPtr == m_pCurPushBuffer->m_BufferData) // haven't done anyting, don't bother
|
||||
return;
|
||||
*(m_pOutputPtr) = PBCMD_END; // mark end
|
||||
m_pCurPushBuffer->m_State = PUSHBUFFER_SUBMITTED;
|
||||
// here, enqueue for task
|
||||
PBQueue.AddWorkUnit( m_pCurPushBuffer );
|
||||
}
|
||||
GetPushBuffer();
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::SubmitIfNotBusy( void )
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::SubmitIfNotBusy" );
|
||||
if ( PBQueue.IsEmpty() )
|
||||
SubmitPushBufferAndGetANewOne();
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::UpdateStereoTexture( IDirect3DTexture9 *pTex, bool devLost, bool *pStereoActiveThisFrame )
|
||||
{
|
||||
#if ( IS_WINDOWS_PC ) && !NO_STEREO_D3D9
|
||||
Assert( m_pStereoTexUpdater );
|
||||
if ( m_pStereoTexUpdater )
|
||||
{
|
||||
if ( pStereoActiveThisFrame != NULL )
|
||||
{
|
||||
*pStereoActiveThisFrame = m_pStereoTexUpdater->IsStereoActive();
|
||||
}
|
||||
|
||||
// We always want to call this so it can deal with a lost device
|
||||
m_pStereoTexUpdater->UpdateStereoTexture( Dx9Device(), pTex, devLost );
|
||||
}
|
||||
#else
|
||||
if ( pStereoActiveThisFrame != NULL )
|
||||
{
|
||||
*pStereoActiveThisFrame = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::Synchronize( void )
|
||||
{
|
||||
#if SHADERAPI_BUFFER_D3DCALLS
|
||||
if( m_bBufferingD3DCalls )
|
||||
{
|
||||
Assert( 0 );
|
||||
Error( "Synchronize not supported with SHADERAPI_BUFFER_D3DCALLS" );
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
if ( ASyncMode())
|
||||
{
|
||||
SubmitPushBufferAndGetANewOne();
|
||||
// here, wait for queue to become empty
|
||||
while (! PBQueue.IsEmpty() )
|
||||
{
|
||||
// Sleep(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::AsynchronousLock( IDirect3DIndexBuffer9* ib,
|
||||
size_t offset, size_t size, void **ptr,
|
||||
DWORD flags,
|
||||
LockedBufferContext *lb)
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::AsynchronousLock index" );
|
||||
|
||||
if ( size <= sizeof( PushBuffers[0]->m_BufferData ))
|
||||
{
|
||||
// can use one of our pushbuffers for this
|
||||
lb->m_pPushBuffer = FindFreePushBuffer( PUSHBUFFER_BEING_USED_FOR_LOCKEDDATA );
|
||||
*(ptr) = lb->m_pPushBuffer->m_BufferData;
|
||||
Assert( *ptr );
|
||||
lb->m_pMallocedMemory = NULL;
|
||||
}
|
||||
else // out of buffer space or size too big
|
||||
{
|
||||
lb->m_pPushBuffer = NULL;
|
||||
lb->m_pMallocedMemory = new uint8 [ size ];
|
||||
*(ptr) = lb->m_pMallocedMemory;
|
||||
}
|
||||
// now, push lock commands
|
||||
AllocatePushBufferSpace( 1+N_DWORDS_IN_PTR+3 );
|
||||
*(m_pOutputPtr++)=PBCMD_ASYNC_LOCK_IB;
|
||||
*((LPDIRECT3DINDEXBUFFER *) m_pOutputPtr)=ib;
|
||||
m_pOutputPtr+=N_DWORDS_IN_PTR;
|
||||
*(m_pOutputPtr++)=offset;
|
||||
*(m_pOutputPtr++)=size;
|
||||
*(m_pOutputPtr++)=flags;
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::AsynchronousLock( IDirect3DVertexBuffer9* vb,
|
||||
size_t offset, size_t size, void **ptr,
|
||||
DWORD flags,
|
||||
LockedBufferContext *lb)
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::AsynchronousLock vertex" );
|
||||
// we have commands in flight. Need to use temporary memory for this lock.
|
||||
// if the size needed is < the amount of space in a push buffer, we can use
|
||||
// a push buffer for the buffer. Otherwise, we're going to malloc one.
|
||||
if ( size <= sizeof( PushBuffers[0]->m_BufferData ))
|
||||
{
|
||||
// can use one of our pushbuffers for this
|
||||
lb->m_pPushBuffer = FindFreePushBuffer( PUSHBUFFER_BEING_USED_FOR_LOCKEDDATA );
|
||||
*(ptr) = lb->m_pPushBuffer->m_BufferData;
|
||||
Assert( *ptr );
|
||||
lb->m_pMallocedMemory = NULL;
|
||||
}
|
||||
else // out of buffer space or size too big
|
||||
{
|
||||
lb->m_pPushBuffer = NULL;
|
||||
lb->m_pMallocedMemory = new uint8 [ size ];
|
||||
*(ptr) = lb->m_pMallocedMemory;
|
||||
}
|
||||
// now, push lock commands
|
||||
AllocatePushBufferSpace( 1+N_DWORDS_IN_PTR+3 );
|
||||
*(m_pOutputPtr++)=PBCMD_ASYNC_LOCK_VB;
|
||||
*((LPDIRECT3DVERTEXBUFFER *) m_pOutputPtr)=vb;
|
||||
m_pOutputPtr+=N_DWORDS_IN_PTR;
|
||||
*(m_pOutputPtr++)=offset;
|
||||
*(m_pOutputPtr++)=size;
|
||||
*(m_pOutputPtr++)=flags;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline void RememberLockedPointer( void *key, void *value )
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "RememberLockedPointer" );
|
||||
int repl=-1;
|
||||
int i;
|
||||
for(i=0;i<MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE;i++)
|
||||
{
|
||||
if ( RememberedPointerHistory[i].m_pKey==key )
|
||||
break;
|
||||
if ( (repl == -1 ) && (RememberedPointerHistory[i].m_pRememberedPtr == 0 ) )
|
||||
repl=i;
|
||||
}
|
||||
if (i != MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE )
|
||||
{
|
||||
RememberedPointerHistory[i].m_pRememberedPtr = value;
|
||||
if ( value==NULL )
|
||||
RememberedPointerHistory[i].m_pKey = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (repl == -1 )
|
||||
{
|
||||
Assert( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
RememberedPointerHistory[repl].m_pKey = key;
|
||||
RememberedPointerHistory[repl].m_pRememberedPtr = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void *RecallLockedPointer( void *key )
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "RecallLockedPointer" );
|
||||
|
||||
for(int i=0;i<MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE;i++)
|
||||
if ( RememberedPointerHistory[i].m_pKey == key )
|
||||
return RememberedPointerHistory[i].m_pRememberedPtr;
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::HandleAsynchronousLockVBCommand( uint32 const *dptr )
|
||||
{
|
||||
dptr++;
|
||||
LPDIRECT3DVERTEXBUFFER vb=*((LPDIRECT3DVERTEXBUFFER *) dptr);
|
||||
dptr+=N_DWORDS_IN_PTR;
|
||||
uint32 offset=*(dptr++);
|
||||
uint32 size=*(dptr++);
|
||||
uint32 flags=*(dptr++);
|
||||
void *locked_ptr=0;
|
||||
vb->Lock( offset, size, &locked_ptr, flags );
|
||||
RememberLockedPointer( vb, locked_ptr );
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::HandleAsynchronousUnLockVBCommand( uint32 const *dptr )
|
||||
{
|
||||
dptr++;
|
||||
LPDIRECT3DVERTEXBUFFER vb=*((LPDIRECT3DVERTEXBUFFER *) dptr);
|
||||
dptr+=N_DWORDS_IN_PTR;
|
||||
LockedBufferContext lb=*((LockedBufferContext *) dptr);
|
||||
dptr+=N_DWORDS( LockedBufferContext );
|
||||
size_t unlock_size=*( dptr++ );
|
||||
void *locked_data=RecallLockedPointer( vb );
|
||||
Assert( locked_data );
|
||||
if (lb.m_pPushBuffer)
|
||||
{
|
||||
Assert( ! lb.m_pMallocedMemory );
|
||||
if ( locked_data )
|
||||
memcpy( locked_data, lb.m_pPushBuffer->m_BufferData, unlock_size );
|
||||
lb.m_pPushBuffer->m_State = PUSHBUFFER_AVAILABLE;
|
||||
}
|
||||
else if ( lb.m_pMallocedMemory )
|
||||
{
|
||||
Assert( ! lb.m_pPushBuffer );
|
||||
if ( locked_data )
|
||||
memcpy( locked_data, lb.m_pMallocedMemory, unlock_size );
|
||||
delete[] lb.m_pMallocedMemory;
|
||||
}
|
||||
// now, actually unlock
|
||||
RememberLockedPointer( vb, NULL );
|
||||
vb->Unlock();
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::HandleAsynchronousLockIBCommand( uint32 const *dptr )
|
||||
{
|
||||
dptr++;
|
||||
LPDIRECT3DINDEXBUFFER ib=*((LPDIRECT3DINDEXBUFFER *) dptr);
|
||||
Assert( ib );
|
||||
dptr+=N_DWORDS_IN_PTR;
|
||||
uint32 offset=*(dptr++);
|
||||
uint32 size=*(dptr++);
|
||||
uint32 flags=*(dptr++);
|
||||
void *locked_ptr=0;
|
||||
ib->Lock( offset, size, &locked_ptr, flags );
|
||||
RememberLockedPointer( ib, locked_ptr );
|
||||
}
|
||||
|
||||
void D3DDeviceWrapper::HandleAsynchronousUnLockIBCommand( uint32 const *dptr )
|
||||
{
|
||||
dptr++;
|
||||
LPDIRECT3DINDEXBUFFER ib=*((LPDIRECT3DINDEXBUFFER *) dptr);
|
||||
dptr+=N_DWORDS_IN_PTR;
|
||||
LockedBufferContext lb=*((LockedBufferContext *) dptr);
|
||||
dptr+=N_DWORDS( LockedBufferContext );
|
||||
size_t unlock_size=*( dptr++ );
|
||||
void *locked_data=RecallLockedPointer( ib );
|
||||
Assert( locked_data );
|
||||
if (lb.m_pPushBuffer)
|
||||
{
|
||||
Assert( ! lb.m_pMallocedMemory );
|
||||
if ( locked_data )
|
||||
memcpy( locked_data, lb.m_pPushBuffer->m_BufferData, unlock_size );
|
||||
lb.m_pPushBuffer->m_State = PUSHBUFFER_AVAILABLE;
|
||||
}
|
||||
else if ( lb.m_pMallocedMemory )
|
||||
{
|
||||
Assert( ! lb.m_pPushBuffer );
|
||||
if ( locked_data )
|
||||
memcpy( locked_data, lb.m_pMallocedMemory, unlock_size );
|
||||
delete[] lb.m_pMallocedMemory;
|
||||
}
|
||||
// now, actually unlock
|
||||
RememberLockedPointer( ib, NULL );
|
||||
ib->Unlock();
|
||||
|
||||
}
|
||||
|
||||
|
||||
static inline void *FetchPtr( uint32 const *mem)
|
||||
{
|
||||
void **p=(void **) mem;
|
||||
return *p;
|
||||
}
|
||||
|
||||
#define CALC_STATS 1
|
||||
#if CALC_STATS
|
||||
int n_commands_executed=0;
|
||||
int n_pbs_executed=0;
|
||||
#endif
|
||||
|
||||
void D3DDeviceWrapper::ExecutePushBuffer( PushBuffer const* pb)
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::ExecutePushBuffer" );
|
||||
uint32 const *dptr=pb->m_BufferData;
|
||||
n_pbs_executed++;
|
||||
for(;;)
|
||||
{
|
||||
n_commands_executed++;
|
||||
switch( dptr[0] )
|
||||
{
|
||||
case PBCMD_END:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "END" );
|
||||
n_commands_executed--; // doesn't count
|
||||
return;
|
||||
}
|
||||
|
||||
case PBCMD_SET_RENDERSTATE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_RENDERSTATE" );
|
||||
Dx9Device()->SetRenderState((D3DRENDERSTATETYPE) dptr[1],dptr[2]);
|
||||
dptr+=3;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_SAMPLER_STATE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_SAMPLER_STATE" );
|
||||
Dx9Device()->SetSamplerState(dptr[1], (D3DSAMPLERSTATETYPE) dptr[2], dptr[3]);
|
||||
dptr+=4;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef DX_TO_GL_ABSTRACTION
|
||||
case PBCMD_SET_RENDERSTATEINLINE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_RENDERSTATEINLINE" );
|
||||
Dx9Device()->SetRenderStateInline( (D3DRENDERSTATETYPE)dptr[1], dptr[2] );
|
||||
dptr += 3;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_SAMPLER_STATES:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_SAMPLER_STATES" );
|
||||
Dx9Device()->SetSamplerStates( dptr[1], dptr[2], dptr[3], dptr[4], dptr[5], dptr[6], dptr[7] );
|
||||
dptr += 8;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
case PBCMD_DRAWPRIM:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "DRAWPRIM" );
|
||||
Dx9Device()->DrawPrimitive( (D3DPRIMITIVETYPE) dptr[1], dptr[2], dptr[3] );
|
||||
dptr+=4;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef DX_TO_GL_ABSTRACTION
|
||||
case PBCMD_DRAWPRIMUP_RESZ:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "DRAWPRIMUP_RESZ" );
|
||||
|
||||
struct sPoints
|
||||
{
|
||||
FLOAT pos[3];
|
||||
};
|
||||
sPoints verts[1];
|
||||
|
||||
verts[0].pos[0] = 0.0f;
|
||||
verts[0].pos[1] = 0.0f;
|
||||
verts[0].pos[2] = 0.0f;
|
||||
|
||||
Dx9Device()->DrawPrimitiveUP( D3DPT_POINTLIST, 1, verts, sizeof( sPoints ) );
|
||||
dptr++;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
case PBCMD_DRAWINDEXEDPRIM:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "DRAWINDEXEDPRIM" );
|
||||
Dx9Device()->DrawIndexedPrimitive( (D3DPRIMITIVETYPE) dptr[1], dptr[2], dptr[3],
|
||||
dptr[4], dptr[5], dptr[6]);
|
||||
dptr+=7;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_STREAM_SOURCE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_STREAM_SOURCE" );
|
||||
Dx9Device()->SetStreamSource( dptr[1],(IDirect3DVertexBuffer9 *) FetchPtr(dptr+2),
|
||||
dptr[3],dptr[4] );
|
||||
dptr += 4+N_DWORDS( IDirect3DVertexBuffer9 * );
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_TEXTURE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_TEXTURE" );
|
||||
Dx9Device()->SetTexture( dptr[1],(IDirect3DBaseTexture *) FetchPtr(dptr+2));
|
||||
dptr += 2+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_RENDER_TARGET:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_RENDER_TARGET" );
|
||||
Dx9Device()->SetRenderTarget( dptr[1],(IDirect3DSurface *) FetchPtr(dptr+2));
|
||||
dptr += 2+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_PIXEL_SHADER:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_PIXEL_SHADER" );
|
||||
Dx9Device()->SetPixelShader( (IDirect3DPixelShader9 *) FetchPtr(dptr+1));
|
||||
dptr += 1+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_INDICES:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_INDICES" );
|
||||
Dx9Device()->SetIndices( (IDirect3DIndexBuffer9*) FetchPtr(dptr+1));
|
||||
dptr += 1+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_DEPTH_STENCIL_SURFACE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_DEPTH_STENCIL_SURFACE" );
|
||||
Dx9Device()->SetDepthStencilSurface( (IDirect3DSurface9*) FetchPtr(dptr+1));
|
||||
dptr += 1+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SETVIEWPORT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SETVIEWPORT" );
|
||||
Dx9Device()->SetViewport( (D3DVIEWPORT9 const *) (dptr+1) );
|
||||
dptr += 1+N_DWORDS(D3DVIEWPORT9);
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_VERTEX_SHADER:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_VERTEX_SHADER" );
|
||||
Dx9Device()->SetVertexShader( (IDirect3DVertexShader9 *) FetchPtr(dptr+1));
|
||||
dptr += 1+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_ASYNC_LOCK_VB:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "ASYNC_LOCK_VB" );
|
||||
HandleAsynchronousLockVBCommand(dptr);
|
||||
dptr+=1+N_DWORDS_IN_PTR+3;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_ASYNC_UNLOCK_VB:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "ASYNC_UNLOCK_VB" );
|
||||
HandleAsynchronousUnLockVBCommand( dptr );
|
||||
dptr+=1+N_DWORDS_IN_PTR+N_DWORDS( LockedBufferContext )+1;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_ASYNC_LOCK_IB:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "ASYNC_LOCK_IB" );
|
||||
HandleAsynchronousLockIBCommand(dptr);
|
||||
dptr+=1+N_DWORDS_IN_PTR+3;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_ASYNC_UNLOCK_IB:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "ASYNC_UNLOCK_IB" );
|
||||
HandleAsynchronousUnLockIBCommand( dptr );
|
||||
dptr+=1+N_DWORDS_IN_PTR+N_DWORDS( LockedBufferContext )+1;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_UNLOCK_VB:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "UNLOCK_VB" );
|
||||
IDirect3DVertexBuffer9 *p=(IDirect3DVertexBuffer9 *) FetchPtr(dptr+1);
|
||||
p->Unlock();
|
||||
dptr += 1+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
case PBCMD_UNLOCK_IB:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "UNLOCK_IB" );
|
||||
IDirect3DIndexBuffer9 *p=(IDirect3DIndexBuffer9 *) FetchPtr(dptr+1);
|
||||
p->Unlock();
|
||||
dptr += 1+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef DX_TO_GL_ABSTRACTION
|
||||
case PBCMD_UNLOCK_ACTAULSIZE_VB:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "UNLOCK_ACTUALSIZE_VB" );
|
||||
IDirect3DVertexBuffer9 *p = (IDirect3DVertexBuffer9 *)FetchPtr( dptr + 1 );
|
||||
p->UnlockActualSize( dptr[2] );
|
||||
dptr += 1 + N_DWORDS_IN_PTR + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_UNLOCK_ACTAULSIZE_IB:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "UNLOCK_ACTUALSIZE_IB" );
|
||||
IDirect3DIndexBuffer9 *p = (IDirect3DIndexBuffer9 *)FetchPtr( dptr + 1 );
|
||||
p->UnlockActualSize( dptr[2] );
|
||||
dptr += 1 + N_DWORDS_IN_PTR + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_MAX_USED_VERTEX_SHADER_CONSTANTS_HINT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_MAX_USED_VERTEX_SHADER_CONSTANTS_HINT" );
|
||||
Dx9Device()->SetMaxUsedVertexShaderConstantsHint( dptr[1] );
|
||||
dptr += 2;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
case PBCMD_SET_VERTEX_SHADER_CONSTANT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_VERTEX_SHADER_CONSTANT" );
|
||||
Dx9Device()->SetVertexShaderConstantF( dptr[1], (float const *) dptr+3, dptr[2]);
|
||||
dptr += 3+4*dptr[2];
|
||||
break;
|
||||
}
|
||||
case PBCMD_SET_BOOLEAN_VERTEX_SHADER_CONSTANT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_BOOLEAN_VERTEX_SHADER_CONSTANT" );
|
||||
Dx9Device()->SetVertexShaderConstantB( dptr[1], (int const *) dptr+3, dptr[2]);
|
||||
dptr += 3+dptr[2];
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_INTEGER_VERTEX_SHADER_CONSTANT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_INTEGER_VERTEX_SHADER_CONSTANT" );
|
||||
Dx9Device()->SetVertexShaderConstantI( dptr[1], (int const *) dptr+3, dptr[2]);
|
||||
dptr += 3+4*dptr[2];
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_PIXEL_SHADER_CONSTANT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_PIXEL_SHADER_CONSTANT" );
|
||||
Dx9Device()->SetPixelShaderConstantF( dptr[1], (float const *) dptr+3, dptr[2]);
|
||||
dptr += 3+4*dptr[2];
|
||||
break;
|
||||
}
|
||||
case PBCMD_SET_BOOLEAN_PIXEL_SHADER_CONSTANT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_BOOLEAN_PIXEL_SHADER_CONSTANT" );
|
||||
Dx9Device()->SetPixelShaderConstantB( dptr[1], (int const *) dptr+3, dptr[2]);
|
||||
dptr += 3+dptr[2];
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_INTEGER_PIXEL_SHADER_CONSTANT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_INTEGER_PIXEL_SHADER_CONSTANT" );
|
||||
Dx9Device()->SetPixelShaderConstantI( dptr[1], (int const *) dptr+3, dptr[2]);
|
||||
dptr += 3+4*dptr[2];
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_BEGIN_SCENE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "BEGIN_SCENE" );
|
||||
Dx9Device()->BeginScene();
|
||||
dptr++;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_END_SCENE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "END_SCENE" );
|
||||
Dx9Device()->EndScene();
|
||||
dptr++;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_CLEAR:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "CLEAR" );
|
||||
dptr++;
|
||||
int count=*(dptr++);
|
||||
D3DRECT const *pRects=0;
|
||||
if (count)
|
||||
{
|
||||
pRects=(D3DRECT const *) dptr;
|
||||
dptr+=count*N_DWORDS( D3DRECT );
|
||||
}
|
||||
int flags=*(dptr++);
|
||||
D3DCOLOR color=*((D3DCOLOR const *) (dptr++));
|
||||
float z=*((float const *) (dptr++));
|
||||
int stencil=*(dptr++);
|
||||
Dx9Device()->Clear( count, pRects, flags, color, z, stencil );
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_VERTEXDECLARATION:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_VERTEXDECLARATION" );
|
||||
Dx9Device()->SetVertexDeclaration( (IDirect3DVertexDeclaration9 *) FetchPtr(dptr+1));
|
||||
dptr += 1+N_DWORDS_IN_PTR;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SETCLIPPLANE:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SETCLIPPLANE" );
|
||||
Dx9Device()->SetClipPlane( dptr[1], (float const *) dptr+2 );
|
||||
dptr+=6;
|
||||
}
|
||||
break;
|
||||
|
||||
case PBCMD_STRETCHRECT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "STRETCHRECT" );
|
||||
dptr++;
|
||||
IDirect3DSurface9 *pSourceSurface=(IDirect3DSurface9 *) FetchPtr(dptr);
|
||||
dptr+=N_DWORDS_IN_PTR;
|
||||
RECT const *pSourceRect=0;
|
||||
if (*(dptr++))
|
||||
pSourceRect=(RECT const *) dptr;
|
||||
dptr += N_DWORDS( RECT );
|
||||
IDirect3DSurface9 *pDestSurface= (IDirect3DSurface9 *) FetchPtr( dptr );
|
||||
dptr += N_DWORDS_IN_PTR;
|
||||
RECT const *pDestRect=0;
|
||||
if (*(dptr++))
|
||||
pDestRect=(RECT const *) dptr;
|
||||
dptr += N_DWORDS( RECT );
|
||||
D3DTEXTUREFILTERTYPE Filter = (D3DTEXTUREFILTERTYPE) *(dptr++);
|
||||
Dx9Device()->StretchRect( pSourceSurface, pSourceRect,
|
||||
pDestSurface, pDestRect,
|
||||
Filter );
|
||||
}
|
||||
break;
|
||||
|
||||
#ifndef DX_TO_GL_ABSTRACTION
|
||||
case PBCMD_STRETCHRECT_NVAPI:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "STRETCHRECTNVAPI" );
|
||||
TM_ZONE( TELEMETRY_LEVEL1, TMZF_NONE, "NvAPI_D3D9_StretchRectEx_async" );
|
||||
|
||||
dptr++;
|
||||
IDirect3DResource9 *pSourceResource = (IDirect3DResource9 *)FetchPtr( dptr );
|
||||
dptr += N_DWORDS_IN_PTR;
|
||||
RECT const *pSourceRect = 0;
|
||||
if ( *(dptr++) )
|
||||
pSourceRect = (RECT const *)dptr;
|
||||
dptr += N_DWORDS( RECT );
|
||||
IDirect3DResource9 *pDestResource = (IDirect3DResource9 *)FetchPtr( dptr );
|
||||
dptr += N_DWORDS_IN_PTR;
|
||||
RECT const *pDestRect = 0;
|
||||
if ( *(dptr++) )
|
||||
pDestRect = (RECT const *)dptr;
|
||||
dptr += N_DWORDS( RECT );
|
||||
D3DTEXTUREFILTERTYPE Filter = (D3DTEXTUREFILTERTYPE)*(dptr++);
|
||||
|
||||
NvAPI_D3D9_StretchRectEx( Dx9Device(),
|
||||
pSourceResource, pSourceRect,
|
||||
pDestResource, pDestRect,
|
||||
Filter );
|
||||
pSourceResource->Release();
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
case PBCMD_PRESENT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "PRESENT" );
|
||||
dptr++;
|
||||
RECT const *pSourceRect=0;
|
||||
if (* (dptr++) )
|
||||
pSourceRect=(RECT const *) dptr;
|
||||
dptr+=N_DWORDS( RECT );
|
||||
RECT const *pDestRect = 0;
|
||||
if (* (dptr++) )
|
||||
pDestRect=(RECT const *) dptr;
|
||||
dptr+=N_DWORDS( RECT );
|
||||
VD3DHWND hDestWindowOverride = (VD3DHWND) *(dptr++);
|
||||
RGNDATA const *pDirtyRegion=0;
|
||||
if ( *(dptr++) )
|
||||
pDirtyRegion= (RGNDATA const *) dptr;
|
||||
dptr+=N_DWORDS( RGNDATA );
|
||||
Dx9Device()->Present( pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion );
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_SET_SCISSOR_RECT:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "SET_SCISSOR_RECT" );
|
||||
dptr++;
|
||||
const RECT *pRect = ( RECT * )FetchPtr( dptr );
|
||||
dptr += sizeof( RECT );
|
||||
Dx9Device()->SetScissorRect( pRect );
|
||||
}
|
||||
|
||||
#ifdef DX_TO_GL_ABSTRACTION
|
||||
case PBCMD_ACQUIRE_THREAD_OWNERSHIP:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "ACQUIRE_THREAD_OWNERSHIP" );
|
||||
Dx9Device()->AcquireThreadOwnership();
|
||||
dptr++;
|
||||
break;
|
||||
}
|
||||
|
||||
case PBCMD_RELEASE_THREAD_OWNERSHIP:
|
||||
{
|
||||
VPROF_BUFFER_PLAYBACK( "PBCMD_RELEASE_THREAD_OWNERSHIP" );
|
||||
Dx9Device()->ReleaseThreadOwnership();
|
||||
dptr++;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
1696
materialsystem/shaderapidx9/d3d_async.h
Normal file
1696
materialsystem/shaderapidx9/d3d_async.h
Normal file
File diff suppressed because it is too large
Load Diff
2013
materialsystem/shaderapidx9/dx9asmtogl.cpp
Normal file
2013
materialsystem/shaderapidx9/dx9asmtogl.cpp
Normal file
File diff suppressed because it is too large
Load Diff
101
materialsystem/shaderapidx9/dx9asmtogl.h
Normal file
101
materialsystem/shaderapidx9/dx9asmtogl.h
Normal file
@@ -0,0 +1,101 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// DX9AsmToGL.h
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef DX9_ASM_TO_GL_H
|
||||
#define DX9_ASM_TO_GL_H
|
||||
|
||||
#define DISASM_OK 0
|
||||
#define DISASM_ERROR 1
|
||||
|
||||
#define MAX_SHADER_CONSTANTS 512
|
||||
|
||||
// option bits
|
||||
#define D3DToGL_OptionUseEnvParams 0x01
|
||||
#define D3DToGL_OptionDoFixupZ 0x02 // add insts to put Z in the right interval for GL
|
||||
#define D3DToGL_OptionDoFixupY 0x04 // add insts to flip the Y over for GL
|
||||
#define D3DToGL_OptionDoUserClipPlanes 0x08 // include OPTION vertex_program_2 and append DP4's to write into oCLP[0] and oCLP[1]
|
||||
#define D3DToGL_OptionSpew 0x80000000
|
||||
|
||||
class D3DToGL_ASM
|
||||
{
|
||||
private:
|
||||
// Pointers for dwToken stream management
|
||||
uint32* m_pdwBaseToken;
|
||||
uint32* m_pdwNextToken;
|
||||
|
||||
// Vertex shader or pixel shader, and version (necessary because some opcodes alias)
|
||||
bool m_bVertexShader;
|
||||
uint32 m_dwMinorVersion;
|
||||
uint32 m_dwMajorVersion;
|
||||
|
||||
// Option flags
|
||||
bool m_bUseEnvParams; // set D3DToGL_OptionUseEnvParams in 'options' to use
|
||||
bool m_bDoFixupZ; // set D3DToGL_OptionDoFixupZ
|
||||
bool m_bDoFixupY; // set D3DToGL_OptionDoFixupZ
|
||||
bool m_bDoUserClipPlanes; // set D3DToGL_OptionDoUserClipPlanes
|
||||
bool m_bSpew; // set D3DToGL_OptionSpew
|
||||
|
||||
// Various scratch temps needed to handle mis-matches in instruction sets between D3D and OpenGL
|
||||
bool m_bNeedsD2AddTemp;
|
||||
bool m_bNeedsNRMTemp;
|
||||
bool m_bDeclareAddressReg;
|
||||
bool m_bNeedsLerpTemp;
|
||||
bool m_bNeedsSinCosDeclarations;
|
||||
|
||||
// Keep track of which vs outputs are used so we can declare them
|
||||
bool m_bDeclareVSOPos;
|
||||
bool m_bDeclareVSOFog;
|
||||
uint32 m_dwTexCoordOutMask;
|
||||
|
||||
// Keep track of which temps are used so they can be declared
|
||||
uint32 m_dwTempUsageMask;
|
||||
bool m_bOutputColorRegister[2];
|
||||
bool m_bOutputDepthRegister;
|
||||
|
||||
// Track constants so we know how to declare them
|
||||
bool m_bConstantRegisterReferenced[MAX_SHADER_CONSTANTS];
|
||||
bool m_bConstantRegisterDefined[MAX_SHADER_CONSTANTS];
|
||||
|
||||
// Track sampler types when declared so we can properly decorate TEX instructions
|
||||
uint32 m_dwSamplerTypes[32];
|
||||
|
||||
// Track shadow sampler usage
|
||||
int m_nShadowDepthSampler;
|
||||
bool m_bDeclareShadowOption;
|
||||
|
||||
// Track attribute references
|
||||
// init to 0xFFFFFFFF (unhit)
|
||||
// index by (dwRegToken & D3DSP_REGNUM_MASK) in VS DCL insns
|
||||
// fill with (usage<<4) | (usage index).
|
||||
uint32 m_dwAttribMap[16];
|
||||
|
||||
// GLSL does indentation for readability
|
||||
int m_NumIndentTabs;
|
||||
|
||||
// Utilities to aid in decoding token stream
|
||||
uint32 GetNextToken( void );
|
||||
void SkipTokens( uint32 numToSkip );
|
||||
uint32 Opcode( uint32 dwToken );
|
||||
uint32 OpcodeSpecificData( uint32 dwToken );
|
||||
uint32 TextureType ( uint32 dwToken );
|
||||
uint32 GetRegType( uint32 dwRegToken );
|
||||
|
||||
// Utilities for decoding tokens in to strings according to ASM syntax
|
||||
void PrintOpcode( uint32 inst, char* buff, int nBufLen );
|
||||
void PrintUsageAndIndexToString( uint32 dwToken, char* strUsageUsageIndexName, int nBufLen, bool bGLSL );
|
||||
void PrintParameterToString ( uint32 dwToken, uint32 dwSourceOrDest, char *pRegisterName, int nBufLen, bool bGLSL, int *pARLDestReg );
|
||||
void InsertMoveFromAddressRegister( char *pCode, int nCodeSize, int nARLComp0, int nARLComp1, int nARLComp2 );
|
||||
void InsertMoveInstruction( char *pCode, int nCodeSize, int nARLComponent );
|
||||
void FlagIndirectRegister( uint32 dwToken, int *pARLDestReg );
|
||||
|
||||
// Utilities for decoding tokens in to strings according to GLSL syntax
|
||||
void OpenIntrinsic( uint32 inst, char* buff, int nBufLen );
|
||||
void PrintIndentation( char *pBuf, int nBufLen );
|
||||
|
||||
public:
|
||||
int TranslateShader( uint32* code, char *pDisassembledCode, int nBufLen, bool *bVertexShader, uint32 options, int32 nShadowDepthSampler, char *debugLabel );
|
||||
};
|
||||
|
||||
|
||||
#endif // DX9_ASM_TO_GL_H
|
||||
3527
materialsystem/shaderapidx9/dx9asmtogl2.cpp
Normal file
3527
materialsystem/shaderapidx9/dx9asmtogl2.cpp
Normal file
File diff suppressed because it is too large
Load Diff
229
materialsystem/shaderapidx9/dx9asmtogl2.h
Normal file
229
materialsystem/shaderapidx9/dx9asmtogl2.h
Normal file
@@ -0,0 +1,229 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// DX9AsmToGL2.h
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef DX9_ASM_TO_GL_2_H
|
||||
#define DX9_ASM_TO_GL_2_H
|
||||
#include "tier1/utlstring.h"
|
||||
|
||||
#define DISASM_OK 0
|
||||
#define DISASM_ERROR 1
|
||||
|
||||
#define MAX_SHADER_CONSTANTS 512
|
||||
|
||||
#define MAX_DECLARED_OUTPUTS 32
|
||||
|
||||
#define HEXCODE_HEADER "// Hex: "
|
||||
|
||||
// Option bits
|
||||
#define D3DToGL_OptionUseEnvParams 0x001
|
||||
#define D3DToGL_OptionDoFixupZ 0x002 // Add instructions to put Z in the right interval for GL
|
||||
#define D3DToGL_OptionDoFixupY 0x004 // Add instructions to flip the Y over for GL
|
||||
#define D3DToGL_OptionDoUserClipPlanes 0x008 // ARB mode: Include OPTION vertex_program_2 and append DP4's to write into oCLP[0] and oCLP[1]
|
||||
// GLSL mode: generate code to write gl_ClipVertex
|
||||
#define D3DToGL_OptionGLSL 0x010 // Output GLSL, rather than ASM
|
||||
#define D3DToGL_AddHexComments 0x020 // Include hex comments in the code for debugging
|
||||
#define D3DToGL_PutHexCommentsAfterLines 0x040 // If D3DToGL_AddHexComments is set, this puts the codes to the right, rather than on separate lines
|
||||
#define D3DToGL_GeneratingDebugText 0x080 // This tells it that we're just getting info for debugging so go easy on asserts and errors
|
||||
#define D3DToGL_OptionAllowStaticControlFlow 0x100
|
||||
#define D3DToGL_OptionUseBindableUniforms 0x200 // add "bindable" in front of "vc" / "pc" constant arrays (GLSL only)
|
||||
#define D3DToGL_OptionSRGBWriteSuffix 0x400 // Tack sRGB conversion suffix on to pixel shaders
|
||||
#define D3DToGL_OptionSpew 0x80000000
|
||||
|
||||
// Code for which component of the "dummy" address register is needed by an instruction
|
||||
#define ARL_DEST_NONE -1
|
||||
#define ARL_DEST_X 0
|
||||
#define ARL_DEST_Y 1
|
||||
#define ARL_DEST_Z 2
|
||||
#define ARL_DEST_W 3
|
||||
|
||||
class D3DToGL
|
||||
{
|
||||
private:
|
||||
// Pointers for dwToken stream management
|
||||
uint32* m_pdwBaseToken;
|
||||
uint32* m_pdwNextToken;
|
||||
|
||||
// Vertex shader or pixel shader, and version (necessary because some opcodes alias)
|
||||
bool m_bVertexShader;
|
||||
uint32 m_dwMinorVersion;
|
||||
uint32 m_dwMajorVersion;
|
||||
|
||||
// Option flags
|
||||
bool m_bUseEnvParams; // set D3DToGL_OptionUseEnvParams in 'options' to use
|
||||
bool m_bDoFixupZ; // set D3DToGL_OptionDoFixupZ
|
||||
bool m_bDoFixupY; // set D3DToGL_OptionDoFixupZ
|
||||
bool m_bDoUserClipPlanes; // set D3DToGL_OptionDoUserClipPlanes
|
||||
bool m_bSpew; // set D3DToGL_OptionSpew
|
||||
bool m_bUseBindableUniforms; // set D3DToGL_OptionUseBindableUniforms
|
||||
bool m_bGenerateSRGBWriteSuffix; // set D3DToGL_OptionSRGBWriteSuffix
|
||||
|
||||
// Default: false
|
||||
// If you set this to true, it'll convert to GLSL instead of GL ASM.
|
||||
bool m_bGLSL; // set D3DToGL_OptionGLSL
|
||||
|
||||
// Default: false
|
||||
bool m_bAllowStaticControlFlow; // set D3DToGL_OptionAllowStaticControlFlow
|
||||
|
||||
// Counter for dealing with nested loops
|
||||
int m_nLoopDepth;
|
||||
|
||||
// Add "// Hex: 0xFFEEF00"-type statements after each instruction is parsed.
|
||||
bool m_bAddHexCodeComments; // set D3DToGL_AddHexComments
|
||||
|
||||
// Only applicable if m_bAddHexCodeComments is true.
|
||||
// If this is true, then it puts the hex code comments to the right of the instructions in a comment
|
||||
// rather than preceding the instructions.
|
||||
// Defaults to FALSE.
|
||||
bool m_bPutHexCodesAfterLines; // set D3DToGL_PutHexCommentsAtEnd
|
||||
|
||||
// This tells it that we're just getting info for debugging so go easy on asserts and errors.
|
||||
// Defaults to FALSE.
|
||||
bool m_bGeneratingDebugText;
|
||||
|
||||
// Various scratch temps needed to handle mis-matches in instruction sets between D3D and OpenGL
|
||||
bool m_bNeedsD2AddTemp;
|
||||
bool m_bNeedsNRMTemp;
|
||||
bool m_bDeclareAddressReg;
|
||||
bool m_bNeedsLerpTemp;
|
||||
bool m_bNeedsSinCosDeclarations;
|
||||
|
||||
// Keep track of which vs outputs are used so we can declare them
|
||||
bool m_bDeclareVSOPos;
|
||||
bool m_bDeclareVSOFog;
|
||||
uint32 m_dwTexCoordOutMask;
|
||||
|
||||
// Mask of varyings which need centroid decoration
|
||||
uint32 m_nCentroidMask;
|
||||
|
||||
// Keep track of which temps are used so they can be declared
|
||||
uint32 m_dwTempUsageMask;
|
||||
bool m_bOutputColorRegister[2];
|
||||
bool m_bOutputDepthRegister;
|
||||
|
||||
// Declaration of integer and bool constants
|
||||
uint32 m_dwConstIntUsageMask;
|
||||
uint32 m_dwConstBoolUsageMask;
|
||||
|
||||
// Did we use atomic_temp_var?
|
||||
bool m_bUsedAtomicTempVar;
|
||||
|
||||
// Track constants so we know how to declare them
|
||||
bool m_bConstantRegisterDefined[MAX_SHADER_CONSTANTS];
|
||||
|
||||
// Track sampler types when declared so we can properly decorate TEX instructions
|
||||
uint32 m_dwSamplerTypes[32];
|
||||
|
||||
// Track sampler usage
|
||||
uint32 m_dwSamplerUsageMask;
|
||||
|
||||
// Track shadow sampler usage
|
||||
int m_nShadowDepthSampler;
|
||||
bool m_bDeclareShadowOption;
|
||||
|
||||
// Track attribute references
|
||||
// init to 0xFFFFFFFF (unhit)
|
||||
// index by (dwRegToken & D3DSP_REGNUM_MASK) in VS DCL insns
|
||||
// fill with (usage<<4) | (usage index).
|
||||
uint32 m_dwAttribMap[16];
|
||||
|
||||
// Register high water mark
|
||||
uint32 m_nHighestRegister;
|
||||
|
||||
// GLSL does indentation for readability
|
||||
int m_NumIndentTabs;
|
||||
|
||||
// Output buffers.
|
||||
CUtlBuffer *m_pBufHeaderCode;
|
||||
CUtlBuffer *m_pBufAttribCode;
|
||||
CUtlBuffer *m_pBufParamCode;
|
||||
CUtlBuffer *m_pBufALUCode;
|
||||
|
||||
char *m_pFinalAssignmentsCode;
|
||||
int m_nFinalAssignmentsBufSize;
|
||||
|
||||
// Recorded positions for debugging.
|
||||
uint32* m_pRecordedInputTokenStart;
|
||||
int m_nRecordedParamCodeStrlen;
|
||||
int m_nRecordedALUCodeStrlen;
|
||||
int m_nRecordedAttribCodeStrlen;
|
||||
|
||||
// In GLSL mode, these store the semantic attached to each oN register.
|
||||
// They are the values that you pass to GetUsageIndexAndString.
|
||||
uint32 m_DeclaredOutputs[MAX_DECLARED_OUTPUTS];
|
||||
|
||||
// Have they used the tangent input semantic (i.e. is g_pTangentAttributeName declared)?
|
||||
bool m_bTangentInputUsed;
|
||||
|
||||
|
||||
private:
|
||||
// Utilities to aid in decoding token stream
|
||||
uint32 GetNextToken( void );
|
||||
void SkipTokens( uint32 numToSkip );
|
||||
uint32 Opcode( uint32 dwToken );
|
||||
uint32 OpcodeSpecificData( uint32 dwToken );
|
||||
uint32 TextureType ( uint32 dwToken );
|
||||
uint32 GetRegType( uint32 dwRegToken );
|
||||
|
||||
// Write to the different buffers.
|
||||
void StrcatToHeaderCode( const char *pBuf );
|
||||
void StrcatToALUCode( const char *pBuf );
|
||||
void StrcatToParamCode( const char *pBuf );
|
||||
void StrcatToAttribCode( const char *pBuf );
|
||||
|
||||
// This helps write the token hex codes into the output stream for debugging.
|
||||
void AddTokenHexCodeToBuffer( char *pBuffer, int nSize, int nLastStrlen );
|
||||
void RecordInputAndOutputPositions();
|
||||
void AddTokenHexCode();
|
||||
|
||||
// Utilities for decoding tokens in to strings according to ASM syntax
|
||||
void PrintOpcode( uint32 inst, char* buff, int nBufLen );
|
||||
|
||||
// fSemanticFlags is SEMANTIC_INPUT or SEMANTIC_OUTPUT.
|
||||
void PrintUsageAndIndexToString( uint32 dwToken, char* strUsageUsageIndexName, int nBufLen, int fSemanticFlags );
|
||||
CUtlString GetUsageAndIndexString( uint32 dwToken, int fSemanticFlags );
|
||||
CUtlString GetParameterString( uint32 dwToken, uint32 dwSourceOrDest, bool bForceScalarSource, int *pARLDestReg );
|
||||
const char* GetGLSLOperatorString( uint32 inst );
|
||||
|
||||
void PrintParameterToString ( uint32 dwToken, uint32 dwSourceOrDest, char *pRegisterName, int nBufLen, bool bForceScalarSource, int *pARLDestReg );
|
||||
|
||||
void InsertMoveFromAddressRegister( CUtlBuffer *pCode, int nARLComp0, int nARLComp1, int nARLComp2 = ARL_DEST_NONE );
|
||||
void InsertMoveInstruction( CUtlBuffer *pCode, int nARLComponent );
|
||||
void FlagIndirectRegister( uint32 dwToken, int *pARLDestReg );
|
||||
|
||||
// Utilities for decoding tokens in to strings according to GLSL syntax
|
||||
bool OpenIntrinsic( uint32 inst, char* buff, int nBufLen, uint32 destDimension, uint32 nArgumentDimension );
|
||||
void PrintIndentation( char *pBuf, int nBufLen );
|
||||
|
||||
uint32 MaintainAttributeMap( uint32 dwToken, uint32 dwRegToken );
|
||||
|
||||
CUtlString FixGLSLSwizzle( const char *pDestRegisterName, const char *pSrcRegisterName );
|
||||
void WriteGLSLCmp( const char *pDestReg, const char *pSrc0Reg, const char *pSrc1Reg, const char *pSrc2Reg );
|
||||
void WriteGLSLSamplerDefinitions();
|
||||
void WriteGLSLOutputVariableAssignments();
|
||||
void NoteTangentInputUsed();
|
||||
|
||||
void Handle_DCL();
|
||||
void Handle_DEF();
|
||||
void Handle_MAD( uint32 nInstruction );
|
||||
void Handle_DP2ADD();
|
||||
void Handle_SINCOS();
|
||||
void Handle_LRP( uint32 nInstruction );
|
||||
void Handle_TEX( uint32 dwToken, bool bIsTexLDL );
|
||||
void Handle_TexLDD( uint32 nInstruction );
|
||||
void Handle_TexCoord();
|
||||
void Handle_UnaryOp( uint32 nInstruction );
|
||||
void HandleBinaryOp_GLSL( uint32 nInstruction );
|
||||
void HandleBinaryOp_ASM( uint32 nInstruction );
|
||||
void Handle_CMP();
|
||||
void Handle_NRM();
|
||||
void Handle_DeclarativeNonDclOp( uint32 nInstruction );
|
||||
|
||||
public:
|
||||
D3DToGL();
|
||||
|
||||
int TranslateShader( uint32* code, CUtlBuffer *pBufDisassembledCode, bool *bVertexShader, uint32 options, int32 nShadowDepthSampler, uint32 nCentroidMask, char *debugLabel );
|
||||
};
|
||||
|
||||
|
||||
#endif // DX9_ASM_TO_GL_2_H
|
||||
1288
materialsystem/shaderapidx9/dx9hook.h
Normal file
1288
materialsystem/shaderapidx9/dx9hook.h
Normal file
File diff suppressed because it is too large
Load Diff
5762
materialsystem/shaderapidx9/dxabstract.cpp
Normal file
5762
materialsystem/shaderapidx9/dxabstract.cpp
Normal file
File diff suppressed because it is too large
Load Diff
2377
materialsystem/shaderapidx9/dxabstract.h
Normal file
2377
materialsystem/shaderapidx9/dxabstract.h
Normal file
File diff suppressed because it is too large
Load Diff
1047
materialsystem/shaderapidx9/dynamicib.h
Normal file
1047
materialsystem/shaderapidx9/dynamicib.h
Normal file
File diff suppressed because it is too large
Load Diff
1096
materialsystem/shaderapidx9/dynamicvb.h
Normal file
1096
materialsystem/shaderapidx9/dynamicvb.h
Normal file
File diff suppressed because it is too large
Load Diff
72
materialsystem/shaderapidx9/fontremaptable.h
Normal file
72
materialsystem/shaderapidx9/fontremaptable.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/////////////////////////
|
||||
// windows stock fonts //
|
||||
/////////////////////////
|
||||
{"courier new", "platform/vgui/fonts/cour.ttf", false, false},
|
||||
{"times new roman", "platform/vgui/fonts/times.ttf", false, false},
|
||||
{"trebuchet ms", "platform/vgui/fonts/trebuc.ttf", false, false},
|
||||
{"verdana", "platform/vgui/fonts/verdana.ttf", false, false},
|
||||
{"tahoma", "platform/vgui/fonts/tahoma.ttf", false, false},
|
||||
{"lucida console", "platform/vgui/fonts/lucon.ttf", false, false},
|
||||
{"arial", "platform/vgui/fonts/arial.ttf", false, false},
|
||||
{"arial bold", "platform/vgui/fonts/arialbd.ttf", false, false},
|
||||
{"arial narrow", "platform/vgui/fonts/arialn.ttf", false, false},
|
||||
{"arial unicode ms", "platform/vgui/fonts/xarialuni.ttf", true, false},
|
||||
{"marlett", "platform/vgui/fonts/marlett.ttf", false, false},
|
||||
|
||||
////////////////
|
||||
// game fonts //
|
||||
////////////////
|
||||
#if 0
|
||||
// TF
|
||||
{"tf2", "tf/resource/tf2.ttf", false, false},
|
||||
{"tf2 build", "tf/resource/tf2build.ttf", false, false},
|
||||
{"tf2 professor", "tf/resource/tf2professor.ttf", false, false},
|
||||
{"tf2 secondary", "tf/resource/tf2secondary.ttf", false, false},
|
||||
{"team fortress", "tf/resource/tf.ttf", false, false},
|
||||
{"tfd", "tf/resource/tfd.ttf", false, false},
|
||||
{"tflogo", "tf/resource/tflogo.ttf", false, false},
|
||||
|
||||
// EP2
|
||||
{"hl2ep2", "ep2/resource/hl2ep2.ttf", false, false},
|
||||
|
||||
// EPISODIC
|
||||
{"hl2ep1", "episodic/resource/hl2ep1.ttf", false, false},
|
||||
|
||||
// HL2
|
||||
{"halflife2", "hl2/resource/halflife2.ttf", false, false},
|
||||
{"hl2cross", "hl2/resource/HL2Crosshairs.ttf", false, false},
|
||||
|
||||
// LEFT4DEAD
|
||||
{"future rot", "left4dead/resource/futurot.ttf", false, false},
|
||||
{"cs", "left4dead/resource/cs.ttf", false, false},
|
||||
{"csd", "left4dead/resource/csd.ttf", false, false},
|
||||
{"counter-strike", "left4dead/resource/cstrike.ttf", false, false},
|
||||
{"toolbox", "left4dead/resource/toolbox.ttf", false, false},
|
||||
{"trade gothic", "left4dead/resource/tg.ttf", false, false},
|
||||
{"trade gothic bold", "left4dead/resource/tgb.ttf", false, false},
|
||||
|
||||
// ALIEN SWARM
|
||||
{"enter sansman", "swarm/resource/Enter_Sansman_Bold.ttf", false, false},
|
||||
{"impact", "swarm/resource/impact.ttf", false, false},
|
||||
{"microsoft sans serif", "swarm/resource/micross.ttf", false, false},
|
||||
#elif defined( PORTAL2 )
|
||||
// PORTAL2
|
||||
{"universltstd-cn", "platform/vgui/fonts/universc.ttf", false, true},
|
||||
{"universltstd-lightcn", "platform/vgui/fonts/univercl.ttf", false, true},
|
||||
{"universltstd-boldcn", "platform/vgui/fonts/univercb.ttf", false, true},
|
||||
|
||||
// cyrillic capable
|
||||
{"universltcyr-57condensed", "platform/vgui/fonts/unltcyr5.ttf", false, true},
|
||||
{"universltcyr-67boldcond", "platform/vgui/fonts/unltcyr6.ttf", false, true},
|
||||
|
||||
{"consolas", "platform/vgui/fonts/consola.ttf", false, true},
|
||||
#elif defined( CSTRIKE15 )
|
||||
// COUNTER-STRIKE: SOURCE 1.5
|
||||
{"verdana bold", "csgo/resource/verdanab.ttf", false, false},
|
||||
{"cs", "csgo/resource/cs.ttf", false, false},
|
||||
{"csd", "csgo/resource/csd.ttf", false, false},
|
||||
{"counter-strike", "csgo/resource/Cstrike.ttf", false, false},
|
||||
{"counter-strike logo", "csgo/resource/CSLogo.ttf", false, false},
|
||||
{"Stratum2-Bold", "csgo/resource/stratum2bold.ttf", false, false},
|
||||
{"Stratum2-Medium", "csgo/resource/stratum2medium.ttf", false, false},
|
||||
#endif
|
||||
1026
materialsystem/shaderapidx9/hardwareconfig.cpp
Normal file
1026
materialsystem/shaderapidx9/hardwareconfig.cpp
Normal file
File diff suppressed because it is too large
Load Diff
299
materialsystem/shaderapidx9/hardwareconfig.h
Normal file
299
materialsystem/shaderapidx9/hardwareconfig.h
Normal file
@@ -0,0 +1,299 @@
|
||||
//===== Copyright (c) 1996-2008, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef HARDWARECONFIG_H
|
||||
#define HARDWARECONFIG_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "materialsystem/imaterialsystemhardwareconfig.h"
|
||||
#include "IHardwareConfigInternal.h"
|
||||
#include "bitmap/imageformat.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ShaderDeviceInfo_t;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Vendor IDs sometimes needed for vendor-specific code
|
||||
//-----------------------------------------------------------------------------
|
||||
#define VENDORID_NVIDIA 0x10DE
|
||||
#define VENDORID_ATI 0x1002
|
||||
#define VENDORID_INTEL 0x8086
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ShaderAPI constants
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
enum
|
||||
{
|
||||
#if defined( DX_TO_GL_ABSTRACTION )
|
||||
MAXUSERCLIPPLANES = 2,
|
||||
|
||||
#if defined( OSX )
|
||||
MAX_NUM_LIGHTS = 2,
|
||||
#else
|
||||
MAX_NUM_LIGHTS = 4,
|
||||
#endif
|
||||
|
||||
#else
|
||||
MAXUSERCLIPPLANES = 6,
|
||||
MAX_NUM_LIGHTS = 4,
|
||||
#endif
|
||||
|
||||
MAX_OUTPUTS = 3,
|
||||
|
||||
#if defined( _PS3 )
|
||||
MAX_FRAGMENT_PROGRAM_CONSTS = 96,
|
||||
#endif
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hardware caps structures
|
||||
//-----------------------------------------------------------------------------
|
||||
enum CompressedTextureState_t
|
||||
{
|
||||
COMPRESSED_TEXTURES_ON,
|
||||
COMPRESSED_TEXTURES_OFF,
|
||||
COMPRESSED_TEXTURES_NOT_INITIALIZED
|
||||
};
|
||||
|
||||
struct HardwareCaps_t : public MaterialAdapterInfo_t
|
||||
{
|
||||
// *****************************NOTE*********************************************
|
||||
// If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
|
||||
// If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
|
||||
// If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
|
||||
// If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
|
||||
// If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!!
|
||||
// *****************************NOTE*********************************************
|
||||
//
|
||||
// NOTE: Texture stages are an obsolete concept; used by fixed-function hardware
|
||||
// Samplers are dx9+, indicating how many textures we can simultaneously bind
|
||||
// In Dx8, samplers didn't exist and texture stages were used to indicate the
|
||||
// number of simultaneously bound textures; we'll emulate that by slamming
|
||||
// the number of samplers to == the number of texture stages.
|
||||
CompressedTextureState_t m_SupportsCompressedTextures;
|
||||
VertexCompressionType_t m_SupportsCompressedVertices;
|
||||
int m_NumSamplers;
|
||||
int m_NumVertexSamplers;
|
||||
int m_nMaxAnisotropy;
|
||||
int m_MaxTextureWidth;
|
||||
int m_MaxTextureHeight;
|
||||
int m_MaxTextureDepth;
|
||||
int m_MaxTextureAspectRatio;
|
||||
int m_MaxPrimitiveCount;
|
||||
int m_NumPixelShaderConstants;
|
||||
int m_NumBooleanPixelShaderConstants;
|
||||
int m_NumIntegerPixelShaderConstants;
|
||||
int m_NumVertexShaderConstants;
|
||||
int m_NumBooleanVertexShaderConstants;
|
||||
int m_NumIntegerVertexShaderConstants;
|
||||
int m_TextureMemorySize;
|
||||
int m_MaxNumLights;
|
||||
int m_MaxVertexShaderBlendMatrices;
|
||||
int m_MaxUserClipPlanes;
|
||||
HDRType_t m_HDRType;
|
||||
char m_pShaderDLL[32];
|
||||
ImageFormat m_ShadowDepthTextureFormat;
|
||||
ImageFormat m_HighPrecisionShadowDepthTextureFormat;
|
||||
ImageFormat m_NullTextureFormat;
|
||||
int m_nMaxVertexTextureDimension;
|
||||
unsigned long m_AlphaToCoverageState; // State to ping to toggle Alpha To Coverage (vendor-dependent)
|
||||
unsigned long m_AlphaToCoverageEnableValue; // Value to set above state to turn on Alpha To Coverage (vendor-dependent)
|
||||
unsigned long m_AlphaToCoverageDisableValue; // Value to set above state to turn off Alpha To Coverage (vendor-dependent)
|
||||
int m_nMaxViewports;
|
||||
float m_flMinGammaControlPoint;
|
||||
float m_flMaxGammaControlPoint;
|
||||
int m_nGammaControlPointCount;
|
||||
int m_MaxVertexShader30InstructionSlots;
|
||||
int m_MaxPixelShader30InstructionSlots;
|
||||
int m_MaxSimultaneousRenderTargets;
|
||||
|
||||
bool m_bDeviceOk : 1;
|
||||
bool m_HasSetDeviceGammaRamp : 1;
|
||||
bool m_SupportsPixelShaders_2_b : 1;
|
||||
bool m_SupportsShaderModel_3_0 : 1;
|
||||
bool m_bSupportsAnisotropicFiltering : 1;
|
||||
bool m_bSupportsMagAnisotropicFiltering : 1;
|
||||
bool m_bSupportsVertexTextures : 1;
|
||||
bool m_ZBiasAndSlopeScaledDepthBiasSupported : 1;
|
||||
bool m_SupportsMipmappedCubemaps : 1;
|
||||
bool m_PreferDynamicTextures : 1;
|
||||
bool m_SupportsSRGB : 1;
|
||||
bool m_UseFastClipping : 1;
|
||||
bool m_bNeedsATICentroidHack : 1;
|
||||
bool m_bDisableShaderOptimizations : 1;
|
||||
bool m_bSupportsStreamOffset : 1;
|
||||
bool m_bFogColorSpecifiedInLinearSpace : 1;
|
||||
bool m_bFogColorAlwaysLinearSpace : 1;
|
||||
bool m_bSupportsAlphaToCoverage : 1;
|
||||
bool m_bSupportsShadowDepthTextures : 1;
|
||||
bool m_bSupportsFetch4 : 1;
|
||||
bool m_bSoftwareVertexProcessing : 1;
|
||||
bool m_bScissorSupported : 1;
|
||||
bool m_bSupportsFloat32RenderTargets : 1;
|
||||
bool m_bSupportsBorderColor : 1;
|
||||
bool m_bDX10Card : 1; // Indicates DX10 part with performant vertex textures running DX9 path
|
||||
bool m_bDX10Blending : 1; // Indicates DX10 part that does DX10 blending (but may not have performant vertex textures, such as Intel parts)
|
||||
bool m_bSupportsTessellation : 1;
|
||||
bool m_bPreferZPrepass : 1;
|
||||
bool m_bSuppressPixelShaderCentroidHackFixup : 1;
|
||||
bool m_bPreferTexturesInHWMemory : 1;
|
||||
bool m_bPreferHardwareSync : 1;
|
||||
bool m_bUnsupported : 1;
|
||||
bool m_bSupportsStaticControlFlow : 1; // Useful on OpenGL, where we have a mix of support...
|
||||
bool m_FakeSRGBWrite : 1; // Gotta do this on OpenGL. Mostly hidden, but some high level code needs to know
|
||||
bool m_CanDoSRGBReadFromRTs : 1; // Gotta do this on OpenGL. Mostly hidden, but some high level code needs to know
|
||||
bool m_bSupportsGLMixedSizeTargets : 1; // on OpenGL, are mixed size depth buffers supported - aka ARB_framebuffer_object
|
||||
bool m_bSupportsSRGBDecode : 1; // Supports GL_EXT_texture_sRGB_decode, which allows us to toggle sRGB read D3D-style
|
||||
bool m_bSupportsCascadedShadowMapping : 1;
|
||||
bool m_bSupportsRESZ : 1;
|
||||
bool m_bSupportsINTZ : 1;
|
||||
|
||||
HDRType_t m_MaxHDRType;
|
||||
|
||||
uint8 m_nCSMQuality;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Contains the hardware configuration for the current device
|
||||
//-----------------------------------------------------------------------------
|
||||
class CHardwareConfig : public IHardwareConfigInternal
|
||||
{
|
||||
public:
|
||||
CHardwareConfig();
|
||||
|
||||
// Sets up the hardware caps given the specified DX level
|
||||
void SetupHardwareCaps( const ShaderDeviceInfo_t& mode, const HardwareCaps_t &actualCaps );
|
||||
|
||||
// FIXME: This is for backward compat only.. don't use these
|
||||
void SetupHardwareCaps( int nDXLevel, const HardwareCaps_t &actualCaps );
|
||||
HardwareCaps_t& ActualCapsForEdit() { return m_ActualCaps; }
|
||||
HardwareCaps_t& CapsForEdit() { return m_Caps; }
|
||||
|
||||
// Members of IMaterialSystemHardwareConfig
|
||||
virtual bool HasStencilBuffer() const;
|
||||
virtual int GetFrameBufferColorDepth() const;
|
||||
virtual int GetSamplerCount() const;
|
||||
virtual bool HasSetDeviceGammaRamp() const;
|
||||
virtual VertexCompressionType_t SupportsCompressedVertices() const;
|
||||
virtual bool SupportsBorderColor() const;
|
||||
virtual bool SupportsFetch4() const;
|
||||
virtual bool SupportsStaticControlFlow() const;
|
||||
virtual int MaximumAnisotropicLevel() const;
|
||||
virtual int MaxTextureWidth() const;
|
||||
virtual int MaxTextureHeight() const;
|
||||
virtual int TextureMemorySize() const;
|
||||
virtual bool SupportsMipmappedCubemaps() const;
|
||||
virtual int NumVertexShaderConstants() const;
|
||||
virtual int NumBooleanVertexShaderConstants() const;
|
||||
virtual int NumIntegerVertexShaderConstants() const;
|
||||
virtual int NumPixelShaderConstants() const;
|
||||
virtual int NumBooleanPixelShaderConstants() const;
|
||||
virtual int NumIntegerPixelShaderConstants() const;
|
||||
virtual int MaxNumLights() const;
|
||||
virtual int MaxTextureAspectRatio() const;
|
||||
virtual int MaxVertexShaderBlendMatrices() const;
|
||||
virtual int MaxUserClipPlanes() const;
|
||||
virtual bool UseFastClipping() const;
|
||||
virtual int GetDXSupportLevel() const;
|
||||
virtual const char *GetShaderDLLName() const;
|
||||
virtual bool ReadPixelsFromFrontBuffer() const;
|
||||
virtual bool PreferDynamicTextures() const;
|
||||
virtual bool SupportsHDR() const;
|
||||
virtual bool NeedsAAClamp() const;
|
||||
virtual bool NeedsATICentroidHack() const;
|
||||
virtual int GetMaxDXSupportLevel() const;
|
||||
virtual bool SpecifiesFogColorInLinearSpace() const;
|
||||
virtual bool SupportsSRGB() const;
|
||||
virtual bool FakeSRGBWrite() const;
|
||||
virtual bool CanDoSRGBReadFromRTs() const;
|
||||
virtual bool SupportsGLMixedSizeTargets() const;
|
||||
virtual bool IsAAEnabled() const;
|
||||
virtual int GetVertexSamplerCount() const;
|
||||
virtual int GetMaxVertexTextureDimension() const;
|
||||
virtual int MaxTextureDepth() const;
|
||||
virtual HDRType_t GetHDRType() const;
|
||||
virtual HDRType_t GetHardwareHDRType() const;
|
||||
virtual bool SupportsStreamOffset() const;
|
||||
virtual int StencilBufferBits() const;
|
||||
virtual int MaxViewports() const;
|
||||
virtual void OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport );
|
||||
|
||||
// PS30 only supports shadow filter modes 0-2 (there's no use supporting mode 3, which is the ATI_NOPCF pass only used on low end), while PS20B supports all modes
|
||||
virtual ShadowFilterMode_t GetShadowFilterMode( bool bForceLowQualityShadows, bool bPS30 ) const;
|
||||
|
||||
virtual int NeedsShaderSRGBConversion() const;
|
||||
virtual bool UsesSRGBCorrectBlending() const;
|
||||
virtual bool HasFastVertexTextures() const;
|
||||
virtual int MaxHWMorphBatchCount() const;
|
||||
virtual float GetShadowDepthBias() const;
|
||||
virtual float GetShadowSlopeScaleDepthBias() const;
|
||||
virtual bool PreferZPrepass() const;
|
||||
virtual bool SuppressPixelShaderCentroidHackFixup() const;
|
||||
virtual bool PreferTexturesInHWMemory() const;
|
||||
virtual bool PreferHardwareSync() const;
|
||||
virtual bool ActualHasFastVertexTextures() const;
|
||||
virtual bool SupportsShadowDepthTextures( void ) const;
|
||||
virtual ImageFormat GetShadowDepthTextureFormat( void ) const;
|
||||
virtual ImageFormat GetHighPrecisionShadowDepthTextureFormat( void ) const;
|
||||
virtual ImageFormat GetNullTextureFormat( void ) const;
|
||||
virtual int GetMinDXSupportLevel() const;
|
||||
virtual bool IsUnsupported() const;
|
||||
|
||||
const char *GetHWSpecificShaderDLLName() const;
|
||||
int GetActualSamplerCount() const;
|
||||
int GetActualVertexSamplerCount() const;
|
||||
|
||||
virtual bool SupportsHDRMode( HDRType_t nHDRMode ) const;
|
||||
|
||||
const HardwareCaps_t& ActualCaps() const { return m_ActualCaps; }
|
||||
const HardwareCaps_t& Caps() const { return m_Caps; }
|
||||
virtual bool GetHDREnabled( void ) const;
|
||||
virtual void SetHDREnabled( bool bEnable );
|
||||
|
||||
float GetLightMapScaleFactor( void ) const;
|
||||
|
||||
bool SupportsCascadedShadowMapping( void ) const;
|
||||
CSMQualityMode_t GetCSMQuality() const;
|
||||
bool SupportsBilinearPCFSampling() const;
|
||||
CSMShaderMode_t GetCSMShaderMode( CSMQualityMode_t nQualityLevel ) const;
|
||||
bool GetCSMAccurateBlending() const;
|
||||
void SetCSMAccurateBlending( bool bEnable );
|
||||
|
||||
bool SupportsResolveDepth() const;
|
||||
bool HasFullResolutionDepthTexture() const;
|
||||
|
||||
protected:
|
||||
// Gets the recommended configuration associated with a particular dx level
|
||||
void ForceCapsToDXLevel( HardwareCaps_t *pCaps, int nDxLevel, const HardwareCaps_t &actualCaps );
|
||||
|
||||
// Members related to capabilities
|
||||
HardwareCaps_t m_ActualCaps;
|
||||
HardwareCaps_t m_Caps;
|
||||
HardwareCaps_t m_UnOverriddenCaps;
|
||||
bool m_bHDREnabled;
|
||||
bool m_bCSMAccurateBlending;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton hardware config
|
||||
//-----------------------------------------------------------------------------
|
||||
extern CHardwareConfig *g_pHardwareConfig;
|
||||
|
||||
|
||||
#endif // HARDWARECONFIG_H
|
||||
107
materialsystem/shaderapidx9/hardwareconfig_ps3nonvirt.h
Normal file
107
materialsystem/shaderapidx9/hardwareconfig_ps3nonvirt.h
Normal file
@@ -0,0 +1,107 @@
|
||||
//========== Copyright <20> 2005, Valve Corporation, All rights reserved. ========
|
||||
#ifndef HARDWARECONFIG_PS3NONVIRT_H
|
||||
#define HARDWARECONFIG_PS3NONVIRT_H
|
||||
|
||||
#ifdef _PS3
|
||||
|
||||
#include "ihardwareconfiginternal.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PS3 non-virtual implementation proxy
|
||||
//
|
||||
// cat hardwareconfig_ps3nonvirt.h | nonvirtualscript.pl > hardwareconfig_ps3nonvirt.inl
|
||||
struct CPs3NonVirt_IHardwareConfigInternal
|
||||
{
|
||||
//NONVIRTUALSCRIPTBEGIN
|
||||
//NONVIRTUALSCRIPT/PROXY/CPs3NonVirt_IHardwareConfigInternal
|
||||
//NONVIRTUALSCRIPT/DELEGATE/g_pHardwareConfig->CHardwareConfig::
|
||||
|
||||
//
|
||||
// IMaterialSystemHardwareConfig
|
||||
//
|
||||
static bool HasSetDeviceGammaRamp();
|
||||
static VertexCompressionType_t SupportsCompressedVertices();
|
||||
static int MaximumAnisotropicLevel();
|
||||
static int MaxTextureWidth();
|
||||
static int MaxTextureHeight();
|
||||
static int TextureMemorySize();
|
||||
static bool SupportsMipmappedCubemaps();
|
||||
static int MaxTextureAspectRatio();
|
||||
static int MaxVertexShaderBlendMatrices();
|
||||
static bool UseFastClipping();
|
||||
static bool ReadPixelsFromFrontBuffer();
|
||||
static bool PreferDynamicTextures();
|
||||
static bool NeedsAAClamp();
|
||||
static bool SpecifiesFogColorInLinearSpace();
|
||||
static bool IsAAEnabled(); // Is antialiasing being used?
|
||||
static int GetVertexSamplerCount();
|
||||
static int GetMaxVertexTextureDimension();
|
||||
static int MaxTextureDepth();
|
||||
static bool SupportsStreamOffset();
|
||||
static int StencilBufferBits();
|
||||
static int MaxViewports();
|
||||
static void OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport );
|
||||
static int MaxHWMorphBatchCount();
|
||||
static float GetShadowDepthBias();
|
||||
static float GetShadowSlopeScaleDepthBias();
|
||||
static bool PreferZPrepass();
|
||||
static bool SuppressPixelShaderCentroidHackFixup();
|
||||
static bool PreferTexturesInHWMemory();
|
||||
static bool PreferHardwareSync();
|
||||
static bool SupportsShadowDepthTextures();
|
||||
static ImageFormat GetShadowDepthTextureFormat();
|
||||
static ImageFormat GetHighPrecisionShadowDepthTextureFormat();
|
||||
static ImageFormat GetNullTextureFormat();
|
||||
static float GetLightMapScaleFactor();
|
||||
|
||||
//NONVIRTUALSCRIPTEND
|
||||
|
||||
//
|
||||
// Predefined implementation
|
||||
//
|
||||
static inline bool SupportsStaticControlFlow() { return true; }
|
||||
static inline bool FakeSRGBWrite() { return false; }
|
||||
static inline bool CanDoSRGBReadFromRTs() { return true; }
|
||||
static inline bool SupportsGLMixedSizeTargets() { return true; }
|
||||
static inline int MaxNumLights() { return MAX_NUM_LIGHTS; }
|
||||
static inline int MaxUserClipPlanes() { return 0; }
|
||||
static inline ShadowFilterMode_t GetShadowFilterMode( bool bForceLowQualityShadows, bool bPS30 ) { return SHADOWFILTERMODE_DEFAULT; } // PCF filter
|
||||
static inline bool SupportsHDRMode( HDRType_t nHDRMode ) { return ( nHDRMode == HDR_TYPE_NONE ) || ( nHDRMode == HDR_TYPE_INTEGER ); }
|
||||
static inline HDRType_t GetHDRType() { return HDR_TYPE_INTEGER; }
|
||||
static inline HDRType_t GetHardwareHDRType() { return HDR_TYPE_INTEGER; }
|
||||
static inline bool HasFastVertexTextures() { return false; }
|
||||
static inline bool ActualHasFastVertexTextures() { return false; }
|
||||
static int NeedsShaderSRGBConversion() { return false; }
|
||||
static inline bool SupportsBorderColor() { return true; }
|
||||
static inline bool SupportsFetch4() { return false; }
|
||||
static inline bool NeedsATICentroidHack() { return false; }
|
||||
static inline int NumVertexShaderConstants() { return 256; }
|
||||
static inline int NumPixelShaderConstants() { return MAX_FRAGMENT_PROGRAM_CONSTS; }
|
||||
static inline bool GetHDREnabled() { return true; }
|
||||
static inline void SetHDREnabled( bool bEnable ) {}
|
||||
static inline bool IsUnsupported() { return false; }
|
||||
static inline int GetFrameBufferColorDepth() { return 4; }
|
||||
static inline int GetSamplerCount() { return 16; }
|
||||
static inline int GetDXSupportLevel() { return 98; }
|
||||
static inline int GetMaxDXSupportLevel() { return GetDXSupportLevel(); }
|
||||
static inline int GetMinDXSupportLevel() { return GetDXSupportLevel(); }
|
||||
static inline bool SupportsHDR() { return true; }
|
||||
static inline bool SupportsSRGB() { return true; }
|
||||
static inline bool UsesSRGBCorrectBlending() { return IsX360(); }
|
||||
static inline bool SupportsPixelShaders_2_b() { return true; }
|
||||
static inline const char *GetShaderDLLName() { return "shaderapidx9"; }
|
||||
static inline const char *GetHWSpecificShaderDLLName() { return "shaderapidx9"; }
|
||||
static inline bool SupportsCascadedShadowMapping() { return false; }
|
||||
static inline bool SupportsBilinearPCFSampling() { return true; }
|
||||
};
|
||||
|
||||
inline CPs3NonVirt_IHardwareConfigInternal* HardwareConfig()
|
||||
{
|
||||
return ( CPs3NonVirt_IHardwareConfigInternal * ) 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
164
materialsystem/shaderapidx9/hardwareconfig_ps3nonvirt.inl
Normal file
164
materialsystem/shaderapidx9/hardwareconfig_ps3nonvirt.inl
Normal file
@@ -0,0 +1,164 @@
|
||||
bool CPs3NonVirt_IHardwareConfigInternal::HasSetDeviceGammaRamp()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::HasSetDeviceGammaRamp();
|
||||
}
|
||||
|
||||
VertexCompressionType_t CPs3NonVirt_IHardwareConfigInternal::SupportsCompressedVertices()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::SupportsCompressedVertices();
|
||||
}
|
||||
|
||||
int CPs3NonVirt_IHardwareConfigInternal::MaximumAnisotropicLevel()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::MaximumAnisotropicLevel();
|
||||
}
|
||||
|
||||
int CPs3NonVirt_IHardwareConfigInternal::MaxTextureWidth()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::MaxTextureWidth();
|
||||
}
|
||||
|
||||
int CPs3NonVirt_IHardwareConfigInternal::MaxTextureHeight()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::MaxTextureHeight();
|
||||
}
|
||||
|
||||
int CPs3NonVirt_IHardwareConfigInternal::TextureMemorySize()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::TextureMemorySize();
|
||||
}
|
||||
|
||||
bool CPs3NonVirt_IHardwareConfigInternal::SupportsMipmappedCubemaps()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::SupportsMipmappedCubemaps();
|
||||
}
|
||||
|
||||
int CPs3NonVirt_IHardwareConfigInternal::MaxTextureAspectRatio()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::MaxTextureAspectRatio();
|
||||
}
|
||||
|
||||
int CPs3NonVirt_IHardwareConfigInternal::MaxVertexShaderBlendMatrices()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::MaxVertexShaderBlendMatrices();
|
||||
}
|
||||
|
||||
bool CPs3NonVirt_IHardwareConfigInternal::UseFastClipping()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::UseFastClipping();
|
||||
}
|
||||
|
||||
bool CPs3NonVirt_IHardwareConfigInternal::ReadPixelsFromFrontBuffer()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::ReadPixelsFromFrontBuffer();
|
||||
}
|
||||
|
||||
bool CPs3NonVirt_IHardwareConfigInternal::PreferDynamicTextures()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::PreferDynamicTextures();
|
||||
}
|
||||
|
||||
bool CPs3NonVirt_IHardwareConfigInternal::NeedsAAClamp()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::NeedsAAClamp();
|
||||
}
|
||||
|
||||
bool CPs3NonVirt_IHardwareConfigInternal::SpecifiesFogColorInLinearSpace()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::SpecifiesFogColorInLinearSpace();
|
||||
}
|
||||
|
||||
int CPs3NonVirt_IHardwareConfigInternal::GetVertexSamplerCount()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::GetVertexSamplerCount();
|
||||
}
|
||||
|
||||
int CPs3NonVirt_IHardwareConfigInternal::GetMaxVertexTextureDimension()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::GetMaxVertexTextureDimension();
|
||||
}
|
||||
|
||||
int CPs3NonVirt_IHardwareConfigInternal::MaxTextureDepth()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::MaxTextureDepth();
|
||||
}
|
||||
|
||||
bool CPs3NonVirt_IHardwareConfigInternal::SupportsStreamOffset()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::SupportsStreamOffset();
|
||||
}
|
||||
|
||||
int CPs3NonVirt_IHardwareConfigInternal::StencilBufferBits()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::StencilBufferBits();
|
||||
}
|
||||
|
||||
int CPs3NonVirt_IHardwareConfigInternal::MaxViewports()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::MaxViewports();
|
||||
}
|
||||
|
||||
void CPs3NonVirt_IHardwareConfigInternal::OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport )
|
||||
{
|
||||
g_pHardwareConfig->CHardwareConfig::OverrideStreamOffsetSupport(bOverrideEnabled,bEnableSupport);
|
||||
}
|
||||
|
||||
int CPs3NonVirt_IHardwareConfigInternal::MaxHWMorphBatchCount()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::MaxHWMorphBatchCount();
|
||||
}
|
||||
|
||||
float CPs3NonVirt_IHardwareConfigInternal::GetShadowDepthBias()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::GetShadowDepthBias();
|
||||
}
|
||||
|
||||
float CPs3NonVirt_IHardwareConfigInternal::GetShadowSlopeScaleDepthBias()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::GetShadowSlopeScaleDepthBias();
|
||||
}
|
||||
|
||||
bool CPs3NonVirt_IHardwareConfigInternal::PreferZPrepass()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::PreferZPrepass();
|
||||
}
|
||||
|
||||
bool CPs3NonVirt_IHardwareConfigInternal::SuppressPixelShaderCentroidHackFixup()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::SuppressPixelShaderCentroidHackFixup();
|
||||
}
|
||||
|
||||
bool CPs3NonVirt_IHardwareConfigInternal::PreferTexturesInHWMemory()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::PreferTexturesInHWMemory();
|
||||
}
|
||||
|
||||
bool CPs3NonVirt_IHardwareConfigInternal::PreferHardwareSync()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::PreferHardwareSync();
|
||||
}
|
||||
|
||||
bool CPs3NonVirt_IHardwareConfigInternal::SupportsShadowDepthTextures()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::SupportsShadowDepthTextures();
|
||||
}
|
||||
|
||||
ImageFormat CPs3NonVirt_IHardwareConfigInternal::GetShadowDepthTextureFormat()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::GetShadowDepthTextureFormat();
|
||||
}
|
||||
|
||||
ImageFormat CPs3NonVirt_IHardwareConfigInternal::GetHighPrecisionShadowDepthTextureFormat()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::GetHighPrecisionShadowDepthTextureFormat();
|
||||
}
|
||||
|
||||
ImageFormat CPs3NonVirt_IHardwareConfigInternal::GetNullTextureFormat()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::GetNullTextureFormat();
|
||||
}
|
||||
|
||||
float CPs3NonVirt_IHardwareConfigInternal::GetLightMapScaleFactor()
|
||||
{
|
||||
return g_pHardwareConfig->CHardwareConfig::GetLightMapScaleFactor();
|
||||
}
|
||||
358
materialsystem/shaderapidx9/hl2stereo.h
Normal file
358
materialsystem/shaderapidx9/hl2stereo.h
Normal file
@@ -0,0 +1,358 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: hl2stereo.h
|
||||
// Authors: John McDonald
|
||||
// Email: devsupport@nvidia.com
|
||||
//
|
||||
// Utility classes for stereo
|
||||
//
|
||||
// Copyright (c) 2009 NVIDIA Corporation. All rights reserved.
|
||||
//
|
||||
// NOTE: This file is provided as-is, with no warranty either expressed or implied.
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __HL2STEREO__
|
||||
#define __HL2STEREO__ 1
|
||||
|
||||
#include "nvapi.h"
|
||||
|
||||
namespace nv
|
||||
{
|
||||
namespace stereo
|
||||
{
|
||||
typedef struct _Nv_Stereo_Image_Header
|
||||
{
|
||||
unsigned int dwSignature;
|
||||
unsigned int dwWidth;
|
||||
unsigned int dwHeight;
|
||||
unsigned int dwBPP;
|
||||
unsigned int dwFlags;
|
||||
} NVSTEREOIMAGEHEADER, *LPNVSTEREOIMAGEHEADER;
|
||||
|
||||
#define NVSTEREO_IMAGE_SIGNATURE 0x4433564e //NV3D
|
||||
#define NVSTEREO_SWAP_EYES 0x00000001
|
||||
|
||||
inline void PopulateTextureData( float *leftEye, float *rightEye, LPNVSTEREOIMAGEHEADER header, unsigned int width, unsigned int height, unsigned int pixelBytes, float eyeSep, float sep, float conv )
|
||||
{
|
||||
// Normally sep is in [0, 100], and we want the fractional part of 1.
|
||||
float finalSeparation = eyeSep * sep * 0.005f;
|
||||
leftEye[0] = -finalSeparation;
|
||||
leftEye[1] = conv;
|
||||
leftEye[2] = -1.0f;
|
||||
|
||||
rightEye[0] = -leftEye[0];
|
||||
rightEye[1] = leftEye[1];
|
||||
rightEye[2] = -leftEye[2];
|
||||
|
||||
// Fill the header
|
||||
header->dwSignature = NVSTEREO_IMAGE_SIGNATURE;
|
||||
header->dwWidth = width;
|
||||
header->dwHeight = height;
|
||||
header->dwBPP = pixelBytes * 8;
|
||||
header->dwFlags = 0;
|
||||
}
|
||||
|
||||
// This is expensive...may take more than 1ms to return. Only call this once at startup.
|
||||
inline bool IsStereoEnabled()
|
||||
{
|
||||
NvU8 stereoEnabled = 0;
|
||||
if ( NVAPI_OK != NvAPI_Stereo_IsEnabled( &stereoEnabled ) )
|
||||
{
|
||||
// Only try to call initialize once here...doing this just in case their library always returns
|
||||
// one of the other error codes continually.
|
||||
static bool s_bFirstTime = true;
|
||||
if ( s_bFirstTime )
|
||||
{
|
||||
s_bFirstTime = false;
|
||||
NvAPI_Initialize();
|
||||
NvAPI_Stereo_CreateConfigurationProfileRegistryKey( NVAPI_STEREO_DX9_REGISTRY_PROFILE );
|
||||
if ( NVAPI_OK != NvAPI_Stereo_IsEnabled( &stereoEnabled ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return stereoEnabled != 0;
|
||||
}
|
||||
|
||||
#ifndef NO_STEREO_D3D9
|
||||
// The D3D9 "Driver" for stereo updates, encapsulates the logic that is Direct3D9 specific.
|
||||
struct D3D9Type
|
||||
{
|
||||
typedef IDirect3DDevice9 Device;
|
||||
typedef IDirect3DTexture9 Texture;
|
||||
typedef IDirect3DSurface9 StagingResource;
|
||||
|
||||
static const NV_STEREO_REGISTRY_PROFILE_TYPE RegistryProfileType = NVAPI_STEREO_DX9_REGISTRY_PROFILE;
|
||||
|
||||
static const int StereoTexWidth = 8;
|
||||
static const int StereoTexHeight = 1;
|
||||
static const D3DFORMAT StereoTexFormat = D3DFMT_R32F;
|
||||
static const int StereoBytesPerPixel = 4;
|
||||
|
||||
static StagingResource *CreateStagingResource( Device *pDevice, float eyeSep, float sep, float conv )
|
||||
{
|
||||
StagingResource *staging = 0;
|
||||
unsigned int stagingWidth = StereoTexWidth * 2;
|
||||
unsigned int stagingHeight = StereoTexHeight + 1;
|
||||
|
||||
pDevice->CreateOffscreenPlainSurface( stagingWidth, stagingHeight, StereoTexFormat, D3DPOOL_SYSTEMMEM, &staging, NULL );
|
||||
|
||||
if ( !staging )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
D3DLOCKED_RECT lr;
|
||||
staging->LockRect( &lr, NULL, 0 );
|
||||
unsigned char *sysData = ( unsigned char * ) lr.pBits;
|
||||
unsigned int sysMemPitch = stagingWidth * StereoBytesPerPixel;
|
||||
|
||||
float *leftEyePtr = ( float * )sysData;
|
||||
float *rightEyePtr = leftEyePtr + StereoTexWidth;
|
||||
LPNVSTEREOIMAGEHEADER header = ( LPNVSTEREOIMAGEHEADER )( sysData + sysMemPitch );
|
||||
PopulateTextureData( leftEyePtr, rightEyePtr, header, stagingWidth, stagingHeight, StereoBytesPerPixel, eyeSep, sep, conv );
|
||||
staging->UnlockRect();
|
||||
|
||||
return staging;
|
||||
}
|
||||
|
||||
static void UpdateTextureFromStaging( Device *pDevice, Texture *tex, StagingResource *staging )
|
||||
{
|
||||
RECT stereoSrcRect;
|
||||
stereoSrcRect.top = 0;
|
||||
stereoSrcRect.bottom = StereoTexHeight;
|
||||
stereoSrcRect.left = 0;
|
||||
stereoSrcRect.right = StereoTexWidth;
|
||||
|
||||
POINT stereoDstPoint;
|
||||
stereoDstPoint.x = 0;
|
||||
stereoDstPoint.y = 0;
|
||||
|
||||
IDirect3DSurface9 *texSurface;
|
||||
tex->GetSurfaceLevel( 0, &texSurface );
|
||||
|
||||
pDevice->UpdateSurface( staging, &stereoSrcRect, texSurface, &stereoDstPoint );
|
||||
texSurface->Release();
|
||||
}
|
||||
};
|
||||
#endif // NO_STEREO_D3D9
|
||||
|
||||
#ifndef NO_STEREO_D3D10
|
||||
// The D3D10 "Driver" for stereo updates, encapsulates the logic that is Direct3D10 specific.
|
||||
struct D3D10Type
|
||||
{
|
||||
typedef ID3D10Device Device;
|
||||
typedef ID3D10Texture2D Texture;
|
||||
typedef ID3D10Texture2D StagingResource;
|
||||
|
||||
static const NV_STEREO_REGISTRY_PROFILE_TYPE RegistryProfileType = NVAPI_STEREO_DX10_REGISTRY_PROFILE;
|
||||
|
||||
static const int StereoTexWidth = 8;
|
||||
static const int StereoTexHeight = 1;
|
||||
static const DXGI_FORMAT StereoTexFormat = DXGI_FORMAT_R32_FLOAT;
|
||||
static const int StereoBytesPerPixel = 4;
|
||||
|
||||
static StagingResource *CreateStagingResource( Device *pDevice, float eyeSep, float sep, float conv )
|
||||
{
|
||||
StagingResource *staging = 0;
|
||||
unsigned int stagingWidth = StereoTexWidth * 2;
|
||||
unsigned int stagingHeight = StereoTexHeight + 1;
|
||||
|
||||
// Allocate the buffer sys mem data to write the stereo tag and stereo params
|
||||
D3D10_SUBRESOURCE_DATA sysData;
|
||||
sysData.SysMemPitch = StereoBytesPerPixel * stagingWidth;
|
||||
sysData.pSysMem = new unsigned char[sysData.SysMemPitch * stagingHeight];
|
||||
|
||||
float *leftEyePtr = ( float * )sysData.pSysMem;
|
||||
float *rightEyePtr = leftEyePtr + StereoTexWidth;
|
||||
LPNVSTEREOIMAGEHEADER header = ( LPNVSTEREOIMAGEHEADER )( ( unsigned char * )sysData.pSysMem + sysData.SysMemPitch );
|
||||
PopulateTextureData( leftEyePtr, rightEyePtr, header, stagingWidth, stagingHeight, StereoBytesPerPixel, eyeSep, sep, conv );
|
||||
|
||||
D3D10_TEXTURE2D_DESC desc;
|
||||
memset( &desc, 0, sizeof( D3D10_TEXTURE2D_DESC ) );
|
||||
desc.Width = stagingWidth;
|
||||
desc.Height = stagingHeight;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = StereoTexFormat;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Usage = D3D10_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
pDevice->CreateTexture2D( &desc, &sysData, &staging );
|
||||
delete [] sysData.pSysMem;
|
||||
return staging;
|
||||
}
|
||||
|
||||
static void UpdateTextureFromStaging( Device *pDevice, Texture *tex, StagingResource *staging )
|
||||
{
|
||||
D3D10_BOX stereoSrcBox;
|
||||
stereoSrcBox.front = 0;
|
||||
stereoSrcBox.back = 1;
|
||||
stereoSrcBox.top = 0;
|
||||
stereoSrcBox.bottom = StereoTexHeight;
|
||||
stereoSrcBox.left = 0;
|
||||
stereoSrcBox.right = StereoTexWidth;
|
||||
|
||||
pDevice->CopySubresourceRegion( tex, 0, 0, 0, 0, staging, 0, &stereoSrcBox );
|
||||
}
|
||||
};
|
||||
#endif // NO_STEREO_D3D10
|
||||
|
||||
// The HL2 Stereo class, which can work for either D3D9 or D3D10, depending on which type it's specialized for
|
||||
// Note that both types can live side-by-side in two seperate instances as well.
|
||||
// Also note that there are convenient typedefs below the class definition.
|
||||
template < class D3DType >
|
||||
class HL2Stereo
|
||||
{
|
||||
public:
|
||||
typedef typename D3DType Parms;
|
||||
typedef typename D3DType::Device Device;
|
||||
typedef typename D3DType::Texture Texture;
|
||||
typedef typename D3DType::StagingResource StagingResource;
|
||||
|
||||
HL2Stereo() :
|
||||
mEyeSeparation( 0 ),
|
||||
mSeparation( 0 ),
|
||||
mConvergence( 0 ),
|
||||
mStereoHandle( 0 ),
|
||||
mInitialized( false ),
|
||||
mActive( false ),
|
||||
mDeviceLost( true ) // mDeviceLost is set to true to initialize the texture with good data at app startup.
|
||||
{
|
||||
NvAPI_Initialize();
|
||||
NvAPI_Stereo_CreateConfigurationProfileRegistryKey( D3DType::RegistryProfileType );
|
||||
}
|
||||
|
||||
~HL2Stereo()
|
||||
{
|
||||
if ( mStereoHandle )
|
||||
{
|
||||
NvAPI_Stereo_DestroyHandle( mStereoHandle );
|
||||
mStereoHandle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Init( Device *dev )
|
||||
{
|
||||
NvAPI_Stereo_CreateHandleFromIUnknown( dev, &mStereoHandle );
|
||||
|
||||
// Set that we've initialized regardless --we'll only try to init once.
|
||||
mInitialized = true;
|
||||
}
|
||||
|
||||
// Not const because we will update the various values if an update is needed.
|
||||
bool RequiresUpdate( bool deviceLost )
|
||||
{
|
||||
bool active = IsStereoActive();
|
||||
bool updateRequired;
|
||||
float eyeSep, sep, conv;
|
||||
if ( active )
|
||||
{
|
||||
if ( NVAPI_OK != NvAPI_Stereo_GetEyeSeparation( mStereoHandle, &eyeSep ) )
|
||||
return false;
|
||||
if ( NVAPI_OK != NvAPI_Stereo_GetSeparation( mStereoHandle, &sep ) )
|
||||
return false;
|
||||
if ( NVAPI_OK != NvAPI_Stereo_GetConvergence( mStereoHandle, &conv ) )
|
||||
return false;
|
||||
|
||||
// clamp the convergence to prevent wallhack exploit
|
||||
if ( conv > 31.0f )
|
||||
{
|
||||
conv = 31.0f;
|
||||
NvAPI_Stereo_SetConvergence( mStereoHandle, conv );
|
||||
DevMsg( "[NVIDIA Stereo 3D] Clamping convergence: %.2f\n", conv);
|
||||
}
|
||||
|
||||
updateRequired = ( eyeSep != mEyeSeparation )
|
||||
|| ( sep != mSeparation )
|
||||
|| ( conv != mConvergence )
|
||||
|| ( active != mActive );
|
||||
}
|
||||
else
|
||||
{
|
||||
eyeSep = sep = conv = 0;
|
||||
updateRequired = active != mActive;
|
||||
}
|
||||
|
||||
// If the device was lost and is now restored, need to update the texture contents again.
|
||||
updateRequired = updateRequired || ( !deviceLost && mDeviceLost );
|
||||
mDeviceLost = deviceLost;
|
||||
|
||||
if ( updateRequired )
|
||||
{
|
||||
//Msg( "*** NV_STEREO - UpdateRequired == true\n" );
|
||||
mEyeSeparation = eyeSep;
|
||||
mSeparation = sep;
|
||||
mConvergence = conv;
|
||||
mActive = active;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsStereoActive() const
|
||||
{
|
||||
NvU8 stereoActive = 0;
|
||||
if ( NVAPI_OK != NvAPI_Stereo_IsActivated( mStereoHandle, &stereoActive ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return stereoActive != 0;
|
||||
}
|
||||
|
||||
void UpdateStereoTexture( Device *dev, Texture *tex, bool deviceLost )
|
||||
{
|
||||
if ( !mInitialized )
|
||||
{
|
||||
Init( dev );
|
||||
}
|
||||
|
||||
if ( !RequiresUpdate( deviceLost ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DevMsg( "[NVIDIA Stereo 3D] UpdateStereoTexture: EyeSep: %.2f, Sep: %.2f, Conv: %.2f\n", mEyeSeparation, mSeparation, mConvergence);
|
||||
|
||||
StagingResource *staging = D3DType::CreateStagingResource( dev, mEyeSeparation, mSeparation, mConvergence );
|
||||
if ( staging )
|
||||
{
|
||||
D3DType::UpdateTextureFromStaging( dev, tex, staging );
|
||||
staging->Release();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
float mEyeSeparation;
|
||||
float mSeparation;
|
||||
float mConvergence;
|
||||
|
||||
StereoHandle mStereoHandle;
|
||||
bool mInitialized;
|
||||
bool mActive;
|
||||
bool mDeviceLost;
|
||||
};
|
||||
|
||||
#ifndef NO_STEREO_D3D9
|
||||
typedef HL2Stereo< D3D9Type > HL2StereoD3D9;
|
||||
#endif
|
||||
|
||||
#ifndef NO_STEREO_D3D10
|
||||
typedef HL2Stereo< D3D10Type > HL2StereoD3D10;
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* __HL2STEREO__ */
|
||||
110
materialsystem/shaderapidx9/imeshdx8.h
Normal file
110
materialsystem/shaderapidx9/imeshdx8.h
Normal file
@@ -0,0 +1,110 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef IMESHDX8_H
|
||||
#define IMESHDX8_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "meshbase.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
|
||||
|
||||
abstract_class IMeshMgr
|
||||
{
|
||||
public:
|
||||
// Initialize, shutdown
|
||||
virtual void Init() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
// Task switch...
|
||||
virtual void ReleaseBuffers() = 0;
|
||||
virtual void RestoreBuffers() = 0;
|
||||
|
||||
// Releases all dynamic vertex buffers
|
||||
virtual void DestroyVertexBuffers() = 0;
|
||||
|
||||
// Discards the dynamic vertex and index buffer
|
||||
virtual void DiscardVertexBuffers() = 0;
|
||||
|
||||
// Creates, destroys static meshes
|
||||
virtual IMesh* CreateStaticMesh( VertexFormat_t vertexFormat, const char *pTextureBudgetGroup, IMaterial *pMaterial = NULL, VertexStreamSpec_t *pStreamSpec = NULL ) = 0;
|
||||
virtual void DestroyStaticMesh( IMesh* pMesh ) = 0;
|
||||
|
||||
// Gets at the dynamic mesh
|
||||
virtual IMesh* GetDynamicMesh( IMaterial* pMaterial, VertexFormat_t vertexFormat, int nHWSkinBoneCount, bool buffered = true,
|
||||
IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0) = 0;
|
||||
|
||||
|
||||
// ------------ New Vertex/Index Buffer interface ----------------------------
|
||||
// Do we need support for bForceTempMesh and bSoftwareVertexShader?
|
||||
// I don't think we use bSoftwareVertexShader anymore. .need to look into bForceTempMesh.
|
||||
virtual IVertexBuffer *CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup ) = 0;
|
||||
virtual IIndexBuffer *CreateIndexBuffer( ShaderBufferType_t indexBufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup ) = 0;
|
||||
virtual void DestroyVertexBuffer( IVertexBuffer * ) = 0;
|
||||
virtual void DestroyIndexBuffer( IIndexBuffer * ) = 0;
|
||||
// Do we need to specify the stream here in the case of locking multiple dynamic VBs on different streams?
|
||||
virtual IVertexBuffer *GetDynamicVertexBuffer( int streamID, VertexFormat_t vertexFormat, bool bBuffered = true ) = 0;
|
||||
virtual IIndexBuffer *GetDynamicIndexBuffer( ) = 0;
|
||||
virtual void BindVertexBuffer( int streamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 ) = 0;
|
||||
virtual void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes ) = 0;
|
||||
virtual void Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount ) = 0;
|
||||
// ------------ End ----------------------------
|
||||
virtual VertexFormat_t GetCurrentVertexFormat( void ) const = 0;
|
||||
virtual void RenderPassWithVertexAndIndexBuffers( const unsigned char *pInstanceCommandBuffer ) = 0;
|
||||
virtual void DrawInstancedPrims( const unsigned char *pInstanceCommandBuffer ) = 0;
|
||||
|
||||
// Computes the vertex format
|
||||
virtual VertexFormat_t ComputeVertexFormat( unsigned int flags,
|
||||
int numTexCoords, int* pTexCoordDimensions, int numBoneWeights,
|
||||
int userDataSize ) const = 0;
|
||||
|
||||
// Returns the number of buffers...
|
||||
virtual int BufferCount() const = 0;
|
||||
|
||||
// Use fat vertices (for tools)
|
||||
virtual void UseFatVertices( bool bUseFat ) = 0;
|
||||
|
||||
// Returns the number of vertices + indices we can render using the dynamic mesh
|
||||
// Passing true in the second parameter will return the max # of vertices + indices
|
||||
// we can use before a flush is provoked and may return different values
|
||||
// if called multiple times in succession.
|
||||
// Passing false into the second parameter will return
|
||||
// the maximum possible vertices + indices that can be rendered in a single batch
|
||||
virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices ) = 0;
|
||||
|
||||
// Returns the max number of vertices we can render for a given material
|
||||
virtual int GetMaxVerticesToRender( IMaterial *pMaterial ) = 0;
|
||||
virtual int GetMaxIndicesToRender( ) = 0;
|
||||
virtual IMesh *GetFlexMesh() = 0;
|
||||
|
||||
virtual void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc ) const = 0;
|
||||
|
||||
virtual int VertexFormatSize( VertexFormat_t vertexFormat ) const = 0;
|
||||
|
||||
virtual IVertexBuffer *GetDynamicVertexBuffer( IMaterial *pMaterial, bool buffered = true ) = 0;
|
||||
|
||||
virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords ) = 0;
|
||||
|
||||
virtual void DrawInstances( int nInstanceCount, const MeshInstanceData_t *pInstances ) = 0;
|
||||
|
||||
#ifdef _GAMECONSOLE
|
||||
virtual int GetDynamicIndexBufferAllocationCount() = 0;
|
||||
virtual int GetDynamicIndexBufferIndicesLeft() = 0;
|
||||
|
||||
// Backdoor used by the queued context to directly use write-combined memory
|
||||
virtual IMesh *GetExternalMesh( const ExternalMeshInfo_t& info ) = 0;
|
||||
virtual void SetExternalMeshData( IMesh *pMesh, const ExternalMeshData_t &data ) = 0;
|
||||
virtual IIndexBuffer *GetExternalIndexBuffer( int nIndexCount, uint16 *pIndexData ) = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // IMESHDX8_H
|
||||
214
materialsystem/shaderapidx9/inputlayoutdx10.cpp
Normal file
214
materialsystem/shaderapidx9/inputlayoutdx10.cpp
Normal file
@@ -0,0 +1,214 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include <d3d10.h>
|
||||
#undef GetCommandLine
|
||||
|
||||
#include "inputlayoutdx10.h"
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "shaderdevicedx10.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Standard input layouts
|
||||
//-----------------------------------------------------------------------------
|
||||
static const DXGI_FORMAT s_pSizeLookup[] =
|
||||
{
|
||||
DXGI_FORMAT_UNKNOWN, // Should be unused...
|
||||
DXGI_FORMAT_R32_FLOAT, // D3DDECLTYPE_FLOAT1
|
||||
DXGI_FORMAT_R32G32_FLOAT, // D3DDECLTYPE_FLOAT2,
|
||||
DXGI_FORMAT_R32G32B32_FLOAT, // D3DDECLTYPE_FLOAT3,
|
||||
DXGI_FORMAT_R32G32B32A32_FLOAT, // D3DDECLTYPE_FLOAT4
|
||||
};
|
||||
|
||||
struct FieldInfo_t
|
||||
{
|
||||
const char *m_pSemanticString;
|
||||
unsigned int m_nSemanticIndex;
|
||||
uint64 m_nFormatMask;
|
||||
int m_nFieldSize;
|
||||
};
|
||||
|
||||
static FieldInfo_t s_pFieldInfo[] =
|
||||
{
|
||||
{ "POSITION", 0, VERTEX_POSITION, sizeof( float ) * 3 },
|
||||
{ "BLENDWEIGHT", 0, VERTEX_BONE_WEIGHT_MASK, 0 },
|
||||
{ "BLENDINDICES", 0, VERTEX_BONE_INDEX, 4 },
|
||||
{ "NORMAL", 0, VERTEX_NORMAL, sizeof( float ) * 3 },
|
||||
{ "COLOR", 0, VERTEX_COLOR, 4 },
|
||||
{ "SPECULAR", 0, VERTEX_SPECULAR, 4 },
|
||||
{ "TEXCOORD", 0, VERTEX_TEXCOORD_MASK(0), 0 },
|
||||
{ "TEXCOORD", 1, VERTEX_TEXCOORD_MASK(1), 0 },
|
||||
{ "TEXCOORD", 2, VERTEX_TEXCOORD_MASK(2), 0 },
|
||||
{ "TEXCOORD", 3, VERTEX_TEXCOORD_MASK(3), 0 },
|
||||
{ "TEXCOORD", 4, VERTEX_TEXCOORD_MASK(4), 0 },
|
||||
{ "TEXCOORD", 5, VERTEX_TEXCOORD_MASK(5), 0 },
|
||||
{ "TEXCOORD", 6, VERTEX_TEXCOORD_MASK(6), 0 },
|
||||
{ "TEXCOORD", 7, VERTEX_TEXCOORD_MASK(7), 0 },
|
||||
{ "TANGENT", 0, VERTEX_TANGENT_S, sizeof( float ) * 3 },
|
||||
{ "BINORMAL", 0, VERTEX_TANGENT_T, sizeof( float ) * 3 },
|
||||
{ "USERDATA", 0, USER_DATA_SIZE_MASK, 0 },
|
||||
{ NULL, 0, 0 },
|
||||
};
|
||||
|
||||
static D3D10_INPUT_ELEMENT_DESC s_pVertexDesc[] =
|
||||
{
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "BLENDWEIGHT", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "BLENDINDICES", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "SPECULAR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 1, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 2, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 3, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 4, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 5, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 6, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 7, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "BINORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "USERDATA", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
|
||||
static D3D10_INPUT_ELEMENT_DESC s_pFallbackVertexDesc[] =
|
||||
{
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 15, 0, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "BLENDWEIGHT", 0, DXGI_FORMAT_R32G32_FLOAT, 15, 12, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "BLENDINDICES", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 15, 20, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 15, 24, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 15, 36, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "SPECULAR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 15, 40, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 15, 44, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT, 15, 52, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 2, DXGI_FORMAT_R32G32_FLOAT, 15, 60, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 3, DXGI_FORMAT_R32G32_FLOAT, 15, 68, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 4, DXGI_FORMAT_R32G32_FLOAT, 15, 76, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 5, DXGI_FORMAT_R32G32_FLOAT, 15, 84, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 6, DXGI_FORMAT_R32G32_FLOAT, 15, 92, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TEXCOORD", 7, DXGI_FORMAT_R32G32_FLOAT, 15, 100, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 15, 108, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "BINORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 15, 120, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
{ "USERDATA", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 15, 132, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX },
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Computes the required input desc based on the vertex format
|
||||
//-----------------------------------------------------------------------------
|
||||
static void PrintInputDesc( int nCount, const D3D10_INPUT_ELEMENT_DESC *pDecl )
|
||||
{
|
||||
for ( int i = 0; i < nCount; i++ )
|
||||
{
|
||||
Msg( "%s (%d): Stream: %d, Offset: %d, Instanced? %c\n",
|
||||
pDecl[i].SemanticName,
|
||||
pDecl[i].SemanticIndex,
|
||||
( int )pDecl[i].InputSlot,
|
||||
( int )pDecl[i].AlignedByteOffset,
|
||||
pDecl[i].InputSlotClass == D3D10_INPUT_PER_VERTEX_DATA ? 'n' : 'y'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Checks to see if a shader requires a particular field
|
||||
//-----------------------------------------------------------------------------
|
||||
static bool CheckShaderSignatureExpectations( ID3D10ShaderReflection* pReflection, const char* pSemantic, unsigned int nSemanticIndex )
|
||||
{
|
||||
D3D10_SHADER_DESC shaderDesc;
|
||||
D3D10_SIGNATURE_PARAMETER_DESC paramDesc;
|
||||
|
||||
Assert( pSemantic );
|
||||
Assert( pReflection );
|
||||
|
||||
pReflection->GetDesc( &shaderDesc );
|
||||
|
||||
for ( unsigned int k=0; k < shaderDesc.InputParameters; k++ )
|
||||
{
|
||||
pReflection->GetInputParameterDesc( k, ¶mDesc );
|
||||
if ( ( nSemanticIndex == paramDesc.SemanticIndex ) && !Q_stricmp( pSemantic, paramDesc.SemanticName ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Computes the required input desc based on the vertex format
|
||||
//-----------------------------------------------------------------------------
|
||||
static unsigned int ComputeInputDesc( VertexFormat_t fmt, D3D10_INPUT_ELEMENT_DESC *pDecl, ID3D10ShaderReflection* pReflection )
|
||||
{
|
||||
unsigned int nCount = 0;
|
||||
int nOffset = 0;
|
||||
|
||||
// Fix up the global table so we don't need special-case code
|
||||
int nBoneCount = NumBoneWeights( fmt );
|
||||
s_pFieldInfo[1].m_nFieldSize = sizeof( float ) * nBoneCount;
|
||||
s_pVertexDesc[1].Format = s_pSizeLookup[ nBoneCount ];
|
||||
|
||||
int nUserDataSize = UserDataSize( fmt );
|
||||
s_pFieldInfo[16].m_nFieldSize = sizeof( float ) * nUserDataSize;
|
||||
s_pVertexDesc[16].Format = s_pSizeLookup[ nUserDataSize ];
|
||||
|
||||
// NOTE: Fix s_pFieldInfo, s_pVertexDesc, s_pFallbackVertexDesc if you add more fields
|
||||
// As well as the fallback stream (stream #15)
|
||||
COMPILE_TIME_ASSERT( VERTEX_MAX_TEXTURE_COORDINATES == 8 );
|
||||
for ( int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i )
|
||||
{
|
||||
int nTexCoordCount = TexCoordSize( i, fmt );
|
||||
s_pFieldInfo[6+i].m_nFieldSize = sizeof( float ) * nTexCoordCount;
|
||||
s_pVertexDesc[6+i].Format = s_pSizeLookup[ nTexCoordCount ];
|
||||
}
|
||||
|
||||
// FIXME: Change this loop so CheckShaderSignatureExpectations is called once!
|
||||
for ( int i = 0; s_pFieldInfo[i].m_pSemanticString; ++i )
|
||||
{
|
||||
if ( fmt & s_pFieldInfo[i].m_nFormatMask )
|
||||
{
|
||||
memcpy( &pDecl[nCount], &s_pVertexDesc[i], sizeof(D3D10_INPUT_ELEMENT_DESC) );
|
||||
pDecl[nCount].AlignedByteOffset = nOffset;
|
||||
nOffset += s_pFieldInfo[i].m_nFieldSize;
|
||||
++nCount;
|
||||
}
|
||||
else if ( CheckShaderSignatureExpectations( pReflection, s_pFieldInfo[i].m_pSemanticString, s_pFieldInfo[i].m_nSemanticIndex ) )
|
||||
{
|
||||
memcpy( &pDecl[nCount], &s_pFallbackVertexDesc[i], sizeof(D3D10_INPUT_ELEMENT_DESC) );
|
||||
++nCount;
|
||||
}
|
||||
}
|
||||
|
||||
// For debugging only...
|
||||
// PrintInputDesc( nCount, pDecl );
|
||||
|
||||
return nCount;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the input layout associated with a vertex format
|
||||
//-----------------------------------------------------------------------------
|
||||
ID3D10InputLayout *CreateInputLayout( VertexFormat_t fmt, ID3D10ShaderReflection* pReflection, const void *pByteCode, size_t nByteCodeLen )
|
||||
{
|
||||
D3D10_INPUT_ELEMENT_DESC pDecl[32];
|
||||
unsigned int nDeclCount = ComputeInputDesc( fmt, pDecl, pReflection );
|
||||
|
||||
ID3D10InputLayout *pInputLayout;
|
||||
HRESULT hr = D3D10Device()->CreateInputLayout( pDecl, nDeclCount, pByteCode, nByteCodeLen, &pInputLayout );
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
Warning( "CreateInputLayout::Unable to create input layout for format %X!\n", fmt );
|
||||
return NULL;
|
||||
}
|
||||
return pInputLayout;
|
||||
}
|
||||
35
materialsystem/shaderapidx9/inputlayoutdx10.h
Normal file
35
materialsystem/shaderapidx9/inputlayoutdx10.h
Normal file
@@ -0,0 +1,35 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef INPUTLAYOUTDX10_H
|
||||
#define INPUTLAYOUTDX10_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "materialsystem/IMaterial.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declaration
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ID3D10InputLayout;
|
||||
struct ID3D10ShaderReflection;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the input layout associated with a vertex format
|
||||
// FIXME: Note that we'll need to change this from a VertexFormat_t
|
||||
//-----------------------------------------------------------------------------
|
||||
ID3D10InputLayout *CreateInputLayout( VertexFormat_t fmt,
|
||||
ID3D10ShaderReflection* pReflection, const void *pByteCode, size_t nByteCodeLen );
|
||||
|
||||
|
||||
#endif // INPUTLAYOUTDX10_H
|
||||
|
||||
34
materialsystem/shaderapidx9/ivertexbufferdx8.h
Normal file
34
materialsystem/shaderapidx9/ivertexbufferdx8.h
Normal file
@@ -0,0 +1,34 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef IVERTEXBUFFERDX8_H
|
||||
#define IVERTEXBUFFERDX8_H
|
||||
#pragma once
|
||||
|
||||
#include "IVertexBuffer.h"
|
||||
|
||||
abstract_class IVertexBufferDX8 : public IVertexBuffer
|
||||
{
|
||||
public:
|
||||
// TEMPORARY!
|
||||
virtual int Begin( int flags, int numVerts ) = 0;
|
||||
|
||||
// Sets up the renderstate
|
||||
virtual void SetRenderState( int stream ) = 0;
|
||||
|
||||
// Gets FVF info
|
||||
virtual void ComputeFVFInfo( int flags, int& fvf, int& size ) const = 0;
|
||||
|
||||
// Cleans up the vertex buffers
|
||||
virtual void CleanUp() = 0;
|
||||
|
||||
// Flushes the vertex buffers
|
||||
virtual void Flush() = 0;
|
||||
};
|
||||
|
||||
#endif // IVERTEXBUFFERDX8_H
|
||||
194
materialsystem/shaderapidx9/locald3dtypes.h
Normal file
194
materialsystem/shaderapidx9/locald3dtypes.h
Normal file
@@ -0,0 +1,194 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef LOCALD3DTYPES_H
|
||||
#define LOCALD3DTYPES_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier0/platform.h"
|
||||
|
||||
#if defined( DX10 ) && !defined( DX_TO_GL_ABSTRACTION )
|
||||
|
||||
#include <d3d10.h>
|
||||
#include <d3dx10.h>
|
||||
|
||||
struct IDirect3D10BaseTexture
|
||||
{
|
||||
ID3D10Resource *m_pBaseTexture;
|
||||
ID3D10ShaderResourceView *m_pSRView;
|
||||
ID3D10RenderTargetView *m_pRTView;
|
||||
};
|
||||
|
||||
class CDx10Types
|
||||
{
|
||||
public:
|
||||
typedef struct IDirect3D10BaseTexture IDirect3DTexture;
|
||||
// FIXME: What is this called now ?
|
||||
// typedef ID3D10TextureCube IDirect3DCubeTexture;
|
||||
typedef ID3D10Texture3D IDirect3DVolumeTexture;
|
||||
typedef ID3D10Device IDirect3DDevice;
|
||||
typedef D3D10_VIEWPORT D3DVIEWPORT;
|
||||
typedef ID3D10Buffer IDirect3DIndexBuffer;
|
||||
typedef ID3D10Buffer IDirect3DVertexBuffer;
|
||||
typedef ID3D10VertexShader IDirect3DVertexShader;
|
||||
typedef ID3D10PixelShader IDirect3DPixelShader;
|
||||
typedef ID3D10ShaderResourceView IDirect3DSurface;
|
||||
typedef ID3DX10Font ID3DXFont;
|
||||
typedef ID3D10Query ID3DQuery;
|
||||
|
||||
typedef ID3D10Device *LPDIRECT3DDEVICE;
|
||||
typedef ID3D10Buffer *LPDIRECT3DINDEXBUFFER;
|
||||
typedef ID3D10Buffer *LPDIRECT3DVERTEXBUFFER;
|
||||
};
|
||||
|
||||
#endif // defined( DX10 ) && !defined( POSIX )
|
||||
|
||||
|
||||
#if !defined( _X360 ) && !defined( DX_TO_GL_ABSTRACTION )
|
||||
#ifdef _DEBUG
|
||||
#define D3D_DEBUG_INFO 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct IDirect3DTexture9;
|
||||
struct IDirect3DBaseTexture9;
|
||||
struct IDirect3DCubeTexture9;
|
||||
struct IDirect3D9;
|
||||
struct IDirect3DDevice9;
|
||||
struct IDirect3DSurface9;
|
||||
struct IDirect3DIndexBuffer9;
|
||||
struct IDirect3DVertexBuffer9;
|
||||
struct IDirect3DVertexShader9;
|
||||
struct IDirect3DPixelShader9;
|
||||
struct IDirect3DVolumeTexture9;
|
||||
|
||||
typedef struct _D3DLIGHT9 D3DLIGHT9;
|
||||
typedef struct _D3DADAPTER_IDENTIFIER9 D3DADAPTER_IDENTIFIER9;
|
||||
typedef struct _D3DCAPS9 D3DCAPS9;
|
||||
typedef struct _D3DVIEWPORT9 D3DVIEWPORT9;
|
||||
typedef struct _D3DMATERIAL9 D3DMATERIAL9;
|
||||
typedef IDirect3DTexture9 IDirect3DTexture;
|
||||
typedef IDirect3DBaseTexture9 IDirect3DBaseTexture;
|
||||
typedef IDirect3DCubeTexture9 IDirect3DCubeTexture;
|
||||
typedef IDirect3DVolumeTexture9 IDirect3DVolumeTexture;
|
||||
typedef IDirect3DDevice9 IDirect3DDevice;
|
||||
typedef D3DMATERIAL9 D3DMATERIAL;
|
||||
typedef D3DLIGHT9 D3DLIGHT;
|
||||
typedef IDirect3DSurface9 IDirect3DSurface;
|
||||
typedef D3DCAPS9 D3DCAPS;
|
||||
typedef IDirect3DIndexBuffer9 IDirect3DIndexBuffer;
|
||||
typedef IDirect3DVertexBuffer9 IDirect3DVertexBuffer;
|
||||
typedef IDirect3DPixelShader9 IDirect3DPixelShader;
|
||||
typedef IDirect3DDevice *LPDIRECT3DDEVICE;
|
||||
typedef IDirect3DIndexBuffer *LPDIRECT3DINDEXBUFFER;
|
||||
typedef IDirect3DVertexBuffer *LPDIRECT3DVERTEXBUFFER;
|
||||
|
||||
class CDx9Types
|
||||
{
|
||||
public:
|
||||
typedef IDirect3DTexture9 IDirect3DTexture;
|
||||
typedef IDirect3DBaseTexture9 IDirect3DBaseTexture;
|
||||
typedef IDirect3DCubeTexture9 IDirect3DCubeTexture;
|
||||
typedef IDirect3DVolumeTexture9 IDirect3DVolumeTexture;
|
||||
typedef IDirect3DDevice9 IDirect3DDevice;
|
||||
typedef D3DMATERIAL9 D3DMATERIAL;
|
||||
typedef D3DLIGHT9 D3DLIGHT;
|
||||
typedef IDirect3DSurface9 IDirect3DSurface;
|
||||
typedef D3DCAPS9 D3DCAPS;
|
||||
typedef IDirect3DIndexBuffer9 IDirect3DIndexBuffer;
|
||||
typedef IDirect3DVertexBuffer9 IDirect3DVertexBuffer;
|
||||
typedef IDirect3DPixelShader9 IDirect3DPixelShader;
|
||||
typedef IDirect3DDevice *LPDIRECT3DDEVICE;
|
||||
typedef IDirect3DIndexBuffer *LPDIRECT3DINDEXBUFFER;
|
||||
typedef IDirect3DVertexBuffer *LPDIRECT3DVERTEXBUFFER;
|
||||
};
|
||||
|
||||
typedef void *HardwareShader_t;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The vertex and pixel shader type
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef intp VertexShader_t;
|
||||
typedef intp PixelShader_t;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Bitpattern for an invalid shader
|
||||
//-----------------------------------------------------------------------------
|
||||
#define INVALID_SHADER ( 0xFFFFFFFF )
|
||||
#define INVALID_HARDWARE_SHADER ( NULL )
|
||||
|
||||
#define D3DSAMP_NOTSUPPORTED D3DSAMP_FORCE_DWORD
|
||||
#define D3DRS_NOTSUPPORTED D3DRS_FORCE_DWORD
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
|
||||
#if defined( _X360 )
|
||||
|
||||
// not supported, keeping for port ease
|
||||
#define D3DSAMP_SRGBTEXTURE D3DSAMP_NOTSUPPORTED
|
||||
#define D3DRS_LIGHTING D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_DIFFUSEMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SPECULARENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SHADEMODE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_LASTPIXEL D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_DITHERENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGCOLOR D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGTABLEMODE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGSTART D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGEND D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGDENSITY D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_RANGEFOGENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_TEXTUREFACTOR D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_CLIPPING D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_AMBIENT D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_FOGVERTEXMODE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_COLORVERTEX D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_LOCALVIEWER D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_NORMALIZENORMALS D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SPECULARMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_AMBIENTMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_EMISSIVEMATERIALSOURCE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_VERTEXBLEND D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALEENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALE_A D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALE_B D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POINTSCALE_C D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_PATCHEDGESTYLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_DEBUGMONITORTOKEN D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_INDEXEDVERTEXBLENDENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_TWEENFACTOR D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_POSITIONDEGREE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_NORMALDEGREE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ANTIALIASEDLINEENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_X D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_Y D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_Z D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ADAPTIVETESS_W D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_ENABLEADAPTIVETESSELLATION D3DRS_NOTSUPPORTED
|
||||
#define D3DRS_SRGBWRITEENABLE D3DRS_NOTSUPPORTED
|
||||
#define D3DLOCK_DISCARD 0
|
||||
#define D3DUSAGE_DYNAMIC 0
|
||||
#define D3DUSAGE_AUTOGENMIPMAP 0
|
||||
#define D3DDEVTYPE_REF D3DDEVTYPE_HAL
|
||||
#define D3DENUM_WHQL_LEVEL 0
|
||||
#define D3DCREATE_SOFTWARE_VERTEXPROCESSING D3DCREATE_HARDWARE_VERTEXPROCESSING
|
||||
#define D3DDMT_ENABLE 0
|
||||
|
||||
typedef enum D3DSHADEMODE
|
||||
{
|
||||
D3DSHADE_FLAT = 0,
|
||||
D3DSHADE_GOURAUD = 0,
|
||||
D3DSHADE_NONE = -1
|
||||
};
|
||||
|
||||
#endif // _X360
|
||||
|
||||
#endif // LOCALD3DTYPES_H
|
||||
413
materialsystem/shaderapidx9/meshbase.cpp
Normal file
413
materialsystem/shaderapidx9/meshbase.cpp
Normal file
@@ -0,0 +1,413 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "meshbase.h"
|
||||
#include "shaderapi_global.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helpers with VertexDesc_t...
|
||||
//-----------------------------------------------------------------------------
|
||||
// FIXME: add compression-agnostic read-accessors (which decompress and return by value, checking desc.m_CompressionType)
|
||||
inline Vector &Position( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
return *(Vector*)((unsigned char*)desc.m_pPosition + vert * desc.m_VertexSize_Position );
|
||||
}
|
||||
|
||||
inline float Wrinkle( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
return *(float*)((unsigned char*)desc.m_pWrinkle + vert * desc.m_VertexSize_Wrinkle );
|
||||
}
|
||||
|
||||
inline float *BoneWeight( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
Assert( desc.m_CompressionType == VERTEX_COMPRESSION_NONE );
|
||||
return (float*)((unsigned char*)desc.m_pBoneWeight + vert * desc.m_VertexSize_BoneWeight );
|
||||
}
|
||||
|
||||
inline unsigned char *BoneIndex( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
return desc.m_pBoneMatrixIndex + vert * desc.m_VertexSize_BoneMatrixIndex;
|
||||
}
|
||||
|
||||
inline Vector &Normal( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
Assert( desc.m_CompressionType == VERTEX_COMPRESSION_NONE );
|
||||
return *(Vector*)((unsigned char*)desc.m_pNormal + vert * desc.m_VertexSize_Normal );
|
||||
}
|
||||
|
||||
inline unsigned char *Color( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
return desc.m_pColor + vert * desc.m_VertexSize_Color;
|
||||
}
|
||||
|
||||
inline Vector2D &TexCoord( VertexDesc_t const &desc, int vert, int stage )
|
||||
{
|
||||
return *(Vector2D*)((unsigned char*)desc.m_pTexCoord[stage] + vert * desc.m_VertexSize_TexCoord[stage] );
|
||||
}
|
||||
|
||||
inline Vector &TangentS( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
return *(Vector*)((unsigned char*)desc.m_pTangentS + vert * desc.m_VertexSize_TangentS );
|
||||
}
|
||||
|
||||
inline Vector &TangentT( VertexDesc_t const &desc, int vert )
|
||||
{
|
||||
return *(Vector*)((unsigned char*)desc.m_pTangentT + vert * desc.m_VertexSize_TangentT );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Vertex Buffer implementations begin here
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CVertexBufferBase::CVertexBufferBase( const char *pBudgetGroupName )
|
||||
{
|
||||
m_pBudgetGroupName = pBudgetGroupName;
|
||||
}
|
||||
|
||||
CVertexBufferBase::~CVertexBufferBase()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Displays the vertex format
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVertexBufferBase::PrintVertexFormat( VertexFormat_t vertexFormat )
|
||||
{
|
||||
VertexCompressionType_t compression = CompressionType( vertexFormat );
|
||||
if( vertexFormat & VERTEX_POSITION )
|
||||
{
|
||||
Msg( "VERTEX_POSITION|" );
|
||||
}
|
||||
if( vertexFormat & VERTEX_NORMAL )
|
||||
{
|
||||
// FIXME: genericise this stuff using VertexElement_t data tables (so funcs like 'just work' if we make compression changes)
|
||||
if ( compression == VERTEX_COMPRESSION_ON )
|
||||
Msg( "VERTEX_NORMAL[COMPRESSED]|" );
|
||||
else
|
||||
Msg( "VERTEX_NORMAL|" );
|
||||
}
|
||||
if( vertexFormat & VERTEX_COLOR )
|
||||
{
|
||||
Msg( "VERTEX_COLOR|" );
|
||||
}
|
||||
if( vertexFormat & VERTEX_SPECULAR )
|
||||
{
|
||||
Msg( "VERTEX_SPECULAR|" );
|
||||
}
|
||||
if( vertexFormat & VERTEX_TANGENT_S )
|
||||
{
|
||||
Msg( "VERTEX_TANGENT_S|" );
|
||||
}
|
||||
if( vertexFormat & VERTEX_TANGENT_T )
|
||||
{
|
||||
Msg( "VERTEX_TANGENT_T|" );
|
||||
}
|
||||
if( vertexFormat & VERTEX_BONE_INDEX )
|
||||
{
|
||||
Msg( "VERTEX_BONE_INDEX|" );
|
||||
}
|
||||
if( NumBoneWeights( vertexFormat ) > 0 )
|
||||
{
|
||||
Msg( "VERTEX_BONEWEIGHT(%d)%s|",
|
||||
NumBoneWeights( vertexFormat ), ( compression ? "[COMPRESSED]" : "" ) );
|
||||
}
|
||||
if( UserDataSize( vertexFormat ) > 0 )
|
||||
{
|
||||
Msg( "VERTEX_USERDATA_SIZE(%d)|", UserDataSize( vertexFormat ) );
|
||||
}
|
||||
int i;
|
||||
for( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ )
|
||||
{
|
||||
int nDim = TexCoordSize( i, vertexFormat );
|
||||
if ( nDim == 0 )
|
||||
continue;
|
||||
|
||||
Msg( "VERTEX_TEXCOORD_SIZE(%d,%d)", i, nDim );
|
||||
}
|
||||
Msg( "\n" );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to construct vertex data
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVertexBufferBase::ComputeVertexDescription( unsigned char *pBuffer,
|
||||
VertexFormat_t vertexFormat, VertexDesc_t &desc )
|
||||
{
|
||||
ComputeVertexDesc< false >( pBuffer, vertexFormat, desc );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the vertex format size
|
||||
//-----------------------------------------------------------------------------
|
||||
int CVertexBufferBase::VertexFormatSize( VertexFormat_t vertexFormat )
|
||||
{
|
||||
VertexDesc_t desc;
|
||||
return ComputeVertexDesc< true >( NULL, vertexFormat, desc );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Spews the mesh data
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVertexBufferBase::Spew( int nVertexCount, const VertexDesc_t &desc )
|
||||
{
|
||||
LOCK_SHADERAPI();
|
||||
|
||||
char pTempBuf[1024];
|
||||
Q_snprintf( pTempBuf, sizeof(pTempBuf), "\nVerts %d (First %d, Offset %d) :\n", nVertexCount, desc.m_nFirstVertex, desc.m_nOffset );
|
||||
Warning( "%s", pTempBuf );
|
||||
|
||||
Assert( ( desc.m_NumBoneWeights == 2 ) || ( desc.m_NumBoneWeights == 0 ) );
|
||||
|
||||
int nLen = 0;
|
||||
int nBoneWeightCount = desc.m_NumBoneWeights;
|
||||
for ( int i = 0; i < nVertexCount; ++i )
|
||||
{
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "[%4d] ", i + desc.m_nFirstVertex );
|
||||
if ( desc.m_VertexSize_Position )
|
||||
{
|
||||
Vector &pos = Position( desc, i );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "P %8.2f %8.2f %8.2f ",
|
||||
pos[0], pos[1], pos[2]);
|
||||
}
|
||||
|
||||
if ( desc.m_VertexSize_Wrinkle )
|
||||
{
|
||||
float flWrinkle = Wrinkle( desc, i );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "Wr %8.2f ",flWrinkle );
|
||||
}
|
||||
|
||||
if ( nBoneWeightCount )
|
||||
{
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "BW ");
|
||||
float* pWeight = BoneWeight( desc, i );
|
||||
for ( int j = 0; j < nBoneWeightCount; ++j )
|
||||
{
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "%1.2f ", pWeight[j] );
|
||||
}
|
||||
}
|
||||
if ( desc.m_VertexSize_BoneMatrixIndex )
|
||||
{
|
||||
unsigned char *pIndex = BoneIndex( desc, i );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "BI %d %d %d %d ", ( int )pIndex[0], ( int )pIndex[1], ( int )pIndex[2], ( int )pIndex[3] );
|
||||
Assert( pIndex[0] >= 0 && pIndex[0] < 16 );
|
||||
Assert( pIndex[1] >= 0 && pIndex[1] < 16 );
|
||||
Assert( pIndex[2] >= 0 && pIndex[2] < 16 );
|
||||
Assert( pIndex[3] >= 0 && pIndex[3] < 16 );
|
||||
}
|
||||
|
||||
if ( desc.m_VertexSize_Normal )
|
||||
{
|
||||
Vector & normal = Normal( desc, i );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "N %1.2f %1.2f %1.2f ",
|
||||
normal[0], normal[1], normal[2]);
|
||||
}
|
||||
|
||||
if ( desc.m_VertexSize_Color )
|
||||
{
|
||||
unsigned char* pColor = Color( desc, i );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "C b %3d g %3d r %3d a %3d ",
|
||||
pColor[0], pColor[1], pColor[2], pColor[3]);
|
||||
}
|
||||
|
||||
for ( int j = 0; j < VERTEX_MAX_TEXTURE_COORDINATES; ++j )
|
||||
{
|
||||
if ( desc.m_VertexSize_TexCoord[j] )
|
||||
{
|
||||
Vector2D& texcoord = TexCoord( desc, i, j );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "T%d %.2f %.2f ", j,texcoord[0], texcoord[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if ( desc.m_VertexSize_TangentS )
|
||||
{
|
||||
Vector& tangentS = TangentS( desc, i );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "S %1.2f %1.2f %1.2f ",
|
||||
tangentS[0], tangentS[1], tangentS[2]);
|
||||
}
|
||||
|
||||
if ( desc.m_VertexSize_TangentT )
|
||||
{
|
||||
Vector& tangentT = TangentT( desc, i );
|
||||
nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "T %1.2f %1.2f %1.2f ",
|
||||
tangentT[0], tangentT[1], tangentT[2]);
|
||||
}
|
||||
|
||||
Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "\n" );
|
||||
Warning( "%s", pTempBuf );
|
||||
nLen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Validates vertex buffer data
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVertexBufferBase::ValidateData( int nVertexCount, const VertexDesc_t &spewDesc )
|
||||
{
|
||||
LOCK_SHADERAPI();
|
||||
#ifdef VALIDATE_DEBUG
|
||||
int i;
|
||||
|
||||
// This is needed so buffering can just use this
|
||||
VertexFormat_t fmt = m_pMaterial->GetVertexUsage();
|
||||
|
||||
// Set up the vertex descriptor
|
||||
VertexDesc_t desc = spewDesc;
|
||||
|
||||
int numBoneWeights = NumBoneWeights( fmt );
|
||||
for ( i = 0; i < nVertexCount; ++i )
|
||||
{
|
||||
if( fmt & VERTEX_POSITION )
|
||||
{
|
||||
D3DXVECTOR3& pos = Position( desc, i );
|
||||
Assert( IsFinite( pos[0] ) && IsFinite( pos[1] ) && IsFinite( pos[2] ) );
|
||||
}
|
||||
if( fmt & VERTEX_WRINKLE )
|
||||
{
|
||||
float flWrinkle = Wrinkle( desc, i );
|
||||
Assert( IsFinite( flWrinkle ) );
|
||||
}
|
||||
if (numBoneWeights > 0)
|
||||
{
|
||||
float* pWeight = BoneWeight( desc, i );
|
||||
for (int j = 0; j < numBoneWeights; ++j)
|
||||
{
|
||||
Assert( pWeight[j] >= 0.0f && pWeight[j] <= 1.0f );
|
||||
}
|
||||
}
|
||||
if( fmt & VERTEX_BONE_INDEX )
|
||||
{
|
||||
unsigned char *pIndex = BoneIndex( desc, i );
|
||||
Assert( pIndex[0] >= 0 && pIndex[0] < 16 );
|
||||
Assert( pIndex[1] >= 0 && pIndex[1] < 16 );
|
||||
Assert( pIndex[2] >= 0 && pIndex[2] < 16 );
|
||||
Assert( pIndex[3] >= 0 && pIndex[3] < 16 );
|
||||
}
|
||||
if( fmt & VERTEX_NORMAL )
|
||||
{
|
||||
D3DXVECTOR3& normal = Normal( desc, i );
|
||||
Assert( normal[0] >= -1.05f && normal[0] <= 1.05f );
|
||||
Assert( normal[1] >= -1.05f && normal[1] <= 1.05f );
|
||||
Assert( normal[2] >= -1.05f && normal[2] <= 1.05f );
|
||||
}
|
||||
|
||||
if (fmt & VERTEX_COLOR)
|
||||
{
|
||||
int* pColor = (int*)Color( desc, i );
|
||||
Assert( *pColor != FLOAT32_NAN_BITS );
|
||||
}
|
||||
|
||||
for (int j = 0; j < VERTEX_MAX_TEXTURE_COORDINATES; ++j)
|
||||
{
|
||||
if( TexCoordSize( j, fmt ) > 0)
|
||||
{
|
||||
D3DXVECTOR2& texcoord = TexCoord( desc, i, j );
|
||||
Assert( IsFinite( texcoord[0] ) && IsFinite( texcoord[1] ) );
|
||||
}
|
||||
}
|
||||
|
||||
if (fmt & VERTEX_TANGENT_S)
|
||||
{
|
||||
D3DXVECTOR3& tangentS = TangentS( desc, i );
|
||||
Assert( IsFinite( tangentS[0] ) && IsFinite( tangentS[1] ) && IsFinite( tangentS[2] ) );
|
||||
}
|
||||
|
||||
if (fmt & VERTEX_TANGENT_T)
|
||||
{
|
||||
D3DXVECTOR3& tangentT = TangentT( desc, i );
|
||||
Assert( IsFinite( tangentT[0] ) && IsFinite( tangentT[1] ) && IsFinite( tangentT[2] ) );
|
||||
}
|
||||
}
|
||||
#endif // _DEBUG
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Index Buffer implementations begin here
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CIndexBufferBase::CIndexBufferBase( const char *pBudgetGroupName ) : m_pBudgetGroupName( pBudgetGroupName )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Spews the mesh data
|
||||
//-----------------------------------------------------------------------------
|
||||
void CIndexBufferBase::Spew( int nIndexCount, const IndexDesc_t &indexDesc )
|
||||
{
|
||||
LOCK_SHADERAPI();
|
||||
|
||||
char pTempBuf[512];
|
||||
int nLen = 0;
|
||||
pTempBuf[0] = '\0';
|
||||
char *pTemp = pTempBuf;
|
||||
Q_snprintf( pTempBuf, sizeof(pTempBuf), "\nIndices: %d (First %d, Offset %d)\n", nIndexCount, indexDesc.m_nFirstIndex, indexDesc.m_nOffset );
|
||||
Warning( "%s", pTempBuf );
|
||||
for ( int i = 0; i < nIndexCount; ++i )
|
||||
{
|
||||
nLen += Q_snprintf( pTemp, sizeof(pTempBuf) - nLen - 1, "%d ", ( int )indexDesc.m_pIndices[i] );
|
||||
pTemp = pTempBuf + nLen;
|
||||
if ( (i & 0x0F) == 0x0F )
|
||||
{
|
||||
Q_snprintf( pTemp, sizeof(pTempBuf) - nLen - 1, "\n" );
|
||||
Warning( "%s", pTempBuf );
|
||||
pTempBuf[0] = '\0';
|
||||
nLen = 0;
|
||||
pTemp = pTempBuf;
|
||||
}
|
||||
}
|
||||
Q_snprintf( pTemp, sizeof(pTempBuf) - nLen - 1, "\n" );
|
||||
Warning( "%s", pTempBuf );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Call this in debug mode to make sure our data is good.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CIndexBufferBase::ValidateData( int nIndexCount, const IndexDesc_t& desc )
|
||||
{
|
||||
/* FIXME */
|
||||
// NOTE: Is there anything reasonable to do here at all?
|
||||
// Or is this a bogus method altogether?
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Base mesh
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CMeshBase::CMeshBase()
|
||||
{
|
||||
}
|
||||
|
||||
CMeshBase::~CMeshBase()
|
||||
{
|
||||
}
|
||||
389
materialsystem/shaderapidx9/meshbase.h
Normal file
389
materialsystem/shaderapidx9/meshbase.h
Normal file
@@ -0,0 +1,389 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef MESHBASE_H
|
||||
#define MESHBASE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "materialsystem/imaterial.h"
|
||||
|
||||
|
||||
struct VertexStreamSpec_t;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Base vertex buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class CVertexBufferBase : public IVertexBuffer
|
||||
{
|
||||
// Methods of IVertexBuffer
|
||||
public:
|
||||
virtual void Spew( int nVertexCount, const VertexDesc_t &desc );
|
||||
virtual void ValidateData( int nVertexCount, const VertexDesc_t& desc );
|
||||
|
||||
public:
|
||||
// constructor, destructor
|
||||
CVertexBufferBase( const char *pBudgetGroupName );
|
||||
virtual ~CVertexBufferBase();
|
||||
|
||||
// Displays the vertex format
|
||||
static void PrintVertexFormat( VertexFormat_t vertexFormat );
|
||||
|
||||
// Used to construct vertex data
|
||||
static void ComputeVertexDescription( unsigned char *pBuffer, VertexFormat_t vertexFormat, VertexDesc_t &desc );
|
||||
|
||||
// Returns the vertex format size
|
||||
static int VertexFormatSize( VertexFormat_t vertexFormat );
|
||||
|
||||
protected:
|
||||
const char *m_pBudgetGroupName;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Base index buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class CIndexBufferBase : public IIndexBuffer
|
||||
{
|
||||
// Methods of IIndexBuffer
|
||||
public:
|
||||
virtual void Spew( int nIndexCount, const IndexDesc_t &desc );
|
||||
virtual void ValidateData( int nIndexCount, const IndexDesc_t& desc );
|
||||
virtual IMesh* GetMesh() { return NULL; }
|
||||
|
||||
// Other public methods
|
||||
public:
|
||||
// constructor, destructor
|
||||
CIndexBufferBase( const char *pBudgetGroupName );
|
||||
virtual ~CIndexBufferBase() {}
|
||||
|
||||
protected:
|
||||
const char *m_pBudgetGroupName;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Base mesh
|
||||
//-----------------------------------------------------------------------------
|
||||
class CMeshBase : public IMesh
|
||||
{
|
||||
// Methods of IMesh
|
||||
public:
|
||||
|
||||
// Other public methods that need to be overridden
|
||||
public:
|
||||
// Begins a pass
|
||||
virtual void BeginPass( ) = 0;
|
||||
|
||||
// Draws a single pass of the mesh
|
||||
virtual void RenderPass( const unsigned char *pInstanceCommandBuffer ) = 0;
|
||||
|
||||
// DrawPrims
|
||||
virtual void DrawPrims( const unsigned char *pInstanceCommandBuffer ) = 0;
|
||||
|
||||
// Does it have a color mesh?
|
||||
virtual bool HasColorMesh() const = 0;
|
||||
|
||||
// Does it have a flex mesh?
|
||||
virtual bool HasFlexMesh() const = 0;
|
||||
|
||||
// Is it using a vertex ID?
|
||||
virtual bool IsUsingVertexID() const = 0;
|
||||
|
||||
// Is it using tessellation for higher-order surfaces?
|
||||
#if ENABLE_TESSELLATION
|
||||
virtual TessellationMode_t GetTessellationType() const = 0;
|
||||
#else
|
||||
TessellationMode_t GetTessellationType() const { return TESSELLATION_MODE_DISABLED; }
|
||||
#endif
|
||||
|
||||
// Are vertex data streams specified in a custom manner?
|
||||
virtual VertexStreamSpec_t *GetVertexStreamSpec() const = 0;
|
||||
|
||||
virtual IMesh *GetMesh() { return this; }
|
||||
|
||||
virtual void * AccessRawHardwareDataStream( uint8 nRawStreamIndex, uint32 numBytes, uint32 uiFlags, void *pvContext ) { return NULL; }
|
||||
|
||||
virtual ICachedPerFrameMeshData *GetCachedPerFrameMeshData() { return NULL; }
|
||||
virtual void ReconstructFromCachedPerFrameMeshData( ICachedPerFrameMeshData *pData ) {}
|
||||
public:
|
||||
// constructor, destructor
|
||||
CMeshBase();
|
||||
virtual ~CMeshBase();
|
||||
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Utility method for VertexDesc_t (don't want to expose it in public, in imesh.h)
|
||||
// We've split this into two versions, one for computing size-only, and the standard
|
||||
// version which computes field offsets and sizes.
|
||||
// The code would be cleaner if we split it into two functions, but for now we'll keep
|
||||
// all of the if( !bSizeOnly ) for easier maintenance if we need to change any of the fields.
|
||||
//-----------------------------------------------------------------------------
|
||||
template< bool bSizeOnly >
|
||||
inline int ComputeVertexDesc( unsigned char * pBuffer, VertexFormat_t vertexFormat, VertexDesc_t & desc )
|
||||
{
|
||||
int i;
|
||||
int *pVertexSizesToSet[64];
|
||||
int nVertexSizesToSet = 0;
|
||||
static ALIGN32 ModelVertexDX8_t temp[4];
|
||||
float *dummyData = (float*)&temp; // should be larger than any CMeshBuilder command can set.
|
||||
|
||||
// Determine which vertex compression type this format specifies (affects element sizes/decls):
|
||||
VertexCompressionType_t compression = CompressionType( vertexFormat );
|
||||
int nNumBoneWeights = NumBoneWeights( vertexFormat );
|
||||
|
||||
if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_CompressionType = compression;
|
||||
desc.m_NumBoneWeights = nNumBoneWeights;
|
||||
}
|
||||
|
||||
// We use fvf instead of flags here because we may pad out the fvf
|
||||
// vertex structure to optimize performance
|
||||
int offset = 0;
|
||||
// NOTE: At the moment, we assume that if you specify wrinkle, you also specify position
|
||||
Assert( ( ( vertexFormat & VERTEX_WRINKLE ) == 0 ) || ( ( vertexFormat & VERTEX_POSITION ) != 0 ) );
|
||||
if ( vertexFormat & VERTEX_POSITION )
|
||||
{
|
||||
if ( !bSizeOnly )
|
||||
{
|
||||
// UNDONE: compress position+wrinkle to SHORT4N, and roll the scale into the transform matrices
|
||||
desc.m_pPosition = reinterpret_cast<float*>(pBuffer);
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Position;
|
||||
}
|
||||
|
||||
VertexElement_t posElement = (vertexFormat & VERTEX_FORMAT_PAD_POS_NORM ) != 0 ? VERTEX_ELEMENT_POSITION4D : VERTEX_ELEMENT_POSITION;
|
||||
offset += GetVertexElementSize( posElement, compression );
|
||||
|
||||
if ( vertexFormat & VERTEX_WRINKLE )
|
||||
{
|
||||
if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pWrinkle = reinterpret_cast<float*>( pBuffer + offset );
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Wrinkle;
|
||||
}
|
||||
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_WRINKLE, compression );
|
||||
}
|
||||
else if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pWrinkle = dummyData;
|
||||
desc.m_VertexSize_Wrinkle = 0;
|
||||
}
|
||||
}
|
||||
else if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pPosition = dummyData;
|
||||
desc.m_VertexSize_Position = 0;
|
||||
desc.m_pWrinkle = dummyData;
|
||||
desc.m_VertexSize_Wrinkle = 0;
|
||||
}
|
||||
|
||||
// Bone weights/matrix indices
|
||||
Assert( ( nNumBoneWeights == 2 ) || ( nNumBoneWeights == 0 ) );
|
||||
|
||||
// We assume that if you have any indices/weights, you have exactly two of them
|
||||
Assert( ( ( nNumBoneWeights == 2 ) && ( ( vertexFormat & VERTEX_BONE_INDEX ) != 0 ) ) ||
|
||||
( ( nNumBoneWeights == 0 ) && ( ( vertexFormat & VERTEX_BONE_INDEX ) == 0 ) ) );
|
||||
|
||||
if ( ( vertexFormat & VERTEX_BONE_INDEX ) != 0 )
|
||||
{
|
||||
if ( nNumBoneWeights > 0 )
|
||||
{
|
||||
// Always exactly two weights
|
||||
Assert( nNumBoneWeights == 2 );
|
||||
if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pBoneWeight = reinterpret_cast<float*>(pBuffer + offset);
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_BoneWeight;
|
||||
}
|
||||
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_BONEWEIGHTS2, compression );
|
||||
}
|
||||
else if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pBoneWeight = dummyData;
|
||||
desc.m_VertexSize_BoneWeight = 0;
|
||||
}
|
||||
|
||||
if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pBoneMatrixIndex = pBuffer + offset;
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_BoneMatrixIndex;
|
||||
}
|
||||
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_BONEINDEX, compression );
|
||||
}
|
||||
else if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pBoneWeight = dummyData;
|
||||
desc.m_VertexSize_BoneWeight = 0;
|
||||
|
||||
desc.m_pBoneMatrixIndex = (unsigned char*)dummyData;
|
||||
desc.m_VertexSize_BoneMatrixIndex = 0;
|
||||
}
|
||||
|
||||
if ( vertexFormat & VERTEX_NORMAL )
|
||||
{
|
||||
if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pNormal = reinterpret_cast<float*>(pBuffer + offset);
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Normal;
|
||||
}
|
||||
|
||||
// See PackNormal_[SHORT2|UBYTE4|HEND3N] in mathlib.h for the compression algorithm
|
||||
|
||||
VertexElement_t normalElement = (vertexFormat & VERTEX_FORMAT_PAD_POS_NORM ) != 0 ? VERTEX_ELEMENT_NORMAL4D : VERTEX_ELEMENT_NORMAL;
|
||||
offset += GetVertexElementSize( normalElement, compression );
|
||||
}
|
||||
else if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pNormal = dummyData;
|
||||
desc.m_VertexSize_Normal = 0;
|
||||
}
|
||||
|
||||
if ( vertexFormat & VERTEX_COLOR )
|
||||
{
|
||||
if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pColor = pBuffer + offset;
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Color;
|
||||
}
|
||||
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_COLOR, compression );
|
||||
}
|
||||
else if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pColor = (unsigned char*)dummyData;
|
||||
desc.m_VertexSize_Color = 0;
|
||||
}
|
||||
|
||||
if ( vertexFormat & VERTEX_SPECULAR )
|
||||
{
|
||||
if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pSpecular = pBuffer + offset;
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Specular;
|
||||
}
|
||||
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_SPECULAR, compression );
|
||||
}
|
||||
else if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pSpecular = (unsigned char*)dummyData;
|
||||
desc.m_VertexSize_Specular = 0;
|
||||
}
|
||||
|
||||
// Set up texture coordinates
|
||||
static const VertexElement_t texCoordElements[4] = { VERTEX_ELEMENT_TEXCOORD1D_0, VERTEX_ELEMENT_TEXCOORD2D_0, VERTEX_ELEMENT_TEXCOORD3D_0, VERTEX_ELEMENT_TEXCOORD4D_0 };
|
||||
for ( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i )
|
||||
{
|
||||
// FIXME: compress texcoords to SHORT2N/SHORT4N, with a scale rolled into the texture transform
|
||||
int nSize = TexCoordSize( i, vertexFormat );
|
||||
if ( nSize != 0 )
|
||||
{
|
||||
if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pTexCoord[i] = reinterpret_cast<float*>(pBuffer + offset);
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_TexCoord[i];
|
||||
}
|
||||
|
||||
VertexElement_t texCoordElement = (VertexElement_t)( texCoordElements[ nSize - 1 ] + i );
|
||||
offset += GetVertexElementSize( texCoordElement, compression );
|
||||
}
|
||||
else if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pTexCoord[i] = dummyData;
|
||||
desc.m_VertexSize_TexCoord[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Binormal + tangent...
|
||||
// Note we have to put these at the end so the vertex is FVF + stuff at end
|
||||
if ( vertexFormat & VERTEX_TANGENT_S )
|
||||
{
|
||||
// UNDONE: use normal compression here (use mem_dumpvballocs to see if this uses much memory)
|
||||
if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pTangentS = reinterpret_cast<float*>(pBuffer + offset);
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_TangentS;
|
||||
}
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_TANGENT_S, compression );
|
||||
|
||||
}
|
||||
else if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pTangentS = dummyData;
|
||||
desc.m_VertexSize_TangentS = 0;
|
||||
}
|
||||
|
||||
if ( vertexFormat & VERTEX_TANGENT_T )
|
||||
{
|
||||
// UNDONE: use normal compression here (use mem_dumpvballocs to see if this uses much memory)
|
||||
if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pTangentT = reinterpret_cast<float*>(pBuffer + offset);
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_TangentT;
|
||||
}
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_TANGENT_T, compression );
|
||||
}
|
||||
else if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pTangentT = dummyData;
|
||||
desc.m_VertexSize_TangentT = 0;
|
||||
}
|
||||
|
||||
// User data..
|
||||
int userDataSize = UserDataSize( vertexFormat );
|
||||
if ( userDataSize > 0 )
|
||||
{
|
||||
if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pUserData = reinterpret_cast<float*>(pBuffer + offset);
|
||||
pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_UserData;
|
||||
}
|
||||
|
||||
VertexElement_t userDataElement = (VertexElement_t)( VERTEX_ELEMENT_USERDATA1 + ( userDataSize - 1 ) );
|
||||
// See PackNormal_[SHORT2|UBYTE4|HEND3N] in mathlib.h for the compression algorithm
|
||||
offset += GetVertexElementSize( userDataElement, compression );
|
||||
}
|
||||
else if ( !bSizeOnly )
|
||||
{
|
||||
desc.m_pUserData = dummyData;
|
||||
desc.m_VertexSize_UserData = 0;
|
||||
}
|
||||
|
||||
// We always use vertex sizes which are half-cache aligned (16 bytes)
|
||||
// x360 compressed vertexes are not compatible with forced alignments
|
||||
bool bCacheAlign = ( vertexFormat & VERTEX_FORMAT_USE_EXACT_FORMAT ) == 0;
|
||||
if ( bCacheAlign && ( offset > 16 ) && IsPC() )
|
||||
{
|
||||
offset = (offset + 0xF) & (~0xF);
|
||||
}
|
||||
desc.m_ActualVertexSize = offset;
|
||||
|
||||
if ( !bSizeOnly )
|
||||
{
|
||||
// Now set the m_VertexSize for all the members that were actually valid.
|
||||
Assert( nVertexSizesToSet < sizeof(pVertexSizesToSet)/sizeof(pVertexSizesToSet[0]) );
|
||||
for ( int iElement=0; iElement < nVertexSizesToSet; iElement++ )
|
||||
{
|
||||
*pVertexSizesToSet[iElement] = offset;
|
||||
}
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
#endif // MESHBASE_H
|
||||
778
materialsystem/shaderapidx9/meshdx10.cpp
Normal file
778
materialsystem/shaderapidx9/meshdx10.cpp
Normal file
@@ -0,0 +1,778 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include <d3d10.h>
|
||||
#undef GetCommandLine
|
||||
|
||||
#include "meshdx10.h"
|
||||
#include "utlvector.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "IHardwareConfigInternal.h"
|
||||
#include "shaderapi_global.h"
|
||||
#include "shaderapi/ishaderutil.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
#include "shaderdevicedx10.h"
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "tier0/vprof.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "materialsystem/idebugtextureinfo.h"
|
||||
#include "materialsystem/ivballoctracker.h"
|
||||
#include "tier2/tier2.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Dx10 implementation of a vertex buffer
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// globals
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef _DEBUG
|
||||
int CVertexBufferDx10::s_nBufferCount = 0;
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CVertexBufferDx10::CVertexBufferDx10( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroupName ) :
|
||||
BaseClass( pBudgetGroupName )
|
||||
{
|
||||
Assert( nVertexCount != 0 );
|
||||
|
||||
m_pVertexBuffer = NULL;
|
||||
m_VertexFormat = fmt;
|
||||
m_nVertexCount = ( fmt == VERTEX_FORMAT_UNKNOWN ) ? 0 : nVertexCount;
|
||||
m_nBufferSize = ( fmt == VERTEX_FORMAT_UNKNOWN ) ? nVertexCount : nVertexCount * VertexSize();
|
||||
m_nFirstUnwrittenOffset = 0;
|
||||
m_bIsLocked = false;
|
||||
m_bIsDynamic = ( type == SHADER_BUFFER_TYPE_DYNAMIC ) || ( type == SHADER_BUFFER_TYPE_DYNAMIC_TEMP );
|
||||
m_bFlush = false;
|
||||
}
|
||||
|
||||
CVertexBufferDx10::~CVertexBufferDx10()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates, destroys the vertex buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CVertexBufferDx10::Allocate( )
|
||||
{
|
||||
Assert( !m_pVertexBuffer );
|
||||
|
||||
m_nFirstUnwrittenOffset = 0;
|
||||
|
||||
D3D10_BUFFER_DESC bd;
|
||||
bd.Usage = D3D10_USAGE_DYNAMIC;
|
||||
bd.ByteWidth = m_nBufferSize;
|
||||
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||
bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
||||
bd.MiscFlags = 0;
|
||||
|
||||
HRESULT hr = D3D10Device()->CreateBuffer( &bd, NULL, &m_pVertexBuffer );
|
||||
bool bOk = !FAILED( hr ) && ( m_pVertexBuffer != 0 );
|
||||
|
||||
if ( bOk )
|
||||
{
|
||||
// Track VB allocations
|
||||
g_VBAllocTracker->CountVB( m_pVertexBuffer, m_bIsDynamic, m_nBufferSize, VertexSize(), GetVertexFormat() );
|
||||
|
||||
if ( !m_bIsDynamic )
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize );
|
||||
}
|
||||
else
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize );
|
||||
// Dynamic meshes should never be compressed (slows down writing to them)
|
||||
Assert( CompressionType( GetVertexFormat() ) == VERTEX_COMPRESSION_NONE );
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
++s_nBufferCount;
|
||||
#endif
|
||||
}
|
||||
|
||||
return bOk;
|
||||
}
|
||||
|
||||
void CVertexBufferDx10::Free()
|
||||
{
|
||||
if ( m_pVertexBuffer )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
--s_nBufferCount;
|
||||
#endif
|
||||
|
||||
// Track VB allocations
|
||||
g_VBAllocTracker->UnCountVB( m_pVertexBuffer );
|
||||
|
||||
m_pVertexBuffer->Release();
|
||||
m_pVertexBuffer = NULL;
|
||||
|
||||
if ( !m_bIsDynamic )
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize );
|
||||
}
|
||||
else
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Vertex Buffer info
|
||||
//-----------------------------------------------------------------------------
|
||||
int CVertexBufferDx10::VertexCount() const
|
||||
{
|
||||
Assert( !m_bIsDynamic );
|
||||
return m_nVertexCount;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the buffer format (only valid for static index buffers)
|
||||
//-----------------------------------------------------------------------------
|
||||
VertexFormat_t CVertexBufferDx10::GetVertexFormat() const
|
||||
{
|
||||
Assert( !m_bIsDynamic );
|
||||
return m_VertexFormat;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if the buffer is dynamic
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CVertexBufferDx10::IsDynamic() const
|
||||
{
|
||||
return m_bIsDynamic;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Only used by dynamic buffers, indicates the next lock should perform a discard.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVertexBufferDx10::Flush()
|
||||
{
|
||||
// This strange-looking line makes a flush only occur if the buffer is dynamic.
|
||||
m_bFlush = m_bIsDynamic;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Casts a dynamic buffer to be a particular vertex type
|
||||
//-----------------------------------------------------------------------------
|
||||
void CVertexBufferDx10::BeginCastBuffer( VertexFormat_t format )
|
||||
{
|
||||
Assert( format != MATERIAL_INDEX_FORMAT_UNKNOWN );
|
||||
Assert( m_bIsDynamic && ( m_VertexFormat == 0 || m_VertexFormat == format ) );
|
||||
if ( !m_bIsDynamic )
|
||||
return;
|
||||
|
||||
m_VertexFormat = format;
|
||||
m_nVertexCount = m_nBufferSize / VertexSize();
|
||||
}
|
||||
|
||||
void CVertexBufferDx10::EndCastBuffer( )
|
||||
{
|
||||
Assert( m_bIsDynamic && m_VertexFormat != 0 );
|
||||
if ( !m_bIsDynamic )
|
||||
return;
|
||||
m_VertexFormat = 0;
|
||||
m_nVertexCount = 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the number of indices that can be written into the buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
int CVertexBufferDx10::GetRoomRemaining() const
|
||||
{
|
||||
return ( m_nBufferSize - m_nFirstUnwrittenOffset ) / VertexSize();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Lock, unlock
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CVertexBufferDx10::Lock( int nMaxVertexCount, bool bAppend, VertexDesc_t &desc )
|
||||
{
|
||||
Assert( !m_bIsLocked && ( nMaxVertexCount != 0 ) && ( nMaxVertexCount <= m_nVertexCount ) );
|
||||
Assert( m_VertexFormat != 0 );
|
||||
|
||||
// FIXME: Why do we need to sync matrices now?
|
||||
ShaderUtil()->SyncMatrices();
|
||||
g_ShaderMutex.Lock();
|
||||
|
||||
void *pLockedData = NULL;
|
||||
HRESULT hr;
|
||||
|
||||
// This can happen if the buffer was locked but a type wasn't bound
|
||||
if ( m_VertexFormat == 0 )
|
||||
goto vertexBufferLockFailed;
|
||||
|
||||
// Just give the app crap buffers to fill up while we're suppressed...
|
||||
if ( g_pShaderDevice->IsDeactivated() || ( nMaxVertexCount == 0 ) )
|
||||
goto vertexBufferLockFailed;
|
||||
|
||||
// Did we ask for something too large?
|
||||
if ( nMaxVertexCount > m_nVertexCount )
|
||||
{
|
||||
Warning( "Too many vertices for vertex buffer. . tell a programmer (%d>%d)\n", nMaxVertexCount, m_nVertexCount );
|
||||
goto vertexBufferLockFailed;
|
||||
}
|
||||
|
||||
// We might not have a buffer owing to alt-tab type stuff
|
||||
if ( !m_pVertexBuffer )
|
||||
{
|
||||
if ( !Allocate() )
|
||||
goto vertexBufferLockFailed;
|
||||
}
|
||||
|
||||
// Check to see if we have enough memory
|
||||
int nMemoryRequired = nMaxVertexCount * VertexSize();
|
||||
bool bHasEnoughMemory = ( m_nFirstUnwrittenOffset + nMemoryRequired <= m_nBufferSize );
|
||||
|
||||
D3D10_MAP map;
|
||||
if ( bAppend )
|
||||
{
|
||||
// Can't have the first lock after a flush be an appending lock
|
||||
Assert( !m_bFlush );
|
||||
|
||||
// If we're appending and we don't have enough room, then puke!
|
||||
if ( !bHasEnoughMemory || m_bFlush )
|
||||
goto vertexBufferLockFailed;
|
||||
map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we're not appending, no overwrite unless we don't have enough room
|
||||
// If we're a static buffer, always discard if we're not appending
|
||||
if ( !m_bFlush && bHasEnoughMemory && m_bIsDynamic )
|
||||
{
|
||||
map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE;
|
||||
}
|
||||
else
|
||||
{
|
||||
map = D3D10_MAP_WRITE_DISCARD;
|
||||
m_nFirstUnwrittenOffset = 0;
|
||||
m_bFlush = false;
|
||||
}
|
||||
}
|
||||
|
||||
hr = m_pVertexBuffer->Map( map, 0, &pLockedData );
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
Warning( "Failed to lock vertex buffer in CVertexBufferDx10::Lock\n" );
|
||||
goto vertexBufferLockFailed;
|
||||
}
|
||||
|
||||
ComputeVertexDescription( (unsigned char*)pLockedData + m_nFirstUnwrittenOffset, m_VertexFormat, desc );
|
||||
desc.m_nFirstVertex = 0;
|
||||
desc.m_nOffset = m_nFirstUnwrittenOffset;
|
||||
m_bIsLocked = true;
|
||||
return true;
|
||||
|
||||
vertexBufferLockFailed:
|
||||
g_ShaderMutex.Unlock();
|
||||
|
||||
// Set up a bogus index descriptor
|
||||
ComputeVertexDescription( 0, 0, desc );
|
||||
desc.m_nFirstVertex = 0;
|
||||
desc.m_nOffset = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
void CVertexBufferDx10::Unlock( int nWrittenVertexCount, VertexDesc_t &desc )
|
||||
{
|
||||
Assert( nWrittenVertexCount <= m_nVertexCount );
|
||||
|
||||
// NOTE: This can happen if the lock occurs during alt-tab
|
||||
// or if another application is initializing
|
||||
if ( !m_bIsLocked )
|
||||
return;
|
||||
|
||||
if ( m_pVertexBuffer )
|
||||
{
|
||||
m_pVertexBuffer->Unmap();
|
||||
}
|
||||
|
||||
m_nFirstUnwrittenOffset += nWrittenVertexCount * VertexSize();
|
||||
m_bIsLocked = false;
|
||||
g_ShaderMutex.Unlock();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Dx10 implementation of an index buffer
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// globals
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// shove indices into this if you don't actually want indices
|
||||
static unsigned int s_nScratchIndexBuffer = 0;
|
||||
|
||||
#ifdef _DEBUG
|
||||
int CIndexBufferDx10::s_nBufferCount = 0;
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CIndexBufferDx10::CIndexBufferDx10( ShaderBufferType_t type, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroupName ) :
|
||||
BaseClass( pBudgetGroupName )
|
||||
{
|
||||
Assert( nIndexCount != 0 );
|
||||
Assert( IsDynamicBufferType( type ) || ( fmt != MATERIAL_INDEX_FORMAT_UNKNOWN ) );
|
||||
|
||||
m_pIndexBuffer = NULL;
|
||||
m_IndexFormat = fmt;
|
||||
m_nIndexCount = ( fmt == MATERIAL_INDEX_FORMAT_UNKNOWN ) ? 0 : nIndexCount;
|
||||
m_nBufferSize = ( fmt == MATERIAL_INDEX_FORMAT_UNKNOWN ) ? nIndexCount : nIndexCount * IndexSize();
|
||||
m_nFirstUnwrittenOffset = 0;
|
||||
m_bIsLocked = false;
|
||||
m_bIsDynamic = IsDynamicBufferType( type );
|
||||
m_bFlush = false;
|
||||
|
||||
// NOTE: This has to happen at the end since m_IndexFormat must be valid for IndexSize() to work
|
||||
if ( m_bIsDynamic )
|
||||
{
|
||||
m_IndexFormat = MATERIAL_INDEX_FORMAT_UNKNOWN;
|
||||
m_nIndexCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
CIndexBufferDx10::~CIndexBufferDx10()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates, destroys the index buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CIndexBufferDx10::Allocate( )
|
||||
{
|
||||
Assert( !m_pIndexBuffer );
|
||||
|
||||
m_nFirstUnwrittenOffset = 0;
|
||||
|
||||
D3D10_BUFFER_DESC bd;
|
||||
bd.Usage = D3D10_USAGE_DYNAMIC;
|
||||
bd.ByteWidth = m_nBufferSize;
|
||||
bd.BindFlags = D3D10_BIND_INDEX_BUFFER;
|
||||
bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
|
||||
bd.MiscFlags = 0;
|
||||
|
||||
HRESULT hr = D3D10Device()->CreateBuffer( &bd, NULL, &m_pIndexBuffer );
|
||||
bool bOk = !FAILED( hr ) && ( m_pIndexBuffer != NULL );
|
||||
|
||||
if ( bOk )
|
||||
{
|
||||
if ( !m_bIsDynamic )
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize );
|
||||
}
|
||||
else
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize );
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
++s_nBufferCount;
|
||||
#endif
|
||||
}
|
||||
|
||||
return bOk;
|
||||
}
|
||||
|
||||
void CIndexBufferDx10::Free()
|
||||
{
|
||||
if ( m_pIndexBuffer )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
--s_nBufferCount;
|
||||
#endif
|
||||
|
||||
m_pIndexBuffer->Release();
|
||||
m_pIndexBuffer = NULL;
|
||||
|
||||
if ( !m_bIsDynamic )
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize );
|
||||
}
|
||||
else
|
||||
{
|
||||
VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER,
|
||||
COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the buffer size (only valid for static index buffers)
|
||||
//-----------------------------------------------------------------------------
|
||||
int CIndexBufferDx10::IndexCount() const
|
||||
{
|
||||
Assert( !m_bIsDynamic );
|
||||
return m_nIndexCount;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the buffer format (only valid for static index buffers)
|
||||
//-----------------------------------------------------------------------------
|
||||
MaterialIndexFormat_t CIndexBufferDx10::IndexFormat() const
|
||||
{
|
||||
Assert( !m_bIsDynamic );
|
||||
return m_IndexFormat;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns true if the buffer is dynamic
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CIndexBufferDx10::IsDynamic() const
|
||||
{
|
||||
return m_bIsDynamic;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Only used by dynamic buffers, indicates the next lock should perform a discard.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CIndexBufferDx10::Flush()
|
||||
{
|
||||
// This strange-looking line makes a flush only occur if the buffer is dynamic.
|
||||
m_bFlush = m_bIsDynamic;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Casts a dynamic buffer to be a particular index type
|
||||
//-----------------------------------------------------------------------------
|
||||
void CIndexBufferDx10::BeginCastBuffer( MaterialIndexFormat_t format )
|
||||
{
|
||||
Assert( format != MATERIAL_INDEX_FORMAT_UNKNOWN );
|
||||
Assert( m_bIsDynamic && ( m_IndexFormat == MATERIAL_INDEX_FORMAT_UNKNOWN || m_IndexFormat == format ) );
|
||||
if ( !m_bIsDynamic )
|
||||
return;
|
||||
|
||||
m_IndexFormat = format;
|
||||
m_nIndexCount = m_nBufferSize / IndexSize();
|
||||
}
|
||||
|
||||
void CIndexBufferDx10::EndCastBuffer( )
|
||||
{
|
||||
Assert( m_bIsDynamic && m_IndexFormat != MATERIAL_INDEX_FORMAT_UNKNOWN );
|
||||
if ( !m_bIsDynamic )
|
||||
return;
|
||||
m_IndexFormat = MATERIAL_INDEX_FORMAT_UNKNOWN;
|
||||
m_nIndexCount = 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the number of indices that can be written into the buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
int CIndexBufferDx10::GetRoomRemaining() const
|
||||
{
|
||||
return ( m_nBufferSize - m_nFirstUnwrittenOffset ) / IndexSize();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Locks, unlocks the mesh
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CIndexBufferDx10::Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t &desc )
|
||||
{
|
||||
Assert( !m_bIsLocked && ( nMaxIndexCount != 0 ) && ( nMaxIndexCount <= m_nIndexCount ) );
|
||||
Assert( m_IndexFormat != MATERIAL_INDEX_FORMAT_UNKNOWN );
|
||||
|
||||
// FIXME: Why do we need to sync matrices now?
|
||||
ShaderUtil()->SyncMatrices();
|
||||
g_ShaderMutex.Lock();
|
||||
|
||||
void *pLockedData = NULL;
|
||||
HRESULT hr;
|
||||
|
||||
// This can happen if the buffer was locked but a type wasn't bound
|
||||
if ( m_IndexFormat == MATERIAL_INDEX_FORMAT_UNKNOWN )
|
||||
goto indexBufferLockFailed;
|
||||
|
||||
// Just give the app crap buffers to fill up while we're suppressed...
|
||||
if ( g_pShaderDevice->IsDeactivated() || ( nMaxIndexCount == 0 ) )
|
||||
goto indexBufferLockFailed;
|
||||
|
||||
// Did we ask for something too large?
|
||||
if ( nMaxIndexCount > m_nIndexCount )
|
||||
{
|
||||
Warning( "Too many indices for index buffer. . tell a programmer (%d>%d)\n", nMaxIndexCount, m_nIndexCount );
|
||||
goto indexBufferLockFailed;
|
||||
}
|
||||
|
||||
// We might not have a buffer owing to alt-tab type stuff
|
||||
if ( !m_pIndexBuffer )
|
||||
{
|
||||
if ( !Allocate() )
|
||||
goto indexBufferLockFailed;
|
||||
}
|
||||
|
||||
// Check to see if we have enough memory
|
||||
int nMemoryRequired = nMaxIndexCount * IndexSize();
|
||||
bool bHasEnoughMemory = ( m_nFirstUnwrittenOffset + nMemoryRequired <= m_nBufferSize );
|
||||
|
||||
D3D10_MAP map;
|
||||
if ( bAppend )
|
||||
{
|
||||
// Can't have the first lock after a flush be an appending lock
|
||||
Assert( !m_bFlush );
|
||||
|
||||
// If we're appending and we don't have enough room, then puke!
|
||||
if ( !bHasEnoughMemory || m_bFlush )
|
||||
goto indexBufferLockFailed;
|
||||
map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we're not appending, no overwrite unless we don't have enough room
|
||||
if ( !m_bFlush && bHasEnoughMemory && m_bIsDynamic )
|
||||
{
|
||||
map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE;
|
||||
}
|
||||
else
|
||||
{
|
||||
map = D3D10_MAP_WRITE_DISCARD;
|
||||
m_nFirstUnwrittenOffset = 0;
|
||||
m_bFlush = false;
|
||||
}
|
||||
}
|
||||
|
||||
hr = m_pIndexBuffer->Map( map, 0, &pLockedData );
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
Warning( "Failed to lock index buffer in CIndexBufferDx10::Lock\n" );
|
||||
goto indexBufferLockFailed;
|
||||
}
|
||||
|
||||
desc.m_pIndices = (unsigned short*)( (unsigned char*)pLockedData + m_nFirstUnwrittenOffset );
|
||||
desc.m_nIndexSize = IndexSize() >> 1;
|
||||
desc.m_nFirstIndex = 0;
|
||||
desc.m_nOffset = m_nFirstUnwrittenOffset;
|
||||
m_bIsLocked = true;
|
||||
return true;
|
||||
|
||||
indexBufferLockFailed:
|
||||
g_ShaderMutex.Unlock();
|
||||
|
||||
// Set up a bogus index descriptor
|
||||
desc.m_pIndices = (unsigned short*)( &s_nScratchIndexBuffer );
|
||||
desc.m_nFirstIndex = 0;
|
||||
desc.m_nIndexSize = 0;
|
||||
desc.m_nOffset = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
void CIndexBufferDx10::Unlock( int nWrittenIndexCount, IndexDesc_t &desc )
|
||||
{
|
||||
Assert( nWrittenIndexCount <= m_nIndexCount );
|
||||
|
||||
// NOTE: This can happen if the lock occurs during alt-tab
|
||||
// or if another application is initializing
|
||||
if ( !m_bIsLocked )
|
||||
return;
|
||||
|
||||
if ( m_pIndexBuffer )
|
||||
{
|
||||
m_pIndexBuffer->Unmap();
|
||||
}
|
||||
|
||||
m_nFirstUnwrittenOffset += nWrittenIndexCount * IndexSize();
|
||||
m_bIsLocked = false;
|
||||
g_ShaderMutex.Unlock();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Locks, unlocks an existing mesh
|
||||
//-----------------------------------------------------------------------------
|
||||
void CIndexBufferDx10::ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc )
|
||||
{
|
||||
Assert( 0 );
|
||||
}
|
||||
|
||||
void CIndexBufferDx10::ModifyEnd( IndexDesc_t& desc )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// The empty mesh...
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CMeshDx10::CMeshDx10()
|
||||
{
|
||||
m_pVertexMemory = new unsigned char[VERTEX_BUFFER_SIZE];
|
||||
}
|
||||
|
||||
CMeshDx10::~CMeshDx10()
|
||||
{
|
||||
delete[] m_pVertexMemory;
|
||||
}
|
||||
|
||||
void CMeshDx10::LockMesh( int numVerts, int numIndices, MeshDesc_t& desc )
|
||||
{
|
||||
// Who cares about the data?
|
||||
desc.m_pPosition = (float*)m_pVertexMemory;
|
||||
desc.m_pNormal = (float*)m_pVertexMemory;
|
||||
desc.m_pColor = m_pVertexMemory;
|
||||
int i;
|
||||
for ( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i)
|
||||
desc.m_pTexCoord[i] = (float*)m_pVertexMemory;
|
||||
desc.m_pIndices = (unsigned short*)m_pVertexMemory;
|
||||
|
||||
desc.m_pBoneWeight = (float*)m_pVertexMemory;
|
||||
desc.m_pBoneMatrixIndex = (unsigned char*)m_pVertexMemory;
|
||||
desc.m_pTangentS = (float*)m_pVertexMemory;
|
||||
desc.m_pTangentT = (float*)m_pVertexMemory;
|
||||
desc.m_pUserData = (float*)m_pVertexMemory;
|
||||
desc.m_NumBoneWeights = 2;
|
||||
|
||||
desc.m_VertexSize_Position = 0;
|
||||
desc.m_VertexSize_BoneWeight = 0;
|
||||
desc.m_VertexSize_BoneMatrixIndex = 0;
|
||||
desc.m_VertexSize_Normal = 0;
|
||||
desc.m_VertexSize_Color = 0;
|
||||
for( i=0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ )
|
||||
desc.m_VertexSize_TexCoord[i] = 0;
|
||||
desc.m_VertexSize_TangentS = 0;
|
||||
desc.m_VertexSize_TangentT = 0;
|
||||
desc.m_VertexSize_UserData = 0;
|
||||
desc.m_ActualVertexSize = 0; // Size of the vertices.. Some of the m_VertexSize_ elements above
|
||||
|
||||
desc.m_nFirstVertex = 0;
|
||||
desc.m_nIndexSize = 0;
|
||||
}
|
||||
|
||||
void CMeshDx10::UnlockMesh( int numVerts, int numIndices, MeshDesc_t& desc )
|
||||
{
|
||||
}
|
||||
|
||||
void CMeshDx10::ModifyBeginEx( bool bReadOnly, int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc )
|
||||
{
|
||||
// Who cares about the data?
|
||||
desc.m_pPosition = (float*)m_pVertexMemory;
|
||||
desc.m_pNormal = (float*)m_pVertexMemory;
|
||||
desc.m_pColor = m_pVertexMemory;
|
||||
int i;
|
||||
for ( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i)
|
||||
desc.m_pTexCoord[i] = (float*)m_pVertexMemory;
|
||||
desc.m_pIndices = (unsigned short*)m_pVertexMemory;
|
||||
|
||||
desc.m_pBoneWeight = (float*)m_pVertexMemory;
|
||||
desc.m_pBoneMatrixIndex = (unsigned char*)m_pVertexMemory;
|
||||
desc.m_pTangentS = (float*)m_pVertexMemory;
|
||||
desc.m_pTangentT = (float*)m_pVertexMemory;
|
||||
desc.m_pUserData = (float*)m_pVertexMemory;
|
||||
desc.m_NumBoneWeights = 2;
|
||||
|
||||
desc.m_VertexSize_Position = 0;
|
||||
desc.m_VertexSize_BoneWeight = 0;
|
||||
desc.m_VertexSize_BoneMatrixIndex = 0;
|
||||
desc.m_VertexSize_Normal = 0;
|
||||
desc.m_VertexSize_Color = 0;
|
||||
for( i=0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ )
|
||||
desc.m_VertexSize_TexCoord[i] = 0;
|
||||
desc.m_VertexSize_TangentS = 0;
|
||||
desc.m_VertexSize_TangentT = 0;
|
||||
desc.m_VertexSize_UserData = 0;
|
||||
desc.m_ActualVertexSize = 0; // Size of the vertices.. Some of the m_VertexSize_ elements above
|
||||
|
||||
desc.m_nFirstVertex = 0;
|
||||
desc.m_nIndexSize = 0;
|
||||
}
|
||||
|
||||
void CMeshDx10::ModifyBegin( int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc )
|
||||
{
|
||||
ModifyBeginEx( false, firstVertex, numVerts, firstIndex, numIndices, desc );
|
||||
}
|
||||
|
||||
void CMeshDx10::ModifyEnd( MeshDesc_t& desc )
|
||||
{
|
||||
}
|
||||
|
||||
// returns the # of vertices (static meshes only)
|
||||
int CMeshDx10::VertexCount() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Sets the primitive type
|
||||
void CMeshDx10::SetPrimitiveType( MaterialPrimitiveType_t type )
|
||||
{
|
||||
}
|
||||
|
||||
// Draws the entire mesh
|
||||
void CMeshDx10::Draw( int firstIndex, int numIndices )
|
||||
{
|
||||
}
|
||||
|
||||
void CMeshDx10::Draw(CPrimList *pPrims, int nPrims)
|
||||
{
|
||||
}
|
||||
|
||||
// Copy verts and/or indices to a mesh builder. This only works for temp meshes!
|
||||
void CMeshDx10::CopyToMeshBuilder(
|
||||
int iStartVert, // Which vertices to copy.
|
||||
int nVerts,
|
||||
int iStartIndex, // Which indices to copy.
|
||||
int nIndices,
|
||||
int indexOffset, // This is added to each index.
|
||||
CMeshBuilder &builder )
|
||||
{
|
||||
}
|
||||
|
||||
// Spews the mesh data
|
||||
void CMeshDx10::Spew( int numVerts, int numIndices, const MeshDesc_t & desc )
|
||||
{
|
||||
}
|
||||
|
||||
void CMeshDx10::ValidateData( int numVerts, int numIndices, const MeshDesc_t & desc )
|
||||
{
|
||||
}
|
||||
|
||||
// gets the associated material
|
||||
IMaterial* CMeshDx10::GetMaterial()
|
||||
{
|
||||
// umm. this don't work none
|
||||
Assert(0);
|
||||
return 0;
|
||||
}
|
||||
289
materialsystem/shaderapidx9/meshdx10.h
Normal file
289
materialsystem/shaderapidx9/meshdx10.h
Normal file
@@ -0,0 +1,289 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
|
||||
#ifndef MESHDX10_H
|
||||
#define MESHDX10_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "meshbase.h"
|
||||
#include "shaderapi/ishaderdevice.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declaration
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ID3D10Buffer;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dx10 implementation of a vertex buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
class CVertexBufferDx10 : public CVertexBufferBase
|
||||
{
|
||||
typedef CVertexBufferBase BaseClass;
|
||||
|
||||
// Methods of IVertexBuffer
|
||||
public:
|
||||
virtual int VertexCount() const;
|
||||
virtual VertexFormat_t GetVertexFormat() const;
|
||||
virtual bool Lock( int nMaxVertexCount, bool bAppend, VertexDesc_t &desc );
|
||||
virtual void Unlock( int nWrittenVertexCount, VertexDesc_t &desc );
|
||||
virtual bool IsDynamic() const;
|
||||
virtual void BeginCastBuffer( VertexFormat_t format );
|
||||
virtual void EndCastBuffer( );
|
||||
virtual int GetRoomRemaining() const;
|
||||
|
||||
// Other public methods
|
||||
public:
|
||||
// constructor, destructor
|
||||
CVertexBufferDx10( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroupName );
|
||||
virtual ~CVertexBufferDx10();
|
||||
|
||||
ID3D10Buffer* GetDx10Buffer() const;
|
||||
int VertexSize() const;
|
||||
|
||||
// Only used by dynamic buffers, indicates the next lock should perform a discard.
|
||||
void Flush();
|
||||
|
||||
protected:
|
||||
// Creates, destroys the index buffer
|
||||
bool Allocate( );
|
||||
void Free();
|
||||
|
||||
ID3D10Buffer *m_pVertexBuffer;
|
||||
VertexFormat_t m_VertexFormat;
|
||||
int m_nVertexCount;
|
||||
int m_nBufferSize;
|
||||
int m_nFirstUnwrittenOffset;
|
||||
bool m_bIsLocked : 1;
|
||||
bool m_bIsDynamic : 1;
|
||||
bool m_bFlush : 1; // Used only for dynamic buffers, indicates to discard the next time
|
||||
|
||||
#ifdef _DEBUG
|
||||
static int s_nBufferCount;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// inline methods for CVertexBufferDx10
|
||||
//-----------------------------------------------------------------------------
|
||||
inline ID3D10Buffer* CVertexBufferDx10::GetDx10Buffer() const
|
||||
{
|
||||
return m_pVertexBuffer;
|
||||
}
|
||||
|
||||
inline int CVertexBufferDx10::VertexSize() const
|
||||
{
|
||||
return VertexFormatSize( m_VertexFormat );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dx10 implementation of an index buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
class CIndexBufferDx10 : public CIndexBufferBase
|
||||
{
|
||||
typedef CIndexBufferBase BaseClass;
|
||||
|
||||
// Methods of IIndexBuffer
|
||||
public:
|
||||
virtual int IndexCount() const;
|
||||
virtual MaterialIndexFormat_t IndexFormat() const;
|
||||
virtual int GetRoomRemaining() const;
|
||||
virtual bool Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t &desc );
|
||||
virtual void Unlock( int nWrittenIndexCount, IndexDesc_t &desc );
|
||||
virtual void ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc );
|
||||
virtual void ModifyEnd( IndexDesc_t& desc );
|
||||
virtual bool IsDynamic() const;
|
||||
virtual void BeginCastBuffer( MaterialIndexFormat_t format );
|
||||
virtual void EndCastBuffer( );
|
||||
|
||||
// Other public methods
|
||||
public:
|
||||
// constructor, destructor
|
||||
CIndexBufferDx10( ShaderBufferType_t type, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroupName );
|
||||
virtual ~CIndexBufferDx10();
|
||||
|
||||
ID3D10Buffer* GetDx10Buffer() const;
|
||||
MaterialIndexFormat_t GetIndexFormat() const;
|
||||
|
||||
// Only used by dynamic buffers, indicates the next lock should perform a discard.
|
||||
void Flush();
|
||||
|
||||
protected:
|
||||
// Creates, destroys the index buffer
|
||||
bool Allocate( );
|
||||
void Free();
|
||||
|
||||
// Returns the size of the index in bytes
|
||||
int IndexSize() const;
|
||||
|
||||
ID3D10Buffer *m_pIndexBuffer;
|
||||
MaterialIndexFormat_t m_IndexFormat;
|
||||
int m_nIndexCount;
|
||||
int m_nBufferSize;
|
||||
int m_nFirstUnwrittenOffset; // Used only for dynamic buffers, indicates where it's safe to write (nooverwrite)
|
||||
bool m_bIsLocked : 1;
|
||||
bool m_bIsDynamic : 1;
|
||||
bool m_bFlush : 1; // Used only for dynamic buffers, indicates to discard the next time
|
||||
|
||||
#ifdef _DEBUG
|
||||
static int s_nBufferCount;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the size of the index in bytes
|
||||
//-----------------------------------------------------------------------------
|
||||
inline int CIndexBufferDx10::IndexSize() const
|
||||
{
|
||||
switch( m_IndexFormat )
|
||||
{
|
||||
default:
|
||||
case MATERIAL_INDEX_FORMAT_UNKNOWN:
|
||||
return 0;
|
||||
case MATERIAL_INDEX_FORMAT_16BIT:
|
||||
return 2;
|
||||
case MATERIAL_INDEX_FORMAT_32BIT:
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
inline ID3D10Buffer* CIndexBufferDx10::GetDx10Buffer() const
|
||||
{
|
||||
return m_pIndexBuffer;
|
||||
}
|
||||
|
||||
inline MaterialIndexFormat_t CIndexBufferDx10::GetIndexFormat() const
|
||||
{
|
||||
return m_IndexFormat;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dx10 implementation of a mesh
|
||||
//-----------------------------------------------------------------------------
|
||||
class CMeshDx10 : public CMeshBase
|
||||
{
|
||||
public:
|
||||
CMeshDx10();
|
||||
virtual ~CMeshDx10();
|
||||
|
||||
// FIXME: Make this work! Unsupported methods of IIndexBuffer
|
||||
virtual bool Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t& desc ) { Assert(0); return false; }
|
||||
virtual void Unlock( int nWrittenIndexCount, IndexDesc_t& desc ) { Assert(0); }
|
||||
virtual int GetRoomRemaining() const { Assert(0); return 0; }
|
||||
virtual void ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc ) { Assert(0); }
|
||||
virtual void ModifyEnd( IndexDesc_t& desc ) { Assert(0); }
|
||||
virtual void Spew( int nIndexCount, const IndexDesc_t & desc ) { Assert(0); }
|
||||
virtual void ValidateData( int nIndexCount, const IndexDesc_t &desc ) { Assert(0); }
|
||||
virtual bool Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc ) { Assert(0); return false; }
|
||||
virtual void Unlock( int nVertexCount, VertexDesc_t &desc ) { Assert(0); }
|
||||
virtual void Spew( int nVertexCount, const VertexDesc_t &desc ) { Assert(0); }
|
||||
virtual void ValidateData( int nVertexCount, const VertexDesc_t & desc ) { Assert(0); }
|
||||
virtual bool IsDynamic() const { Assert(0); return false; }
|
||||
virtual void BeginCastBuffer( MaterialIndexFormat_t format ) { Assert(0); }
|
||||
virtual void BeginCastBuffer( VertexFormat_t format ) { Assert(0); }
|
||||
virtual void EndCastBuffer( ) { Assert(0); }
|
||||
|
||||
void LockMesh( int numVerts, int numIndices, MeshDesc_t& desc );
|
||||
void UnlockMesh( int numVerts, int numIndices, MeshDesc_t& desc );
|
||||
|
||||
void ModifyBeginEx( bool bReadOnly, int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc );
|
||||
void ModifyBegin( int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc );
|
||||
void ModifyEnd( MeshDesc_t& desc );
|
||||
|
||||
// returns the # of vertices (static meshes only)
|
||||
int VertexCount() const;
|
||||
|
||||
virtual void BeginPass( ) {}
|
||||
virtual void RenderPass( const unsigned char *pInstanceCommandBuffer ) {}
|
||||
virtual bool HasColorMesh() const { return false; }
|
||||
virtual bool IsUsingMorphData() const { return false; }
|
||||
virtual bool HasFlexMesh() const { return false; }
|
||||
virtual VertexStreamSpec_t *GetVertexStreamSpec() const { return NULL; }
|
||||
virtual void DrawInstances( MaterialPrimitiveType_t type, int nCount, const MeshInstanceData_t *pInstanceData ) {}
|
||||
|
||||
// Sets the primitive type
|
||||
void SetPrimitiveType( MaterialPrimitiveType_t type );
|
||||
|
||||
// Using vertex ID stream?
|
||||
bool IsUsingVertexID() const { return false; }
|
||||
|
||||
// Using tessellation for subd surfaces?
|
||||
TessellationMode_t GetTessellationType() const { return TESSELLATION_MODE_DISABLED; }
|
||||
|
||||
// Draws the entire mesh
|
||||
void Draw(int firstIndex, int numIndices);
|
||||
void DrawModulated( const Vector4D &vecDiffuseModulation, int firstIndex, int numIndices) {}
|
||||
|
||||
void Draw(CPrimList *pPrims, int nPrims);
|
||||
|
||||
// Copy verts and/or indices to a mesh builder. This only works for temp meshes!
|
||||
virtual void CopyToMeshBuilder(
|
||||
int iStartVert, // Which vertices to copy.
|
||||
int nVerts,
|
||||
int iStartIndex, // Which indices to copy.
|
||||
int nIndices,
|
||||
int indexOffset, // This is added to each index.
|
||||
CMeshBuilder &builder );
|
||||
|
||||
// Spews the mesh data
|
||||
void Spew( int numVerts, int numIndices, const MeshDesc_t & desc );
|
||||
|
||||
void ValidateData( int numVerts, int numIndices, const MeshDesc_t & desc );
|
||||
|
||||
// gets the associated material
|
||||
IMaterial* GetMaterial();
|
||||
|
||||
void SetColorMesh( IMesh *pColorMesh, int nVertexOffset )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual int IndexCount() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual MaterialIndexFormat_t IndexFormat() const
|
||||
{
|
||||
Assert( 0 );
|
||||
return MATERIAL_INDEX_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
virtual void SetFlexMesh( IMesh *pMesh, int nVertexOffset ) {}
|
||||
|
||||
virtual void DisableFlexMesh() {}
|
||||
|
||||
virtual void MarkAsDrawn() {}
|
||||
|
||||
virtual VertexFormat_t GetVertexFormat() const { return VERTEX_POSITION; }
|
||||
|
||||
virtual IMesh *GetMesh()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
VERTEX_BUFFER_SIZE = 1024 * 1024
|
||||
};
|
||||
|
||||
unsigned char* m_pVertexMemory;
|
||||
};
|
||||
|
||||
#endif // MESHDX10_H
|
||||
|
||||
6931
materialsystem/shaderapidx9/meshdx8.cpp
Normal file
6931
materialsystem/shaderapidx9/meshdx8.cpp
Normal file
File diff suppressed because it is too large
Load Diff
157
materialsystem/shaderapidx9/recording.cpp
Normal file
157
materialsystem/shaderapidx9/recording.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
#include "recording.h"
|
||||
#include "shaderapi/IShaderUtil.h"
|
||||
#include "materialsystem/IMaterialSystem.h"
|
||||
#include "ShaderAPIDX8_Global.h"
|
||||
#include "UtlVector.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
#ifdef RECORDING
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Globals
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static CUtlVector<unsigned char> g_pRecordingBuffer;
|
||||
static int g_ArgsRemaining = 0;
|
||||
static int g_CommandStartIdx = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Opens the recording file
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static FILE* OpenRecordingFile()
|
||||
{
|
||||
#ifdef CRASH_RECORDING
|
||||
static FILE *fp = 0;
|
||||
#else
|
||||
FILE* fp = 0;
|
||||
#endif
|
||||
static bool g_CantOpenFile = false;
|
||||
static bool g_NeverOpened = true;
|
||||
if (!g_CantOpenFile)
|
||||
{
|
||||
#ifdef CRASH_RECORDING
|
||||
if( g_NeverOpened )
|
||||
{
|
||||
fp = fopen( "shaderdx8.rec", "wbc" );
|
||||
}
|
||||
#else
|
||||
fp = fopen( "shaderdx8.rec", g_NeverOpened ? "wb" : "ab" );
|
||||
#endif
|
||||
if (!fp)
|
||||
{
|
||||
Warning("Unable to open recording file shaderdx8.rec!\n");
|
||||
g_CantOpenFile = true;
|
||||
}
|
||||
g_NeverOpened = false;
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Writes to the recording file
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define COMMAND_BUFFER_SIZE 32768
|
||||
|
||||
static void WriteRecordingFile()
|
||||
{
|
||||
// Store the command size
|
||||
*(int*)&g_pRecordingBuffer[g_CommandStartIdx] =
|
||||
g_pRecordingBuffer.Size() - g_CommandStartIdx;
|
||||
|
||||
#ifndef CRASH_RECORDING
|
||||
// When not crash recording, flush when buffer gets too big,
|
||||
// or when Present() is called
|
||||
if ((g_pRecordingBuffer.Size() < COMMAND_BUFFER_SIZE) &&
|
||||
(g_pRecordingBuffer[g_CommandStartIdx+4] != DX8_PRESENT))
|
||||
return;
|
||||
#endif
|
||||
|
||||
FILE* fp = OpenRecordingFile();
|
||||
if (fp)
|
||||
{
|
||||
// store the command size
|
||||
fwrite( g_pRecordingBuffer.Base(), 1, g_pRecordingBuffer.Size(), fp );
|
||||
fflush( fp );
|
||||
#ifndef CRASH_RECORDING
|
||||
fclose( fp );
|
||||
#endif
|
||||
}
|
||||
|
||||
g_pRecordingBuffer.RemoveAll();
|
||||
}
|
||||
|
||||
// Write the buffered crap out on shutdown.
|
||||
void FinishRecording()
|
||||
{
|
||||
#ifndef CRASH_RECORDING
|
||||
FILE* fp = OpenRecordingFile();
|
||||
if (fp)
|
||||
{
|
||||
// store the command size
|
||||
fwrite( g_pRecordingBuffer.Base(), 1, g_pRecordingBuffer.Size(), fp );
|
||||
fflush( fp );
|
||||
}
|
||||
|
||||
g_pRecordingBuffer.RemoveAll();
|
||||
#endif
|
||||
}
|
||||
|
||||
// set this to true in the debugger to actually record commands.
|
||||
static bool g_bDoRecord = true;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Records a command
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void RecordCommand( RecordingCommands_t cmd, int numargs )
|
||||
{
|
||||
if( !g_bDoRecord )
|
||||
{
|
||||
return;
|
||||
}
|
||||
Assert( g_ArgsRemaining == 0 );
|
||||
|
||||
g_CommandStartIdx = g_pRecordingBuffer.AddMultipleToTail( 6 );
|
||||
|
||||
// save space for the total command size
|
||||
g_pRecordingBuffer[g_CommandStartIdx+4] = cmd;
|
||||
g_pRecordingBuffer[g_CommandStartIdx+5] = numargs;
|
||||
g_ArgsRemaining = numargs;
|
||||
if (g_ArgsRemaining == 0)
|
||||
WriteRecordingFile();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Records an argument for a command, flushes when the command is done
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void RecordArgument( void const* pMemory, int size )
|
||||
{
|
||||
if( !g_bDoRecord )
|
||||
{
|
||||
return;
|
||||
}
|
||||
Assert( g_ArgsRemaining > 0 );
|
||||
int tail = g_pRecordingBuffer.Size();
|
||||
g_pRecordingBuffer.AddMultipleToTail( size );
|
||||
memcpy( &g_pRecordingBuffer[tail], pMemory, size );
|
||||
if (--g_ArgsRemaining == 0)
|
||||
WriteRecordingFile();
|
||||
}
|
||||
|
||||
|
||||
#endif // RECORDING
|
||||
209
materialsystem/shaderapidx9/recording.h
Normal file
209
materialsystem/shaderapidx9/recording.h
Normal file
@@ -0,0 +1,209 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef RECORDING_H
|
||||
#define RECORDING_H
|
||||
#pragma once
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Use this to put us into a 'recording' mode
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//#define RECORDING
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Uncomment these to record special frames in the recording
|
||||
// that reset the entire render state.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//#define RECORD_KEYFRAMES 1
|
||||
#define KEYFRAME_INTERVAL 100 // number of actual frames between each keyframe
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Use this to allow us to record crashes (write every command immediately)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//#define CRASH_RECORDING
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Use this to record textures (checkboards are used for textures otherwise)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define RECORD_TEXTURES
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Use this to record debug strings . .these are only useful if you are doing "playback -list"
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define RECORD_DEBUG_STRINGS
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Recording state, if you change this, change the table in playback/playback.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
enum RecordingCommands_t
|
||||
{
|
||||
DX8_CREATE_DEVICE = 0,
|
||||
DX8_DESTROY_DEVICE,
|
||||
DX8_RESET,
|
||||
DX8_SHOW_CURSOR,
|
||||
DX8_BEGIN_SCENE,
|
||||
DX8_END_SCENE,
|
||||
DX8_PRESENT,
|
||||
DX8_CREATE_TEXTURE,
|
||||
DX8_DESTROY_TEXTURE,
|
||||
DX8_SET_TEXTURE,
|
||||
DX8_SET_TRANSFORM,
|
||||
DX8_CREATE_VERTEX_SHADER,
|
||||
DX8_CREATE_PIXEL_SHADER,
|
||||
DX8_DESTROY_VERTEX_SHADER,
|
||||
DX8_DESTROY_PIXEL_SHADER,
|
||||
DX8_SET_VERTEX_SHADER,
|
||||
DX8_SET_PIXEL_SHADER,
|
||||
DX8_SET_VERTEX_SHADER_CONSTANT,
|
||||
DX8_SET_PIXEL_SHADER_CONSTANT,
|
||||
DX8_SET_MATERIAL,
|
||||
DX8_LIGHT_ENABLE,
|
||||
DX8_SET_LIGHT,
|
||||
DX8_SET_VIEWPORT,
|
||||
DX8_CLEAR,
|
||||
DX8_VALIDATE_DEVICE,
|
||||
DX8_SET_RENDER_STATE,
|
||||
DX8_SET_TEXTURE_STAGE_STATE,
|
||||
|
||||
DX8_CREATE_VERTEX_BUFFER,
|
||||
DX8_DESTROY_VERTEX_BUFFER,
|
||||
DX8_LOCK_VERTEX_BUFFER,
|
||||
DX8_VERTEX_DATA,
|
||||
DX8_UNLOCK_VERTEX_BUFFER,
|
||||
|
||||
DX8_CREATE_INDEX_BUFFER,
|
||||
DX8_DESTROY_INDEX_BUFFER,
|
||||
DX8_LOCK_INDEX_BUFFER,
|
||||
DX8_INDEX_DATA,
|
||||
DX8_UNLOCK_INDEX_BUFFER,
|
||||
|
||||
DX8_SET_STREAM_SOURCE,
|
||||
DX8_SET_INDICES,
|
||||
DX8_DRAW_PRIMITIVE,
|
||||
DX8_DRAW_INDEXED_PRIMITIVE,
|
||||
|
||||
DX8_LOCK_TEXTURE,
|
||||
DX8_UNLOCK_TEXTURE,
|
||||
|
||||
DX8_KEYFRAME, // isn't actually a dx8 command, used to help find particular frames
|
||||
|
||||
DX8_SET_TEXTURE_DATA,
|
||||
DX8_BLIT_TEXTURE_BITS,
|
||||
|
||||
DX8_GET_DEVICE_CAPS,
|
||||
DX8_GET_ADAPTER_IDENTIFIER,
|
||||
|
||||
DX8_HARDWARE_SYNC,
|
||||
|
||||
DX8_COPY_FRAMEBUFFER_TO_TEXTURE,
|
||||
DX8_DEBUG_STRING,
|
||||
DX8_CREATE_DEPTH_TEXTURE,
|
||||
DX8_DESTROY_DEPTH_TEXTURE,
|
||||
DX8_SET_RENDER_TARGET,
|
||||
|
||||
DX8_TEST_COOPERATIVE_LEVEL,
|
||||
|
||||
DX8_SET_VERTEX_BUFFER_FORMAT, // isn't actually a dx8 command. . let's playback know what format a buffer is for listing info
|
||||
|
||||
DX8_SET_SAMPLER_STATE,
|
||||
DX8_SET_VERTEX_DECLARATION,
|
||||
DX8_CREATE_VERTEX_DECLARATION,
|
||||
DX8_SET_FVF,
|
||||
DX8_SET_CLIP_PLANE,
|
||||
|
||||
DX8_SYNC_TOKEN,
|
||||
|
||||
DX8_LOCK_VERTEX_TEXTURE,
|
||||
DX8_UNLOCK_VERTEX_TEXTURE,
|
||||
|
||||
DX8_SET_SCISSOR_RECT,
|
||||
|
||||
DX8_NUM_RECORDING_COMMANDS
|
||||
};
|
||||
|
||||
#ifdef RECORDING
|
||||
|
||||
void RecordCommand( RecordingCommands_t cmd, int numargs );
|
||||
void RecordArgument( void const* pMemory, int size );
|
||||
void FinishRecording( void );
|
||||
|
||||
inline void RecordInt( int i )
|
||||
{
|
||||
RecordArgument( &i, sizeof(int) );
|
||||
}
|
||||
|
||||
inline void RecordFloat( float f )
|
||||
{
|
||||
RecordArgument( &f, sizeof(float) );
|
||||
}
|
||||
|
||||
# define RECORD_COMMAND( _cmd, _numargs ) RecordCommand( _cmd, _numargs )
|
||||
# define RECORD_INT( _int ) RecordInt( _int )
|
||||
# define RECORD_FLOAT( _float ) RecordFloat( _float )
|
||||
# define RECORD_STRING( _string ) RecordArgument( _string, strlen(_string) + 1 )
|
||||
# define RECORD_STRUCT( _struct, _size ) RecordArgument( _struct, _size )
|
||||
|
||||
# define RECORD_RENDER_STATE( _state, _val ) \
|
||||
RECORD_COMMAND( DX8_SET_RENDER_STATE, 2 ); \
|
||||
RECORD_INT( _state ); \
|
||||
RECORD_INT( _val )
|
||||
|
||||
# define RECORD_TEXTURE_STAGE_STATE( _stage, _state, _val ) \
|
||||
RECORD_COMMAND( DX8_SET_TEXTURE_STAGE_STATE, 3 ); \
|
||||
RECORD_INT( _stage ); \
|
||||
RECORD_INT( _state ); \
|
||||
RECORD_INT( _val )
|
||||
|
||||
# define RECORD_SAMPLER_STATE( _stage, _state, _val ) \
|
||||
RECORD_COMMAND( DX8_SET_SAMPLER_STATE, 3 ); \
|
||||
RECORD_INT( _stage ); \
|
||||
RECORD_INT( _state ); \
|
||||
RECORD_INT( _val )
|
||||
|
||||
# define RECORD_SAMPLER_STATES( _sampler, _addressU, _addressV, _addressW, _minFilter, _magFilter, _mipFilter ) \
|
||||
RECORD_COMMAND( DX8_SET_SAMPLER_STATE, 7 ); \
|
||||
RECORD_INT( _sampler ); \
|
||||
RECORD_INT( _addressU ); \
|
||||
RECORD_INT( _addressV ); \
|
||||
RECORD_INT( _addressW ); \
|
||||
RECORD_INT( _minFilter ); \
|
||||
RECORD_INT( _magFilter ); \
|
||||
RECORD_INT( _mipFilter )
|
||||
|
||||
# ifdef RECORD_DEBUG_STRINGS
|
||||
# define RECORD_DEBUG_STRING( _str ) \
|
||||
RECORD_COMMAND( DX8_DEBUG_STRING, 1 ); \
|
||||
RECORD_STRING( _str )
|
||||
# else
|
||||
# define RECORD_DEBUG_STRING( _str ) 0
|
||||
# endif
|
||||
|
||||
#else // not RECORDING
|
||||
|
||||
# undef RECORD_TEXTURES
|
||||
|
||||
# define RECORD_COMMAND( _cmd, _numargs ) 0
|
||||
# define RECORD_INT( _int ) 0
|
||||
# define RECORD_FLOAT( _float ) 0
|
||||
# define RECORD_STRING( _string ) 0
|
||||
# define RECORD_STRUCT( _struct, _size ) 0
|
||||
# define RECORD_RENDER_STATE( _state, _val ) 0
|
||||
# define RECORD_TEXTURE_STAGE_STATE( _stage, _state, _val ) 0
|
||||
# define RECORD_SAMPLER_STATE( _stage, _state, _val ) 0
|
||||
# define RECORD_SAMPLER_STATES( _sampler, _addressU, _addressV, _addressW, _minFilter, _magFilter, _mipFilter ) 0
|
||||
# define RECORD_DEBUG_STRING( _str ) 0
|
||||
|
||||
#endif // RECORDING
|
||||
|
||||
#endif // RECORDING_H
|
||||
112
materialsystem/shaderapidx9/shaderapi_global.h
Normal file
112
materialsystem/shaderapidx9/shaderapi_global.h
Normal file
@@ -0,0 +1,112 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERAPI_GLOBAL_H
|
||||
#define SHADERAPI_GLOBAL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier0/threadtools.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Use this to fill in structures with the current board state
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef _DEBUG
|
||||
#define DEBUG_BOARD_STATE 0
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IShaderUtil;
|
||||
class CShaderDeviceBase;
|
||||
class CShaderDeviceMgrBase;
|
||||
class CShaderAPIBase;
|
||||
class IShaderShadow;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global interfaces
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef _PS3
|
||||
#include "shaderutil_ps3nonvirt.h"
|
||||
#define g_pShaderUtil ShaderUtil()
|
||||
inline CPs3NonVirt_IShaderUtil * ShaderUtil()
|
||||
{
|
||||
return ( CPs3NonVirt_IShaderUtil * ) 1;
|
||||
}
|
||||
#else
|
||||
extern IShaderUtil* g_pShaderUtil;
|
||||
inline IShaderUtil* ShaderUtil()
|
||||
{
|
||||
return g_pShaderUtil;
|
||||
}
|
||||
#endif
|
||||
|
||||
extern CShaderDeviceBase *g_pShaderDevice;
|
||||
extern CShaderDeviceMgrBase *g_pShaderDeviceMgr;
|
||||
extern CShaderAPIBase *g_pShaderAPI;
|
||||
extern IShaderShadow *g_pShaderShadow;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Memory debugging
|
||||
//-----------------------------------------------------------------------------
|
||||
#define MEM_ALLOC_D3D_CREDIT() MEM_ALLOC_CREDIT_("D3D:" __FILE__)
|
||||
#define BEGIN_D3D_ALLOCATION() MemAlloc_PushAllocDbgInfo("D3D:" __FILE__, __LINE__)
|
||||
#define END_D3D_ALLOCATION() MemAlloc_PopAllocDbgInfo()
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Threading
|
||||
//-----------------------------------------------------------------------------
|
||||
extern bool g_bUseShaderMutex;
|
||||
|
||||
//#define USE_SHADER_DISALLOW 1
|
||||
//#define STRICT_MT_SHADERAPI 1
|
||||
|
||||
#if defined(_DEBUG)
|
||||
#if !defined(STRICT_MT_SHADERAPI)
|
||||
#define UNCONDITIONAL_MT_SHADERAPI 1
|
||||
#endif
|
||||
#else
|
||||
#if !defined(STRICT_MT_SHADERAPI) && !defined(UNCONDITIONAL_MT_SHADERAPI)
|
||||
#define ST_SHADERAPI 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(ST_SHADERAPI)
|
||||
typedef CThreadNullMutex CShaderMutex;
|
||||
#elif defined(STRICT_MT_SHADERAPI)
|
||||
typedef CThreadConditionalMutex<CThreadTerminalMutex<CThreadFastMutex>, &g_bUseShaderMutex> CShaderMutex;
|
||||
#elif defined(UNCONDITIONAL_MT_SHADERAPI)
|
||||
typedef CThreadFastMutex CShaderMutex;
|
||||
#else
|
||||
typedef CThreadConditionalMutex<CThreadFastMutex, &g_bUseShaderMutex> CShaderMutex;
|
||||
#endif
|
||||
|
||||
extern CShaderMutex g_ShaderMutex;
|
||||
|
||||
extern bool g_bShaderAccessDisallowed;
|
||||
|
||||
#ifdef USE_SHADER_DISALLOW
|
||||
#define TestShaderPermission() do { if ( (!g_bUseShaderMutex || g_ShaderMutex.GetDepth() == 0) && g_bShaderAccessDisallowed ) { ExecuteOnce( DebuggerBreakIfDebugging() ); } } while (0)
|
||||
#define LOCK_SHADERAPI() TestShaderPermission(); AUTO_LOCK_( CShaderMutex, g_ShaderMutex )
|
||||
#define LockShaderMutex() TestShaderPermission(); g_ShaderMutex.Lock();
|
||||
#define UnlockShaderMutex() TestShaderPermission(); g_ShaderMutex.Unlock();
|
||||
#else
|
||||
#define TestShaderPermission() ((void)0)
|
||||
#define LOCK_SHADERAPI() ((void)0)
|
||||
#define LockShaderMutex() ((void)0)
|
||||
#define UnlockShaderMutex() ((void)0)
|
||||
#endif
|
||||
|
||||
#endif // SHADERAPI_GLOBAL_H
|
||||
45
materialsystem/shaderapidx9/shaderapibase.cpp
Normal file
45
materialsystem/shaderapidx9/shaderapibase.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#undef PROTECTED_THINGS_ENABLE // prevent warnings when windows.h gets included
|
||||
|
||||
#include "shaderapibase.h"
|
||||
#include "shaderapi/ishaderutil.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// The Base implementation of the shader render class
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CShaderAPIBase::CShaderAPIBase()
|
||||
{
|
||||
}
|
||||
|
||||
CShaderAPIBase::~CShaderAPIBase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Methods of IShaderDynamicAPI
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderAPIBase::GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo )
|
||||
{
|
||||
g_pShaderUtil->GetCurrentColorCorrection( pInfo );
|
||||
}
|
||||
|
||||
|
||||
85
materialsystem/shaderapidx9/shaderapibase.h
Normal file
85
materialsystem/shaderapidx9/shaderapibase.h
Normal file
@@ -0,0 +1,85 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERRENDERBASE_H
|
||||
#define SHADERRENDERBASE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
#include "shaderapi_global.h"
|
||||
#include "locald3dtypes.h"
|
||||
|
||||
// Colors for PIX graphs
|
||||
#define PIX_VALVE_ORANGE 0xFFF5940F
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Base implementation of the shader rendering interface
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderAPIBase : public IShaderAPI
|
||||
{
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderAPIBase();
|
||||
virtual ~CShaderAPIBase();
|
||||
|
||||
// Called when the device is initializing or shutting down
|
||||
virtual bool OnDeviceInit() = 0;
|
||||
virtual void OnDeviceShutdown() = 0;
|
||||
|
||||
// Pix events
|
||||
virtual void BeginPIXEvent( unsigned long color, const char *szName ) = 0;
|
||||
virtual void EndPIXEvent() = 0;
|
||||
virtual void AdvancePIXFrame() = 0;
|
||||
|
||||
// Release, reacquire objects
|
||||
virtual void ReleaseShaderObjects( bool bReleaseManagedResources = true ) = 0;
|
||||
virtual void RestoreShaderObjects() = 0;
|
||||
|
||||
// Resets the render state to its well defined initial value
|
||||
virtual void ResetRenderState( bool bFullReset = true ) = 0;
|
||||
|
||||
// Returns a d3d texture associated with a texture handle
|
||||
virtual IDirect3DBaseTexture* GetD3DTexture( ShaderAPITextureHandle_t hTexture ) = 0;
|
||||
|
||||
// Queues a non-full reset of render state next BeginFrame.
|
||||
virtual void QueueResetRenderState() = 0;
|
||||
|
||||
// Methods of IShaderDynamicAPI
|
||||
public:
|
||||
virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo );
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Pix measurement class
|
||||
//-----------------------------------------------------------------------------
|
||||
class CPixEvent
|
||||
{
|
||||
public:
|
||||
CPixEvent( unsigned long color, const char *szName )
|
||||
{
|
||||
if ( g_pShaderAPI )
|
||||
g_pShaderAPI->BeginPIXEvent( color, szName );
|
||||
}
|
||||
|
||||
~CPixEvent()
|
||||
{
|
||||
if ( g_pShaderAPI )
|
||||
g_pShaderAPI->EndPIXEvent();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // SHADERRENDERBASE_H
|
||||
1445
materialsystem/shaderapidx9/shaderapidx10.cpp
Normal file
1445
materialsystem/shaderapidx9/shaderapidx10.cpp
Normal file
File diff suppressed because it is too large
Load Diff
869
materialsystem/shaderapidx9/shaderapidx10.h
Normal file
869
materialsystem/shaderapidx9/shaderapidx10.h
Normal file
@@ -0,0 +1,869 @@
|
||||
//===== Copyright © 1996-2008, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERAPIDX10_H
|
||||
#define SHADERAPIDX10_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <d3d10.h>
|
||||
|
||||
#include "shaderapibase.h"
|
||||
#include "materialsystem/idebugtextureinfo.h"
|
||||
#include "meshdx10.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
struct MaterialSystemHardwareIdentifier_t;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// DX10 enumerations that don't appear to exist
|
||||
//-----------------------------------------------------------------------------
|
||||
#define MAX_DX10_VIEWPORTS 16
|
||||
#define MAX_DX10_STREAMS 16
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A record describing the state on the board
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ShaderIndexBufferStateDx10_t
|
||||
{
|
||||
ID3D10Buffer *m_pBuffer;
|
||||
DXGI_FORMAT m_Format;
|
||||
UINT m_nOffset;
|
||||
|
||||
bool operator!=( const ShaderIndexBufferStateDx10_t& src ) const
|
||||
{
|
||||
return memcmp( this, &src, sizeof(ShaderIndexBufferStateDx10_t) ) != 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct ShaderVertexBufferStateDx10_t
|
||||
{
|
||||
ID3D10Buffer *m_pBuffer;
|
||||
UINT m_nStride;
|
||||
UINT m_nOffset;
|
||||
};
|
||||
|
||||
struct ShaderInputLayoutStateDx10_t
|
||||
{
|
||||
VertexShaderHandle_t m_hVertexShader;
|
||||
VertexFormat_t m_pVertexDecl[ MAX_DX10_STREAMS ];
|
||||
};
|
||||
|
||||
struct ShaderStateDx10_t
|
||||
{
|
||||
int m_nViewportCount;
|
||||
D3D10_VIEWPORT m_pViewports[ MAX_DX10_VIEWPORTS ];
|
||||
FLOAT m_ClearColor[4];
|
||||
ShaderRasterState_t m_RasterState;
|
||||
ID3D10RasterizerState *m_pRasterState;
|
||||
ID3D10VertexShader *m_pVertexShader;
|
||||
ID3D10GeometryShader *m_pGeometryShader;
|
||||
ID3D10PixelShader *m_pPixelShader;
|
||||
ShaderVertexBufferStateDx10_t m_pVertexBuffer[ MAX_DX10_STREAMS ];
|
||||
ShaderIndexBufferStateDx10_t m_IndexBuffer;
|
||||
ShaderInputLayoutStateDx10_t m_InputLayout;
|
||||
D3D10_PRIMITIVE_TOPOLOGY m_Topology;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Commit function helper class
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef void (*StateCommitFunc_t)( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t ¤tState, bool bForce );
|
||||
|
||||
class CFunctionCommit
|
||||
{
|
||||
public:
|
||||
CFunctionCommit();
|
||||
~CFunctionCommit();
|
||||
|
||||
void Init( int nFunctionCount );
|
||||
|
||||
// Methods related to queuing functions to be called per-(pMesh->Draw call) or per-pass
|
||||
void ClearAllCommitFuncs( );
|
||||
void CallCommitFuncs( bool bForce );
|
||||
bool IsCommitFuncInUse( int nFunc ) const;
|
||||
void MarkCommitFuncInUse( int nFunc );
|
||||
void AddCommitFunc( StateCommitFunc_t f );
|
||||
void CallCommitFuncs( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t ¤tState, bool bForce = false );
|
||||
|
||||
private:
|
||||
// A list of state commit functions to run as per-draw call commit time
|
||||
unsigned char* m_pCommitFlags;
|
||||
int m_nCommitBufferSize;
|
||||
CUtlVector< StateCommitFunc_t > m_CommitFuncs;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Dx10 implementation of the shader API
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderAPIDx10 : public CShaderAPIBase, public IDebugTextureInfo
|
||||
{
|
||||
typedef CShaderAPIBase BaseClass;
|
||||
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderAPIDx10( );
|
||||
virtual ~CShaderAPIDx10();
|
||||
|
||||
// Methods of IShaderAPI
|
||||
// NOTE: These methods have been ported over
|
||||
public:
|
||||
virtual void SetViewports( int nCount, const ShaderViewport_t* pViewports );
|
||||
virtual int GetViewports( ShaderViewport_t* pViewports, int nMax ) const;
|
||||
virtual void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight );
|
||||
virtual void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b );
|
||||
virtual void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a );
|
||||
virtual void SetRasterState( const ShaderRasterState_t& state );
|
||||
virtual void BindVertexShader( VertexShaderHandle_t hVertexShader );
|
||||
virtual void BindGeometryShader( GeometryShaderHandle_t hGeometryShader );
|
||||
virtual void BindPixelShader( PixelShaderHandle_t hPixelShader );
|
||||
virtual void BindVertexBuffer( int nStreamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 );
|
||||
virtual void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes );
|
||||
virtual void Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount );
|
||||
virtual void OnPresent( void );
|
||||
virtual void UpdateGameTime( float ) {}
|
||||
|
||||
// Methods of IShaderDynamicAPI
|
||||
public:
|
||||
virtual void GetBackBufferDimensions( int& nWidth, int& nHeight ) const;
|
||||
virtual void GetCurrentRenderTargetDimensions( int& nWidth, int& nHeight ) const;
|
||||
virtual void GetCurrentViewport( int& nX, int& nY, int& nWidth, int& nHeight ) const;
|
||||
virtual void SetScreenSizeForVPOS( int pshReg = 32 );
|
||||
virtual void SetVSNearAndFarZ( int vshReg );
|
||||
virtual float GetFarZ();
|
||||
|
||||
public:
|
||||
// Methods of CShaderAPIBase
|
||||
virtual bool OnDeviceInit() { ResetRenderState(); return true; }
|
||||
virtual void OnDeviceShutdown() {}
|
||||
virtual void ReleaseShaderObjects( bool bReleaseManagedResources = true );
|
||||
virtual void RestoreShaderObjects();
|
||||
virtual void BeginPIXEvent( unsigned long color, const char *szName ) {}
|
||||
virtual void EndPIXEvent() {}
|
||||
virtual void AdvancePIXFrame() {}
|
||||
|
||||
// NOTE: These methods have not been ported over.
|
||||
// IDebugTextureInfo implementation.
|
||||
public:
|
||||
|
||||
virtual bool IsDebugTextureListFresh( int numFramesAllowed = 1 ) { return false; }
|
||||
virtual void EnableDebugTextureList( bool bEnable ) {}
|
||||
virtual void EnableGetAllTextures( bool bEnable ) {}
|
||||
virtual KeyValues* GetDebugTextureList() { return NULL; }
|
||||
virtual int GetTextureMemoryUsed( TextureMemoryType eTextureMemory ) { return 0; }
|
||||
virtual bool SetDebugTextureRendering( bool bEnable ) { return false; }
|
||||
|
||||
public:
|
||||
// Other public methods
|
||||
void Unbind( VertexShaderHandle_t hShader );
|
||||
void Unbind( GeometryShaderHandle_t hShader );
|
||||
void Unbind( PixelShaderHandle_t hShader );
|
||||
void UnbindVertexBuffer( ID3D10Buffer *pBuffer );
|
||||
void UnbindIndexBuffer( ID3D10Buffer *pBuffer );
|
||||
|
||||
void PrintfVA( char *fmt, va_list vargs ) {}
|
||||
void Printf( char *fmt, ... ) {}
|
||||
float Knob( char *knobname, float *setvalue = NULL ) { return 0.0f;}
|
||||
|
||||
private:
|
||||
|
||||
// Returns a d3d texture associated with a texture handle
|
||||
virtual IDirect3DBaseTexture* GetD3DTexture( ShaderAPITextureHandle_t hTexture ) { Assert(0); return NULL; }
|
||||
virtual void QueueResetRenderState() {}
|
||||
|
||||
void SetTopology( MaterialPrimitiveType_t topology );
|
||||
|
||||
virtual bool DoRenderTargetsNeedSeparateDepthBuffer() const;
|
||||
|
||||
void SetHardwareGammaRamp( float fGamma )
|
||||
{
|
||||
}
|
||||
|
||||
// Used to clear the transition table when we know it's become invalid.
|
||||
void ClearSnapshots();
|
||||
|
||||
// Sets the mode...
|
||||
bool SetMode( void* hwnd, int nAdapter, const ShaderDeviceInfo_t &info )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void ChangeVideoMode( const ShaderDeviceInfo_t &info )
|
||||
{
|
||||
}
|
||||
|
||||
// Called when the dx support level has changed
|
||||
virtual void DXSupportLevelChanged( int nDXLevel ) {}
|
||||
|
||||
virtual void EnableUserClipTransformOverride( bool bEnable ) {}
|
||||
virtual void UserClipTransform( const VMatrix &worldToView ) {}
|
||||
virtual bool GetUserClipTransform( VMatrix &worldToView ) { return false; }
|
||||
|
||||
// Sets the default *dynamic* state
|
||||
void SetDefaultState( );
|
||||
|
||||
// Returns the snapshot id for the shader state
|
||||
StateSnapshot_t TakeSnapshot( );
|
||||
|
||||
// Returns true if the state snapshot is transparent
|
||||
bool IsTranslucent( StateSnapshot_t id ) const;
|
||||
bool IsAlphaTested( StateSnapshot_t id ) const;
|
||||
bool UsesVertexAndPixelShaders( StateSnapshot_t id ) const;
|
||||
virtual bool IsDepthWriteEnabled( StateSnapshot_t id ) const;
|
||||
|
||||
// Gets the vertex format for a set of snapshot ids
|
||||
VertexFormat_t ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds ) const;
|
||||
|
||||
// Gets the vertex format for a set of snapshot ids
|
||||
VertexFormat_t ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds ) const;
|
||||
|
||||
// Begins a rendering pass that uses a state snapshot
|
||||
void BeginPass( StateSnapshot_t snapshot );
|
||||
|
||||
// Uses a state snapshot
|
||||
void UseSnapshot( StateSnapshot_t snapshot );
|
||||
|
||||
// Sets the lights
|
||||
void SetLights( int lightNum, const LightDesc_t* pDesc );
|
||||
void SetLightingState( const MaterialLightingState_t &state );
|
||||
void SetAmbientLightCube( Vector4D cube[6] );
|
||||
virtual void SetLightingOrigin( Vector vLightingOrigin ) {}
|
||||
|
||||
// Render state for the ambient light cube (vertex shaders)
|
||||
virtual void GetDX9LightState( LightState_t *state ) const {}
|
||||
|
||||
void CopyRenderTargetToTexture( ShaderAPITextureHandle_t texID )
|
||||
{
|
||||
}
|
||||
|
||||
void CopyRenderTargetToTextureEx( ShaderAPITextureHandle_t texID, int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect )
|
||||
{
|
||||
}
|
||||
|
||||
// Set the number of bone weights
|
||||
void SetNumBoneWeights( int numBones );
|
||||
|
||||
// Flushes any primitives that are buffered
|
||||
void FlushBufferedPrimitives();
|
||||
|
||||
// Creates/destroys Mesh
|
||||
IMesh* CreateStaticMesh( VertexFormat_t fmt, const char *pTextureBudgetGroup, IMaterial * pMaterial = NULL, VertexStreamSpec_t *pStreamSpec = NULL );
|
||||
void DestroyStaticMesh( IMesh* mesh );
|
||||
|
||||
// Gets the dynamic mesh; note that you've got to render the mesh
|
||||
// before calling this function a second time. Clients should *not*
|
||||
// call DestroyStaticMesh on the mesh returned by this call.
|
||||
IMesh* GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride );
|
||||
IMesh* GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t fmt, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride );
|
||||
IVertexBuffer *GetDynamicVertexBuffer( IMaterial* pMaterial, bool buffered )
|
||||
{
|
||||
Assert( 0 );
|
||||
return NULL;
|
||||
}
|
||||
IMesh* GetFlexMesh();
|
||||
|
||||
// Renders a single pass of a material
|
||||
void RenderPass( const unsigned char *pInstanceCommandBuffer, int nPass, int nPassCount );
|
||||
|
||||
// stuff related to matrix stacks
|
||||
void MatrixMode( MaterialMatrixMode_t matrixMode );
|
||||
void PushMatrix();
|
||||
void PopMatrix();
|
||||
void LoadMatrix( float *m );
|
||||
void LoadBoneMatrix( int boneIndex, const float *m ) {}
|
||||
void MultMatrix( float *m );
|
||||
void MultMatrixLocal( float *m );
|
||||
void GetMatrix( MaterialMatrixMode_t matrixMode, float *dst );
|
||||
void LoadIdentity( void );
|
||||
void LoadCameraToWorld( void );
|
||||
void Ortho( double left, double top, double right, double bottom, double zNear, double zFar );
|
||||
void PerspectiveX( double fovx, double aspect, double zNear, double zFar );
|
||||
void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right );
|
||||
void PickMatrix( int x, int y, int width, int height );
|
||||
void Rotate( float angle, float x, float y, float z );
|
||||
void Translate( float x, float y, float z );
|
||||
void Scale( float x, float y, float z );
|
||||
void ScaleXY( float x, float y );
|
||||
|
||||
void Viewport( int x, int y, int width, int height );
|
||||
void GetViewport( int& x, int& y, int& width, int& height ) const;
|
||||
|
||||
// Fog methods...
|
||||
void FogMode( MaterialFogMode_t fogMode );
|
||||
void FogStart( float fStart );
|
||||
void FogEnd( float fEnd );
|
||||
void SetFogZ( float fogZ );
|
||||
void FogMaxDensity( float flMaxDensity );
|
||||
void GetFogDistances( float *fStart, float *fEnd, float *fFogZ );
|
||||
void FogColor3f( float r, float g, float b );
|
||||
void FogColor3fv( float const* rgb );
|
||||
void FogColor3ub( unsigned char r, unsigned char g, unsigned char b );
|
||||
void FogColor3ubv( unsigned char const* rgb );
|
||||
|
||||
virtual void SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b );
|
||||
virtual void SceneFogMode( MaterialFogMode_t fogMode );
|
||||
virtual void GetSceneFogColor( unsigned char *rgb );
|
||||
virtual MaterialFogMode_t GetSceneFogMode( );
|
||||
virtual int GetPixelFogCombo( ); // deprecated. . don't use.
|
||||
|
||||
void SetHeightClipZ( float z );
|
||||
void SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode );
|
||||
|
||||
void SetClipPlane( int index, const float *pPlane );
|
||||
void EnableClipPlane( int index, bool bEnable );
|
||||
|
||||
void SetFastClipPlane( const float *pPlane );
|
||||
void EnableFastClip( bool bEnable );
|
||||
|
||||
// We use smaller dynamic VBs during level transitions, to free up memory
|
||||
virtual int GetCurrentDynamicVBSize( void );
|
||||
virtual void DestroyVertexBuffers( bool bExitingLevel = false );
|
||||
|
||||
// Sets the vertex and pixel shaders
|
||||
void SetVertexShaderIndex( int vshIndex );
|
||||
void SetPixelShaderIndex( int pshIndex );
|
||||
|
||||
// Sets the constant register for vertex and pixel shaders
|
||||
void SetVertexShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false );
|
||||
void SetPixelShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false );
|
||||
|
||||
void SetBooleanVertexShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false )
|
||||
{
|
||||
Assert(0);
|
||||
}
|
||||
|
||||
|
||||
void SetIntegerVertexShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false )
|
||||
{
|
||||
Assert(0);
|
||||
}
|
||||
|
||||
|
||||
void SetBooleanPixelShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false )
|
||||
{
|
||||
Assert(0);
|
||||
}
|
||||
|
||||
void SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false )
|
||||
{
|
||||
Assert(0);
|
||||
}
|
||||
|
||||
bool ShouldWriteDepthToDestAlpha( void ) const
|
||||
{
|
||||
Assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void InvalidateDelayedShaderConstants( void );
|
||||
|
||||
// Gamma<->Linear conversions according to the video hardware we're running on
|
||||
float GammaToLinear_HardwareSpecific( float fGamma ) const
|
||||
{
|
||||
return 0.;
|
||||
}
|
||||
|
||||
float LinearToGamma_HardwareSpecific( float fLinear ) const
|
||||
{
|
||||
return 0.;
|
||||
}
|
||||
|
||||
//Set's the linear->gamma conversion textures to use for this hardware for both srgb writes enabled and disabled(identity)
|
||||
void SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture );
|
||||
|
||||
// Cull mode
|
||||
void CullMode( MaterialCullMode_t cullMode );
|
||||
void FlipCullMode( void );
|
||||
|
||||
// Force writes only when z matches. . . useful for stenciling things out
|
||||
// by rendering the desired Z values ahead of time.
|
||||
void ForceDepthFuncEquals( bool bEnable );
|
||||
|
||||
// Forces Z buffering on or off
|
||||
void OverrideDepthEnable( bool bEnable, bool bDepthEnable );
|
||||
// Forces alpha writes on or off
|
||||
void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable );
|
||||
//forces color writes on or off
|
||||
void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable );
|
||||
|
||||
// Sets the shade mode
|
||||
void ShadeMode( ShaderShadeMode_t mode );
|
||||
|
||||
// Binds a particular material to render with
|
||||
void Bind( IMaterial* pMaterial );
|
||||
|
||||
// Returns the nearest supported format
|
||||
ImageFormat GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired = true ) const;
|
||||
ImageFormat GetNearestRenderTargetFormat( ImageFormat fmt ) const;
|
||||
|
||||
// Sets the texture state
|
||||
void BindTexture( Sampler_t stage, ShaderAPITextureHandle_t textureHandle );
|
||||
|
||||
void BindVertexTexture( VertexTextureSampler_t vtSampler, ShaderAPITextureHandle_t textureHandle );
|
||||
|
||||
void SetRenderTarget( ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle )
|
||||
{
|
||||
}
|
||||
|
||||
void SetRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle )
|
||||
{
|
||||
}
|
||||
|
||||
// Indicates we're going to be modifying this texture
|
||||
// TexImage2D, TexSubImage2D, TexWrap, TexMinFilter, and TexMagFilter
|
||||
// all use the texture specified by this function.
|
||||
void ModifyTexture( ShaderAPITextureHandle_t textureHandle );
|
||||
|
||||
// Texture management methods
|
||||
void TexImage2D( int level, int cubeFace, ImageFormat dstFormat, int zOffset, int width, int height,
|
||||
ImageFormat srcFormat, bool bSrcIsTiled, void *imageData );
|
||||
void TexSubImage2D( int level, int cubeFace, int xOffset, int yOffset, int zOffset, int width, int height,
|
||||
ImageFormat srcFormat, int srcStride, bool bSrcIsTiled, void *imageData );
|
||||
|
||||
bool TexLock( int level, int cubeFaceID, int xOffset, int yOffset,
|
||||
int width, int height, CPixelWriter& writer );
|
||||
void TexUnlock( );
|
||||
|
||||
void UpdateTexture( int xOffset, int yOffset, int w, int h, ShaderAPITextureHandle_t hDstTexture, ShaderAPITextureHandle_t hSrcTexture );
|
||||
|
||||
void *LockTex( ShaderAPITextureHandle_t hTexture );
|
||||
void UnlockTex( ShaderAPITextureHandle_t hTexture );
|
||||
|
||||
// These are bound to the texture, not the texture environment
|
||||
void TexMinFilter( ShaderTexFilterMode_t texFilterMode );
|
||||
void TexMagFilter( ShaderTexFilterMode_t texFilterMode );
|
||||
void TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode );
|
||||
void TexSetPriority( int priority );
|
||||
|
||||
ShaderAPITextureHandle_t CreateTexture(
|
||||
int width,
|
||||
int height,
|
||||
int depth,
|
||||
ImageFormat dstImageFormat,
|
||||
int numMipLevels,
|
||||
int numCopies,
|
||||
int flags,
|
||||
const char *pDebugName,
|
||||
const char *pTextureGroupName );
|
||||
void CreateTextures(
|
||||
ShaderAPITextureHandle_t *pHandles,
|
||||
int count,
|
||||
int width,
|
||||
int height,
|
||||
int depth,
|
||||
ImageFormat dstImageFormat,
|
||||
int numMipLevels,
|
||||
int numCopies,
|
||||
int flags,
|
||||
const char *pDebugName,
|
||||
const char *pTextureGroupName );
|
||||
ShaderAPITextureHandle_t CreateDepthTexture( ImageFormat renderFormat, int width, int height, const char *pDebugName, bool bTexture );
|
||||
void DeleteTexture( ShaderAPITextureHandle_t textureHandle );
|
||||
bool IsTexture( ShaderAPITextureHandle_t textureHandle );
|
||||
bool IsTextureResident( ShaderAPITextureHandle_t textureHandle );
|
||||
|
||||
// stuff that isn't to be used from within a shader
|
||||
void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth );
|
||||
void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth );
|
||||
void PerformFullScreenStencilOperation( void );
|
||||
void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat );
|
||||
virtual void ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride );
|
||||
|
||||
// Selection mode methods
|
||||
int SelectionMode( bool selectionMode );
|
||||
void SelectionBuffer( unsigned int* pBuffer, int size );
|
||||
void ClearSelectionNames( );
|
||||
void LoadSelectionName( int name );
|
||||
void PushSelectionName( int name );
|
||||
void PopSelectionName();
|
||||
|
||||
void FlushHardware();
|
||||
void ResetRenderState( bool bFullReset = true );
|
||||
|
||||
// Can we download textures?
|
||||
virtual bool CanDownloadTextures() const;
|
||||
|
||||
// Board-independent calls, here to unify how shaders set state
|
||||
// Implementations should chain back to IShaderUtil->BindTexture(), etc.
|
||||
|
||||
// Use this to begin and end the frame
|
||||
void BeginFrame();
|
||||
void EndFrame();
|
||||
|
||||
// returns current time
|
||||
double CurrentTime() const;
|
||||
|
||||
// Get the current camera position in world space.
|
||||
void GetWorldSpaceCameraPosition( float * pPos ) const;
|
||||
void GetWorldSpaceCameraDirection( float* pDir ) const;
|
||||
|
||||
void ForceHardwareSync( void );
|
||||
|
||||
int GetCurrentNumBones( void ) const;
|
||||
bool IsHWMorphingEnabled( ) const;
|
||||
TessellationMode_t GetTessellationMode( ) const;
|
||||
int GetCurrentLightCombo( void ) const;
|
||||
int MapLightComboToPSLightCombo( int nLightCombo ) const;
|
||||
MaterialFogMode_t GetCurrentFogType( void ) const; // deprecated. don't use.
|
||||
|
||||
void RecordString( const char *pStr );
|
||||
|
||||
void EvictManagedResources();
|
||||
|
||||
// Get stats on GPU memory usage
|
||||
void GetGPUMemoryStats( GPUMemoryStats &stats );
|
||||
|
||||
// Gets the lightmap dimensions
|
||||
virtual void GetLightmapDimensions( int *w, int *h );
|
||||
|
||||
virtual void SyncToken( const char *pToken );
|
||||
|
||||
// Setup standard vertex shader constants (that don't change)
|
||||
// This needs to be called anytime that overbright changes.
|
||||
virtual void SetStandardVertexShaderConstants( float fOverbright )
|
||||
{
|
||||
}
|
||||
|
||||
// Scissor Rect
|
||||
virtual void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ) {}
|
||||
|
||||
// Reports support for a given CSAA mode
|
||||
bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ) { return false; }
|
||||
|
||||
// Level of anisotropic filtering
|
||||
virtual void SetAnisotropicLevel( int nAnisotropyLevel )
|
||||
{
|
||||
}
|
||||
|
||||
void SetDefaultDynamicState()
|
||||
{
|
||||
}
|
||||
virtual void CommitPixelShaderLighting( int pshReg )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords )
|
||||
{
|
||||
}
|
||||
|
||||
ShaderAPIOcclusionQuery_t CreateOcclusionQueryObject( void )
|
||||
{
|
||||
return INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE;
|
||||
}
|
||||
|
||||
void DestroyOcclusionQueryObject( ShaderAPIOcclusionQuery_t handle )
|
||||
{
|
||||
}
|
||||
|
||||
void BeginOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle )
|
||||
{
|
||||
}
|
||||
|
||||
void EndOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle )
|
||||
{
|
||||
}
|
||||
|
||||
int OcclusionQuery_GetNumPixelsRendered( ShaderAPIOcclusionQuery_t handle, bool bFlush )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void AcquireThreadOwnership() {}
|
||||
virtual void ReleaseThreadOwnership() {}
|
||||
|
||||
virtual bool SupportsBorderColor() const { return false; }
|
||||
virtual bool SupportsFetch4() const { return false; }
|
||||
virtual void EnableBuffer2FramesAhead( bool bEnable ) {}
|
||||
|
||||
virtual void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) {}
|
||||
|
||||
void SetPixelShaderFogParams( int reg )
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool InFlashlightMode() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool InEditorMode() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id );
|
||||
|
||||
float GetSubDHeight();
|
||||
// Binds a standard texture
|
||||
virtual void BindStandardTexture( Sampler_t stage, StandardTextureId_t id )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void BindStandardVertexTexture( VertexTextureSampler_t stage, StandardTextureId_t id )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture )
|
||||
{
|
||||
}
|
||||
|
||||
virtual const FlashlightState_t &GetFlashlightState( VMatrix &worldToTexture ) const
|
||||
{
|
||||
static FlashlightState_t blah;
|
||||
return blah;
|
||||
}
|
||||
|
||||
virtual const FlashlightState_t &GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **pFlashlightDepthTexture ) const
|
||||
{
|
||||
static FlashlightState_t blah;
|
||||
return blah;
|
||||
}
|
||||
|
||||
virtual void GetFlashlightShaderInfo( bool *pShadowsEnabled, bool *pUberLight ) const
|
||||
{
|
||||
*pShadowsEnabled = false;
|
||||
*pUberLight = false;
|
||||
}
|
||||
|
||||
virtual float GetFlashlightAmbientOcclusion( ) const { return 1.0f; }
|
||||
|
||||
virtual void SetModeChangeCallback( ModeChangeCallbackFunc_t func )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual void ClearVertexAndPixelShaderRefCounts()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void PurgeUnusedVertexAndPixelShaders()
|
||||
{
|
||||
}
|
||||
|
||||
// Sets morph target factors
|
||||
virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights )
|
||||
{
|
||||
}
|
||||
|
||||
// NOTE: Stuff after this is added after shipping HL2.
|
||||
ITexture *GetRenderTargetEx( int nRenderTargetID ) const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SetToneMappingScaleLinear( const Vector &scale )
|
||||
{
|
||||
}
|
||||
|
||||
const Vector &GetToneMappingScaleLinear( void ) const
|
||||
{
|
||||
static Vector dummy;
|
||||
return dummy;
|
||||
}
|
||||
|
||||
// For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer)
|
||||
virtual void HandleDeviceLost()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void EnableLinearColorSpaceFrameBuffer( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
// Lets the shader know about the full-screen texture so it can
|
||||
virtual void SetFullScreenTextureHandle( ShaderAPITextureHandle_t h )
|
||||
{
|
||||
}
|
||||
|
||||
void SetFloatRenderingParameter(int parm_number, float value)
|
||||
{
|
||||
}
|
||||
|
||||
void SetIntRenderingParameter(int parm_number, int value)
|
||||
{
|
||||
}
|
||||
|
||||
void SetTextureRenderingParameter(int parm_number, ITexture *pTexture)
|
||||
{
|
||||
}
|
||||
|
||||
void SetVectorRenderingParameter(int parm_number, Vector const &value)
|
||||
{
|
||||
}
|
||||
|
||||
float GetFloatRenderingParameter(int parm_number) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetIntRenderingParameter(int parm_number) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
ITexture *GetTextureRenderingParameter(int parm_number) const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Vector GetVectorRenderingParameter(int parm_number) const
|
||||
{
|
||||
return Vector(0,0,0);
|
||||
}
|
||||
|
||||
// Methods related to stencil
|
||||
virtual void SetStencilState( const ShaderStencilState_t &state ) {}
|
||||
|
||||
void ClearStencilBufferRectangle( int xmin, int ymin, int xmax, int ymax,int value)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices )
|
||||
{
|
||||
*pMaxVerts = 32768;
|
||||
*pMaxIndices = 32768;
|
||||
}
|
||||
|
||||
// Returns the max possible vertices + indices to render in a single draw call
|
||||
virtual int GetMaxVerticesToRender( IMaterial *pMaterial )
|
||||
{
|
||||
return 32768;
|
||||
}
|
||||
|
||||
virtual int GetMaxIndicesToRender( )
|
||||
{
|
||||
return 32768;
|
||||
}
|
||||
virtual int CompareSnapshots( StateSnapshot_t snapshot0, StateSnapshot_t snapshot1 ) { return 0; }
|
||||
|
||||
virtual void DisableAllLocalLights() {}
|
||||
|
||||
virtual bool SupportsMSAAMode( int nMSAAMode ) { return false; }
|
||||
|
||||
// Hooks for firing PIX events from outside the Material System...
|
||||
virtual void SetPIXMarker( unsigned long color, const char *szName ) {}
|
||||
|
||||
virtual void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc ) const {}
|
||||
|
||||
virtual bool SupportsShadowDepthTextures() { return false; }
|
||||
|
||||
virtual int NeedsShaderSRGBConversion(void) const { return 1; }
|
||||
|
||||
virtual bool SupportsFetch4() { return false; }
|
||||
|
||||
virtual void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) {}
|
||||
|
||||
virtual void SetDisallowAccess( bool ) {}
|
||||
virtual void EnableShaderShaderMutex( bool ) {}
|
||||
virtual void ShaderLock() {}
|
||||
virtual void ShaderUnlock() {}
|
||||
virtual void EnableHWMorphing( bool bEnable ) {}
|
||||
ImageFormat GetNullTextureFormat( void ) { return IMAGE_FORMAT_ABGR8888; } // stub
|
||||
virtual void PushDeformation( DeformationBase_t const *Deformation )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void PopDeformation( )
|
||||
{
|
||||
}
|
||||
|
||||
virtual int GetNumActiveDeformations() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
virtual void ExecuteCommandBuffer( uint8 *pBuf )
|
||||
{
|
||||
}
|
||||
|
||||
virtual void DrawInstances( int nInstanceCount, const MeshInstanceData_t *pInstances )
|
||||
{
|
||||
}
|
||||
|
||||
void SetStandardTextureHandle(StandardTextureId_t,ShaderAPITextureHandle_t)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int GetPackedDeformationInformation( int nMaskOfUnderstoodDeformations,
|
||||
float *pConstantValuesOut,
|
||||
int nBufferSize,
|
||||
int nMaximumDeformations,
|
||||
int *pNumDefsOut ) const
|
||||
{
|
||||
*pNumDefsOut = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual bool OwnGPUResources( bool bEnable )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void FlipCulling( bool bFlipCulling ) {}
|
||||
|
||||
virtual void EnableSinglePassFlashlightMode( bool bEnable ) {}
|
||||
virtual bool SinglePassFlashlightModeEnabled( void ) { return false; }
|
||||
|
||||
virtual void SetTextureFilterMode( Sampler_t sampler, TextureFilterMode_t nMode )
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
TRANSLUCENT = 0x1,
|
||||
ALPHATESTED = 0x2,
|
||||
VERTEX_AND_PIXEL_SHADERS = 0x4,
|
||||
DEPTHWRITE = 0x8,
|
||||
};
|
||||
void EnableAlphaToCoverage() {} ;
|
||||
void DisableAlphaToCoverage() {} ;
|
||||
|
||||
ImageFormat GetShadowDepthTextureFormat() { return IMAGE_FORMAT_UNKNOWN; };
|
||||
|
||||
//
|
||||
// NOTE: Under here are real methods being used by dx10 implementation
|
||||
// above is stuff I still have to port over.
|
||||
//
|
||||
private:
|
||||
void ClearShaderState( ShaderStateDx10_t* pState );
|
||||
void CommitStateChanges( bool bForce = false );
|
||||
|
||||
private:
|
||||
CMeshDx10 m_Mesh;
|
||||
|
||||
bool m_bResettingRenderState : 1;
|
||||
CFunctionCommit m_Commit;
|
||||
ShaderStateDx10_t m_DesiredState;
|
||||
ShaderStateDx10_t m_CurrentState;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton global
|
||||
//-----------------------------------------------------------------------------
|
||||
extern CShaderAPIDx10* g_pShaderAPIDx10;
|
||||
|
||||
#endif // SHADERAPIDX10_H
|
||||
|
||||
177
materialsystem/shaderapidx9/shaderapidx10.vpc
Normal file
177
materialsystem/shaderapidx9/shaderapidx10.vpc
Normal file
@@ -0,0 +1,177 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// SHADERAPIDX10.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$macro SRCDIR "..\.."
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\bin"
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_dll_win32_base.vpc"
|
||||
|
||||
$Configuration "Debug"
|
||||
{
|
||||
$General
|
||||
{
|
||||
$OutputDirectory ".\Debug_dx10$PLATSUBDIR"
|
||||
$IntermediateDirectory ".\Debug_dx10$PLATSUBDIR"
|
||||
}
|
||||
}
|
||||
|
||||
$Configuration "Release"
|
||||
{
|
||||
$General
|
||||
{
|
||||
$OutputDirectory ".\Release_dx10$PLATSUBDIR"
|
||||
$IntermediateDirectory ".\Release_dx10$PLATSUBDIR"
|
||||
}
|
||||
}
|
||||
|
||||
// Common Configuration
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE;$SRCDIR\dx10sdk\include;..\"
|
||||
$PreprocessorDefinitions "$BASE;SHADERAPIDX10;SHADER_DLL_EXPORT;PROTECTED_THINGS_ENABLE;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead"
|
||||
$PreprocessorDefinitions "$BASE;USE_ACTUAL_DX" [$WINDOWS||$X360]
|
||||
|
||||
// $AdditionalOptions "/FC"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "shaderapidx10"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
// Shared riles
|
||||
$File "cvballoctracker.cpp"
|
||||
$File "shaderdevicebase.cpp"
|
||||
$File "shaderapibase.cpp"
|
||||
$File "meshbase.cpp"
|
||||
|
||||
// DX10 related files
|
||||
$File "ShaderDeviceDx10.cpp" \
|
||||
"ShaderAPIDx10.cpp" \
|
||||
"MeshDx10.cpp" \
|
||||
"InputLayoutDx10.cpp" \
|
||||
"ShaderShadowDx10.cpp"
|
||||
{
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$PreprocessorDefinitions "DX10"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DX9 related files
|
||||
$File "ColorFormatDX8.cpp"
|
||||
$File "d3d_async.cpp"
|
||||
$File "$SRCDIR\public\filesystem_helpers.cpp"
|
||||
$File "HardwareConfig.cpp"
|
||||
$File "MeshDX8.cpp"
|
||||
$File "Recording.cpp"
|
||||
$File "ShaderAPIDX8.cpp"
|
||||
$File "ShaderDeviceDX8.cpp"
|
||||
$File "ShaderShadowDX8.cpp"
|
||||
$File "TextureDX8.cpp"
|
||||
$File "TransitionTable.cpp"
|
||||
$File "vertexdecl.cpp"
|
||||
$File "VertexShaderDX8.cpp"
|
||||
$File "wmi.cpp"
|
||||
$File "dx9asmtogl2.cpp" [!$PS3]
|
||||
}
|
||||
|
||||
$Folder "DirectX Header Files"
|
||||
{
|
||||
$File "$SRCDIR\dx10sdk\include\d3d10.h"
|
||||
$File "$SRCDIR\dx10sdk\include\d3dx10.h"
|
||||
$File "$SRCDIR\dx10sdk\include\d3dx10core.h"
|
||||
$File "$SRCDIR\dx10sdk\include\d3dx10math.h"
|
||||
$File "$SRCDIR\dx10sdk\include\d3dx10math.inl"
|
||||
$File "$SRCDIR\dx10sdk\include\d3dx10mesh.h"
|
||||
$File "$SRCDIR\dx10sdk\include\d3dx10tex.h"
|
||||
}
|
||||
|
||||
$Folder "Public Header Files"
|
||||
{
|
||||
$File "$SRCDIR\public\shaderapi\ishaderdevice.h"
|
||||
$File "$SRCDIR\public\shaderapi\ishaderutil.h"
|
||||
$File "$SRCDIR\public\shaderapi\ishaderapi.h"
|
||||
$File "$SRCDIR\public\shaderapi\ishaderdynamic.h"
|
||||
$File "$SRCDIR\public\shaderapi\ishadershadow.h"
|
||||
$File "$SRCDIR\public\materialsystem\idebugtextureinfo.h"
|
||||
$File "$SRCDIR\public\materialsystem\ivballoctracker.h"
|
||||
$File "$SRCDIR\public\materialsystem\shader_vcs_version.h"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
// Shared files
|
||||
$File "meshbase.h"
|
||||
$File "shaderdevicebase.h"
|
||||
$File "shaderapibase.h"
|
||||
$File "shaderapi_global.h"
|
||||
$File "HardwareConfig.h"
|
||||
|
||||
// DX10 related files
|
||||
$File "ShaderDeviceDx10.h"
|
||||
$File "ShaderAPIDx10.h"
|
||||
$File "MeshDx10.h"
|
||||
$File "ShaderShadowDx10.h"
|
||||
$File "shaderapidx10_global.h"
|
||||
$File "inputlayoutdx10.h"
|
||||
|
||||
// DX9 related files
|
||||
$File "TransitionTable.h"
|
||||
$File "vertexdecl.h"
|
||||
$File "CMaterialSystemStats.h"
|
||||
$File "ColorFormatDX8.h"
|
||||
$File "d3d_async.h"
|
||||
$File "dynamicib.h"
|
||||
$File "dynamicvb.h"
|
||||
$File "IMeshDX8.h"
|
||||
$File "locald3dtypes.h"
|
||||
$File "Recording.h"
|
||||
$File "ShaderAPIDX8.h"
|
||||
$File "ShaderAPIDX8_Global.h"
|
||||
$File "ShaderShadowDX8.h"
|
||||
$File "stubd3ddevice.h"
|
||||
$File "TextureDX8.h"
|
||||
$File "VertexShaderDX8.h"
|
||||
$File "wmi.h"
|
||||
}
|
||||
|
||||
$Folder "Link Libraries"
|
||||
{
|
||||
$File "$SRCDIR\lib\public\tier2.lib"
|
||||
$File "$SRCDIR\lib\public\bitmap.lib"
|
||||
$File "$SRCDIR\lib\public\mathlib.lib"
|
||||
$File "$SRCDIR\lib\common\vc7\bzip2.lib" [!$VS2015]
|
||||
$File "$SRCDIR\lib\common\vc14\bzip2.lib" [$VS2015]
|
||||
$File "$SRCDIR\lib\public\videocfg.lib"
|
||||
$File "$SRCDIR\dx10sdk\lib\x86\d3d9.lib"
|
||||
$File "$SRCDIR\dx10sdk\lib\x86\d3d10.lib"
|
||||
$File "$SRCDIR\dx10sdk\lib\x86\dxgi.lib"
|
||||
|
||||
$File "$SRCDIR\dx10sdk\lib\x86\d3dx10.lib" \
|
||||
"$SRCDIR\dx10sdk\lib\x86\d3dx9.lib"
|
||||
{
|
||||
$Configuration "Debug"
|
||||
{
|
||||
$ExcludedFromBuild "Yes"
|
||||
}
|
||||
}
|
||||
|
||||
$File "$SRCDIR\dx10sdk\lib\x86\d3dx10d.lib" \
|
||||
"$SRCDIR\dx10sdk\lib\x86\d3dx9d.lib"
|
||||
{
|
||||
$Configuration "Release"
|
||||
{
|
||||
$ExcludedFromBuild "Yes"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
19
materialsystem/shaderapidx9/shaderapidx10_global.h
Normal file
19
materialsystem/shaderapidx9/shaderapidx10_global.h
Normal file
@@ -0,0 +1,19 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERAPIDX10_GLOBAL_H
|
||||
#define SHADERAPIDX10_GLOBAL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "shaderapi_global.h"
|
||||
|
||||
|
||||
#endif // SHADERAPIDX10_GLOBAL_H
|
||||
17690
materialsystem/shaderapidx9/shaderapidx8.cpp
Normal file
17690
materialsystem/shaderapidx9/shaderapidx8.cpp
Normal file
File diff suppressed because it is too large
Load Diff
502
materialsystem/shaderapidx9/shaderapidx8.h
Normal file
502
materialsystem/shaderapidx9/shaderapidx8.h
Normal file
@@ -0,0 +1,502 @@
|
||||
//===== Copyright © 1996-2008, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERAPIDX8_H
|
||||
#define SHADERAPIDX8_H
|
||||
|
||||
#include "shaderapibase.h"
|
||||
#include "shaderapi/ishadershadow.h"
|
||||
#include "materialsystem/IShader.h"
|
||||
#include "locald3dtypes.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Vendor-specific defines
|
||||
//-----------------------------------------------------------------------------
|
||||
#define ATI_FETCH4_ENABLE MAKEFOURCC('G','E','T','4')
|
||||
#define ATI_FETCH4_DISABLE MAKEFOURCC('G','E','T','1')
|
||||
#define ATISAMP_FETCH4 D3DSAMP_MIPMAPLODBIAS
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CMeshBase;
|
||||
class CMeshBuilder;
|
||||
struct ShadowState_t;
|
||||
struct DepthTestState_t;
|
||||
class IMaterialInternal;
|
||||
struct MeshInstanceData_t;
|
||||
|
||||
//#define _X360_GPU_OWN_RESOURCES
|
||||
#if defined( _X360_GPU_OWN_RESOURCES )
|
||||
#define IsGPUOwnSupported() ( true )
|
||||
#else
|
||||
#define IsGPUOwnSupported() ( false )
|
||||
#endif
|
||||
|
||||
#if defined( _X360 )
|
||||
// Define this to link shader compilation code from D3DX9.LIB
|
||||
//#define X360_LINK_WITH_SHADER_COMPILE 1
|
||||
#endif
|
||||
#if defined( X360_LINK_WITH_SHADER_COMPILE ) && defined( _CERT )
|
||||
#error "Don't ship with X360_LINK_WITH_SHADER_COMPILE defined!! It causes 2MB+ DLL bloat. Only define it while revving XDKs."
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// State that matters to buffered meshes... (for debugging only)
|
||||
//-----------------------------------------------------------------------------
|
||||
struct BufferedState_t
|
||||
{
|
||||
D3DXMATRIX m_Transform[3];
|
||||
D3DVIEWPORT9 m_Viewport;
|
||||
int m_BoundTexture[16];
|
||||
void *m_VertexShader;
|
||||
void *m_PixelShader;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Compiled lighting state
|
||||
//-----------------------------------------------------------------------------
|
||||
struct CompiledLightingState_t
|
||||
{
|
||||
Vector4D m_AmbientLightCube[6];
|
||||
int m_nLocalLightCount;
|
||||
Vector4D m_PixelShaderLocalLights[6];
|
||||
Vector4D m_VertexShaderLocalLights[20];
|
||||
int m_VertexShaderLocalLightLoopControl[4];
|
||||
int m_VertexShaderLocalLightEnable[VERTEX_SHADER_LIGHT_ENABLE_BOOL_CONST_COUNT];
|
||||
};
|
||||
|
||||
struct InstanceInfo_t
|
||||
{
|
||||
// Have we compiled various bits of lighting state?
|
||||
bool m_bAmbientCubeCompiled : 1;
|
||||
bool m_bPixelShaderLocalLightsCompiled : 1;
|
||||
bool m_bVertexShaderLocalLightsCompiled : 1;
|
||||
|
||||
// Have we set various shader constants?
|
||||
bool m_bSetSkinConstants : 1;
|
||||
bool m_bSetLightVertexShaderConstants : 1;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The DX8 shader API
|
||||
//-----------------------------------------------------------------------------
|
||||
// FIXME: Remove this! Either move them into CShaderAPIBase or CShaderAPIDx8
|
||||
class IShaderAPIDX8 : public CShaderAPIBase
|
||||
{
|
||||
public:
|
||||
// Draws the mesh
|
||||
virtual void DrawMesh( CMeshBase *pMesh, int nCount, const MeshInstanceData_t *pInstances, VertexCompressionType_t nCompressionType, CompiledLightingState_t* pCompiledState, InstanceInfo_t *pInfo ) = 0;
|
||||
|
||||
// Draw the mesh with the currently bound vertex and index buffers.
|
||||
virtual void DrawWithVertexAndIndexBuffers( void ) = 0;
|
||||
|
||||
// Gets the current buffered state... (debug only)
|
||||
virtual void GetBufferedState( BufferedState_t &state ) = 0;
|
||||
|
||||
// Gets the current backface cull state....
|
||||
virtual D3DCULL GetCullMode() const = 0;
|
||||
|
||||
// Measures fill rate
|
||||
virtual void ComputeFillRate() = 0;
|
||||
|
||||
// Selection mode methods
|
||||
virtual bool IsInSelectionMode() const = 0;
|
||||
|
||||
// We hit somefin in selection mode
|
||||
virtual void RegisterSelectionHit( float minz, float maxz ) = 0;
|
||||
|
||||
// Get the currently bound material
|
||||
virtual IMaterialInternal* GetBoundMaterial() = 0;
|
||||
|
||||
// These methods are called by the transition table
|
||||
// They depend on dynamic state so can't exist inside the transition table
|
||||
virtual void ApplyZBias( const DepthTestState_t &shaderState ) = 0;
|
||||
virtual void ApplyCullEnable( bool bEnable ) = 0;
|
||||
virtual void ApplyFogMode( ShaderFogMode_t fogMode, bool bVertexFog, bool bSRGBWritesEnabled, bool bDisableGammaCorrection ) = 0;
|
||||
|
||||
virtual int GetActualSamplerCount() const = 0;
|
||||
|
||||
virtual bool IsRenderingMesh() const = 0;
|
||||
|
||||
// Fog methods...
|
||||
virtual void EnableFixedFunctionFog( bool bFogEnable ) = 0;
|
||||
|
||||
virtual int GetCurrentFrameCounter( void ) const = 0;
|
||||
|
||||
// Workaround hack for visualization of selection mode
|
||||
virtual void SetupSelectionModeVisualizationState() = 0;
|
||||
|
||||
virtual bool UsingSoftwareVertexProcessing() const = 0;
|
||||
|
||||
//notification that the SRGB write state is being changed
|
||||
virtual void EnabledSRGBWrite( bool bEnabled ) = 0;
|
||||
virtual void SetSRGBWrite( bool bState ) = 0;
|
||||
|
||||
// Alpha to coverage
|
||||
virtual void ApplyAlphaToCoverage( bool bEnable ) = 0;
|
||||
|
||||
virtual void PrintfVA( char *fmt, va_list vargs ) = 0;
|
||||
virtual void Printf( char *fmt, ... ) = 0;
|
||||
virtual float Knob( char *knobname, float *setvalue = NULL ) = 0;
|
||||
|
||||
virtual void NotifyShaderConstantsChangedInRenderPass() = 0;
|
||||
|
||||
virtual void GenerateNonInstanceRenderState( MeshInstanceData_t *pInstance, CompiledLightingState_t** pCompiledState, InstanceInfo_t **pInfo ) = 0;
|
||||
|
||||
// Executes the per-instance command buffer
|
||||
virtual void ExecuteInstanceCommandBuffer( const unsigned char *pCmdBuf, int nInstanceIndex, bool bForceStateSet ) = 0;
|
||||
|
||||
// Sets the vertex decl
|
||||
virtual void SetVertexDecl( VertexFormat_t vertexFormat, bool bHasColorMesh, bool bUsingFlex, bool bUsingMorph, bool bUsingPreTessPatch, VertexStreamSpec_t *pStreamSpec ) = 0;
|
||||
|
||||
// Set Tessellation Enable
|
||||
#if ENABLE_TESSELLATION
|
||||
virtual void SetTessellationMode( TessellationMode_t mode ) = 0;
|
||||
#else
|
||||
void SetTessellationMode( TessellationMode_t mode ) {}
|
||||
#endif
|
||||
|
||||
virtual void AddShaderComboInformation( const ShaderComboSemantics_t *pSemantics ) = 0;
|
||||
|
||||
virtual float GetLightMapScaleFactor() const = 0;
|
||||
};
|
||||
|
||||
#ifdef _PS3
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PS3 non-virtual implementation proxy
|
||||
//
|
||||
// cat shaderapidx8.h | nonvirtualscript.pl > shaderapidx8_ps3nonvirt.inl
|
||||
struct CPs3NonVirt_IShaderAPIDX8
|
||||
{
|
||||
//NONVIRTUALSCRIPTBEGIN
|
||||
//NONVIRTUALSCRIPT/PROXY/CPs3NonVirt_IShaderAPIDX8
|
||||
//NONVIRTUALSCRIPT/DELEGATE/g_ShaderAPIDX8.CShaderAPIDx8::
|
||||
|
||||
static ShaderAPITextureHandle_t GetStandardTextureHandle(StandardTextureId_t id);
|
||||
|
||||
//
|
||||
// IShaderAPI
|
||||
//
|
||||
static void SetViewports( int nCount, const ShaderViewport_t* pViewports, bool setImmediately = false );
|
||||
static int GetViewports( ShaderViewport_t* pViewports, int nMax );
|
||||
static void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight );
|
||||
static void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b );
|
||||
static void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a );
|
||||
static void BindVertexShader( VertexShaderHandle_t hVertexShader );
|
||||
static void BindGeometryShader( GeometryShaderHandle_t hGeometryShader );
|
||||
static void BindPixelShader( PixelShaderHandle_t hPixelShader );
|
||||
static void SetRasterState( const ShaderRasterState_t& state );
|
||||
static bool SetMode( void* hwnd, int nAdapter, const ShaderDeviceInfo_t &info );
|
||||
static void ChangeVideoMode( const ShaderDeviceInfo_t &info );
|
||||
static StateSnapshot_t TakeSnapshot( );
|
||||
static void TexMinFilter( ShaderTexFilterMode_t texFilterMode );
|
||||
static void TexMagFilter( ShaderTexFilterMode_t texFilterMode );
|
||||
static void TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode );
|
||||
static void CopyRenderTargetToTexture( ShaderAPITextureHandle_t textureHandle );
|
||||
static void Bind( IMaterial* pMaterial );
|
||||
static IMesh* GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool bBuffered = true, IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0);
|
||||
static IMesh* GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t vertexFormat, int nHWSkinBoneCount, bool bBuffered = true, IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0 );
|
||||
static bool IsTranslucent( StateSnapshot_t id );
|
||||
static bool IsAlphaTested( StateSnapshot_t id );
|
||||
static bool UsesVertexAndPixelShaders( StateSnapshot_t id );
|
||||
static bool IsDepthWriteEnabled( StateSnapshot_t id );
|
||||
static VertexFormat_t ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds );
|
||||
static VertexFormat_t ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds );
|
||||
static void BeginPass( StateSnapshot_t snapshot );
|
||||
static void RenderPass( const unsigned char *pInstanceCommandBuffer, int nPass, int nPassCount );
|
||||
static void SetNumBoneWeights( int numBones );
|
||||
static void SetLights( int nCount, const LightDesc_t *pDesc );
|
||||
static void SetLightingOrigin( Vector vLightingOrigin );
|
||||
static void SetLightingState( const MaterialLightingState_t& state );
|
||||
static void SetAmbientLightCube( Vector4D cube[6] );
|
||||
static void ShadeMode( ShaderShadeMode_t mode );
|
||||
static void CullMode( MaterialCullMode_t cullMode );
|
||||
static void FlipCullMode();
|
||||
static void ForceDepthFuncEquals( bool bEnable );
|
||||
static void OverrideDepthEnable( bool bEnable, bool bDepthWriteEnable, bool bDepthTestEnable = true );
|
||||
static void SetHeightClipZ( float z );
|
||||
static void SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode );
|
||||
static void SetClipPlane( int index, const float *pPlane );
|
||||
static void EnableClipPlane( int index, bool bEnable );
|
||||
static ImageFormat GetNearestSupportedFormat( ImageFormat fmt );
|
||||
static ImageFormat GetNearestRenderTargetFormat( ImageFormat fmt );
|
||||
static bool DoRenderTargetsNeedSeparateDepthBuffer();
|
||||
static ShaderAPITextureHandle_t CreateTexture( int width, int height, int depth, ImageFormat dstImageFormat, int numMipLevels, int numCopies, int flags, const char *pDebugName, const char *pTextureGroupName );
|
||||
static void DeleteTexture( ShaderAPITextureHandle_t textureHandle );
|
||||
static ShaderAPITextureHandle_t CreateDepthTexture( ImageFormat renderTargetFormat, int width, int height, const char *pDebugName, bool bTexture, bool bAliasDepthSurfaceOverColorX360 = false );
|
||||
static bool IsTexture( ShaderAPITextureHandle_t textureHandle );
|
||||
static bool IsTextureResident( ShaderAPITextureHandle_t textureHandle );
|
||||
static void ModifyTexture( ShaderAPITextureHandle_t textureHandle );
|
||||
static void TexImage2D( int level, int cubeFaceID, ImageFormat dstFormat, int zOffset, int width, int height, ImageFormat srcFormat, bool bSrcIsTiled, void *imageData );
|
||||
static void TexSubImage2D( int level, int cubeFaceID, int xOffset, int yOffset, int zOffset, int width, int height, ImageFormat srcFormat, int srcStride, bool bSrcIsTiled, void *imageData );
|
||||
static bool TexLock( int level, int cubeFaceID, int xOffset, int yOffset, int width, int height, CPixelWriter& writer );
|
||||
static void TexUnlock( );
|
||||
static void UpdateTexture( int xOffset, int yOffset, int w, int h, ShaderAPITextureHandle_t hDstTexture, ShaderAPITextureHandle_t hSrcTexture );
|
||||
static void *LockTex( ShaderAPITextureHandle_t hTexture );
|
||||
static void UnlockTex( ShaderAPITextureHandle_t hTexture );
|
||||
static void TexSetPriority( int priority );
|
||||
static void BindTexture( Sampler_t sampler, TextureBindFlags_t nBindFlags, ShaderAPITextureHandle_t textureHandle );
|
||||
static void SetRenderTarget( ShaderAPITextureHandle_t colorTextureHandle = SHADER_RENDERTARGET_BACKBUFFER, ShaderAPITextureHandle_t depthTextureHandle = SHADER_RENDERTARGET_DEPTHBUFFER );
|
||||
static void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth );
|
||||
static void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat );
|
||||
static void ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride );
|
||||
static void FlushHardware();
|
||||
static void BeginFrame();
|
||||
static void EndFrame();
|
||||
static int SelectionMode( bool selectionMode );
|
||||
static void SelectionBuffer( unsigned int* pBuffer, int size );
|
||||
static void ClearSelectionNames( );
|
||||
static void LoadSelectionName( int name );
|
||||
static void PushSelectionName( int name );
|
||||
static void PopSelectionName();
|
||||
static void ForceHardwareSync();
|
||||
static void ClearSnapshots();
|
||||
static void FogStart( float fStart );
|
||||
static void FogEnd( float fEnd );
|
||||
static void SetFogZ( float fogZ );
|
||||
static void SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b );
|
||||
static void GetSceneFogColor( unsigned char *rgb );
|
||||
static void SceneFogMode( MaterialFogMode_t fogMode );
|
||||
static bool CanDownloadTextures();
|
||||
static void ResetRenderState( bool bFullReset = true );
|
||||
static int GetCurrentDynamicVBSize();
|
||||
static void DestroyVertexBuffers( bool bExitingLevel = false );
|
||||
static void EvictManagedResources();
|
||||
static void GetGPUMemoryStats( GPUMemoryStats &stats );
|
||||
static void SetAnisotropicLevel( int nAnisotropyLevel );
|
||||
static void SyncToken( const char *pToken );
|
||||
static void SetStandardVertexShaderConstants( float fOverbright );
|
||||
static ShaderAPIOcclusionQuery_t CreateOcclusionQueryObject();
|
||||
static void DestroyOcclusionQueryObject( ShaderAPIOcclusionQuery_t q );
|
||||
static void BeginOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t q );
|
||||
static void EndOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t q );
|
||||
static int OcclusionQuery_GetNumPixelsRendered( ShaderAPIOcclusionQuery_t hQuery, bool bFlush = false );
|
||||
static void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture );
|
||||
static void ClearVertexAndPixelShaderRefCounts();
|
||||
static void PurgeUnusedVertexAndPixelShaders();
|
||||
static void DXSupportLevelChanged( int nDXLevel );
|
||||
static void EnableUserClipTransformOverride( bool bEnable );
|
||||
static void UserClipTransform( const VMatrix &worldToView );
|
||||
static void SetRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t colorTextureHandle = SHADER_RENDERTARGET_BACKBUFFER, ShaderAPITextureHandle_t depthTextureHandle = SHADER_RENDERTARGET_DEPTHBUFFER );
|
||||
static void CopyRenderTargetToTextureEx( ShaderAPITextureHandle_t textureHandle, int nRenderTargetID, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL );
|
||||
static void HandleDeviceLost();
|
||||
static void EnableLinearColorSpaceFrameBuffer( bool bEnable );
|
||||
static void SetFullScreenTextureHandle( ShaderAPITextureHandle_t h );
|
||||
static void SetFloatRenderingParameter(int parm_number, float value);
|
||||
static void SetIntRenderingParameter(int parm_number, int value);
|
||||
static void SetVectorRenderingParameter(int parm_number, Vector const &value);
|
||||
static float GetFloatRenderingParameter(int parm_number);
|
||||
static int GetIntRenderingParameter(int parm_number);
|
||||
static Vector GetVectorRenderingParameter(int parm_number);
|
||||
static void SetFastClipPlane( const float *pPlane );
|
||||
static void EnableFastClip( bool bEnable );
|
||||
static void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices );
|
||||
static int GetMaxVerticesToRender( IMaterial *pMaterial );
|
||||
static int GetMaxIndicesToRender( );
|
||||
static void SetStencilState( const ShaderStencilState_t& state );
|
||||
static void ClearStencilBufferRectangle(int xmin, int ymin, int xmax, int ymax, int value);
|
||||
static void DisableAllLocalLights();
|
||||
static int CompareSnapshots( StateSnapshot_t snapshot0, StateSnapshot_t snapshot1 );
|
||||
static IMesh *GetFlexMesh();
|
||||
static void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture );
|
||||
static void SetCascadedShadowMappingState( const CascadedShadowMappingState_t &state, ITexture *pDepthTextureAtlas );
|
||||
static const CascadedShadowMappingState_t &GetCascadedShadowMappingState( ITexture **pDepthTextureAtlas, bool bLightMapScale = false );
|
||||
static bool SupportsMSAAMode( int nMSAAMode );
|
||||
static bool PostQueuedTexture( const void *pData, int nSize, ShaderAPITextureHandle_t *pHandles, int nHandles, int nWidth, int nHeight, int nDepth, int nMips, int *pRefCount );
|
||||
static void ReloadZcullMemory( int nStencilRef );
|
||||
static void AntiAliasingHint( int nHint );
|
||||
static void FlushTextureCache();
|
||||
static void InvokeGpuDataTransferCache( uint32 uiDepthBufferCacheOperation );
|
||||
static bool OwnGPUResources( bool bEnable );
|
||||
static void GetFogDistances( float *fStart, float *fEnd, float *fFogZ );
|
||||
static void BeginPIXEvent( unsigned long color, const char *szName );
|
||||
static void EndPIXEvent();
|
||||
static void SetPIXMarker( unsigned long color, const char *szName );
|
||||
static void EnableAlphaToCoverage();
|
||||
static void DisableAlphaToCoverage();
|
||||
static void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc );
|
||||
static int VertexFormatSize( VertexFormat_t vertexFormat );
|
||||
static void SetDisallowAccess( bool b );
|
||||
static void EnableShaderShaderMutex( bool b );
|
||||
static void ShaderLock();
|
||||
static void ShaderUnlock();
|
||||
static void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias );
|
||||
static void BindVertexBuffer( int nStreamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 );
|
||||
static void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes );
|
||||
static void Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount );
|
||||
static void PerformFullScreenStencilOperation();
|
||||
static void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor );
|
||||
static bool SupportsCSAAMode( int nNumSamples, int nQualityLevel );
|
||||
static void InvalidateDelayedShaderConstants();
|
||||
static float GammaToLinear_HardwareSpecific( float fGamma );
|
||||
static float LinearToGamma_HardwareSpecific( float fLinear );
|
||||
static void SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture );
|
||||
static void BindVertexTexture( VertexTextureSampler_t nSampler, ShaderAPITextureHandle_t textureHandle );
|
||||
static void EnableHWMorphing( bool bEnable );
|
||||
static void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights );
|
||||
static void FogMaxDensity( float flMaxDensity );
|
||||
static void CreateTextures( ShaderAPITextureHandle_t *pHandles, int count, int width, int height, int depth, ImageFormat dstImageFormat, int numMipLevels, int numCopies, int flags, const char *pDebugName, const char *pTextureGroupName );
|
||||
static void AcquireThreadOwnership();
|
||||
static void ReleaseThreadOwnership();
|
||||
static void EnableBuffer2FramesAhead( bool bEnable );
|
||||
static void FlipCulling( bool bFlipCulling );
|
||||
static void SetTextureRenderingParameter(int parm_number, ITexture *pTexture);
|
||||
static void EnableSinglePassFlashlightMode( bool bEnable );
|
||||
static void MatrixMode( MaterialMatrixMode_t matrixMode );
|
||||
static void PushMatrix();
|
||||
static void PopMatrix();
|
||||
static void LoadMatrix( float *m );
|
||||
static void MultMatrix( float *m );
|
||||
static void MultMatrixLocal( float *m );
|
||||
static void LoadIdentity();
|
||||
static void LoadCameraToWorld();
|
||||
static void Ortho( double left, double right, double bottom, double top, double zNear, double zFar );
|
||||
static void PerspectiveX( double fovx, double aspect, double zNear, double zFar );
|
||||
static void PickMatrix( int x, int y, int width, int height );
|
||||
static void Rotate( float angle, float x, float y, float z );
|
||||
static void Translate( float x, float y, float z );
|
||||
static void Scale( float x, float y, float z );
|
||||
static void ScaleXY( float x, float y );
|
||||
static void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right );
|
||||
static void LoadBoneMatrix( int boneIndex, const float *m );
|
||||
static void SetStandardTextureHandle( StandardTextureId_t nId, ShaderAPITextureHandle_t nHandle );
|
||||
static void DrawInstances( int nInstanceCount, const MeshInstanceData_t *pInstance );
|
||||
static void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable );
|
||||
static void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable );
|
||||
static void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth );
|
||||
static void OnPresent();
|
||||
static void UpdateGameTime( float flTime );
|
||||
|
||||
//
|
||||
// IShaderDynamicAPI
|
||||
//
|
||||
static double CurrentTime();
|
||||
static void GetLightmapDimensions( int *w, int *h );
|
||||
static MaterialFogMode_t GetSceneFogMode( );
|
||||
static void SetVertexShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false );
|
||||
static void SetPixelShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false );
|
||||
static void SetDefaultState();
|
||||
static void GetWorldSpaceCameraPosition( float* pPos );
|
||||
static void GetWorldSpaceCameraDirection( float* pDir );
|
||||
static int GetCurrentNumBones();
|
||||
static MaterialFogMode_t GetCurrentFogType();
|
||||
static void SetVertexShaderIndex( int vshIndex = -1 );
|
||||
static void SetPixelShaderIndex( int pshIndex = 0 );
|
||||
static void GetBackBufferDimensions( int& width, int& height );
|
||||
static const AspectRatioInfo_t &GetAspectRatioInfo( void );
|
||||
static void GetCurrentRenderTargetDimensions( int& nWidth, int& nHeight );
|
||||
static void GetCurrentViewport( int& nX, int& nY, int& nWidth, int& nHeight );
|
||||
static void SetPixelShaderFogParams( int reg );
|
||||
static bool InFlashlightMode();
|
||||
static const FlashlightState_t &GetFlashlightState( VMatrix &worldToTexture );
|
||||
static bool InEditorMode();
|
||||
static void BindStandardTexture( Sampler_t sampler, TextureBindFlags_t nBindFlags, StandardTextureId_t id );
|
||||
static ITexture *GetRenderTargetEx( int nRenderTargetID );
|
||||
static void SetToneMappingScaleLinear( const Vector &scale );
|
||||
static const Vector &GetToneMappingScaleLinear();
|
||||
static const FlashlightState_t &GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **pFlashlightDepthTexture );
|
||||
static void GetDX9LightState( LightState_t *state );
|
||||
static int GetPixelFogCombo( );
|
||||
static void BindStandardVertexTexture( VertexTextureSampler_t sampler, StandardTextureId_t id );
|
||||
static bool IsHWMorphingEnabled( );
|
||||
static void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id );
|
||||
static void SetBooleanVertexShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false );
|
||||
static void SetIntegerVertexShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false );
|
||||
static void SetBooleanPixelShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false );
|
||||
static void SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false );
|
||||
static bool ShouldWriteDepthToDestAlpha();
|
||||
static void GetMatrix( MaterialMatrixMode_t matrixMode, float *dst );
|
||||
static void PushDeformation( DeformationBase_t const *Deformation );
|
||||
static void PopDeformation( );
|
||||
static int GetNumActiveDeformations();
|
||||
static int GetPackedDeformationInformation( int nMaskOfUnderstoodDeformations, float *pConstantValuesOut, int nBufferSize, int nMaximumDeformations, int *pNumDefsOut );
|
||||
static void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords );
|
||||
static void ExecuteCommandBuffer( uint8 *pCmdBuffer );
|
||||
#ifdef _PS3
|
||||
static void ExecuteCommandBufferPPU( uint8 *pCmdBuffer );
|
||||
#endif
|
||||
static void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo );
|
||||
static ITexture *GetTextureRenderingParameter(int parm_number);
|
||||
static void SetScreenSizeForVPOS( int pshReg = 32 );
|
||||
static void SetVSNearAndFarZ( int vshReg );
|
||||
static float GetFarZ();
|
||||
static bool SinglePassFlashlightModeEnabled();
|
||||
static void GetActualProjectionMatrix( float *pMatrix );
|
||||
static void SetDepthFeatheringShaderConstants( int iConstant, float fDepthBlendScale );
|
||||
static void GetFlashlightShaderInfo( bool *pShadowsEnabled, bool *pUberLight );
|
||||
static float GetFlashlightAmbientOcclusion( );
|
||||
static void SetTextureFilterMode( Sampler_t sampler, TextureFilterMode_t nMode );
|
||||
static TessellationMode_t GetTessellationMode();
|
||||
static float GetSubDHeight();
|
||||
static bool IsRenderingPaint();
|
||||
static bool IsStereoActiveThisFrame();
|
||||
|
||||
//
|
||||
// CShaderAPIBase
|
||||
//
|
||||
static bool OnDeviceInit();
|
||||
static void OnDeviceShutdown();
|
||||
static void AdvancePIXFrame();
|
||||
static void ReleaseShaderObjects( bool bReleaseManagedResources = true );
|
||||
static void RestoreShaderObjects();
|
||||
static IDirect3DBaseTexture* GetD3DTexture( ShaderAPITextureHandle_t hTexture );
|
||||
static void GetPs3Texture(void* pPs3tex, ShaderAPITextureHandle_t hTexture );
|
||||
static void GetPs3Texture(void* pPs3tex, StandardTextureId_t nTextureId );
|
||||
static void QueueResetRenderState();
|
||||
|
||||
//
|
||||
// IShaderAPIDX8
|
||||
//
|
||||
static void DrawMesh( CMeshBase *pMesh, int nCount, const MeshInstanceData_t *pInstances, VertexCompressionType_t nCompressionType, CompiledLightingState_t* pCompiledState, InstanceInfo_t *pInfo );
|
||||
static void DrawWithVertexAndIndexBuffers();
|
||||
static void GetBufferedState( BufferedState_t &state );
|
||||
static D3DCULL GetCullMode();
|
||||
static void ComputeFillRate();
|
||||
static bool IsInSelectionMode();
|
||||
static void RegisterSelectionHit( float minz, float maxz );
|
||||
static IMaterialInternal* GetBoundMaterial();
|
||||
static void ApplyZBias( const DepthTestState_t& shaderState );
|
||||
static void ApplyCullEnable( bool bEnable );
|
||||
static void ApplyFogMode( ShaderFogMode_t fogMode, bool bVertexFog, bool bSRGBWritesEnabled, bool bDisableGammaCorrection );
|
||||
static int GetActualSamplerCount();
|
||||
static bool IsRenderingMesh();
|
||||
static void EnableFixedFunctionFog( bool bFogEnable );
|
||||
static int GetCurrentFrameCounter();
|
||||
static void SetupSelectionModeVisualizationState();
|
||||
static bool UsingSoftwareVertexProcessing();
|
||||
static void EnabledSRGBWrite( bool bEnabled );
|
||||
static void ApplyAlphaToCoverage( bool bEnable );
|
||||
static void PrintfVA( char *fmt, va_list vargs );
|
||||
static void Printf( char *fmt, ... ) {}
|
||||
static float Knob( char *knobname, float *setvalue = NULL );
|
||||
static void NotifyShaderConstantsChangedInRenderPass();
|
||||
static void GenerateNonInstanceRenderState( MeshInstanceData_t *pInstance, CompiledLightingState_t** pCompiledState, InstanceInfo_t **pInfo );
|
||||
static void ExecuteInstanceCommandBuffer( const unsigned char *pCmdBuf, int nInstanceIndex, bool bForceStateSet );
|
||||
static void SetVertexDecl( VertexFormat_t vertexFormat, bool bHasColorMesh, bool bUsingFlex, bool bUsingMorph, bool bUsingPreTessPatch, VertexStreamSpec_t *pStreamSpec );
|
||||
static void SetTessellationMode( TessellationMode_t mode );
|
||||
static IMesh *GetExternalMesh( const ExternalMeshInfo_t& info );
|
||||
static void SetExternalMeshData( IMesh *pMesh, const ExternalMeshData_t &data );
|
||||
static IIndexBuffer *GetExternalIndexBuffer( int nIndexCount, uint16 *pIndexData );
|
||||
static void FlushGPUCache( void *pBaseAddr, size_t nSizeInBytes );
|
||||
static void AddShaderComboInformation( const ShaderComboSemantics_t *pSemantics );
|
||||
static void SetSRGBWrite( bool bState );
|
||||
|
||||
static void BeginConsoleZPass2( int nNumDynamicIndicesNeeded );
|
||||
static void EndConsoleZPass();
|
||||
|
||||
//NONVIRTUALSCRIPTEND
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // SHADERAPIDX8_H
|
||||
124
materialsystem/shaderapidx9/shaderapidx8_global.h
Normal file
124
materialsystem/shaderapidx9/shaderapidx8_global.h
Normal file
@@ -0,0 +1,124 @@
|
||||
//===== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERAPIDX8_GLOBAL_H
|
||||
#define SHADERAPIDX8_GLOBAL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier0/dbg.h"
|
||||
#include "tier0/memalloc.h"
|
||||
#include "shaderapi_global.h"
|
||||
#include "tier2/tier2.h"
|
||||
#include "shaderdevicedx8.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Use this to fill in structures with the current board state
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define DEBUG_BOARD_STATE 0
|
||||
#endif
|
||||
|
||||
#if !defined( _GAMECONSOLE )
|
||||
#include "d3d_async.h"
|
||||
typedef D3DDeviceWrapper D3DDev_t;
|
||||
D3DDev_t *Dx9Device();
|
||||
IDirect3D9 *D3D();
|
||||
#else
|
||||
#define SHADERAPI_NO_D3DDeviceWrapper 1
|
||||
typedef IDirect3DDevice D3DDeviceWrapper;
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Measures driver allocations
|
||||
//-----------------------------------------------------------------------------
|
||||
//#define MEASURE_DRIVER_ALLOCATIONS 1
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IShaderUtil;
|
||||
class IVertexBufferDX8;
|
||||
class IShaderShadowDX8;
|
||||
class IMeshMgr;
|
||||
class IShaderAPIDX8;
|
||||
class IFileSystem;
|
||||
class IShaderManager;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A new shader draw flag we need to workaround dx8
|
||||
//-----------------------------------------------------------------------------
|
||||
enum
|
||||
{
|
||||
SHADER_HAS_CONSTANT_COLOR = 0x80000000
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The main shader API
|
||||
//-----------------------------------------------------------------------------
|
||||
extern IShaderAPIDX8 *g_pShaderAPIDX8;
|
||||
#ifdef _PS3
|
||||
class CPs3NonVirt_IShaderAPIDX8;
|
||||
inline CPs3NonVirt_IShaderAPIDX8* ShaderAPI()
|
||||
{
|
||||
return ( CPs3NonVirt_IShaderAPIDX8 * ) 1;
|
||||
}
|
||||
#else
|
||||
inline IShaderAPIDX8* ShaderAPI()
|
||||
{
|
||||
return g_pShaderAPIDX8;
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The shader shadow
|
||||
//-----------------------------------------------------------------------------
|
||||
IShaderShadowDX8* ShaderShadow();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Manager of all vertex + pixel shaders
|
||||
//-----------------------------------------------------------------------------
|
||||
inline IShaderManager *ShaderManager()
|
||||
{
|
||||
extern IShaderManager *g_pShaderManager;
|
||||
return g_pShaderManager;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The mesh manager
|
||||
//-----------------------------------------------------------------------------
|
||||
IMeshMgr* MeshMgr();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The main hardware config interface
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifdef _PS3
|
||||
#include "shaderapidx9/hardwareconfig_ps3nonvirt.h"
|
||||
#elif defined( _OSX )
|
||||
// @wge: Moved from materialsystem_global.h, since we include shaderapidx8 headers in material system
|
||||
inline IHardwareConfigInternal *HardwareConfig()
|
||||
{
|
||||
extern IHardwareConfigInternal* g_pHWConfig;
|
||||
return g_pHWConfig;
|
||||
}
|
||||
#else
|
||||
inline IMaterialSystemHardwareConfig* HardwareConfig()
|
||||
{
|
||||
return g_pMaterialSystemHardwareConfig;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // SHADERAPIDX8_GLOBAL_H
|
||||
1451
materialsystem/shaderapidx9/shaderapidx8_ps3nonvirt.inl
Normal file
1451
materialsystem/shaderapidx9/shaderapidx8_ps3nonvirt.inl
Normal file
File diff suppressed because it is too large
Load Diff
89
materialsystem/shaderapidx9/shaderapidx9.vpc
Normal file
89
materialsystem/shaderapidx9/shaderapidx9.vpc
Normal file
@@ -0,0 +1,89 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// SHADERDX8.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Macro SHADERAPIDX9DIR "."
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\bin"
|
||||
$Macro OUTBINNAME "shaderapidx9"
|
||||
//$Macro SCE_PS3_ROOT "$env(SCE_PS3_ROOT)"
|
||||
|
||||
$include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
|
||||
|
||||
// Common Configuration
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE;$SRCDIR\dx9sdk\include;..\" [$WINDOWS && !$GL]
|
||||
$AdditionalIncludeDirectories "$BASE;$SRCDIR\thirdparty\nvidia\nvapi" [$WINDOWS]
|
||||
$AdditionalIncludeDirectories "$BASE;$(XEDK)\include\xbox;..\" [$X360]
|
||||
$AdditionalIncludeDirectories "$BASE;..\" [$PS3||$POSIX||$GL]
|
||||
$PreprocessorDefinitions "$BASE;SHADERAPIDX9;SHADER_DLL_EXPORT;PROTECTED_THINGS_ENABLE;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead"
|
||||
$PreprocessorDefinitions "$BASE;USE_ACTUAL_DX" [( $WINDOWS || $X360 ) && !$GL]
|
||||
$PreprocessorDefinitions "$BASE;GL_GLEXT_PROTOTYPES;DX_TO_GL_ABSTRACTION" [$GL]
|
||||
// $AdditionalOptions "/FC"
|
||||
}
|
||||
|
||||
$Linker
|
||||
{
|
||||
$SystemFrameworks "Carbon;OpenGL;Quartz;Cocoa;IOKit"
|
||||
$SystemLibraries "iconv" [$OSXALL]
|
||||
$AdditionalDependencies "$BASE ws2_32.lib" [$WINDOWS]
|
||||
$AdditionalDependencies "$BASE libgcm_sys_stub.a libsysutil_stub.a libresc_stub.a libspurs_stub.a" [$PS3]
|
||||
}
|
||||
}
|
||||
|
||||
$Configuration "Debug"
|
||||
{
|
||||
$Linker [$X360]
|
||||
{
|
||||
$AdditionalDependencies "$BASE d3dx9d.lib xuirund.lib xuirenderd.lib xaudiod2.lib xmcored.lib"
|
||||
}
|
||||
$Linker [$PS3]
|
||||
{
|
||||
// NOTE: We refer to our own build of libPSGL but to system version of libPSGLcgc, even though we build and maintain our own version of libPSGLcgc as well
|
||||
$AdditionalDependencies "$BASE libgcm_cmddbg.a"
|
||||
}
|
||||
}
|
||||
|
||||
$Configuration "Release"
|
||||
{
|
||||
$Linker [$X360]
|
||||
{
|
||||
$AdditionalDependencies "$BASE d3dx9.lib xuirun.lib xuirender.lib xaudio2.lib xmcore.lib"
|
||||
}
|
||||
|
||||
// NOTE: We refer to our own build of libPSGL but to system version of libPSGLcgc, even though we build and maintain our own version of libPSGLcgc as well
|
||||
// Also, there are 2 release build configurations, ultra-opt and opt, which are different by this one thing only: there's no error checking in "ultra", so it'll be ultra-hard to debug RSX crashes. So, it's linked against in CERT builds only
|
||||
|
||||
$Linker [$PS3]
|
||||
{
|
||||
$AdditionalDependencies "$BASE libgcm_cmd.a"
|
||||
}
|
||||
}
|
||||
|
||||
$include "shaderapidx9_inc.vpc"
|
||||
|
||||
$Project "shaderapidx9"
|
||||
{
|
||||
$Folder "Link Libraries"
|
||||
{
|
||||
$Lib bitmap
|
||||
$Lib mathlib
|
||||
$Lib tier2
|
||||
$Lib vtf
|
||||
$Lib videocfg [$WINDOWS||$POSIX]
|
||||
$ImpLib togl [!$IS_LIB_PROJECT && $GL]
|
||||
|
||||
|
||||
$Lib "$LIBCOMMON\bzip2"
|
||||
|
||||
$File "$SRCDIR\dx9sdk\lib$PLATSUBDIR\d3d9.lib" [$WINDOWS && !$GL]
|
||||
$File "$SRCDIR\dx9sdk\lib$PLATSUBDIR\d3dx9.lib" [$WINDOWS && !$GL]
|
||||
|
||||
$File "$SRCDIR\thirdparty\nvidia\nvapi\lib$PLATSUBDIR\nvapi.lib" [$WINDOWS]
|
||||
}
|
||||
}
|
||||
93
materialsystem/shaderapidx9/shaderapidx9_inc.vpc
Normal file
93
materialsystem/shaderapidx9/shaderapidx9_inc.vpc
Normal file
@@ -0,0 +1,93 @@
|
||||
$Project
|
||||
{
|
||||
$Folder "ShaderApiDx9"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "$SHADERAPIDX9DIR\colorformatdx8.cpp"
|
||||
$File "$SHADERAPIDX9DIR\d3d_async.cpp"
|
||||
$File "$SRCDIR\public\filesystem_helpers.cpp" [!$OSXALL]
|
||||
$File "$SHADERAPIDX9DIR\hardwareconfig.cpp"
|
||||
$File "$SHADERAPIDX9DIR\meshbase.cpp"
|
||||
$File "$SHADERAPIDX9DIR\meshdx8.cpp"
|
||||
$File "$SHADERAPIDX9DIR\recording.cpp" [$WINDOWS && !$GL]
|
||||
$File "$SHADERAPIDX9DIR\shaderapidx8.cpp"
|
||||
$File "$SHADERAPIDX9DIR\shaderdevicebase.cpp"
|
||||
$File "$SHADERAPIDX9DIR\shaderapibase.cpp"
|
||||
$File "$SHADERAPIDX9DIR\shaderdevicedx8.cpp"
|
||||
$File "$SHADERAPIDX9DIR\shadershadowdx8.cpp"
|
||||
$File "$SHADERAPIDX9DIR\texturedx8.cpp"
|
||||
$File "$SHADERAPIDX9DIR\TransitionTable.cpp"
|
||||
$File "$SHADERAPIDX9DIR\cvballoctracker.cpp"
|
||||
$File "$SHADERAPIDX9DIR\vertexdecl.cpp"
|
||||
$File "$SHADERAPIDX9DIR\vertexshaderdx8.cpp"
|
||||
$File "$SHADERAPIDX9DIR\wmi.cpp" [$WINDOWS && !$GL]
|
||||
$File "$SHADERAPIDX9DIR\textureheap.cpp" [$X360]
|
||||
$File "$SRCDIR\common\ps3\vjobutils.cpp" [$PS3]
|
||||
$File "$SRCDIR\common\ps3\spu_job_shared.cpp" [$PS3]
|
||||
$File "$SHADERAPIDX9DIR\winutils.cpp" [!$WINDOWS]
|
||||
}
|
||||
|
||||
$Folder "Nvidia Stereo Header Files" [$WINDOWS && !$GL]
|
||||
{
|
||||
$File "$SHADERAPIDX9DIR\hl2stereo.h"
|
||||
}
|
||||
|
||||
$Folder "DirectX Header Files" [$WINDOWS && !$GL]
|
||||
{
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9anim.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9core.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9effect.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9math.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9math.inl"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9mesh.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9shader.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9shape.h"
|
||||
$File "$SRCDIR\dx9sdk\include\d3dx9tex.h"
|
||||
}
|
||||
|
||||
$Folder "Public Header Files"
|
||||
{
|
||||
$File "$SRCDIR\public\shaderapi\IShaderDevice.h"
|
||||
$File "$SRCDIR\public\shaderapi\ishaderutil.h"
|
||||
$File "$SRCDIR\public\shaderapi\ishaderapi.h"
|
||||
$File "$SRCDIR\public\shaderapi\ishaderdynamic.h"
|
||||
$File "$SRCDIR\public\shaderapi\ishadershadow.h"
|
||||
$File "$SRCDIR\public\shaderapi\commandbuffer.h"
|
||||
$File "$SRCDIR\public\materialsystem\idebugtextureinfo.h"
|
||||
$File "$SRCDIR\public\materialsystem\ivballoctracker.h"
|
||||
$File "$SRCDIR\public\materialsystem\shader_vcs_version.h"
|
||||
$File "$SRCDIR\public\vjobs\root.h"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "$SHADERAPIDX9DIR\TransitionTable.h"
|
||||
$File "$SHADERAPIDX9DIR\vertexdecl.h"
|
||||
$File "$SHADERAPIDX9DIR\colorformatdx8.h"
|
||||
$File "$SHADERAPIDX9DIR\d3d_async.h" [$WINDOWS]
|
||||
$File "$SHADERAPIDX9DIR\dynamicib.h"
|
||||
$File "$SHADERAPIDX9DIR\dynamicvb.h"
|
||||
$File "$SHADERAPIDX9DIR\hardwareconfig.h"
|
||||
$File "$SHADERAPIDX9DIR\meshbase.h"
|
||||
$File "$SHADERAPIDX9DIR\imeshdx8.h"
|
||||
$File "$SHADERAPIDX9DIR\locald3dtypes.h"
|
||||
$File "$SHADERAPIDX9DIR\recording.h"
|
||||
$File "$SHADERAPIDX9DIR\shaderapidx8.h"
|
||||
$File "$SHADERAPIDX9DIR\shaderdevicebase.h"
|
||||
$File "$SHADERAPIDX9DIR\shaderapibase.h"
|
||||
$File "$SHADERAPIDX9DIR\shaderdevicedx8.h"
|
||||
$File "$SHADERAPIDX9DIR\shaderapidx8_global.h"
|
||||
$File "$SHADERAPIDX9DIR\shadershadowdx8.h"
|
||||
$File "$SHADERAPIDX9DIR\stubd3ddevice.h"
|
||||
$File "$SHADERAPIDX9DIR\texturedx8.h"
|
||||
$File "$SHADERAPIDX9DIR\vertexshaderdx8.h"
|
||||
$File "$SHADERAPIDX9DIR\wmi.h" [$WINDOWS && !$GL]
|
||||
$File "$SHADERAPIDX9DIR\textureheap.h" [$X360]
|
||||
$File "$SHADERAPIDX9DIR\hardwareconfig_ps3nonvirt.h" [$PS3]
|
||||
$File "$SHADERAPIDX9DIR\hardwareconfig_ps3nonvirt.inl" [$PS3]
|
||||
$File "$SHADERAPIDX9DIR\shaderapidx8_ps3nonvirt.inl" [$PS3]
|
||||
}
|
||||
}
|
||||
}
|
||||
1235
materialsystem/shaderapidx9/shaderdevicebase.cpp
Normal file
1235
materialsystem/shaderapidx9/shaderdevicebase.cpp
Normal file
File diff suppressed because it is too large
Load Diff
239
materialsystem/shaderapidx9/shaderdevicebase.h
Normal file
239
materialsystem/shaderapidx9/shaderdevicebase.h
Normal file
@@ -0,0 +1,239 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERDEVICEBASE_H
|
||||
#define SHADERDEVICEBASE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
#include "shaderapi/IShaderDevice.h"
|
||||
#include "IHardwareConfigInternal.h"
|
||||
#include "bitmap/imageformat.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "hardwareconfig.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class KeyValues;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// define this if you want to run with NVPERFHUD
|
||||
//-----------------------------------------------------------------------------
|
||||
//#define NVPERFHUD 1
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Uncomment this to activate the reference rasterizer
|
||||
//-----------------------------------------------------------------------------
|
||||
//#define USE_REFERENCE_RASTERIZER 1
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Base implementation of the shader device
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderDeviceMgrBase : public CBaseAppSystem< IShaderDeviceMgr >
|
||||
{
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderDeviceMgrBase();
|
||||
virtual ~CShaderDeviceMgrBase();
|
||||
|
||||
// Methods of IAppSystem
|
||||
virtual bool Connect( CreateInterfaceFn factory );
|
||||
virtual void Disconnect();
|
||||
virtual void *QueryInterface( const char *pInterfaceName );
|
||||
|
||||
// Methods of IShaderDeviceMgr
|
||||
virtual bool GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, KeyValues *pCongifuration );
|
||||
virtual void AddModeChangeCallback( ShaderModeChangeCallbackFunc_t func );
|
||||
virtual void RemoveModeChangeCallback( ShaderModeChangeCallbackFunc_t func );
|
||||
virtual bool GetRecommendedVideoConfig( int nAdapter, KeyValues *pConfiguration );
|
||||
|
||||
virtual void AddDeviceDependentObject( IShaderDeviceDependentObject *pObject );
|
||||
virtual void RemoveDeviceDependentObject( IShaderDeviceDependentObject *pObject );
|
||||
virtual void InvokeDeviceLostNotifications( void );
|
||||
virtual void InvokeDeviceResetNotifications( IDirect3DDevice9 *pDevice, D3DPRESENT_PARAMETERS *pPresentParameters, void *pHWnd );
|
||||
|
||||
// Reads in the hardware caps from the dxsupport.cfg file
|
||||
void ReadHardwareCaps( HardwareCaps_t &caps, int nDxLevel );
|
||||
|
||||
// Reads in the max + preferred DX support level
|
||||
void ReadDXSupportLevels( HardwareCaps_t &caps );
|
||||
|
||||
// Returns the hardware caps for a particular adapter
|
||||
const HardwareCaps_t& GetHardwareCaps( int nAdapter ) const;
|
||||
|
||||
// Invokes mode change callbacks
|
||||
void InvokeModeChangeCallbacks( int screenWidth, int screenHeight );
|
||||
|
||||
// Factory to return from SetMode
|
||||
static void* ShaderInterfaceFactory( const char *pInterfaceName, int *pReturnCode );
|
||||
|
||||
// Returns only valid dx levels
|
||||
int GetClosestActualDXLevel( int nDxLevel ) const;
|
||||
|
||||
protected:
|
||||
struct AdapterInfo_t
|
||||
{
|
||||
HardwareCaps_t m_ActualCaps;
|
||||
};
|
||||
|
||||
private:
|
||||
// Reads in the dxsupport.cfg keyvalues
|
||||
KeyValues *ReadDXSupportKeyValues();
|
||||
|
||||
// Reads in ConVars + config variables
|
||||
void LoadConfig( KeyValues *pKeyValues, KeyValues *pConfiguration );
|
||||
|
||||
// Loads the hardware caps, for cases in which the D3D caps lie or where we need to augment the caps
|
||||
void LoadHardwareCaps( KeyValues *pGroup, HardwareCaps_t &caps );
|
||||
|
||||
// Gets the recommended configuration associated with a particular dx level
|
||||
bool GetRecommendedVideoConfig( int nAdapter, int nVendorID, int nDeviceID, KeyValues *pConfiguration );
|
||||
bool GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, int nVendorID, int nDeviceID, KeyValues *pConfiguration );
|
||||
|
||||
// Returns the amount of video memory in bytes for a particular adapter
|
||||
virtual int GetVidMemBytes( int nAdapter ) const = 0;
|
||||
|
||||
// Returns the physical screen desktop resolution
|
||||
virtual void GetDesktopResolution( int *pWidth, int *pHeight, int nAdapter ) const = 0;
|
||||
|
||||
// Looks for override keyvalues in the dxsupport cfg keyvalues
|
||||
KeyValues *FindDXLevelSpecificConfig( KeyValues *pKeyValues, int nDxLevel );
|
||||
KeyValues *FindDXLevelAndVendorSpecificConfig( KeyValues *pKeyValues, int nDxLevel, int nVendorID );
|
||||
KeyValues *FindCPUSpecificConfig( KeyValues *pKeyValues, int nCPUMhz, bool bAMD );
|
||||
KeyValues *FindMemorySpecificConfig( KeyValues *pKeyValues, int nSystemRamMB );
|
||||
KeyValues *FindVidMemSpecificConfig( KeyValues *pKeyValues, int nVideoRamMB );
|
||||
KeyValues *FindCardSpecificConfig( KeyValues *pKeyValues, int nVendorID, int nDeviceID );
|
||||
|
||||
protected:
|
||||
// Stores adapter info for all adapters
|
||||
CUtlVector<AdapterInfo_t> m_Adapters;
|
||||
|
||||
// Installed mode change callbacks
|
||||
CUtlVector< ShaderModeChangeCallbackFunc_t > m_ModeChangeCallbacks;
|
||||
CUtlVector< IShaderDeviceDependentObject* > m_DeviceDependentObjects;
|
||||
|
||||
KeyValues *m_pDXSupport;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Base implementation of the shader device
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderDeviceBase : public IShaderDevice
|
||||
{
|
||||
public:
|
||||
enum IPCMessage_t
|
||||
{
|
||||
RELEASE_MESSAGE = 0x5E740DE0,
|
||||
REACQUIRE_MESSAGE = 0x5E740DE1,
|
||||
EVICT_MESSAGE = 0x5E740DE2,
|
||||
};
|
||||
|
||||
// Methods of IShaderDevice
|
||||
public:
|
||||
virtual ImageFormat GetBackBufferFormat() const;
|
||||
virtual int StencilBufferBits() const;
|
||||
virtual bool IsAAEnabled() const;
|
||||
virtual bool AddView( void* hWnd );
|
||||
virtual void RemoveView( void* hWnd );
|
||||
virtual void SetView( void* hWnd );
|
||||
virtual void GetWindowSize( int& nWidth, int& nHeight ) const;
|
||||
|
||||
// Methods exposed to the rest of shader api
|
||||
virtual bool InitDevice( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode ) = 0;
|
||||
virtual void ShutdownDevice() = 0;
|
||||
virtual bool IsDeactivated() const = 0;
|
||||
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderDeviceBase();
|
||||
virtual ~CShaderDeviceBase();
|
||||
|
||||
virtual void OtherAppInitializing( bool initializing ) {}
|
||||
virtual void EvictManagedResourcesInternal() {}
|
||||
|
||||
void* GetIPCHWnd();
|
||||
void SendIPCMessage( IPCMessage_t message );
|
||||
|
||||
protected:
|
||||
// IPC communication for multiple shaderapi apps
|
||||
void InstallWindowHook( void *hWnd );
|
||||
void RemoveWindowHook( void *hWnd );
|
||||
void SetCurrentThreadAsOwner();
|
||||
void RemoveThreadOwner();
|
||||
bool ThreadOwnsDevice();
|
||||
|
||||
// Finds a child window
|
||||
int FindView( void* hWnd ) const;
|
||||
|
||||
int m_nAdapter;
|
||||
void *m_hWnd;
|
||||
void* m_hWndCookie;
|
||||
bool m_bInitialized : 1;
|
||||
bool m_bIsMinimized : 1;
|
||||
|
||||
// The current view hwnd
|
||||
void* m_ViewHWnd;
|
||||
|
||||
int m_nWindowWidth;
|
||||
int m_nWindowHeight;
|
||||
ThreadId_t m_dwThreadId;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inline methods
|
||||
//-----------------------------------------------------------------------------
|
||||
inline void* CShaderDeviceBase::GetIPCHWnd()
|
||||
{
|
||||
return m_hWndCookie;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helper class to reduce code related to shader buffers
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T >
|
||||
class CShaderBuffer : public IShaderBuffer
|
||||
{
|
||||
public:
|
||||
CShaderBuffer( T *pBlob ) : m_pBlob( pBlob ) {}
|
||||
|
||||
virtual size_t GetSize() const
|
||||
{
|
||||
return m_pBlob ? m_pBlob->GetBufferSize() : 0;
|
||||
}
|
||||
|
||||
virtual const void* GetBits() const
|
||||
{
|
||||
return m_pBlob ? m_pBlob->GetBufferPointer() : NULL;
|
||||
}
|
||||
|
||||
virtual void Release()
|
||||
{
|
||||
if ( m_pBlob )
|
||||
{
|
||||
m_pBlob->Release();
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
private:
|
||||
T *m_pBlob;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // SHADERDEVICEBASE_H
|
||||
1003
materialsystem/shaderapidx9/shaderdevicedx10.cpp
Normal file
1003
materialsystem/shaderapidx9/shaderdevicedx10.cpp
Normal file
File diff suppressed because it is too large
Load Diff
255
materialsystem/shaderapidx9/shaderdevicedx10.h
Normal file
255
materialsystem/shaderapidx9/shaderdevicedx10.h
Normal file
@@ -0,0 +1,255 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERDEVICEDX10_H
|
||||
#define SHADERDEVICEDX10_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "shaderdevicebase.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/utlrbtree.h"
|
||||
#include "tier1/utllinkedlist.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declaration
|
||||
//-----------------------------------------------------------------------------
|
||||
struct IDXGIFactory;
|
||||
struct IDXGIAdapter;
|
||||
struct IDXGIOutput;
|
||||
struct IDXGISwapChain;
|
||||
struct ID3D10Device;
|
||||
struct ID3D10RenderTargetView;
|
||||
struct ID3D10VertexShader;
|
||||
struct ID3D10PixelShader;
|
||||
struct ID3D10GeometryShader;
|
||||
struct ID3D10InputLayout;
|
||||
struct ID3D10ShaderReflection;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Base implementation of the shader device
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderDeviceMgrDx10 : public CShaderDeviceMgrBase
|
||||
{
|
||||
typedef CShaderDeviceMgrBase BaseClass;
|
||||
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderDeviceMgrDx10();
|
||||
virtual ~CShaderDeviceMgrDx10();
|
||||
|
||||
// Methods of IAppSystem
|
||||
virtual bool Connect( CreateInterfaceFn factory );
|
||||
virtual void Disconnect();
|
||||
virtual InitReturnVal_t Init();
|
||||
virtual void Shutdown();
|
||||
|
||||
// Methods of IShaderDeviceMgr
|
||||
virtual int GetAdapterCount() const;
|
||||
virtual void GetAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const;
|
||||
virtual int GetModeCount( int nAdapter ) const;
|
||||
virtual void GetModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter, int mode ) const;
|
||||
virtual void GetCurrentModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter ) const;
|
||||
virtual bool SetAdapter( int nAdapter, int nFlags );
|
||||
virtual CreateInterfaceFn SetMode( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode );
|
||||
|
||||
private:
|
||||
// Returns the screen resolution
|
||||
virtual void GetDesktopResolution( int *pWidth, int *pHeight, int nAdapter ) const;
|
||||
|
||||
// Initialize adapter information
|
||||
void InitAdapterInfo();
|
||||
|
||||
// Determines hardware caps from D3D
|
||||
bool ComputeCapsFromD3D( HardwareCaps_t *pCaps, IDXGIAdapter *pAdapter, IDXGIOutput *pOutput );
|
||||
|
||||
// Returns the amount of video memory in bytes for a particular adapter
|
||||
virtual int GetVidMemBytes( int nAdapter ) const;
|
||||
|
||||
// Returns the appropriate adapter output to use
|
||||
IDXGIOutput* GetAdapterOutput( int nAdapter ) const;
|
||||
|
||||
// Returns the adapter interface for a particular adapter
|
||||
IDXGIAdapter* GetAdapter( int nAdapter ) const;
|
||||
|
||||
// Used to enumerate adapters, attach to windows
|
||||
IDXGIFactory *m_pDXGIFactory;
|
||||
|
||||
friend class CShaderDeviceDx10;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Dx10 implementation of the shader device
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderDeviceDx10 : public CShaderDeviceBase
|
||||
{
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderDeviceDx10();
|
||||
virtual ~CShaderDeviceDx10();
|
||||
|
||||
public:
|
||||
// Methods of IShaderDevice
|
||||
virtual bool IsUsingGraphics() const;
|
||||
virtual int GetCurrentAdapter() const;
|
||||
virtual ImageFormat GetBackBufferFormat() const;
|
||||
virtual void GetBackBufferDimensions( int& width, int& height ) const;
|
||||
virtual void SpewDriverInfo() const;
|
||||
virtual void Present();
|
||||
virtual IShaderBuffer* CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion );
|
||||
virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer *pShader );
|
||||
virtual void DestroyVertexShader( VertexShaderHandle_t hShader );
|
||||
virtual GeometryShaderHandle_t CreateGeometryShader( IShaderBuffer* pShaderBuffer );
|
||||
virtual void DestroyGeometryShader( GeometryShaderHandle_t hShader );
|
||||
virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer );
|
||||
virtual void DestroyPixelShader( PixelShaderHandle_t hShader );
|
||||
virtual void ReleaseResources( bool bReleaseManagedResources = true ) {}
|
||||
virtual void ReacquireResources() {}
|
||||
virtual IMesh* CreateStaticMesh( VertexFormat_t format, const char *pTextureBudgetGroup, IMaterial * pMaterial, VertexStreamSpec_t *pStreamSpec );
|
||||
virtual void DestroyStaticMesh( IMesh* mesh );
|
||||
virtual IVertexBuffer *CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pTextureBudgetGroup );
|
||||
virtual void DestroyVertexBuffer( IVertexBuffer *pVertexBuffer );
|
||||
virtual IIndexBuffer *CreateIndexBuffer( ShaderBufferType_t type, MaterialIndexFormat_t fmt, int nIndexCount, const char *pTextureBudgetGroup );
|
||||
virtual void DestroyIndexBuffer( IIndexBuffer *pIndexBuffer );
|
||||
virtual IVertexBuffer *GetDynamicVertexBuffer( int nStreamID, VertexFormat_t vertexFormat, bool bBuffered = true );
|
||||
virtual IIndexBuffer *GetDynamicIndexBuffer();
|
||||
virtual void SetHardwareGammaRamp( float fGamma, float fGammaTVRangeMin, float fGammaTVRangeMax, float fGammaTVExponent, bool bTVEnabled );
|
||||
|
||||
// A special path used to tick the front buffer while loading on the 360
|
||||
virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode, ShaderNonInteractiveInfo_t *pInfo ) {}
|
||||
virtual void RefreshFrontBufferNonInteractive( ) {}
|
||||
virtual void HandleThreadEvent( uint32 threadEvent ) {}
|
||||
|
||||
public:
|
||||
// Methods of CShaderDeviceBase
|
||||
virtual bool InitDevice( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode );
|
||||
virtual void ShutdownDevice();
|
||||
virtual bool IsDeactivated() const { return false; }
|
||||
|
||||
// Other public methods
|
||||
ID3D10VertexShader* GetVertexShader( VertexShaderHandle_t hShader ) const;
|
||||
ID3D10GeometryShader* GetGeometryShader( GeometryShaderHandle_t hShader ) const;
|
||||
ID3D10PixelShader* GetPixelShader( PixelShaderHandle_t hShader ) const;
|
||||
ID3D10InputLayout* GetInputLayout( VertexShaderHandle_t hShader, VertexFormat_t format );
|
||||
|
||||
private:
|
||||
struct InputLayout_t
|
||||
{
|
||||
ID3D10InputLayout *m_pInputLayout;
|
||||
VertexFormat_t m_VertexFormat;
|
||||
};
|
||||
|
||||
typedef CUtlRBTree< InputLayout_t, unsigned short > InputLayoutDict_t;
|
||||
|
||||
static bool InputLayoutLessFunc( const InputLayout_t &lhs, const InputLayout_t &rhs )
|
||||
{
|
||||
return ( lhs.m_VertexFormat < rhs.m_VertexFormat );
|
||||
}
|
||||
|
||||
struct VertexShader_t
|
||||
{
|
||||
ID3D10VertexShader *m_pShader;
|
||||
ID3D10ShaderReflection *m_pInfo;
|
||||
void *m_pByteCode;
|
||||
size_t m_nByteCodeLen;
|
||||
InputLayoutDict_t m_InputLayouts;
|
||||
|
||||
VertexShader_t() : m_InputLayouts( 0, 0, InputLayoutLessFunc ) {}
|
||||
};
|
||||
|
||||
struct GeometryShader_t
|
||||
{
|
||||
ID3D10GeometryShader *m_pShader;
|
||||
ID3D10ShaderReflection *m_pInfo;
|
||||
};
|
||||
|
||||
struct PixelShader_t
|
||||
{
|
||||
ID3D10PixelShader *m_pShader;
|
||||
ID3D10ShaderReflection *m_pInfo;
|
||||
};
|
||||
|
||||
typedef CUtlFixedLinkedList< VertexShader_t >::IndexType_t VertexShaderIndex_t;
|
||||
typedef CUtlFixedLinkedList< GeometryShader_t >::IndexType_t GeometryShaderIndex_t;
|
||||
typedef CUtlFixedLinkedList< PixelShader_t >::IndexType_t PixelShaderIndex_t;
|
||||
|
||||
void SetupHardwareCaps();
|
||||
void ReleaseInputLayouts( VertexShaderIndex_t nIndex );
|
||||
|
||||
IDXGIOutput *m_pOutput;
|
||||
ID3D10Device *m_pDevice;
|
||||
IDXGISwapChain *m_pSwapChain;
|
||||
ID3D10RenderTargetView *m_pRenderTargetView;
|
||||
|
||||
CUtlFixedLinkedList< VertexShader_t > m_VertexShaderDict;
|
||||
CUtlFixedLinkedList< GeometryShader_t > m_GeometryShaderDict;
|
||||
CUtlFixedLinkedList< PixelShader_t > m_PixelShaderDict;
|
||||
|
||||
friend ID3D10Device *D3D10Device();
|
||||
friend IDXGISwapChain *D3D10SwapChain();
|
||||
friend ID3D10RenderTargetView *D3D10RenderTargetView();
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inline methods of CShaderDeviceDx10
|
||||
//-----------------------------------------------------------------------------
|
||||
inline ID3D10VertexShader* CShaderDeviceDx10::GetVertexShader( VertexShaderHandle_t hShader ) const
|
||||
{
|
||||
if ( hShader != VERTEX_SHADER_HANDLE_INVALID )
|
||||
return m_VertexShaderDict[ (VertexShaderIndex_t)hShader ].m_pShader;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline ID3D10GeometryShader* CShaderDeviceDx10::GetGeometryShader( GeometryShaderHandle_t hShader ) const
|
||||
{
|
||||
if ( hShader != GEOMETRY_SHADER_HANDLE_INVALID )
|
||||
return m_GeometryShaderDict[ (GeometryShaderIndex_t)hShader ].m_pShader;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline ID3D10PixelShader* CShaderDeviceDx10::GetPixelShader( PixelShaderHandle_t hShader ) const
|
||||
{
|
||||
if ( hShader != PIXEL_SHADER_HANDLE_INVALID )
|
||||
return m_PixelShaderDict[ (PixelShaderIndex_t)hShader ].m_pShader;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton
|
||||
//-----------------------------------------------------------------------------
|
||||
extern CShaderDeviceDx10* g_pShaderDeviceDx10;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Utility methods
|
||||
//-----------------------------------------------------------------------------
|
||||
inline ID3D10Device *D3D10Device()
|
||||
{
|
||||
return g_pShaderDeviceDx10->m_pDevice;
|
||||
}
|
||||
|
||||
inline IDXGISwapChain *D3D10SwapChain()
|
||||
{
|
||||
return g_pShaderDeviceDx10->m_pSwapChain;
|
||||
}
|
||||
|
||||
inline ID3D10RenderTargetView *D3D10RenderTargetView()
|
||||
{
|
||||
return g_pShaderDeviceDx10->m_pRenderTargetView;
|
||||
}
|
||||
|
||||
|
||||
#endif // SHADERDEVICEDX10_H
|
||||
4335
materialsystem/shaderapidx9/shaderdevicedx8.cpp
Normal file
4335
materialsystem/shaderapidx9/shaderdevicedx8.cpp
Normal file
File diff suppressed because it is too large
Load Diff
404
materialsystem/shaderapidx9/shaderdevicedx8.h
Normal file
404
materialsystem/shaderapidx9/shaderdevicedx8.h
Normal file
@@ -0,0 +1,404 @@
|
||||
//===== Copyright (c) 1996-2008, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef SHADERDEVICEDX8_H
|
||||
#define SHADERDEVICEDX8_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "shaderdevicebase.h"
|
||||
#include "shaderapidx8_global.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Describes which D3DDEVTYPE to use
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef USE_REFERENCE_RASTERIZER
|
||||
#define DX8_DEVTYPE D3DDEVTYPE_HAL
|
||||
#else
|
||||
#define DX8_DEVTYPE D3DDEVTYPE_REF
|
||||
#endif
|
||||
|
||||
|
||||
// PC: By default, PIX profiling is explicitly disallowed using the D3DPERF_SetOptions(1) API on PC
|
||||
// X360: PIX_INSTRUMENTATION will only generate PIX events in RELEASE builds on 360
|
||||
// Also be sure to enable PIX_ENABLE in imaterialsystem.h
|
||||
// Uncomment to use PIX instrumentation:
|
||||
//#define PIX_INSTRUMENTATION
|
||||
|
||||
#define MAX_PIX_ERRORS 3
|
||||
|
||||
#if defined( PIX_INSTRUMENTATION ) && defined ( DX_TO_GL_ABSTRACTION ) && defined( _WIN32 )
|
||||
typedef int (WINAPI *D3DPERF_BeginEvent_FuncPtr)( D3DCOLOR col, LPCWSTR wszName );
|
||||
typedef int (WINAPI *D3DPERF_EndEvent_FuncPtr)( void );
|
||||
typedef void (WINAPI *D3DPERF_SetMarker_FuncPtr)( D3DCOLOR col, LPCWSTR wszName );
|
||||
typedef void (WINAPI *D3DPERF_SetOptions_FuncPtr)( DWORD dwOptions );
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Base implementation of the shader device
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderDeviceMgrDx8 : public CShaderDeviceMgrBase
|
||||
{
|
||||
typedef CShaderDeviceMgrBase BaseClass;
|
||||
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderDeviceMgrDx8();
|
||||
virtual ~CShaderDeviceMgrDx8();
|
||||
|
||||
// Methods of IAppSystem
|
||||
virtual bool Connect( CreateInterfaceFn factory );
|
||||
virtual void Disconnect();
|
||||
virtual InitReturnVal_t Init();
|
||||
virtual void Shutdown();
|
||||
|
||||
// Methods of IShaderDevice
|
||||
virtual int GetAdapterCount() const;
|
||||
virtual void GetAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const;
|
||||
virtual int GetModeCount( int nAdapter ) const;
|
||||
virtual void GetModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter, int mode ) const;
|
||||
virtual void GetCurrentModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter ) const;
|
||||
virtual bool SetAdapter( int nAdapter, int nFlags );
|
||||
virtual CreateInterfaceFn SetMode( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode );
|
||||
|
||||
// Determines hardware caps from D3D
|
||||
bool ComputeCapsFromD3D( HardwareCaps_t *pCaps, int nAdapter );
|
||||
|
||||
// Forces caps to a specific dx level
|
||||
void ForceCapsToDXLevel( HardwareCaps_t *pCaps, int nDxLevel, const HardwareCaps_t &actualCaps );
|
||||
|
||||
// Validates the mode...
|
||||
bool ValidateMode( int nAdapter, const ShaderDeviceInfo_t &info ) const;
|
||||
|
||||
// Returns the amount of video memory in bytes for a particular adapter
|
||||
virtual int GetVidMemBytes( int nAdapter ) const;
|
||||
|
||||
#if !defined( _X360 )
|
||||
FORCEINLINE IDirect3D9 *D3D() const
|
||||
{
|
||||
return m_pD3D;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined( PIX_INSTRUMENTATION ) && defined ( DX_TO_GL_ABSTRACTION ) && defined( _WIN32 )
|
||||
HMODULE m_hD3D9;
|
||||
D3DPERF_BeginEvent_FuncPtr m_pBeginEvent;
|
||||
D3DPERF_EndEvent_FuncPtr m_pEndEvent;
|
||||
D3DPERF_SetMarker_FuncPtr m_pSetMarker;
|
||||
D3DPERF_SetOptions_FuncPtr m_pSetOptions;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// Determine capabilities
|
||||
bool DetermineHardwareCaps( );
|
||||
|
||||
private:
|
||||
// Returns the screen resolution
|
||||
virtual void GetDesktopResolution( int *pWidth, int *pHeight, int nAdapter ) const;
|
||||
|
||||
// Initialize adapter information
|
||||
void InitAdapterInfo();
|
||||
|
||||
// Code to detect support for texture border mode (not a simple caps check)
|
||||
void CheckBorderColorSupport( HardwareCaps_t *pCaps, int nAdapter );
|
||||
|
||||
// Vendor-dependent code to detect support for various flavors of shadow mapping
|
||||
void CheckVendorDependentShadowMappingSupport( HardwareCaps_t *pCaps, int nAdapter );
|
||||
|
||||
// Vendor-dependent code to detect Alpha To Coverage Backdoors
|
||||
void CheckVendorDependentAlphaToCoverage( HardwareCaps_t *pCaps, int nAdapter );
|
||||
|
||||
// Vendor-dependent code to detect support for optimal depth buffer rt resolve
|
||||
void CheckVendorDependentDepthResolveSupport( HardwareCaps_t *pCaps, int nAdapter );
|
||||
|
||||
// Compute the effective DX support level based on all the other caps
|
||||
void ComputeDXSupportLevel( HardwareCaps_t &caps );
|
||||
|
||||
// Used to enumerate adapters, attach to windows
|
||||
#if !defined( _X360 )
|
||||
IDirect3D9 *m_pD3D;
|
||||
#endif
|
||||
|
||||
bool m_bAdapterInfoIntialized : 1;
|
||||
};
|
||||
|
||||
extern CShaderDeviceMgrDx8* g_pShaderDeviceMgrDx8;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// IDirect3D accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
#if defined( _X360 )
|
||||
|
||||
extern IDirect3D9 *m_pD3D;
|
||||
inline IDirect3D9* D3D()
|
||||
{
|
||||
return m_pD3D;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline IDirect3D9* D3D()
|
||||
{
|
||||
return g_pShaderDeviceMgrDx8->D3D();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define NUM_FRAME_SYNC_QUERIES 2
|
||||
#define NUM_FRAME_SYNC_FRAMES_LATENCY 0
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Dx8implementation of the shader device
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderDeviceDx8 : public CShaderDeviceBase
|
||||
{
|
||||
// Methods of IShaderDevice
|
||||
public:
|
||||
virtual bool IsUsingGraphics() const;
|
||||
virtual ImageFormat GetBackBufferFormat() const;
|
||||
virtual void GetBackBufferDimensions( int& width, int& height ) const;
|
||||
virtual const AspectRatioInfo_t &GetAspectRatioInfo( void ) const;
|
||||
virtual void Present();
|
||||
virtual IShaderBuffer* CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion );
|
||||
virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer *pBuffer );
|
||||
virtual void DestroyVertexShader( VertexShaderHandle_t hShader );
|
||||
virtual GeometryShaderHandle_t CreateGeometryShader( IShaderBuffer* pShaderBuffer );
|
||||
virtual void DestroyGeometryShader( GeometryShaderHandle_t hShader );
|
||||
virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer );
|
||||
virtual void DestroyPixelShader( PixelShaderHandle_t hShader );
|
||||
virtual void ReleaseResources( bool bReleaseManagedResources = true );
|
||||
virtual void ReacquireResources();
|
||||
virtual IMesh* CreateStaticMesh( VertexFormat_t format, const char *pBudgetGroup, IMaterial * pMaterial = NULL, VertexStreamSpec_t *pStreamSpec = NULL );
|
||||
virtual void DestroyStaticMesh( IMesh* mesh );
|
||||
virtual IVertexBuffer *CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup );
|
||||
virtual void DestroyVertexBuffer( IVertexBuffer *pVertexBuffer );
|
||||
virtual IIndexBuffer *CreateIndexBuffer( ShaderBufferType_t bufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup );
|
||||
virtual void DestroyIndexBuffer( IIndexBuffer *pIndexBuffer );
|
||||
virtual IVertexBuffer *GetDynamicVertexBuffer( int nStreamID, VertexFormat_t vertexFormat, bool bBuffered = true );
|
||||
virtual IIndexBuffer *GetDynamicIndexBuffer();
|
||||
virtual void SetHardwareGammaRamp( float fGamma, float fGammaTVRangeMin, float fGammaTVRangeMax, float fGammaTVExponent, bool bTVEnabled );
|
||||
virtual void SpewDriverInfo() const;
|
||||
virtual int GetCurrentAdapter() const;
|
||||
virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode, ShaderNonInteractiveInfo_t *pInfo = NULL );
|
||||
virtual void RefreshFrontBufferNonInteractive();
|
||||
|
||||
// Alternative method for ib/vs
|
||||
// NOTE: If this works, remove GetDynamicVertexBuffer/IndexBuffer
|
||||
|
||||
// Methods of CShaderDeviceBase
|
||||
public:
|
||||
virtual bool InitDevice( void* hWnd, int nAdapter, const ShaderDeviceInfo_t &info );
|
||||
virtual void ShutdownDevice();
|
||||
virtual bool IsDeactivated() const;
|
||||
|
||||
// Other public methods
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderDeviceDx8();
|
||||
virtual ~CShaderDeviceDx8();
|
||||
|
||||
// Call this when another app is initializing or finished initializing
|
||||
virtual void OtherAppInitializing( bool initializing );
|
||||
|
||||
// This handles any events queued because they were called outside of the owning thread
|
||||
virtual void HandleThreadEvent( uint32 threadEvent );
|
||||
|
||||
// FIXME: Make private
|
||||
// Which device are we using?
|
||||
UINT m_DisplayAdapter;
|
||||
D3DDEVTYPE m_DeviceType;
|
||||
|
||||
protected:
|
||||
enum DeviceState_t
|
||||
{
|
||||
DEVICE_STATE_OK = 0,
|
||||
DEVICE_STATE_OTHER_APP_INIT,
|
||||
DEVICE_STATE_LOST_DEVICE,
|
||||
DEVICE_STATE_NEEDS_RESET,
|
||||
};
|
||||
|
||||
struct NonInteractiveRefreshState_t
|
||||
{
|
||||
IDirect3DVertexShader9 *m_pVertexShader;
|
||||
IDirect3DPixelShader9 *m_pPixelShader;
|
||||
IDirect3DPixelShader9 *m_pPixelShaderStartup;
|
||||
IDirect3DPixelShader9 *m_pPixelShaderStartupPass2;
|
||||
IDirect3DVertexDeclaration9 *m_pVertexDecl;
|
||||
ShaderNonInteractiveInfo_t m_Info;
|
||||
MaterialNonInteractiveMode_t m_Mode;
|
||||
float m_flLastPacifierTime;
|
||||
int m_nPacifierFrame;
|
||||
|
||||
float m_flStartTime;
|
||||
float m_flLastPresentTime;
|
||||
float m_flPeakDt;
|
||||
float m_flTotalDt;
|
||||
int m_nSamples;
|
||||
int m_nCountAbove66;
|
||||
};
|
||||
|
||||
protected:
|
||||
// Creates the D3D Device
|
||||
bool CreateD3DDevice( void* pHWnd, int nAdapter, const ShaderDeviceInfo_t &info );
|
||||
|
||||
// Actually creates the D3D Device once the present parameters are set up
|
||||
IDirect3DDevice9* InvokeCreateDevice( void* hWnd, int nAdapter, DWORD deviceCreationFlags );
|
||||
|
||||
// Checks for CreateQuery support
|
||||
void DetectQuerySupport( IDirect3DDevice9* pD3DDevice );
|
||||
|
||||
// Computes the presentation parameters
|
||||
void SetPresentParameters( void* hWnd, int nAdapter, const ShaderDeviceInfo_t &info, bool bSetSymbolsOnly = false );
|
||||
void CalcBackBufferDimensions( const ShaderDisplayMode_t &mode, const ShaderDeviceInfo_t &info, int *pBackBufferWidth, int *pBackBufferHeight );
|
||||
|
||||
// Computes the supersample flags
|
||||
D3DMULTISAMPLE_TYPE ComputeMultisampleType( int nSampleCount );
|
||||
|
||||
// Is the device active?
|
||||
bool IsActive() const;
|
||||
|
||||
// Try to reset the device, returned true if it succeeded
|
||||
bool TryDeviceReset();
|
||||
|
||||
// Queue up the fact that the device was lost
|
||||
void MarkDeviceLost();
|
||||
|
||||
// Deals with lost devices
|
||||
void CheckDeviceLost( bool bOtherAppInitializing );
|
||||
|
||||
// Changes the window size
|
||||
bool ResizeWindow( const ShaderDeviceInfo_t &info );
|
||||
|
||||
// Deals with the frame synching object
|
||||
void AllocFrameSyncObjects( void );
|
||||
void FreeFrameSyncObjects( void );
|
||||
|
||||
// Alloc and free objects that are necessary for frame syncing
|
||||
void AllocFrameSyncTextureObject();
|
||||
void FreeFrameSyncTextureObject();
|
||||
|
||||
// Alloc and free objects necessary for noninteractive frame refresh on the x360
|
||||
bool AllocNonInteractiveRefreshObjects();
|
||||
void FreeNonInteractiveRefreshObjects();
|
||||
bool BuildStaticShader( bool bVertexShader, void **ppShader, const char *shaderName,
|
||||
const char *strShaderProgram, const DWORD *shaderData, unsigned int shaderSize );
|
||||
|
||||
// FIXME: This is for backward compat; I still haven't solved a way of decoupling this
|
||||
virtual bool OnAdapterSet() = 0;
|
||||
virtual void ResetRenderState( bool bFullReset = true ) = 0;
|
||||
|
||||
// For measuring if we meed TCR 022 on the XBox (refreshing often enough)
|
||||
void UpdatePresentStats();
|
||||
|
||||
bool InNonInteractiveMode() const;
|
||||
|
||||
void ReacquireResourcesInternal( bool bResetState = false, bool bForceReacquire = false, char const *pszForceReason = NULL );
|
||||
|
||||
|
||||
void OnDebugEvent( const char * pEvent = "" );
|
||||
#ifdef DX_TO_GL_ABSTRACTION
|
||||
public:
|
||||
virtual void DoStartupShaderPreloading( void );
|
||||
|
||||
protected:
|
||||
#endif
|
||||
|
||||
#ifndef _GAMECONSOLE
|
||||
IDirect3DDevice9 *m_pD3DDevice;
|
||||
#endif
|
||||
|
||||
D3DPRESENT_PARAMETERS m_PresentParameters;
|
||||
ImageFormat m_AdapterFormat;
|
||||
|
||||
// Mode info
|
||||
int m_DeviceSupportsCreateQuery;
|
||||
|
||||
ShaderDeviceInfo_t m_PendingVideoModeChangeConfig;
|
||||
DeviceState_t m_DeviceState;
|
||||
|
||||
bool m_bOtherAppInitializing : 1;
|
||||
bool m_bQueuedDeviceLost : 1;
|
||||
bool m_IsResizing : 1;
|
||||
bool m_bPendingVideoModeChange : 1;
|
||||
bool m_bUsingStencil : 1;
|
||||
bool m_bResourcesReleased : 1;
|
||||
|
||||
// amount of stencil variation we have available
|
||||
int m_iStencilBufferBits;
|
||||
|
||||
#ifdef _X360
|
||||
CON_COMMAND_MEMBER_F( CShaderDeviceDx8, "360vidinfo", SpewVideoInfo360, "Get information on the video mode on the 360", 0 );
|
||||
#endif
|
||||
|
||||
// Frame sync objects
|
||||
IDirect3DQuery9 *m_pFrameSyncQueryObject[NUM_FRAME_SYNC_QUERIES];
|
||||
bool m_bQueryIssued[NUM_FRAME_SYNC_QUERIES];
|
||||
int m_currentSyncQuery;
|
||||
IDirect3DTexture9 *m_pFrameSyncTexture;
|
||||
|
||||
#if defined( _X360 )
|
||||
HXUIDC m_hDC;
|
||||
#endif
|
||||
|
||||
AspectRatioInfo_t m_AspectRatioInfo;
|
||||
|
||||
// Used for x360 only
|
||||
NonInteractiveRefreshState_t m_NonInteractiveRefresh;
|
||||
CThreadFastMutex m_nonInteractiveModeMutex;
|
||||
friend class CShaderDeviceMgrDx8;
|
||||
|
||||
int m_numReleaseResourcesRefCount; // This is holding the number of ReleaseResources calls queued up,
|
||||
// for every ReleaseResources call there should be a matching call to
|
||||
// ReacquireResources, only the last top-level ReacquireResources will
|
||||
// have effect. Nested ReleaseResources calls are bugs.
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Globals
|
||||
//-----------------------------------------------------------------------------
|
||||
#if defined( _GAMECONSOLE )
|
||||
extern IDirect3DDevice9 *m_pD3DDevice;
|
||||
FORCEINLINE IDirect3DDevice9 *Dx9Device()
|
||||
{
|
||||
return m_pD3DDevice;
|
||||
}
|
||||
#else
|
||||
class D3DDeviceWrapper;
|
||||
D3DDeviceWrapper *Dx9Device();
|
||||
#endif
|
||||
|
||||
extern CShaderDeviceDx8* g_pShaderDeviceDx8;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Inline methods
|
||||
//-----------------------------------------------------------------------------
|
||||
#if defined( _GAMECONSOLE )
|
||||
FORCEINLINE bool CShaderDeviceDx8::IsActive() const
|
||||
{
|
||||
return ( m_pD3DDevice != NULL );
|
||||
}
|
||||
#endif
|
||||
|
||||
// used to determine if we're deactivated
|
||||
FORCEINLINE bool CShaderDeviceDx8::IsDeactivated() const
|
||||
{
|
||||
return ( IsPC() && ( ( m_DeviceState != DEVICE_STATE_OK ) || m_bQueuedDeviceLost || m_numReleaseResourcesRefCount ) );
|
||||
}
|
||||
|
||||
|
||||
#endif // SHADERDEVICEDX8_H
|
||||
173
materialsystem/shaderapidx9/shadershadowdx10.cpp
Normal file
173
materialsystem/shaderapidx9/shadershadowdx10.cpp
Normal file
@@ -0,0 +1,173 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "shadershadowdx10.h"
|
||||
#include "utlvector.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "IHardwareConfigInternal.h"
|
||||
#include "shadersystem.h"
|
||||
#include "shaderapi/ishaderutil.h"
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "materialsystem/idebugtextureinfo.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Class Factory
|
||||
//-----------------------------------------------------------------------------
|
||||
static CShaderShadowDx10 s_ShaderShadow;
|
||||
CShaderShadowDx10 *g_pShaderShadowDx10 = &s_ShaderShadow;
|
||||
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderShadowDx10, IShaderShadow,
|
||||
SHADERSHADOW_INTERFACE_VERSION, s_ShaderShadow )
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The shader shadow interface
|
||||
//-----------------------------------------------------------------------------
|
||||
CShaderShadowDx10::CShaderShadowDx10()
|
||||
{
|
||||
m_IsTranslucent = false;
|
||||
m_IsAlphaTested = false;
|
||||
m_bIsDepthWriteEnabled = true;
|
||||
m_bUsesVertexAndPixelShaders = false;
|
||||
}
|
||||
|
||||
CShaderShadowDx10::~CShaderShadowDx10()
|
||||
{
|
||||
}
|
||||
|
||||
// Sets the default *shadow* state
|
||||
void CShaderShadowDx10::SetDefaultState()
|
||||
{
|
||||
m_IsTranslucent = false;
|
||||
m_IsAlphaTested = false;
|
||||
m_bIsDepthWriteEnabled = true;
|
||||
m_bUsesVertexAndPixelShaders = false;
|
||||
}
|
||||
|
||||
// Methods related to depth buffering
|
||||
void CShaderShadowDx10::DepthFunc( ShaderDepthFunc_t depthFunc )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableDepthWrites( bool bEnable )
|
||||
{
|
||||
m_bIsDepthWriteEnabled = bEnable;
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableDepthTest( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnablePolyOffset( PolygonOffsetMode_t nOffsetMode )
|
||||
{
|
||||
}
|
||||
|
||||
// Suppresses/activates color writing
|
||||
void CShaderShadowDx10::EnableColorWrites( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
// Suppresses/activates alpha writing
|
||||
void CShaderShadowDx10::EnableAlphaWrites( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
// Methods related to alpha blending
|
||||
void CShaderShadowDx10::EnableBlending( bool bEnable )
|
||||
{
|
||||
m_IsTranslucent = bEnable;
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableBlendingForceOpaque( bool bEnable )
|
||||
{
|
||||
m_IsTranslucent = bEnable;
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::BlendOp( ShaderBlendOp_t blendOp )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::BlendOpSeparateAlpha( ShaderBlendOp_t blendOp )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::SetShadowDepthFiltering( Sampler_t stage )
|
||||
{
|
||||
}
|
||||
|
||||
// Alpha testing
|
||||
void CShaderShadowDx10::EnableAlphaTest( bool bEnable )
|
||||
{
|
||||
m_IsAlphaTested = bEnable;
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ )
|
||||
{
|
||||
}
|
||||
|
||||
// Wireframe/filled polygons
|
||||
void CShaderShadowDx10::PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Back face culling
|
||||
void CShaderShadowDx10::EnableCulling( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
// Alpha to coverage
|
||||
void CShaderShadowDx10::EnableAlphaToCoverage( bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Indicates the vertex format for use with a vertex shader
|
||||
// The flags to pass in here come from the VertexFormatFlags_t enum
|
||||
// If pTexCoordDimensions is *not* specified, we assume all coordinates
|
||||
// are 2-dimensional
|
||||
void CShaderShadowDx10::VertexShaderVertexFormat( unsigned int flags,
|
||||
int numTexCoords, int* pTexCoordDimensions,
|
||||
int userDataSize )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableTexture( Sampler_t stage, bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableVertexTexture( VertexTextureSampler_t stage, bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
// Sets the vertex and pixel shaders
|
||||
void CShaderShadowDx10::SetVertexShader( const char *pShaderName, int vshIndex )
|
||||
{
|
||||
m_bUsesVertexAndPixelShaders = ( pShaderName != NULL );
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::EnableBlendingSeparateAlpha( bool bEnable )
|
||||
{
|
||||
}
|
||||
void CShaderShadowDx10::SetPixelShader( const char *pShaderName, int pshIndex )
|
||||
{
|
||||
m_bUsesVertexAndPixelShaders = ( pShaderName != NULL );
|
||||
}
|
||||
|
||||
void CShaderShadowDx10::BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor )
|
||||
{
|
||||
}
|
||||
|
||||
807
materialsystem/shaderapidx9/shadershadowdx8.cpp
Normal file
807
materialsystem/shaderapidx9/shadershadowdx8.cpp
Normal file
@@ -0,0 +1,807 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
#define DISABLE_PROTECTED_THINGS
|
||||
#include "togl/rendermechanism.h"
|
||||
#include "shadershadowdx8.h"
|
||||
#include "locald3dtypes.h"
|
||||
#include "utlvector.h"
|
||||
#include "shaderapi/ishaderutil.h"
|
||||
#include "shaderapidx8_global.h"
|
||||
#include "shaderapidx8.h"
|
||||
#include "materialsystem/imaterialsystemhardwareconfig.h"
|
||||
#include "materialsystem/imaterialsystem.h"
|
||||
#include "imeshdx8.h"
|
||||
#include "materialsystem/materialsystem_config.h"
|
||||
#include "vertexshaderdx8.h"
|
||||
|
||||
// NOTE: This must be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The DX8 implementation of the shader setup interface
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderShadowDX8 : public IShaderShadowDX8
|
||||
{
|
||||
public:
|
||||
// constructor, destructor
|
||||
CShaderShadowDX8( );
|
||||
virtual ~CShaderShadowDX8();
|
||||
|
||||
// Initialize render state
|
||||
void Init( );
|
||||
|
||||
// Sets the default state
|
||||
void SetDefaultState();
|
||||
|
||||
// Methods related to depth buffering
|
||||
void DepthFunc( ShaderDepthFunc_t depthFunc );
|
||||
void EnableDepthWrites( bool bEnable );
|
||||
void EnableDepthTest( bool bEnable );
|
||||
void EnablePolyOffset( PolygonOffsetMode_t nOffsetMode );
|
||||
|
||||
// Suppresses/activates color writing
|
||||
void EnableColorWrites( bool bEnable );
|
||||
void EnableAlphaWrites( bool bEnable );
|
||||
|
||||
// Methods related to alpha blending
|
||||
void EnableBlending( bool bEnable );
|
||||
void EnableBlendingForceOpaque( bool bEnable );
|
||||
void BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor );
|
||||
void BlendOp( ShaderBlendOp_t blendOp );
|
||||
void EnableBlendingSeparateAlpha( bool bEnable );
|
||||
void BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor );
|
||||
void BlendOpSeparateAlpha( ShaderBlendOp_t blendOp );
|
||||
|
||||
// Alpha testing
|
||||
void EnableAlphaTest( bool bEnable );
|
||||
void AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ );
|
||||
|
||||
// Wireframe/filled polygons
|
||||
void PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode );
|
||||
|
||||
// Back face culling
|
||||
void EnableCulling( bool bEnable );
|
||||
|
||||
// Convert from linear to gamma color space on writes to frame buffer.
|
||||
void EnableSRGBWrite( bool bEnable );
|
||||
|
||||
// Convert from gamma to linear on texture fetch.
|
||||
void EnableSRGBRead( Sampler_t stage, bool bEnable );
|
||||
|
||||
// Set up appropriate shadow filtering state (such as Fetch4 on ATI)
|
||||
//void SetShadowDepthFiltering( Sampler_t stage );
|
||||
|
||||
// Computes the vertex format
|
||||
virtual void VertexShaderVertexFormat( unsigned int nFlags,
|
||||
int nTexCoordCount, int* pTexCoordDimensions, int nUserDataSize );
|
||||
|
||||
// Pixel and vertex shader methods
|
||||
virtual void SetVertexShader( const char* pFileName, int nStaticVshIndex );
|
||||
virtual void SetPixelShader( const char* pFileName, int nStaticPshIndex );
|
||||
|
||||
// Per texture unit stuff
|
||||
void EnableTexture( Sampler_t stage, bool bEnable );
|
||||
void EnableVertexTexture( VertexTextureSampler_t sampler, bool bEnable );
|
||||
|
||||
// Last call to be make before snapshotting
|
||||
void ComputeAggregateShadowState( );
|
||||
|
||||
// Gets at the shadow state
|
||||
const ShadowState_t & GetShadowState();
|
||||
const ShadowShaderState_t & GetShadowShaderState();
|
||||
|
||||
void FogMode( ShaderFogMode_t fogMode, bool bVertexFog );
|
||||
void DisableFogGammaCorrection( bool bDisable );
|
||||
|
||||
// Alpha to coverage
|
||||
void EnableAlphaToCoverage( bool bEnable );
|
||||
|
||||
virtual float GetLightMapScaleFactor( void ) const;
|
||||
|
||||
private:
|
||||
struct SamplerState_t
|
||||
{
|
||||
bool m_TextureEnable : 1;
|
||||
};
|
||||
|
||||
// Computes the blend factor
|
||||
D3DBLEND BlendFuncValue( ShaderBlendFactor_t factor ) const;
|
||||
|
||||
// Computes the blend op
|
||||
D3DBLENDOP BlendOpValue( ShaderBlendOp_t blendOp ) const;
|
||||
|
||||
// Configures our texture indices
|
||||
void ConfigureTextureCoordinates( unsigned int flags );
|
||||
|
||||
// returns true if we're using texture coordinates at a given stage
|
||||
bool IsUsingTextureCoordinates( Sampler_t stage ) const;
|
||||
|
||||
// State needed to create the snapshots
|
||||
IMaterialSystemHardwareConfig* m_pHardwareConfig;
|
||||
|
||||
// Alpha blending...
|
||||
D3DBLEND m_SrcBlend;
|
||||
D3DBLEND m_DestBlend;
|
||||
D3DBLENDOP m_BlendOp;
|
||||
|
||||
// Separate alpha blending...
|
||||
D3DBLEND m_SrcBlendAlpha;
|
||||
D3DBLEND m_DestBlendAlpha;
|
||||
D3DBLENDOP m_BlendOpAlpha;
|
||||
|
||||
// Alpha testing
|
||||
D3DCMPFUNC m_AlphaFunc;
|
||||
int m_AlphaRef;
|
||||
|
||||
// The current shadow state
|
||||
ShadowState_t m_ShadowState;
|
||||
ShadowShaderState_t m_ShadowShaderState;
|
||||
|
||||
// State info stores with each sampler stage
|
||||
SamplerState_t m_SamplerState[MAX_SAMPLERS];
|
||||
SamplerState_t m_VertexSamplerState[MAX_VERTEX_SAMPLERS];
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Class factory
|
||||
//-----------------------------------------------------------------------------
|
||||
static CShaderShadowDX8 g_ShaderShadow;
|
||||
IShaderShadowDX8 *g_pShaderShadowDx8 = &g_ShaderShadow;
|
||||
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderShadowDX8, IShaderShadow,
|
||||
SHADERSHADOW_INTERFACE_VERSION, g_ShaderShadow )
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global instance
|
||||
//-----------------------------------------------------------------------------
|
||||
IShaderShadowDX8* ShaderShadow()
|
||||
{
|
||||
return &g_ShaderShadow;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CShaderShadowDX8::CShaderShadowDX8( ) : m_pHardwareConfig(0)
|
||||
{
|
||||
memset( &m_ShadowState, 0, sizeof(m_ShadowState) );
|
||||
}
|
||||
|
||||
CShaderShadowDX8::~CShaderShadowDX8()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Initialize render state
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderShadowDX8::Init( )
|
||||
{
|
||||
m_pHardwareConfig = g_pHardwareConfig;
|
||||
|
||||
// Clear out the shadow state
|
||||
memset( &m_ShadowState, 0, sizeof(m_ShadowState) );
|
||||
|
||||
m_ShadowState.m_FogAndMiscState.m_bDisableFogGammaCorrection = false;
|
||||
|
||||
// Pixel + vertex shaders
|
||||
m_ShadowShaderState.m_VertexShader = INVALID_SHADER;
|
||||
m_ShadowShaderState.m_PixelShader = INVALID_SHADER;
|
||||
m_ShadowShaderState.m_nStaticPshIndex = 0;
|
||||
m_ShadowShaderState.m_nStaticVshIndex = 0;
|
||||
m_ShadowShaderState.m_VertexUsage = 0;
|
||||
|
||||
m_ShadowState.m_nFetch4Enable = 0;
|
||||
#if ( defined ( DX_TO_GL_ABSTRACTION ) )
|
||||
m_ShadowState.m_nShadowFilterEnable = 0;
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < MAX_SAMPLERS; ++i)
|
||||
{
|
||||
// A *real* measure if the texture stage is being used.
|
||||
// we sometimes have to set the shadow state to not mirror this.
|
||||
m_SamplerState[i].m_TextureEnable = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the default state
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderShadowDX8::SetDefaultState()
|
||||
{
|
||||
DepthFunc( SHADER_DEPTHFUNC_NEAREROREQUAL );
|
||||
EnableDepthWrites( true );
|
||||
EnableDepthTest( true );
|
||||
EnableColorWrites( true );
|
||||
EnableAlphaWrites( false );
|
||||
EnableAlphaTest( false );
|
||||
EnableBlending( false );
|
||||
BlendFunc( SHADER_BLEND_ZERO, SHADER_BLEND_ZERO );
|
||||
BlendOp( SHADER_BLEND_OP_ADD );
|
||||
EnableBlendingSeparateAlpha( false );
|
||||
BlendFuncSeparateAlpha( SHADER_BLEND_ZERO, SHADER_BLEND_ZERO );
|
||||
BlendOpSeparateAlpha( SHADER_BLEND_OP_ADD );
|
||||
AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, 0.7f );
|
||||
PolyMode( SHADER_POLYMODEFACE_FRONT_AND_BACK, SHADER_POLYMODE_FILL );
|
||||
EnableCulling( true );
|
||||
EnableAlphaToCoverage( false );
|
||||
EnablePolyOffset( SHADER_POLYOFFSET_DISABLE );
|
||||
EnableSRGBWrite( false );
|
||||
SetVertexShader( NULL, 0 );
|
||||
SetPixelShader( NULL, 0 );
|
||||
FogMode( SHADER_FOGMODE_DISABLED, false );
|
||||
DisableFogGammaCorrection( false );
|
||||
m_ShadowShaderState.m_VertexUsage = 0;
|
||||
|
||||
int i;
|
||||
int nSamplerCount = HardwareConfig()->GetSamplerCount();
|
||||
for( i = 0; i < nSamplerCount; i++ )
|
||||
{
|
||||
EnableTexture( (Sampler_t)i, false );
|
||||
EnableSRGBRead( (Sampler_t)i, false );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets at the shadow state
|
||||
//-----------------------------------------------------------------------------
|
||||
const ShadowState_t &CShaderShadowDX8::GetShadowState()
|
||||
{
|
||||
return m_ShadowState;
|
||||
}
|
||||
|
||||
const ShadowShaderState_t &CShaderShadowDX8::GetShadowShaderState()
|
||||
{
|
||||
return m_ShadowShaderState;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Depth functions...
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderShadowDX8::DepthFunc( ShaderDepthFunc_t depthFunc )
|
||||
{
|
||||
D3DCMPFUNC zFunc;
|
||||
|
||||
switch( depthFunc )
|
||||
{
|
||||
case SHADER_DEPTHFUNC_NEVER:
|
||||
zFunc = D3DCMP_NEVER;
|
||||
break;
|
||||
case SHADER_DEPTHFUNC_NEARER:
|
||||
zFunc = (ShaderUtil()->GetConfig().bReverseDepth ^ ReverseDepthOnX360()) ? D3DCMP_GREATER : D3DCMP_LESS;
|
||||
break;
|
||||
case SHADER_DEPTHFUNC_EQUAL:
|
||||
zFunc = D3DCMP_EQUAL;
|
||||
break;
|
||||
case SHADER_DEPTHFUNC_NEAREROREQUAL:
|
||||
zFunc = (ShaderUtil()->GetConfig().bReverseDepth ^ ReverseDepthOnX360()) ? D3DCMP_GREATEREQUAL : D3DCMP_LESSEQUAL;
|
||||
break;
|
||||
case SHADER_DEPTHFUNC_FARTHER:
|
||||
zFunc = (ShaderUtil()->GetConfig().bReverseDepth ^ ReverseDepthOnX360()) ? D3DCMP_LESS : D3DCMP_GREATER;
|
||||
break;
|
||||
case SHADER_DEPTHFUNC_NOTEQUAL:
|
||||
zFunc = D3DCMP_NOTEQUAL;
|
||||
break;
|
||||
case SHADER_DEPTHFUNC_FARTHEROREQUAL:
|
||||
zFunc = (ShaderUtil()->GetConfig().bReverseDepth ^ ReverseDepthOnX360()) ? D3DCMP_LESSEQUAL : D3DCMP_GREATEREQUAL;
|
||||
break;
|
||||
case SHADER_DEPTHFUNC_ALWAYS:
|
||||
zFunc = D3DCMP_ALWAYS;
|
||||
break;
|
||||
default:
|
||||
zFunc = D3DCMP_ALWAYS;
|
||||
Warning( "DepthFunc: invalid param\n" );
|
||||
break;
|
||||
}
|
||||
|
||||
m_ShadowState.m_DepthTestState.m_ZFunc = zFunc;
|
||||
}
|
||||
|
||||
void CShaderShadowDX8::EnableDepthWrites( bool bEnable )
|
||||
{
|
||||
m_ShadowState.m_DepthTestState.m_ZWriteEnable = bEnable;
|
||||
}
|
||||
|
||||
void CShaderShadowDX8::EnableDepthTest( bool bEnable )
|
||||
{
|
||||
m_ShadowState.m_DepthTestState.m_ZEnable = bEnable ? D3DZB_TRUE : D3DZB_FALSE;
|
||||
}
|
||||
|
||||
void CShaderShadowDX8::EnablePolyOffset( PolygonOffsetMode_t nOffsetMode )
|
||||
{
|
||||
m_ShadowState.m_DepthTestState.m_ZBias = nOffsetMode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Color write state
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderShadowDX8::EnableColorWrites( bool bEnable )
|
||||
{
|
||||
if (bEnable)
|
||||
{
|
||||
m_ShadowState.m_DepthTestState.m_ColorWriteEnable |= D3DCOLORWRITEENABLE_BLUE |
|
||||
D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ShadowState.m_DepthTestState.m_ColorWriteEnable &= ~( D3DCOLORWRITEENABLE_BLUE |
|
||||
D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED );
|
||||
}
|
||||
}
|
||||
|
||||
void CShaderShadowDX8::EnableAlphaWrites( bool bEnable )
|
||||
{
|
||||
if (bEnable)
|
||||
{
|
||||
m_ShadowState.m_DepthTestState.m_ColorWriteEnable |= D3DCOLORWRITEENABLE_ALPHA;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ShadowState.m_DepthTestState.m_ColorWriteEnable &= ~D3DCOLORWRITEENABLE_ALPHA;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Alpha blending states
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderShadowDX8::EnableBlending( bool bEnable )
|
||||
{
|
||||
m_ShadowState.m_AlphaBlendState.m_AlphaBlendEnable = bEnable;
|
||||
m_ShadowState.m_AlphaBlendState.m_AlphaBlendEnabledForceOpaque = false;
|
||||
}
|
||||
|
||||
void CShaderShadowDX8::EnableBlendingForceOpaque( bool bEnable )
|
||||
{
|
||||
m_ShadowState.m_AlphaBlendState.m_AlphaBlendEnable = bEnable;
|
||||
m_ShadowState.m_AlphaBlendState.m_AlphaBlendEnabledForceOpaque = true;
|
||||
}
|
||||
|
||||
// Separate alpha blending
|
||||
void CShaderShadowDX8::EnableBlendingSeparateAlpha( bool bEnable )
|
||||
{
|
||||
m_ShadowState.m_AlphaBlendState.m_SeparateAlphaBlendEnable = bEnable;
|
||||
}
|
||||
|
||||
void CShaderShadowDX8::EnableAlphaTest( bool bEnable )
|
||||
{
|
||||
m_ShadowState.m_AlphaTestAndMiscState.m_AlphaTestEnable = bEnable;
|
||||
}
|
||||
|
||||
void CShaderShadowDX8::AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ )
|
||||
{
|
||||
D3DCMPFUNC d3dCmpFunc;
|
||||
|
||||
switch( alphaFunc )
|
||||
{
|
||||
case SHADER_ALPHAFUNC_NEVER:
|
||||
d3dCmpFunc = D3DCMP_NEVER;
|
||||
break;
|
||||
case SHADER_ALPHAFUNC_LESS:
|
||||
d3dCmpFunc = D3DCMP_LESS;
|
||||
break;
|
||||
case SHADER_ALPHAFUNC_EQUAL:
|
||||
d3dCmpFunc = D3DCMP_EQUAL;
|
||||
break;
|
||||
case SHADER_ALPHAFUNC_LEQUAL:
|
||||
d3dCmpFunc = D3DCMP_LESSEQUAL;
|
||||
break;
|
||||
case SHADER_ALPHAFUNC_GREATER:
|
||||
d3dCmpFunc = D3DCMP_GREATER;
|
||||
break;
|
||||
case SHADER_ALPHAFUNC_NOTEQUAL:
|
||||
d3dCmpFunc = D3DCMP_NOTEQUAL;
|
||||
break;
|
||||
case SHADER_ALPHAFUNC_GEQUAL:
|
||||
d3dCmpFunc = D3DCMP_GREATEREQUAL;
|
||||
break;
|
||||
case SHADER_ALPHAFUNC_ALWAYS:
|
||||
d3dCmpFunc = D3DCMP_ALWAYS;
|
||||
break;
|
||||
default:
|
||||
Warning( "AlphaFunc: invalid param\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
m_AlphaFunc = d3dCmpFunc;
|
||||
m_AlphaRef = (int)(alphaRef * 255);
|
||||
}
|
||||
|
||||
D3DBLEND CShaderShadowDX8::BlendFuncValue( ShaderBlendFactor_t factor ) const
|
||||
{
|
||||
switch( factor )
|
||||
{
|
||||
case SHADER_BLEND_ZERO:
|
||||
return D3DBLEND_ZERO;
|
||||
|
||||
case SHADER_BLEND_ONE:
|
||||
return D3DBLEND_ONE;
|
||||
|
||||
case SHADER_BLEND_DST_COLOR:
|
||||
return D3DBLEND_DESTCOLOR;
|
||||
|
||||
case SHADER_BLEND_ONE_MINUS_DST_COLOR:
|
||||
return D3DBLEND_INVDESTCOLOR;
|
||||
|
||||
case SHADER_BLEND_SRC_ALPHA:
|
||||
return D3DBLEND_SRCALPHA;
|
||||
|
||||
case SHADER_BLEND_ONE_MINUS_SRC_ALPHA:
|
||||
return D3DBLEND_INVSRCALPHA;
|
||||
|
||||
case SHADER_BLEND_DST_ALPHA:
|
||||
return D3DBLEND_DESTALPHA;
|
||||
|
||||
case SHADER_BLEND_ONE_MINUS_DST_ALPHA:
|
||||
return D3DBLEND_INVDESTALPHA;
|
||||
|
||||
case SHADER_BLEND_SRC_ALPHA_SATURATE:
|
||||
return D3DBLEND_SRCALPHASAT;
|
||||
|
||||
case SHADER_BLEND_SRC_COLOR:
|
||||
return D3DBLEND_SRCCOLOR;
|
||||
|
||||
case SHADER_BLEND_ONE_MINUS_SRC_COLOR:
|
||||
return D3DBLEND_INVSRCCOLOR;
|
||||
}
|
||||
|
||||
Warning( "BlendFunc: invalid factor\n" );
|
||||
return D3DBLEND_ONE;
|
||||
}
|
||||
|
||||
D3DBLENDOP CShaderShadowDX8::BlendOpValue( ShaderBlendOp_t blendOp ) const
|
||||
{
|
||||
switch( blendOp )
|
||||
{
|
||||
case SHADER_BLEND_OP_ADD:
|
||||
return D3DBLENDOP_ADD;
|
||||
|
||||
case SHADER_BLEND_OP_SUBTRACT:
|
||||
return D3DBLENDOP_SUBTRACT;
|
||||
|
||||
case SHADER_BLEND_OP_REVSUBTRACT:
|
||||
return D3DBLENDOP_REVSUBTRACT;
|
||||
|
||||
case SHADER_BLEND_OP_MIN:
|
||||
return D3DBLENDOP_MIN;
|
||||
|
||||
case SHADER_BLEND_OP_MAX:
|
||||
return D3DBLENDOP_MAX;
|
||||
}
|
||||
|
||||
Warning( "BlendOp: invalid op\n" );
|
||||
return D3DBLENDOP_ADD;
|
||||
}
|
||||
|
||||
void CShaderShadowDX8::BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor )
|
||||
{
|
||||
D3DBLEND d3dSrcFactor = BlendFuncValue( srcFactor );
|
||||
D3DBLEND d3dDstFactor = BlendFuncValue( dstFactor );
|
||||
m_SrcBlend = d3dSrcFactor;
|
||||
m_DestBlend = d3dDstFactor;
|
||||
}
|
||||
|
||||
// Separate alpha blending
|
||||
void CShaderShadowDX8::BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor )
|
||||
{
|
||||
D3DBLEND d3dSrcFactor = BlendFuncValue( srcFactor );
|
||||
D3DBLEND d3dDstFactor = BlendFuncValue( dstFactor );
|
||||
m_SrcBlendAlpha = d3dSrcFactor;
|
||||
m_DestBlendAlpha = d3dDstFactor;
|
||||
}
|
||||
|
||||
void CShaderShadowDX8::BlendOp( ShaderBlendOp_t blendOp )
|
||||
{
|
||||
m_BlendOp = BlendOpValue( blendOp );
|
||||
}
|
||||
|
||||
void CShaderShadowDX8::BlendOpSeparateAlpha( ShaderBlendOp_t blendOp )
|
||||
{
|
||||
m_BlendOpAlpha = BlendOpValue( blendOp );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Polygon fill mode states
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderShadowDX8::PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode )
|
||||
{
|
||||
// DX8 can't handle different modes on front and back faces
|
||||
// FIXME: Assert( face == SHADER_POLYMODEFACE_FRONT_AND_BACK );
|
||||
if (face == SHADER_POLYMODEFACE_BACK)
|
||||
return;
|
||||
|
||||
D3DFILLMODE fillMode;
|
||||
switch( polyMode )
|
||||
{
|
||||
case SHADER_POLYMODE_POINT:
|
||||
fillMode = D3DFILL_POINT;
|
||||
break;
|
||||
case SHADER_POLYMODE_LINE:
|
||||
fillMode = D3DFILL_WIREFRAME;
|
||||
break;
|
||||
case SHADER_POLYMODE_FILL:
|
||||
fillMode = D3DFILL_SOLID;
|
||||
break;
|
||||
default:
|
||||
Warning( "PolyMode: invalid poly mode\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
m_ShadowState.m_AlphaTestAndMiscState.m_FillMode = fillMode;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Backface cull states
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderShadowDX8::EnableCulling( bool bEnable )
|
||||
{
|
||||
m_ShadowState.m_AlphaTestAndMiscState.m_CullEnable = bEnable;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Alpha to coverage
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderShadowDX8::EnableAlphaToCoverage( bool bEnable )
|
||||
{
|
||||
m_ShadowState.m_AlphaTestAndMiscState.m_EnableAlphaToCoverage = bEnable;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Enables auto-conversion from linear to gamma space on write to framebuffer.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderShadowDX8::EnableSRGBWrite( bool bEnable )
|
||||
{
|
||||
if ( m_pHardwareConfig->SupportsSRGB() )
|
||||
{
|
||||
m_ShadowState.m_FogAndMiscState.m_SRGBWriteEnable = bEnable;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ShadowState.m_FogAndMiscState.m_SRGBWriteEnable = false;
|
||||
}
|
||||
}
|
||||
|
||||
void CShaderShadowDX8::EnableTexture( Sampler_t sampler, bool bEnable )
|
||||
{
|
||||
if ( sampler < m_pHardwareConfig->GetSamplerCount() )
|
||||
{
|
||||
m_SamplerState[sampler].m_TextureEnable = bEnable;
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning( "Attempting to bind a texture to an invalid sampler (%d)!\n", sampler );
|
||||
}
|
||||
}
|
||||
|
||||
void CShaderShadowDX8::EnableVertexTexture( VertexTextureSampler_t vtSampler, bool bEnable )
|
||||
{
|
||||
if ( vtSampler < m_pHardwareConfig->GetVertexSamplerCount() )
|
||||
{
|
||||
m_VertexSamplerState[vtSampler].m_TextureEnable = bEnable;
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning( "Attempting to bind a texture to an invalid vertex sampler (%d)!\n", vtSampler );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CShaderShadowDX8::EnableSRGBRead( Sampler_t sampler, bool bEnable )
|
||||
{
|
||||
}
|
||||
|
||||
#if 0
|
||||
void CShaderShadowDX8::SetShadowDepthFiltering( Sampler_t stage )
|
||||
{
|
||||
int nMask = ( 1 << stage );
|
||||
if ( stage < m_pHardwareConfig->GetSamplerCount() )
|
||||
{
|
||||
#if ( defined ( POSIX ) )
|
||||
// m_ShadowState.m_ShadowFilterEnable |= nMask;
|
||||
#else
|
||||
if ( !m_pHardwareConfig->SupportsFetch4() )
|
||||
{
|
||||
m_ShadowState.m_nFetch4Enable &= ~nMask;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ShadowState.m_nFetch4Enable |= nMask;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning( "Attempting set shadow filtering state on an invalid sampler (%d)!\n", stage );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Compute the vertex format from vertex descriptor flags
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderShadowDX8::VertexShaderVertexFormat( unsigned int nFlags,
|
||||
int nTexCoordCount, int* pTexCoordDimensions, int nUserDataSize )
|
||||
{
|
||||
// Code that creates a Mesh should specify whether it contains bone weights+indices, *not* the shader.
|
||||
Assert( ( nFlags & VERTEX_BONE_INDEX ) == 0 );
|
||||
nFlags &= ~VERTEX_BONE_INDEX;
|
||||
|
||||
// This indicates we're using a vertex shader
|
||||
m_ShadowShaderState.m_VertexUsage = MeshMgr()->ComputeVertexFormat( nFlags, nTexCoordCount,
|
||||
pTexCoordDimensions, 0, nUserDataSize );
|
||||
|
||||
// Avoid an error if vertex stream 0 is too narrow
|
||||
if ( CVertexBufferBase::VertexFormatSize( m_ShadowShaderState.m_VertexUsage ) <= 16 )
|
||||
{
|
||||
// FIXME: this is only necessary because we
|
||||
// (a) put the flex normal/position stream in ALL vertex decls
|
||||
// (b) bind stream 0's VB to stream 2 if there is no actual flex data
|
||||
// ...it would be far more sensible to not add stream 2 to all vertex decls.
|
||||
static bool bComplained = false;
|
||||
if( !bComplained )
|
||||
{
|
||||
Warning( "ERROR: shader asking for a too-narrow vertex format - you will see errors if running with debug D3D DLLs!\n\tPadding the vertex format with extra texcoords\n\tWill not warn again.\n" );
|
||||
bComplained = true;
|
||||
}
|
||||
// All vertex formats should contain position...
|
||||
Assert( nFlags & VERTEX_POSITION );
|
||||
nFlags |= VERTEX_POSITION;
|
||||
// This error should occur only if we have zero texcoords, or if we have a single, 1-D texcoord
|
||||
Assert( ( nTexCoordCount == 0 ) ||
|
||||
( ( nTexCoordCount == 1 ) && pTexCoordDimensions && ( pTexCoordDimensions[0] == 1 ) ) );
|
||||
nTexCoordCount = 1;
|
||||
m_ShadowShaderState.m_VertexUsage = MeshMgr()->ComputeVertexFormat( nFlags, nTexCoordCount, NULL, 0, nUserDataSize );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Pixel and vertex shader methods
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderShadowDX8::SetVertexShader( const char* pFileName, int nStaticVshIndex )
|
||||
{
|
||||
char debugLabel[500] = "";
|
||||
#ifdef DX_TO_GL_ABSTRACTION
|
||||
Q_snprintf( debugLabel, sizeof(debugLabel), "vs-file %s vs-index %d", pFileName, nStaticVshIndex );
|
||||
#endif
|
||||
|
||||
m_ShadowShaderState.m_VertexShader = ShaderManager()->CreateVertexShader( pFileName, nStaticVshIndex, debugLabel );
|
||||
m_ShadowShaderState.m_nStaticVshIndex = nStaticVshIndex;
|
||||
}
|
||||
|
||||
void CShaderShadowDX8::SetPixelShader( const char* pFileName, int nStaticPshIndex )
|
||||
{
|
||||
char debugLabel[500] = "";
|
||||
#ifdef DX_TO_GL_ABSTRACTION
|
||||
Q_snprintf( debugLabel, sizeof(debugLabel), "ps-file %s ps-index %d", pFileName, nStaticPshIndex );
|
||||
#endif
|
||||
|
||||
m_ShadowShaderState.m_PixelShader = ShaderManager()->CreatePixelShader( pFileName, nStaticPshIndex, debugLabel );
|
||||
m_ShadowShaderState.m_nStaticPshIndex = nStaticPshIndex;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the lightmap scale factor
|
||||
//-----------------------------------------------------------------------------
|
||||
float CShaderShadowDX8::GetLightMapScaleFactor( void ) const
|
||||
{
|
||||
return g_pHardwareConfig->GetLightMapScaleFactor();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Fog
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderShadowDX8::FogMode( ShaderFogMode_t fogMode, bool bVertexFog )
|
||||
{
|
||||
Assert( fogMode >= 0 && fogMode < SHADER_FOGMODE_NUMFOGMODES );
|
||||
m_ShadowState.m_FogAndMiscState.m_FogMode = fogMode;
|
||||
m_ShadowState.m_FogAndMiscState.m_bVertexFogEnable = bVertexFog;
|
||||
}
|
||||
|
||||
void CShaderShadowDX8::DisableFogGammaCorrection( bool bDisable )
|
||||
{
|
||||
m_ShadowState.m_FogAndMiscState.m_bDisableFogGammaCorrection = bDisable;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// NOTE: See Version 5 of this file for NVidia 8-stage shader stuff
|
||||
//-----------------------------------------------------------------------------
|
||||
inline bool CShaderShadowDX8::IsUsingTextureCoordinates( Sampler_t sampler ) const
|
||||
{
|
||||
return m_SamplerState[sampler].m_TextureEnable;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Computes shadow state based on bunches of other parameters
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderShadowDX8::ComputeAggregateShadowState( )
|
||||
{
|
||||
// Initialize the texture stage usage; this may get changed later
|
||||
int nEnableMask = 0;
|
||||
for (int i = 0; i < m_pHardwareConfig->GetSamplerCount(); ++i)
|
||||
{
|
||||
if ( IsUsingTextureCoordinates( (Sampler_t)i ) )
|
||||
{
|
||||
nEnableMask |= ( 1 << i );
|
||||
}
|
||||
}
|
||||
// Always use the same alpha src + dest if it's disabled
|
||||
// NOTE: This is essential for stateblocks to work
|
||||
if ( m_ShadowState.m_AlphaBlendState.m_AlphaBlendEnable )
|
||||
{
|
||||
m_ShadowState.m_AlphaBlendState.m_SrcBlend = m_SrcBlend;
|
||||
m_ShadowState.m_AlphaBlendState.m_DestBlend = m_DestBlend;
|
||||
m_ShadowState.m_AlphaBlendState.m_BlendOp = m_BlendOp;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ShadowState.m_AlphaBlendState.m_SrcBlend = D3DBLEND_ONE;
|
||||
m_ShadowState.m_AlphaBlendState.m_DestBlend = D3DBLEND_ZERO;
|
||||
m_ShadowState.m_AlphaBlendState.m_BlendOp = D3DBLENDOP_ADD;
|
||||
}
|
||||
|
||||
// GR
|
||||
if (m_ShadowState.m_AlphaBlendState.m_SeparateAlphaBlendEnable)
|
||||
{
|
||||
m_ShadowState.m_AlphaBlendState.m_SrcBlendAlpha = m_SrcBlendAlpha;
|
||||
m_ShadowState.m_AlphaBlendState.m_DestBlendAlpha = m_DestBlendAlpha;
|
||||
m_ShadowState.m_AlphaBlendState.m_BlendOpAlpha = m_BlendOpAlpha;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ShadowState.m_AlphaBlendState.m_SrcBlendAlpha = D3DBLEND_ONE;
|
||||
m_ShadowState.m_AlphaBlendState.m_DestBlendAlpha = D3DBLEND_ZERO;
|
||||
m_ShadowState.m_AlphaBlendState.m_BlendOpAlpha = D3DBLENDOP_ADD;
|
||||
}
|
||||
|
||||
// Use the same func if it's disabled
|
||||
if (m_ShadowState.m_AlphaTestAndMiscState.m_AlphaTestEnable)
|
||||
{
|
||||
// If alpha test is enabled, just use the values set
|
||||
m_ShadowState.m_AlphaTestAndMiscState.m_AlphaFunc = m_AlphaFunc;
|
||||
m_ShadowState.m_AlphaTestAndMiscState.m_AlphaRef = m_AlphaRef;
|
||||
}
|
||||
else
|
||||
{
|
||||
// A default value
|
||||
m_ShadowState.m_AlphaTestAndMiscState.m_AlphaFunc = D3DCMP_GREATEREQUAL;
|
||||
m_ShadowState.m_AlphaTestAndMiscState.m_AlphaRef = 0;
|
||||
|
||||
// If not alpha testing and doing a standard alpha blend, force on alpha testing
|
||||
if ( m_ShadowState.m_AlphaBlendState.m_AlphaBlendEnable )
|
||||
{
|
||||
if ( ( m_ShadowState.m_AlphaBlendState.m_SrcBlend == D3DBLEND_SRCALPHA ) && ( m_ShadowState.m_AlphaBlendState.m_DestBlend == D3DBLEND_INVSRCALPHA ) )
|
||||
{
|
||||
m_ShadowState.m_AlphaTestAndMiscState.m_AlphaFunc = D3DCMP_GREATEREQUAL;
|
||||
m_ShadowState.m_AlphaTestAndMiscState.m_AlphaRef = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Alpha to coverage
|
||||
if ( m_ShadowState.m_AlphaTestAndMiscState.m_EnableAlphaToCoverage )
|
||||
{
|
||||
// Only allow this to be enabled if blending is disabled and testing is enabled
|
||||
if ( ( m_ShadowState.m_AlphaBlendState.m_AlphaBlendEnable == true ) || ( m_ShadowState.m_AlphaTestAndMiscState.m_AlphaTestEnable == false ) )
|
||||
{
|
||||
m_ShadowState.m_AlphaTestAndMiscState.m_EnableAlphaToCoverage = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
195
materialsystem/shaderapidx9/shadershadowdx8.h
Normal file
195
materialsystem/shaderapidx9/shadershadowdx8.h
Normal file
@@ -0,0 +1,195 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef SHADERSHADOWDX8_H
|
||||
#define SHADERSHADOWDX8_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
#include "locald3dtypes.h"
|
||||
#include "shaderapi/ishadershadow.h"
|
||||
|
||||
class IShaderAPIDX8;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Important enumerations
|
||||
//-----------------------------------------------------------------------------
|
||||
enum
|
||||
{
|
||||
MAX_SAMPLERS = 16,
|
||||
MAX_VERTEX_SAMPLERS = 4,
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A structure maintaining the shadowed board state
|
||||
//-----------------------------------------------------------------------------
|
||||
struct SamplerShadowState_t
|
||||
{
|
||||
bool m_TextureEnable : 1;
|
||||
bool m_SRGBReadEnable : 1;
|
||||
bool m_Fetch4Enable : 1;
|
||||
#if ( defined ( POSIX ) )
|
||||
bool m_ShadowFilterEnable : 1;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct DepthTestState_t
|
||||
{
|
||||
// assumes D3DCMPFUNC and D3DZBUFFER TYPE fit in a byte
|
||||
uint8 m_ZFunc;
|
||||
uint8 m_ZEnable;
|
||||
uint8 m_ColorWriteEnable;
|
||||
unsigned char m_ZWriteEnable:1;
|
||||
unsigned char m_ZBias:2;
|
||||
|
||||
typedef uint32 UIntAlias;
|
||||
FORCEINLINE void Check( void ) const { COMPILE_TIME_ASSERT( sizeof( *this ) == sizeof( UIntAlias ) ); }
|
||||
|
||||
};
|
||||
|
||||
struct AlphaTestAndMiscState_t
|
||||
{
|
||||
uint8 m_AlphaFunc;
|
||||
uint8 m_AlphaRef;
|
||||
// Fill mode
|
||||
uint8 m_FillMode;
|
||||
unsigned char m_AlphaTestEnable:1;
|
||||
unsigned char m_EnableAlphaToCoverage:1;
|
||||
// Cull State?
|
||||
unsigned char m_CullEnable:1;
|
||||
|
||||
typedef uint32 UIntAlias;
|
||||
FORCEINLINE void Check( void ) const { COMPILE_TIME_ASSERT( sizeof( *this ) == sizeof( UIntAlias ) ); }
|
||||
};
|
||||
|
||||
struct FogAndMiscState_t
|
||||
{
|
||||
uint8 m_FogMode;
|
||||
unsigned char m_bVertexFogEnable:1;
|
||||
unsigned char m_bDisableFogGammaCorrection:1;
|
||||
// Auto-convert from linear to gamma upon writing to the frame buffer?
|
||||
unsigned char m_SRGBWriteEnable:1;
|
||||
|
||||
typedef uint16 UIntAlias;
|
||||
|
||||
FORCEINLINE ShaderFogMode_t FogMode( void ) const { return ( ShaderFogMode_t ) m_FogMode; }
|
||||
FORCEINLINE void Check( void ) const { COMPILE_TIME_ASSERT( sizeof( *this ) == sizeof( UIntAlias ) ); }
|
||||
};
|
||||
|
||||
|
||||
struct AlphaBlendState_t
|
||||
{
|
||||
// Alpha state
|
||||
uint8 m_SrcBlend;
|
||||
uint8 m_DestBlend;
|
||||
uint8 m_BlendOp;
|
||||
|
||||
// Separate alpha blend state
|
||||
uint8 m_SrcBlendAlpha;
|
||||
uint8 m_DestBlendAlpha;
|
||||
uint8 m_BlendOpAlpha;
|
||||
|
||||
unsigned char m_AlphaBlendEnable:1;
|
||||
unsigned char m_AlphaBlendEnabledForceOpaque:1; // alpha blending enabled for this batch, but return false for IsTranslucent() so object can be rendered with opaques
|
||||
// Seperate Alpha Blend?
|
||||
unsigned char m_SeparateAlphaBlendEnable:1;
|
||||
|
||||
uint8 m_nPad00;
|
||||
|
||||
typedef uint64 UIntAlias;
|
||||
FORCEINLINE void Check( void ) const { COMPILE_TIME_ASSERT( sizeof( *this ) == sizeof( UIntAlias ) ); }
|
||||
};
|
||||
|
||||
struct ShadowState_t
|
||||
{
|
||||
// Depth buffering state
|
||||
union
|
||||
{
|
||||
DepthTestState_t m_DepthTestState;
|
||||
DepthTestState_t::UIntAlias m_nDepthTestStateAsInt;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
AlphaTestAndMiscState_t m_AlphaTestAndMiscState;
|
||||
AlphaTestAndMiscState_t::UIntAlias m_nAlphaTestAndMiscStateAsInt;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
FogAndMiscState_t m_FogAndMiscState;
|
||||
FogAndMiscState_t::UIntAlias m_nFogAndMiscStateAsInt;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
AlphaBlendState_t m_AlphaBlendState;
|
||||
AlphaBlendState_t::UIntAlias m_nAlphaBlendStateAsInt;
|
||||
};
|
||||
|
||||
|
||||
// Sampler state. encoded as ints so we can do mask operations for fast change detection
|
||||
uint32 m_nFetch4Enable;
|
||||
|
||||
#if ( defined ( PLATFORM_OPENGL ) )
|
||||
uint32 m_nShadowFilterEnable;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// These are part of the "shadow" since they describe the shading algorithm
|
||||
// but aren't actually captured in the state transition table
|
||||
// because it would produce too many transitions
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ShadowShaderState_t
|
||||
{
|
||||
// The vertex + pixel shader group to use...
|
||||
VertexShader_t m_VertexShader;
|
||||
PixelShader_t m_PixelShader;
|
||||
|
||||
// The static vertex + pixel shader indices
|
||||
int m_nStaticVshIndex;
|
||||
int m_nStaticPshIndex;
|
||||
|
||||
// Vertex data used by this snapshot
|
||||
// Note that the vertex format actually used will be the
|
||||
// aggregate of the vertex formats used by all snapshots in a material
|
||||
VertexFormat_t m_VertexUsage;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The shader setup API
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IShaderShadowDX8 : public IShaderShadow
|
||||
{
|
||||
public:
|
||||
// Initializes it
|
||||
virtual void Init() = 0;
|
||||
|
||||
// Gets at the shadow state
|
||||
virtual ShadowState_t const& GetShadowState() = 0;
|
||||
virtual ShadowShaderState_t const& GetShadowShaderState() = 0;
|
||||
|
||||
// This must be called right before taking a snapshot
|
||||
virtual void ComputeAggregateShadowState( ) = 0;
|
||||
|
||||
// Class factory methods
|
||||
static IShaderShadowDX8* Create( IShaderAPIDX8* pShaderAPIDX8 );
|
||||
static void Destroy( IShaderShadowDX8* pShaderShadow );
|
||||
};
|
||||
|
||||
extern IShaderShadowDX8 *g_pShaderShadowDx8;
|
||||
|
||||
#endif // SHADERSHADOWDX8_H
|
||||
809
materialsystem/shaderapidx9/stubd3ddevice.h
Normal file
809
materialsystem/shaderapidx9/stubd3ddevice.h
Normal file
@@ -0,0 +1,809 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef STUBD3DDEVICE_H
|
||||
#define STUBD3DDEVICE_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#ifdef STUBD3D
|
||||
|
||||
#include "locald3dtypes.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
#ifdef USE_FOPEN
|
||||
#include <stdio.h>
|
||||
#define FPRINTF fprintf
|
||||
#else
|
||||
#define FPRINTF s_pFileSystem->FPrintf
|
||||
#endif
|
||||
|
||||
#ifdef USE_FOPEN
|
||||
|
||||
static FILE *s_FileHandle;
|
||||
|
||||
#else
|
||||
|
||||
static IFileSystem *s_pFileSystem;
|
||||
static FileHandle_t s_FileHandle;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
class CStubD3DTexture : public IDirect3DTexture8
|
||||
{
|
||||
private:
|
||||
IDirect3DTexture8 *m_pTexture;
|
||||
IDirect3DDevice8 *m_pDevice;
|
||||
|
||||
public:
|
||||
CStubD3DTexture( IDirect3DTexture8 *pTexture, IDirect3DDevice8 *pDevice )
|
||||
{
|
||||
m_pTexture = pTexture;
|
||||
m_pDevice = pDevice;
|
||||
}
|
||||
|
||||
/*** IUnknown methods ***/
|
||||
HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::QueryInterface\n" );
|
||||
return m_pTexture->QueryInterface( riid, ppvObj );
|
||||
}
|
||||
|
||||
ULONG __stdcall AddRef()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::AddRef\n" );
|
||||
return m_pTexture->AddRef();
|
||||
}
|
||||
|
||||
ULONG __stdcall Release()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::Release\n" );
|
||||
return m_pTexture->Release();
|
||||
}
|
||||
|
||||
/*** IDirect3DBaseTexture8 methods ***/
|
||||
HRESULT __stdcall GetDevice( IDirect3DDevice8** ppDevice )
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetDevice\n" );
|
||||
#if 0
|
||||
*ppDevice = m_pDevice;
|
||||
return D3D_OK;
|
||||
#else
|
||||
return m_pTexture->GetDevice( ppDevice );
|
||||
#endif
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetPrivateData( REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::SetPrivateData\n" );
|
||||
return m_pTexture->SetPrivateData( refguid, pData, SizeOfData, Flags );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetPrivateData( REFGUID refguid,void* pData,DWORD* pSizeOfData )
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetPrivateData\n" );
|
||||
return m_pTexture->GetPrivateData( refguid, pData, pSizeOfData );
|
||||
}
|
||||
|
||||
HRESULT __stdcall FreePrivateData( REFGUID refguid )
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetPrivateData\n" );
|
||||
return m_pTexture->FreePrivateData( refguid );
|
||||
}
|
||||
|
||||
DWORD __stdcall SetPriority( DWORD PriorityNew )
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::SetPriority\n" );
|
||||
return m_pTexture->SetPriority( PriorityNew );
|
||||
}
|
||||
|
||||
DWORD __stdcall GetPriority()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetPriority\n" );
|
||||
return m_pTexture->GetPriority();
|
||||
}
|
||||
|
||||
void __stdcall PreLoad()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::PreLoad\n" );
|
||||
m_pTexture->PreLoad();
|
||||
}
|
||||
|
||||
D3DRESOURCETYPE __stdcall GetType()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetType\n" );
|
||||
return m_pTexture->GetType();
|
||||
}
|
||||
|
||||
DWORD __stdcall SetLOD( DWORD LODNew )
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::SetLOD\n" );
|
||||
return m_pTexture->SetLOD( LODNew );
|
||||
}
|
||||
|
||||
DWORD __stdcall GetLOD()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetLOD\n" );
|
||||
return m_pTexture->GetLOD();
|
||||
}
|
||||
|
||||
DWORD __stdcall GetLevelCount()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetLevelCount\n" );
|
||||
return m_pTexture->GetLevelCount();
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetLevelDesc(UINT Level,D3DSURFACE_DESC *pDesc)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetLevelCount\n" );
|
||||
return m_pTexture->GetLevelDesc( Level, pDesc );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetSurfaceLevel(UINT Level,IDirect3DSurface8** ppSurfaceLevel)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::GetSurfaceLevel\n" );
|
||||
return m_pTexture->GetSurfaceLevel( Level, ppSurfaceLevel );
|
||||
}
|
||||
|
||||
HRESULT __stdcall LockRect(UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::LockRect\n" );
|
||||
return m_pTexture->LockRect( Level, pLockedRect, pRect, Flags );
|
||||
}
|
||||
|
||||
HRESULT __stdcall UnlockRect(UINT Level)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::UnlockRect\n" );
|
||||
return m_pTexture->UnlockRect( Level );
|
||||
}
|
||||
|
||||
HRESULT __stdcall AddDirtyRect( CONST RECT* pDirtyRect )
|
||||
{
|
||||
FPRINTF( s_FileHandle, "IDirect3DTexture8::AddDirtyRect\n" );
|
||||
return m_pTexture->AddDirtyRect( pDirtyRect );
|
||||
}
|
||||
};
|
||||
|
||||
class CStubD3DDevice : public IDirect3DDevice8
|
||||
{
|
||||
public:
|
||||
CStubD3DDevice( IDirect3DDevice8 *pD3DDevice, IFileSystem *pFileSystem )
|
||||
{
|
||||
Assert( pD3DDevice );
|
||||
m_pD3DDevice = pD3DDevice;
|
||||
#ifdef USE_FOPEN
|
||||
s_FileHandle = fopen( "stubd3d.txt", "w" );
|
||||
#else
|
||||
Assert( pFileSystem );
|
||||
s_pFileSystem = pFileSystem;
|
||||
s_FileHandle = pFileSystem->Open( "stubd3d.txt", "w" );
|
||||
#endif
|
||||
}
|
||||
|
||||
~CStubD3DDevice()
|
||||
{
|
||||
#ifdef USE_FOPEN
|
||||
fclose( s_FileHandle );
|
||||
#else
|
||||
s_pFileSystem->Close( s_FileHandle );
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
IDirect3DDevice8 *m_pD3DDevice;
|
||||
|
||||
public:
|
||||
/*** IUnknown methods ***/
|
||||
HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "QueryInterface\n" );
|
||||
return m_pD3DDevice->QueryInterface( riid, ppvObj );
|
||||
}
|
||||
|
||||
ULONG __stdcall AddRef()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "AddRef\n" );
|
||||
return m_pD3DDevice->AddRef();
|
||||
}
|
||||
|
||||
ULONG __stdcall Release()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "Release\n" );
|
||||
return m_pD3DDevice->Release();
|
||||
delete this;
|
||||
}
|
||||
|
||||
/*** IDirect3DDevice8 methods ***/
|
||||
HRESULT __stdcall TestCooperativeLevel()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "TestCooperativeLevel\n" );
|
||||
return m_pD3DDevice->TestCooperativeLevel();
|
||||
}
|
||||
|
||||
UINT __stdcall GetAvailableTextureMem()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetAvailableTextureMem\n" );
|
||||
return m_pD3DDevice->GetAvailableTextureMem();
|
||||
}
|
||||
|
||||
HRESULT __stdcall ResourceManagerDiscardBytes(DWORD Bytes)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "ResourceManagerDiscardBytes\n" );
|
||||
return m_pD3DDevice->ResourceManagerDiscardBytes( Bytes );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetDirect3D(IDirect3D8** ppD3D8)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetDirect3D\n" );
|
||||
return m_pD3DDevice->GetDirect3D( ppD3D8 );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetDeviceCaps(D3DCAPS8* pCaps)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetDeviceCaps\n" );
|
||||
return m_pD3DDevice->GetDeviceCaps( pCaps );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetDisplayMode(D3DDISPLAYMODE* pMode)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetDisplayMode\n" );
|
||||
return m_pD3DDevice->GetDisplayMode( pMode );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS *pParameters)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetCreationParameters\n" );
|
||||
return m_pD3DDevice->GetCreationParameters( pParameters );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetCursorProperties(UINT XHotSpot,UINT YHotSpot,IDirect3DSurface8* pCursorBitmap)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetCursorProperties\n" );
|
||||
return m_pD3DDevice->SetCursorProperties( XHotSpot, YHotSpot, pCursorBitmap );
|
||||
}
|
||||
|
||||
void __stdcall SetCursorPosition(UINT XScreenSpace,UINT YScreenSpace,DWORD Flags)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetCursorPosition\n" );
|
||||
m_pD3DDevice->SetCursorPosition( XScreenSpace, YScreenSpace, Flags );
|
||||
}
|
||||
|
||||
BOOL __stdcall ShowCursor(BOOL bShow)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "ShowCursor\n" );
|
||||
return m_pD3DDevice->ShowCursor( bShow );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DSwapChain8** pSwapChain)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateAdditionalSwapChain\n" );
|
||||
return m_pD3DDevice->CreateAdditionalSwapChain( pPresentationParameters, pSwapChain );
|
||||
}
|
||||
|
||||
HRESULT __stdcall Reset(D3DPRESENT_PARAMETERS* pPresentationParameters)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "Reset\n" );
|
||||
return m_pD3DDevice->Reset( pPresentationParameters );
|
||||
}
|
||||
|
||||
HRESULT __stdcall Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "Present\n" );
|
||||
return m_pD3DDevice->Present( pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetBackBuffer(UINT BackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface8** ppBackBuffer)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetBackBuffer\n" );
|
||||
return m_pD3DDevice->GetBackBuffer( BackBuffer, Type, ppBackBuffer );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetRasterStatus(D3DRASTER_STATUS* pRasterStatus)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetRasterStatus\n" );
|
||||
return m_pD3DDevice->GetRasterStatus( pRasterStatus );
|
||||
}
|
||||
|
||||
void __stdcall SetGammaRamp(DWORD Flags,CONST D3DGAMMARAMP* pRamp)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetGammaRamp\n" );
|
||||
m_pD3DDevice->SetGammaRamp( Flags, pRamp );
|
||||
}
|
||||
|
||||
void __stdcall GetGammaRamp(D3DGAMMARAMP* pRamp)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetGammaRamp\n" );
|
||||
m_pD3DDevice->GetGammaRamp( pRamp );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateTexture(UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture8** ppTexture)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateTexture\n" );
|
||||
#if 0
|
||||
HRESULT ret = m_pD3DDevice->CreateTexture( Width, Height, Levels, Usage, Format, Pool, ppTexture );
|
||||
if( ret == D3D_OK )
|
||||
{
|
||||
*ppTexture = new CStubD3DTexture( *ppTexture, this );
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
return m_pD3DDevice->CreateTexture( Width, Height, Levels, Usage, Format, Pool, ppTexture );
|
||||
#endif
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateVolumeTexture(UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture8** ppVolumeTexture)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateVolumeTexture\n" );
|
||||
return m_pD3DDevice->CreateVolumeTexture( Width, Height, Depth, Levels, Usage, Format, Pool, ppVolumeTexture );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateCubeTexture(UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture8** ppCubeTexture)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateCubeTexture\n" );
|
||||
return m_pD3DDevice->CreateCubeTexture( EdgeLength, Levels, Usage, Format, Pool, ppCubeTexture );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateVertexBuffer(UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IDirect3DVertexBuffer8** ppVertexBuffer)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateVertexBuffer\n" );
|
||||
return m_pD3DDevice->CreateVertexBuffer( Length, Usage, FVF, Pool, ppVertexBuffer );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateIndexBuffer(UINT Length,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer8** ppIndexBuffer)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateIndexBuffer\n" );
|
||||
return m_pD3DDevice->CreateIndexBuffer( Length, Usage, Format, Pool, ppIndexBuffer );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateRenderTarget(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,BOOL Lockable,IDirect3DSurface8** ppSurface)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateRenderTarget\n" );
|
||||
return m_pD3DDevice->CreateRenderTarget( Width, Height, Format, MultiSample, Lockable, ppSurface );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateDepthStencilSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,IDirect3DSurface8** ppSurface)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateDepthStencilSurface\n" );
|
||||
return m_pD3DDevice->CreateDepthStencilSurface( Width, Height, Format, MultiSample, ppSurface );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateImageSurface(UINT Width,UINT Height,D3DFORMAT Format,IDirect3DSurface8** ppSurface)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateImageSurface\n" );
|
||||
return m_pD3DDevice->CreateImageSurface( Width, Height, Format, ppSurface );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CopyRects(IDirect3DSurface8* pSourceSurface,CONST RECT* pSourceRectsArray,UINT cRects,IDirect3DSurface8* pDestinationSurface,CONST POINT* pDestPointsArray)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CopyRects\n" );
|
||||
return m_pD3DDevice->CopyRects( pSourceSurface, pSourceRectsArray, cRects, pDestinationSurface, pDestPointsArray );
|
||||
}
|
||||
|
||||
HRESULT __stdcall UpdateTexture(IDirect3DBaseTexture8* pSourceTexture,IDirect3DBaseTexture8* pDestinationTexture)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "UpdateTexture\n" );
|
||||
return m_pD3DDevice->UpdateTexture( pSourceTexture, pDestinationTexture );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetFrontBuffer(IDirect3DSurface8* pDestSurface)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetFrontBuffer\n" );
|
||||
return m_pD3DDevice->GetFrontBuffer( pDestSurface );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetRenderTarget(IDirect3DSurface8* pRenderTarget,IDirect3DSurface8* pNewZStencil)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetRenderTarget\n" );
|
||||
return m_pD3DDevice->SetRenderTarget( pRenderTarget, pNewZStencil );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetRenderTarget(IDirect3DSurface8** ppRenderTarget)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetRenderTarget\n" );
|
||||
return m_pD3DDevice->GetRenderTarget( ppRenderTarget );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetDepthStencilSurface(IDirect3DSurface8** ppZStencilSurface)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetDepthStencilSurface\n" );
|
||||
return m_pD3DDevice->GetDepthStencilSurface( ppZStencilSurface );
|
||||
}
|
||||
|
||||
HRESULT __stdcall BeginScene( void )
|
||||
{
|
||||
FPRINTF( s_FileHandle, "BeginScene\n" );
|
||||
return m_pD3DDevice->BeginScene();
|
||||
}
|
||||
|
||||
HRESULT __stdcall EndScene()
|
||||
{
|
||||
FPRINTF( s_FileHandle, "EndScene\n" );
|
||||
return m_pD3DDevice->EndScene();
|
||||
}
|
||||
|
||||
HRESULT __stdcall Clear(DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "Clear\n" );
|
||||
return m_pD3DDevice->Clear( Count, pRects, Flags, Color, Z, Stencil );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetTransform\n" );
|
||||
return m_pD3DDevice->SetTransform( State, pMatrix );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetTransform(D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetTransform\n" );
|
||||
return m_pD3DDevice->GetTransform( State, pMatrix );
|
||||
}
|
||||
|
||||
HRESULT __stdcall MultiplyTransform(D3DTRANSFORMSTATETYPE transformState,CONST D3DMATRIX* pMatrix)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "MultiplyTransform\n" );
|
||||
return m_pD3DDevice->MultiplyTransform( transformState, pMatrix );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetViewport(CONST D3DVIEWPORT8* pViewport)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetViewport\n" );
|
||||
return m_pD3DDevice->SetViewport( pViewport );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetViewport(D3DVIEWPORT8* pViewport)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetViewport\n" );
|
||||
return m_pD3DDevice->GetViewport( pViewport );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetMaterial(CONST D3DMATERIAL8* pMaterial)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetMaterial\n" );
|
||||
return m_pD3DDevice->SetMaterial( pMaterial );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetMaterial(D3DMATERIAL8* pMaterial)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetMaterial\n" );
|
||||
return m_pD3DDevice->GetMaterial( pMaterial );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetLight(DWORD Index,CONST D3DLIGHT8* pLight)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetLight\n" );
|
||||
return m_pD3DDevice->SetLight( Index, pLight );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetLight(DWORD Index,D3DLIGHT8* pLight)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetLight\n" );
|
||||
return m_pD3DDevice->GetLight( Index, pLight );
|
||||
}
|
||||
|
||||
HRESULT __stdcall LightEnable(DWORD Index,BOOL Enable)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "LightEnable\n" );
|
||||
return m_pD3DDevice->LightEnable( Index, Enable );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetLightEnable(DWORD Index,BOOL* pEnable)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetLightEnable\n" );
|
||||
return m_pD3DDevice->GetLightEnable( Index, pEnable );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetClipPlane(DWORD Index,CONST float* pPlane)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetClipPlane\n" );
|
||||
return m_pD3DDevice->SetClipPlane( Index, pPlane );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetClipPlane(DWORD Index,float* pPlane)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetClipPlane\n" );
|
||||
return m_pD3DDevice->GetClipPlane( Index, pPlane );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetRenderState(D3DRENDERSTATETYPE State,DWORD Value)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetRenderState\n" );
|
||||
return m_pD3DDevice->SetRenderState( State, Value );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetRenderState(D3DRENDERSTATETYPE State,DWORD* pValue)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetRenderState\n" );
|
||||
return m_pD3DDevice->GetRenderState( State, pValue );
|
||||
}
|
||||
|
||||
HRESULT __stdcall BeginStateBlock(void)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "BeginStateBlock\n" );
|
||||
return m_pD3DDevice->BeginStateBlock();
|
||||
}
|
||||
|
||||
HRESULT __stdcall EndStateBlock(DWORD* pToken)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "EndStateBlock\n" );
|
||||
return m_pD3DDevice->EndStateBlock( pToken );
|
||||
}
|
||||
|
||||
HRESULT __stdcall ApplyStateBlock(DWORD Token)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "ApplyStateBlock\n" );
|
||||
return m_pD3DDevice->ApplyStateBlock( Token );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CaptureStateBlock(DWORD Token)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CaptureStateBlock\n" );
|
||||
return m_pD3DDevice->CaptureStateBlock( Token );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DeleteStateBlock(DWORD Token)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DeleteStateBlock\n" );
|
||||
return m_pD3DDevice->DeleteStateBlock( Token );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateStateBlock(D3DSTATEBLOCKTYPE Type,DWORD* pToken)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateStateBlock\n" );
|
||||
return m_pD3DDevice->CreateStateBlock( Type, pToken );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetClipStatus(CONST D3DCLIPSTATUS8* pClipStatus)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetClipStatus\n" );
|
||||
return m_pD3DDevice->SetClipStatus( pClipStatus );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetClipStatus(D3DCLIPSTATUS8* pClipStatus)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetClipStatus\n" );
|
||||
return m_pD3DDevice->GetClipStatus( pClipStatus );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetTexture(DWORD Stage,IDirect3DBaseTexture8** ppTexture)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetTexture\n" );
|
||||
return m_pD3DDevice->GetTexture( Stage, ppTexture );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetTexture(DWORD Stage,IDirect3DBaseTexture8* pTexture)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetTexture\n" );
|
||||
return m_pD3DDevice->SetTexture( Stage, pTexture );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetTextureStageState\n" );
|
||||
return m_pD3DDevice->GetTextureStageState( Stage, Type, pValue );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD Value)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetTextureStageState\n" );
|
||||
return m_pD3DDevice->SetTextureStageState( Stage, Type, Value );
|
||||
}
|
||||
|
||||
HRESULT __stdcall ValidateDevice(DWORD* pNumPasses)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "ValidateDevice\n" );
|
||||
#if 0
|
||||
return m_pD3DDevice->ValidateDevice( pNumPasses );
|
||||
#else
|
||||
return D3D_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetInfo(DWORD DevInfoID,void* pDevInfoStruct,DWORD DevInfoStructSize)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetInfo\n" );
|
||||
return m_pD3DDevice->GetInfo( DevInfoID, pDevInfoStruct, DevInfoStructSize );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetPaletteEntries(UINT PaletteNumber,CONST PALETTEENTRY* pEntries)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetPaletteEntries\n" );
|
||||
return m_pD3DDevice->SetPaletteEntries( PaletteNumber, pEntries );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetPaletteEntries(UINT PaletteNumber,PALETTEENTRY* pEntries)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetPaletteEntries\n" );
|
||||
return m_pD3DDevice->GetPaletteEntries( PaletteNumber, pEntries );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetCurrentTexturePalette(UINT PaletteNumber)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetCurrentTexturePalette\n" );
|
||||
return m_pD3DDevice->SetCurrentTexturePalette( PaletteNumber );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetCurrentTexturePalette(UINT *PaletteNumber)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetCurrentTexturePalette\n" );
|
||||
return m_pD3DDevice->GetCurrentTexturePalette( PaletteNumber );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DrawPrimitive\n" );
|
||||
return m_pD3DDevice->DrawPrimitive( PrimitiveType, StartVertex, PrimitiveCount );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DrawIndexedPrimitive(D3DPRIMITIVETYPE primitiveType,UINT minIndex,UINT NumVertices,UINT startIndex,UINT primCount)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DrawIndexedPrimitive\n" );
|
||||
return m_pD3DDevice->DrawIndexedPrimitive( primitiveType,minIndex,NumVertices,startIndex,primCount );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DrawPrimitiveUP\n" );
|
||||
return m_pD3DDevice->DrawPrimitiveUP( PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DrawIndexedPrimitiveUP\n" );
|
||||
return m_pD3DDevice->DrawIndexedPrimitiveUP( PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount, pIndexData, IndexDataFormat,pVertexStreamZeroData, VertexStreamZeroStride );
|
||||
}
|
||||
|
||||
HRESULT __stdcall ProcessVertices(UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "ProcessVertices\n" );
|
||||
return m_pD3DDevice->ProcessVertices( SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreateVertexShader(CONST DWORD* pDeclaration,CONST DWORD* pFunction,DWORD* pHandle,DWORD Usage)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreateVertexShader\n" );
|
||||
return m_pD3DDevice->CreateVertexShader( pDeclaration, pFunction, pHandle, Usage );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetVertexShader(DWORD Handle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetVertexShader\n" );
|
||||
return m_pD3DDevice->SetVertexShader( Handle );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetVertexShader(DWORD* pHandle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetVertexShader\n" );
|
||||
return m_pD3DDevice->GetVertexShader( pHandle );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DeleteVertexShader(DWORD Handle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DeleteVertexShader\n" );
|
||||
return m_pD3DDevice->DeleteVertexShader( Handle );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetVertexShaderConstant(DWORD Register,CONST void* pConstantData,DWORD ConstantCount)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetVertexShaderConstant\n" );
|
||||
return m_pD3DDevice->SetVertexShaderConstant( Register, pConstantData, ConstantCount );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetVertexShaderConstant(DWORD Register,void* pConstantData,DWORD ConstantCount)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetVertexShaderConstant\n" );
|
||||
return m_pD3DDevice->GetVertexShaderConstant( Register, pConstantData, ConstantCount );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetVertexShaderDeclaration(DWORD Handle,void* pData,DWORD* pSizeOfData)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetVertexShaderDeclaration\n" );
|
||||
return m_pD3DDevice->GetVertexShaderDeclaration( Handle, pData, pSizeOfData );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetVertexShaderFunction(DWORD Handle,void* pData,DWORD* pSizeOfData)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetVertexShaderFunction\n" );
|
||||
return m_pD3DDevice->GetVertexShaderFunction( Handle, pData, pSizeOfData );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetStreamSource\n" );
|
||||
return m_pD3DDevice->SetStreamSource( StreamNumber, pStreamData, Stride );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer8** ppStreamData,UINT* pStride)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetStreamSource\n" );
|
||||
return m_pD3DDevice->GetStreamSource( StreamNumber, ppStreamData, pStride );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetIndices(IDirect3DIndexBuffer8* pIndexData,UINT BaseVertexIndex)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetIndices\n" );
|
||||
return m_pD3DDevice->SetIndices( pIndexData, BaseVertexIndex );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetIndices(IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetIndices\n" );
|
||||
return m_pD3DDevice->GetIndices( ppIndexData, pBaseVertexIndex );
|
||||
}
|
||||
|
||||
HRESULT __stdcall CreatePixelShader(CONST DWORD* pFunction,DWORD* pHandle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "CreatePixelShader\n" );
|
||||
return m_pD3DDevice->CreatePixelShader( pFunction, pHandle );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetPixelShader(DWORD Handle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetPixelShader\n" );
|
||||
return m_pD3DDevice->SetPixelShader( Handle );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetPixelShader(DWORD* pHandle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetPixelShader\n" );
|
||||
return m_pD3DDevice->GetPixelShader( pHandle );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DeletePixelShader(DWORD Handle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DeletePixelShader\n" );
|
||||
return m_pD3DDevice->DeletePixelShader( Handle );
|
||||
}
|
||||
|
||||
HRESULT __stdcall SetPixelShaderConstant(DWORD Register,CONST void* pConstantData,DWORD ConstantCount)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "SetPixelShaderConstant\n" );
|
||||
return m_pD3DDevice->SetPixelShaderConstant( Register, pConstantData, ConstantCount );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetPixelShaderConstant(DWORD Register,void* pConstantData,DWORD ConstantCount)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetPixelShaderConstant\n" );
|
||||
return m_pD3DDevice->GetPixelShaderConstant( Register, pConstantData, ConstantCount );
|
||||
}
|
||||
|
||||
HRESULT __stdcall GetPixelShaderFunction(DWORD Handle,void* pData,DWORD* pSizeOfData)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "GetPixelShaderFunction\n" );
|
||||
return m_pD3DDevice->GetPixelShaderFunction( Handle, pData, pSizeOfData );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DrawRectPatch(UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DrawRectPatch\n" );
|
||||
return m_pD3DDevice->DrawRectPatch( Handle, pNumSegs, pRectPatchInfo );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DrawTriPatch(UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DrawTriPatch\n" );
|
||||
return m_pD3DDevice->DrawTriPatch( Handle, pNumSegs, pTriPatchInfo );
|
||||
}
|
||||
|
||||
HRESULT __stdcall DeletePatch(UINT Handle)
|
||||
{
|
||||
FPRINTF( s_FileHandle, "DeletePatch\n" );
|
||||
return m_pD3DDevice->DeletePatch( Handle );
|
||||
}
|
||||
};
|
||||
|
||||
#endif // STUBD3D
|
||||
|
||||
#endif // STUBD3DDEVICE_H
|
||||
|
||||
1217
materialsystem/shaderapidx9/texturedx8.cpp
Normal file
1217
materialsystem/shaderapidx9/texturedx8.cpp
Normal file
File diff suppressed because it is too large
Load Diff
106
materialsystem/shaderapidx9/texturedx8.h
Normal file
106
materialsystem/shaderapidx9/texturedx8.h
Normal file
@@ -0,0 +1,106 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef TEXTUREDX8_H
|
||||
#define TEXTUREDX8_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
#include "bitmap/imageformat.h"
|
||||
#include "locald3dtypes.h"
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class CPixelWriter;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns the size of texture memory
|
||||
//-----------------------------------------------------------------------------
|
||||
int ComputeTextureMemorySize( const GUID &nDeviceId, D3DDEVTYPE deviceType );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Texture creation
|
||||
//-----------------------------------------------------------------------------
|
||||
IDirect3DBaseTexture *CreateD3DTexture( int width, int height, int depth,
|
||||
ImageFormat dstFormat, int numLevels, int creationFlags, char *debugLabel=NULL ); // OK to not-supply the last param
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Texture destruction
|
||||
//-----------------------------------------------------------------------------
|
||||
void DestroyD3DTexture( IDirect3DBaseTexture *pTex );
|
||||
|
||||
int GetD3DTextureRefCount( IDirect3DBaseTexture *pTex );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Texture heap methods
|
||||
//-----------------------------------------------------------------------------
|
||||
#if defined( _X360 )
|
||||
void SetD3DTextureImmobile( IDirect3DBaseTexture *pTex, bool bImmobile );
|
||||
void CompactTextureHeap();
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Stats...
|
||||
//-----------------------------------------------------------------------------
|
||||
int TextureCount();
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Info for texture loading
|
||||
//-----------------------------------------------------------------------------
|
||||
struct TextureLoadInfo_t
|
||||
{
|
||||
ShaderAPITextureHandle_t m_TextureHandle;
|
||||
int m_nCopy;
|
||||
IDirect3DBaseTexture *m_pTexture;
|
||||
int m_nLevel;
|
||||
D3DCUBEMAP_FACES m_CubeFaceID;
|
||||
int m_nWidth;
|
||||
int m_nHeight;
|
||||
int m_nZOffset; // What z-slice of the volume texture are we loading?
|
||||
ImageFormat m_SrcFormat;
|
||||
unsigned char *m_pSrcData;
|
||||
|
||||
#if defined( _X360 )
|
||||
bool m_bSrcIsTiled; // format may not be, but data could be
|
||||
bool m_bCanConvertFormat; // allow format conversion
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Texture image upload
|
||||
//-----------------------------------------------------------------------------
|
||||
void LoadTexture( TextureLoadInfo_t &info );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Upload to a sub-piece of a texture
|
||||
//-----------------------------------------------------------------------------
|
||||
void LoadSubTexture( TextureLoadInfo_t &info, int xOffset, int yOffset, int srcStride );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Lock, unlock a texture...
|
||||
//-----------------------------------------------------------------------------
|
||||
bool LockTexture( ShaderAPITextureHandle_t textureHandle, int copy, IDirect3DBaseTexture* pTexture, int level,
|
||||
D3DCUBEMAP_FACES cubeFaceID, int xOffset, int yOffset, int width, int height, bool bDiscard,
|
||||
CPixelWriter& writer );
|
||||
|
||||
void UnlockTexture( ShaderAPITextureHandle_t textureHandle, int copy, IDirect3DBaseTexture* pTexture, int level,
|
||||
D3DCUBEMAP_FACES cubeFaceID );
|
||||
|
||||
#endif // TEXTUREDX8_H
|
||||
2222
materialsystem/shaderapidx9/textureheap.cpp
Normal file
2222
materialsystem/shaderapidx9/textureheap.cpp
Normal file
File diff suppressed because it is too large
Load Diff
201
materialsystem/shaderapidx9/textureheap.h
Normal file
201
materialsystem/shaderapidx9/textureheap.h
Normal file
@@ -0,0 +1,201 @@
|
||||
//========== Copyright <20> 2005, Valve Corporation, All rights reserved. ========
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef TEXTUREHEAP_H
|
||||
#define TEXTUREHEAP_H
|
||||
|
||||
// Portal2 Console is not using due to amount of memory free on Xbox and RSX memory on PS3.
|
||||
// The desired console pattern is to have a similar footprint, because PS3 does not have a streaming solution and it has enough texture memory
|
||||
// the texture content choices for the consoles will be made to adapt.
|
||||
|
||||
// Uncomment to allow system to operate
|
||||
//#define SUPPORTS_TEXTURE_STREAMING
|
||||
|
||||
#if defined( _X360 )
|
||||
|
||||
#include "locald3dtypes.h"
|
||||
#include "utllinkedlist.h"
|
||||
#include "filesystem.h"
|
||||
#include "materialsystem/itexture.h"
|
||||
|
||||
typedef int TextureCacheHandle_t;
|
||||
#define INVALID_TEXTURECACHE_HANDLE 0
|
||||
|
||||
class CTextureHeap
|
||||
{
|
||||
public:
|
||||
CTextureHeap();
|
||||
|
||||
IDirect3DTexture *AllocTexture( int width, int height, int levels, DWORD usage, D3DFORMAT format, bool bNoD3DMemory, bool bCacheable );
|
||||
IDirect3DCubeTexture *AllocCubeTexture( int width, int levels, DWORD usage, D3DFORMAT format, bool bNoD3DMemory );
|
||||
IDirect3DVolumeTexture *AllocVolumeTexture( int width, int height, int depth, int levels, DWORD usage, D3DFORMAT format );
|
||||
IDirect3DSurface *AllocRenderTargetSurface( int width, int height, D3DFORMAT format, RTMultiSampleCount360_t multiSampleCount = RT_MULTISAMPLE_NONE, int base = -1 );
|
||||
|
||||
// Perform the real d3d allocation, returns true if succesful, false otherwise.
|
||||
// Only valid for a texture created with no d3d bits, otherwise no-op.
|
||||
bool FixupAllocD3DMemory( IDirect3DBaseTexture *pTexture );
|
||||
|
||||
// Release header and d3d bits.
|
||||
void FreeTexture( IDirect3DBaseTexture *pTexture );
|
||||
|
||||
// Returns the total amount of memory needed or allocated for the entire texture.
|
||||
int GetSize( IDirect3DBaseTexture *pTexture );
|
||||
// Returns the amount of memory needed just for the cacheable component.
|
||||
int GetCacheableSize( IDirect3DBaseTexture *pTexture );
|
||||
|
||||
// Crunch the heap.
|
||||
void Compact();
|
||||
|
||||
// Get current backbuffer multisample type
|
||||
D3DMULTISAMPLE_TYPE GetBackBufferMultiSampleType();
|
||||
|
||||
// Query to determine if the texture is managed by cacheing.
|
||||
bool IsTextureCacheManaged( IDirect3DBaseTexture *pD3DTexture );
|
||||
bool IsBaseAllocated( IDirect3DBaseTexture *pD3DTexture );
|
||||
bool IsTextureResident( IDirect3DBaseTexture *pD3DTexture );
|
||||
|
||||
// update the lru for a texture. returns false if the high mipmpa is not valid
|
||||
bool TouchTexture( class CXboxTexture *pXboxTexture );
|
||||
void SetCacheableTextureParams( IDirect3DBaseTexture *pD3DTexture, const char *pFilename, int mipSkipCount );
|
||||
void FlushTextureCache();
|
||||
void SpewTextureCache();
|
||||
int GetCacheableHeapSize();
|
||||
|
||||
private:
|
||||
bool RestoreCacheableTexture( IDirect3DBaseTexture *pD3DTexture );
|
||||
|
||||
CUtlFixedLinkedList< IDirect3DBaseTexture* > m_TextureCache;
|
||||
};
|
||||
|
||||
#if defined( SUPPORTS_TEXTURE_STREAMING )
|
||||
#define BASEPOOL1024_SIZE ( 12*1024*1024 ) // 1024x1024 DXT5
|
||||
#define BASEPOOL512_SIZE ( 12*1024*1024 ) // 1024x1024 DXT1
|
||||
#define BASEPOOL256_SIZE ( 16*1024*1024 ) // 512x512 DXT5
|
||||
#define BASEPOOL128_SIZE ( 16*1024*1024 ) // 512x512 DXT1
|
||||
#define BASEPOOL64_SIZE ( 4*1024*1024 ) // 256x256 DXT5
|
||||
#define BASEPOOL32_SIZE ( 4*1024*1024 ) // 256x256 DXT1
|
||||
#else
|
||||
#define BASEPOOL1024_SIZE 0
|
||||
#define BASEPOOL512_SIZE 0
|
||||
#define BASEPOOL256_SIZE 0
|
||||
#define BASEPOOL128_SIZE 0
|
||||
#define BASEPOOL64_SIZE 0
|
||||
#define BASEPOOL32_SIZE 0
|
||||
#endif
|
||||
|
||||
enum TextureAllocator_t
|
||||
{
|
||||
TA_BASEPOOL_1024, // 1024K = 1024x1024 DXT5 Mip0
|
||||
TA_BASEPOOL_512, // 512K = 1024x1024 DXT1 Mip0
|
||||
TA_BASEPOOL_256, // 256K = 512x512 DXT5 Mip0
|
||||
TA_BASEPOOL_128, // 128K = 512x512 DXT1 Mip0
|
||||
TA_BASEPOOL_64, // 64K = 256x256 DXT5 Mip0
|
||||
TA_BASEPOOL_32, // 32K = 256x256 DXT1 Mip0
|
||||
TA_MIXED,
|
||||
TA_STANDARD,
|
||||
TA_MAX
|
||||
};
|
||||
|
||||
enum TextureLoadError_t
|
||||
{
|
||||
TEXLOADERROR_NONE = 0,
|
||||
TEXLOADERROR_FILEOPEN = -1,
|
||||
TEXLOADERROR_READING = -2,
|
||||
};
|
||||
|
||||
struct THBaseInfo_t
|
||||
{
|
||||
THBaseInfo_t()
|
||||
{
|
||||
m_tcHandle = INVALID_TEXTURECACHE_HANDLE;
|
||||
m_hFilename = NULL;
|
||||
m_hAsyncControl = NULL;
|
||||
m_nFrameCount = 0;
|
||||
m_nBaseSize = 0;
|
||||
m_nMipSize = 0;
|
||||
m_nMipSkipCount = 0;
|
||||
m_bBaseAllocated = false;
|
||||
m_bMipAllocated = false;
|
||||
m_BaseValid = 0;
|
||||
}
|
||||
|
||||
TextureAllocator_t m_fAllocator;
|
||||
|
||||
// for cacheable tetxures
|
||||
TextureCacheHandle_t m_tcHandle;
|
||||
FileNameHandle_t m_hFilename;
|
||||
FSAsyncControl_t m_hAsyncControl;
|
||||
|
||||
// for age, tracks which frame a texture was touched, fastest GPU non-blocking technique
|
||||
int m_nFrameCount;
|
||||
|
||||
// base and mip are both non-zero for cacheable textures, which require mips
|
||||
// a non-cacheable texture only has a non-zero base, regardless of its mips
|
||||
unsigned int m_nBaseSize;
|
||||
unsigned int m_nMipSize;
|
||||
|
||||
// used for texture restoration, the top mip
|
||||
int m_nMipSkipCount;
|
||||
|
||||
// tracks when valid for rendering, r/w across threads
|
||||
CInterlockedInt m_BaseValid;
|
||||
|
||||
// tracks when valid for i/o loading
|
||||
bool m_bBaseAllocated : 1;
|
||||
// tracks when mip is a true seperate allocation, used to resolve offset or pointer
|
||||
bool m_bMipAllocated : 1;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get Texture HW bases
|
||||
//-----------------------------------------------------------------------------
|
||||
inline void *GetD3DTextureBasePtr( IDirect3DBaseTexture* pTex )
|
||||
{
|
||||
return (void *)( (unsigned int)pTex->Format.BaseAddress << 12 );
|
||||
}
|
||||
inline void *GetD3DTextureMipPtr( IDirect3DBaseTexture* pTex )
|
||||
{
|
||||
// could be an offset or a pointer, state dependant
|
||||
return (void *)( (unsigned int)pTex->Format.MipAddress << 12 );
|
||||
}
|
||||
|
||||
extern CTextureHeap g_TextureHeap;
|
||||
|
||||
struct THInfo_t : public THBaseInfo_t
|
||||
{
|
||||
// Mixed heap info
|
||||
int nLogicalBytes;
|
||||
int nBytes;
|
||||
bool bFree:1;
|
||||
bool bNonTexture:1;
|
||||
|
||||
THInfo_t *pPrev, *pNext;
|
||||
};
|
||||
|
||||
class CXboxTexture : public IDirect3DTexture, public THInfo_t
|
||||
{
|
||||
public:
|
||||
CXboxTexture()
|
||||
: bImmobile( false )
|
||||
{
|
||||
}
|
||||
|
||||
bool CanRelocate() { return ( !bImmobile && !IsBusy() ); }
|
||||
|
||||
bool bImmobile;
|
||||
};
|
||||
|
||||
class CXboxCubeTexture : public IDirect3DCubeTexture, public THBaseInfo_t
|
||||
{
|
||||
};
|
||||
|
||||
class CXboxVolumeTexture : public IDirect3DVolumeTexture, public THBaseInfo_t
|
||||
{
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // TEXTUREHEAP_H
|
||||
859
materialsystem/shaderapidx9/vertexdecl.cpp
Normal file
859
materialsystem/shaderapidx9/vertexdecl.cpp
Normal file
@@ -0,0 +1,859 @@
|
||||
//===== Copyright <20> 1996-2008, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#undef PROTECTED_THINGS_ENABLE
|
||||
#include "vertexdecl.h" // this includes <windows.h> inside the dx headers
|
||||
#define PROTECTED_THINGS_ENABLE
|
||||
#include "materialsystem/imaterialsystemhardwareconfig.h"
|
||||
#include "shaderapidx8_global.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "utlrbtree.h"
|
||||
#include "recording.h"
|
||||
#include "tier1/strtools.h"
|
||||
#include "tier0/vprof.h"
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "shaderdevicedx8.h"
|
||||
#include "convar.h"
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Computes the DX8 vertex specification
|
||||
//-----------------------------------------------------------------------------
|
||||
static const char *DeclTypeToString( BYTE type )
|
||||
{
|
||||
switch( type )
|
||||
{
|
||||
case D3DDECLTYPE_FLOAT1:
|
||||
return "D3DDECLTYPE_FLOAT1";
|
||||
case D3DDECLTYPE_FLOAT2:
|
||||
return "D3DDECLTYPE_FLOAT2";
|
||||
case D3DDECLTYPE_FLOAT3:
|
||||
return "D3DDECLTYPE_FLOAT3";
|
||||
case D3DDECLTYPE_FLOAT4:
|
||||
return "D3DDECLTYPE_FLOAT4";
|
||||
case D3DDECLTYPE_D3DCOLOR:
|
||||
return "D3DDECLTYPE_D3DCOLOR";
|
||||
case D3DDECLTYPE_UBYTE4:
|
||||
return "D3DDECLTYPE_UBYTE4";
|
||||
case D3DDECLTYPE_SHORT2:
|
||||
return "D3DDECLTYPE_SHORT2";
|
||||
case D3DDECLTYPE_SHORT4:
|
||||
return "D3DDECLTYPE_SHORT4";
|
||||
case D3DDECLTYPE_UBYTE4N:
|
||||
return "D3DDECLTYPE_UBYTE4N";
|
||||
case D3DDECLTYPE_SHORT2N:
|
||||
return "D3DDECLTYPE_SHORT2N";
|
||||
case D3DDECLTYPE_SHORT4N:
|
||||
return "D3DDECLTYPE_SHORT4N";
|
||||
case D3DDECLTYPE_USHORT2N:
|
||||
return "D3DDECLTYPE_USHORT2N";
|
||||
case D3DDECLTYPE_USHORT4N:
|
||||
return "D3DDECLTYPE_USHORT4N";
|
||||
case D3DDECLTYPE_UDEC3:
|
||||
return "D3DDECLTYPE_UDEC3";
|
||||
case D3DDECLTYPE_DEC3N:
|
||||
return "D3DDECLTYPE_DEC3N";
|
||||
case D3DDECLTYPE_FLOAT16_2:
|
||||
return "D3DDECLTYPE_FLOAT16_2";
|
||||
case D3DDECLTYPE_FLOAT16_4:
|
||||
return "D3DDECLTYPE_FLOAT16_4";
|
||||
default:
|
||||
Assert( 0 );
|
||||
return "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
static const char *DeclMethodToString( BYTE method )
|
||||
{
|
||||
switch( method )
|
||||
{
|
||||
case D3DDECLMETHOD_DEFAULT:
|
||||
return "D3DDECLMETHOD_DEFAULT";
|
||||
case D3DDECLMETHOD_PARTIALU:
|
||||
return "D3DDECLMETHOD_PARTIALU";
|
||||
case D3DDECLMETHOD_PARTIALV:
|
||||
return "D3DDECLMETHOD_PARTIALV";
|
||||
case D3DDECLMETHOD_CROSSUV:
|
||||
return "D3DDECLMETHOD_CROSSUV";
|
||||
case D3DDECLMETHOD_UV:
|
||||
return "D3DDECLMETHOD_UV";
|
||||
case D3DDECLMETHOD_LOOKUP:
|
||||
return "D3DDECLMETHOD_LOOKUP";
|
||||
case D3DDECLMETHOD_LOOKUPPRESAMPLED:
|
||||
return "D3DDECLMETHOD_LOOKUPPRESAMPLED";
|
||||
default:
|
||||
Assert( 0 );
|
||||
return "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
static const char *DeclUsageToString( BYTE usage )
|
||||
{
|
||||
switch( usage )
|
||||
{
|
||||
case D3DDECLUSAGE_POSITION:
|
||||
return "D3DDECLUSAGE_POSITION";
|
||||
case D3DDECLUSAGE_BLENDWEIGHT:
|
||||
return "D3DDECLUSAGE_BLENDWEIGHT";
|
||||
case D3DDECLUSAGE_BLENDINDICES:
|
||||
return "D3DDECLUSAGE_BLENDINDICES";
|
||||
case D3DDECLUSAGE_NORMAL:
|
||||
return "D3DDECLUSAGE_NORMAL";
|
||||
case D3DDECLUSAGE_PSIZE:
|
||||
return "D3DDECLUSAGE_PSIZE";
|
||||
case D3DDECLUSAGE_COLOR:
|
||||
return "D3DDECLUSAGE_COLOR";
|
||||
case D3DDECLUSAGE_TEXCOORD:
|
||||
return "D3DDECLUSAGE_TEXCOORD";
|
||||
case D3DDECLUSAGE_TANGENT:
|
||||
return "D3DDECLUSAGE_TANGENT";
|
||||
case D3DDECLUSAGE_BINORMAL:
|
||||
return "D3DDECLUSAGE_BINORMAL";
|
||||
case D3DDECLUSAGE_TESSFACTOR:
|
||||
return "D3DDECLUSAGE_TESSFACTOR";
|
||||
// case D3DDECLUSAGE_POSITIONTL:
|
||||
// return "D3DDECLUSAGE_POSITIONTL";
|
||||
default:
|
||||
Assert( 0 );
|
||||
return "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
static D3DDECLTYPE VertexElementToDeclType( 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 D3DDECLTYPE_SHORT2;
|
||||
case VERTEX_ELEMENT_USERDATA4: return D3DDECLTYPE_SHORT2;
|
||||
#else //( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 )
|
||||
case VERTEX_ELEMENT_NORMAL: return D3DDECLTYPE_UBYTE4;
|
||||
case VERTEX_ELEMENT_USERDATA4: return D3DDECLTYPE_UBYTE4;
|
||||
#endif
|
||||
case VERTEX_ELEMENT_BONEWEIGHTS1: return D3DDECLTYPE_SHORT2;
|
||||
case VERTEX_ELEMENT_BONEWEIGHTS2: return D3DDECLTYPE_SHORT2;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Uncompressed-vertex element sizes
|
||||
switch ( element )
|
||||
{
|
||||
case VERTEX_ELEMENT_POSITION: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_POSITION4D: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_NORMAL: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_NORMAL4D: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_COLOR: return D3DDECLTYPE_D3DCOLOR;
|
||||
case VERTEX_ELEMENT_SPECULAR: return D3DDECLTYPE_D3DCOLOR;
|
||||
case VERTEX_ELEMENT_TANGENT_S: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TANGENT_T: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_WRINKLE:
|
||||
// Wrinkle is packed into Position.W, it is not specified as a separate vertex element
|
||||
Assert( 0 );
|
||||
return D3DDECLTYPE_UNUSED;
|
||||
#if !defined( _X360 )
|
||||
case VERTEX_ELEMENT_BONEINDEX: return D3DDECLTYPE_D3DCOLOR;
|
||||
#else
|
||||
// UBYTE4 comes in as [0,255] in the shader, which is ideal for bone indices
|
||||
// (unfortunately, UBYTE4 is not universally supported on PC DX8 GPUs)
|
||||
case VERTEX_ELEMENT_BONEINDEX: return D3DDECLTYPE_UBYTE4;
|
||||
#endif
|
||||
case VERTEX_ELEMENT_BONEWEIGHTS1: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_BONEWEIGHTS2: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_BONEWEIGHTS3: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_BONEWEIGHTS4: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_USERDATA1: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_USERDATA2: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_USERDATA3: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_USERDATA4: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_0: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_1: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_2: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_3: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_4: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_5: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_6: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD1D_7: return D3DDECLTYPE_FLOAT1;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_0: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_1: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_2: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_3: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_4: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_5: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_6: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD2D_7: return D3DDECLTYPE_FLOAT2;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_0: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_1: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_2: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_3: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_4: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_5: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_6: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD3D_7: return D3DDECLTYPE_FLOAT3;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_0: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_1: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_2: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_3: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_4: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_5: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_6: return D3DDECLTYPE_FLOAT4;
|
||||
case VERTEX_ELEMENT_TEXCOORD4D_7: return D3DDECLTYPE_FLOAT4;
|
||||
default:
|
||||
Assert(0);
|
||||
return D3DDECLTYPE_UNUSED;
|
||||
};
|
||||
}
|
||||
|
||||
void PrintVertexDeclaration( const D3DVERTEXELEMENT9 *pDecl )
|
||||
{
|
||||
int i;
|
||||
static D3DVERTEXELEMENT9 declEnd = D3DDECL_END();
|
||||
for ( i = 0; ; i++ )
|
||||
{
|
||||
if ( memcmp( &pDecl[i], &declEnd, sizeof( declEnd ) ) == 0 )
|
||||
{
|
||||
Warning( "D3DDECL_END\n" );
|
||||
break;
|
||||
}
|
||||
Msg( "%d: Stream: %d, Offset: %d, Type: %s, Method: %s, Usage: %s, UsageIndex: %d\n",
|
||||
i, ( int )pDecl[i].Stream, ( int )pDecl[i].Offset,
|
||||
DeclTypeToString( pDecl[i].Type ),
|
||||
DeclMethodToString( pDecl[i].Method ),
|
||||
DeclUsageToString( pDecl[i].Usage ),
|
||||
( int )pDecl[i].UsageIndex );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Converts format to a vertex decl
|
||||
//-----------------------------------------------------------------------------
|
||||
void ComputeVertexSpec( VertexFormat_t fmt, D3DVERTEXELEMENT9 *pDecl,
|
||||
bool bStaticLit, bool bUsingFlex, bool bUsingMorph, bool bUsingPreTessPatch,
|
||||
VertexStreamSpec_t *pStreamSpec )
|
||||
{
|
||||
int i = 0;
|
||||
int iStream;
|
||||
int offset;
|
||||
|
||||
VertexCompressionType_t compressionType = CompressionType( fmt );
|
||||
|
||||
if ( IsX360() )
|
||||
{
|
||||
// On 360, there's a performance penalty for reading more than 2 streams in the vertex shader
|
||||
// (we don't do this yet, but we should be aware if we start doing it)
|
||||
|
||||
// As an extra clarification - perf difference is only observed in bandwidth-bound cases,
|
||||
// so it is safe to use extra streams as long as we aren't bandwidth-bound,
|
||||
// the assertion is safe to be removed.
|
||||
|
||||
#ifdef _DEBUG
|
||||
int numStreams = 1 + ( bStaticLit ? 1 : 0 ) + ( bUsingFlex ? 1 : 0 ) + ( bUsingMorph ? 1 : 0 );
|
||||
numStreams;
|
||||
// Assert( numStreams <= 2 );
|
||||
#endif
|
||||
}
|
||||
|
||||
if( bUsingPreTessPatch )
|
||||
{
|
||||
// Special case for Pre-Tessellated Patches
|
||||
// Ignore all of the inputs and create a very custom vertex declaration
|
||||
|
||||
// patch stream
|
||||
pDecl[i].Stream = 0;
|
||||
pDecl[i].Offset = 0;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_POSITION;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT2;
|
||||
i ++;
|
||||
pDecl[i].Stream = 0;
|
||||
pDecl[i].Offset = 8;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT4;
|
||||
i ++;
|
||||
pDecl[i].Stream = 0;
|
||||
pDecl[i].Offset = 24;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = 1;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT4;
|
||||
i ++;
|
||||
// Quad stream
|
||||
//0
|
||||
pDecl[i].Stream = VertexStreamSpec_t::STREAM_SUBDQUADS;
|
||||
pDecl[i].Offset = 0;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_POSITION;
|
||||
pDecl[i].UsageIndex = 1;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT4;
|
||||
i ++;
|
||||
pDecl[i].Stream = VertexStreamSpec_t::STREAM_SUBDQUADS;
|
||||
pDecl[i].Offset = 16;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = 2;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT4;
|
||||
i ++;
|
||||
pDecl[i].Stream = VertexStreamSpec_t::STREAM_SUBDQUADS;
|
||||
pDecl[i].Offset = 32;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = 3;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT4;
|
||||
i ++;
|
||||
//1
|
||||
pDecl[i].Stream = VertexStreamSpec_t::STREAM_SUBDQUADS;
|
||||
pDecl[i].Offset = 48;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_POSITION;
|
||||
pDecl[i].UsageIndex = 2;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT4;
|
||||
i ++;
|
||||
pDecl[i].Stream = VertexStreamSpec_t::STREAM_SUBDQUADS;
|
||||
pDecl[i].Offset = 64;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = 4;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT4;
|
||||
i ++;
|
||||
pDecl[i].Stream = VertexStreamSpec_t::STREAM_SUBDQUADS;
|
||||
pDecl[i].Offset = 80;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = 5;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT4;
|
||||
i ++;
|
||||
//2
|
||||
pDecl[i].Stream = VertexStreamSpec_t::STREAM_SUBDQUADS;
|
||||
pDecl[i].Offset = 96;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_POSITION;
|
||||
pDecl[i].UsageIndex = 3;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT4;
|
||||
i ++;
|
||||
pDecl[i].Stream = VertexStreamSpec_t::STREAM_SUBDQUADS;
|
||||
pDecl[i].Offset = 112;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = 6;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT4;
|
||||
i ++;
|
||||
pDecl[i].Stream = VertexStreamSpec_t::STREAM_SUBDQUADS;
|
||||
pDecl[i].Offset = 128;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = 7;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT4;
|
||||
i ++;
|
||||
//3
|
||||
pDecl[i].Stream = VertexStreamSpec_t::STREAM_SUBDQUADS;
|
||||
pDecl[i].Offset = 144;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_POSITION;
|
||||
pDecl[i].UsageIndex = 4;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT4;
|
||||
i ++;
|
||||
pDecl[i].Stream = VertexStreamSpec_t::STREAM_SUBDQUADS;
|
||||
pDecl[i].Offset =160;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = 8;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT4;
|
||||
i ++;
|
||||
pDecl[i].Stream = VertexStreamSpec_t::STREAM_SUBDQUADS;
|
||||
pDecl[i].Offset = 176;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = 9;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT4;
|
||||
i ++;
|
||||
// patch ID
|
||||
pDecl[i].Stream = VertexStreamSpec_t::STREAM_MORPH;
|
||||
pDecl[i].Offset = 0;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = 10;
|
||||
pDecl[i].Type = D3DDECLTYPE_FLOAT1;
|
||||
i ++;
|
||||
|
||||
static D3DVERTEXELEMENT9 declEnd = D3DDECL_END();
|
||||
pDecl[i] = declEnd;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Stream 0
|
||||
//
|
||||
iStream = 0;
|
||||
offset = 0;
|
||||
|
||||
if ( fmt & VERTEX_POSITION )
|
||||
{
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_POSITION;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
|
||||
// Handle 4D positions
|
||||
VertexElement_t posElement = fmt & VERTEX_FORMAT_PAD_POS_NORM ? VERTEX_ELEMENT_POSITION4D : VERTEX_ELEMENT_POSITION;
|
||||
|
||||
pDecl[i].Type = VertexElementToDeclType( posElement, compressionType );
|
||||
offset += GetVertexElementSize( posElement, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
int numBones = NumBoneWeights(fmt);
|
||||
if ( numBones > 0 )
|
||||
{
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_BLENDWEIGHT;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
|
||||
// Always exactly two weights
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_BONEWEIGHTS2, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_BONEWEIGHTS2, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
if ( fmt & VERTEX_BONE_INDEX )
|
||||
{
|
||||
// this isn't FVF!!!!!
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_BLENDINDICES;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_BONEINDEX, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_BONEINDEX, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
int normalOffset = -1;
|
||||
if ( fmt & VERTEX_NORMAL )
|
||||
{
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = offset;
|
||||
normalOffset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_NORMAL;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
|
||||
// Handle 4D positions
|
||||
VertexElement_t normalElement = fmt & VERTEX_FORMAT_PAD_POS_NORM ? VERTEX_ELEMENT_NORMAL4D : VERTEX_ELEMENT_NORMAL;
|
||||
|
||||
pDecl[i].Type = VertexElementToDeclType( normalElement, compressionType );
|
||||
offset += GetVertexElementSize( normalElement, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
if ( fmt & VERTEX_COLOR )
|
||||
{
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_COLOR;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_COLOR, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_COLOR, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
if ( fmt & VERTEX_SPECULAR )
|
||||
{
|
||||
Assert( !bStaticLit );
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_COLOR;
|
||||
pDecl[i].UsageIndex = 1; // SPECULAR goes in the second COLOR slot
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_SPECULAR, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_SPECULAR, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
VertexElement_t texCoordDimensions[4] = { VERTEX_ELEMENT_TEXCOORD1D_0,
|
||||
VERTEX_ELEMENT_TEXCOORD2D_0,
|
||||
VERTEX_ELEMENT_TEXCOORD3D_0,
|
||||
VERTEX_ELEMENT_TEXCOORD4D_0 };
|
||||
for ( int j = 0; j < VERTEX_MAX_TEXTURE_COORDINATES; ++j )
|
||||
{
|
||||
int nCoordSize = TexCoordSize( j, fmt );
|
||||
if ( nCoordSize <= 0 )
|
||||
continue;
|
||||
Assert( nCoordSize <= 4 );
|
||||
|
||||
// Check if the texcoord goes as a separate stream spec
|
||||
if ( VertexStreamSpec_t *pSpecEntry = FindVertexStreamSpec( VERTEX_TEXCOORD_SIZE( j, nCoordSize ), pStreamSpec ) )
|
||||
{
|
||||
if ( pSpecEntry->iStreamSpec != VertexStreamSpec_t::STREAM_DEFAULT )
|
||||
// Special streams for TexCoordN are handled later
|
||||
continue;
|
||||
}
|
||||
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = j;
|
||||
VertexElement_t texCoordElement = (VertexElement_t)( texCoordDimensions[ nCoordSize - 1 ] + j );
|
||||
pDecl[i].Type = VertexElementToDeclType( texCoordElement, compressionType );
|
||||
offset += GetVertexElementSize( texCoordElement, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
if ( fmt & VERTEX_TANGENT_S )
|
||||
{
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TANGENT;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
// NOTE: this is currently *not* compressed
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_TANGENT_S, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_TANGENT_S, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
if ( fmt & VERTEX_TANGENT_T )
|
||||
{
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_BINORMAL;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
// NOTE: this is currently *not* compressed
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_TANGENT_T, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_TANGENT_T, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
int userDataSize = UserDataSize(fmt);
|
||||
if ( userDataSize > 0 )
|
||||
{
|
||||
Assert( userDataSize == 4 ); // This is actually only ever used for tangents
|
||||
pDecl[i].Stream = iStream;
|
||||
if ( ( compressionType == VERTEX_COMPRESSION_ON ) &&
|
||||
( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) )
|
||||
{
|
||||
// FIXME: Normals and tangents are packed together into a single UBYTE4 element,
|
||||
// so just point this back at the same data while we're testing UBYTE4 out.
|
||||
pDecl[i].Offset = normalOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
pDecl[i].Offset = offset;
|
||||
}
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TANGENT;
|
||||
pDecl[i].UsageIndex = 0;
|
||||
VertexElement_t userDataElement = (VertexElement_t)( VERTEX_ELEMENT_USERDATA1 + ( userDataSize - 1 ) );
|
||||
pDecl[i].Type = VertexElementToDeclType( userDataElement, compressionType );
|
||||
offset += GetVertexElementSize( userDataElement, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
//
|
||||
// Stream 1
|
||||
//
|
||||
++ iStream;
|
||||
offset = 0;
|
||||
|
||||
if ( bStaticLit )
|
||||
{
|
||||
// r_staticlight_streams (from engine.dll)
|
||||
static ConVarRef r_staticlight_streams( "r_staticlight_streams", true );
|
||||
int iColorSemanticSlot = 1; // Static lighting goes into COLOR1 semantic (and COLOR2, COLOR3, ...)
|
||||
int numStaticColorSamples = r_staticlight_streams.GetInt(); // NUM_BUMP_VECTS;
|
||||
|
||||
for ( int iColorSample = 0; iColorSample < numStaticColorSamples; ++ iColorSample )
|
||||
{
|
||||
// force stream to have specular color in it, which is used for baked static lighting
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_COLOR;
|
||||
pDecl[i].UsageIndex = iColorSemanticSlot ++;
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_SPECULAR, compressionType );
|
||||
offset += GetVertexElementSize( VERTEX_ELEMENT_SPECULAR, compressionType );
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
for ( VertexStreamSpec_t *pSpecEntry = pStreamSpec;
|
||||
pSpecEntry && pSpecEntry->iVertexDataElement != VERTEX_FORMAT_UNKNOWN;
|
||||
++ pSpecEntry )
|
||||
{
|
||||
if ( pSpecEntry->iStreamSpec != VertexStreamSpec_t::STREAM_SPECULAR1 )
|
||||
continue;
|
||||
|
||||
// Supporting only 2D texcoords to be passed with VHV
|
||||
int idxTexCoord = 0;
|
||||
int nCoordSize = 2;
|
||||
for ( ; idxTexCoord < VERTEX_MAX_TEXTURE_COORDINATES; ++ idxTexCoord )
|
||||
{
|
||||
if ( pSpecEntry->iVertexDataElement == VERTEX_TEXCOORD_SIZE( idxTexCoord, nCoordSize ) )
|
||||
break;
|
||||
}
|
||||
Assert( pSpecEntry->iVertexDataElement == VERTEX_TEXCOORD_SIZE( idxTexCoord, nCoordSize ) );
|
||||
if ( pSpecEntry->iVertexDataElement != VERTEX_TEXCOORD_SIZE( idxTexCoord, nCoordSize ) )
|
||||
{
|
||||
Warning( " ERROR: Cannot compute vertex spec for fmt 0x%08llX requesting 0x%08llX to be passed on STREAM_SPECULAR1!\n",
|
||||
fmt, pSpecEntry->iVertexDataElement);
|
||||
}
|
||||
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = idxTexCoord;
|
||||
VertexElement_t texCoordElement = (VertexElement_t)( texCoordDimensions[ nCoordSize - 1 ] + idxTexCoord );
|
||||
pDecl[i].Type = VertexElementToDeclType( texCoordElement, compressionType );
|
||||
offset += GetVertexElementSize( texCoordElement, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
//
|
||||
// Stream 2
|
||||
//
|
||||
++ iStream;
|
||||
offset = 0;
|
||||
|
||||
{
|
||||
// FIXME: There needs to be a better way of doing this
|
||||
// In 2.0b, assume position is 4d, storing wrinkle in pos.w.
|
||||
bool bUseWrinkle = bUsingFlex && ( HardwareConfig()->GetDXSupportLevel() >= 92 );
|
||||
|
||||
// Force stream 2 to have flex deltas in it
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_POSITION;
|
||||
pDecl[i].UsageIndex = 1;
|
||||
// FIXME: unify this with VertexElementToDeclType():
|
||||
pDecl[i].Type = bUseWrinkle ? D3DDECLTYPE_FLOAT4 : D3DDECLTYPE_FLOAT3;
|
||||
++i;
|
||||
|
||||
int normalOffset = GetVertexElementSize( VERTEX_ELEMENT_POSITION, compressionType );
|
||||
if ( bUseWrinkle )
|
||||
{
|
||||
normalOffset += GetVertexElementSize( VERTEX_ELEMENT_WRINKLE, compressionType );
|
||||
}
|
||||
|
||||
// Normal deltas
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = normalOffset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_NORMAL;
|
||||
pDecl[i].UsageIndex = 1;
|
||||
// NOTE: this is currently *not* compressed
|
||||
// If we are using vertex compression and not actually morphing (ie. binding the primary stream again for the morph channel), then make sure we are setting the vertexdecl up for the compression format so that we don't get 0 * NaN in the vertex shader and get badness.
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_NORMAL, bUsingFlex ? VERTEX_COMPRESSION_NONE : compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
//
|
||||
// Stream 3
|
||||
//
|
||||
++ iStream;
|
||||
offset = 0;
|
||||
|
||||
if ( bUsingMorph )
|
||||
{
|
||||
// force stream 3 to have vertex index in it, which is used for doing vertex texture reads
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_POSITION;
|
||||
pDecl[i].UsageIndex = 2;
|
||||
pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_USERDATA1, compressionType );
|
||||
++i;
|
||||
}
|
||||
|
||||
//
|
||||
// Unique Streams
|
||||
//
|
||||
for ( int iUniqueStreamSpec = VertexStreamSpec_t::STREAM_UNIQUE_A;
|
||||
iUniqueStreamSpec < VertexStreamSpec_t::STREAM_UNIQUE_A + VertexStreamSpec_t::MAX_UNIQUE_STREAMS;
|
||||
++ iUniqueStreamSpec )
|
||||
{
|
||||
++ iStream;
|
||||
offset = 0;
|
||||
|
||||
for ( VertexStreamSpec_t *pSpecEntry = pStreamSpec;
|
||||
pSpecEntry && pSpecEntry->iVertexDataElement != VERTEX_FORMAT_UNKNOWN;
|
||||
++ pSpecEntry )
|
||||
{
|
||||
if ( pSpecEntry->iStreamSpec != iUniqueStreamSpec )
|
||||
continue;
|
||||
|
||||
// Supporting only 2D texcoords to be passed as unique streams
|
||||
int idxTexCoord = 0;
|
||||
int nCoordSize = 2;
|
||||
for ( ; idxTexCoord < VERTEX_MAX_TEXTURE_COORDINATES; ++ idxTexCoord )
|
||||
{
|
||||
if ( pSpecEntry->iVertexDataElement == VERTEX_TEXCOORD_SIZE( idxTexCoord, nCoordSize ) )
|
||||
break;
|
||||
}
|
||||
Assert( pSpecEntry->iVertexDataElement == VERTEX_TEXCOORD_SIZE( idxTexCoord, nCoordSize ) );
|
||||
if ( pSpecEntry->iVertexDataElement != VERTEX_TEXCOORD_SIZE( idxTexCoord, nCoordSize ) )
|
||||
{
|
||||
Warning( " ERROR: Cannot compute vertex spec for fmt 0x%08llX requesting 0x%08llX to be passed on STREAM%d!\n",
|
||||
fmt, pSpecEntry->iVertexDataElement, iUniqueStreamSpec );
|
||||
}
|
||||
|
||||
pDecl[i].Stream = iStream;
|
||||
pDecl[i].Offset = offset;
|
||||
pDecl[i].Method = D3DDECLMETHOD_DEFAULT;
|
||||
pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD;
|
||||
pDecl[i].UsageIndex = idxTexCoord;
|
||||
VertexElement_t texCoordElement = (VertexElement_t)( texCoordDimensions[ nCoordSize - 1 ] + idxTexCoord );
|
||||
pDecl[i].Type = VertexElementToDeclType( texCoordElement, compressionType );
|
||||
offset += GetVertexElementSize( texCoordElement, compressionType );
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
static D3DVERTEXELEMENT9 declEnd = D3DDECL_END();
|
||||
pDecl[i] = declEnd;
|
||||
|
||||
//PrintVertexDeclaration( pDecl );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the declspec associated with a vertex format
|
||||
//-----------------------------------------------------------------------------
|
||||
struct VertexDeclLookup_t
|
||||
{
|
||||
enum LookupFlags_t
|
||||
{
|
||||
STATIC_LIT = 0x1,
|
||||
USING_MORPH = 0x2,
|
||||
USING_FLEX = 0x4,
|
||||
USING_PRE_TESS_PATCHES = 0x8,
|
||||
STATIC_LIT3 = 0x10,
|
||||
};
|
||||
|
||||
VertexFormat_t m_VertexFormat;
|
||||
int m_nFlags;
|
||||
IDirect3DVertexDeclaration9 *m_pDecl;
|
||||
|
||||
bool operator==( const VertexDeclLookup_t &src ) const
|
||||
{
|
||||
return ( m_VertexFormat == src.m_VertexFormat ) && ( m_nFlags == src.m_nFlags );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dictionary of vertex decls
|
||||
// FIXME: stick this in the class?
|
||||
// FIXME: Does anything cause this to get flushed?
|
||||
//-----------------------------------------------------------------------------
|
||||
static bool VertexDeclLessFunc( const VertexDeclLookup_t &src1, const VertexDeclLookup_t &src2 )
|
||||
{
|
||||
if ( src1.m_nFlags == src2.m_nFlags )
|
||||
return src1.m_VertexFormat < src2.m_VertexFormat;
|
||||
|
||||
return ( src1.m_nFlags < src2.m_nFlags );
|
||||
}
|
||||
|
||||
static CUtlRBTree<VertexDeclLookup_t, int> s_VertexDeclDict( 0, 256, VertexDeclLessFunc );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the declspec associated with a vertex format
|
||||
//-----------------------------------------------------------------------------
|
||||
IDirect3DVertexDeclaration9 *FindOrCreateVertexDecl( VertexFormat_t fmt, bool bStaticLit, bool bUsingFlex, bool bUsingMorph, bool bUsingPreTessPatch, VertexStreamSpec_t *pStreamSpec )
|
||||
{
|
||||
MEM_ALLOC_D3D_CREDIT();
|
||||
|
||||
VertexDeclLookup_t lookup;
|
||||
lookup.m_VertexFormat = fmt;
|
||||
lookup.m_nFlags = 0;
|
||||
if ( bStaticLit )
|
||||
{
|
||||
// r_staticlight_streams (from engine.dll)
|
||||
static ConVarRef r_staticlight_streams( "r_staticlight_streams", true );
|
||||
|
||||
if ( r_staticlight_streams.GetInt() == 3 )
|
||||
{
|
||||
lookup.m_nFlags |= VertexDeclLookup_t::STATIC_LIT3;
|
||||
}
|
||||
else
|
||||
{
|
||||
lookup.m_nFlags |= VertexDeclLookup_t::STATIC_LIT;
|
||||
}
|
||||
}
|
||||
if ( bUsingMorph )
|
||||
{
|
||||
lookup.m_nFlags |= VertexDeclLookup_t::USING_MORPH;
|
||||
}
|
||||
if ( bUsingFlex )
|
||||
{
|
||||
lookup.m_nFlags |= VertexDeclLookup_t::USING_FLEX;
|
||||
}
|
||||
if( bUsingPreTessPatch )
|
||||
{
|
||||
lookup.m_nFlags |= VertexDeclLookup_t::USING_PRE_TESS_PATCHES;
|
||||
}
|
||||
|
||||
int i = s_VertexDeclDict.Find( lookup );
|
||||
if ( i != s_VertexDeclDict.InvalidIndex() )
|
||||
{
|
||||
// found
|
||||
return s_VertexDeclDict[i].m_pDecl;
|
||||
}
|
||||
|
||||
D3DVERTEXELEMENT9 decl[32];
|
||||
ComputeVertexSpec( fmt, decl, bStaticLit, bUsingFlex, bUsingMorph, bUsingPreTessPatch, pStreamSpec );
|
||||
|
||||
HRESULT hr =
|
||||
Dx9Device()->CreateVertexDeclaration( decl, &lookup.m_pDecl );
|
||||
|
||||
// NOTE: can't record until we have m_pDecl!
|
||||
RECORD_COMMAND( DX8_CREATE_VERTEX_DECLARATION, 2 );
|
||||
RECORD_INT( ( int )lookup.m_pDecl );
|
||||
RECORD_STRUCT( decl, sizeof( decl ) );
|
||||
COMPILE_TIME_ASSERT( sizeof( decl ) == sizeof( D3DVERTEXELEMENT9 ) * 32 );
|
||||
|
||||
Assert( hr == D3D_OK );
|
||||
if ( hr != D3D_OK )
|
||||
{
|
||||
Warning( " ERROR: failed to create vertex decl for vertex format %x! You'll probably see messed-up mesh rendering - to diagnose, build shaderapidx9.dll in debug.\n", (int)fmt );
|
||||
}
|
||||
|
||||
s_VertexDeclDict.Insert( lookup );
|
||||
return lookup.m_pDecl;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Clears out all declspecs
|
||||
//-----------------------------------------------------------------------------
|
||||
void ReleaseAllVertexDecl()
|
||||
{
|
||||
int i = s_VertexDeclDict.FirstInorder();
|
||||
while ( i != s_VertexDeclDict.InvalidIndex() )
|
||||
{
|
||||
s_VertexDeclDict[i].m_pDecl->Release();
|
||||
i = s_VertexDeclDict.NextInorder( i );
|
||||
}
|
||||
}
|
||||
38
materialsystem/shaderapidx9/vertexdecl.h
Normal file
38
materialsystem/shaderapidx9/vertexdecl.h
Normal file
@@ -0,0 +1,38 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef VERTEXDECL_H
|
||||
#define VERTEXDECL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "locald3dtypes.h"
|
||||
#include "materialsystem/imaterial.h"
|
||||
|
||||
//
|
||||
// VertexStreamSpec_t *pStreamSpec
|
||||
// is an array of stream specifications terminated with an entry {VERTEX_FORMAT_UNKNOWN, STREAM_DEFAULT}
|
||||
// or NULL if all the streams should be mapped in a default manner
|
||||
//
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets the declspec associated with a vertex format
|
||||
//-----------------------------------------------------------------------------
|
||||
IDirect3DVertexDeclaration9 *FindOrCreateVertexDecl( VertexFormat_t fmt, bool bStaticLit, bool bUsingFlex, bool bUsingMorph, bool bUsingPreTessPatch, VertexStreamSpec_t *pStreamSpec );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Clears out all declspecs
|
||||
//-----------------------------------------------------------------------------
|
||||
void ReleaseAllVertexDecl( );
|
||||
|
||||
|
||||
#endif // VERTEXDECL_H
|
||||
|
||||
4708
materialsystem/shaderapidx9/vertexshaderdx8.cpp
Normal file
4708
materialsystem/shaderapidx9/vertexshaderdx8.cpp
Normal file
File diff suppressed because it is too large
Load Diff
147
materialsystem/shaderapidx9/vertexshaderdx8.h
Normal file
147
materialsystem/shaderapidx9/vertexshaderdx8.h
Normal file
@@ -0,0 +1,147 @@
|
||||
//===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
|
||||
|
||||
#ifndef VERTEXSHADERDX8_H
|
||||
#define VERTEXSHADERDX8_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "shaderapi/ishaderapi.h"
|
||||
#include "datacache/idatacache.h"
|
||||
#include "locald3dtypes.h"
|
||||
|
||||
|
||||
// uncomment to get dynamic compilation for HLSL shaders
|
||||
// **IMPORTANT**: if you are trying to use DYNAMIC_SHADER_COMPILE in a RELEASE build, you *must* modify the .vpc file to re-enable the /FC compiler option, otherwise the __FILE__ macro won't work properly in
|
||||
// GetShaderSourcePath() and shader files won't be found.
|
||||
//#define DYNAMIC_SHADER_COMPILE
|
||||
|
||||
// uncomment to get spew about what combos are being compiled.
|
||||
//#define DYNAMIC_SHADER_COMPILE_VERBOSE
|
||||
|
||||
// uncomment to hide combos that are 0 (requires VERBOSE above)
|
||||
//#define DYNAMIC_SHADER_COMPILE_THIN
|
||||
|
||||
// Uncomment to use remoteshadercompiler.exe as a shader compile server
|
||||
// Must also set mat_remoteshadercompile to remote shader compile machine name
|
||||
//#define REMOTE_DYNAMIC_SHADER_COMPILE
|
||||
|
||||
// uncomment and fill in with a path to use a specific set of shader source files. Meant for network use.
|
||||
// PC path format is of style "\\\\somemachine\\sourcetreeshare\\materialsystem\\stdshaders"
|
||||
// Mac path format is of style "/Volumes/jasonm/portal2/staging/src/materialsystem/stdshaders"
|
||||
// Linux path format is of style "/home/mariod/p4/csgo/trunk/src/materialsystem/stdshaders"
|
||||
// Xbox is not supported. Xbox's ability to see PC is not supported by XDK in Vista.
|
||||
//#define DYNAMIC_SHADER_COMPILE_CUSTOM_PATH "/Volumes/Data/p4/csgo/staging/src/materialsystem/stdshaders"
|
||||
|
||||
//#define SHADER_COMBO_SPEW_VERBOSE 1
|
||||
|
||||
// uncomment to get disassembled (asm) shader code in your game dir as *.asm
|
||||
//#define DYNAMIC_SHADER_COMPILE_WRITE_ASSEMBLY
|
||||
|
||||
// uncomment to get disassembled (asm) shader code in your game dir as *.asm
|
||||
//#define WRITE_ASSEMBLY
|
||||
|
||||
#if defined( DYNAMIC_SHADER_COMPILE ) && defined( _X360 ) && !defined( X360_LINK_WITH_SHADER_COMPILE )
|
||||
// automatically turn on X360_LINK_WITH_SHADER_COMPILE with dynamic shader compile
|
||||
#define X360_LINK_WITH_SHADER_COMPILE 1
|
||||
#endif
|
||||
|
||||
#if defined( _X360 )
|
||||
// Define this to link shader compilation code from D3DX9.LIB
|
||||
//#define X360_LINK_WITH_SHADER_COMPILE 1
|
||||
#endif
|
||||
#if defined( X360_LINK_WITH_SHADER_COMPILE ) && defined( _CERT )
|
||||
#error "Don't ship with X360_LINK_WITH_SHADER_COMPILE defined!! It causes 2MB+ DLL bloat. Only define it while revving XDKs."
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Vertex + pixel shader manager
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IShaderManager
|
||||
{
|
||||
protected:
|
||||
|
||||
// The current vertex and pixel shader index
|
||||
int m_nVertexShaderIndex;
|
||||
int m_nPixelShaderIndex;
|
||||
|
||||
public:
|
||||
// Initialize, shutdown
|
||||
virtual void Init() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
// Compiles vertex shaders
|
||||
virtual IShaderBuffer *CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) = 0;
|
||||
|
||||
// New version of these methods [dx10 port]
|
||||
virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer* pShaderBuffer ) = 0;
|
||||
virtual void DestroyVertexShader( VertexShaderHandle_t hShader ) = 0;
|
||||
virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer ) = 0;
|
||||
virtual void DestroyPixelShader( PixelShaderHandle_t hShader ) = 0;
|
||||
|
||||
// Creates vertex, pixel shaders
|
||||
virtual VertexShader_t CreateVertexShader( const char *pVertexShaderFile, int nStaticVshIndex = 0, char *debugLabel = NULL ) = 0;
|
||||
virtual PixelShader_t CreatePixelShader( const char *pPixelShaderFile, int nStaticPshIndex = 0, char *debugLabel = NULL ) = 0;
|
||||
|
||||
// Sets which dynamic version of the vertex + pixel shader to use
|
||||
FORCEINLINE void SetVertexShaderIndex( int vshIndex );
|
||||
FORCEINLINE void SetPixelShaderIndex( int pshIndex );
|
||||
|
||||
// Sets the vertex + pixel shader render state
|
||||
virtual void SetVertexShader( VertexShader_t shader ) = 0;
|
||||
virtual void SetPixelShader( PixelShader_t shader ) = 0;
|
||||
|
||||
virtual void SetPixelShaderState_Internal( HardwareShader_t shader, DataCacheHandle_t hCachedShader ) = 0;
|
||||
virtual void SetVertexShaderState_Internal( HardwareShader_t shader, DataCacheHandle_t hCachedShader ) = 0;
|
||||
|
||||
// Resets the vertex + pixel shader state
|
||||
virtual void ResetShaderState() = 0;
|
||||
|
||||
// Flushes all shaders so they are reloaded+recompiled (does nothing unless dynamic shader compile is enabled)
|
||||
virtual void FlushShaders() = 0;
|
||||
|
||||
// Returns the current vertex + pixel shaders
|
||||
virtual void *GetCurrentVertexShader() = 0;
|
||||
virtual void *GetCurrentPixelShader() = 0;
|
||||
|
||||
virtual void ClearVertexAndPixelShaderRefCounts() = 0;
|
||||
virtual void PurgeUnusedVertexAndPixelShaders() = 0;
|
||||
|
||||
// The low-level dx call to set the vertex shader state
|
||||
virtual void BindVertexShader( VertexShaderHandle_t shader ) = 0;
|
||||
virtual void BindPixelShader( PixelShaderHandle_t shader ) = 0;
|
||||
|
||||
virtual void AddShaderComboInformation( const ShaderComboSemantics_t *pSemantics ) = 0;
|
||||
|
||||
#if defined( _X360 )
|
||||
virtual const char *GetActiveVertexShaderName() = 0;
|
||||
virtual const char *GetActivePixelShaderName() = 0;
|
||||
#endif
|
||||
|
||||
#if defined( DX_TO_GL_ABSTRACTION ) && !defined( _GAMECONSOLE )
|
||||
virtual void DoStartupShaderPreloading() = 0;
|
||||
#endif
|
||||
|
||||
virtual HardwareShader_t GetVertexShader( VertexShader_t vs, int dynIdx ) = 0;
|
||||
virtual HardwareShader_t GetPixelShader( PixelShader_t ps, int dynIdx ) = 0;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Methods related to setting vertex + pixel shader state
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE void IShaderManager::SetVertexShaderIndex( int vshIndex )
|
||||
{
|
||||
m_nVertexShaderIndex = vshIndex;
|
||||
}
|
||||
|
||||
FORCEINLINE void IShaderManager::SetPixelShaderIndex( int pshIndex )
|
||||
{
|
||||
m_nPixelShaderIndex = pshIndex;
|
||||
}
|
||||
|
||||
extern void DestroyAllVertexAndPixelShaders( void );
|
||||
|
||||
#endif // VERTEXSHADERDX8_H
|
||||
54
materialsystem/shaderapidx9/winutils.cpp
Normal file
54
materialsystem/shaderapidx9/winutils.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
//======Copyright 1996-2006, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// winutils.cpp
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "winutils.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "appframework/ilaunchermgr.h"
|
||||
|
||||
void GlobalMemoryStatus( MEMORYSTATUS *pOut )
|
||||
{
|
||||
//cheese: return 2GB physical
|
||||
pOut->dwTotalPhys = (1<<31);
|
||||
}
|
||||
|
||||
void Sleep( unsigned int ms )
|
||||
{
|
||||
DebuggerBreak();
|
||||
ThreadSleep( ms );
|
||||
}
|
||||
|
||||
bool IsIconic( VD3DHWND hWnd )
|
||||
{
|
||||
// FIXME for now just act non-minimized all the time
|
||||
//DebuggerBreak();
|
||||
return false;
|
||||
}
|
||||
|
||||
BOOL ClientToScreen( VD3DHWND hWnd, LPPOINT pPoint )
|
||||
{
|
||||
DebuggerBreak();
|
||||
return true;
|
||||
}
|
||||
|
||||
void* GetCurrentThread()
|
||||
{
|
||||
DebuggerBreak();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SetThreadAffinityMask( void *hThread, int nMask )
|
||||
{
|
||||
DebuggerBreak();
|
||||
}
|
||||
|
||||
bool GUID::operator==( const struct _GUID &other ) const
|
||||
{
|
||||
DebuggerBreak();
|
||||
return memcmp( this, &other, sizeof( GUID ) ) == 0;
|
||||
}
|
||||
#endif
|
||||
21
materialsystem/shaderapidx9/winutils.h
Normal file
21
materialsystem/shaderapidx9/winutils.h
Normal file
@@ -0,0 +1,21 @@
|
||||
//================ Copyright (c) 1996-2009 Valve Corporation. All Rights Reserved. =================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
#ifndef WINUTILS_H
|
||||
#define WINUTILS_H
|
||||
|
||||
#include "togl/rendermechanism.h"
|
||||
|
||||
#if !defined(_WIN32)
|
||||
|
||||
void Sleep( unsigned int ms );
|
||||
bool IsIconic( VD3DHWND hWnd );
|
||||
BOOL ClientToScreen( VD3DHWND hWnd, LPPOINT pPoint );
|
||||
void* GetCurrentThread();
|
||||
void SetThreadAffinityMask( void *hThread, int nMask );
|
||||
void GlobalMemoryStatus( MEMORYSTATUS *pOut );
|
||||
#endif
|
||||
|
||||
#endif // WINUTILS_H
|
||||
204
materialsystem/shaderapidx9/wmi.cpp
Normal file
204
materialsystem/shaderapidx9/wmi.cpp
Normal file
@@ -0,0 +1,204 @@
|
||||
//====== Copyright <20> 1996-2006, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
// Avoid conflicts with MSVC headers and memdbgon.h
|
||||
#undef PROTECTED_THINGS_ENABLE
|
||||
#include "basetypes.h"
|
||||
|
||||
#define _WIN32_DCOM
|
||||
#include <comdef.h>
|
||||
#pragma warning( disable : 4127 ) // VS 2010 warning?
|
||||
#pragma warning( disable : 4805 ) // VS 2013 warning: warning C4805: '==' : unsafe mix of type 'INT' and type 'bool' in operation
|
||||
#include <atlcomtime.h>
|
||||
#pragma warning( default : 4805 )
|
||||
#pragma warning( default : 4127 )
|
||||
#include <Wbemidl.h>
|
||||
|
||||
// NOTE: This has to be the last file included!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
# pragma comment(lib, "wbemuuid.lib")
|
||||
|
||||
int GetVidMemBytes( void )
|
||||
{
|
||||
static int bBeenHere = false;
|
||||
static int nBytes = 0;
|
||||
|
||||
if( bBeenHere )
|
||||
{
|
||||
return nBytes;
|
||||
}
|
||||
|
||||
bBeenHere = true;
|
||||
|
||||
// Initialize COM
|
||||
HRESULT hr = CoInitialize( NULL );
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
OutputDebugString ( "GetWMIDeviceStats - Unable to initialize COM library.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Set general COM security levels --------------------------
|
||||
// Note: If you are using Windows 2000, you need to specify
|
||||
// the default authentication credentials for a user by using
|
||||
// a SOLE_AUTHENTICATION_LIST structure in the pAuthList
|
||||
// parameter of CoInitializeSecurity ------------------------
|
||||
|
||||
hr = CoInitializeSecurity(
|
||||
NULL,
|
||||
-1, // COM authentication
|
||||
NULL, // Authentication services
|
||||
NULL, // Reserved
|
||||
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
|
||||
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
|
||||
NULL, // Authentication info
|
||||
EOAC_NONE, // Additional capabilities
|
||||
NULL // Reserved
|
||||
);
|
||||
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
OutputDebugString ( "GetWMIDeviceStats - Unable to initialize security.\n");
|
||||
CoUninitialize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Obtain the initial locator to WMI
|
||||
IWbemLocator *pLoc = NULL;
|
||||
|
||||
hr = CoCreateInstance(
|
||||
CLSID_WbemLocator,
|
||||
0,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
IID_IWbemLocator, (LPVOID *) &pLoc);
|
||||
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
OutputDebugString ( "GetWMIDeviceStats - Failed to create IWbemLocator object.\n");
|
||||
CoUninitialize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Connect to WMI through the IWbemLocator::ConnectServer method
|
||||
|
||||
IWbemServices *pSvc = NULL;
|
||||
|
||||
// Connect to the root\cimv2 namespace with
|
||||
// the current user and obtain pointer pSvc
|
||||
// to make IWbemServices calls.
|
||||
hr = pLoc->ConnectServer(
|
||||
_bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace
|
||||
NULL, // User name. NULL = current user
|
||||
NULL, // User password. NULL = current
|
||||
0, // Locale. NULL indicates current
|
||||
NULL, // Security flags.
|
||||
0, // Authority (e.g. Kerberos)
|
||||
0, // Context object
|
||||
&pSvc // pointer to IWbemServices proxy
|
||||
);
|
||||
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
OutputDebugString ( "GetWMIDeviceStats - Could not connect.\n");
|
||||
pLoc->Release();
|
||||
CoUninitialize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// OutputDebugString ( L"GetWMIDeviceStats - Connected to ROOT\\CIMV2 WMI namespace\n");
|
||||
|
||||
|
||||
// Set security levels on the proxy
|
||||
|
||||
hr = CoSetProxyBlanket(
|
||||
pSvc, // Indicates the proxy to set
|
||||
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
|
||||
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
|
||||
NULL, // Server principal name
|
||||
RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx
|
||||
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
|
||||
NULL, // client identity
|
||||
EOAC_NONE // proxy capabilities
|
||||
);
|
||||
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
OutputDebugString ( "GetWMIDeviceStats - Could not set proxy blanket.\n");
|
||||
pSvc->Release();
|
||||
pLoc->Release();
|
||||
CoUninitialize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Use the IWbemServices pointer to make requests of WMI
|
||||
|
||||
//
|
||||
// --- Win32_VideoController --------------------------------------------------
|
||||
//
|
||||
|
||||
IEnumWbemClassObject* pEnumerator = NULL;
|
||||
hr = pSvc->ExecQuery( bstr_t("WQL"), bstr_t("SELECT * FROM Win32_VideoController"),
|
||||
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
|
||||
|
||||
if ( FAILED( hr ) )
|
||||
{
|
||||
OutputDebugString ( "GetWMIDeviceStats - Query for Win32_VideoController failed.\n");
|
||||
|
||||
pSvc->Release();
|
||||
pLoc->Release();
|
||||
CoUninitialize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Get the data from the above query
|
||||
IWbemClassObject *pclsObj = NULL;
|
||||
ULONG uReturn = 0;
|
||||
|
||||
while ( pEnumerator )
|
||||
{
|
||||
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
|
||||
|
||||
if(0 == uReturn)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
VARIANT vtProp;
|
||||
VariantInit(&vtProp);
|
||||
|
||||
// Pluck a series of properties out of the query from Win32_VideoController
|
||||
|
||||
// hr = pclsObj->Get(L"Description", 0, &vtProp, 0, 0); // Basically the same as "VideoProcessor"
|
||||
// if ( SUCCEEDED( hr ) )
|
||||
// {
|
||||
// wsprintf( pAdapter->m_szPrimaryAdapterDescription, vtProp.bstrVal );
|
||||
// }
|
||||
|
||||
hr = pclsObj->Get(L"AdapterRAM", 0, &vtProp, 0, 0);
|
||||
if ( SUCCEEDED( hr ) )
|
||||
{
|
||||
nBytes = vtProp.intVal; // Video RAM in bytes
|
||||
}
|
||||
|
||||
VariantClear(&vtProp);
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
pSvc->Release();
|
||||
pLoc->Release();
|
||||
pEnumerator->Release();
|
||||
pclsObj->Release();
|
||||
CoUninitialize();
|
||||
|
||||
return nBytes;
|
||||
}
|
||||
17
materialsystem/shaderapidx9/wmi.h
Normal file
17
materialsystem/shaderapidx9/wmi.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//====== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef WMI_H
|
||||
#define WMI_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
int GetVidMemBytes( void );
|
||||
|
||||
|
||||
#endif // WMI_H
|
||||
3
materialsystem/shaderapidx9/xbox/xbox.def
Normal file
3
materialsystem/shaderapidx9/xbox/xbox.def
Normal file
@@ -0,0 +1,3 @@
|
||||
LIBRARY shaderapidx9_360.dll
|
||||
EXPORTS
|
||||
CreateInterface @1
|
||||
Reference in New Issue
Block a user