This commit is contained in:
nephacks
2025-06-04 03:22:50 +02:00
parent f234f23848
commit f12416cffd
14243 changed files with 6446499 additions and 26 deletions

View File

@@ -0,0 +1,174 @@
//============ Copyright (c) Valve Corporation, All rights reserved. ============
#ifndef ISCENESYSTEM
#define ISCENESYSTEM
#ifdef _WIN32
#pragma once
#endif
#include "appframework/iappsystem.h"
#include "mathlib/camera.h"
#include "rendersystem/irenderdevice.h"
#include "rendersystem/irendercontext.h"
#include "rendersystem/indexdata.h"
#include "rendersystem/vertexdata.h"
#include "particles/particles.h"
#include "rendersystem/schema/renderbuffer.g.h"
#include "rendersystem/schema/renderable.g.h"
//---------------------------------------------------------------------------------------------------------------------------------------------------
// Forward declarations
//---------------------------------------------------------------------------------------------------------------------------------------------------
class CSceneObject; // something that can be rendered
class CSceneParticleObject;
class CSceneMonitorObject;
class CSceneObjectList; // a set of objects which pass some
// test (for example, being in the
// frustum. generated by traversal
class CSceneView; // describes one scene render, such as
// a splitscreen view, a shadow map
// frustum, etc.
enum MaterialDrawMode_t
{
MATDRAWMODE_REGULAR = 0, // full forward rendering
MATDRAWMODE_LIGHTPREPASS = 1, // output to a gbuffer
MATDRAWMODE_LIGHTPOSTPASS = 2, // 2nd pass deferred
MATDRAWMODE_NUMMODES
};
// placeholder
struct Mat2DrawModeDescriptor_t
{
HRenderTextureStrong m_hTextureToBind;
RenderShaderHandle_t m_hVertexShader;
RenderShaderHandle_t m_hPixelShader;
};
class IMat2
{
public:
Mat2DrawModeDescriptor_t m_drawDescriptors[MATDRAWMODE_NUMMODES];
RenderInputLayout_t m_hLayout;
uint m_nPassFlags; // SCENEOBJECTFLAG_ flags about which material this pass renders in.
void Bind( IRenderContext *pCtx, MaterialDrawMode_t nMode, RenderInputLayout_t hLayout = RENDER_INPUT_LAYOUT_INVALID );
};
struct ModelVertexXFormStream_t
{
Vector4D m_matTransform0;
Vector4D m_matTransform1;
Vector4D m_matTransform2;
};
struct CMeshDrawPrimitive_t
{
uint32 m_nSortKey;
matrix3x4_t *m_pTransform;
MaterialDrawDescriptor_t const *m_pDrawOp;
CSceneObject *m_pObject;
};
class ISceneObjectDesc
{
public:
virtual CSceneObject *Create( void ) = 0;
virtual void DrawArray( class IRenderContext *pCtx, CMeshDrawPrimitive_t *pRenderList, int nNumRenderablesToDraw,
class CSceneView const *pView, class CSceneLayer *pLayer ) {}
// generate the simple static vb primitives for this object. may be called with a non 0
// nStartPrimitive multiple times if there is a buffer overflow (this should be a rare
// occurrence
virtual int GeneratePrimitives( CSceneObject *pObject, int nStartPrimitive, int nMaxOutputPrimitives, CMeshDrawPrimitive_t *pOutBuf,
CSceneView const *pView, CSceneLayer *pLayer ) { return 0; }
};
class CSceneLayer;
typedef void (*LAYERDRAWFN)( class ISceneView *pView, IRenderContext *pCtx, CSceneLayer *pLayer );
class ISceneView // this class is going to become concrete
{
public:
virtual CSceneLayer *AddRenderLayer( RenderViewport_t const &viewport, MaterialDrawMode_t eShaderMode ) =0;
virtual CSceneLayer *AddProceduralLayer( RenderViewport_t const &viewport, LAYERDRAWFN pFnToRender ) =0;
virtual ~ISceneView( void ) {}
};
abstract_class ISceneSystem : public IAppSystem
{
public:
// creating renderables
virtual CSceneObject *CreateSceneObject( ISceneObjectDesc *pDesc, uint nFlags ) =0;
// finding and adding renderable types
virtual ISceneObjectDesc *GetSceneObjectDesc( char const *pName ) = 0;
virtual void AddSceneObjectType( char const *pName, ISceneObjectDesc *pDescriptor ) =0;
virtual CSceneObject *CreateSceneObject( uint nFlags ) =0;
// rendering. First call beginRenderingViews, then call AddRenerView on all of the views you
// want to render, and then call FinishRenderingViews which will kick off all of the threads.
// since rendering is asynchronous, you need to call WaitForRenderingToComplete() before
// starting another render or changing the state of sceneobjects, etc.
virtual void BeginRenderingViews( IRenderDevice *pDevice ) = 0;
virtual ISceneView *AddView( CFrustum const &frustum ) = 0;
virtual void BeginRenderingDynamicView( ISceneView *pView ) = 0; // only call this on views created during rendering
virtual void FinishRenderingViews( void ) = 0;
virtual void WaitForRenderingToComplete( void ) = 0;
virtual void InitSystem( void ) =0;
// general obejct stuff
virtual void SetObjectBounds( CSceneObject *pObj, Vector const &vecMins, Vector const &vecMaxes ) =0;
// particles
virtual CSceneParticleObject *CreateParticleObject( const char *pParticleSystemName, float flDelay = 0.0f, int nRandomSeed = 0 ) =0;
virtual CSceneMonitorObject *CreateMonitorObject( void ) =0;
virtual CParticleSystemMgr *ParticleMgr( void ) =0;
virtual bool ReadParticleConfigFile( const char *pFileName, bool bPrecache, bool bDecommitTempMemory = true ) =0;
// create a particle system by name. returns null if one of that name does not exist
virtual CParticleCollection *CreateParticleCollection( const char *pParticleSystemName, float flDelay = 0.0f, int nRandomSeed = 0 ) =0;
virtual CParticleCollection *CreateParticleCollection( ParticleSystemHandle_t particleSystemName, float flDelay = 0.0f, int nRandomSeed = 0 ) =0;
virtual void Shutdown( void ) =0;
virtual ~ISceneSystem( void ) {}
};
#endif // ISCENESYSTEM

View File

@@ -0,0 +1,170 @@
//============ Copyright (c) Valve Corporation, All rights reserved. ============
#ifndef SCENEOBJECT_H
#define SCENEOBJECT_H
#ifdef _WIN32
#pragma once
#endif
#include "scenesystem/iscenesystem.h"
class ISceneObjectDesc;
enum ESceneObjectFlags
{
SCENEOBJECTFLAG_IS_LOADED = 1, // this will go away when we have permanent data - we can't afford to poll all objects.
SCENEOBJECTFLAG_DRAW_IN_PREPASS = 2,
SCENEOBJECTFLAG_DRAW_IN_LIGHTPASS = 4,
SCENEOBJECTFLAG_DRAW_IN_COMBINE_PASS = 8,
SCENEOBJECTFLAG_DRAW_IN_TRANSLUCENT_PASS = 16,
SCENEOBJECTFLAG_DRAW_IN_REFLECTION_PASS = 32,
SCENEOBJECTFLAG_IS_DISABLED = 64,
};
enum ESceneObjectTypeFlags
{
SCENEOBJECTTYPEFLAG_IS_PROCEDURAL = 1, // objects with this set draw via calling the DrawArray entrypoint in the ISceneObjectDesc, not by bundling up meshes
SCENEOBJECTTYPEFLAG_FROM_POOL = 2, // was allocated from our pool
};
class CSceneObjectReference_t // this is what we store in our spatial data structures. 32 bytes
{
public:
VectorAligned m_vecAABBMins;
uint m_nRenderableFlags;
VectorAligned m_vecAABBMaxes;
class CSceneObject *m_pObject;
};
class CSceneObject
{
public:
CSceneObject *m_pNext; // temp for linking objects in list
CSceneObjectReference_t *m_pRefData;
uint8 m_nID; // not unique! - for hashing, etc
uint8 m_nNumDrawPrimitives;
uint8 m_nObjectTypeFlags;
uint8 m_nPad;
HRenderableStrong m_hRenderable;
uint m_nRenderableFlags; // this is a mirror of the flags for objects which are not in hierarchy yet
// temporary so that alex can check in without breaking scenesystem
IMat2 *m_pMaterialHack;
union
{
MaterialDrawDescriptor_t const *m_pDrawPrimitives; // fixed mesh objects have this
void *m_pObjectData; // procedurals and non-fixed meshes get this, and it is used as a sort key
};
template<class T> FORCEINLINE T * ObjectData( void )
{
Assert( m_nNumDrawPrimitives == 0 );
return ( reinterpret_cast< T* >( m_pObjectData ) );
}
matrix3x4_t m_transform;
ISceneObjectDesc *m_pDesc;
FORCEINLINE uint32 GetID( void ) const
{
return m_nID;
}
FORCEINLINE void MirrorFlags( void ) const
{
if ( m_pRefData )
{
m_pRefData->m_nRenderableFlags = m_nRenderableFlags;
}
}
FORCEINLINE bool IsLoaded( void ) const
{
return ( m_nRenderableFlags & SCENEOBJECTFLAG_IS_LOADED ) != 0;
}
FORCEINLINE void SetLoaded( void )
{
m_nRenderableFlags |= SCENEOBJECTFLAG_IS_LOADED;
MirrorFlags();
}
FORCEINLINE void ClearLoaded( void )
{
m_nRenderableFlags &= ~SCENEOBJECTFLAG_IS_LOADED;
MirrorFlags();
}
FORCEINLINE void SetBounds( Vector const &vecMins, Vector const &vecMaxes )
{
g_pSceneSystem->SetObjectBounds( this, vecMins, vecMaxes );
}
};
// particle vertex layout defs - ! to be moved. eventaully all of this will be hidden inside the particles.lib render ops
struct VertexRepeatedStream_t
{
Vector2D m_vecCoord; // -1 1 1 1 1 -1 -1 -1
};
struct VertexUVPos_t
{
Vector m_vecPos;
Vector2D m_vecUV;
};
struct VertexPerParticleStream_t
{
Vector m_vecPos;
float m_flRadius;
VertexColor_t m_color;
};
class CSceneParticleObject : public CSceneObject
{
public:
IMat2 *m_pMaterial; // will go away with particle/mat2 integration
CParticleCollection *m_pParticles;
};
class CSceneMonitorObject : public CSceneObject
{
public:
Vector m_MonitorVerts[4];
HRenderTextureStrong m_hMonitorTexture;
RenderTargetBinding_t m_hRenderTargetBinding;
IMat2 *m_pMaterial;
CFrustum m_frustum;
};
#define DRAWLIST_CHUNKSIZE 1024
class CSceneDrawList
{
public:
CSceneDrawList *m_pNext;
int m_nNumPrimitives;
CMeshDrawPrimitive_t m_drawPrimitives[DRAWLIST_CHUNKSIZE];
};
#endif

View File

@@ -0,0 +1,89 @@
//============ Copyright (c) Valve Corporation, All rights reserved. ============
#ifndef SCENEVIEW_H
#define SCENEVIEW_H
#ifdef _WIN32
#pragma once
#endif
#include "mathlib/camera.h"
#include "tier1/utlvector.h"
#include "tier1/utlintrusivelist.h"
#include "rendersystem/irendercontext.h"
// to use the scenesystem, you feed it a bunch of CSceneViews to render. More CSceneViews may be
// generated during rendering as a result of things such as lights, etc.
enum ELayerType
{
LAYERTYPE_DRAW_WORLDOBJECTS, // this layer causes a world-graph traversal producing an object list
LAYERTYPE_PROCEDURAL,
};
enum ELayerFlags
{
LAYERFLAG_NEEDS_FULLSORT = 1,
LAYERFLAGS_CLEAR_RENDERTARGET = 2,
};
class CSceneDrawList;
struct CStandardTextureBindingRecord_t
{
StandardTextureID_t m_nID;
HRenderTexture m_hTexture;
};
class CSceneLayer
{
public:
RenderViewport_t m_viewport;
ELayerType m_eLayerType;
MaterialDrawMode_t m_eShaderMode;
int m_nShadingMode; // mode to use for binding materials when rendering into this layer
uint m_nObjectFlagsRequiredMask;
uint m_nObjectFlagsExcludedMask;
uint m_nLayerFlags; // LAYERFLAG_xxx
Vector4D m_vecClearColor;
int m_nClearFlags;
int m_nLayerIndex;
RenderTargetBinding_t m_hRenderTargetBinding;
LAYERDRAWFN m_pRenderProcedure;
CUtlIntrusiveList<CSceneDrawList> m_pendingDrawList;
CUtlIntrusiveList<CDisplayList> m_renderLists;
CUtlVectorFixed<CStandardTextureBindingRecord_t, STDTEXTURE_NUMBER_OF_IDS> m_standardBindings;
FORCEINLINE void AddStandardTextureBinding( StandardTextureID_t nID, HRenderTexture hTexture );
};
FORCEINLINE void CSceneLayer::AddStandardTextureBinding( StandardTextureID_t nID, HRenderTexture hTexture )
{
int nSlot = m_standardBindings.AddToTail();
m_standardBindings[nSlot].m_nID = nID;
m_standardBindings[nSlot].m_hTexture = hTexture;
}
// constant buffer layout for camera constants. needs to be moved somewhere where shaders can see it.
struct ViewRelatedConstants_t
{
VMatrix m_mViewProjection;
Vector4D m_vEyePt;
Vector4D m_vEyeDir;
Vector4D m_flFarPlane;
};
// reserved constant slots. needs to go somewhere in the new mat/shader system
#define VERTEX_CONSTANT_SLOT_VIEWRELATED_BASE 0
#endif //sceneview_h