⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shaderapidx8.cpp

📁 hl2 source code. Do not use it illegal.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	// Sets the constant register for vertex and pixel shaders
	void SetVertexShaderConstant( int var, float const* pVec, int numVecs = 1, bool bForce = false );
	void SetPixelShaderConstant( int var, float const* pVec, int numVecs = 1, bool bForce = false );

	// Returns the nearest supported format
	ImageFormat GetNearestSupportedFormat( ImageFormat fmt ) const;
	ImageFormat GetNearestRenderTargetFormat( ImageFormat format ) const;

	// This is only used for statistics gathering..
	void SetLightmapTextureIdRange( int firstId, int lastId );

	// stuff that shouldn't be used from within a shader 
    void ModifyTexture( unsigned int textureNum );
	void BindTexture( TextureStage_t stage, unsigned int textureNum );
	void DeleteTexture( unsigned int textureNum );
	bool IsTexture( unsigned int textureNum );
	bool IsTextureResident( unsigned int textureNum );

	// Set the render target to a texID.
	// Set to SHADER_RENDERTARGET_BACKBUFFER if you want to use the regular framebuffer.
	void SetRenderTarget( unsigned int colorTexture = SHADER_RENDERTARGET_BACKBUFFER, 
		unsigned int depthTexture = SHADER_RENDERTARGET_DEPTHBUFFER );
	ImageFormat GetBackBufferFormat() const;
	void GetBackBufferDimensions( int& width, int& height ) const;

	// These are bound to the texture, not the texture environment
	void TexMinFilter( ShaderTexFilterMode_t texFilterMode );
	void TexMagFilter( ShaderTexFilterMode_t texFilterMode );
	void TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode );
	void TexSetPriority( int priority );

	void CreateTexture( unsigned int textureNum, int width, 
		int height, ImageFormat dstImageFormat, int numMipLevels, int numCopies, int creationFlags );
	void CreateDepthTexture( unsigned int textureNum, ImageFormat renderTargetFormat, int width, int height );
	void TexImage2D( int level, int cubeFaceID, ImageFormat dstFormat, int width, int height, 
							 ImageFormat srcFormat, void *imageData );
	void TexSubImage2D( int level, int cubeFaceID, int xOffset, int yOffset, int width, int height,
							 ImageFormat srcFormat, int srcStride, void *imageData );

	bool TexLock( int level, int cubeFaceID, int xOffset, int yOffset, 
									int width, int height, CPixelWriter& writer );
	void TexUnlock( );

	// stuff that isn't to be used from within a shader
	// what's the best way to hide this? subclassing?
	void DepthRange( float zNear, float zFar );
	void ClearBuffers( bool bClearColor, bool bClearDepth, int renderTargetWidth, int renderTargetHeight );
	void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b );
	void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a );
	void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat );

	// We need to make the ambient cube...
	void CreateAmbientCubeTexture();
	void ReleaseAmbientCubeTexture();

	// Gets the current buffered state... (debug only)
	void GetBufferedState( BufferedState_t& state );

	// Buffered primitives
	void FlushBufferedPrimitives( );

	// Make sure we finish drawing everything that has been requested 
	void FlushHardware();
	
	// Use this to begin and end the frame
	void BeginFrame();
	void EndFrame();

	// Use this to spew information about the 3D layer 
	void SpewDriverInfo() const;

	// Used to clear the transition table when we know it's become invalid.
	void ClearSnapshots();

	// returns the D3D interfaces....
	IDirect3DDevice* D3DDevice()	
	{ 
		return m_pD3DDevice; 
	}
	IDirect3D*		  D3D()			
	{ 
		return m_pD3D; 
	}

	virtual int GetActualNumTextureUnits() const;

	// Inherited from IMaterialSystemHardwareConfig
	bool HasAlphaBuffer() const;
	bool HasStencilBuffer() const;
	bool HasARBMultitexture() const;
	bool HasNVRegisterCombiners() const;
	bool HasTextureEnvCombine() const;
	int	 GetFrameBufferColorDepth() const;
	int  GetNumTextureUnits() const;
	int  GetNumTextureStages() const;
	bool HasIteratorsPerTextureUnit() const;
	bool HasSetDeviceGammaRamp() const;
	bool SupportsCompressedTextures() const;
	bool SupportsVertexAndPixelShaders() const;
	bool SupportsPixelShaders_1_4() const;
	bool SupportsPixelShaders_2_0() const;
	bool SupportsVertexShaders_2_0() const;
	bool SupportsPartialTextureDownload() const;
	bool SupportsStateSnapshotting() const;
	int  MaximumAnisotropicLevel() const;
	int  MaxTextureWidth() const;
	int  MaxTextureHeight() const;
	int	 MaxTextureAspectRatio() const;
	int	 TextureMemorySize() const;
	bool SupportsOverbright() const;
	bool SupportsMipmapping() const;
	bool SupportsCubeMaps() const;
	bool SupportsMipmappedCubemaps() const;
	bool SupportsNonPow2Textures() const;
	int	 NumVertexShaderConstants() const;
	int	 NumPixelShaderConstants() const;
	int	 MaxNumLights() const;
	bool SupportsHardwareLighting() const;
	int	 MaxBlendMatrices() const;
	int	 MaxBlendMatrixIndices() const;
	int	 MaxVertexShaderBlendMatrices() const;
	int	 GetDXSupportLevel() const;
	const char *GetShaderDLLName() const;
	int	 MaxUserClipPlanes() const;
	bool UseFastClipping() const;
	int  GetAnisotropicLevel() const;
	bool UseForcedTrilinear() const;
	bool UseForcedBilinear() const;
	bool UseFastZReject() const;
	void UpdateFastClipUserClipPlane( void );
	bool ReadPixelsFromFrontBuffer() const;
	bool PreferDynamicTextures() const;
	bool HasProjectedBumpEnv() const;

	// GR - HDR stuff
	bool SupportsHDR() const;
	bool NeedsAAClamp() const;
	bool SupportsSpheremapping() const;
	virtual bool HasFastZReject() const;
	virtual bool NeedsATICentroidHack() const;
	virtual const char *GetHWSpecificShaderDLLName() const;

	// returns the current time in seconds....
	double CurrentTime() const;

	// Get the current camera position in world space.
	void GetWorldSpaceCameraPosition( float* pPos ) const;

	// Fog methods
	void FogMode( MaterialFogMode_t fogMode );
	void FogStart( float fStart );
	void FogEnd( float fEnd );
	void SetFogZ( float fogZ );
	float GetFogStart( void ) const;
	float GetFogEnd( void ) const;
	void FogColor3f( float r, float g, float b );
	void FogColor3fv( float const* rgb );
	void FogColor3ub( unsigned char r, unsigned char g, unsigned char b );
	void FogColor3ubv( unsigned char const* rgb );

	void SceneFogMode( MaterialFogMode_t fogMode );
	MaterialFogMode_t GetSceneFogMode( );
	void SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b );
	void GetSceneFogColor( unsigned char *rgb );
	
	// Selection mode methods
	int  SelectionMode( bool selectionMode );
	void SelectionBuffer( unsigned int* pBuffer, int size );
	void ClearSelectionNames( );
	void LoadSelectionName( int name );
	void PushSelectionName( int name );
	void PopSelectionName();
	bool IsInSelectionMode() const;
	void RegisterSelectionHit( float minz, float maxz );
	void WriteHitRecord();

    // lightmap stuff
	void BindLightmap( TextureStage_t stage );
	void BindLightmapAlpha( TextureStage_t stage );
	void BindBumpLightmap( TextureStage_t stage );
	void BindWhite( TextureStage_t stage );
	void BindBlack( TextureStage_t stage );
	void BindGrey( TextureStage_t stage );
	void BindFlatNormalMap( TextureStage_t stage );
	void BindSyncTexture( TextureStage_t stage, int texture );
	void BindFBTexture( TextureStage_t stage );
	void BindNormalizationCubeMap( TextureStage_t stage );

	// Gets the lightmap dimensions
	virtual void GetLightmapDimensions( int *w, int *h );

	// Use this to get the mesh builder that allows us to modify vertex data
	CMeshBuilder* GetVertexModifyBuilder();

	// Helper to get at the texture state stage
	TextureStageState_t& TextureStage( int stage ) { return m_DynamicState.m_TextureStage[stage]; }
	TextureStageState_t const& TextureStage( int stage ) const { return m_DynamicState.m_TextureStage[stage]; }

	void SetAmbientLight( float r, float g, float b );
	void SetLight( int lightNum, LightDesc_t& desc );
	void SetAmbientLightCube( Vector4D colors[6] );

	int GetMaxLights( void ) const;
	const LightDesc_t& GetLight( int lightNum ) const;

	void SetVertexShaderStateAmbientLightCube();
	void BindAmbientLightCubeToStage0( );

	void CopyRenderTargetToTexture( int texID );

	// Returns the cull mode (for fill rate computation)
	D3DCULL GetCullMode() const;

	// Gets the window size
	void GetWindowSize( int& width, int& height ) const;

	// Applies Z Bias
	void ApplyZBias( ShadowState_t const& shaderState );

	// Applies texture enable
	void ApplyTextureEnable( ShadowState_t const& state, int stage );

	// Applies cull enable
	void ApplyCullEnable( bool bEnable );

	// Applies alpha blending
	void ApplyAlphaBlend( bool bEnable, D3DBLEND srcBlend, D3DBLEND destBlend );

	// Applies alpha texture op
	void ApplyColorTextureStage( int stage, D3DTEXTUREOP op, int arg1, int arg2 );
	void ApplyAlphaTextureStage( int stage, D3DTEXTUREOP op, int arg1, int arg2 );

	// Sets the material rendering state
	void SetMaterialProperty( float overbrightVal );

	// Sets texture stage stage + render stage state
	void SetSamplerState( int stage, D3DSAMPLERSTATETYPE state, DWORD val );
	void SetTextureStageState( int stage, D3DTEXTURESTAGESTATETYPE state, DWORD val );
	void SetRenderStateForce( D3DRENDERSTATETYPE state, DWORD val );
	void SetRenderState( D3DRENDERSTATETYPE state, DWORD val );

	// Can we download textures?
	virtual bool CanDownloadTextures() const;

	// Are we using graphics?
	virtual bool IsUsingGraphics() const;

	// Call this when another app is initializing or finished initializing
	void OtherAppInitializing( bool initializing );

	// Initializes the C1 constant (has the overbright term)
	void SetVertexShaderConstantC1( float overbright );

	void ForceHardwareSync( void );

	void DrawDebugText( int desiredLeft, int desiredTop, 
					    MaterialRect_t *pActualRect,
						const char *pText );

	void EvictManagedResources();
	// Gets at a particular transform
	inline D3DXMATRIX& GetTransform( int i )
	{
		return *m_pMatrixStack[i]->GetTop();
	}

	int GetCurrentNumBones( void ) const;
	int GetCurrentLightCombo( void ) const;
	int GetCurrentFogType( void ) const;

	void RecordString( const char *pStr );

	virtual bool IsRenderingMesh() const { return m_pRenderMesh != 0; }

	void SetTextureTransformDimension( int textureStage, int dimension, bool projected );
	void DisableTextureTransform( int textureMatrix );
	void SetBumpEnvMatrix( int textureStage, float m00, float m01, float m10, float m11 );
private:
	CShaderAPIDX8( CShaderAPIDX8 const& );

	enum
	{
		INVALID_TRANSITION_OP = 0xFFFF
	};

	struct Texture_t
	{
		Texture_t()
		{
			m_Flags = 0;
		}
		
		int m_BindId;

		// FIXME: Compress this info
		D3DTEXTUREADDRESS m_UTexWrap;
		D3DTEXTUREADDRESS m_VTexWrap;
		D3DTEXTUREFILTERTYPE m_MagFilter;
		D3DTEXTUREFILTERTYPE m_MinFilter;
		D3DTEXTUREFILTERTYPE m_MipFilter;
	    unsigned char m_NumLevels;
		unsigned char m_SwitchNeeded;	// Do we need to advance the current copy?
		unsigned char m_NumCopies;		// copies are used to optimize procedural textures
		unsigned char m_CurrentCopy;	// the current copy we're using...

		// stats stuff
		int m_SizeBytes;
		int m_SizeTexels;
		int m_LastBoundFrame;

		enum Flags_t
		{
			IS_DEPTH_STENCIL = 1
		};
		
		unsigned int m_Flags;
		typedef IDirect3DBaseTexture *IDirect3DBaseTexturePtr; // garymcthack
		typedef IDirect3DBaseTexture **IDirect3DBaseTexturePtrPtr; // garymcthack
		IDirect3DBaseTexturePtr &GetTexture( void )
		{
			Assert( m_NumCopies == 1 );
			Assert( !( m_Flags & IS_DEPTH_STENCIL ) );
			return m_pTexture;
		}
		IDirect3DBaseTexturePtr &GetTexture( int copy )
		{
			Assert( m_NumCopies > 1 );
			Assert( !( m_Flags & IS_DEPTH_STENCIL ) );
			return m_ppTexture[copy];
		}
		IDirect3DBaseTexturePtrPtr &GetTextureArray( void )
		{
			Assert( m_NumCopies > 1 );
			Assert( !( m_Flags & IS_DEPTH_STENCIL ) );
			return m_ppTexture;
		}
		typedef IDirect3DSurface *IDirect3DSurfacePtr; // garymcthack
		IDirect3DSurfacePtr &GetDepthStencilSurface( void )
		{
			Assert( m_NumCopies == 1 );
			Assert( m_Flags & IS_DEPTH_STENCIL );
			return m_pDepthStencilSurface;
		}
	private:
		union
		{
			IDirect3DBaseTexture*  m_pTexture;		// used when there's one copy
			IDirect3DBaseTexture** m_ppTexture;	// used when there are more than one copies
			IDirect3DSurface*		m_pDepthStencilSurface; // used when there's one depth stencil surface
		};
	};

	// Allow us to override support level based on device + vendor id
	struct DeviceSupportLevels_t
	{
		int m_nVendorId;
		int m_nDeviceIdMin;
		int m_nDeviceIdMax;
		int m_nDXSupportLevel;
		int m_nCreateQuery;		// Whether the card supports CreateQuery or not.  -1 = detect, 1 = yes, 0 = no.
		char m_pShaderDLL[32];
		bool m_bFastZReject;
		bool m_bFastClipping;
		bool m_bNeedsATICentroidHack;
	};

	enum CompressedTextureState_t
	{
		COMPRESSED_TEXTURES_ON,
		COMPRESSED_TEXTURES_OFF,
		COMPRESSED_TEXTURES_NOT_INITIALIZED
	};

	struct HardwareCaps_t
	{
		// NOTE: The difference between texture units and texture stages
		// is that texture units represents the number of simultaneous textures
		// if there's more stages than units, it usually is because there's
		// some sort of emulation of extra hardware features going on.
		int  m_NumTextureUnits;
		int  m_NumTextureStages;
		bool m_HasSetDeviceGammaRamp;
		bool m_SupportsVertexShaders;
		bool m_SupportsVertexShaders_2_0;
		bool m_SupportsPixelShaders;
		bool m_SupportsPixelShaders_1_4;
		bool m_SupportsPixelShaders_2_0;
		CompressedTextureState_t m_SupportsCompressedTextures;
		bool m_bSupportsAnisotropicFiltering;
		int	 m_nMaxAnisotropy;
		int  m_MaxTextureWidth;
		int  m_MaxTextureHeight;
		int	 m_MaxTextureAspectRatio;
		int  m_MaxPrimitiveCount;
		bool m_ZBiasSupported;
		bool m_SlopeScaledDepthBiasSupported;
		bool m_SupportsMipmapping;
		bool m_SupportsOverbright;
		bool m_SupportsCubeMaps;
		int  m_NumPixelShaderConstants;
		int  m_NumVertexShaderConstants;
		int  m_TextureMemorySize;
		int  m_MaxNumLights;
		bool m_SupportsHardwareLighting;
		int  m_MaxBlendMatrices;
		int  m_MaxBlendMatrixIndices;
		int	 m_MaxVertexShaderBlendMatrices;
		bool m_SupportsMipmappedCubemaps;
		bool m_SupportsNonPow2Textures;
		int  m_DXSupportLevel;
		bool m_PreferDynamicTextures;
		bool m_HasProjectedBumpEnv;
		int m_MaxUserClipPlanes;
		// GR
		bool m_SupportsSRGB;
		bool m_SupportsFatTextures;
		bool m_SupportsHDR;
		bool m_bSupportsSpheremapping;
		bool m_UseFastClipping;
		char m_pShaderDLL[32];
		bool m_bFastZReject;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -