mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-09-20 12:36:05 +08:00
Added most recent version of unmodified HL2 SDK for Episode 1 engine
This commit is contained in:
150
materialsystem/shaderlib/ShaderDLL.cpp
Normal file
150
materialsystem/shaderlib/ShaderDLL.cpp
Normal file
@ -0,0 +1,150 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Header: $
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
|
||||
#include "shaderlib/ShaderDLL.h"
|
||||
#include "materialsystem/IShader.h"
|
||||
#include "utlvector.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "materialsystem/imaterialsystemhardwareconfig.h"
|
||||
#include "materialsystem/materialsystem_config.h"
|
||||
#include "IShaderSystem.h"
|
||||
#include "materialsystem/ishaderapi.h"
|
||||
#include "shaderlib_cvar.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The standard implementation of CShaderDLL
|
||||
//-----------------------------------------------------------------------------
|
||||
class CShaderDLL : public IShaderDLLInternal, public IShaderDLL
|
||||
{
|
||||
public:
|
||||
CShaderDLL();
|
||||
|
||||
// methods of IShaderDLL
|
||||
virtual bool Connect( CreateInterfaceFn factory );
|
||||
virtual void Disconnect();
|
||||
virtual int ShaderCount() const;
|
||||
virtual IShader *GetShader( int nShader );
|
||||
|
||||
// methods of IShaderDLLInternal
|
||||
virtual void InsertShader( IShader *pShader );
|
||||
|
||||
private:
|
||||
CUtlVector< IShader * > m_ShaderList;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global interfaces/structures
|
||||
//-----------------------------------------------------------------------------
|
||||
IMaterialSystemHardwareConfig* g_pHardwareConfig;
|
||||
const MaterialSystem_Config_t *g_pConfig;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Interfaces/structures local to shaderlib
|
||||
//-----------------------------------------------------------------------------
|
||||
IShaderSystem* g_pSLShaderSystem;
|
||||
|
||||
|
||||
// Pattern necessary because shaders register themselves in global constructors
|
||||
static CShaderDLL *s_pShaderDLL;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global accessor
|
||||
//-----------------------------------------------------------------------------
|
||||
IShaderDLL *GetShaderDLL()
|
||||
{
|
||||
// Pattern necessary because shaders register themselves in global constructors
|
||||
if ( !s_pShaderDLL )
|
||||
{
|
||||
s_pShaderDLL = new CShaderDLL;
|
||||
}
|
||||
|
||||
return s_pShaderDLL;
|
||||
}
|
||||
|
||||
IShaderDLLInternal *GetShaderDLLInternal()
|
||||
{
|
||||
// Pattern necessary because shaders register themselves in global constructors
|
||||
if ( !s_pShaderDLL )
|
||||
{
|
||||
s_pShaderDLL = new CShaderDLL;
|
||||
}
|
||||
|
||||
return static_cast<IShaderDLLInternal*>( s_pShaderDLL );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton interface
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _XBOX
|
||||
EXPOSE_INTERFACE_FN( (InstantiateInterfaceFn)GetShaderDLLInternal, IShaderDLLInternal, SHADER_DLL_INTERFACE_VERSION );
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Connect, disconnect...
|
||||
//-----------------------------------------------------------------------------
|
||||
CShaderDLL::CShaderDLL()
|
||||
{
|
||||
MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Connect, disconnect...
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CShaderDLL::Connect( CreateInterfaceFn factory )
|
||||
{
|
||||
g_pHardwareConfig = (IMaterialSystemHardwareConfig*)factory( MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION, NULL );
|
||||
g_pConfig = (const MaterialSystem_Config_t*)factory( MATERIALSYSTEM_CONFIG_VERSION, NULL );
|
||||
g_pSLShaderSystem = (IShaderSystem*)factory( SHADERSYSTEM_INTERFACE_VERSION, NULL );
|
||||
InitShaderLibCVars( factory );
|
||||
|
||||
return ( g_pConfig != NULL ) && (g_pHardwareConfig != NULL) && ( g_pSLShaderSystem != NULL );
|
||||
}
|
||||
|
||||
void CShaderDLL::Disconnect()
|
||||
{
|
||||
g_pHardwareConfig = NULL;
|
||||
g_pConfig = NULL;
|
||||
g_pSLShaderSystem = NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Iterates over all shaders
|
||||
//-----------------------------------------------------------------------------
|
||||
int CShaderDLL::ShaderCount() const
|
||||
{
|
||||
return m_ShaderList.Count();
|
||||
}
|
||||
|
||||
IShader *CShaderDLL::GetShader( int nShader )
|
||||
{
|
||||
if ( ( nShader < 0 ) || ( nShader >= m_ShaderList.Count() ) )
|
||||
return NULL;
|
||||
|
||||
return m_ShaderList[nShader];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Adds to the shader lists
|
||||
//-----------------------------------------------------------------------------
|
||||
void CShaderDLL::InsertShader( IShader *pShader )
|
||||
{
|
||||
Assert( pShader );
|
||||
m_ShaderList.AddToTail( pShader );
|
||||
}
|
||||
|
Reference in New Issue
Block a user