📄 shaderapidx8.cpp
字号:
bool m_bNeedsATICentroidHack;
};
// Mode setting utility methods
bool ValidateMode( void* hwnd, const MaterialVideoMode_t &mode, int flags ) const;
bool DoesModeRequireDeviceChange( void* hwnd, const MaterialVideoMode_t &mode, int flags ) const;
bool CanRenderWindowed( ) const;
void SetPresentParameters( MaterialVideoMode_t const& mode, int flags, int nSampleCount );
// Changes the window size
bool ResizeWindow( const MaterialVideoMode_t &mode, int flags, int nSampleCount );
// Finds a child window
int FindView( void* hwnd ) const;
// Initialize, shutdown the D3DDevice....
bool InitDevice( void* hwnd, const MaterialVideoMode_t &mode, int flags, int nSampleCount );
void ShutdownDevice( );
// Creates the D3D Device
bool CreateD3DDevice( void* hwnd, const MaterialVideoMode_t &mode, int flags, int nSampleCount );
// Alloc and free objects that are necessary for frame syncing
void AllocFrameSyncObjects( void );
void FreeFrameSyncObjects( void );
// Creates the matrix stack
void CreateMatrixStacks();
// Initializes the render state
void InitRenderState( );
// Resets all dx renderstates to dx default so that our shadows are correct.
void ResetDXRenderState( );
// Resets the render state
void ResetRenderState( );
// Initializes vertex and pixel shaders
void InitVertexAndPixelShaders( );
// Determines hardware capabilities
bool DetermineHardwareCaps( );
// Discards the vertex and index buffers
void DiscardVertexBuffers();
// Deals with lost devices
void CheckDeviceLost();
// Computes the fill rate
void ComputeFillRate();
// Takes a snapshot
virtual StateSnapshot_t TakeSnapshot( );
// Gets the matrix stack from the matrix mode
int GetMatrixStack( MaterialMatrixMode_t mode ) const;
// Flushes the matrix state, returns false if we don't need to
// do any more work
bool MatrixIsChanging( TransformType_t transform = TRANSFORM_IS_GENERAL );
// Updates the matrix transform state
void UpdateMatrixTransform( TransformType_t transform = TRANSFORM_IS_GENERAL );
// Sets the vertex shader modelView state..
const D3DXMATRIX &GetProjectionMatrix( void );
void SetVertexShaderViewProj();
void SetVertexShaderModelViewProjAndModelView();
FORCEINLINE void UpdateVertexShaderFogParams( void )
{
MEASURE_TIMED_STAT(MATERIAL_SYSTEM_STATS_FOG_MODE);
if( m_Caps.m_SupportsPixelShaders )
{
float ooFogRange = 1.0f / ( m_VertexShaderFogParams[1] - m_VertexShaderFogParams[0] );
m_VertexShaderFogParams[2] = m_DynamicState.m_FogZ;
m_VertexShaderFogParams[3] = ooFogRange;
float fogParams[4];
fogParams[0] = ooFogRange * m_VertexShaderFogParams[1];
fogParams[1] = 1.0f;
float clipDirection[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
switch( m_DynamicState.m_HeightClipMode )
{
case MATERIAL_HEIGHTCLIPMODE_DISABLE:
clipDirection[0] = 1.0f;
fogParams[2] = ( float )COORD_EXTENT;
break;
case MATERIAL_HEIGHTCLIPMODE_RENDER_ABOVE_HEIGHT:
clipDirection[0] = -1.0f;
fogParams[2] = m_DynamicState.m_HeightClipZ;
break;
case MATERIAL_HEIGHTCLIPMODE_RENDER_BELOW_HEIGHT:
clipDirection[0] = 1.0f;
fogParams[2] = m_DynamicState.m_HeightClipZ;
break;
NO_DEFAULT;
//default:
// Assert( 0 );
// break;
}
// $const = $cClipDirection * $cHeightClipZ;
clipDirection[1] = clipDirection[0] * fogParams[2];
fogParams[3] = m_VertexShaderFogParams[3];
float vertexShaderCameraPos[4];
vertexShaderCameraPos[0] = m_WorldSpaceCameraPositon[0];
vertexShaderCameraPos[1] = m_WorldSpaceCameraPositon[1];
vertexShaderCameraPos[2] = m_WorldSpaceCameraPositon[2];
vertexShaderCameraPos[3] = m_DynamicState.m_FogZ; // waterheight
// cFogEndOverFogRange, cFogOne, cHeightClipZ, cOOFogRange
SetVertexShaderConstant( VERTEX_SHADER_FOG_PARAMS, fogParams, 1 );
// cClipDirection, unused, unused, unused
SetVertexShaderConstant( VERTEX_SHADER_CLIP_DIRECTION, clipDirection, 1 );
// eyepos.x eyepos.y eyepos.z cWaterZ
SetVertexShaderConstant( VERTEX_SHADER_CAMERA_POS, vertexShaderCameraPos );
}
}
// Compute stats info for a texture
void ComputeStatsInfo( unsigned int textureIdx, bool isCubeMap );
// Gets the texture
IDirect3DBaseTexture* GetD3DTexture( int idx );
// For procedural textures
void AdvanceCurrentCopy( int textureIdx );
// Finds a texture
bool FindTexture( int id, int& idx );
// Deletes a D3D texture
void DeleteD3DTexture( int idx );
// Unbinds a texture
void UnbindTexture( int textureIdx );
// Releases all D3D textures
void ReleaseAllTextures();
// Deletes all textures
void DeleteAllTextures();
// Gets the currently modified texture index
int GetModifyTextureIndex() const;
// Gets the bind id
int GetBoundTextureBindId( int textureStage ) const;
// Sets the texture state
void SetTextureState( int stage, int textureIdx, bool force = false );
// Grab/release the render targets
void AcquireRenderTargets();
void ReleaseRenderTargets();
// Gets the texture being modified
IDirect3DBaseTexture* GetModifyTexture();
IDirect3DBaseTexture** GetModifyTextureReference();
// returns true if we're using texture coordinates at a given stage
bool IsUsingTextureCoordinates( int stage, int flags ) const;
// Returns true if the board thinks we're generating spheremap coordinates
bool IsSpheremapRenderStateActive( int stage ) const;
// Returns true if we're modulating constant color into the vertex color
bool IsModulatingVertexColor() const;
// Generates spheremap coordinates
void GenerateSpheremapCoordinates( CMeshBuilder& builder, int stage );
// Modulates the vertex color
void ModulateVertexColor( CMeshBuilder& meshBuilder );
// Recomputes ambient light cube
void RecomputeAmbientLightCube( );
// Debugging spew
void SpewBoardState();
// Compute and save the world space camera position.
void CacheWorldSpaceCameraPosition();
// Compute and save the projection atrix with polyoffset built in if we need it.
void CachePolyOffsetProjectionMatrix();
// Releases/reloads resources when other apps want some memory
void ReleaseResources();
void ReacquireResources();
// Vertex shader helper functions
int FindVertexShader( VertexFormat_t fmt, char const* pFileName ) const;
int FindPixelShader( char const* pFileName ) const;
// Returns copies of the front and back buffers
IDirect3DSurface* GetFrontBufferImage( ImageFormat& format );
IDirect3DSurface* GetBackBufferImage( ImageFormat& format );
// Flips an image vertically
void FlipVertical( int width, int height, ImageFormat format, unsigned char *pData );
// used to determine if we're deactivated
bool IsDeactivated() const { return m_OtherAppInitializing || m_DisplayLost; }
// Commits transforms and lighting
void CommitStateChanges();
// Commits transforms that have to be dealt with on a per pass basis (ie. projection matrix for polyoffset)
void CommitPerPassStateChanges( StateSnapshot_t id );
// Commits user clip planes
void CommitUserClipPlanes();
// transform commit
bool VertexShaderTransformChanged( int i );
bool FixedFunctionTransformChanged( int i );
void UpdateVertexShaderMatrix( int iMatrix );
void UpdateAllVertexShaderMatrices( void );
void SetVertexShaderStateSkinningMatrices();
void CommitVertexShaderTransforms();
void CommitPerPassVertexShaderTransforms();
void UpdateFixedFunctionMatrix( int iMatrix );
void SetFixedFunctionStateSkinningMatrices();
void CommitFixedFunctionTransforms();
void CommitPerPassFixedFunctionTransforms();
void SetSkinningMatrices();
// lighting commit
bool VertexShaderLightingChanged( int i );
bool VertexShaderLightingEnableChanged( int i );
bool FixedFunctionLightingChanged( int i );
bool FixedFunctionLightingEnableChanged( int i );
VertexShaderLightTypes_t ComputeLightType( int i ) const;
void SortLights( int* index );
void CommitVertexShaderLighting();
void CommitFixedFunctionLighting();
// Saves/restores all bind indices...
void StoreBindIndices( int* pBindId );
void RestoreBindIndices( int* pBindId );
// Compute the effective DX support level based on all the other caps
void ComputeDXSupportLevel();
// Read dx support levels
void ReadDXSupportLevels();
// Gets the hardware-specific info for the current card
const DeviceSupportLevels_t *GetCardSpecificInfo();
// Gets the surface associated with a texture (refcount of surface is increased)
IDirect3DSurface* GetTextureSurface( unsigned int tex );
IDirect3DSurface* GetDepthTextureSurface( unsigned int tex );
// Main D3D interface
IDirect3D* m_pD3D;
IDirect3DDevice* m_pD3DDevice;
// The HWND
HWND m_HWnd;
int m_nWindowWidth;
int m_nWindowHeight;
// "normal" back buffer and depth buffer. Need to keep this around so that we
// know what to set the render target to when we are done rendering to a texture.
IDirect3DSurface *m_pBackBufferSurface;
IDirect3DSurface *m_pZBufferSurface;
//
// State needed at the time of rendering (after snapshots have been applied)
//
// Interface for the D3DXMatrixStack
ID3DXMatrixStack* m_pMatrixStack[NUM_MATRIX_MODES];
// Current matrix mode
D3DTRANSFORMSTATETYPE m_MatrixMode;
int m_CurrStack;
// The current camera position in world space.
Vector4D m_WorldSpaceCameraPositon;
// The current projection matrix with polyoffset baked into it.
D3DXMATRIX m_CachedPolyOffsetProjectionMatrix;
D3DXMATRIX m_CachedPolyOffsetProjectionMatrixWithClip;
D3DXMATRIX m_CachedFastClipProjectionMatrix;
// The texture stage state that changes frequently
DynamicState_t m_DynamicState;
// Render data
IMeshDX8* m_pRenderMesh;
IMaterialInternal* m_pMaterial;
// Members related to capabilities
HardwareCaps_t m_Caps;
// Mode info
MaterialVideoMode_t m_Mode;
D3DPRESENT_PARAMETERS m_PresentParameters;
int m_DeviceSupportsCreateQuery;
int m_ModeFlags;
bool m_OtherAppInitializing;
bool m_DisplayLost;
bool m_IsResizing;
bool m_SoftwareTL;
// The current view hwnd
HWND m_ViewHWnd;
// Render-to-texture stuff...
bool m_UsingTextureRenderTarget;
int m_ViewportMaxWidth;
int m_ViewportMaxHeight;
// Which device are we using?
UINT m_DisplayAdapter;
D3DDEVTYPE m_DeviceType;
// Ambient cube map ok?
int m_CachedAmbientLightCube;
// The current frame
int m_CurrentFrame;
// The texture we're currently modifying
int m_ModifyTextureIdx;
char m_ModifyTextureLockedLevel;
unsigned char m_ModifyTextureLockedFace;
// lightmap texture id range
int m_FirstLightmapId;
int m_LastLightmapId;
inline int GetTextureCount( void )
{
return m_Textures.Count();
}
inline Texture_t& GetTexture( int index )
{
return m_Textures[ index ];
}
// Various support levels
CUtlVector< DeviceSupportLevels_t > m_DeviceSupportLevels;
// Stores all textures...
CUtlVector< Texture_t > m_Textures;
// Mesh builder used to modify vertex data
CMeshBuilder m_ModifyBuilder;
float m_VertexShaderFogParams[4];
// Shadow state transition table
CTransitionTable m_TransitionTable;
StateSnapshot_t m_nCurrentSnapshot;
// Depth test override...
bool m_bOverrideMaterialIgnoreZ;
bool m_bIgnoreZValue;
// Selection name stack
CUtlStack< int > m_SelectionNames;
bool m_InSelectionMode;
unsigned int* m_pSelectionBufferEnd;
unsigned int* m_pSelectionBuffer;
unsigned int* m_pCurrSelectionRecord;
float m_SelectionMinZ;
float m_SelectionMaxZ;
int m_NumHits;
// Vendor + device id
int m_nVendorId;
int m_nDeviceId;
GUID m_DeviceGUID;
// fog
unsigned char m_SceneFogColor[3];
MaterialFogMode_t m_SceneFogMode;
// Debug font stuff.
ID3DXFont *m_pDebugFont;
IDirect3DQuery9 *m_pFrameSyncQueryObject;
};
//-----------------------------------------------------------------------------
// Class Factory
//-----------------------------------------------------------------------------
static CShaderAPIDX8 g_ShaderAPIDX8;
IShaderAPIDX8 *g_pShaderAPIDX8 = &g_ShaderAPIDX8;
IMaterialSystemHardwareConfig *g_pHardwareConfig = &g_ShaderAPIDX8;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIDX8, IShaderAPI,
SHADERAPI_INTERFACE_VERSION, g_ShaderAPIDX8 )
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIDX8, IMaterialSystemHardwareConfig,
MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION, g_ShaderAPIDX8 )
//-----------------------------------------------------------------------------
// Stats interface
//-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -