initial
This commit is contained in:
108
public/materialsystem2/imaterial2.h
Normal file
108
public/materialsystem2/imaterial2.h
Normal file
@@ -0,0 +1,108 @@
|
||||
//============ Copyright (c) Valve Corporation, All rights reserved. ============
|
||||
|
||||
#ifndef IMATERIAL2_H
|
||||
#define IMATERIAL2_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlsymbol.h"
|
||||
|
||||
// TODO: Split out common enums and typedefs out of irenderdevice.h and include the lighter-weight .h file here
|
||||
#include "rendersystem/irenderdevice.h"
|
||||
|
||||
/* Example API usage
|
||||
IMaterialMode *pMode = pMaterial->GetMode( 0 );
|
||||
if ( pMode != NULL ) // NULL if unsupported mode
|
||||
{
|
||||
MaterialRenderablePass_t renderablePassArray[ MATERIAL_RENDERABLE_PASS_MAX ];
|
||||
int nNumPasses = pMode->ComputeRenderablePassesForContext( *pRenderContext, renderablePassArray );
|
||||
for ( int i = 0; i < nNumPasses; i++ )
|
||||
{
|
||||
g_pMaterialSystem2->SetRenderStateForRenderablePass( *pRenderContext, g_hLayout, renderablePassArray[i] );
|
||||
pRenderContext->DrawIndexed( RENDER_PRIM_TRIANGLES, 0, 6 );
|
||||
}
|
||||
}
|
||||
//*/
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
class IRenderContext;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
abstract_class IMaterialLayer
|
||||
{
|
||||
public:
|
||||
// Need calls to get shader handle and anything else that will help the renderer bucket passes
|
||||
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
#define MATERIAL_RENDERABLE_PASS_MAX 8 // For code that wants to hard-code the array size to pass into ComputeRenderablePassesForContext() below
|
||||
|
||||
enum MaterialShaderProgram_t
|
||||
{
|
||||
MATERIAL_SHADER_PROGRAM_VS = 0,
|
||||
MATERIAL_SHADER_PROGRAM_GS,
|
||||
MATERIAL_SHADER_PROGRAM_PS,
|
||||
|
||||
MATERIAL_SHADER_PROGRAM_MAX,
|
||||
};
|
||||
|
||||
struct MaterialRenderablePass_t
|
||||
{
|
||||
const IMaterialLayer *pLayer;
|
||||
//MaterialDataFromClient *data;
|
||||
|
||||
// TODO: This data needs to be compacted
|
||||
int nLayerIndex;
|
||||
int nPassIndex;
|
||||
|
||||
// TODO: Change this to shader handles
|
||||
uint64 staticComboIdArray[ MATERIAL_SHADER_PROGRAM_MAX ]; // Should these be a 16-bit index to a post-skipped combo or anything smaller than 64-bits?
|
||||
uint64 dynamicComboIdArray[ MATERIAL_SHADER_PROGRAM_MAX ];
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
abstract_class IMaterialMode
|
||||
{
|
||||
public:
|
||||
// This gets the max number of passes this mode will ever render
|
||||
virtual int GetTotalNumPasses() const = 0;
|
||||
|
||||
// This must be called to converge on a dynamic combo before calling g_pMaterialSystem2->SetRenderStateForRenderablePass().
|
||||
// The array size must be at least GetTotalNumPasses() large, but using MATERIAL_RENDERABLE_PASS_MAX will always work.
|
||||
// NOTE: If you pass in a NULL pRenderContext, it will return all possible passes
|
||||
virtual int ComputeRenderablePassesForContext( IRenderContext &renderContext, MaterialRenderablePass_t *pRenderablePassArray, int nRenderablePassArraySize = MATERIAL_RENDERABLE_PASS_MAX ) = 0;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Material interface
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
abstract_class IMaterial2
|
||||
{
|
||||
public:
|
||||
// Get the name of the material. This is a full path to the vmt file starting from "mod/materials" without a file extension
|
||||
virtual const char *GetName() const = 0;
|
||||
virtual CUtlSymbol GetNameSymbol() const = 0;
|
||||
|
||||
// When async loading, this will let the caller know everything is loaded
|
||||
virtual bool IsLoaded() const = 0;
|
||||
|
||||
// If there was a problem loading the material, this will reference the error material internally
|
||||
virtual bool IsErrorMaterial() const = 0;
|
||||
|
||||
// The number of modes is constant for all materials and is defined by the client and stored in the material system.
|
||||
// Returning NULL means this is an unsupported mode. A non-NULL mode can still have 0 passes depending on game state, so
|
||||
// NULL here means the mode isn't supported by this material and it is up to the caller to decide what to do.
|
||||
// For a simple renderer that doesn't create custom render modes in the material system, GetMode(0) is always valid.
|
||||
virtual IMaterialMode *GetMode( int nMode ) = 0;
|
||||
|
||||
// Decrement the ref count on the material. The memory will eventually be freed if the ref count hits 0.
|
||||
virtual void Release() = 0;
|
||||
};
|
||||
|
||||
#endif // IMATERIAL2_H
|
||||
49
public/materialsystem2/imaterialsystem2.h
Normal file
49
public/materialsystem2/imaterialsystem2.h
Normal file
@@ -0,0 +1,49 @@
|
||||
//============ Copyright (c) Valve Corporation, All rights reserved. ============
|
||||
|
||||
#ifndef IMATERIALSYSTEM2
|
||||
#define IMATERIALSYSTEM2
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "appframework/iappsystem.h"
|
||||
#include "materialsystem2/imaterial2.h"
|
||||
|
||||
// TODO: Split out common enums and typedefs out of irenderdevice.h and include the lighter-weight .h file here
|
||||
#include "rendersystem/irenderdevice.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
class IRenderContext;
|
||||
class IRenderHardwareConfig;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// The new material system
|
||||
//---------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
abstract_class IMaterialSystem2 : public IAppSystem
|
||||
{
|
||||
public:
|
||||
// This must be called before anything else in this interface! If you don't need modes, then call it with an array of { "", NULL } which is the
|
||||
// same as not using modes at all in your vfx shader files. The error shader is setup in this function, so it must be called! Last element must be NULL!
|
||||
// NOTE: Most callers will want the first mode string to be "" which is the default mode where the mode section in the .vfx is ignored
|
||||
virtual void SetModeStrings( const char **pModeStrings ) = 0;
|
||||
|
||||
// If material cannot load, it will still return the error material. You can find out if you have that material by calling IMaterial2::IsErrorMaterial()
|
||||
virtual IMaterial2 *FindOrCreateMaterialFromVmt( const char *pVmtFileName, const char *pTextureGroupName, RenderSystemAssetFileLoadMode_t loadMode = LOADMODE_IMMEDIATE ) = 0;
|
||||
|
||||
// renderablePass is created by IMaterial2->IMaterialMode->ComputeRenderablePassesForContext()
|
||||
virtual void SetRenderStateForRenderablePass( IRenderContext &renderContext, RenderInputLayout_t hInputLayout, const MaterialRenderablePass_t &renderablePass ) const = 0;
|
||||
|
||||
// This will free all materials, shaders, constant buffers, textures, etc. that are ref counted to 0
|
||||
virtual void FreeAllUnreferencedData() = 0;
|
||||
|
||||
// Must be called when no one else is calling into the material system or any IMaterial2
|
||||
virtual void FrameUpdate() = 0;
|
||||
|
||||
// Temp interface to reload shaders (This will eventually live inside the material system but we don't have concommands right now)
|
||||
virtual void DynamicShaderCompile_ReloadAllShaders() = 0;
|
||||
};
|
||||
|
||||
#endif // IMATERIALSYSTEM2
|
||||
Reference in New Issue
Block a user