1
This commit is contained in:
1791
materialsystem/shaderlib/BaseShader.cpp
Normal file
1791
materialsystem/shaderlib/BaseShader.cpp
Normal file
File diff suppressed because it is too large
Load Diff
169
materialsystem/shaderlib/ShaderDLL.cpp
Normal file
169
materialsystem/shaderlib/ShaderDLL.cpp
Normal file
@ -0,0 +1,169 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "shaderlib/ShaderDLL.h"
|
||||
#include "materialsystem/IShader.h"
|
||||
#include "tier1/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/mathlib.h"
|
||||
#include "tier1/tier1.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 bool Connect( CreateInterfaceFn factory, bool bIsMaterialSystem );
|
||||
virtual void Disconnect( bool bIsMaterialSystem );
|
||||
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
|
||||
//-----------------------------------------------------------------------------
|
||||
EXPOSE_INTERFACE_FN( (InstantiateInterfaceFn)GetShaderDLLInternal, IShaderDLLInternal, SHADER_DLL_INTERFACE_VERSION );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Connect, disconnect...
|
||||
//-----------------------------------------------------------------------------
|
||||
CShaderDLL::CShaderDLL()
|
||||
{
|
||||
MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Connect, disconnect...
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CShaderDLL::Connect( CreateInterfaceFn factory, bool bIsMaterialSystem )
|
||||
{
|
||||
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 );
|
||||
|
||||
if ( !bIsMaterialSystem )
|
||||
{
|
||||
ConnectTier1Libraries( &factory, 1 );
|
||||
InitShaderLibCVars( factory );
|
||||
}
|
||||
|
||||
return ( g_pConfig != NULL ) && (g_pHardwareConfig != NULL) && ( g_pSLShaderSystem != NULL );
|
||||
}
|
||||
|
||||
void CShaderDLL::Disconnect( bool bIsMaterialSystem )
|
||||
{
|
||||
if ( !bIsMaterialSystem )
|
||||
{
|
||||
ConVar_Unregister();
|
||||
DisconnectTier1Libraries();
|
||||
}
|
||||
|
||||
g_pHardwareConfig = NULL;
|
||||
g_pConfig = NULL;
|
||||
g_pSLShaderSystem = NULL;
|
||||
}
|
||||
|
||||
bool CShaderDLL::Connect( CreateInterfaceFn factory )
|
||||
{
|
||||
return Connect( factory, false );
|
||||
}
|
||||
|
||||
void CShaderDLL::Disconnect()
|
||||
{
|
||||
Disconnect( false );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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 );
|
||||
}
|
||||
|
33
materialsystem/shaderlib/shaderDLL_Global.h
Normal file
33
materialsystem/shaderlib/shaderDLL_Global.h
Normal file
@ -0,0 +1,33 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Header: $
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef SHADERDLL_GLOBAL_H
|
||||
#define SHADERDLL_GLOBAL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IShaderSystem;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
inline IShaderSystem *GetShaderSystem()
|
||||
{
|
||||
extern IShaderSystem* g_pSLShaderSystem;
|
||||
return g_pSLShaderSystem;
|
||||
}
|
||||
|
||||
|
||||
#endif // SHADERDLL_GLOBAL_H
|
70
materialsystem/shaderlib/shaderlib.vpc
Normal file
70
materialsystem/shaderlib/shaderlib.vpc
Normal file
@ -0,0 +1,70 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// SHADERLIB.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$macro SRCDIR "..\.."
|
||||
$include "$SRCDIR\vpc_scripts\source_lib_base.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE;..\"
|
||||
$PreprocessorDefinitions "$BASE;FAST_MATERIALVAR_ACCESS"
|
||||
$PreprocessorDefinitions "$BASE;fopen=dont_use_fopen" [$WINDOWS]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$Project "shaderlib"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "BaseShader.cpp"
|
||||
$File "ShaderDLL.cpp"
|
||||
$File "shaderlib_cvar.cpp"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "shaderDLL_Global.h"
|
||||
$File "shaderlib_cvar.h"
|
||||
$File "$SRCDIR\public\shaderlib\BaseShader.h"
|
||||
$File "$SRCDIR\public\tier0\basetypes.h"
|
||||
$File "$SRCDIR\public\tier0\commonmacros.h"
|
||||
$File "$SRCDIR\public\shaderlib\cshader.h"
|
||||
$File "$SRCDIR\public\tier0\dbg.h"
|
||||
$File "$SRCDIR\public\tier0\fasttimer.h"
|
||||
$File "$SRCDIR\public\appframework\IAppSystem.h"
|
||||
$File "$SRCDIR\public\tier0\icommandline.h"
|
||||
$File "$SRCDIR\public\icvar.h"
|
||||
$File "$SRCDIR\public\materialsystem\imaterial.h"
|
||||
$File "$SRCDIR\public\materialsystem\imaterialsystem.h"
|
||||
$File "$SRCDIR\public\materialsystem\imaterialsystemhardwareconfig.h"
|
||||
$File "$SRCDIR\public\materialsystem\imaterialvar.h"
|
||||
$File "$SRCDIR\public\materialsystem\imesh.h"
|
||||
$File "$SRCDIR\public\materialsystem\IShader.h"
|
||||
$File "$SRCDIR\public\materialsystem\ishaderapi.h"
|
||||
$File "..\IShaderSystem.h"
|
||||
$File "$SRCDIR\public\materialsystem\itexture.h"
|
||||
$File "$SRCDIR\public\materialsystem\materialsystem_config.h"
|
||||
$File "$SRCDIR\public\mathlib\mathlib.h"
|
||||
$File "$SRCDIR\public\tier0\memdbgoff.h"
|
||||
$File "$SRCDIR\public\tier0\memdbgon.h"
|
||||
$File "$SRCDIR\public\tier0\platform.h"
|
||||
$File "$SRCDIR\public\tier0\protected_things.h"
|
||||
$File "$SRCDIR\public\shaderlib\ShaderDLL.h"
|
||||
$File "$SRCDIR\public\string_t.h"
|
||||
$File "$SRCDIR\public\tier1\strtools.h"
|
||||
$File "$SRCDIR\public\tier1\utlmemory.h"
|
||||
$File "$SRCDIR\public\tier1\utlvector.h"
|
||||
$File "$SRCDIR\public\mathlib\vector.h"
|
||||
$File "$SRCDIR\public\mathlib\vector2d.h"
|
||||
$File "$SRCDIR\public\mathlib\vector4d.h"
|
||||
$File "$SRCDIR\public\mathlib\vmatrix.h"
|
||||
$File "$SRCDIR\public\mathlib\vplane.h"
|
||||
$File "$SRCDIR\public\vstdlib\vstdlib.h"
|
||||
}
|
||||
}
|
42
materialsystem/shaderlib/shaderlib_cvar.cpp
Normal file
42
materialsystem/shaderlib/shaderlib_cvar.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "icvar.h"
|
||||
#include "tier1/tier1.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
// ------------------------------------------------------------------------------------------- //
|
||||
// ConVar stuff.
|
||||
// ------------------------------------------------------------------------------------------- //
|
||||
class CShaderLibConVarAccessor : public IConCommandBaseAccessor
|
||||
{
|
||||
public:
|
||||
virtual bool RegisterConCommandBase( ConCommandBase *pCommand )
|
||||
{
|
||||
// Link to engine's list instead
|
||||
g_pCVar->RegisterConCommand( pCommand );
|
||||
|
||||
char const *pValue = g_pCVar->GetCommandLineValue( pCommand->GetName() );
|
||||
if( pValue && !pCommand->IsCommand() )
|
||||
{
|
||||
( ( ConVar * )pCommand )->SetValue( pValue );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
CShaderLibConVarAccessor g_ConVarAccessor;
|
||||
|
||||
|
||||
void InitShaderLibCVars( CreateInterfaceFn cvarFactory )
|
||||
{
|
||||
if ( g_pCVar )
|
||||
{
|
||||
ConVar_Register( FCVAR_MATERIAL_SYSTEM_THREAD, &g_ConVarAccessor );
|
||||
}
|
||||
}
|
20
materialsystem/shaderlib/shaderlib_cvar.h
Normal file
20
materialsystem/shaderlib/shaderlib_cvar.h
Normal file
@ -0,0 +1,20 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef SHADERLIB_CVAR_H
|
||||
#define SHADERLIB_CVAR_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
|
||||
void InitShaderLibCVars( CreateInterfaceFn cvarFactory );
|
||||
|
||||
|
||||
#endif // SHADERLIB_CVAR_H
|
Reference in New Issue
Block a user