diff options
| author | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:31:46 -0800 |
|---|---|---|
| committer | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:46:31 -0800 |
| commit | f56bb35301836e56582a575a75864392a0177875 (patch) | |
| tree | de61ddd39de3e7df52759711950b4c288592f0dc /sp/src/public/shaderapi | |
| parent | Mark some more files as text. (diff) | |
| download | source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.tar.xz source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.zip | |
Fix line endings. WHAMMY.
Diffstat (limited to 'sp/src/public/shaderapi')
| -rw-r--r-- | sp/src/public/shaderapi/IShaderDevice.h | 778 | ||||
| -rw-r--r-- | sp/src/public/shaderapi/commandbuffer.h | 216 | ||||
| -rw-r--r-- | sp/src/public/shaderapi/ishaderapi.h | 1234 | ||||
| -rw-r--r-- | sp/src/public/shaderapi/ishaderdynamic.h | 690 | ||||
| -rw-r--r-- | sp/src/public/shaderapi/ishadershadow.h | 736 | ||||
| -rw-r--r-- | sp/src/public/shaderapi/ishaderutil.h | 262 | ||||
| -rw-r--r-- | sp/src/public/shaderapi/shareddefs.h | 222 |
7 files changed, 2069 insertions, 2069 deletions
diff --git a/sp/src/public/shaderapi/IShaderDevice.h b/sp/src/public/shaderapi/IShaderDevice.h index 93c0326c..34749de0 100644 --- a/sp/src/public/shaderapi/IShaderDevice.h +++ b/sp/src/public/shaderapi/IShaderDevice.h @@ -1,389 +1,389 @@ -//========= Copyright Valve Corporation, All rights reserved. ============//
-//
-// Purpose:
-//
-// $NoKeywords: $
-//
-//===========================================================================//
-
-#ifndef ISHADERDEVICE_H
-#define ISHADERDEVICE_H
-
-#ifdef _WIN32
-#pragma once
-#endif
-
-#include "tier1/interface.h"
-#include "appframework/IAppSystem.h"
-#include "bitmap/imageformat.h"
-#include "tier1/utlbuffer.h"
-#include "materialsystem/imaterial.h"
-#include "shaderapi/ishaderdynamic.h"
-
-
-//-----------------------------------------------------------------------------
-// forward declarations
-//-----------------------------------------------------------------------------
-struct MaterialAdapterInfo_t;
-class IMesh;
-class KeyValues;
-
-
-//-----------------------------------------------------------------------------
-// Describes how to set the mode
-//-----------------------------------------------------------------------------
-#define SHADER_DISPLAY_MODE_VERSION 1
-
-struct ShaderDisplayMode_t
-{
- ShaderDisplayMode_t() { memset( this, 0, sizeof(ShaderDisplayMode_t) ); m_nVersion = SHADER_DISPLAY_MODE_VERSION; }
-
- int m_nVersion;
- int m_nWidth; // 0 when running windowed means use desktop resolution
- int m_nHeight;
- ImageFormat m_Format; // use ImageFormats (ignored for windowed mode)
- int m_nRefreshRateNumerator; // Refresh rate. Use 0 in numerator + denominator for a default setting.
- int m_nRefreshRateDenominator; // Refresh rate = numerator / denominator.
-};
-
-
-//-----------------------------------------------------------------------------
-// Describes how to set the device
-//-----------------------------------------------------------------------------
-#define SHADER_DEVICE_INFO_VERSION 1
-
-struct ShaderDeviceInfo_t
-{
- ShaderDeviceInfo_t() { memset( this, 0, sizeof(ShaderDeviceInfo_t) ); m_nVersion = SHADER_DEVICE_INFO_VERSION; m_DisplayMode.m_nVersion = SHADER_DISPLAY_MODE_VERSION; }
-
- int m_nVersion;
- ShaderDisplayMode_t m_DisplayMode;
- int m_nBackBufferCount; // valid values are 1 or 2 [2 results in triple buffering]
- int m_nAASamples; // Number of AA samples to use
- int m_nAAQuality; // AA quality level
- int m_nDXLevel; // 0 means use recommended DX level for this adapter
- int m_nWindowedSizeLimitWidth; // Used if m_bLimitWindowedSize is set, defines max bounds for the back buffer
- int m_nWindowedSizeLimitHeight;
-
- bool m_bWindowed : 1;
- bool m_bResizing : 1; // Only is meaningful when using windowed mode; means the window can be resized.
- bool m_bUseStencil : 1;
- bool m_bLimitWindowedSize : 1; // In windowed mode, should we prevent the back buffer from getting too large?
- bool m_bWaitForVSync : 1; // Would we not present until vsync?
- bool m_bScaleToOutputResolution : 1; // 360 ONLY: sets up hardware scaling
- bool m_bProgressive : 1; // 360 ONLY: interlaced or progressive
- bool m_bUsingMultipleWindows : 1; // Forces D3DPresent to use _COPY instead
-};
-
-
-//-----------------------------------------------------------------------------
-// Info for non-interactive mode
-//-----------------------------------------------------------------------------
-struct ShaderNonInteractiveInfo_t
-{
- ShaderAPITextureHandle_t m_hTempFullscreenTexture;
- int m_nPacifierCount;
- ShaderAPITextureHandle_t m_pPacifierTextures[64];
- float m_flNormalizedX;
- float m_flNormalizedY;
- float m_flNormalizedSize;
-};
-
-
-//-----------------------------------------------------------------------------
-// For vertex/index buffers. What type is it?
-// (NOTE: mirror this with a similarly named enum at the material system level for backwards compatability.)
-//-----------------------------------------------------------------------------
-enum ShaderBufferType_t
-{
- SHADER_BUFFER_TYPE_STATIC = 0,
- SHADER_BUFFER_TYPE_DYNAMIC,
- SHADER_BUFFER_TYPE_STATIC_TEMP,
- SHADER_BUFFER_TYPE_DYNAMIC_TEMP,
-
- SHADER_BUFFER_TYPE_COUNT,
-};
-
-inline bool IsDynamicBufferType( ShaderBufferType_t type )
-{
- return ( ( type == SHADER_BUFFER_TYPE_DYNAMIC ) || ( type == SHADER_BUFFER_TYPE_DYNAMIC_TEMP ) );
-}
-
-
-//-----------------------------------------------------------------------------
-// Handle to a vertex, pixel, and geometry shader
-//-----------------------------------------------------------------------------
-DECLARE_POINTER_HANDLE( VertexShaderHandle_t );
-DECLARE_POINTER_HANDLE( GeometryShaderHandle_t );
-DECLARE_POINTER_HANDLE( PixelShaderHandle_t );
-
-#define VERTEX_SHADER_HANDLE_INVALID ( (VertexShaderHandle_t)0 )
-#define GEOMETRY_SHADER_HANDLE_INVALID ( (GeometryShaderHandle_t)0 )
-#define PIXEL_SHADER_HANDLE_INVALID ( (PixelShaderHandle_t)0 )
-
-
-//-----------------------------------------------------------------------------
-// A shader buffer returns a block of memory which must be released when done with it
-//-----------------------------------------------------------------------------
-abstract_class IShaderBuffer
-{
-public:
- virtual size_t GetSize() const = 0;
- virtual const void* GetBits() const = 0;
- virtual void Release() = 0;
-};
-
-
-//-----------------------------------------------------------------------------
-// Mode chance callback
-//-----------------------------------------------------------------------------
-typedef void (*ShaderModeChangeCallbackFunc_t)( void );
-
-
-//-----------------------------------------------------------------------------
-// Methods related to discovering and selecting devices
-//-----------------------------------------------------------------------------
-#define SHADER_DEVICE_MGR_INTERFACE_VERSION "ShaderDeviceMgr001"
-abstract_class IShaderDeviceMgr : public IAppSystem
-{
-public:
- // Gets the number of adapters...
- virtual int GetAdapterCount() const = 0;
-
- // Returns info about each adapter
- virtual void GetAdapterInfo( int nAdapter, MaterialAdapterInfo_t& info ) const = 0;
-
- // Gets recommended congifuration for a particular adapter at a particular dx level
- virtual bool GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, KeyValues *pConfiguration ) = 0;
-
- // Returns the number of modes
- virtual int GetModeCount( int nAdapter ) const = 0;
-
- // Returns mode information..
- virtual void GetModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter, int nMode ) const = 0;
-
- // Returns the current mode info for the requested adapter
- virtual void GetCurrentModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter ) const = 0;
-
- // Initialization, shutdown
- virtual bool SetAdapter( int nAdapter, int nFlags ) = 0;
-
- // Sets the mode
- // Use the returned factory to get at an IShaderDevice and an IShaderRender
- // and any other interfaces we decide to create.
- // A returned factory of NULL indicates the mode was not set properly.
- virtual CreateInterfaceFn SetMode( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode ) = 0;
-
- // Installs a callback to get called
- virtual void AddModeChangeCallback( ShaderModeChangeCallbackFunc_t func ) = 0;
- virtual void RemoveModeChangeCallback( ShaderModeChangeCallbackFunc_t func ) = 0;
-};
-
-
-//-----------------------------------------------------------------------------
-// Methods related to control of the device
-//-----------------------------------------------------------------------------
-#define SHADER_DEVICE_INTERFACE_VERSION "ShaderDevice001"
-abstract_class IShaderDevice
-{
-public:
- // Releases/reloads resources when other apps want some memory
- virtual void ReleaseResources() = 0;
- virtual void ReacquireResources() = 0;
-
- // returns the backbuffer format and dimensions
- virtual ImageFormat GetBackBufferFormat() const = 0;
- virtual void GetBackBufferDimensions( int& width, int& height ) const = 0;
-
- // Returns the current adapter in use
- virtual int GetCurrentAdapter() const = 0;
-
- // Are we using graphics?
- virtual bool IsUsingGraphics() const = 0;
-
- // Use this to spew information about the 3D layer
- virtual void SpewDriverInfo() const = 0;
-
- // What's the bit depth of the stencil buffer?
- virtual int StencilBufferBits() const = 0;
-
- // Are we using a mode that uses MSAA
- virtual bool IsAAEnabled() const = 0;
-
- // Does a page flip
- virtual void Present() = 0;
-
- // Returns the window size
- virtual void GetWindowSize( int &nWidth, int &nHeight ) const = 0;
-
- // Gamma ramp control
- virtual void SetHardwareGammaRamp( float fGamma, float fGammaTVRangeMin, float fGammaTVRangeMax, float fGammaTVExponent, bool bTVEnabled ) = 0;
-
- // Creates/ destroys a child window
- virtual bool AddView( void* hWnd ) = 0;
- virtual void RemoveView( void* hWnd ) = 0;
-
- // Activates a view
- virtual void SetView( void* hWnd ) = 0;
-
- // Shader compilation
- virtual IShaderBuffer* CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) = 0;
-
- // Shader creation, destruction
- virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer* pShaderBuffer ) = 0;
- virtual void DestroyVertexShader( VertexShaderHandle_t hShader ) = 0;
- virtual GeometryShaderHandle_t CreateGeometryShader( IShaderBuffer* pShaderBuffer ) = 0;
- virtual void DestroyGeometryShader( GeometryShaderHandle_t hShader ) = 0;
- virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer ) = 0;
- virtual void DestroyPixelShader( PixelShaderHandle_t hShader ) = 0;
-
- // Utility methods to make shader creation simpler
- // NOTE: For the utlbuffer version, use a binary buffer for a compiled shader
- // and a text buffer for a source-code (.fxc) shader
- VertexShaderHandle_t CreateVertexShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion );
- VertexShaderHandle_t CreateVertexShader( CUtlBuffer &buf, const char *pShaderVersion = NULL );
- GeometryShaderHandle_t CreateGeometryShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion );
- GeometryShaderHandle_t CreateGeometryShader( CUtlBuffer &buf, const char *pShaderVersion = NULL );
- PixelShaderHandle_t CreatePixelShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion );
- PixelShaderHandle_t CreatePixelShader( CUtlBuffer &buf, const char *pShaderVersion = NULL );
-
- // NOTE: Deprecated!! Use CreateVertexBuffer/CreateIndexBuffer instead
- // Creates/destroys Mesh
- virtual IMesh* CreateStaticMesh( VertexFormat_t vertexFormat, const char *pTextureBudgetGroup, IMaterial * pMaterial = NULL ) = 0;
- virtual void DestroyStaticMesh( IMesh* mesh ) = 0;
-
- // Creates/destroys static vertex + index buffers
- virtual IVertexBuffer *CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup ) = 0;
- virtual void DestroyVertexBuffer( IVertexBuffer *pVertexBuffer ) = 0;
-
- virtual IIndexBuffer *CreateIndexBuffer( ShaderBufferType_t bufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup ) = 0;
- virtual void DestroyIndexBuffer( IIndexBuffer *pIndexBuffer ) = 0;
-
- // Do we need to specify the stream here in the case of locking multiple dynamic VBs on different streams?
- virtual IVertexBuffer *GetDynamicVertexBuffer( int nStreamID, VertexFormat_t vertexFormat, bool bBuffered = true ) = 0;
- virtual IIndexBuffer *GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered = true ) = 0;
-
- // A special path used to tick the front buffer while loading on the 360
- virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode, ShaderNonInteractiveInfo_t *pInfo = NULL ) = 0;
- virtual void RefreshFrontBufferNonInteractive( ) = 0;
- virtual void HandleThreadEvent( uint32 threadEvent ) = 0;
-
-#ifdef DX_TO_GL_ABSTRACTION
- virtual void DoStartupShaderPreloading( void ) = 0;
-#endif
-
-};
-
-
-//-----------------------------------------------------------------------------
-// Helper wrapper for IShaderBuffer for reading precompiled shader files
-// NOTE: This is meant to be instanced on the stack; so don't call Release!
-//-----------------------------------------------------------------------------
-class CUtlShaderBuffer : public IShaderBuffer
-{
-public:
- CUtlShaderBuffer( CUtlBuffer &buf ) : m_pBuf( &buf ) {}
-
- virtual size_t GetSize() const
- {
- return m_pBuf->TellMaxPut();
- }
-
- virtual const void* GetBits() const
- {
- return m_pBuf->Base();
- }
-
- virtual void Release()
- {
- Assert( 0 );
- }
-
-private:
- CUtlBuffer *m_pBuf;
-};
-
-
-//-----------------------------------------------------------------------------
-// Inline methods of IShaderDevice
-//-----------------------------------------------------------------------------
-inline VertexShaderHandle_t IShaderDevice::CreateVertexShader( CUtlBuffer &buf, const char *pShaderVersion )
-{
- // NOTE: Text buffers are assumed to have source-code shader files
- // Binary buffers are assumed to have compiled shader files
- if ( buf.IsText() )
- {
- Assert( pShaderVersion );
- return CreateVertexShader( (const char *)buf.Base(), buf.TellMaxPut(), pShaderVersion );
- }
-
- CUtlShaderBuffer shaderBuffer( buf );
- return CreateVertexShader( &shaderBuffer );
-}
-
-inline VertexShaderHandle_t IShaderDevice::CreateVertexShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion )
-{
- VertexShaderHandle_t hVertexShader = VERTEX_SHADER_HANDLE_INVALID;
- IShaderBuffer* pShaderBuffer = CompileShader( pProgram, nBufLen, pShaderVersion );
- if ( pShaderBuffer )
- {
- hVertexShader = CreateVertexShader( pShaderBuffer );
- pShaderBuffer->Release();
- }
- return hVertexShader;
-}
-
-inline GeometryShaderHandle_t IShaderDevice::CreateGeometryShader( CUtlBuffer &buf, const char *pShaderVersion )
-{
- // NOTE: Text buffers are assumed to have source-code shader files
- // Binary buffers are assumed to have compiled shader files
- if ( buf.IsText() )
- {
- Assert( pShaderVersion );
- return CreateGeometryShader( (const char *)buf.Base(), buf.TellMaxPut(), pShaderVersion );
- }
-
- CUtlShaderBuffer shaderBuffer( buf );
- return CreateGeometryShader( &shaderBuffer );
-}
-
-inline GeometryShaderHandle_t IShaderDevice::CreateGeometryShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion )
-{
- GeometryShaderHandle_t hGeometryShader = GEOMETRY_SHADER_HANDLE_INVALID;
- IShaderBuffer* pShaderBuffer = CompileShader( pProgram, nBufLen, pShaderVersion );
- if ( pShaderBuffer )
- {
- hGeometryShader = CreateGeometryShader( pShaderBuffer );
- pShaderBuffer->Release();
- }
- return hGeometryShader;
-}
-
-inline PixelShaderHandle_t IShaderDevice::CreatePixelShader( CUtlBuffer &buf, const char *pShaderVersion )
-{
- // NOTE: Text buffers are assumed to have source-code shader files
- // Binary buffers are assumed to have compiled shader files
- if ( buf.IsText() )
- {
- Assert( pShaderVersion );
- return CreatePixelShader( (const char *)buf.Base(), buf.TellMaxPut(), pShaderVersion );
- }
-
- CUtlShaderBuffer shaderBuffer( buf );
- return CreatePixelShader( &shaderBuffer );
-}
-
-inline PixelShaderHandle_t IShaderDevice::CreatePixelShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion )
-{
- PixelShaderHandle_t hPixelShader = PIXEL_SHADER_HANDLE_INVALID;
- IShaderBuffer* pShaderBuffer = CompileShader( pProgram, nBufLen, pShaderVersion );
- if ( pShaderBuffer )
- {
- hPixelShader = CreatePixelShader( pShaderBuffer );
- pShaderBuffer->Release();
- }
- return hPixelShader;
-}
-
-
-#endif // ISHADERDEVICE_H
+//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef ISHADERDEVICE_H +#define ISHADERDEVICE_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "tier1/interface.h" +#include "appframework/IAppSystem.h" +#include "bitmap/imageformat.h" +#include "tier1/utlbuffer.h" +#include "materialsystem/imaterial.h" +#include "shaderapi/ishaderdynamic.h" + + +//----------------------------------------------------------------------------- +// forward declarations +//----------------------------------------------------------------------------- +struct MaterialAdapterInfo_t; +class IMesh; +class KeyValues; + + +//----------------------------------------------------------------------------- +// Describes how to set the mode +//----------------------------------------------------------------------------- +#define SHADER_DISPLAY_MODE_VERSION 1 + +struct ShaderDisplayMode_t +{ + ShaderDisplayMode_t() { memset( this, 0, sizeof(ShaderDisplayMode_t) ); m_nVersion = SHADER_DISPLAY_MODE_VERSION; } + + int m_nVersion; + int m_nWidth; // 0 when running windowed means use desktop resolution + int m_nHeight; + ImageFormat m_Format; // use ImageFormats (ignored for windowed mode) + int m_nRefreshRateNumerator; // Refresh rate. Use 0 in numerator + denominator for a default setting. + int m_nRefreshRateDenominator; // Refresh rate = numerator / denominator. +}; + + +//----------------------------------------------------------------------------- +// Describes how to set the device +//----------------------------------------------------------------------------- +#define SHADER_DEVICE_INFO_VERSION 1 + +struct ShaderDeviceInfo_t +{ + ShaderDeviceInfo_t() { memset( this, 0, sizeof(ShaderDeviceInfo_t) ); m_nVersion = SHADER_DEVICE_INFO_VERSION; m_DisplayMode.m_nVersion = SHADER_DISPLAY_MODE_VERSION; } + + int m_nVersion; + ShaderDisplayMode_t m_DisplayMode; + int m_nBackBufferCount; // valid values are 1 or 2 [2 results in triple buffering] + int m_nAASamples; // Number of AA samples to use + int m_nAAQuality; // AA quality level + int m_nDXLevel; // 0 means use recommended DX level for this adapter + int m_nWindowedSizeLimitWidth; // Used if m_bLimitWindowedSize is set, defines max bounds for the back buffer + int m_nWindowedSizeLimitHeight; + + bool m_bWindowed : 1; + bool m_bResizing : 1; // Only is meaningful when using windowed mode; means the window can be resized. + bool m_bUseStencil : 1; + bool m_bLimitWindowedSize : 1; // In windowed mode, should we prevent the back buffer from getting too large? + bool m_bWaitForVSync : 1; // Would we not present until vsync? + bool m_bScaleToOutputResolution : 1; // 360 ONLY: sets up hardware scaling + bool m_bProgressive : 1; // 360 ONLY: interlaced or progressive + bool m_bUsingMultipleWindows : 1; // Forces D3DPresent to use _COPY instead +}; + + +//----------------------------------------------------------------------------- +// Info for non-interactive mode +//----------------------------------------------------------------------------- +struct ShaderNonInteractiveInfo_t +{ + ShaderAPITextureHandle_t m_hTempFullscreenTexture; + int m_nPacifierCount; + ShaderAPITextureHandle_t m_pPacifierTextures[64]; + float m_flNormalizedX; + float m_flNormalizedY; + float m_flNormalizedSize; +}; + + +//----------------------------------------------------------------------------- +// For vertex/index buffers. What type is it? +// (NOTE: mirror this with a similarly named enum at the material system level for backwards compatability.) +//----------------------------------------------------------------------------- +enum ShaderBufferType_t +{ + SHADER_BUFFER_TYPE_STATIC = 0, + SHADER_BUFFER_TYPE_DYNAMIC, + SHADER_BUFFER_TYPE_STATIC_TEMP, + SHADER_BUFFER_TYPE_DYNAMIC_TEMP, + + SHADER_BUFFER_TYPE_COUNT, +}; + +inline bool IsDynamicBufferType( ShaderBufferType_t type ) +{ + return ( ( type == SHADER_BUFFER_TYPE_DYNAMIC ) || ( type == SHADER_BUFFER_TYPE_DYNAMIC_TEMP ) ); +} + + +//----------------------------------------------------------------------------- +// Handle to a vertex, pixel, and geometry shader +//----------------------------------------------------------------------------- +DECLARE_POINTER_HANDLE( VertexShaderHandle_t ); +DECLARE_POINTER_HANDLE( GeometryShaderHandle_t ); +DECLARE_POINTER_HANDLE( PixelShaderHandle_t ); + +#define VERTEX_SHADER_HANDLE_INVALID ( (VertexShaderHandle_t)0 ) +#define GEOMETRY_SHADER_HANDLE_INVALID ( (GeometryShaderHandle_t)0 ) +#define PIXEL_SHADER_HANDLE_INVALID ( (PixelShaderHandle_t)0 ) + + +//----------------------------------------------------------------------------- +// A shader buffer returns a block of memory which must be released when done with it +//----------------------------------------------------------------------------- +abstract_class IShaderBuffer +{ +public: + virtual size_t GetSize() const = 0; + virtual const void* GetBits() const = 0; + virtual void Release() = 0; +}; + + +//----------------------------------------------------------------------------- +// Mode chance callback +//----------------------------------------------------------------------------- +typedef void (*ShaderModeChangeCallbackFunc_t)( void ); + + +//----------------------------------------------------------------------------- +// Methods related to discovering and selecting devices +//----------------------------------------------------------------------------- +#define SHADER_DEVICE_MGR_INTERFACE_VERSION "ShaderDeviceMgr001" +abstract_class IShaderDeviceMgr : public IAppSystem +{ +public: + // Gets the number of adapters... + virtual int GetAdapterCount() const = 0; + + // Returns info about each adapter + virtual void GetAdapterInfo( int nAdapter, MaterialAdapterInfo_t& info ) const = 0; + + // Gets recommended congifuration for a particular adapter at a particular dx level + virtual bool GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, KeyValues *pConfiguration ) = 0; + + // Returns the number of modes + virtual int GetModeCount( int nAdapter ) const = 0; + + // Returns mode information.. + virtual void GetModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter, int nMode ) const = 0; + + // Returns the current mode info for the requested adapter + virtual void GetCurrentModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter ) const = 0; + + // Initialization, shutdown + virtual bool SetAdapter( int nAdapter, int nFlags ) = 0; + + // Sets the mode + // Use the returned factory to get at an IShaderDevice and an IShaderRender + // and any other interfaces we decide to create. + // A returned factory of NULL indicates the mode was not set properly. + virtual CreateInterfaceFn SetMode( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode ) = 0; + + // Installs a callback to get called + virtual void AddModeChangeCallback( ShaderModeChangeCallbackFunc_t func ) = 0; + virtual void RemoveModeChangeCallback( ShaderModeChangeCallbackFunc_t func ) = 0; +}; + + +//----------------------------------------------------------------------------- +// Methods related to control of the device +//----------------------------------------------------------------------------- +#define SHADER_DEVICE_INTERFACE_VERSION "ShaderDevice001" +abstract_class IShaderDevice +{ +public: + // Releases/reloads resources when other apps want some memory + virtual void ReleaseResources() = 0; + virtual void ReacquireResources() = 0; + + // returns the backbuffer format and dimensions + virtual ImageFormat GetBackBufferFormat() const = 0; + virtual void GetBackBufferDimensions( int& width, int& height ) const = 0; + + // Returns the current adapter in use + virtual int GetCurrentAdapter() const = 0; + + // Are we using graphics? + virtual bool IsUsingGraphics() const = 0; + + // Use this to spew information about the 3D layer + virtual void SpewDriverInfo() const = 0; + + // What's the bit depth of the stencil buffer? + virtual int StencilBufferBits() const = 0; + + // Are we using a mode that uses MSAA + virtual bool IsAAEnabled() const = 0; + + // Does a page flip + virtual void Present() = 0; + + // Returns the window size + virtual void GetWindowSize( int &nWidth, int &nHeight ) const = 0; + + // Gamma ramp control + virtual void SetHardwareGammaRamp( float fGamma, float fGammaTVRangeMin, float fGammaTVRangeMax, float fGammaTVExponent, bool bTVEnabled ) = 0; + + // Creates/ destroys a child window + virtual bool AddView( void* hWnd ) = 0; + virtual void RemoveView( void* hWnd ) = 0; + + // Activates a view + virtual void SetView( void* hWnd ) = 0; + + // Shader compilation + virtual IShaderBuffer* CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) = 0; + + // Shader creation, destruction + virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer* pShaderBuffer ) = 0; + virtual void DestroyVertexShader( VertexShaderHandle_t hShader ) = 0; + virtual GeometryShaderHandle_t CreateGeometryShader( IShaderBuffer* pShaderBuffer ) = 0; + virtual void DestroyGeometryShader( GeometryShaderHandle_t hShader ) = 0; + virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer ) = 0; + virtual void DestroyPixelShader( PixelShaderHandle_t hShader ) = 0; + + // Utility methods to make shader creation simpler + // NOTE: For the utlbuffer version, use a binary buffer for a compiled shader + // and a text buffer for a source-code (.fxc) shader + VertexShaderHandle_t CreateVertexShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ); + VertexShaderHandle_t CreateVertexShader( CUtlBuffer &buf, const char *pShaderVersion = NULL ); + GeometryShaderHandle_t CreateGeometryShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ); + GeometryShaderHandle_t CreateGeometryShader( CUtlBuffer &buf, const char *pShaderVersion = NULL ); + PixelShaderHandle_t CreatePixelShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ); + PixelShaderHandle_t CreatePixelShader( CUtlBuffer &buf, const char *pShaderVersion = NULL ); + + // NOTE: Deprecated!! Use CreateVertexBuffer/CreateIndexBuffer instead + // Creates/destroys Mesh + virtual IMesh* CreateStaticMesh( VertexFormat_t vertexFormat, const char *pTextureBudgetGroup, IMaterial * pMaterial = NULL ) = 0; + virtual void DestroyStaticMesh( IMesh* mesh ) = 0; + + // Creates/destroys static vertex + index buffers + virtual IVertexBuffer *CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup ) = 0; + virtual void DestroyVertexBuffer( IVertexBuffer *pVertexBuffer ) = 0; + + virtual IIndexBuffer *CreateIndexBuffer( ShaderBufferType_t bufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup ) = 0; + virtual void DestroyIndexBuffer( IIndexBuffer *pIndexBuffer ) = 0; + + // Do we need to specify the stream here in the case of locking multiple dynamic VBs on different streams? + virtual IVertexBuffer *GetDynamicVertexBuffer( int nStreamID, VertexFormat_t vertexFormat, bool bBuffered = true ) = 0; + virtual IIndexBuffer *GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered = true ) = 0; + + // A special path used to tick the front buffer while loading on the 360 + virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode, ShaderNonInteractiveInfo_t *pInfo = NULL ) = 0; + virtual void RefreshFrontBufferNonInteractive( ) = 0; + virtual void HandleThreadEvent( uint32 threadEvent ) = 0; + +#ifdef DX_TO_GL_ABSTRACTION + virtual void DoStartupShaderPreloading( void ) = 0; +#endif + +}; + + +//----------------------------------------------------------------------------- +// Helper wrapper for IShaderBuffer for reading precompiled shader files +// NOTE: This is meant to be instanced on the stack; so don't call Release! +//----------------------------------------------------------------------------- +class CUtlShaderBuffer : public IShaderBuffer +{ +public: + CUtlShaderBuffer( CUtlBuffer &buf ) : m_pBuf( &buf ) {} + + virtual size_t GetSize() const + { + return m_pBuf->TellMaxPut(); + } + + virtual const void* GetBits() const + { + return m_pBuf->Base(); + } + + virtual void Release() + { + Assert( 0 ); + } + +private: + CUtlBuffer *m_pBuf; +}; + + +//----------------------------------------------------------------------------- +// Inline methods of IShaderDevice +//----------------------------------------------------------------------------- +inline VertexShaderHandle_t IShaderDevice::CreateVertexShader( CUtlBuffer &buf, const char *pShaderVersion ) +{ + // NOTE: Text buffers are assumed to have source-code shader files + // Binary buffers are assumed to have compiled shader files + if ( buf.IsText() ) + { + Assert( pShaderVersion ); + return CreateVertexShader( (const char *)buf.Base(), buf.TellMaxPut(), pShaderVersion ); + } + + CUtlShaderBuffer shaderBuffer( buf ); + return CreateVertexShader( &shaderBuffer ); +} + +inline VertexShaderHandle_t IShaderDevice::CreateVertexShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) +{ + VertexShaderHandle_t hVertexShader = VERTEX_SHADER_HANDLE_INVALID; + IShaderBuffer* pShaderBuffer = CompileShader( pProgram, nBufLen, pShaderVersion ); + if ( pShaderBuffer ) + { + hVertexShader = CreateVertexShader( pShaderBuffer ); + pShaderBuffer->Release(); + } + return hVertexShader; +} + +inline GeometryShaderHandle_t IShaderDevice::CreateGeometryShader( CUtlBuffer &buf, const char *pShaderVersion ) +{ + // NOTE: Text buffers are assumed to have source-code shader files + // Binary buffers are assumed to have compiled shader files + if ( buf.IsText() ) + { + Assert( pShaderVersion ); + return CreateGeometryShader( (const char *)buf.Base(), buf.TellMaxPut(), pShaderVersion ); + } + + CUtlShaderBuffer shaderBuffer( buf ); + return CreateGeometryShader( &shaderBuffer ); +} + +inline GeometryShaderHandle_t IShaderDevice::CreateGeometryShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) +{ + GeometryShaderHandle_t hGeometryShader = GEOMETRY_SHADER_HANDLE_INVALID; + IShaderBuffer* pShaderBuffer = CompileShader( pProgram, nBufLen, pShaderVersion ); + if ( pShaderBuffer ) + { + hGeometryShader = CreateGeometryShader( pShaderBuffer ); + pShaderBuffer->Release(); + } + return hGeometryShader; +} + +inline PixelShaderHandle_t IShaderDevice::CreatePixelShader( CUtlBuffer &buf, const char *pShaderVersion ) +{ + // NOTE: Text buffers are assumed to have source-code shader files + // Binary buffers are assumed to have compiled shader files + if ( buf.IsText() ) + { + Assert( pShaderVersion ); + return CreatePixelShader( (const char *)buf.Base(), buf.TellMaxPut(), pShaderVersion ); + } + + CUtlShaderBuffer shaderBuffer( buf ); + return CreatePixelShader( &shaderBuffer ); +} + +inline PixelShaderHandle_t IShaderDevice::CreatePixelShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) +{ + PixelShaderHandle_t hPixelShader = PIXEL_SHADER_HANDLE_INVALID; + IShaderBuffer* pShaderBuffer = CompileShader( pProgram, nBufLen, pShaderVersion ); + if ( pShaderBuffer ) + { + hPixelShader = CreatePixelShader( pShaderBuffer ); + pShaderBuffer->Release(); + } + return hPixelShader; +} + + +#endif // ISHADERDEVICE_H diff --git a/sp/src/public/shaderapi/commandbuffer.h b/sp/src/public/shaderapi/commandbuffer.h index 7c9137a8..de79915f 100644 --- a/sp/src/public/shaderapi/commandbuffer.h +++ b/sp/src/public/shaderapi/commandbuffer.h @@ -1,108 +1,108 @@ -//========= Copyright Valve Corporation, All rights reserved. ============//
-//
-// Purpose:
-//
-// $NoKeywords: $
-//
-// This file defines a number of constants and structured which are used to build up a command
-// buffer to pass to ShaderAPI for state setting and other operations. Since the prupose of these
-// command buffers is to minimize and optimize calls into shaderapi, their structure is not
-// abstract - they are built out by the calling process.
-//
-//===========================================================================//
-
-#ifndef COMMANDBUFFER_H
-#define COMMANDBUFFER_H
-
-
-#ifdef _WIN32
-#pragma once
-#endif
-
-// all commands defined with their struct
-enum CommandBufferCommand_t
-{
- // flow control commands.
- CBCMD_END = 0, // end of stream
- CBCMD_JUMP = 1, // int cmd, void *adr. jump to another
- // stream. Can be used to implement
- // non-sequentially allocated storage
- CBCMD_JSR = 2, // int cmd, void *adr. subroutine call to another stream.
-
- // constant setting commands
- CBCMD_SET_PIXEL_SHADER_FLOAT_CONST = 256, // int cmd,int first_reg, int nregs, float values[nregs*4]
-
-
- CBCMD_SET_VERTEX_SHADER_FLOAT_CONST = 257, // int cmd,int first_reg, int nregs, float values[nregs*4]
- CBCMD_SET_VERTEX_SHADER_FLOAT_CONST_REF = 258, // int cmd,int first_reg, int nregs, &float values[nregs*4]
- CBCMD_SETPIXELSHADERFOGPARAMS = 259, // int cmd, int regdest
- CBCMD_STORE_EYE_POS_IN_PSCONST = 260, // int cmd, int regdest
- CBCMD_COMMITPIXELSHADERLIGHTING = 261, // int cmd, int regdest
- CBCMD_SETPIXELSHADERSTATEAMBIENTLIGHTCUBE = 262, // int cmd, int regdest
- CBCMD_SETAMBIENTCUBEDYNAMICSTATEVERTEXSHADER = 263, // int cmd
- CBCMD_SET_DEPTH_FEATHERING_CONST = 264, // int cmd, int constant register, float blend scale
-
- // texture binding
- CBCMD_BIND_STANDARD_TEXTURE = 512, // cmd, sampler, texture id
- CBCMD_BIND_SHADERAPI_TEXTURE_HANDLE = 513, // cmd, sampler, texture handle
-
- // shaders
- CBCMD_SET_PSHINDEX = 1024, // cmd, idx
- CBCMD_SET_VSHINDEX = 1025, // cmd, idx
-
- // commands from mainline. In mainline commands no longer have
- // command id's specified like this. So I make up numbers...
- CBCMD_SET_VERTEX_SHADER_FLASHLIGHT_STATE = 2000, // cmd, int first_reg (for worldToTexture matrix)
- CBCMD_SET_PIXEL_SHADER_FLASHLIGHT_STATE = 2001, // cmd, int color reg, int atten reg, int origin reg, sampler (for flashlight texture)
-
- CBCMD_SET_PIXEL_SHADER_UBERLIGHT_STATE = 2002, // cmd
-
- CBCMD_SET_VERTEX_SHADER_NEARZFARZ_STATE = 2003, // cmd
-
-};
-
-//-----------------------------------------------------------------------------
-// Commands used by the per-instance command buffer
-// NOTE: If you add commands, you probably want to change the size of
-// CInstanceStorageBuffer and/or the choice of making it a fixed-size allocation
-// see shaderlib/baseshader.*
-//
-// FIXME!! NOTE that this whole scheme here generates a dependency of the
-// shaders on internal guts of shaderapidx8, since it's responsible for
-// setting various pixel shader + vertex shader constants based on the
-// commands below. We need to remove this dependency as it's way too restrictive
-// and puts the smarts in the wrong place (see CBICMD_SETPIXELSHADERGLINTDAMPING
-// as an example). Not going to solve this for l4d though, as I don't anticipate
-// a large amount of new shader writing for that product.
-//-----------------------------------------------------------------------------
-enum CommandBufferInstanceCommand_t
-{
- CBICMD_END = 0, // end of stream
- CBICMD_JUMP, // int cmd, void *adr. jump to another
- // stream. Can be used to implement
- // non-sequentially allocated storage
- CBICMD_JSR, // int cmd, void *adr. subroutine call to another stream.
-
- CBICMD_SETSKINNINGMATRICES, // int cmd
-
- CBICMD_SETVERTEXSHADERLOCALLIGHTING, // int cmd
- CBICMD_SETPIXELSHADERLOCALLIGHTING, // int cmd, int regdest
- CBICMD_SETVERTEXSHADERAMBIENTLIGHTCUBE, // int cmd
- CBICMD_SETPIXELSHADERAMBIENTLIGHTCUBE, // int cmd, int regdest
- CBICMD_SETPIXELSHADERAMBIENTLIGHTCUBELUMINANCE, // int cmd, int regdest
- CBICMD_SETPIXELSHADERGLINTDAMPING, // int cmd, int regdest
-
- CBICMD_BIND_ENV_CUBEMAP_TEXTURE, // cmd, sampler
-
- CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE,
- CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE_LINEARCOLORSPACE_LINEARSCALE, // int cmd, int constant register, Vector color2
- CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE_LINEARCOLORSPACE, // int cmd, int constant register, Vector color2
- CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE_LINEARSCALE, // int cmd, int constant register, Vector color2, float scale
- CBICMD_SETMODULATIONVERTEXSHADERDYNAMICSTATE, // int cmd, int constant register, Vector color2
- CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE_IDENTITY, // int cmd, int constant register
- CBICMD_SETMODULATIONVERTEXSHADERDYNAMICSTATE_LINEARSCALE, // int cmd, int constant register, Vector color2, float scale
- // This must be last
- CBICMD_COUNT,
-};
-
-#endif // commandbuffer_h
+//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +// This file defines a number of constants and structured which are used to build up a command +// buffer to pass to ShaderAPI for state setting and other operations. Since the prupose of these +// command buffers is to minimize and optimize calls into shaderapi, their structure is not +// abstract - they are built out by the calling process. +// +//===========================================================================// + +#ifndef COMMANDBUFFER_H +#define COMMANDBUFFER_H + + +#ifdef _WIN32 +#pragma once +#endif + +// all commands defined with their struct +enum CommandBufferCommand_t +{ + // flow control commands. + CBCMD_END = 0, // end of stream + CBCMD_JUMP = 1, // int cmd, void *adr. jump to another + // stream. Can be used to implement + // non-sequentially allocated storage + CBCMD_JSR = 2, // int cmd, void *adr. subroutine call to another stream. + + // constant setting commands + CBCMD_SET_PIXEL_SHADER_FLOAT_CONST = 256, // int cmd,int first_reg, int nregs, float values[nregs*4] + + + CBCMD_SET_VERTEX_SHADER_FLOAT_CONST = 257, // int cmd,int first_reg, int nregs, float values[nregs*4] + CBCMD_SET_VERTEX_SHADER_FLOAT_CONST_REF = 258, // int cmd,int first_reg, int nregs, &float values[nregs*4] + CBCMD_SETPIXELSHADERFOGPARAMS = 259, // int cmd, int regdest + CBCMD_STORE_EYE_POS_IN_PSCONST = 260, // int cmd, int regdest + CBCMD_COMMITPIXELSHADERLIGHTING = 261, // int cmd, int regdest + CBCMD_SETPIXELSHADERSTATEAMBIENTLIGHTCUBE = 262, // int cmd, int regdest + CBCMD_SETAMBIENTCUBEDYNAMICSTATEVERTEXSHADER = 263, // int cmd + CBCMD_SET_DEPTH_FEATHERING_CONST = 264, // int cmd, int constant register, float blend scale + + // texture binding + CBCMD_BIND_STANDARD_TEXTURE = 512, // cmd, sampler, texture id + CBCMD_BIND_SHADERAPI_TEXTURE_HANDLE = 513, // cmd, sampler, texture handle + + // shaders + CBCMD_SET_PSHINDEX = 1024, // cmd, idx + CBCMD_SET_VSHINDEX = 1025, // cmd, idx + + // commands from mainline. In mainline commands no longer have + // command id's specified like this. So I make up numbers... + CBCMD_SET_VERTEX_SHADER_FLASHLIGHT_STATE = 2000, // cmd, int first_reg (for worldToTexture matrix) + CBCMD_SET_PIXEL_SHADER_FLASHLIGHT_STATE = 2001, // cmd, int color reg, int atten reg, int origin reg, sampler (for flashlight texture) + + CBCMD_SET_PIXEL_SHADER_UBERLIGHT_STATE = 2002, // cmd + + CBCMD_SET_VERTEX_SHADER_NEARZFARZ_STATE = 2003, // cmd + +}; + +//----------------------------------------------------------------------------- +// Commands used by the per-instance command buffer +// NOTE: If you add commands, you probably want to change the size of +// CInstanceStorageBuffer and/or the choice of making it a fixed-size allocation +// see shaderlib/baseshader.* +// +// FIXME!! NOTE that this whole scheme here generates a dependency of the +// shaders on internal guts of shaderapidx8, since it's responsible for +// setting various pixel shader + vertex shader constants based on the +// commands below. We need to remove this dependency as it's way too restrictive +// and puts the smarts in the wrong place (see CBICMD_SETPIXELSHADERGLINTDAMPING +// as an example). Not going to solve this for l4d though, as I don't anticipate +// a large amount of new shader writing for that product. +//----------------------------------------------------------------------------- +enum CommandBufferInstanceCommand_t +{ + CBICMD_END = 0, // end of stream + CBICMD_JUMP, // int cmd, void *adr. jump to another + // stream. Can be used to implement + // non-sequentially allocated storage + CBICMD_JSR, // int cmd, void *adr. subroutine call to another stream. + + CBICMD_SETSKINNINGMATRICES, // int cmd + + CBICMD_SETVERTEXSHADERLOCALLIGHTING, // int cmd + CBICMD_SETPIXELSHADERLOCALLIGHTING, // int cmd, int regdest + CBICMD_SETVERTEXSHADERAMBIENTLIGHTCUBE, // int cmd + CBICMD_SETPIXELSHADERAMBIENTLIGHTCUBE, // int cmd, int regdest + CBICMD_SETPIXELSHADERAMBIENTLIGHTCUBELUMINANCE, // int cmd, int regdest + CBICMD_SETPIXELSHADERGLINTDAMPING, // int cmd, int regdest + + CBICMD_BIND_ENV_CUBEMAP_TEXTURE, // cmd, sampler + + CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE, + CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE_LINEARCOLORSPACE_LINEARSCALE, // int cmd, int constant register, Vector color2 + CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE_LINEARCOLORSPACE, // int cmd, int constant register, Vector color2 + CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE_LINEARSCALE, // int cmd, int constant register, Vector color2, float scale + CBICMD_SETMODULATIONVERTEXSHADERDYNAMICSTATE, // int cmd, int constant register, Vector color2 + CBICMD_SETMODULATIONPIXELSHADERDYNAMICSTATE_IDENTITY, // int cmd, int constant register + CBICMD_SETMODULATIONVERTEXSHADERDYNAMICSTATE_LINEARSCALE, // int cmd, int constant register, Vector color2, float scale + // This must be last + CBICMD_COUNT, +}; + +#endif // commandbuffer_h diff --git a/sp/src/public/shaderapi/ishaderapi.h b/sp/src/public/shaderapi/ishaderapi.h index f087baea..69782a60 100644 --- a/sp/src/public/shaderapi/ishaderapi.h +++ b/sp/src/public/shaderapi/ishaderapi.h @@ -1,617 +1,617 @@ -//========= Copyright Valve Corporation, All rights reserved. ============//
-//
-// Purpose:
-//
-// $NoKeywords: $
-//
-//===========================================================================//
-
-#ifndef ISHADERAPI_H
-#define ISHADERAPI_H
-
-#ifdef _WIN32
-#pragma once
-#endif
-
-#include "mathlib/vector4d.h"
-#include "shaderapi/ishaderdynamic.h"
-#include "shaderapi/IShaderDevice.h"
-#include "materialsystem/deformations.h"
-
-
-//-----------------------------------------------------------------------------
-// forward declarations
-//-----------------------------------------------------------------------------
-class IShaderUtil;
-class IFileSystem;
-class CPixelWriter;
-class CMeshBuilder;
-struct MaterialVideoMode_t;
-class IMesh;
-class IVertexBuffer;
-class IIndexBuffer;
-struct MeshDesc_t;
-enum MaterialCullMode_t;
-class IDataCache;
-struct MorphWeight_t;
-class IVTFTexture;
-
-
-//-----------------------------------------------------------------------------
-// This must match the definition in playback.cpp!
-//-----------------------------------------------------------------------------
-enum ShaderRenderTarget_t
-{
- SHADER_RENDERTARGET_BACKBUFFER = -1,
- SHADER_RENDERTARGET_DEPTHBUFFER = -1,
- // GR - no RT, used to disable depth buffer
- SHADER_RENDERTARGET_NONE = -2,
-};
-
-
-//-----------------------------------------------------------------------------
-// This must match the definition in playback.cpp!
-//-----------------------------------------------------------------------------
-typedef int ShaderAPITextureHandle_t;
-#define INVALID_SHADERAPI_TEXTURE_HANDLE 0
-
-
-//-----------------------------------------------------------------------------
-// The state snapshot handle
-//-----------------------------------------------------------------------------
-typedef short StateSnapshot_t;
-
-
-//-----------------------------------------------------------------------------
-// The state snapshot handle
-//-----------------------------------------------------------------------------
-typedef int ShaderDLL_t;
-
-
-//-----------------------------------------------------------------------------
-// Texture creation
-//-----------------------------------------------------------------------------
-enum CreateTextureFlags_t
-{
- TEXTURE_CREATE_CUBEMAP = 0x0001,
- TEXTURE_CREATE_RENDERTARGET = 0x0002,
- TEXTURE_CREATE_MANAGED = 0x0004,
- TEXTURE_CREATE_DEPTHBUFFER = 0x0008,
- TEXTURE_CREATE_DYNAMIC = 0x0010,
- TEXTURE_CREATE_AUTOMIPMAP = 0x0020,
- TEXTURE_CREATE_VERTEXTEXTURE = 0x0040, // for internal use only
- TEXTURE_CREATE_FALLBACK = 0x0080, // 360 only
- TEXTURE_CREATE_NOD3DMEMORY = 0x0100, // 360 only
- TEXTURE_CREATE_UNUSED3 = 0x0200, // Dead
- TEXTURE_CREATE_UNUSED4 = 0x0400, // Dead
- TEXTURE_CREATE_UNUSED5 = 0x0800, // Dead
- TEXTURE_CREATE_UNFILTERABLE_OK = 0x1000,
- TEXTURE_CREATE_CANCONVERTFORMAT = 0x2000, // 360 only, allow format conversions at load
- TEXTURE_CREATE_SRGB = 0x4000, // Posix/GL only, for textures which are SRGB-readable
-
-};
-
-
-
-//-----------------------------------------------------------------------------
-// Fill modes
-//-----------------------------------------------------------------------------
-enum ShaderFillMode_t
-{
- SHADER_FILL_SOLID = 0,
- SHADER_FILL_WIREFRAME,
-};
-
-
-//-----------------------------------------------------------------------------
-// Rasterization state object
-//-----------------------------------------------------------------------------
-struct ShaderRasterState_t
-{
- ShaderFillMode_t m_FillMode;
- MaterialCullMode_t m_CullMode;
- bool m_bCullEnable : 1;
- bool m_bDepthBias : 1;
- bool m_bScissorEnable : 1;
- bool m_bMultisampleEnable : 1;
-};
-
-
-//-----------------------------------------------------------------------------
-// Used for occlusion queries
-//-----------------------------------------------------------------------------
-DECLARE_POINTER_HANDLE( ShaderAPIOcclusionQuery_t );
-#define INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE ( (ShaderAPIOcclusionQuery_t)0 )
-
-enum ShaderAPIOcclusionQueryResult_t
-{
- OCCLUSION_QUERY_RESULT_PENDING = -1,
- OCCLUSION_QUERY_RESULT_ERROR = -2
-};
-#define OCCLUSION_QUERY_FINISHED( iQueryResult ) ( ( iQueryResult ) != OCCLUSION_QUERY_RESULT_PENDING )
-
-
-//-----------------------------------------------------------------------------
-// This is what the material system gets to see.
-//-----------------------------------------------------------------------------
-#define SHADERAPI_INTERFACE_VERSION "ShaderApi030"
-abstract_class IShaderAPI : public IShaderDynamicAPI
-{
-public:
- //
- // NOTE: These methods have been ported to DX10
- //
-
- // Viewport methods
- virtual void SetViewports( int nCount, const ShaderViewport_t* pViewports ) = 0;
- virtual int GetViewports( ShaderViewport_t* pViewports, int nMax ) const = 0;
-
- // Buffer clearing
- virtual void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight ) = 0;
- virtual void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b ) = 0;
- virtual void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ) = 0;
-
- // Methods related to binding shaders
- virtual void BindVertexShader( VertexShaderHandle_t hVertexShader ) = 0;
- virtual void BindGeometryShader( GeometryShaderHandle_t hGeometryShader ) = 0;
- virtual void BindPixelShader( PixelShaderHandle_t hPixelShader ) = 0;
-
- // Methods related to state objects
- virtual void SetRasterState( const ShaderRasterState_t& state ) = 0;
-
- //
- // NOTE: These methods have not yet been ported to DX10
- //
-
- // Sets the mode...
- virtual bool SetMode( void* hwnd, int nAdapter, const ShaderDeviceInfo_t &info ) = 0;
-
- virtual void ChangeVideoMode( const ShaderDeviceInfo_t &info ) = 0;
-
- // Returns the snapshot id for the shader state
- virtual StateSnapshot_t TakeSnapshot( ) = 0;
-
- virtual void TexMinFilter( ShaderTexFilterMode_t texFilterMode ) = 0;
- virtual void TexMagFilter( ShaderTexFilterMode_t texFilterMode ) = 0;
- virtual void TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode ) = 0;
-
- virtual void CopyRenderTargetToTexture( ShaderAPITextureHandle_t textureHandle ) = 0;
-
- // Binds a particular material to render with
- virtual void Bind( IMaterial* pMaterial ) = 0;
-
- // Flushes any primitives that are buffered
- virtual void FlushBufferedPrimitives() = 0;
-
- // 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.
- virtual IMesh* GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool bBuffered = true,
- IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0) = 0;
- virtual IMesh* GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t vertexFormat, int nHWSkinBoneCount,
- bool bBuffered = true, IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0 ) = 0;
-
- // Methods to ask about particular state snapshots
- virtual bool IsTranslucent( StateSnapshot_t id ) const = 0;
- virtual bool IsAlphaTested( StateSnapshot_t id ) const = 0;
- virtual bool UsesVertexAndPixelShaders( StateSnapshot_t id ) const = 0;
- virtual bool IsDepthWriteEnabled( StateSnapshot_t id ) const = 0;
-
- // Gets the vertex format for a set of snapshot ids
- virtual VertexFormat_t ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds ) const = 0;
-
- // What fields in the vertex do we actually use?
- virtual VertexFormat_t ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds ) const = 0;
-
- // Begins a rendering pass
- virtual void BeginPass( StateSnapshot_t snapshot ) = 0;
-
- // Renders a single pass of a material
- virtual void RenderPass( int nPass, int nPassCount ) = 0;
-
- // Set the number of bone weights
- virtual void SetNumBoneWeights( int numBones ) = 0;
-
- // Sets the lights
- virtual void SetLight( int lightNum, const LightDesc_t& desc ) = 0;
-
- // Lighting origin for the current model
- virtual void SetLightingOrigin( Vector vLightingOrigin ) = 0;
-
- virtual void SetAmbientLight( float r, float g, float b ) = 0;
- virtual void SetAmbientLightCube( Vector4D cube[6] ) = 0;
-
- // The shade mode
- virtual void ShadeMode( ShaderShadeMode_t mode ) = 0;
-
- // The cull mode
- virtual void CullMode( MaterialCullMode_t cullMode ) = 0;
-
- // Force writes only when z matches. . . useful for stenciling things out
- // by rendering the desired Z values ahead of time.
- virtual void ForceDepthFuncEquals( bool bEnable ) = 0;
-
- // Forces Z buffering to be on or off
- virtual void OverrideDepthEnable( bool bEnable, bool bDepthEnable ) = 0;
-
- virtual void SetHeightClipZ( float z ) = 0;
- virtual void SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode ) = 0;
-
- virtual void SetClipPlane( int index, const float *pPlane ) = 0;
- virtual void EnableClipPlane( int index, bool bEnable ) = 0;
-
- // Put all the model matrices into vertex shader constants.
- virtual void SetSkinningMatrices() = 0;
-
- // Returns the nearest supported format
- virtual ImageFormat GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired = true ) const = 0;
- virtual ImageFormat GetNearestRenderTargetFormat( ImageFormat fmt ) const = 0;
-
- // When AA is enabled, render targets are not AA and require a separate
- // depth buffer.
- virtual bool DoRenderTargetsNeedSeparateDepthBuffer() const = 0;
-
- // Texture management methods
- // For CreateTexture also see CreateTextures below
- virtual ShaderAPITextureHandle_t CreateTexture(
- int width,
- int height,
- int depth,
- ImageFormat dstImageFormat,
- int numMipLevels,
- int numCopies,
- int flags,
- const char *pDebugName,
- const char *pTextureGroupName ) = 0;
-
- virtual void DeleteTexture( ShaderAPITextureHandle_t textureHandle ) = 0;
-
- virtual ShaderAPITextureHandle_t CreateDepthTexture(
- ImageFormat renderTargetFormat,
- int width,
- int height,
- const char *pDebugName,
- bool bTexture ) = 0;
-
- virtual bool IsTexture( ShaderAPITextureHandle_t textureHandle ) = 0;
- virtual bool IsTextureResident( ShaderAPITextureHandle_t textureHandle ) = 0;
-
- // Indicates we're going to be modifying this texture
- // TexImage2D, TexSubImage2D, TexWrap, TexMinFilter, and TexMagFilter
- // all use the texture specified by this function.
- virtual void ModifyTexture( ShaderAPITextureHandle_t textureHandle ) = 0;
-
- virtual void TexImage2D(
- int level,
- int cubeFaceID,
- ImageFormat dstFormat,
- int zOffset,
- int width,
- int height,
- ImageFormat srcFormat,
- bool bSrcIsTiled, // NOTE: for X360 only
- void *imageData ) = 0;
-
- virtual void TexSubImage2D(
- int level,
- int cubeFaceID,
- int xOffset,
- int yOffset,
- int zOffset,
- int width,
- int height,
- ImageFormat srcFormat,
- int srcStride,
- bool bSrcIsTiled, // NOTE: for X360 only
- void *imageData ) = 0;
-
- virtual void TexImageFromVTF( IVTFTexture* pVTF, int iVTFFrame ) = 0;
-
- // An alternate (and faster) way of writing image data
- // (locks the current Modify Texture). Use the pixel writer to write the data
- // after Lock is called
- // Doesn't work for compressed textures
- virtual bool TexLock( int level, int cubeFaceID, int xOffset, int yOffset,
- int width, int height, CPixelWriter& writer ) = 0;
- virtual void TexUnlock( ) = 0;
-
- // These are bound to the texture
- virtual void TexSetPriority( int priority ) = 0;
-
- // Sets the texture state
- virtual void BindTexture( Sampler_t sampler, ShaderAPITextureHandle_t textureHandle ) = 0;
-
- // Set the render target to a texID.
- // Set to SHADER_RENDERTARGET_BACKBUFFER if you want to use the regular framebuffer.
- // Set to SHADER_RENDERTARGET_DEPTHBUFFER if you want to use the regular z buffer.
- virtual void SetRenderTarget( ShaderAPITextureHandle_t colorTextureHandle = SHADER_RENDERTARGET_BACKBUFFER,
- ShaderAPITextureHandle_t depthTextureHandle = SHADER_RENDERTARGET_DEPTHBUFFER ) = 0;
-
- // stuff that isn't to be used from within a shader
- virtual void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth ) = 0;
- virtual void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat ) = 0;
- virtual void ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride ) = 0;
-
- virtual void FlushHardware() = 0;
-
- // Use this to begin and end the frame
- virtual void BeginFrame() = 0;
- virtual void EndFrame() = 0;
-
- // Selection mode methods
- virtual int SelectionMode( bool selectionMode ) = 0;
- virtual void SelectionBuffer( unsigned int* pBuffer, int size ) = 0;
- virtual void ClearSelectionNames( ) = 0;
- virtual void LoadSelectionName( int name ) = 0;
- virtual void PushSelectionName( int name ) = 0;
- virtual void PopSelectionName() = 0;
-
- // Force the hardware to finish whatever it's doing
- virtual void ForceHardwareSync() = 0;
-
- // Used to clear the transition table when we know it's become invalid.
- virtual void ClearSnapshots() = 0;
-
- virtual void FogStart( float fStart ) = 0;
- virtual void FogEnd( float fEnd ) = 0;
- virtual void SetFogZ( float fogZ ) = 0;
- // Scene fog state.
- virtual void SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b ) = 0;
- virtual void GetSceneFogColor( unsigned char *rgb ) = 0;
- virtual void SceneFogMode( MaterialFogMode_t fogMode ) = 0;
-
- // Can we download textures?
- virtual bool CanDownloadTextures() const = 0;
-
- virtual void ResetRenderState( bool bFullReset = true ) = 0;
-
- // We use smaller dynamic VBs during level transitions, to free up memory
- virtual int GetCurrentDynamicVBSize( void ) = 0;
- virtual void DestroyVertexBuffers( bool bExitingLevel = false ) = 0;
-
- virtual void EvictManagedResources() = 0;
-
- // Level of anisotropic filtering
- virtual void SetAnisotropicLevel( int nAnisotropyLevel ) = 0;
-
- // For debugging and building recording files. This will stuff a token into the recording file,
- // then someone doing a playback can watch for the token.
- virtual void SyncToken( const char *pToken ) = 0;
-
- // Setup standard vertex shader constants (that don't change)
- // This needs to be called anytime that overbright changes.
- virtual void SetStandardVertexShaderConstants( float fOverbright ) = 0;
-
- //
- // Occlusion query support
- //
-
- // Allocate and delete query objects.
- virtual ShaderAPIOcclusionQuery_t CreateOcclusionQueryObject( void ) = 0;
- virtual void DestroyOcclusionQueryObject( ShaderAPIOcclusionQuery_t ) = 0;
-
- // Bracket drawing with begin and end so that we can get counts next frame.
- virtual void BeginOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t ) = 0;
- virtual void EndOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t ) = 0;
-
- // OcclusionQuery_GetNumPixelsRendered
- // Get the number of pixels rendered between begin and end on an earlier frame.
- // Calling this in the same frame is a huge perf hit!
- // Returns iQueryResult:
- // iQueryResult >= 0 - iQueryResult is the number of pixels rendered
- // OCCLUSION_QUERY_RESULT_PENDING - query results are not available yet
- // OCCLUSION_QUERY_RESULT_ERROR - query failed
- // Use OCCLUSION_QUERY_FINISHED( iQueryResult ) to test if query finished.
- virtual int OcclusionQuery_GetNumPixelsRendered( ShaderAPIOcclusionQuery_t hQuery, bool bFlush = false ) = 0;
-
- virtual void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture ) = 0;
-
- virtual void ClearVertexAndPixelShaderRefCounts() = 0;
- virtual void PurgeUnusedVertexAndPixelShaders() = 0;
-
- // Called when the dx support level has changed
- virtual void DXSupportLevelChanged() = 0;
-
- // By default, the material system applies the VIEW and PROJECTION matrices to the user clip
- // planes (which are specified in world space) to generate projection-space user clip planes
- // Occasionally (for the particle system in hl2, for example), we want to override that
- // behavior and explictly specify a View transform for user clip planes. The PROJECTION
- // will be mutliplied against this instead of the normal VIEW matrix.
- virtual void EnableUserClipTransformOverride( bool bEnable ) = 0;
- virtual void UserClipTransform( const VMatrix &worldToView ) = 0;
-
- // ----------------------------------------------------------------------------------
- // Everything after this point added after HL2 shipped.
- // ----------------------------------------------------------------------------------
-
- // What fields in the morph do we actually use?
- virtual MorphFormat_t ComputeMorphFormat( int numSnapshots, StateSnapshot_t* pIds ) const = 0;
-
- // Set the render target to a texID.
- // Set to SHADER_RENDERTARGET_BACKBUFFER if you want to use the regular framebuffer.
- // Set to SHADER_RENDERTARGET_DEPTHBUFFER if you want to use the regular z buffer.
- virtual void SetRenderTargetEx( int nRenderTargetID,
- ShaderAPITextureHandle_t colorTextureHandle = SHADER_RENDERTARGET_BACKBUFFER,
- ShaderAPITextureHandle_t depthTextureHandle = SHADER_RENDERTARGET_DEPTHBUFFER ) = 0;
-
- virtual void CopyRenderTargetToTextureEx( ShaderAPITextureHandle_t textureHandle, int nRenderTargetID, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) = 0;
- virtual void CopyTextureToRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t textureHandle, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) = 0;
-
- // For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer)
- virtual void HandleDeviceLost() = 0;
-
- virtual void EnableLinearColorSpaceFrameBuffer( bool bEnable ) = 0;
-
- // Lets the shader know about the full-screen texture so it can
- virtual void SetFullScreenTextureHandle( ShaderAPITextureHandle_t h ) = 0;
-
- // Rendering parameters control special drawing modes withing the material system, shader
- // system, shaders, and engine. renderparm.h has their definitions.
- virtual void SetFloatRenderingParameter(int parm_number, float value) = 0;
- virtual void SetIntRenderingParameter(int parm_number, int value) = 0;
- virtual void SetVectorRenderingParameter(int parm_number, Vector const &value) = 0;
-
- virtual float GetFloatRenderingParameter(int parm_number) const = 0;
- virtual int GetIntRenderingParameter(int parm_number) const = 0;
- virtual Vector GetVectorRenderingParameter(int parm_number) const = 0;
-
- virtual void SetFastClipPlane( const float *pPlane ) = 0;
- virtual void EnableFastClip( bool bEnable ) = 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;
-
- // stencil methods
- virtual void SetStencilEnable(bool onoff) = 0;
- virtual void SetStencilFailOperation(StencilOperation_t op) = 0;
- virtual void SetStencilZFailOperation(StencilOperation_t op) = 0;
- virtual void SetStencilPassOperation(StencilOperation_t op) = 0;
- virtual void SetStencilCompareFunction(StencilComparisonFunction_t cmpfn) = 0;
- virtual void SetStencilReferenceValue(int ref) = 0;
- virtual void SetStencilTestMask(uint32 msk) = 0;
- virtual void SetStencilWriteMask(uint32 msk) = 0;
- virtual void ClearStencilBufferRectangle(int xmin, int ymin, int xmax, int ymax, int value) = 0;
-
- // disables all local lights
- virtual void DisableAllLocalLights() = 0;
- virtual int CompareSnapshots( StateSnapshot_t snapshot0, StateSnapshot_t snapshot1 ) = 0;
-
- virtual IMesh *GetFlexMesh() = 0;
-
- virtual void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture ) = 0;
-
- virtual bool SupportsMSAAMode( int nMSAAMode ) = 0;
-
-#if defined( _X360 )
- virtual HXUIFONT OpenTrueTypeFont( const char *pFontname, int tall, int style ) = 0;
- virtual void CloseTrueTypeFont( HXUIFONT hFont ) = 0;
- virtual bool GetTrueTypeFontMetrics( HXUIFONT hFont, XUIFontMetrics *pFontMetrics, XUICharMetrics charMetrics[256] ) = 0;
- // Render a sequence of characters and extract the data into a buffer
- // For each character, provide the width+height of the font texture subrect,
- // an offset to apply when rendering the glyph, and an offset into a buffer to receive the RGBA data
- virtual bool GetTrueTypeGlyphs( HXUIFONT hFont, int numChars, wchar_t *pWch, int *pOffsetX, int *pOffsetY, int *pWidth, int *pHeight, unsigned char *pRGBA, int *pRGBAOffset ) = 0;
- virtual ShaderAPITextureHandle_t CreateRenderTargetSurface( int width, int height, ImageFormat format, const char *pDebugName, const char *pTextureGroupName ) = 0;
- virtual void PersistDisplay() = 0;
- virtual bool PostQueuedTexture( const void *pData, int nSize, ShaderAPITextureHandle_t *pHandles, int nHandles, int nWidth, int nHeight, int nDepth, int nMips, int *pRefCount ) = 0;
- virtual void *GetD3DDevice() = 0;
-
- virtual void PushVertexShaderGPRAllocation( int iVertexShaderCount = 64 ) = 0;
- virtual void PopVertexShaderGPRAllocation( void ) = 0;
-
- virtual void EnableVSync_360( bool bEnable ) = 0; //360 allows us to bypass vsync blocking up to 60 fps without creating a new device
-#endif
-
- virtual bool OwnGPUResources( bool bEnable ) = 0;
-
- //get fog distances entered with FogStart(), FogEnd(), and SetFogZ()
- virtual void GetFogDistances( float *fStart, float *fEnd, float *fFogZ ) = 0;
-
- // Hooks for firing PIX events from outside the Material System...
- virtual void BeginPIXEvent( unsigned long color, const char *szName ) = 0;
- virtual void EndPIXEvent() = 0;
- virtual void SetPIXMarker( unsigned long color, const char *szName ) = 0;
-
- // Enables and disables for Alpha To Coverage
- virtual void EnableAlphaToCoverage() = 0;
- virtual void DisableAlphaToCoverage() = 0;
-
- // Computes the vertex buffer pointers
- virtual void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc ) const = 0;
-
- virtual bool SupportsShadowDepthTextures( void ) = 0;
-
- virtual void SetDisallowAccess( bool ) = 0;
- virtual void EnableShaderShaderMutex( bool ) = 0;
- virtual void ShaderLock() = 0;
- virtual void ShaderUnlock() = 0;
-
- virtual ImageFormat GetShadowDepthTextureFormat( void ) = 0;
-
- virtual bool SupportsFetch4( void ) = 0;
- virtual void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) = 0;
-
-// ------------ New Vertex/Index Buffer interface ----------------------------
- virtual void BindVertexBuffer( int nStreamID, 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 ----------------------------
-
-
- // Apply stencil operations to every pixel on the screen without disturbing depth or color buffers
- virtual void PerformFullScreenStencilOperation( void ) = 0;
-
- virtual void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ) = 0;
-
- // nVidia CSAA modes, different from SupportsMSAAMode()
- virtual bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ) = 0;
-
- //Notifies the shaderapi to invalidate the current set of delayed constants because we just finished a draw pass. Either actual or not.
- virtual void InvalidateDelayedShaderConstants( void ) = 0;
-
- // Gamma<->Linear conversions according to the video hardware we're running on
- virtual float GammaToLinear_HardwareSpecific( float fGamma ) const =0;
- virtual float LinearToGamma_HardwareSpecific( float fLinear ) const =0;
-
- //Set's the linear->gamma conversion textures to use for this hardware for both srgb writes enabled and disabled(identity)
- virtual void SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture ) = 0;
-
- virtual ImageFormat GetNullTextureFormat( void ) = 0;
-
- virtual void BindVertexTexture( VertexTextureSampler_t nSampler, ShaderAPITextureHandle_t textureHandle ) = 0;
-
- // Enables hardware morphing
- virtual void EnableHWMorphing( bool bEnable ) = 0;
-
- // Sets flexweights for rendering
- virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights ) = 0;
-
- virtual void FogMaxDensity( float flMaxDensity ) = 0;
-
- // Create a multi-frame texture (equivalent to calling "CreateTexture" multiple times, but more efficient)
- virtual 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 ) = 0;
-
- virtual void AcquireThreadOwnership() = 0;
- virtual void ReleaseThreadOwnership() = 0;
-
- virtual bool SupportsNormalMapCompression() const = 0;
-
- // Only does anything on XBox360. This is useful to eliminate stalls
- virtual void EnableBuffer2FramesAhead( bool bEnable ) = 0;
-
- virtual void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) = 0;
-
- // debug logging
- // only implemented in some subclasses
- virtual void PrintfVA( char *fmt, va_list vargs ) = 0;
- virtual void Printf( PRINTF_FORMAT_STRING char *fmt, ... ) = 0;
- virtual float Knob( char *knobname, float *setvalue = NULL ) = 0;
- // Allows us to override the alpha write setting of a material
- virtual void OverrideAlphaWriteEnable( bool bEnable, bool bAlphaWriteEnable ) = 0;
- virtual void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable ) = 0;
-
- //extended clear buffers function with alpha independent from color
- virtual void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth ) = 0;
-};
-
-
-#endif // ISHADERAPI_H
+//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef ISHADERAPI_H +#define ISHADERAPI_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "mathlib/vector4d.h" +#include "shaderapi/ishaderdynamic.h" +#include "shaderapi/IShaderDevice.h" +#include "materialsystem/deformations.h" + + +//----------------------------------------------------------------------------- +// forward declarations +//----------------------------------------------------------------------------- +class IShaderUtil; +class IFileSystem; +class CPixelWriter; +class CMeshBuilder; +struct MaterialVideoMode_t; +class IMesh; +class IVertexBuffer; +class IIndexBuffer; +struct MeshDesc_t; +enum MaterialCullMode_t; +class IDataCache; +struct MorphWeight_t; +class IVTFTexture; + + +//----------------------------------------------------------------------------- +// This must match the definition in playback.cpp! +//----------------------------------------------------------------------------- +enum ShaderRenderTarget_t +{ + SHADER_RENDERTARGET_BACKBUFFER = -1, + SHADER_RENDERTARGET_DEPTHBUFFER = -1, + // GR - no RT, used to disable depth buffer + SHADER_RENDERTARGET_NONE = -2, +}; + + +//----------------------------------------------------------------------------- +// This must match the definition in playback.cpp! +//----------------------------------------------------------------------------- +typedef int ShaderAPITextureHandle_t; +#define INVALID_SHADERAPI_TEXTURE_HANDLE 0 + + +//----------------------------------------------------------------------------- +// The state snapshot handle +//----------------------------------------------------------------------------- +typedef short StateSnapshot_t; + + +//----------------------------------------------------------------------------- +// The state snapshot handle +//----------------------------------------------------------------------------- +typedef int ShaderDLL_t; + + +//----------------------------------------------------------------------------- +// Texture creation +//----------------------------------------------------------------------------- +enum CreateTextureFlags_t +{ + TEXTURE_CREATE_CUBEMAP = 0x0001, + TEXTURE_CREATE_RENDERTARGET = 0x0002, + TEXTURE_CREATE_MANAGED = 0x0004, + TEXTURE_CREATE_DEPTHBUFFER = 0x0008, + TEXTURE_CREATE_DYNAMIC = 0x0010, + TEXTURE_CREATE_AUTOMIPMAP = 0x0020, + TEXTURE_CREATE_VERTEXTEXTURE = 0x0040, // for internal use only + TEXTURE_CREATE_FALLBACK = 0x0080, // 360 only + TEXTURE_CREATE_NOD3DMEMORY = 0x0100, // 360 only + TEXTURE_CREATE_UNUSED3 = 0x0200, // Dead + TEXTURE_CREATE_UNUSED4 = 0x0400, // Dead + TEXTURE_CREATE_UNUSED5 = 0x0800, // Dead + TEXTURE_CREATE_UNFILTERABLE_OK = 0x1000, + TEXTURE_CREATE_CANCONVERTFORMAT = 0x2000, // 360 only, allow format conversions at load + TEXTURE_CREATE_SRGB = 0x4000, // Posix/GL only, for textures which are SRGB-readable + +}; + + + +//----------------------------------------------------------------------------- +// Fill modes +//----------------------------------------------------------------------------- +enum ShaderFillMode_t +{ + SHADER_FILL_SOLID = 0, + SHADER_FILL_WIREFRAME, +}; + + +//----------------------------------------------------------------------------- +// Rasterization state object +//----------------------------------------------------------------------------- +struct ShaderRasterState_t +{ + ShaderFillMode_t m_FillMode; + MaterialCullMode_t m_CullMode; + bool m_bCullEnable : 1; + bool m_bDepthBias : 1; + bool m_bScissorEnable : 1; + bool m_bMultisampleEnable : 1; +}; + + +//----------------------------------------------------------------------------- +// Used for occlusion queries +//----------------------------------------------------------------------------- +DECLARE_POINTER_HANDLE( ShaderAPIOcclusionQuery_t ); +#define INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE ( (ShaderAPIOcclusionQuery_t)0 ) + +enum ShaderAPIOcclusionQueryResult_t +{ + OCCLUSION_QUERY_RESULT_PENDING = -1, + OCCLUSION_QUERY_RESULT_ERROR = -2 +}; +#define OCCLUSION_QUERY_FINISHED( iQueryResult ) ( ( iQueryResult ) != OCCLUSION_QUERY_RESULT_PENDING ) + + +//----------------------------------------------------------------------------- +// This is what the material system gets to see. +//----------------------------------------------------------------------------- +#define SHADERAPI_INTERFACE_VERSION "ShaderApi030" +abstract_class IShaderAPI : public IShaderDynamicAPI +{ +public: + // + // NOTE: These methods have been ported to DX10 + // + + // Viewport methods + virtual void SetViewports( int nCount, const ShaderViewport_t* pViewports ) = 0; + virtual int GetViewports( ShaderViewport_t* pViewports, int nMax ) const = 0; + + // Buffer clearing + virtual void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight ) = 0; + virtual void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b ) = 0; + virtual void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ) = 0; + + // Methods related to binding shaders + virtual void BindVertexShader( VertexShaderHandle_t hVertexShader ) = 0; + virtual void BindGeometryShader( GeometryShaderHandle_t hGeometryShader ) = 0; + virtual void BindPixelShader( PixelShaderHandle_t hPixelShader ) = 0; + + // Methods related to state objects + virtual void SetRasterState( const ShaderRasterState_t& state ) = 0; + + // + // NOTE: These methods have not yet been ported to DX10 + // + + // Sets the mode... + virtual bool SetMode( void* hwnd, int nAdapter, const ShaderDeviceInfo_t &info ) = 0; + + virtual void ChangeVideoMode( const ShaderDeviceInfo_t &info ) = 0; + + // Returns the snapshot id for the shader state + virtual StateSnapshot_t TakeSnapshot( ) = 0; + + virtual void TexMinFilter( ShaderTexFilterMode_t texFilterMode ) = 0; + virtual void TexMagFilter( ShaderTexFilterMode_t texFilterMode ) = 0; + virtual void TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode ) = 0; + + virtual void CopyRenderTargetToTexture( ShaderAPITextureHandle_t textureHandle ) = 0; + + // Binds a particular material to render with + virtual void Bind( IMaterial* pMaterial ) = 0; + + // Flushes any primitives that are buffered + virtual void FlushBufferedPrimitives() = 0; + + // 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. + virtual IMesh* GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool bBuffered = true, + IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0) = 0; + virtual IMesh* GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t vertexFormat, int nHWSkinBoneCount, + bool bBuffered = true, IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0 ) = 0; + + // Methods to ask about particular state snapshots + virtual bool IsTranslucent( StateSnapshot_t id ) const = 0; + virtual bool IsAlphaTested( StateSnapshot_t id ) const = 0; + virtual bool UsesVertexAndPixelShaders( StateSnapshot_t id ) const = 0; + virtual bool IsDepthWriteEnabled( StateSnapshot_t id ) const = 0; + + // Gets the vertex format for a set of snapshot ids + virtual VertexFormat_t ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds ) const = 0; + + // What fields in the vertex do we actually use? + virtual VertexFormat_t ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds ) const = 0; + + // Begins a rendering pass + virtual void BeginPass( StateSnapshot_t snapshot ) = 0; + + // Renders a single pass of a material + virtual void RenderPass( int nPass, int nPassCount ) = 0; + + // Set the number of bone weights + virtual void SetNumBoneWeights( int numBones ) = 0; + + // Sets the lights + virtual void SetLight( int lightNum, const LightDesc_t& desc ) = 0; + + // Lighting origin for the current model + virtual void SetLightingOrigin( Vector vLightingOrigin ) = 0; + + virtual void SetAmbientLight( float r, float g, float b ) = 0; + virtual void SetAmbientLightCube( Vector4D cube[6] ) = 0; + + // The shade mode + virtual void ShadeMode( ShaderShadeMode_t mode ) = 0; + + // The cull mode + virtual void CullMode( MaterialCullMode_t cullMode ) = 0; + + // Force writes only when z matches. . . useful for stenciling things out + // by rendering the desired Z values ahead of time. + virtual void ForceDepthFuncEquals( bool bEnable ) = 0; + + // Forces Z buffering to be on or off + virtual void OverrideDepthEnable( bool bEnable, bool bDepthEnable ) = 0; + + virtual void SetHeightClipZ( float z ) = 0; + virtual void SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode ) = 0; + + virtual void SetClipPlane( int index, const float *pPlane ) = 0; + virtual void EnableClipPlane( int index, bool bEnable ) = 0; + + // Put all the model matrices into vertex shader constants. + virtual void SetSkinningMatrices() = 0; + + // Returns the nearest supported format + virtual ImageFormat GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired = true ) const = 0; + virtual ImageFormat GetNearestRenderTargetFormat( ImageFormat fmt ) const = 0; + + // When AA is enabled, render targets are not AA and require a separate + // depth buffer. + virtual bool DoRenderTargetsNeedSeparateDepthBuffer() const = 0; + + // Texture management methods + // For CreateTexture also see CreateTextures below + virtual ShaderAPITextureHandle_t CreateTexture( + int width, + int height, + int depth, + ImageFormat dstImageFormat, + int numMipLevels, + int numCopies, + int flags, + const char *pDebugName, + const char *pTextureGroupName ) = 0; + + virtual void DeleteTexture( ShaderAPITextureHandle_t textureHandle ) = 0; + + virtual ShaderAPITextureHandle_t CreateDepthTexture( + ImageFormat renderTargetFormat, + int width, + int height, + const char *pDebugName, + bool bTexture ) = 0; + + virtual bool IsTexture( ShaderAPITextureHandle_t textureHandle ) = 0; + virtual bool IsTextureResident( ShaderAPITextureHandle_t textureHandle ) = 0; + + // Indicates we're going to be modifying this texture + // TexImage2D, TexSubImage2D, TexWrap, TexMinFilter, and TexMagFilter + // all use the texture specified by this function. + virtual void ModifyTexture( ShaderAPITextureHandle_t textureHandle ) = 0; + + virtual void TexImage2D( + int level, + int cubeFaceID, + ImageFormat dstFormat, + int zOffset, + int width, + int height, + ImageFormat srcFormat, + bool bSrcIsTiled, // NOTE: for X360 only + void *imageData ) = 0; + + virtual void TexSubImage2D( + int level, + int cubeFaceID, + int xOffset, + int yOffset, + int zOffset, + int width, + int height, + ImageFormat srcFormat, + int srcStride, + bool bSrcIsTiled, // NOTE: for X360 only + void *imageData ) = 0; + + virtual void TexImageFromVTF( IVTFTexture* pVTF, int iVTFFrame ) = 0; + + // An alternate (and faster) way of writing image data + // (locks the current Modify Texture). Use the pixel writer to write the data + // after Lock is called + // Doesn't work for compressed textures + virtual bool TexLock( int level, int cubeFaceID, int xOffset, int yOffset, + int width, int height, CPixelWriter& writer ) = 0; + virtual void TexUnlock( ) = 0; + + // These are bound to the texture + virtual void TexSetPriority( int priority ) = 0; + + // Sets the texture state + virtual void BindTexture( Sampler_t sampler, ShaderAPITextureHandle_t textureHandle ) = 0; + + // Set the render target to a texID. + // Set to SHADER_RENDERTARGET_BACKBUFFER if you want to use the regular framebuffer. + // Set to SHADER_RENDERTARGET_DEPTHBUFFER if you want to use the regular z buffer. + virtual void SetRenderTarget( ShaderAPITextureHandle_t colorTextureHandle = SHADER_RENDERTARGET_BACKBUFFER, + ShaderAPITextureHandle_t depthTextureHandle = SHADER_RENDERTARGET_DEPTHBUFFER ) = 0; + + // stuff that isn't to be used from within a shader + virtual void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth ) = 0; + virtual void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat ) = 0; + virtual void ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride ) = 0; + + virtual void FlushHardware() = 0; + + // Use this to begin and end the frame + virtual void BeginFrame() = 0; + virtual void EndFrame() = 0; + + // Selection mode methods + virtual int SelectionMode( bool selectionMode ) = 0; + virtual void SelectionBuffer( unsigned int* pBuffer, int size ) = 0; + virtual void ClearSelectionNames( ) = 0; + virtual void LoadSelectionName( int name ) = 0; + virtual void PushSelectionName( int name ) = 0; + virtual void PopSelectionName() = 0; + + // Force the hardware to finish whatever it's doing + virtual void ForceHardwareSync() = 0; + + // Used to clear the transition table when we know it's become invalid. + virtual void ClearSnapshots() = 0; + + virtual void FogStart( float fStart ) = 0; + virtual void FogEnd( float fEnd ) = 0; + virtual void SetFogZ( float fogZ ) = 0; + // Scene fog state. + virtual void SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b ) = 0; + virtual void GetSceneFogColor( unsigned char *rgb ) = 0; + virtual void SceneFogMode( MaterialFogMode_t fogMode ) = 0; + + // Can we download textures? + virtual bool CanDownloadTextures() const = 0; + + virtual void ResetRenderState( bool bFullReset = true ) = 0; + + // We use smaller dynamic VBs during level transitions, to free up memory + virtual int GetCurrentDynamicVBSize( void ) = 0; + virtual void DestroyVertexBuffers( bool bExitingLevel = false ) = 0; + + virtual void EvictManagedResources() = 0; + + // Level of anisotropic filtering + virtual void SetAnisotropicLevel( int nAnisotropyLevel ) = 0; + + // For debugging and building recording files. This will stuff a token into the recording file, + // then someone doing a playback can watch for the token. + virtual void SyncToken( const char *pToken ) = 0; + + // Setup standard vertex shader constants (that don't change) + // This needs to be called anytime that overbright changes. + virtual void SetStandardVertexShaderConstants( float fOverbright ) = 0; + + // + // Occlusion query support + // + + // Allocate and delete query objects. + virtual ShaderAPIOcclusionQuery_t CreateOcclusionQueryObject( void ) = 0; + virtual void DestroyOcclusionQueryObject( ShaderAPIOcclusionQuery_t ) = 0; + + // Bracket drawing with begin and end so that we can get counts next frame. + virtual void BeginOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t ) = 0; + virtual void EndOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t ) = 0; + + // OcclusionQuery_GetNumPixelsRendered + // Get the number of pixels rendered between begin and end on an earlier frame. + // Calling this in the same frame is a huge perf hit! + // Returns iQueryResult: + // iQueryResult >= 0 - iQueryResult is the number of pixels rendered + // OCCLUSION_QUERY_RESULT_PENDING - query results are not available yet + // OCCLUSION_QUERY_RESULT_ERROR - query failed + // Use OCCLUSION_QUERY_FINISHED( iQueryResult ) to test if query finished. + virtual int OcclusionQuery_GetNumPixelsRendered( ShaderAPIOcclusionQuery_t hQuery, bool bFlush = false ) = 0; + + virtual void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture ) = 0; + + virtual void ClearVertexAndPixelShaderRefCounts() = 0; + virtual void PurgeUnusedVertexAndPixelShaders() = 0; + + // Called when the dx support level has changed + virtual void DXSupportLevelChanged() = 0; + + // By default, the material system applies the VIEW and PROJECTION matrices to the user clip + // planes (which are specified in world space) to generate projection-space user clip planes + // Occasionally (for the particle system in hl2, for example), we want to override that + // behavior and explictly specify a View transform for user clip planes. The PROJECTION + // will be mutliplied against this instead of the normal VIEW matrix. + virtual void EnableUserClipTransformOverride( bool bEnable ) = 0; + virtual void UserClipTransform( const VMatrix &worldToView ) = 0; + + // ---------------------------------------------------------------------------------- + // Everything after this point added after HL2 shipped. + // ---------------------------------------------------------------------------------- + + // What fields in the morph do we actually use? + virtual MorphFormat_t ComputeMorphFormat( int numSnapshots, StateSnapshot_t* pIds ) const = 0; + + // Set the render target to a texID. + // Set to SHADER_RENDERTARGET_BACKBUFFER if you want to use the regular framebuffer. + // Set to SHADER_RENDERTARGET_DEPTHBUFFER if you want to use the regular z buffer. + virtual void SetRenderTargetEx( int nRenderTargetID, + ShaderAPITextureHandle_t colorTextureHandle = SHADER_RENDERTARGET_BACKBUFFER, + ShaderAPITextureHandle_t depthTextureHandle = SHADER_RENDERTARGET_DEPTHBUFFER ) = 0; + + virtual void CopyRenderTargetToTextureEx( ShaderAPITextureHandle_t textureHandle, int nRenderTargetID, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) = 0; + virtual void CopyTextureToRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t textureHandle, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) = 0; + + // For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer) + virtual void HandleDeviceLost() = 0; + + virtual void EnableLinearColorSpaceFrameBuffer( bool bEnable ) = 0; + + // Lets the shader know about the full-screen texture so it can + virtual void SetFullScreenTextureHandle( ShaderAPITextureHandle_t h ) = 0; + + // Rendering parameters control special drawing modes withing the material system, shader + // system, shaders, and engine. renderparm.h has their definitions. + virtual void SetFloatRenderingParameter(int parm_number, float value) = 0; + virtual void SetIntRenderingParameter(int parm_number, int value) = 0; + virtual void SetVectorRenderingParameter(int parm_number, Vector const &value) = 0; + + virtual float GetFloatRenderingParameter(int parm_number) const = 0; + virtual int GetIntRenderingParameter(int parm_number) const = 0; + virtual Vector GetVectorRenderingParameter(int parm_number) const = 0; + + virtual void SetFastClipPlane( const float *pPlane ) = 0; + virtual void EnableFastClip( bool bEnable ) = 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; + + // stencil methods + virtual void SetStencilEnable(bool onoff) = 0; + virtual void SetStencilFailOperation(StencilOperation_t op) = 0; + virtual void SetStencilZFailOperation(StencilOperation_t op) = 0; + virtual void SetStencilPassOperation(StencilOperation_t op) = 0; + virtual void SetStencilCompareFunction(StencilComparisonFunction_t cmpfn) = 0; + virtual void SetStencilReferenceValue(int ref) = 0; + virtual void SetStencilTestMask(uint32 msk) = 0; + virtual void SetStencilWriteMask(uint32 msk) = 0; + virtual void ClearStencilBufferRectangle(int xmin, int ymin, int xmax, int ymax, int value) = 0; + + // disables all local lights + virtual void DisableAllLocalLights() = 0; + virtual int CompareSnapshots( StateSnapshot_t snapshot0, StateSnapshot_t snapshot1 ) = 0; + + virtual IMesh *GetFlexMesh() = 0; + + virtual void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture ) = 0; + + virtual bool SupportsMSAAMode( int nMSAAMode ) = 0; + +#if defined( _X360 ) + virtual HXUIFONT OpenTrueTypeFont( const char *pFontname, int tall, int style ) = 0; + virtual void CloseTrueTypeFont( HXUIFONT hFont ) = 0; + virtual bool GetTrueTypeFontMetrics( HXUIFONT hFont, XUIFontMetrics *pFontMetrics, XUICharMetrics charMetrics[256] ) = 0; + // Render a sequence of characters and extract the data into a buffer + // For each character, provide the width+height of the font texture subrect, + // an offset to apply when rendering the glyph, and an offset into a buffer to receive the RGBA data + virtual bool GetTrueTypeGlyphs( HXUIFONT hFont, int numChars, wchar_t *pWch, int *pOffsetX, int *pOffsetY, int *pWidth, int *pHeight, unsigned char *pRGBA, int *pRGBAOffset ) = 0; + virtual ShaderAPITextureHandle_t CreateRenderTargetSurface( int width, int height, ImageFormat format, const char *pDebugName, const char *pTextureGroupName ) = 0; + virtual void PersistDisplay() = 0; + virtual bool PostQueuedTexture( const void *pData, int nSize, ShaderAPITextureHandle_t *pHandles, int nHandles, int nWidth, int nHeight, int nDepth, int nMips, int *pRefCount ) = 0; + virtual void *GetD3DDevice() = 0; + + virtual void PushVertexShaderGPRAllocation( int iVertexShaderCount = 64 ) = 0; + virtual void PopVertexShaderGPRAllocation( void ) = 0; + + virtual void EnableVSync_360( bool bEnable ) = 0; //360 allows us to bypass vsync blocking up to 60 fps without creating a new device +#endif + + virtual bool OwnGPUResources( bool bEnable ) = 0; + + //get fog distances entered with FogStart(), FogEnd(), and SetFogZ() + virtual void GetFogDistances( float *fStart, float *fEnd, float *fFogZ ) = 0; + + // Hooks for firing PIX events from outside the Material System... + virtual void BeginPIXEvent( unsigned long color, const char *szName ) = 0; + virtual void EndPIXEvent() = 0; + virtual void SetPIXMarker( unsigned long color, const char *szName ) = 0; + + // Enables and disables for Alpha To Coverage + virtual void EnableAlphaToCoverage() = 0; + virtual void DisableAlphaToCoverage() = 0; + + // Computes the vertex buffer pointers + virtual void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc ) const = 0; + + virtual bool SupportsShadowDepthTextures( void ) = 0; + + virtual void SetDisallowAccess( bool ) = 0; + virtual void EnableShaderShaderMutex( bool ) = 0; + virtual void ShaderLock() = 0; + virtual void ShaderUnlock() = 0; + + virtual ImageFormat GetShadowDepthTextureFormat( void ) = 0; + + virtual bool SupportsFetch4( void ) = 0; + virtual void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) = 0; + +// ------------ New Vertex/Index Buffer interface ---------------------------- + virtual void BindVertexBuffer( int nStreamID, 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 ---------------------------- + + + // Apply stencil operations to every pixel on the screen without disturbing depth or color buffers + virtual void PerformFullScreenStencilOperation( void ) = 0; + + virtual void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ) = 0; + + // nVidia CSAA modes, different from SupportsMSAAMode() + virtual bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ) = 0; + + //Notifies the shaderapi to invalidate the current set of delayed constants because we just finished a draw pass. Either actual or not. + virtual void InvalidateDelayedShaderConstants( void ) = 0; + + // Gamma<->Linear conversions according to the video hardware we're running on + virtual float GammaToLinear_HardwareSpecific( float fGamma ) const =0; + virtual float LinearToGamma_HardwareSpecific( float fLinear ) const =0; + + //Set's the linear->gamma conversion textures to use for this hardware for both srgb writes enabled and disabled(identity) + virtual void SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture ) = 0; + + virtual ImageFormat GetNullTextureFormat( void ) = 0; + + virtual void BindVertexTexture( VertexTextureSampler_t nSampler, ShaderAPITextureHandle_t textureHandle ) = 0; + + // Enables hardware morphing + virtual void EnableHWMorphing( bool bEnable ) = 0; + + // Sets flexweights for rendering + virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights ) = 0; + + virtual void FogMaxDensity( float flMaxDensity ) = 0; + + // Create a multi-frame texture (equivalent to calling "CreateTexture" multiple times, but more efficient) + virtual 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 ) = 0; + + virtual void AcquireThreadOwnership() = 0; + virtual void ReleaseThreadOwnership() = 0; + + virtual bool SupportsNormalMapCompression() const = 0; + + // Only does anything on XBox360. This is useful to eliminate stalls + virtual void EnableBuffer2FramesAhead( bool bEnable ) = 0; + + virtual void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) = 0; + + // debug logging + // only implemented in some subclasses + virtual void PrintfVA( char *fmt, va_list vargs ) = 0; + virtual void Printf( PRINTF_FORMAT_STRING char *fmt, ... ) = 0; + virtual float Knob( char *knobname, float *setvalue = NULL ) = 0; + // Allows us to override the alpha write setting of a material + virtual void OverrideAlphaWriteEnable( bool bEnable, bool bAlphaWriteEnable ) = 0; + virtual void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable ) = 0; + + //extended clear buffers function with alpha independent from color + virtual void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth ) = 0; +}; + + +#endif // ISHADERAPI_H diff --git a/sp/src/public/shaderapi/ishaderdynamic.h b/sp/src/public/shaderapi/ishaderdynamic.h index 090ee0c3..4d1d2d2d 100644 --- a/sp/src/public/shaderapi/ishaderdynamic.h +++ b/sp/src/public/shaderapi/ishaderdynamic.h @@ -1,345 +1,345 @@ -//========= Copyright Valve Corporation, All rights reserved. ============//
-//
-// Purpose:
-//
-// $NoKeywords: $
-//
-//===========================================================================//
-
-#ifndef ISHADERDYNAMIC_H
-#define ISHADERDYNAMIC_H
-
-#ifdef _WIN32
-#pragma once
-#endif
-
-#include "shaderapi/shareddefs.h"
-#include "materialsystem/imaterial.h"
-#include "materialsystem/imaterialsystem.h"
-#include "tier0/basetypes.h"
-
-
-typedef int ShaderAPITextureHandle_t;
-
-//-----------------------------------------------------------------------------
-// forward declarations
-//-----------------------------------------------------------------------------
-class CMeshBuilder;
-class IMaterialVar;
-struct LightDesc_t;
-
-
-//-----------------------------------------------------------------------------
-// State from ShaderAPI used to select proper vertex and pixel shader combos
-//-----------------------------------------------------------------------------
-struct LightState_t
-{
- int m_nNumLights;
- bool m_bAmbientLight;
- bool m_bStaticLight;
- inline int HasDynamicLight() { return (m_bAmbientLight || (m_nNumLights > 0)) ? 1 : 0; }
-};
-
-
-//-----------------------------------------------------------------------------
-// Color correction info
-//-----------------------------------------------------------------------------
-struct ShaderColorCorrectionInfo_t
-{
- bool m_bIsEnabled;
- int m_nLookupCount;
- float m_flDefaultWeight;
- float m_pLookupWeights[4];
-};
-
-
-//-----------------------------------------------------------------------------
-// the 3D shader API interface
-// This interface is all that shaders see.
-//-----------------------------------------------------------------------------
-enum StandardTextureId_t
-{
- // Lightmaps
- TEXTURE_LIGHTMAP = 0,
- TEXTURE_LIGHTMAP_FULLBRIGHT,
- TEXTURE_LIGHTMAP_BUMPED,
- TEXTURE_LIGHTMAP_BUMPED_FULLBRIGHT,
-
- // Flat colors
- TEXTURE_WHITE,
- TEXTURE_BLACK,
- TEXTURE_GREY,
- TEXTURE_GREY_ALPHA_ZERO,
-
- // Normalmaps
- TEXTURE_NORMALMAP_FLAT,
-
- // Normalization
- TEXTURE_NORMALIZATION_CUBEMAP,
- TEXTURE_NORMALIZATION_CUBEMAP_SIGNED,
-
- // Frame-buffer textures
- TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0,
- TEXTURE_FRAME_BUFFER_FULL_TEXTURE_1,
-
- // Color correction
- TEXTURE_COLOR_CORRECTION_VOLUME_0,
- TEXTURE_COLOR_CORRECTION_VOLUME_1,
- TEXTURE_COLOR_CORRECTION_VOLUME_2,
- TEXTURE_COLOR_CORRECTION_VOLUME_3,
-
- // An alias to the Back Frame Buffer
- TEXTURE_FRAME_BUFFER_ALIAS,
-
- // Noise for shadow mapping algorithm
- TEXTURE_SHADOW_NOISE_2D,
-
- // A texture in which morph data gets accumulated (vs30, fast vertex textures required)
- TEXTURE_MORPH_ACCUMULATOR,
-
- // A texture which contains morph weights
- TEXTURE_MORPH_WEIGHTS,
-
- // A snapshot of the frame buffer's depth. Currently only valid on the 360
- TEXTURE_FRAME_BUFFER_FULL_DEPTH,
-
- // A snapshot of the frame buffer's depth. Currently only valid on the 360
- TEXTURE_IDENTITY_LIGHTWARP,
-
- TEXTURE_MAX_STD_TEXTURES = 32
-};
-
-//-----------------------------------------------------------------------------
-// Viewport structure
-//-----------------------------------------------------------------------------
-#define SHADER_VIEWPORT_VERSION 1
-struct ShaderViewport_t
-{
- int m_nVersion;
- int m_nTopLeftX;
- int m_nTopLeftY;
- int m_nWidth;
- int m_nHeight;
- float m_flMinZ;
- float m_flMaxZ;
-
- ShaderViewport_t() : m_nVersion( SHADER_VIEWPORT_VERSION ) {}
-
- void Init()
- {
- memset( this, 0, sizeof(ShaderViewport_t) );
- m_nVersion = SHADER_VIEWPORT_VERSION;
- }
-
- void Init( int x, int y, int nWidth, int nHeight, float flMinZ = 0.0f, float flMaxZ = 1.0f )
- {
- m_nVersion = SHADER_VIEWPORT_VERSION;
- m_nTopLeftX = x; m_nTopLeftY = y; m_nWidth = nWidth; m_nHeight = nHeight;
- m_flMinZ = flMinZ;
- m_flMaxZ = flMaxZ;
- }
-};
-
-
-//-----------------------------------------------------------------------------
-// The Shader interface versions
-//-----------------------------------------------------------------------------
-#define SHADERDYNAMIC_INTERFACE_VERSION "ShaderDynamic001"
-abstract_class IShaderDynamicAPI
-{
-public:
-
- virtual void SetViewports( int nCount, const ShaderViewport_t* pViewports ) = 0;
- virtual int GetViewports( ShaderViewport_t* pViewports, int nMax ) const = 0;
-
- // returns the current time in seconds....
- virtual double CurrentTime() const = 0;
-
- // Gets the lightmap dimensions
- virtual void GetLightmapDimensions( int *w, int *h ) = 0;
-
- // Scene fog state.
- // This is used by the shaders for picking the proper vertex shader for fogging based on dynamic state.
- virtual MaterialFogMode_t GetSceneFogMode( ) = 0;
- virtual void GetSceneFogColor( unsigned char *rgb ) = 0;
-
- // stuff related to matrix stacks
- virtual void MatrixMode( MaterialMatrixMode_t matrixMode ) = 0;
- virtual void PushMatrix() = 0;
- virtual void PopMatrix() = 0;
- virtual void LoadMatrix( float *m ) = 0;
- virtual void MultMatrix( float *m ) = 0;
- virtual void MultMatrixLocal( float *m ) = 0;
- virtual void GetMatrix( MaterialMatrixMode_t matrixMode, float *dst ) = 0;
- virtual void LoadIdentity( void ) = 0;
- virtual void LoadCameraToWorld( void ) = 0;
- virtual void Ortho( double left, double right, double bottom, double top, double zNear, double zFar ) = 0;
- virtual void PerspectiveX( double fovx, double aspect, double zNear, double zFar ) = 0;
- virtual void PickMatrix( int x, int y, int width, int height ) = 0;
- virtual void Rotate( float angle, float x, float y, float z ) = 0;
- virtual void Translate( float x, float y, float z ) = 0;
- virtual void Scale( float x, float y, float z ) = 0;
- virtual void ScaleXY( float x, float y ) = 0;
-
- // Sets the color to modulate by
- virtual void Color3f( float r, float g, float b ) = 0;
- virtual void Color3fv( float const* pColor ) = 0;
- virtual void Color4f( float r, float g, float b, float a ) = 0;
- virtual void Color4fv( float const* pColor ) = 0;
-
- virtual void Color3ub( unsigned char r, unsigned char g, unsigned char b ) = 0;
- virtual void Color3ubv( unsigned char const* pColor ) = 0;
- virtual void Color4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ) = 0;
- virtual void Color4ubv( unsigned char const* pColor ) = 0;
-
- // Sets the constant register for vertex and pixel shaders
- virtual void SetVertexShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false ) = 0;
- virtual void SetPixelShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false ) = 0;
-
- // Sets the default *dynamic* state
- virtual void SetDefaultState() = 0;
-
- // Get the current camera position in world space.
- virtual void GetWorldSpaceCameraPosition( float* pPos ) const = 0;
-
- virtual int GetCurrentNumBones( void ) const = 0;
- virtual int GetCurrentLightCombo( void ) const = 0;
-
- virtual MaterialFogMode_t GetCurrentFogType( void ) const = 0;
-
- // fixme: move this to shadow state
- virtual void SetTextureTransformDimension( TextureStage_t textureStage, int dimension, bool projected ) = 0;
- virtual void DisableTextureTransform( TextureStage_t textureStage ) = 0;
- virtual void SetBumpEnvMatrix( TextureStage_t textureStage, float m00, float m01, float m10, float m11 ) = 0;
-
- // Sets the vertex and pixel shaders
- virtual void SetVertexShaderIndex( int vshIndex = -1 ) = 0;
- virtual void SetPixelShaderIndex( int pshIndex = 0 ) = 0;
-
- // Get the dimensions of the back buffer.
- virtual void GetBackBufferDimensions( int& width, int& height ) const = 0;
-
- // FIXME: The following 6 methods used to live in IShaderAPI
- // and were moved for stdshader_dx8. Let's try to move them back!
-
- // Get the lights
- virtual int GetMaxLights( void ) const = 0;
- virtual const LightDesc_t& GetLight( int lightNum ) const = 0;
-
- virtual void SetPixelShaderFogParams( int reg ) = 0;
-
- // Render state for the ambient light cube
- virtual void SetVertexShaderStateAmbientLightCube() = 0;
- virtual void SetPixelShaderStateAmbientLightCube( int pshReg, bool bForceToBlack = false ) = 0;
- virtual void CommitPixelShaderLighting( int pshReg ) = 0;
-
- // Use this to get the mesh builder that allows us to modify vertex data
- virtual CMeshBuilder* GetVertexModifyBuilder() = 0;
- virtual bool InFlashlightMode() const = 0;
- virtual const FlashlightState_t &GetFlashlightState( VMatrix &worldToTexture ) const = 0;
- virtual bool InEditorMode() const = 0;
-
- // Gets the bound morph's vertex format; returns 0 if no morph is bound
- virtual MorphFormat_t GetBoundMorphFormat() = 0;
-
- // Binds a standard texture
- virtual void BindStandardTexture( Sampler_t sampler, StandardTextureId_t id ) = 0;
-
- virtual ITexture *GetRenderTargetEx( int nRenderTargetID ) = 0;
-
- virtual void SetToneMappingScaleLinear( const Vector &scale ) = 0;
- virtual const Vector &GetToneMappingScaleLinear( void ) const = 0;
- virtual float GetLightMapScaleFactor( void ) const = 0;
-
- virtual void LoadBoneMatrix( int boneIndex, const float *m ) = 0;
-
- virtual void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right ) = 0;
-
- virtual void SetFloatRenderingParameter(int parm_number, float value) = 0;
-
- virtual void SetIntRenderingParameter(int parm_number, int value) = 0 ;
- virtual void SetVectorRenderingParameter(int parm_number, Vector const &value) = 0 ;
-
- virtual float GetFloatRenderingParameter(int parm_number) const = 0 ;
-
- virtual int GetIntRenderingParameter(int parm_number) const = 0 ;
-
- virtual Vector GetVectorRenderingParameter(int parm_number) const = 0 ;
-
- // stencil buffer operations.
- virtual void SetStencilEnable(bool onoff) = 0;
- virtual void SetStencilFailOperation(StencilOperation_t op) = 0;
- virtual void SetStencilZFailOperation(StencilOperation_t op) = 0;
- virtual void SetStencilPassOperation(StencilOperation_t op) = 0;
- virtual void SetStencilCompareFunction(StencilComparisonFunction_t cmpfn) = 0;
- virtual void SetStencilReferenceValue(int ref) = 0;
- virtual void SetStencilTestMask(uint32 msk) = 0;
- virtual void SetStencilWriteMask(uint32 msk) = 0;
- virtual void ClearStencilBufferRectangle( int xmin, int ymin, int xmax, int ymax,int value) = 0;
-
- virtual void GetDXLevelDefaults(uint &max_dxlevel,uint &recommended_dxlevel) = 0;
-
- virtual const FlashlightState_t &GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **pFlashlightDepthTexture ) const = 0;
-
- virtual float GetAmbientLightCubeLuminance() = 0;
-
- virtual void GetDX9LightState( LightState_t *state ) const = 0;
- virtual int GetPixelFogCombo( ) = 0; //0 is either range fog, or no fog simulated with rigged range fog values. 1 is height fog
-
- virtual void BindStandardVertexTexture( VertexTextureSampler_t sampler, StandardTextureId_t id ) = 0;
-
- // Is hardware morphing enabled?
- virtual bool IsHWMorphingEnabled( ) const = 0;
-
- virtual void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id ) = 0;
-
- virtual void SetBooleanVertexShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false ) = 0;
- virtual void SetIntegerVertexShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false ) = 0;
- virtual void SetBooleanPixelShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false ) = 0;
- virtual void SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false ) = 0;
-
- //Are we in a configuration that needs access to depth data through the alpha channel later?
- virtual bool ShouldWriteDepthToDestAlpha( void ) const = 0;
-
-
- // deformations
- virtual void PushDeformation( DeformationBase_t const *Deformation ) = 0;
- virtual void PopDeformation( ) = 0;
- virtual int GetNumActiveDeformations() const =0;
-
-
- // for shaders to set vertex shader constants. returns a packed state which can be used to set
- // the dynamic combo. returns # of active deformations
- virtual int GetPackedDeformationInformation( int nMaskOfUnderstoodDeformations,
- float *pConstantValuesOut,
- int nBufferSize,
- int nMaximumDeformations,
- int *pNumDefsOut ) const = 0;
-
- // This lets the lower level system that certain vertex fields requested
- // in the shadow state aren't actually being read given particular state
- // known only at dynamic state time. It's here only to silence warnings.
- virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords ) = 0;
-
-
- virtual void ExecuteCommandBuffer( uint8 *pCmdBuffer ) =0;
-
- // interface for mat system to tell shaderapi about standard texture handles
- virtual void SetStandardTextureHandle( StandardTextureId_t nId, ShaderAPITextureHandle_t nHandle ) =0;
-
- // Interface for mat system to tell shaderapi about color correction
- virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo ) = 0;
-
- virtual void SetPSNearAndFarZ( int pshReg ) = 0;
-
- virtual void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) = 0;
-};
-// end class IShaderDynamicAPI
-
-//-----------------------------------------------------------------------------
-// Software vertex shaders
-//-----------------------------------------------------------------------------
-typedef void (*SoftwareVertexShader_t)( CMeshBuilder& meshBuilder, IMaterialVar **params, IShaderDynamicAPI *pShaderAPI );
-
-
-#endif // ISHADERDYNAMIC_H
+//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef ISHADERDYNAMIC_H +#define ISHADERDYNAMIC_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "shaderapi/shareddefs.h" +#include "materialsystem/imaterial.h" +#include "materialsystem/imaterialsystem.h" +#include "tier0/basetypes.h" + + +typedef int ShaderAPITextureHandle_t; + +//----------------------------------------------------------------------------- +// forward declarations +//----------------------------------------------------------------------------- +class CMeshBuilder; +class IMaterialVar; +struct LightDesc_t; + + +//----------------------------------------------------------------------------- +// State from ShaderAPI used to select proper vertex and pixel shader combos +//----------------------------------------------------------------------------- +struct LightState_t +{ + int m_nNumLights; + bool m_bAmbientLight; + bool m_bStaticLight; + inline int HasDynamicLight() { return (m_bAmbientLight || (m_nNumLights > 0)) ? 1 : 0; } +}; + + +//----------------------------------------------------------------------------- +// Color correction info +//----------------------------------------------------------------------------- +struct ShaderColorCorrectionInfo_t +{ + bool m_bIsEnabled; + int m_nLookupCount; + float m_flDefaultWeight; + float m_pLookupWeights[4]; +}; + + +//----------------------------------------------------------------------------- +// the 3D shader API interface +// This interface is all that shaders see. +//----------------------------------------------------------------------------- +enum StandardTextureId_t +{ + // Lightmaps + TEXTURE_LIGHTMAP = 0, + TEXTURE_LIGHTMAP_FULLBRIGHT, + TEXTURE_LIGHTMAP_BUMPED, + TEXTURE_LIGHTMAP_BUMPED_FULLBRIGHT, + + // Flat colors + TEXTURE_WHITE, + TEXTURE_BLACK, + TEXTURE_GREY, + TEXTURE_GREY_ALPHA_ZERO, + + // Normalmaps + TEXTURE_NORMALMAP_FLAT, + + // Normalization + TEXTURE_NORMALIZATION_CUBEMAP, + TEXTURE_NORMALIZATION_CUBEMAP_SIGNED, + + // Frame-buffer textures + TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0, + TEXTURE_FRAME_BUFFER_FULL_TEXTURE_1, + + // Color correction + TEXTURE_COLOR_CORRECTION_VOLUME_0, + TEXTURE_COLOR_CORRECTION_VOLUME_1, + TEXTURE_COLOR_CORRECTION_VOLUME_2, + TEXTURE_COLOR_CORRECTION_VOLUME_3, + + // An alias to the Back Frame Buffer + TEXTURE_FRAME_BUFFER_ALIAS, + + // Noise for shadow mapping algorithm + TEXTURE_SHADOW_NOISE_2D, + + // A texture in which morph data gets accumulated (vs30, fast vertex textures required) + TEXTURE_MORPH_ACCUMULATOR, + + // A texture which contains morph weights + TEXTURE_MORPH_WEIGHTS, + + // A snapshot of the frame buffer's depth. Currently only valid on the 360 + TEXTURE_FRAME_BUFFER_FULL_DEPTH, + + // A snapshot of the frame buffer's depth. Currently only valid on the 360 + TEXTURE_IDENTITY_LIGHTWARP, + + TEXTURE_MAX_STD_TEXTURES = 32 +}; + +//----------------------------------------------------------------------------- +// Viewport structure +//----------------------------------------------------------------------------- +#define SHADER_VIEWPORT_VERSION 1 +struct ShaderViewport_t +{ + int m_nVersion; + int m_nTopLeftX; + int m_nTopLeftY; + int m_nWidth; + int m_nHeight; + float m_flMinZ; + float m_flMaxZ; + + ShaderViewport_t() : m_nVersion( SHADER_VIEWPORT_VERSION ) {} + + void Init() + { + memset( this, 0, sizeof(ShaderViewport_t) ); + m_nVersion = SHADER_VIEWPORT_VERSION; + } + + void Init( int x, int y, int nWidth, int nHeight, float flMinZ = 0.0f, float flMaxZ = 1.0f ) + { + m_nVersion = SHADER_VIEWPORT_VERSION; + m_nTopLeftX = x; m_nTopLeftY = y; m_nWidth = nWidth; m_nHeight = nHeight; + m_flMinZ = flMinZ; + m_flMaxZ = flMaxZ; + } +}; + + +//----------------------------------------------------------------------------- +// The Shader interface versions +//----------------------------------------------------------------------------- +#define SHADERDYNAMIC_INTERFACE_VERSION "ShaderDynamic001" +abstract_class IShaderDynamicAPI +{ +public: + + virtual void SetViewports( int nCount, const ShaderViewport_t* pViewports ) = 0; + virtual int GetViewports( ShaderViewport_t* pViewports, int nMax ) const = 0; + + // returns the current time in seconds.... + virtual double CurrentTime() const = 0; + + // Gets the lightmap dimensions + virtual void GetLightmapDimensions( int *w, int *h ) = 0; + + // Scene fog state. + // This is used by the shaders for picking the proper vertex shader for fogging based on dynamic state. + virtual MaterialFogMode_t GetSceneFogMode( ) = 0; + virtual void GetSceneFogColor( unsigned char *rgb ) = 0; + + // stuff related to matrix stacks + virtual void MatrixMode( MaterialMatrixMode_t matrixMode ) = 0; + virtual void PushMatrix() = 0; + virtual void PopMatrix() = 0; + virtual void LoadMatrix( float *m ) = 0; + virtual void MultMatrix( float *m ) = 0; + virtual void MultMatrixLocal( float *m ) = 0; + virtual void GetMatrix( MaterialMatrixMode_t matrixMode, float *dst ) = 0; + virtual void LoadIdentity( void ) = 0; + virtual void LoadCameraToWorld( void ) = 0; + virtual void Ortho( double left, double right, double bottom, double top, double zNear, double zFar ) = 0; + virtual void PerspectiveX( double fovx, double aspect, double zNear, double zFar ) = 0; + virtual void PickMatrix( int x, int y, int width, int height ) = 0; + virtual void Rotate( float angle, float x, float y, float z ) = 0; + virtual void Translate( float x, float y, float z ) = 0; + virtual void Scale( float x, float y, float z ) = 0; + virtual void ScaleXY( float x, float y ) = 0; + + // Sets the color to modulate by + virtual void Color3f( float r, float g, float b ) = 0; + virtual void Color3fv( float const* pColor ) = 0; + virtual void Color4f( float r, float g, float b, float a ) = 0; + virtual void Color4fv( float const* pColor ) = 0; + + virtual void Color3ub( unsigned char r, unsigned char g, unsigned char b ) = 0; + virtual void Color3ubv( unsigned char const* pColor ) = 0; + virtual void Color4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ) = 0; + virtual void Color4ubv( unsigned char const* pColor ) = 0; + + // Sets the constant register for vertex and pixel shaders + virtual void SetVertexShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false ) = 0; + virtual void SetPixelShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false ) = 0; + + // Sets the default *dynamic* state + virtual void SetDefaultState() = 0; + + // Get the current camera position in world space. + virtual void GetWorldSpaceCameraPosition( float* pPos ) const = 0; + + virtual int GetCurrentNumBones( void ) const = 0; + virtual int GetCurrentLightCombo( void ) const = 0; + + virtual MaterialFogMode_t GetCurrentFogType( void ) const = 0; + + // fixme: move this to shadow state + virtual void SetTextureTransformDimension( TextureStage_t textureStage, int dimension, bool projected ) = 0; + virtual void DisableTextureTransform( TextureStage_t textureStage ) = 0; + virtual void SetBumpEnvMatrix( TextureStage_t textureStage, float m00, float m01, float m10, float m11 ) = 0; + + // Sets the vertex and pixel shaders + virtual void SetVertexShaderIndex( int vshIndex = -1 ) = 0; + virtual void SetPixelShaderIndex( int pshIndex = 0 ) = 0; + + // Get the dimensions of the back buffer. + virtual void GetBackBufferDimensions( int& width, int& height ) const = 0; + + // FIXME: The following 6 methods used to live in IShaderAPI + // and were moved for stdshader_dx8. Let's try to move them back! + + // Get the lights + virtual int GetMaxLights( void ) const = 0; + virtual const LightDesc_t& GetLight( int lightNum ) const = 0; + + virtual void SetPixelShaderFogParams( int reg ) = 0; + + // Render state for the ambient light cube + virtual void SetVertexShaderStateAmbientLightCube() = 0; + virtual void SetPixelShaderStateAmbientLightCube( int pshReg, bool bForceToBlack = false ) = 0; + virtual void CommitPixelShaderLighting( int pshReg ) = 0; + + // Use this to get the mesh builder that allows us to modify vertex data + virtual CMeshBuilder* GetVertexModifyBuilder() = 0; + virtual bool InFlashlightMode() const = 0; + virtual const FlashlightState_t &GetFlashlightState( VMatrix &worldToTexture ) const = 0; + virtual bool InEditorMode() const = 0; + + // Gets the bound morph's vertex format; returns 0 if no morph is bound + virtual MorphFormat_t GetBoundMorphFormat() = 0; + + // Binds a standard texture + virtual void BindStandardTexture( Sampler_t sampler, StandardTextureId_t id ) = 0; + + virtual ITexture *GetRenderTargetEx( int nRenderTargetID ) = 0; + + virtual void SetToneMappingScaleLinear( const Vector &scale ) = 0; + virtual const Vector &GetToneMappingScaleLinear( void ) const = 0; + virtual float GetLightMapScaleFactor( void ) const = 0; + + virtual void LoadBoneMatrix( int boneIndex, const float *m ) = 0; + + virtual void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right ) = 0; + + virtual void SetFloatRenderingParameter(int parm_number, float value) = 0; + + virtual void SetIntRenderingParameter(int parm_number, int value) = 0 ; + virtual void SetVectorRenderingParameter(int parm_number, Vector const &value) = 0 ; + + virtual float GetFloatRenderingParameter(int parm_number) const = 0 ; + + virtual int GetIntRenderingParameter(int parm_number) const = 0 ; + + virtual Vector GetVectorRenderingParameter(int parm_number) const = 0 ; + + // stencil buffer operations. + virtual void SetStencilEnable(bool onoff) = 0; + virtual void SetStencilFailOperation(StencilOperation_t op) = 0; + virtual void SetStencilZFailOperation(StencilOperation_t op) = 0; + virtual void SetStencilPassOperation(StencilOperation_t op) = 0; + virtual void SetStencilCompareFunction(StencilComparisonFunction_t cmpfn) = 0; + virtual void SetStencilReferenceValue(int ref) = 0; + virtual void SetStencilTestMask(uint32 msk) = 0; + virtual void SetStencilWriteMask(uint32 msk) = 0; + virtual void ClearStencilBufferRectangle( int xmin, int ymin, int xmax, int ymax,int value) = 0; + + virtual void GetDXLevelDefaults(uint &max_dxlevel,uint &recommended_dxlevel) = 0; + + virtual const FlashlightState_t &GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **pFlashlightDepthTexture ) const = 0; + + virtual float GetAmbientLightCubeLuminance() = 0; + + virtual void GetDX9LightState( LightState_t *state ) const = 0; + virtual int GetPixelFogCombo( ) = 0; //0 is either range fog, or no fog simulated with rigged range fog values. 1 is height fog + + virtual void BindStandardVertexTexture( VertexTextureSampler_t sampler, StandardTextureId_t id ) = 0; + + // Is hardware morphing enabled? + virtual bool IsHWMorphingEnabled( ) const = 0; + + virtual void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id ) = 0; + + virtual void SetBooleanVertexShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false ) = 0; + virtual void SetIntegerVertexShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false ) = 0; + virtual void SetBooleanPixelShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false ) = 0; + virtual void SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false ) = 0; + + //Are we in a configuration that needs access to depth data through the alpha channel later? + virtual bool ShouldWriteDepthToDestAlpha( void ) const = 0; + + + // deformations + virtual void PushDeformation( DeformationBase_t const *Deformation ) = 0; + virtual void PopDeformation( ) = 0; + virtual int GetNumActiveDeformations() const =0; + + + // for shaders to set vertex shader constants. returns a packed state which can be used to set + // the dynamic combo. returns # of active deformations + virtual int GetPackedDeformationInformation( int nMaskOfUnderstoodDeformations, + float *pConstantValuesOut, + int nBufferSize, + int nMaximumDeformations, + int *pNumDefsOut ) const = 0; + + // This lets the lower level system that certain vertex fields requested + // in the shadow state aren't actually being read given particular state + // known only at dynamic state time. It's here only to silence warnings. + virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords ) = 0; + + + virtual void ExecuteCommandBuffer( uint8 *pCmdBuffer ) =0; + + // interface for mat system to tell shaderapi about standard texture handles + virtual void SetStandardTextureHandle( StandardTextureId_t nId, ShaderAPITextureHandle_t nHandle ) =0; + + // Interface for mat system to tell shaderapi about color correction + virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo ) = 0; + + virtual void SetPSNearAndFarZ( int pshReg ) = 0; + + virtual void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) = 0; +}; +// end class IShaderDynamicAPI + +//----------------------------------------------------------------------------- +// Software vertex shaders +//----------------------------------------------------------------------------- +typedef void (*SoftwareVertexShader_t)( CMeshBuilder& meshBuilder, IMaterialVar **params, IShaderDynamicAPI *pShaderAPI ); + + +#endif // ISHADERDYNAMIC_H diff --git a/sp/src/public/shaderapi/ishadershadow.h b/sp/src/public/shaderapi/ishadershadow.h index 2048cc08..170988f7 100644 --- a/sp/src/public/shaderapi/ishadershadow.h +++ b/sp/src/public/shaderapi/ishadershadow.h @@ -1,368 +1,368 @@ -//========= Copyright Valve Corporation, All rights reserved. ============//
-//
-// Purpose:
-//
-// $NoKeywords: $
-//
-//===========================================================================//
-
-#ifndef ISHADERSHADOW_H
-#define ISHADERSHADOW_H
-
-#ifdef _WIN32
-#pragma once
-#endif
-
-#include "shaderapi/shareddefs.h"
-#include <materialsystem/imaterial.h>
-
-
-//-----------------------------------------------------------------------------
-// forward declarations
-//-----------------------------------------------------------------------------
-class CMeshBuilder;
-class IMaterialVar;
-struct LightDesc_t;
-
-
-//-----------------------------------------------------------------------------
-// important enumerations
-//-----------------------------------------------------------------------------
-enum ShaderDepthFunc_t
-{
- SHADER_DEPTHFUNC_NEVER,
- SHADER_DEPTHFUNC_NEARER,
- SHADER_DEPTHFUNC_EQUAL,
- SHADER_DEPTHFUNC_NEAREROREQUAL,
- SHADER_DEPTHFUNC_FARTHER,
- SHADER_DEPTHFUNC_NOTEQUAL,
- SHADER_DEPTHFUNC_FARTHEROREQUAL,
- SHADER_DEPTHFUNC_ALWAYS
-};
-
-enum ShaderBlendFactor_t
-{
- SHADER_BLEND_ZERO,
- SHADER_BLEND_ONE,
- SHADER_BLEND_DST_COLOR,
- SHADER_BLEND_ONE_MINUS_DST_COLOR,
- SHADER_BLEND_SRC_ALPHA,
- SHADER_BLEND_ONE_MINUS_SRC_ALPHA,
- SHADER_BLEND_DST_ALPHA,
- SHADER_BLEND_ONE_MINUS_DST_ALPHA,
- SHADER_BLEND_SRC_ALPHA_SATURATE,
- SHADER_BLEND_SRC_COLOR,
- SHADER_BLEND_ONE_MINUS_SRC_COLOR
-};
-
-enum ShaderBlendOp_t
-{
- SHADER_BLEND_OP_ADD,
- SHADER_BLEND_OP_SUBTRACT,
- SHADER_BLEND_OP_REVSUBTRACT,
- SHADER_BLEND_OP_MIN,
- SHADER_BLEND_OP_MAX
-};
-
-enum ShaderAlphaFunc_t
-{
- SHADER_ALPHAFUNC_NEVER,
- SHADER_ALPHAFUNC_LESS,
- SHADER_ALPHAFUNC_EQUAL,
- SHADER_ALPHAFUNC_LEQUAL,
- SHADER_ALPHAFUNC_GREATER,
- SHADER_ALPHAFUNC_NOTEQUAL,
- SHADER_ALPHAFUNC_GEQUAL,
- SHADER_ALPHAFUNC_ALWAYS
-};
-
-enum ShaderStencilFunc_t
-{
- SHADER_STENCILFUNC_NEVER = 0,
- SHADER_STENCILFUNC_LESS,
- SHADER_STENCILFUNC_EQUAL,
- SHADER_STENCILFUNC_LEQUAL,
- SHADER_STENCILFUNC_GREATER,
- SHADER_STENCILFUNC_NOTEQUAL,
- SHADER_STENCILFUNC_GEQUAL,
- SHADER_STENCILFUNC_ALWAYS
-};
-
-enum ShaderStencilOp_t
-{
- SHADER_STENCILOP_KEEP = 0,
- SHADER_STENCILOP_ZERO,
- SHADER_STENCILOP_SET_TO_REFERENCE,
- SHADER_STENCILOP_INCREMENT_CLAMP,
- SHADER_STENCILOP_DECREMENT_CLAMP,
- SHADER_STENCILOP_INVERT,
- SHADER_STENCILOP_INCREMENT_WRAP,
- SHADER_STENCILOP_DECREMENT_WRAP,
-};
-
-enum ShaderTexChannel_t
-{
- SHADER_TEXCHANNEL_COLOR = 0,
- SHADER_TEXCHANNEL_ALPHA
-};
-
-enum ShaderPolyModeFace_t
-{
- SHADER_POLYMODEFACE_FRONT,
- SHADER_POLYMODEFACE_BACK,
- SHADER_POLYMODEFACE_FRONT_AND_BACK,
-};
-
-enum ShaderPolyMode_t
-{
- SHADER_POLYMODE_POINT,
- SHADER_POLYMODE_LINE,
- SHADER_POLYMODE_FILL
-};
-
-enum ShaderTexArg_t
-{
- SHADER_TEXARG_TEXTURE = 0,
- SHADER_TEXARG_VERTEXCOLOR,
- SHADER_TEXARG_SPECULARCOLOR,
- SHADER_TEXARG_CONSTANTCOLOR,
- SHADER_TEXARG_PREVIOUSSTAGE,
- SHADER_TEXARG_NONE,
- SHADER_TEXARG_ZERO,
- SHADER_TEXARG_TEXTUREALPHA,
- SHADER_TEXARG_INVTEXTUREALPHA,
- SHADER_TEXARG_ONE,
-};
-
-enum ShaderTexOp_t
-{
- // DX5 shaders support these
- SHADER_TEXOP_MODULATE = 0,
- SHADER_TEXOP_MODULATE2X,
- SHADER_TEXOP_MODULATE4X,
- SHADER_TEXOP_SELECTARG1,
- SHADER_TEXOP_SELECTARG2,
- SHADER_TEXOP_DISABLE,
-
- // DX6 shaders support these
- SHADER_TEXOP_ADD,
- SHADER_TEXOP_SUBTRACT,
- SHADER_TEXOP_ADDSIGNED2X,
- SHADER_TEXOP_BLEND_CONSTANTALPHA,
- SHADER_TEXOP_BLEND_TEXTUREALPHA,
- SHADER_TEXOP_BLEND_PREVIOUSSTAGEALPHA,
- SHADER_TEXOP_MODULATECOLOR_ADDALPHA,
- SHADER_TEXOP_MODULATEINVCOLOR_ADDALPHA,
-
- // DX7
- SHADER_TEXOP_DOTPRODUCT3
-};
-
-enum ShaderTexGenParam_t
-{
- SHADER_TEXGENPARAM_OBJECT_LINEAR,
- SHADER_TEXGENPARAM_EYE_LINEAR,
- SHADER_TEXGENPARAM_SPHERE_MAP,
- SHADER_TEXGENPARAM_CAMERASPACEREFLECTIONVECTOR,
- SHADER_TEXGENPARAM_CAMERASPACENORMAL
-};
-
-enum ShaderDrawBitField_t
-{
- SHADER_DRAW_POSITION = 0x0001,
- SHADER_DRAW_NORMAL = 0x0002,
- SHADER_DRAW_COLOR = 0x0004,
- SHADER_DRAW_SPECULAR = 0x0008,
-
- SHADER_DRAW_TEXCOORD0 = 0x0010,
- SHADER_DRAW_TEXCOORD1 = 0x0020,
- SHADER_DRAW_TEXCOORD2 = 0x0040,
- SHADER_DRAW_TEXCOORD3 = 0x0080,
-
- SHADER_DRAW_LIGHTMAP_TEXCOORD0 = 0x0100,
- SHADER_DRAW_LIGHTMAP_TEXCOORD1 = 0x0200,
- SHADER_DRAW_LIGHTMAP_TEXCOORD2 = 0x0400,
- SHADER_DRAW_LIGHTMAP_TEXCOORD3 = 0x0800,
-
- SHADER_DRAW_SECONDARY_TEXCOORD0 = 0x1000,
- SHADER_DRAW_SECONDARY_TEXCOORD1 = 0x2000,
- SHADER_DRAW_SECONDARY_TEXCOORD2 = 0x4000,
- SHADER_DRAW_SECONDARY_TEXCOORD3 = 0x8000,
-
- SHADER_TEXCOORD_MASK = SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_TEXCOORD1 |
- SHADER_DRAW_TEXCOORD2 | SHADER_DRAW_TEXCOORD3,
-
- SHADER_LIGHTMAP_TEXCOORD_MASK = SHADER_DRAW_LIGHTMAP_TEXCOORD0 |
- SHADER_DRAW_LIGHTMAP_TEXCOORD1 |
- SHADER_DRAW_LIGHTMAP_TEXCOORD2 |
- SHADER_DRAW_LIGHTMAP_TEXCOORD3,
-
- SHADER_SECONDARY_TEXCOORD_MASK = SHADER_DRAW_SECONDARY_TEXCOORD0 |
- SHADER_DRAW_SECONDARY_TEXCOORD1 |
- SHADER_DRAW_SECONDARY_TEXCOORD2 |
- SHADER_DRAW_SECONDARY_TEXCOORD3,
-};
-
-
-enum ShaderFogMode_t
-{
- SHADER_FOGMODE_DISABLED = 0,
- SHADER_FOGMODE_OO_OVERBRIGHT,
- SHADER_FOGMODE_BLACK,
- SHADER_FOGMODE_GREY,
- SHADER_FOGMODE_FOGCOLOR,
- SHADER_FOGMODE_WHITE,
- SHADER_FOGMODE_NUMFOGMODES
-};
-
-enum ShaderMaterialSource_t
-{
- SHADER_MATERIALSOURCE_MATERIAL = 0,
- SHADER_MATERIALSOURCE_COLOR1,
- SHADER_MATERIALSOURCE_COLOR2,
-};
-
-
-// m_ZBias has only two bits in ShadowState_t, so be careful extending this enum
-enum PolygonOffsetMode_t
-{
- SHADER_POLYOFFSET_DISABLE = 0x0,
- SHADER_POLYOFFSET_DECAL = 0x1,
- SHADER_POLYOFFSET_SHADOW_BIAS = 0x2,
- SHADER_POLYOFFSET_RESERVED = 0x3 // Reserved for future use
-};
-
-
-//-----------------------------------------------------------------------------
-// The Shader interface versions
-//-----------------------------------------------------------------------------
-#define SHADERSHADOW_INTERFACE_VERSION "ShaderShadow010"
-
-
-//-----------------------------------------------------------------------------
-// the shader API interface (methods called from shaders)
-//-----------------------------------------------------------------------------
-abstract_class IShaderShadow
-{
-public:
- // Sets the default *shadow* state
- virtual void SetDefaultState() = 0;
-
- // Methods related to depth buffering
- virtual void DepthFunc( ShaderDepthFunc_t depthFunc ) = 0;
- virtual void EnableDepthWrites( bool bEnable ) = 0;
- virtual void EnableDepthTest( bool bEnable ) = 0;
- virtual void EnablePolyOffset( PolygonOffsetMode_t nOffsetMode ) = 0;
-
- // These methods for controlling stencil are obsolete and stubbed to do nothing. Stencil
- // control is via the shaderapi/material system now, not part of the shadow state.
- // Methods related to stencil
- virtual void EnableStencil( bool bEnable ) = 0;
- virtual void StencilFunc( ShaderStencilFunc_t stencilFunc ) = 0;
- virtual void StencilPassOp( ShaderStencilOp_t stencilOp ) = 0;
- virtual void StencilFailOp( ShaderStencilOp_t stencilOp ) = 0;
- virtual void StencilDepthFailOp( ShaderStencilOp_t stencilOp ) = 0;
- virtual void StencilReference( int nReference ) = 0;
- virtual void StencilMask( int nMask ) = 0;
- virtual void StencilWriteMask( int nMask ) = 0;
-
- // Suppresses/activates color writing
- virtual void EnableColorWrites( bool bEnable ) = 0;
- virtual void EnableAlphaWrites( bool bEnable ) = 0;
-
- // Methods related to alpha blending
- virtual void EnableBlending( bool bEnable ) = 0;
- virtual void BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ) = 0;
- // More below...
-
- // Alpha testing
- virtual void EnableAlphaTest( bool bEnable ) = 0;
- virtual void AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ ) = 0;
-
- // Wireframe/filled polygons
- virtual void PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode ) = 0;
-
- // Back face culling
- virtual void EnableCulling( bool bEnable ) = 0;
-
- // constant color + transparency
- virtual void EnableConstantColor( bool bEnable ) = 0;
-
- // 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
- virtual void VertexShaderVertexFormat( unsigned int nFlags,
- int nTexCoordCount, int* pTexCoordDimensions, int nUserDataSize ) = 0;
-
- // Pixel and vertex shader methods
- virtual void SetVertexShader( const char* pFileName, int nStaticVshIndex ) = 0;
- virtual void SetPixelShader( const char* pFileName, int nStaticPshIndex = 0 ) = 0;
-
- // Indicates we're going to light the model
- virtual void EnableLighting( bool bEnable ) = 0;
-
- // Enables specular lighting (lighting has also got to be enabled)
- virtual void EnableSpecular( bool bEnable ) = 0;
-
- // Convert from linear to gamma color space on writes to frame buffer.
- virtual void EnableSRGBWrite( bool bEnable ) = 0;
-
- // Convert from gamma to linear on texture fetch.
- virtual void EnableSRGBRead( Sampler_t sampler, bool bEnable ) = 0;
-
- // Activate/deactivate skinning. Indexed blending is automatically
- // enabled if it's available for this hardware. When blending is enabled,
- // we allocate enough room for 3 weights (max allowed)
- virtual void EnableVertexBlend( bool bEnable ) = 0;
-
- // per texture unit stuff
- virtual void OverbrightValue( TextureStage_t stage, float value ) = 0;
- virtual void EnableTexture( Sampler_t sampler, bool bEnable ) = 0;
- virtual void EnableTexGen( TextureStage_t stage, bool bEnable ) = 0;
- virtual void TexGen( TextureStage_t stage, ShaderTexGenParam_t param ) = 0;
-
- // alternate method of specifying per-texture unit stuff, more flexible and more complicated
- // Can be used to specify different operation per channel (alpha/color)...
- virtual void EnableCustomPixelPipe( bool bEnable ) = 0;
- virtual void CustomTextureStages( int stageCount ) = 0;
- virtual void CustomTextureOperation( TextureStage_t stage, ShaderTexChannel_t channel,
- ShaderTexOp_t op, ShaderTexArg_t arg1, ShaderTexArg_t arg2 ) = 0;
-
- // indicates what per-vertex data we're providing
- virtual void DrawFlags( unsigned int drawFlags ) = 0;
-
- // A simpler method of dealing with alpha modulation
- virtual void EnableAlphaPipe( bool bEnable ) = 0;
- virtual void EnableConstantAlpha( bool bEnable ) = 0;
- virtual void EnableVertexAlpha( bool bEnable ) = 0;
- virtual void EnableTextureAlpha( TextureStage_t stage, bool bEnable ) = 0;
-
- // GR - Separate alpha blending
- virtual void EnableBlendingSeparateAlpha( bool bEnable ) = 0;
- virtual void BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ) = 0;
- virtual void FogMode( ShaderFogMode_t fogMode ) = 0;
-
- virtual void SetDiffuseMaterialSource( ShaderMaterialSource_t materialSource ) = 0;
-
- // Indicates the morph format for use with a vertex shader
- // The flags to pass in here come from the MorphFormatFlags_t enum
- virtual void SetMorphFormat( MorphFormat_t flags ) = 0;
-
- virtual void DisableFogGammaCorrection( bool bDisable ) = 0; //some blending modes won't work properly with corrected fog
-
- // Alpha to coverage
- virtual void EnableAlphaToCoverage( bool bEnable ) = 0;
-
- // Shadow map filtering
- virtual void SetShadowDepthFiltering( Sampler_t stage ) = 0;
-
- // More alpha blending state
- virtual void BlendOp( ShaderBlendOp_t blendOp ) = 0;
- virtual void BlendOpSeparateAlpha( ShaderBlendOp_t blendOp ) = 0;
-};
-// end class IShaderShadow
-
-
-
-#endif // ISHADERSHADOW_H
+//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef ISHADERSHADOW_H +#define ISHADERSHADOW_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "shaderapi/shareddefs.h" +#include <materialsystem/imaterial.h> + + +//----------------------------------------------------------------------------- +// forward declarations +//----------------------------------------------------------------------------- +class CMeshBuilder; +class IMaterialVar; +struct LightDesc_t; + + +//----------------------------------------------------------------------------- +// important enumerations +//----------------------------------------------------------------------------- +enum ShaderDepthFunc_t +{ + SHADER_DEPTHFUNC_NEVER, + SHADER_DEPTHFUNC_NEARER, + SHADER_DEPTHFUNC_EQUAL, + SHADER_DEPTHFUNC_NEAREROREQUAL, + SHADER_DEPTHFUNC_FARTHER, + SHADER_DEPTHFUNC_NOTEQUAL, + SHADER_DEPTHFUNC_FARTHEROREQUAL, + SHADER_DEPTHFUNC_ALWAYS +}; + +enum ShaderBlendFactor_t +{ + SHADER_BLEND_ZERO, + SHADER_BLEND_ONE, + SHADER_BLEND_DST_COLOR, + SHADER_BLEND_ONE_MINUS_DST_COLOR, + SHADER_BLEND_SRC_ALPHA, + SHADER_BLEND_ONE_MINUS_SRC_ALPHA, + SHADER_BLEND_DST_ALPHA, + SHADER_BLEND_ONE_MINUS_DST_ALPHA, + SHADER_BLEND_SRC_ALPHA_SATURATE, + SHADER_BLEND_SRC_COLOR, + SHADER_BLEND_ONE_MINUS_SRC_COLOR +}; + +enum ShaderBlendOp_t +{ + SHADER_BLEND_OP_ADD, + SHADER_BLEND_OP_SUBTRACT, + SHADER_BLEND_OP_REVSUBTRACT, + SHADER_BLEND_OP_MIN, + SHADER_BLEND_OP_MAX +}; + +enum ShaderAlphaFunc_t +{ + SHADER_ALPHAFUNC_NEVER, + SHADER_ALPHAFUNC_LESS, + SHADER_ALPHAFUNC_EQUAL, + SHADER_ALPHAFUNC_LEQUAL, + SHADER_ALPHAFUNC_GREATER, + SHADER_ALPHAFUNC_NOTEQUAL, + SHADER_ALPHAFUNC_GEQUAL, + SHADER_ALPHAFUNC_ALWAYS +}; + +enum ShaderStencilFunc_t +{ + SHADER_STENCILFUNC_NEVER = 0, + SHADER_STENCILFUNC_LESS, + SHADER_STENCILFUNC_EQUAL, + SHADER_STENCILFUNC_LEQUAL, + SHADER_STENCILFUNC_GREATER, + SHADER_STENCILFUNC_NOTEQUAL, + SHADER_STENCILFUNC_GEQUAL, + SHADER_STENCILFUNC_ALWAYS +}; + +enum ShaderStencilOp_t +{ + SHADER_STENCILOP_KEEP = 0, + SHADER_STENCILOP_ZERO, + SHADER_STENCILOP_SET_TO_REFERENCE, + SHADER_STENCILOP_INCREMENT_CLAMP, + SHADER_STENCILOP_DECREMENT_CLAMP, + SHADER_STENCILOP_INVERT, + SHADER_STENCILOP_INCREMENT_WRAP, + SHADER_STENCILOP_DECREMENT_WRAP, +}; + +enum ShaderTexChannel_t +{ + SHADER_TEXCHANNEL_COLOR = 0, + SHADER_TEXCHANNEL_ALPHA +}; + +enum ShaderPolyModeFace_t +{ + SHADER_POLYMODEFACE_FRONT, + SHADER_POLYMODEFACE_BACK, + SHADER_POLYMODEFACE_FRONT_AND_BACK, +}; + +enum ShaderPolyMode_t +{ + SHADER_POLYMODE_POINT, + SHADER_POLYMODE_LINE, + SHADER_POLYMODE_FILL +}; + +enum ShaderTexArg_t +{ + SHADER_TEXARG_TEXTURE = 0, + SHADER_TEXARG_VERTEXCOLOR, + SHADER_TEXARG_SPECULARCOLOR, + SHADER_TEXARG_CONSTANTCOLOR, + SHADER_TEXARG_PREVIOUSSTAGE, + SHADER_TEXARG_NONE, + SHADER_TEXARG_ZERO, + SHADER_TEXARG_TEXTUREALPHA, + SHADER_TEXARG_INVTEXTUREALPHA, + SHADER_TEXARG_ONE, +}; + +enum ShaderTexOp_t +{ + // DX5 shaders support these + SHADER_TEXOP_MODULATE = 0, + SHADER_TEXOP_MODULATE2X, + SHADER_TEXOP_MODULATE4X, + SHADER_TEXOP_SELECTARG1, + SHADER_TEXOP_SELECTARG2, + SHADER_TEXOP_DISABLE, + + // DX6 shaders support these + SHADER_TEXOP_ADD, + SHADER_TEXOP_SUBTRACT, + SHADER_TEXOP_ADDSIGNED2X, + SHADER_TEXOP_BLEND_CONSTANTALPHA, + SHADER_TEXOP_BLEND_TEXTUREALPHA, + SHADER_TEXOP_BLEND_PREVIOUSSTAGEALPHA, + SHADER_TEXOP_MODULATECOLOR_ADDALPHA, + SHADER_TEXOP_MODULATEINVCOLOR_ADDALPHA, + + // DX7 + SHADER_TEXOP_DOTPRODUCT3 +}; + +enum ShaderTexGenParam_t +{ + SHADER_TEXGENPARAM_OBJECT_LINEAR, + SHADER_TEXGENPARAM_EYE_LINEAR, + SHADER_TEXGENPARAM_SPHERE_MAP, + SHADER_TEXGENPARAM_CAMERASPACEREFLECTIONVECTOR, + SHADER_TEXGENPARAM_CAMERASPACENORMAL +}; + +enum ShaderDrawBitField_t +{ + SHADER_DRAW_POSITION = 0x0001, + SHADER_DRAW_NORMAL = 0x0002, + SHADER_DRAW_COLOR = 0x0004, + SHADER_DRAW_SPECULAR = 0x0008, + + SHADER_DRAW_TEXCOORD0 = 0x0010, + SHADER_DRAW_TEXCOORD1 = 0x0020, + SHADER_DRAW_TEXCOORD2 = 0x0040, + SHADER_DRAW_TEXCOORD3 = 0x0080, + + SHADER_DRAW_LIGHTMAP_TEXCOORD0 = 0x0100, + SHADER_DRAW_LIGHTMAP_TEXCOORD1 = 0x0200, + SHADER_DRAW_LIGHTMAP_TEXCOORD2 = 0x0400, + SHADER_DRAW_LIGHTMAP_TEXCOORD3 = 0x0800, + + SHADER_DRAW_SECONDARY_TEXCOORD0 = 0x1000, + SHADER_DRAW_SECONDARY_TEXCOORD1 = 0x2000, + SHADER_DRAW_SECONDARY_TEXCOORD2 = 0x4000, + SHADER_DRAW_SECONDARY_TEXCOORD3 = 0x8000, + + SHADER_TEXCOORD_MASK = SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_TEXCOORD1 | + SHADER_DRAW_TEXCOORD2 | SHADER_DRAW_TEXCOORD3, + + SHADER_LIGHTMAP_TEXCOORD_MASK = SHADER_DRAW_LIGHTMAP_TEXCOORD0 | + SHADER_DRAW_LIGHTMAP_TEXCOORD1 | + SHADER_DRAW_LIGHTMAP_TEXCOORD2 | + SHADER_DRAW_LIGHTMAP_TEXCOORD3, + + SHADER_SECONDARY_TEXCOORD_MASK = SHADER_DRAW_SECONDARY_TEXCOORD0 | + SHADER_DRAW_SECONDARY_TEXCOORD1 | + SHADER_DRAW_SECONDARY_TEXCOORD2 | + SHADER_DRAW_SECONDARY_TEXCOORD3, +}; + + +enum ShaderFogMode_t +{ + SHADER_FOGMODE_DISABLED = 0, + SHADER_FOGMODE_OO_OVERBRIGHT, + SHADER_FOGMODE_BLACK, + SHADER_FOGMODE_GREY, + SHADER_FOGMODE_FOGCOLOR, + SHADER_FOGMODE_WHITE, + SHADER_FOGMODE_NUMFOGMODES +}; + +enum ShaderMaterialSource_t +{ + SHADER_MATERIALSOURCE_MATERIAL = 0, + SHADER_MATERIALSOURCE_COLOR1, + SHADER_MATERIALSOURCE_COLOR2, +}; + + +// m_ZBias has only two bits in ShadowState_t, so be careful extending this enum +enum PolygonOffsetMode_t +{ + SHADER_POLYOFFSET_DISABLE = 0x0, + SHADER_POLYOFFSET_DECAL = 0x1, + SHADER_POLYOFFSET_SHADOW_BIAS = 0x2, + SHADER_POLYOFFSET_RESERVED = 0x3 // Reserved for future use +}; + + +//----------------------------------------------------------------------------- +// The Shader interface versions +//----------------------------------------------------------------------------- +#define SHADERSHADOW_INTERFACE_VERSION "ShaderShadow010" + + +//----------------------------------------------------------------------------- +// the shader API interface (methods called from shaders) +//----------------------------------------------------------------------------- +abstract_class IShaderShadow +{ +public: + // Sets the default *shadow* state + virtual void SetDefaultState() = 0; + + // Methods related to depth buffering + virtual void DepthFunc( ShaderDepthFunc_t depthFunc ) = 0; + virtual void EnableDepthWrites( bool bEnable ) = 0; + virtual void EnableDepthTest( bool bEnable ) = 0; + virtual void EnablePolyOffset( PolygonOffsetMode_t nOffsetMode ) = 0; + + // These methods for controlling stencil are obsolete and stubbed to do nothing. Stencil + // control is via the shaderapi/material system now, not part of the shadow state. + // Methods related to stencil + virtual void EnableStencil( bool bEnable ) = 0; + virtual void StencilFunc( ShaderStencilFunc_t stencilFunc ) = 0; + virtual void StencilPassOp( ShaderStencilOp_t stencilOp ) = 0; + virtual void StencilFailOp( ShaderStencilOp_t stencilOp ) = 0; + virtual void StencilDepthFailOp( ShaderStencilOp_t stencilOp ) = 0; + virtual void StencilReference( int nReference ) = 0; + virtual void StencilMask( int nMask ) = 0; + virtual void StencilWriteMask( int nMask ) = 0; + + // Suppresses/activates color writing + virtual void EnableColorWrites( bool bEnable ) = 0; + virtual void EnableAlphaWrites( bool bEnable ) = 0; + + // Methods related to alpha blending + virtual void EnableBlending( bool bEnable ) = 0; + virtual void BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ) = 0; + // More below... + + // Alpha testing + virtual void EnableAlphaTest( bool bEnable ) = 0; + virtual void AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ ) = 0; + + // Wireframe/filled polygons + virtual void PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode ) = 0; + + // Back face culling + virtual void EnableCulling( bool bEnable ) = 0; + + // constant color + transparency + virtual void EnableConstantColor( bool bEnable ) = 0; + + // 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 + virtual void VertexShaderVertexFormat( unsigned int nFlags, + int nTexCoordCount, int* pTexCoordDimensions, int nUserDataSize ) = 0; + + // Pixel and vertex shader methods + virtual void SetVertexShader( const char* pFileName, int nStaticVshIndex ) = 0; + virtual void SetPixelShader( const char* pFileName, int nStaticPshIndex = 0 ) = 0; + + // Indicates we're going to light the model + virtual void EnableLighting( bool bEnable ) = 0; + + // Enables specular lighting (lighting has also got to be enabled) + virtual void EnableSpecular( bool bEnable ) = 0; + + // Convert from linear to gamma color space on writes to frame buffer. + virtual void EnableSRGBWrite( bool bEnable ) = 0; + + // Convert from gamma to linear on texture fetch. + virtual void EnableSRGBRead( Sampler_t sampler, bool bEnable ) = 0; + + // Activate/deactivate skinning. Indexed blending is automatically + // enabled if it's available for this hardware. When blending is enabled, + // we allocate enough room for 3 weights (max allowed) + virtual void EnableVertexBlend( bool bEnable ) = 0; + + // per texture unit stuff + virtual void OverbrightValue( TextureStage_t stage, float value ) = 0; + virtual void EnableTexture( Sampler_t sampler, bool bEnable ) = 0; + virtual void EnableTexGen( TextureStage_t stage, bool bEnable ) = 0; + virtual void TexGen( TextureStage_t stage, ShaderTexGenParam_t param ) = 0; + + // alternate method of specifying per-texture unit stuff, more flexible and more complicated + // Can be used to specify different operation per channel (alpha/color)... + virtual void EnableCustomPixelPipe( bool bEnable ) = 0; + virtual void CustomTextureStages( int stageCount ) = 0; + virtual void CustomTextureOperation( TextureStage_t stage, ShaderTexChannel_t channel, + ShaderTexOp_t op, ShaderTexArg_t arg1, ShaderTexArg_t arg2 ) = 0; + + // indicates what per-vertex data we're providing + virtual void DrawFlags( unsigned int drawFlags ) = 0; + + // A simpler method of dealing with alpha modulation + virtual void EnableAlphaPipe( bool bEnable ) = 0; + virtual void EnableConstantAlpha( bool bEnable ) = 0; + virtual void EnableVertexAlpha( bool bEnable ) = 0; + virtual void EnableTextureAlpha( TextureStage_t stage, bool bEnable ) = 0; + + // GR - Separate alpha blending + virtual void EnableBlendingSeparateAlpha( bool bEnable ) = 0; + virtual void BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ) = 0; + virtual void FogMode( ShaderFogMode_t fogMode ) = 0; + + virtual void SetDiffuseMaterialSource( ShaderMaterialSource_t materialSource ) = 0; + + // Indicates the morph format for use with a vertex shader + // The flags to pass in here come from the MorphFormatFlags_t enum + virtual void SetMorphFormat( MorphFormat_t flags ) = 0; + + virtual void DisableFogGammaCorrection( bool bDisable ) = 0; //some blending modes won't work properly with corrected fog + + // Alpha to coverage + virtual void EnableAlphaToCoverage( bool bEnable ) = 0; + + // Shadow map filtering + virtual void SetShadowDepthFiltering( Sampler_t stage ) = 0; + + // More alpha blending state + virtual void BlendOp( ShaderBlendOp_t blendOp ) = 0; + virtual void BlendOpSeparateAlpha( ShaderBlendOp_t blendOp ) = 0; +}; +// end class IShaderShadow + + + +#endif // ISHADERSHADOW_H diff --git a/sp/src/public/shaderapi/ishaderutil.h b/sp/src/public/shaderapi/ishaderutil.h index 8a0090ba..5fe01995 100644 --- a/sp/src/public/shaderapi/ishaderutil.h +++ b/sp/src/public/shaderapi/ishaderutil.h @@ -1,131 +1,131 @@ -//========= Copyright Valve Corporation, All rights reserved. ============//
-//
-// Purpose:
-//
-// $NoKeywords: $
-//
-//===========================================================================//
-
-#ifndef ISHADERUTIL_H
-#define ISHADERUTIL_H
-
-#ifdef _WIN32
-#pragma once
-#endif
-
-
-#include "materialsystem/imaterial.h"
-#include "appframework/IAppSystem.h"
-#include "shaderapi/ishaderapi.h"
-
-
-//-----------------------------------------------------------------------------
-// forward declarations
-//-----------------------------------------------------------------------------
-class ITexture;
-struct MaterialSystem_Config_t;
-struct ImageFormatInfo_t;
-enum Sampler_t;
-enum VertexTextureSampler_t;
-enum StandardTextureId_t;
-class CPrimList;
-struct ShaderColorCorrectionInfo_t;
-
-#define SHADER_UTIL_INTERFACE_VERSION "VShaderUtil001"
-
-enum shaderthreadevent_t
-{
- SHADER_THREAD_RELEASE_RESOURCES = 1,
- SHADER_THREAD_ACQUIRE_RESOURCES = 2,
- SHADER_THREAD_DEVICE_LOST = 3,
- SHADER_THREAD_EVICT_RESOURCES = 4,
- SHADER_THREAD_OTHER_APP_START = 5,
- SHADER_THREAD_OTHER_APP_END = 6,
- SHADER_THREAD_RESET_RENDER_STATE = 7,
-};
-
-abstract_class IShaderUtil : public IAppSystem
-{
-public:
- // Method to allow clients access to the MaterialSystem_Config
- virtual MaterialSystem_Config_t& GetConfig() = 0;
-
- // Allows us to convert image formats
- virtual bool ConvertImageFormat( unsigned char *src, enum ImageFormat srcImageFormat,
- unsigned char *dst, enum ImageFormat dstImageFormat,
- int width, int height, int srcStride = 0, int dstStride = 0 ) = 0;
-
- // Figures out the amount of memory needed by a bitmap
- virtual int GetMemRequired( int width, int height, int depth, ImageFormat format, bool mipmap ) = 0;
-
- // Gets image format info
- virtual const ImageFormatInfo_t& ImageFormatInfo( ImageFormat fmt ) const = 0;
-
- // Bind standard textures
- virtual void BindStandardTexture( Sampler_t sampler, StandardTextureId_t id ) = 0;
-
- // What are the lightmap dimensions?
- virtual void GetLightmapDimensions( int *w, int *h ) = 0;
-
- // These methods are called when the shader must eject + restore HW memory
- virtual void ReleaseShaderObjects() = 0;
- virtual void RestoreShaderObjects( CreateInterfaceFn shaderFactory, int nChangeFlags = 0 ) = 0;
-
- // Used to prevent meshes from drawing.
- virtual bool IsInStubMode() = 0;
- virtual bool InFlashlightMode() const = 0;
-
- // For the shader API to shove the current version of aniso level into the
- // "definitive" place (g_config) when the shader API decides to change it.
- // Eventually, we should have a better system of who owns the definitive
- // versions of config vars.
- virtual void NoteAnisotropicLevel( int currentLevel ) = 0;
-
- // NOTE: Stuff after this is added after shipping HL2.
-
- // Are we rendering through the editor?
- virtual bool InEditorMode() const = 0;
-
- // Gets the bound morph's vertex format; returns 0 if no morph is bound
- virtual MorphFormat_t GetBoundMorphFormat() = 0;
-
- virtual ITexture *GetRenderTargetEx( int nRenderTargetID ) = 0;
-
- // Tells the material system to draw a buffer clearing quad
- virtual void DrawClearBufferQuad( unsigned char r, unsigned char g, unsigned char b, unsigned char a, bool bClearColor, bool bClearAlpha, bool bClearDepth ) = 0;
-
-#if defined( _X360 )
- virtual void ReadBackBuffer( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *pData, ImageFormat dstFormat, int nDstStride ) = 0;
-#endif
-
- // Calls from meshes to material system to handle queing/threading
- virtual bool OnDrawMesh( IMesh *pMesh, int firstIndex, int numIndices ) = 0;
- virtual bool OnDrawMesh( IMesh *pMesh, CPrimList *pLists, int nLists ) = 0;
- virtual bool OnSetFlexMesh( IMesh *pStaticMesh, IMesh *pMesh, int nVertexOffsetInBytes ) = 0;
- virtual bool OnSetColorMesh( IMesh *pStaticMesh, IMesh *pMesh, int nVertexOffsetInBytes ) = 0;
- virtual bool OnSetPrimitiveType( IMesh *pMesh, MaterialPrimitiveType_t type ) = 0;
- virtual bool OnFlushBufferedPrimitives() = 0;
-
-
- virtual void SyncMatrices() = 0;
- virtual void SyncMatrix( MaterialMatrixMode_t ) = 0;
-
- virtual void BindStandardVertexTexture( VertexTextureSampler_t sampler, StandardTextureId_t id ) = 0;
- virtual void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id ) = 0;
-
- virtual int MaxHWMorphBatchCount() const = 0;
-
- // Interface for mat system to tell shaderapi about color correction
- virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo ) = 0;
- // received an event while not in owning thread, handle this outside
- virtual void OnThreadEvent( uint32 threadEvent ) = 0;
-
- virtual MaterialThreadMode_t GetThreadMode( ) = 0;
- virtual bool IsRenderThreadSafe( ) = 0;
-
- // Remove any materials from memory that aren't in use as determined
- // by the IMaterial's reference count.
- virtual void UncacheUnusedMaterials( bool bRecomputeStateSnapshots = false ) = 0;
-};
-
-#endif // ISHADERUTIL_H
+//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef ISHADERUTIL_H +#define ISHADERUTIL_H + +#ifdef _WIN32 +#pragma once +#endif + + +#include "materialsystem/imaterial.h" +#include "appframework/IAppSystem.h" +#include "shaderapi/ishaderapi.h" + + +//----------------------------------------------------------------------------- +// forward declarations +//----------------------------------------------------------------------------- +class ITexture; +struct MaterialSystem_Config_t; +struct ImageFormatInfo_t; +enum Sampler_t; +enum VertexTextureSampler_t; +enum StandardTextureId_t; +class CPrimList; +struct ShaderColorCorrectionInfo_t; + +#define SHADER_UTIL_INTERFACE_VERSION "VShaderUtil001" + +enum shaderthreadevent_t +{ + SHADER_THREAD_RELEASE_RESOURCES = 1, + SHADER_THREAD_ACQUIRE_RESOURCES = 2, + SHADER_THREAD_DEVICE_LOST = 3, + SHADER_THREAD_EVICT_RESOURCES = 4, + SHADER_THREAD_OTHER_APP_START = 5, + SHADER_THREAD_OTHER_APP_END = 6, + SHADER_THREAD_RESET_RENDER_STATE = 7, +}; + +abstract_class IShaderUtil : public IAppSystem +{ +public: + // Method to allow clients access to the MaterialSystem_Config + virtual MaterialSystem_Config_t& GetConfig() = 0; + + // Allows us to convert image formats + virtual bool ConvertImageFormat( unsigned char *src, enum ImageFormat srcImageFormat, + unsigned char *dst, enum ImageFormat dstImageFormat, + int width, int height, int srcStride = 0, int dstStride = 0 ) = 0; + + // Figures out the amount of memory needed by a bitmap + virtual int GetMemRequired( int width, int height, int depth, ImageFormat format, bool mipmap ) = 0; + + // Gets image format info + virtual const ImageFormatInfo_t& ImageFormatInfo( ImageFormat fmt ) const = 0; + + // Bind standard textures + virtual void BindStandardTexture( Sampler_t sampler, StandardTextureId_t id ) = 0; + + // What are the lightmap dimensions? + virtual void GetLightmapDimensions( int *w, int *h ) = 0; + + // These methods are called when the shader must eject + restore HW memory + virtual void ReleaseShaderObjects() = 0; + virtual void RestoreShaderObjects( CreateInterfaceFn shaderFactory, int nChangeFlags = 0 ) = 0; + + // Used to prevent meshes from drawing. + virtual bool IsInStubMode() = 0; + virtual bool InFlashlightMode() const = 0; + + // For the shader API to shove the current version of aniso level into the + // "definitive" place (g_config) when the shader API decides to change it. + // Eventually, we should have a better system of who owns the definitive + // versions of config vars. + virtual void NoteAnisotropicLevel( int currentLevel ) = 0; + + // NOTE: Stuff after this is added after shipping HL2. + + // Are we rendering through the editor? + virtual bool InEditorMode() const = 0; + + // Gets the bound morph's vertex format; returns 0 if no morph is bound + virtual MorphFormat_t GetBoundMorphFormat() = 0; + + virtual ITexture *GetRenderTargetEx( int nRenderTargetID ) = 0; + + // Tells the material system to draw a buffer clearing quad + virtual void DrawClearBufferQuad( unsigned char r, unsigned char g, unsigned char b, unsigned char a, bool bClearColor, bool bClearAlpha, bool bClearDepth ) = 0; + +#if defined( _X360 ) + virtual void ReadBackBuffer( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *pData, ImageFormat dstFormat, int nDstStride ) = 0; +#endif + + // Calls from meshes to material system to handle queing/threading + virtual bool OnDrawMesh( IMesh *pMesh, int firstIndex, int numIndices ) = 0; + virtual bool OnDrawMesh( IMesh *pMesh, CPrimList *pLists, int nLists ) = 0; + virtual bool OnSetFlexMesh( IMesh *pStaticMesh, IMesh *pMesh, int nVertexOffsetInBytes ) = 0; + virtual bool OnSetColorMesh( IMesh *pStaticMesh, IMesh *pMesh, int nVertexOffsetInBytes ) = 0; + virtual bool OnSetPrimitiveType( IMesh *pMesh, MaterialPrimitiveType_t type ) = 0; + virtual bool OnFlushBufferedPrimitives() = 0; + + + virtual void SyncMatrices() = 0; + virtual void SyncMatrix( MaterialMatrixMode_t ) = 0; + + virtual void BindStandardVertexTexture( VertexTextureSampler_t sampler, StandardTextureId_t id ) = 0; + virtual void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id ) = 0; + + virtual int MaxHWMorphBatchCount() const = 0; + + // Interface for mat system to tell shaderapi about color correction + virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo ) = 0; + // received an event while not in owning thread, handle this outside + virtual void OnThreadEvent( uint32 threadEvent ) = 0; + + virtual MaterialThreadMode_t GetThreadMode( ) = 0; + virtual bool IsRenderThreadSafe( ) = 0; + + // Remove any materials from memory that aren't in use as determined + // by the IMaterial's reference count. + virtual void UncacheUnusedMaterials( bool bRecomputeStateSnapshots = false ) = 0; +}; + +#endif // ISHADERUTIL_H diff --git a/sp/src/public/shaderapi/shareddefs.h b/sp/src/public/shaderapi/shareddefs.h index dec60ed6..663fbfad 100644 --- a/sp/src/public/shaderapi/shareddefs.h +++ b/sp/src/public/shaderapi/shareddefs.h @@ -1,111 +1,111 @@ -//========= Copyright Valve Corporation, All rights reserved. ============//
-//
-// Purpose: NOTE: This file is for backward compat!
-// We'll get rid of it soon. Most of the contents of this file were moved
-// into shaderpi/ishadershadow.h, shaderapi/ishaderdynamic.h, or
-// shaderapi/shareddefs.h
-//
-// $NoKeywords: $
-//
-//===========================================================================//
-
-#ifndef SHADERAPI_SHAREDDEFS_H
-#define SHADERAPI_SHAREDDEFS_H
-
-#ifdef _WIN32
-#pragma once
-#endif
-
-
-//-----------------------------------------------------------------------------
-// Important enumerations
-//-----------------------------------------------------------------------------
-enum ShaderShadeMode_t
-{
- SHADER_FLAT = 0,
- SHADER_SMOOTH
-};
-
-enum ShaderTexCoordComponent_t
-{
- SHADER_TEXCOORD_S = 0,
- SHADER_TEXCOORD_T,
- SHADER_TEXCOORD_U
-};
-
-enum ShaderTexFilterMode_t
-{
- SHADER_TEXFILTERMODE_NEAREST,
- SHADER_TEXFILTERMODE_LINEAR,
- SHADER_TEXFILTERMODE_NEAREST_MIPMAP_NEAREST,
- SHADER_TEXFILTERMODE_LINEAR_MIPMAP_NEAREST,
- SHADER_TEXFILTERMODE_NEAREST_MIPMAP_LINEAR,
- SHADER_TEXFILTERMODE_LINEAR_MIPMAP_LINEAR,
- SHADER_TEXFILTERMODE_ANISOTROPIC
-};
-
-enum ShaderTexWrapMode_t
-{
- SHADER_TEXWRAPMODE_CLAMP,
- SHADER_TEXWRAPMODE_REPEAT,
- SHADER_TEXWRAPMODE_BORDER
- // MIRROR? - probably don't need it.
-};
-
-
-//-----------------------------------------------------------------------------
-// Sampler + texture stage identifiers
-// NOTE: Texture stages are used only by fixed function shading algorithms
-// Samplers are used to enable and bind textures + by programmable shading algorithms
-//-----------------------------------------------------------------------------
-enum TextureStage_t
-{
- SHADER_TEXTURE_STAGE0 = 0,
- SHADER_TEXTURE_STAGE1,
-};
-
-enum Sampler_t
-{
- SHADER_SAMPLER0 = 0,
- SHADER_SAMPLER1,
- SHADER_SAMPLER2,
- SHADER_SAMPLER3,
- SHADER_SAMPLER4,
- SHADER_SAMPLER5,
- SHADER_SAMPLER6,
- SHADER_SAMPLER7,
- SHADER_SAMPLER8,
- SHADER_SAMPLER9,
- SHADER_SAMPLER10,
- SHADER_SAMPLER11,
- SHADER_SAMPLER12,
- SHADER_SAMPLER13,
- SHADER_SAMPLER14,
- SHADER_SAMPLER15,
-};
-
-//-----------------------------------------------------------------------------
-// Vertex texture sampler identifiers
-//-----------------------------------------------------------------------------
-enum VertexTextureSampler_t
-{
- SHADER_VERTEXTEXTURE_SAMPLER0 = 0,
- SHADER_VERTEXTEXTURE_SAMPLER1,
- SHADER_VERTEXTEXTURE_SAMPLER2,
- SHADER_VERTEXTEXTURE_SAMPLER3,
-};
-
-
-#if defined( _X360 )
-#define REVERSE_DEPTH_ON_X360 //uncomment to use D3DFMT_D24FS8 with an inverted depth viewport for better performance. Keep this in sync with the same named #define in materialsystem/stdshaders/common_fxc.h
-#endif
-
-#if defined( REVERSE_DEPTH_ON_X360 )
-#define ReverseDepthOnX360() true
-#else
-#define ReverseDepthOnX360() false
-#endif
-
-
-
-#endif // SHADERAPI_SHAREDDEFS_H
+//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: NOTE: This file is for backward compat! +// We'll get rid of it soon. Most of the contents of this file were moved +// into shaderpi/ishadershadow.h, shaderapi/ishaderdynamic.h, or +// shaderapi/shareddefs.h +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef SHADERAPI_SHAREDDEFS_H +#define SHADERAPI_SHAREDDEFS_H + +#ifdef _WIN32 +#pragma once +#endif + + +//----------------------------------------------------------------------------- +// Important enumerations +//----------------------------------------------------------------------------- +enum ShaderShadeMode_t +{ + SHADER_FLAT = 0, + SHADER_SMOOTH +}; + +enum ShaderTexCoordComponent_t +{ + SHADER_TEXCOORD_S = 0, + SHADER_TEXCOORD_T, + SHADER_TEXCOORD_U +}; + +enum ShaderTexFilterMode_t +{ + SHADER_TEXFILTERMODE_NEAREST, + SHADER_TEXFILTERMODE_LINEAR, + SHADER_TEXFILTERMODE_NEAREST_MIPMAP_NEAREST, + SHADER_TEXFILTERMODE_LINEAR_MIPMAP_NEAREST, + SHADER_TEXFILTERMODE_NEAREST_MIPMAP_LINEAR, + SHADER_TEXFILTERMODE_LINEAR_MIPMAP_LINEAR, + SHADER_TEXFILTERMODE_ANISOTROPIC +}; + +enum ShaderTexWrapMode_t +{ + SHADER_TEXWRAPMODE_CLAMP, + SHADER_TEXWRAPMODE_REPEAT, + SHADER_TEXWRAPMODE_BORDER + // MIRROR? - probably don't need it. +}; + + +//----------------------------------------------------------------------------- +// Sampler + texture stage identifiers +// NOTE: Texture stages are used only by fixed function shading algorithms +// Samplers are used to enable and bind textures + by programmable shading algorithms +//----------------------------------------------------------------------------- +enum TextureStage_t +{ + SHADER_TEXTURE_STAGE0 = 0, + SHADER_TEXTURE_STAGE1, +}; + +enum Sampler_t +{ + SHADER_SAMPLER0 = 0, + SHADER_SAMPLER1, + SHADER_SAMPLER2, + SHADER_SAMPLER3, + SHADER_SAMPLER4, + SHADER_SAMPLER5, + SHADER_SAMPLER6, + SHADER_SAMPLER7, + SHADER_SAMPLER8, + SHADER_SAMPLER9, + SHADER_SAMPLER10, + SHADER_SAMPLER11, + SHADER_SAMPLER12, + SHADER_SAMPLER13, + SHADER_SAMPLER14, + SHADER_SAMPLER15, +}; + +//----------------------------------------------------------------------------- +// Vertex texture sampler identifiers +//----------------------------------------------------------------------------- +enum VertexTextureSampler_t +{ + SHADER_VERTEXTEXTURE_SAMPLER0 = 0, + SHADER_VERTEXTEXTURE_SAMPLER1, + SHADER_VERTEXTEXTURE_SAMPLER2, + SHADER_VERTEXTEXTURE_SAMPLER3, +}; + + +#if defined( _X360 ) +#define REVERSE_DEPTH_ON_X360 //uncomment to use D3DFMT_D24FS8 with an inverted depth viewport for better performance. Keep this in sync with the same named #define in materialsystem/stdshaders/common_fxc.h +#endif + +#if defined( REVERSE_DEPTH_ON_X360 ) +#define ReverseDepthOnX360() true +#else +#define ReverseDepthOnX360() false +#endif + + + +#endif // SHADERAPI_SHAREDDEFS_H |