mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-09-19 12:06:07 +08:00
Added original SDK code for Alien Swarm.
This commit is contained in:
386
public/shaderapi/IShaderDevice.h
Normal file
386
public/shaderapi/IShaderDevice.h
Normal file
@ -0,0 +1,386 @@
|
||||
//===== Copyright <20> 1996-2005, 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;
|
||||
|
||||
virtual bool GetRecommendedVideoConfig( int nAdapter, KeyValues *pConfiguration ) = 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( bool bReleaseManagedResources = true ) = 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, VertexStreamSpec_t *pStreamSpec = 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() = 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;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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
|
105
public/shaderapi/commandbuffer.h
Normal file
105
public/shaderapi/commandbuffer.h
Normal file
@ -0,0 +1,105 @@
|
||||
//===== Copyright <20> 1996-2007, 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
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Commands used by the per-pass command buffers
|
||||
//-----------------------------------------------------------------------------
|
||||
enum CommandBufferCommand_t
|
||||
{
|
||||
// flow control commands.
|
||||
CBCMD_END = 0, // end of stream
|
||||
CBCMD_JUMP, // int cmd, void *adr. jump to another
|
||||
// stream. Can be used to implement
|
||||
// non-sequentially allocated storage
|
||||
CBCMD_JSR, // int cmd, void *adr. subroutine call to another stream.
|
||||
|
||||
// constant setting commands
|
||||
CBCMD_SET_PIXEL_SHADER_FLOAT_CONST, // int cmd,int first_reg, int nregs, float values[nregs*4]
|
||||
|
||||
|
||||
CBCMD_SET_VERTEX_SHADER_FLOAT_CONST, // int cmd,int first_reg, int nregs, float values[nregs*4]
|
||||
CBCMD_SET_VERTEX_SHADER_FLOAT_CONST_REF, // int cmd,int first_reg, int nregs, &float values[nregs*4]
|
||||
CBCMD_SETPIXELSHADERFOGPARAMS, // int cmd, int regdest
|
||||
CBCMD_STORE_EYE_POS_IN_PSCONST, // int cmd, int regdest
|
||||
CBCMD_SET_DEPTH_FEATHERING_CONST, // int cmd, int constant register, float blend scale
|
||||
|
||||
// texture binding
|
||||
CBCMD_BIND_STANDARD_TEXTURE, // cmd, sampler, texture id
|
||||
CBCMD_BIND_SHADERAPI_TEXTURE_HANDLE, // cmd, sampler, texture handle
|
||||
|
||||
// shaders
|
||||
CBCMD_SET_PSHINDEX, // cmd, idx
|
||||
CBCMD_SET_VSHINDEX, // cmd, idx
|
||||
|
||||
CBCMD_SET_VERTEX_SHADER_FLASHLIGHT_STATE, // cmd, int first_reg (for worldToTexture matrix)
|
||||
CBCMD_SET_PIXEL_SHADER_FLASHLIGHT_STATE, // cmd, int color reg, int atten reg, int origin reg, sampler (for flashlight texture)
|
||||
|
||||
CBCMD_SET_PIXEL_SHADER_UBERLIGHT_STATE, // cmd
|
||||
|
||||
CBCMD_SET_VERTEX_SHADER_NEARZFARZ_STATE, // 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_SETMODULATIONPIXELSHADERDYNAMICSTATE_LINEARSCALE_SCALEINW, // 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
|
767
public/shaderapi/ishaderapi.h
Normal file
767
public/shaderapi/ishaderapi.h
Normal file
@ -0,0 +1,767 @@
|
||||
//===== Copyright <20> 1996-2005, 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;
|
||||
struct MeshInstanceData_t;
|
||||
#ifdef _X360
|
||||
enum RTMultiSampleCount360_t;
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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,
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The state snapshot handle
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef short StateSnapshot_t;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The state snapshot handle
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef int ShaderDLL_t;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Texture creation
|
||||
//-----------------------------------------------------------------------------
|
||||
enum CreateTextureFlags_t
|
||||
{
|
||||
TEXTURE_CREATE_CUBEMAP = 0x00001,
|
||||
TEXTURE_CREATE_RENDERTARGET = 0x00002,
|
||||
TEXTURE_CREATE_MANAGED = 0x00004,
|
||||
TEXTURE_CREATE_DEPTHBUFFER = 0x00008,
|
||||
TEXTURE_CREATE_DYNAMIC = 0x00010,
|
||||
TEXTURE_CREATE_AUTOMIPMAP = 0x00020,
|
||||
TEXTURE_CREATE_VERTEXTEXTURE = 0x00040,
|
||||
TEXTURE_CREATE_CACHEABLE = 0x00080, // 360 only, texture may be subject to streaming
|
||||
TEXTURE_CREATE_NOD3DMEMORY = 0x00100, // 360 only, real allocation needs to occur later
|
||||
TEXTURE_CREATE_REDUCED = 0x00200, // 360 only, true dimensions forced smaller (i.e. exclusion)
|
||||
TEXTURE_CREATE_EXCLUDED = 0x00400, // 360 only, marked as excluded
|
||||
TEXTURE_CREATE_DEFAULT_POOL = 0x00800,
|
||||
TEXTURE_CREATE_UNFILTERABLE_OK = 0x01000,
|
||||
TEXTURE_CREATE_CANCONVERTFORMAT = 0x02000, // 360 only, allow format conversions at load
|
||||
TEXTURE_CREATE_PWLCORRECTED = 0x04000, // 360 only, texture is pwl corrected
|
||||
TEXTURE_CREATE_ERROR = 0x08000, // 360 only, texture was forced to checkerboard
|
||||
TEXTURE_CREATE_SYSMEM = 0x10000,
|
||||
TEXTURE_CREATE_SRGB = 0x20000, // Posix/GL only, for textures which are SRGB-readable
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// allowed stencil operations. These match the d3d operations
|
||||
//-----------------------------------------------------------------------------
|
||||
enum ShaderStencilOp_t
|
||||
{
|
||||
#if !defined( _X360 )
|
||||
SHADER_STENCILOP_KEEP = 1,
|
||||
SHADER_STENCILOP_ZERO = 2,
|
||||
SHADER_STENCILOP_SET_TO_REFERENCE = 3,
|
||||
SHADER_STENCILOP_INCREMENT_CLAMP = 4,
|
||||
SHADER_STENCILOP_DECREMENT_CLAMP = 5,
|
||||
SHADER_STENCILOP_INVERT = 6,
|
||||
SHADER_STENCILOP_INCREMENT_WRAP = 7,
|
||||
SHADER_STENCILOP_DECREMENT_WRAP = 8,
|
||||
#else
|
||||
SHADER_STENCILOP_KEEP = D3DSTENCILOP_KEEP,
|
||||
SHADER_STENCILOP_ZERO = D3DSTENCILOP_ZERO,
|
||||
SHADER_STENCILOP_SET_TO_REFERENCE = D3DSTENCILOP_REPLACE,
|
||||
SHADER_STENCILOP_INCREMENT_CLAMP = D3DSTENCILOP_INCRSAT,
|
||||
SHADER_STENCILOP_DECREMENT_CLAMP = D3DSTENCILOP_DECRSAT,
|
||||
SHADER_STENCILOP_INVERT = D3DSTENCILOP_INVERT,
|
||||
SHADER_STENCILOP_INCREMENT_WRAP = D3DSTENCILOP_INCR,
|
||||
SHADER_STENCILOP_DECREMENT_WRAP = D3DSTENCILOP_DECR,
|
||||
#endif
|
||||
SHADER_STENCILOP_FORCE_DWORD = 0x7fffffff
|
||||
};
|
||||
|
||||
enum ShaderStencilFunc_t
|
||||
{
|
||||
#if !defined( _X360 )
|
||||
SHADER_STENCILFUNC_NEVER = 1,
|
||||
SHADER_STENCILFUNC_LESS = 2,
|
||||
SHADER_STENCILFUNC_EQUAL = 3,
|
||||
SHADER_STENCILFUNC_LEQUAL = 4,
|
||||
SHADER_STENCILFUNC_GREATER = 5,
|
||||
SHADER_STENCILFUNC_NOTEQUAL = 6,
|
||||
SHADER_STENCILFUNC_GEQUAL = 7,
|
||||
SHADER_STENCILFUNC_ALWAYS = 8,
|
||||
#else
|
||||
SHADER_STENCILFUNC_NEVER = D3DCMP_NEVER,
|
||||
SHADER_STENCILFUNC_LESS = D3DCMP_LESS,
|
||||
SHADER_STENCILFUNC_EQUAL = D3DCMP_EQUAL,
|
||||
SHADER_STENCILFUNC_LEQUAL = D3DCMP_LESSEQUAL,
|
||||
SHADER_STENCILFUNC_GREATER = D3DCMP_GREATER,
|
||||
SHADER_STENCILFUNC_NOTEQUAL = D3DCMP_NOTEQUAL,
|
||||
SHADER_STENCILFUNC_GEQUAL = D3DCMP_GREATEREQUAL,
|
||||
SHADER_STENCILFUNC_ALWAYS = D3DCMP_ALWAYS,
|
||||
#endif
|
||||
|
||||
SHADER_STENCILFUNC_FORCE_DWORD = 0x7fffffff
|
||||
};
|
||||
|
||||
#if defined( _X360 )
|
||||
enum ShaderHiStencilFunc_t
|
||||
{
|
||||
SHADER_HI_STENCILFUNC_EQUAL = D3DHSCMP_EQUAL,
|
||||
SHADER_HI_STENCILFUNC_NOTEQUAL = D3DHSCMP_NOTEQUAL,
|
||||
|
||||
SHADER_HI_STENCILFUNC_FORCE_DWORD = 0x7fffffff
|
||||
};
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Stencil state
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ShaderStencilState_t
|
||||
{
|
||||
bool m_bEnable;
|
||||
ShaderStencilOp_t m_FailOp;
|
||||
ShaderStencilOp_t m_ZFailOp;
|
||||
ShaderStencilOp_t m_PassOp;
|
||||
ShaderStencilFunc_t m_CompareFunc;
|
||||
int m_nReferenceValue;
|
||||
uint32 m_nTestMask;
|
||||
uint32 m_nWriteMask;
|
||||
|
||||
#if defined( _X360 )
|
||||
bool m_bHiStencilEnable;
|
||||
bool m_bHiStencilWriteEnable;
|
||||
ShaderHiStencilFunc_t m_HiStencilCompareFunc;
|
||||
int m_nHiStencilReferenceValue;
|
||||
#endif
|
||||
|
||||
ShaderStencilState_t()
|
||||
{
|
||||
m_bEnable = false;
|
||||
m_PassOp = m_FailOp = m_ZFailOp = SHADER_STENCILOP_KEEP;
|
||||
m_CompareFunc = SHADER_STENCILFUNC_ALWAYS;
|
||||
m_nReferenceValue = 0;
|
||||
m_nTestMask = m_nWriteMask = 0xFFFFFFFF;
|
||||
|
||||
#if defined( _X360 )
|
||||
m_bHiStencilEnable = false;
|
||||
m_bHiStencilWriteEnable = false;
|
||||
m_HiStencilCompareFunc = SHADER_HI_STENCILFUNC_EQUAL;
|
||||
m_nHiStencilReferenceValue = 0;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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 "ShaderApi029"
|
||||
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( const unsigned char *pInstanceCommandBuffer, int nPass, int nPassCount ) = 0;
|
||||
|
||||
// Set the number of bone weights
|
||||
virtual void SetNumBoneWeights( int numBones ) = 0;
|
||||
|
||||
// Sets the lights
|
||||
virtual void SetLights( int nCount, const LightDesc_t *pDesc ) = 0;
|
||||
|
||||
// Lighting origin for the current model
|
||||
virtual void SetLightingOrigin( Vector vLightingOrigin ) = 0;
|
||||
|
||||
virtual void SetLightingState( const MaterialLightingState_t& state ) = 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;
|
||||
virtual void FlipCullMode( void ) = 0; //CW->CCW or CCW->CW, intended for mirror support where the view matrix is flipped horizontally
|
||||
|
||||
// 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;
|
||||
|
||||
// Returns the nearest supported format
|
||||
virtual ImageFormat GetNearestSupportedFormat( ImageFormat fmt ) 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;
|
||||
|
||||
// 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;
|
||||
|
||||
// Copy sysmem surface to default pool surface asynchronously
|
||||
virtual void UpdateTexture( int xOffset, int yOffset, int w, int h, ShaderAPITextureHandle_t hDstTexture, ShaderAPITextureHandle_t hSrcTexture ) = 0;
|
||||
virtual void *LockTex( ShaderAPITextureHandle_t hTexture ) = 0;
|
||||
virtual void UnlockTex( ShaderAPITextureHandle_t hTexture ) = 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( int nDXLevel ) = 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.
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
|
||||
// Sets the ambient light color
|
||||
virtual void SetAmbientLightColor( float r, float g, float b ) = 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 SetStencilState( const ShaderStencilState_t& state ) = 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, wchar_t wchFirst, wchar_t wchLast, XUIFontMetrics *pFontMetrics, XUICharMetrics *pCharMetrics ) = 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, RTMultiSampleCount360_t multiSampleCount, 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;
|
||||
|
||||
// 360 allows us to bypass vsync blocking up to 60 fps without creating a new device
|
||||
virtual void EnableVSync_360( bool bEnable ) = 0;
|
||||
|
||||
virtual void SetCacheableTextureParams( ShaderAPITextureHandle_t *pHandles, int count, const char *pFilename, int mipSkipCount ) = 0;
|
||||
virtual void FlushHiStencil() = 0;
|
||||
|
||||
virtual void Begin360ZPass( int nNumDynamicIndicesNeeded ) = 0;
|
||||
virtual void End360ZPass() = 0;
|
||||
virtual unsigned int Get360ZPassCounter() const = 0;
|
||||
#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 void SetDisallowAccess( bool ) = 0;
|
||||
virtual void EnableShaderShaderMutex( bool ) = 0;
|
||||
virtual void ShaderLock() = 0;
|
||||
virtual void ShaderUnlock() = 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 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;
|
||||
|
||||
// Only does anything on XBox360. This is useful to eliminate stalls
|
||||
virtual void EnableBuffer2FramesAhead( bool bEnable ) = 0;
|
||||
|
||||
virtual void FlipCulling( bool bFlipCulling ) = 0;
|
||||
|
||||
virtual void SetTextureRenderingParameter(int parm_number, ITexture *pTexture) = 0;
|
||||
|
||||
//only actually sets a bool that can be read in from shaders, doesn't do any of the legwork
|
||||
virtual void EnableSinglePassFlashlightMode( bool bEnable ) = 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 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;
|
||||
virtual void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right ) = 0;
|
||||
|
||||
virtual void LoadBoneMatrix( int boneIndex, const float *m ) = 0;
|
||||
|
||||
// interface for mat system to tell shaderapi about standard texture handles
|
||||
virtual void SetStandardTextureHandle( StandardTextureId_t nId, ShaderAPITextureHandle_t nHandle ) =0;
|
||||
|
||||
virtual void DrawInstances( int nInstanceCount, const MeshInstanceData_t *pInstance ) = 0;
|
||||
|
||||
// Allows us to override the color/alpha write settings of a material
|
||||
virtual void OverrideAlphaWriteEnable( bool bOverrideEnable, 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;
|
||||
|
||||
virtual void OnPresent( void ) = 0;
|
||||
|
||||
virtual void UpdateGameTime( float flTime ) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // ISHADERAPI_H
|
291
public/shaderapi/ishaderdynamic.h
Normal file
291
public/shaderapi/ishaderdynamic.h
Normal file
@ -0,0 +1,291 @@
|
||||
//===== Copyright <20> 1996-2008, 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"
|
||||
|
||||
|
||||
typedef int ShaderAPITextureHandle_t;
|
||||
#define INVALID_SHADERAPI_TEXTURE_HANDLE 0
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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_BLACK_ALPHA_ZERO,
|
||||
TEXTURE_GREY,
|
||||
TEXTURE_GREY_ALPHA_ZERO,
|
||||
|
||||
// Normalmaps
|
||||
TEXTURE_NORMALMAP_FLAT,
|
||||
TEXTURE_SSBUMP_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,
|
||||
|
||||
// The current local env_cubemap
|
||||
TEXTURE_LOCAL_ENV_CUBEMAP,
|
||||
|
||||
// Texture containing subdivision surface patch data
|
||||
TEXTURE_SUBDIVISION_PATCHES,
|
||||
|
||||
// Screen-space texture which contains random 3D reflection vectors used in SSAO algorithm
|
||||
TEXTURE_SSAO_NOISE_2D,
|
||||
|
||||
TEXTURE_PAINT,
|
||||
|
||||
TEXTURE_MAX_STD_TEXTURES = TEXTURE_SSAO_NOISE_2D + 1
|
||||
};
|
||||
|
||||
enum TextureFilterMode_t
|
||||
{
|
||||
TFILTER_MODE_POINTSAMPLED = 1,
|
||||
};
|
||||
|
||||
enum TessellationMode_t;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Shader interface versions
|
||||
//-----------------------------------------------------------------------------
|
||||
#define SHADERDYNAMIC_INTERFACE_VERSION "ShaderDynamic001"
|
||||
abstract_class IShaderDynamicAPI
|
||||
{
|
||||
public:
|
||||
// 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;
|
||||
|
||||
// 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 void GetWorldSpaceCameraDirection( float* pDir ) const = 0;
|
||||
|
||||
virtual int GetCurrentNumBones( void ) const = 0;
|
||||
|
||||
virtual MaterialFogMode_t GetCurrentFogType( void ) const = 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;
|
||||
|
||||
// Get the dimensions of the current render target
|
||||
virtual void GetCurrentRenderTargetDimensions( int& nWidth, int& nHeight ) const = 0;
|
||||
|
||||
// Get the current viewport
|
||||
virtual void GetCurrentViewport( int& nX, int& nY, int& nWidth, int& nHeight ) 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!
|
||||
|
||||
virtual void SetPixelShaderFogParams( int reg ) = 0;
|
||||
|
||||
// Use this to get the mesh builder that allows us to modify vertex data
|
||||
virtual bool InFlashlightMode() const = 0;
|
||||
virtual const FlashlightState_t &GetFlashlightState( VMatrix &worldToTexture ) const = 0;
|
||||
virtual bool InEditorMode() const = 0;
|
||||
|
||||
// Binds a standard texture
|
||||
virtual void BindStandardTexture( Sampler_t sampler, StandardTextureId_t id ) = 0;
|
||||
|
||||
virtual ITexture *GetRenderTargetEx( int nRenderTargetID ) const = 0;
|
||||
|
||||
virtual void SetToneMappingScaleLinear( const Vector &scale ) = 0;
|
||||
virtual const Vector &GetToneMappingScaleLinear( void ) const = 0;
|
||||
|
||||
// Sets the ambient light color
|
||||
virtual void SetAmbientLightColor( float r, float g, float b ) = 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 ;
|
||||
|
||||
virtual const FlashlightState_t &GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **pFlashlightDepthTexture ) const = 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;
|
||||
|
||||
// Returns current matrices
|
||||
virtual void GetMatrix( MaterialMatrixMode_t matrixMode, float *dst ) = 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 color correction
|
||||
virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo ) = 0;
|
||||
|
||||
virtual ITexture *GetTextureRenderingParameter(int parm_number) const = 0;
|
||||
|
||||
virtual void SetScreenSizeForVPOS( int pshReg = 32 ) = 0;
|
||||
virtual void SetVSNearAndFarZ( int vshReg ) = 0;
|
||||
virtual float GetFarZ() = 0;
|
||||
|
||||
virtual bool SinglePassFlashlightModeEnabled( void ) = 0;
|
||||
|
||||
virtual void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) = 0;
|
||||
|
||||
virtual void GetFlashlightShaderInfo( bool *pShadowsEnabled, bool *pUberLight ) const = 0;
|
||||
|
||||
virtual float GetFlashlightAmbientOcclusion( ) const = 0;
|
||||
|
||||
// allows overriding texture filtering mode on an already bound texture.
|
||||
virtual void SetTextureFilterMode( Sampler_t sampler, TextureFilterMode_t nMode ) = 0;
|
||||
|
||||
virtual TessellationMode_t GetTessellationMode() const = 0;
|
||||
|
||||
virtual float GetSubDHeight() = 0;
|
||||
|
||||
#ifdef _X360
|
||||
// Enables X360-specific command predication.
|
||||
// Set values to 'true' if batches should be rendered in the z-pass and/or the render pass.
|
||||
// Disabling predication returns to default values, which allows D3D to control predication
|
||||
virtual void EnablePredication( bool bZPass, bool bRenderPass ) = 0;
|
||||
virtual void DisablePredication() = 0;
|
||||
#endif // _X360
|
||||
};
|
||||
|
||||
// end class IShaderDynamicAPI
|
||||
|
||||
|
||||
#endif // ISHADERDYNAMIC_H
|
207
public/shaderapi/ishadershadow.h
Normal file
207
public/shaderapi/ishadershadow.h
Normal file
@ -0,0 +1,207 @@
|
||||
//===== Copyright <20> 1996-2005, 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 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 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
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
virtual void EnableBlendingSeparateAlpha( bool bEnable ) = 0;
|
||||
virtual void BlendFuncSeparateAlpha( 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;
|
||||
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
|
||||
// Per texture unit stuff
|
||||
virtual void EnableTexture( Sampler_t sampler, bool bEnable ) = 0;
|
||||
|
||||
virtual void FogMode( ShaderFogMode_t fogMode, bool bVertexFog ) = 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;
|
||||
|
||||
// Per vertex texture unit stuff
|
||||
virtual void EnableVertexTexture( VertexTextureSampler_t sampler, bool bEnable ) = 0;
|
||||
|
||||
// More alpha blending state
|
||||
virtual void BlendOp( ShaderBlendOp_t blendOp ) = 0;
|
||||
virtual void BlendOpSeparateAlpha( ShaderBlendOp_t blendOp ) = 0;
|
||||
|
||||
virtual float GetLightMapScaleFactor( void ) const = 0;
|
||||
};
|
||||
// end class IShaderShadow
|
||||
|
||||
|
||||
|
||||
#endif // ISHADERSHADOW_H
|
136
public/shaderapi/ishaderutil.h
Normal file
136
public/shaderapi/ishaderutil.h
Normal file
@ -0,0 +1,136 @@
|
||||
//===== Copyright <20> 1996-2005, 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( int nChangeFlags = 0 ) = 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;
|
||||
|
||||
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;
|
||||
|
||||
// Gets texture handles for ITextures
|
||||
virtual ShaderAPITextureHandle_t GetShaderAPITextureBindHandle( ITexture *pTexture, int nFrame, int nTextureChannel ) = 0;
|
||||
|
||||
virtual float GetSubDHeight() = 0;
|
||||
|
||||
virtual bool OnDrawMeshModulated( IMesh *pMesh, const Vector4D &diffuseModulation, int firstIndex, int numIndices ) = 0;
|
||||
|
||||
// received an event while not in owning thread, handle this outside
|
||||
virtual void OnThreadEvent( uint32 threadEvent ) = 0;
|
||||
|
||||
virtual MaterialThreadMode_t GetThreadMode() = 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;
|
||||
|
||||
virtual bool IsInFrame( ) const = 0;
|
||||
};
|
||||
|
||||
#endif // ISHADERUTIL_H
|
106
public/shaderapi/shareddefs.h
Normal file
106
public/shaderapi/shareddefs.h
Normal file
@ -0,0 +1,106 @@
|
||||
//===== Copyright <20> 1996-2005, 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 identifiers
|
||||
// Samplers are used to enable and bind textures + by programmable shading algorithms
|
||||
//-----------------------------------------------------------------------------
|
||||
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,
|
||||
|
||||
SHADER_SAMPLER_COUNT,
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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
|
Reference in New Issue
Block a user