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,264 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef BVH_SUPPORT_H
#define BVH_SUPPORT_H
#include <tier0/platform.h>
#include <mathlib/vector.h>
#include <mathlib/vector4d.h>
#include <mathlib/mathlib.h>
#include <mathlib/vmatrix.h>
//--------------------------------------------------------------------------------------
// Temp material: this is all throwaway
//--------------------------------------------------------------------------------------
#define MAX_SHADER_NAME 48
#define MAX_BINDS 16
enum BindStage_t
{
STAGE_VS = 0,
STAGE_HS = 1,
STAGE_DS = 2,
STAGE_GS = 3,
STAGE_PS = 4
};
enum BindSampler_t
{
SAMPLER_LINEAR = 0,
SAMPLER_POINT = 1,
SAMPLER_ANISO = 2,
SAMPLER_SHADOW_LESS = 3
};
struct MaterialResourceBinding_t
{
DECLARE_BYTESWAP_DATADESC();
uint8 m_cBindStage; // Which stage to bind to (VS,HS,DS,GS,PS)
uint8 m_cBindSlot; // Which slot to bind to in this stage
uint8 m_cBindSampler; // If this is a texture, this is the sampler enum to use
//uint8 m_padding; // don't worry about padding, because we're storing an array of 16 of them
};
struct Material_t
{
DECLARE_BYTESWAP_DATADESC();
char m_szShaderVS[MAX_SHADER_NAME];
char m_szShaderPS[MAX_SHADER_NAME];
int32 m_nBinds;
MaterialResourceBinding_t m_Binds[MAX_BINDS];
float m_flPhongExp;
float m_flPhongBoost;
// Alloc these in blocks of 4 for alignment
bool m_bAlphaTest; // Need to explicitly call out alpha-test so that we can bind textures during the shadow pass
bool m_bInstanced; // use instancing for this material
bool m_bUseAtlas; // use an atlas with an indirection texture
bool m_bVertexColor; // don't use a texture map, color is in the vertices
bool m_bNormalMap; // have a normal map
bool m_bPhong; // use phong
bool m_bPhongTexture; // pull phong exp from a texture
bool m_bPadding;
};
//--------------------------------------------------------------------------------------
// Tiled coordinate
//--------------------------------------------------------------------------------------
struct IntVector
{
DECLARE_BYTESWAP_DATADESC();
int x,y,z;
};
extern Vector g_vWorldUnitsPerTile;
struct TiledPosition_t
{
DECLARE_BYTESWAP_DATADESC();
IntVector m_vTile;
Vector m_vLocal;
void Rationalize()
{
Vector vFloor( floor( m_vLocal.x / g_vWorldUnitsPerTile.x ),
floor( m_vLocal.y / g_vWorldUnitsPerTile.y ),
floor( m_vLocal.z / g_vWorldUnitsPerTile.z ) );
m_vTile.x += (int)vFloor.x;
m_vTile.y += (int)vFloor.y;
m_vTile.z += (int)vFloor.z;
m_vLocal -= vFloor * g_vWorldUnitsPerTile;
}
TiledPosition_t operator +( TiledPosition_t &Other )
{
TiledPosition_t retVal;
retVal.m_vTile.x = m_vTile.x + Other.m_vTile.x;
retVal.m_vTile.y = m_vTile.y + Other.m_vTile.y;
retVal.m_vTile.z = m_vTile.z + Other.m_vTile.z;
retVal.m_vLocal = m_vLocal + Other.m_vLocal;
retVal.Rationalize();
return retVal;
}
TiledPosition_t operator -( TiledPosition_t &Other )
{
TiledPosition_t retVal;
retVal.m_vTile.x = m_vTile.x - Other.m_vTile.x;
retVal.m_vTile.y = m_vTile.y - Other.m_vTile.y;
retVal.m_vTile.z = m_vTile.z - Other.m_vTile.z;
retVal.m_vLocal = m_vLocal - Other.m_vLocal;
retVal.Rationalize();
return retVal;
}
Vector ToWorldPosition()
{
Vector vTile( m_vTile.x, m_vTile.y, m_vTile.z );
return vTile * g_vWorldUnitsPerTile + m_vLocal;
}
};
#include "frustum.h"
//--------------------------------------------------------------------------------------
// generic buffer for variable sized vertices
//--------------------------------------------------------------------------------------
class CGenericBuffer
{
public:
CGenericBuffer( int nElementStride = 0, int nGrowElements = 1024, int nInitElements = 1024 ) :
m_pMemory( NULL ),
m_nAllocBytes( 0 )
{
Init( nElementStride, nGrowElements, nInitElements );
}
~CGenericBuffer()
{
Purge();
}
void Init( int nElementStride, int nGrowElements = 1024, int nInitElements = 1024 )
{
Purge();
m_nElementStride = nElementStride;
m_nGrowBytes = nGrowElements * nElementStride;
m_nAllocBytes = nInitElements * nElementStride;
m_pMemory = new unsigned char[ nInitElements * nElementStride ];
}
int GetElementStride() const { return m_nElementStride; }
unsigned char *Base() const { return m_pMemory; }
int ByteCount() const { return m_nElements * m_nElementStride; }
int Count() const { return m_nElements; }
int AddToTail( unsigned char* pElement )
{
EnsureAddSize( 1 );
Q_memcpy( m_pMemory + m_nElements * m_nElementStride, pElement, m_nElementStride );
m_nElements++;
return m_nElements-1;
}
int AddMultipleToTail( int nCount, unsigned char* pElements )
{
EnsureAddSize( nCount );
Q_memcpy( m_pMemory + m_nElements * m_nElementStride, pElements, nCount * m_nElementStride );
m_nElements += nCount;
return m_nElements-1;
}
int AddMultipleToTail( int nCount )
{
EnsureAddSize( nCount );
Q_memset( m_pMemory + m_nElements * m_nElementStride, 0, nCount * m_nElementStride );
m_nElements += nCount;
return m_nElements-1;
}
void RestrideElements( int nNewStride )
{
uint8 *pNewMemory = new uint8[ nNewStride * m_nElements ];
int nMinStride = MIN( nNewStride, m_nElementStride );
uint8 *pNewStart = pNewMemory;
for ( int i=0; i<m_nElements; ++i )
{
Q_memcpy( pNewStart, m_pMemory + i * m_nElementStride, nMinStride );
pNewStart += nNewStride;
}
delete []m_pMemory;
m_pMemory = pNewMemory;
m_nElementStride = nNewStride;
m_nAllocBytes = nNewStride * m_nElements;
}
void RemoveAll()
{
m_nElements = 0;
}
void Purge()
{
if ( m_pMemory )
delete []m_pMemory;
m_pMemory = NULL;
m_nElements = 0;
m_nAllocBytes = 0;
}
unsigned char* operator[]( int i )
{
return m_pMemory + i * m_nElementStride;
}
private:
void Resize( int nNeededBytes )
{
unsigned char *pNewMemory = new unsigned char[ nNeededBytes ];
Q_memcpy( pNewMemory, m_pMemory, m_nAllocBytes );
m_nAllocBytes = nNeededBytes;
delete []m_pMemory;
m_pMemory = pNewMemory;
}
inline void EnsureAddSize( int nElementsToAdd )
{
int nUsedBytes = m_nElements * m_nElementStride;
int nNeededBytes = nUsedBytes + nElementsToAdd * m_nElementStride;
if ( m_nAllocBytes < nNeededBytes )
{
Resize( MAX( nNeededBytes, nUsedBytes + m_nGrowBytes ) );
}
}
private:
unsigned char *m_pMemory;
int m_nElementStride;
int m_nElements;
int m_nAllocBytes;
int m_nGrowBytes;
};
//--------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------
#endif

View File

@@ -0,0 +1,132 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef FRUSTUM_H
#define FRUSTUM_H
#include "mathlib/camera.h"
#include "mathlib/ssemath.h"
#include "worldrenderer/bvhsupport.h"
class CWorldRenderFrustum : public CFrustum
{
public:
//
// Slight modification of
// http://appsrv.cse.cuhk.edu.hk/~fzhang/pssm_vrcia/shadow_vrcia.pdf
//
float CalculateSplitPlaneDistance( int nSplit, int nShadowSplits, float flMaxShadowDistance )
{
float fIM = (float)nSplit / (float)nShadowSplits;
float f = MIN( flMaxShadowDistance, m_camera.m_flZFar );
float n = m_camera.m_flZNear;
float fBias = 0.1f;
float flLog = n + ( n * powf( f / n, fIM ) );
float flLinear = ( n + ( f - n ) * fIM );
return ( flLog * 0.9f + flLinear * 0.10f ) + fBias;
}
void UpdateLightFrustumFromClippedVolume( float flNear, float flFar )
{
//VMatrix mLightProj = OrthoMatrixRH( m_fSplitXSize, m_fSplitZSize, MAX( m_camera.m_flZNear, flNear ), MIN( m_camera.m_flZFar, flFar ) );
VMatrix mLightProj = OrthoMatrixRH( m_fSplitXSize, m_fSplitZSize, flNear, flFar );
SetProj( mLightProj );
CalcViewProj();
}
void SetSplitSizes( float flXSize, float flZSize ) { m_fSplitXSize = flXSize; m_fSplitZSize = flZSize; }
void CalculateLightFrusta( CWorldRenderFrustum **ppOutFrustums, int nShadowSplits, Vector vLightDir, float flLightDistance, float flLightFarPlane, float flMaxShadowDistance )
{
float fPreviousSplit = m_camera.m_flZNear;
Vector vEye = m_camera.m_origin;
Vector vEyeDir = m_forward;
vEyeDir.NormalizeInPlace();
vLightDir.NormalizeInPlace();
for( int i=0; i<nShadowSplits; i++ )
{
float fSplitPlane = CalculateSplitPlaneDistance( i + 1, nShadowSplits, flMaxShadowDistance );
float fZDist = fSplitPlane - fPreviousSplit;
float fCenterZ = ( fPreviousSplit + fSplitPlane ) * 0.5f;
float fXSize = tanf( DEG2RAD(m_camera.m_flFOVX) * 0.5f ) * fSplitPlane * 2.0f;
fXSize += ( nShadowSplits - i ) * 12.0f;
fZDist *= 1.10f;
#if ( SNAP_SHADOW_MAP == 1 )
fXSize = max( fXSize, fZDist );
fZDist = fXSize;
#endif
Vector vLightLookAt = vEye + vEyeDir * fCenterZ;
Vector vLightPosition = vLightLookAt + vLightDir * flLightDistance;
// Create the light frustum
VMatrix mLightView;
VMatrix mLightProj;
#if ( SNAP_SHADOW_MAP == 1 )
Vector vFrustumUp( 0,1,0 );
#else
Vector vFrustumUp = vEyeDir;
#endif
mLightView = ViewMatrixRH( vLightPosition, vLightLookAt, vFrustumUp );
#if ( SNAP_SHADOW_MAP == 1 )
// Clamp camera movement to full-pixels only
float fUnitsPerTexel = fXSize / (float)g_ShadowDepthTextureSize;
mLightView._41 = floorf( mLightView._41 / fUnitsPerTexel ) * fUnitsPerTexel;
mLightView._42 = floorf( mLightView._42 / fUnitsPerTexel ) * fUnitsPerTexel;
#endif
CWorldRenderFrustum *pOutFrustum = (ppOutFrustums)[i];
mLightProj = OrthoMatrixRH( fXSize, fZDist, m_camera.m_flZNear, flLightFarPlane );
pOutFrustum->SetSplitSizes( fXSize, fZDist );
pOutFrustum->SetView( mLightView );
pOutFrustum->SetProj( mLightProj );
pOutFrustum->CalcViewProj();
pOutFrustum->SetCameraPosition( vLightPosition );
Vector vLightForward;
Vector vLightLeft;
Vector vLightUp;
VMatrix mView( pOutFrustum->GetView() );
MatrixGetRow( mView, 0, &vLightLeft );
MatrixGetRow( mView, 1, &vLightUp );
MatrixGetRow( mView, 2, &vLightForward );
Vector vLightRight = -vLightLeft;
vLightForward = -vLightForward;
pOutFrustum->SetNearFarPlanes( m_camera.m_flZNear, flLightFarPlane );
pOutFrustum->SetForward( -vLightDir );
Frustum_t lightFrustum;
VPlane pSixPlanes[6];
GenerateOrthoFrustum( vec3_origin, vLightForward, vLightRight, vLightUp,
-fXSize/2.0f, fXSize/2.0f, -fZDist/2.0f, fZDist/2.0f,
m_camera.m_flZNear, flLightFarPlane,
pSixPlanes );
lightFrustum.SetPlanes( pSixPlanes );
pOutFrustum->SetFrustum( lightFrustum );
fPreviousSplit = fSplitPlane;
}
}
protected:
float m_fSplitXSize;
float m_fSplitZSize;
};
#endif

View File

@@ -0,0 +1,76 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef IBVHNODE_H
#define IBVHNODE_H
#ifdef _WIN32
#pragma once
#endif
#include "worldstructures.h"
#include "bvhsupport.h"
class IResourceDictionary;
//-----------------------------------------------------------------------------
// Methods related to rendering nodes
//-----------------------------------------------------------------------------
abstract_class IBVHNode
{
public:
// helpers
virtual int GetID() = 0;
virtual int GetFlags() = 0;
virtual void SetFlags( int nFlags ) = 0;
virtual TiledPosition_t GetOrigin() = 0;
virtual AABB_t GetBounds() = 0;
virtual void SetBounds( AABB_t bounds ) = 0;
virtual float GetMinDistance() = 0;
virtual int GetNumChildren() = 0;
virtual int GetNumResources() = 0;
virtual int GetNumDrawCalls() = 0;
virtual bool IsFullyResident() = 0;
virtual void SetIsFullyResident( bool bRes ) = 0;
virtual bool IsLoading() = 0;
virtual void SetIsLoading( bool bLoading ) = 0;
virtual int GetChild( int c ) = 0;
virtual int GetParent() = 0;
virtual void SetParent( int i ) = 0;
virtual int GetResourceIndex( int r ) = 0;
virtual void SetResourceIndex( int r, int index ) = 0;
virtual CBVHDrawCall &GetDrawCall( int d ) = 0;
virtual void Draw( IRenderContext *pRenderContext,
CBVHDrawCall *pDrawCall,
IResourceDictionary *pDictionary,
ShaderComboVariation_t nVariation = VARIATION_DEFAULT,
ConstantBufferHandle_t hObjectCB = 0 ) = 0;
virtual void Draw( IRenderContext *pRenderContext,
IResourceDictionary *pDictionary,
CFrustum &frustum,
Vector &vOriginShift,
uint nCurrentFrameNumber,
ShaderComboVariation_t nVariation = VARIATION_DEFAULT,
ConstantBufferHandle_t hObjectCB = 0 ) = 0;
virtual int GetNumPointLights() = 0;
virtual int GetNumHemiLights() = 0;
virtual int GetNumSpotLights() = 0;
virtual PointLightData_t *GetPointLights() = 0;
virtual HemiLightData_t *GetHemiLights() = 0;
virtual SpotLightData_t *GetSpotLights() = 0;
// loading-related
virtual unsigned char* Init( unsigned char *pData ) = 0;
// Tools only
virtual void SetupMaterialForDraw( IRenderContext *pRenderContext, IResourceDictionary *pIDictionary, RenderInputLayout_t inputLayout, int nDraw, ShaderComboVariation_t nVariation ) = 0;
virtual void SetNodeResources( int *pResources, int nResources ) = 0;
};
#endif

View File

@@ -0,0 +1,52 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef IRESOURCEDICTIONARY_H
#define IRESOURCEDICTIONARY_H
#ifdef _WIN32
#pragma once
#endif
#include "tier1/interface.h"
#include "filesystem.h"
#include "tier1/utlstringmap.h"
//-----------------------------------------------------------------------------
// Methods related to resources
//-----------------------------------------------------------------------------
abstract_class IResourceDictionary
{
public:
virtual char *GetPageFile() = 0;
virtual bool Init( unsigned char *pData, int nTransientMemoryBytes, BVHBuilderParams_t &buildParams, bool bToolMode = false ) = 0;
virtual void Destroy( IRenderDevice *pDevice ) = 0;
virtual bool LoadEntrySerial( void *pMemory, uint64 nMemorySize, CBVHDictionaryEntry &entry ) = 0;
virtual int GetNumResources() = 0;
virtual CBVHDictionaryEntry &GetEntry( int i ) = 0;
virtual int GetNumLayoutDescs() = 0;
virtual BVHInputLayoutDesc_t &GetLayoutDesc( int i ) = 0;
virtual RenderInputLayout_t &TranslateInputLayout( int iLayout ) = 0;
virtual void EvictNode( IRenderDevice *pDevice, IBVHNode* pNode ) = 0;
virtual void CalculateNodeResidency( IBVHNode *pNode ) = 0;
// Tools entry points
virtual bool LoadNodeSerial( IRenderDevice *pDevice, IRenderContext *pContext, IBVHNode *pNode, bool bLoadIAData ) = 0;
virtual bool UpdateEntrySerial( void *pMemory, uint64 nMemorySize, uint64 nOffsetFromEntry, CBVHDictionaryEntry &entry ) = 0;
virtual void ShiftEntries( uint64 nByteOffset ) = 0;
virtual void WriteEntries( FileHandle_t fp ) = 0;
virtual void CollectEntries( CUtlVector<CBVHDictionaryEntry> &resourceEntries, CUtlVector<IResourceDictionary*> &dictionaryList, CUtlStringMap<int> &instanceDictionary, int *pResourceRemap ) = 0;
virtual uint64 GetNonEntryDataSize() = 0;
virtual void WriteNonEntryData( int32 nNewResources, char *pNewPageFile, FileHandle_t fp ) = 0;
virtual void AddStaticEntries( CBVHDictionaryEntry *pEntries, int nEntries ) = 0;
virtual int AddEntry( uint8 nFlags, uint64 nSizeBytes, int nResourceType, char *pName, bool bInstanced ) = 0;
virtual void ByteSwapDictionary( CUtlBuffer *pOutBuffer, char *pNewPageFile ) = 0;
virtual void ByteSwapResourceFile( FileHandle_t fp ) = 0;
};
#endif

View File

@@ -0,0 +1,64 @@
//============ Copyright (c) Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//===============================================================================//
#ifndef IWORLD_H
#define IWORLD_H
#ifdef COMPILER_MSVC
#pragma once
#endif
#include "worldrenderer/worldschema.h"
#include "worldrenderer/iworldnode.h"
struct WorldBuilderParams_t;
class KeyValues;
//-----------------------------------------------------------------------------
enum BuildListAction_t
{
BUILD_ACTION_NONE = 0,
BUILD_ACTION_RENDER_PARENT = 1
};
abstract_class IWorld
{
public:
// Loading
virtual void CreateAndDispatchLoadRequests( const Vector &vEye ) = 0;
virtual void Destroy() = 0;
// Reflection
virtual int GetNumNodes() = 0;
virtual const WorldBuilderParams_t *GetBuilderParams() = 0;
virtual IWorldNode *GetNode( int n ) = 0;
virtual bool IsAncestor( int nNodeInQuestion, int nPotentialAncestor ) = 0;
virtual const NodeData_t *GetNodeData( int n ) = 0;
virtual AABB_t GetNodeBounds( int n ) = 0;
virtual Vector GetNodeOrigin( int n ) = 0;
virtual float GetNodeMinDistance( int n ) = 0;
// Resource updates
virtual void ClearOutstandingLoadRequests() = 0;
virtual void UpdateResources() = 0;
// Visibility
virtual int GetLeafNodeForPoint( Vector &vPosition ) = 0;
virtual float GetMaxVisibleDistance( Vector &vPosition ) = 0;
// Rendering
virtual BuildListAction_t BuildRenderList( WorldNodeFlags_t nSkipFlags,
const Vector &vEyePoint,
float flLODScale,
float flFarPlane,
float flElapsedTime ) = 0;
// Entities
virtual void GetEntities( char *pEntityName, CUtlVector<KeyValues*> &entityList ) = 0;
};
#endif // IWORLD_H

View File

@@ -0,0 +1,49 @@
//============ Copyright (c) Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//===============================================================================//
#ifndef IWORLDNODE_H
#define IWORLDNODE_H
#ifdef COMPILER_MSVC
#pragma once
#endif
#include "tier0/platform.h"
#include "mathlib/vector.h"
#include "mathlib/vector4d.h"
#include "mathlib/mathlib.h"
#include "mathlib/vmatrix.h"
#include "mathlib/camera.h"
#include "worldrenderer/worldnodeschema.h"
class CSceneObject;
abstract_class IWorldNode
{
public:
// helpers
//virtual int32 GetID() = 0;
//virtual int32 GetFlags() = 0;
//virtual int32 GetNumChildren() = 0;
virtual int32 GetNumSceneObjects() = 0;
virtual bool IsFullyResident() = 0;
virtual void SetIsFullyResident( bool bRes ) = 0;
virtual bool IsLoading() = 0;
virtual void SetIsLoading( bool bLoading ) = 0;
//virtual int32 GetChild( int32 c ) = 0;
//virtual int32 GetParent() = 0;
virtual CSceneObject *GetSceneObject( int32 s ) = 0;
virtual int32 GetNumPointLights() = 0;
virtual int32 GetNumHemiLights() = 0;
virtual int32 GetNumSpotLights() = 0;
virtual WorldPointLightData_t *GetPointLights() = 0;
virtual WorldHemiLightData_t *GetHemiLights() = 0;
virtual WorldSpotLightData_t *GetSpotLights() = 0;
};
#endif // IWORLDNODE_H

View File

@@ -0,0 +1,120 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef IWORLDRENDERER_H
#define IWORLDRENDERER_H
#ifdef _WIN32
#pragma once
#endif
#include "tier1/interface.h"
#include "appframework/IAppSystem.h"
#include "bitmap/imageformat.h"
#include "tier1/utlbuffer.h"
#include "mathlib/vector4d.h"
#include "ibvhnode.h"
#include "iresourcedictionary.h"
#include "raytrace.h"
#include "bitvec.h"
//-----------------------------------------------------------------------------
enum RenderAction_t
{
ACTION_NONE = 0,
ACTION_RENDER_PARENT = 1
};
//-----------------------------------------------------------------------------
// Methods related to a traversal through the world
//-----------------------------------------------------------------------------
abstract_class IWorldTraversal
{
public:
virtual Vector GetOrigin() = 0;
virtual int GetStartNode() = 0;
virtual void SetOrigin( Vector &vOrigin ) = 0;
virtual void SetStartNode( int nNode ) = 0;
};
//-----------------------------------------------------------------------------
// Methods related to rendering the world
//-----------------------------------------------------------------------------
abstract_class IWorldRenderer
{
public:
// Loading
virtual bool Unserialize( const char *pszFileName, bool bToolMode = false ) = 0;
virtual bool Initialize( IRenderDevice *pDevice, uint64 nMaxGPUMemoryBytes, uint64 nMaxSysMemoryBytes ) = 0;
virtual void CreateAndDispatchLoadRequests( IRenderDevice *pDevice, const Vector &vEye ) = 0;
virtual void DestroyResources( IRenderDevice *pDevice ) = 0;
// Reflection
virtual IResourceDictionary *GetResourceDictionary() = 0;
virtual const WorldFileHeader_t *GetHeader() = 0;
virtual IBVHNode *GetNode( int i ) = 0;
virtual bool IsAncestor( int nNodeInQuestion, int nPotentialAncestor ) = 0;
virtual int GetNumNodes() = 0;
virtual int GetNumChunks() = 0;
virtual BVHChunkDescriptor_t &GetChunkDesc( int i ) = 0;
virtual uint64 GetMaxNodeSizeBytes() = 0;
virtual uint64 GetAvgNodeSizeBytes() = 0;
// Resource updates
virtual void ClearOutstandingLoadRequests() = 0;
virtual bool UpdateResources( IRenderDevice *pDevice, IRenderContext *pContext, int nMaxResourcesToUpdate ) = 0;
// Raycasting
virtual float CastRay( Vector *pNormalOut, Vector vOrigin, Vector vDir ) = 0;
virtual Vector CalculateCurrentOrigin( Vector &vPosition ) = 0;
// Visibility
virtual int GetLeafNodeForPoint( Vector &vPosition ) = 0;
/*
virtual CVarBitVec *GetVisibilityVectorForPoint( Vector &vPosition ) = 0;
virtual CVarBitVec *GetAllVisibleVector( ) = 0;
*/
virtual float GetMaxVisibleDistance( Vector &vPosition ) = 0;
// Rendering
virtual RenderAction_t BuildRenderList( CUtlVector<IBVHNode*> *pRenderListOut,
BVHNodeFlags_t nSkipFlags,
const Vector &vEyePoint,
float flLODScale,
float flFarPlane,
float flElapsedTime,
int nCurrentFrameNumber ) = 0;
virtual void SortRenderList( CUtlVector<IBVHNode*> *pRenderList, Vector &vEyePoint ) = 0;
virtual void RenderNode( IBVHNode* pNode, IRenderContext *pContext, CFrustum &frustum, Vector &vOriginShift, uint nCurrentFrameNumber, ShaderComboVariation_t nVariation = VARIATION_DEFAULT, ConstantBufferHandle_t hObjectCB = 0 ) = 0;
// Entities
virtual void GetEntities( char *pEntityName, CUtlVector<KeyValues*> &entityList, CUtlVector<Vector> *pOriginList = NULL ) = 0;
virtual void GetEntities( char *pEntityName, CUtlVector<KeyValues*> &entityList, IWorldTraversal *pTraversal ) = 0;
// Traversals
virtual CUtlVector<IWorldTraversal*> *GetTraversals() = 0;
virtual RayTracingEnvironment *GetKDTreeForTraversal( IWorldTraversal *pTraversal ) = 0;
// Tools only (TODO: pull these into their own interface)
virtual void ShiftOrigins( Vector vOriginShift ) = 0;
virtual void ShiftNodes( int nIDOffset, int *pResourceRemap ) = 0;
virtual void WriteNodes( FileHandle_t fp ) = 0;
virtual void WriteNodesSwapped( CUtlBuffer *pOutBuffer ) = 0;
virtual uint64 GetChunkSize( BVHChunkType_t nChunkType ) = 0;
virtual uint64 GetChunkOffset( BVHChunkType_t nChunkType ) = 0;
virtual void WriteHeaderData( int32 nChunks, FileHandle_t fp ) = 0;
virtual void WriteChunkDesc( BVHChunkDescriptor_t &chunkDesc, FileHandle_t fp ) = 0;
virtual void WriteNonTerminatedEntityChunk( FileHandle_t fp ) = 0;
virtual bool ReorderResourceFile( IBVHNode **ppOrderedNodes, int nNodes ) = 0;
virtual bool WriteHierarchyFile( char *pWHFName ) = 0;
virtual bool WriteByteSwappedWorld( char *pWHFName, char *pWRFName ) = 0;
};
#endif

View File

@@ -0,0 +1,30 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef IWORLDRENDERERMGR_H
#define IWORLDRENDERERMGR_H
#include "iworldrenderer.h"
#include "iworld.h"
abstract_class IWorldRendererMgr : public IAppSystem
{
public:
virtual IWorldRenderer *CreateWorldRenderer() = 0;
virtual void DestroyWorldRenderer( IWorldRenderer *pWorldRenderer ) = 0;
virtual bool IsHWInstancingEnabled() = 0;
virtual void SetHWInstancingEnabled( bool bInstancingEnabled ) = 0;
// New world stuff
virtual HWorld CreateWorld( const char *pWorldName ) = 0;
virtual void DestroyWorld( HWorld hWorld ) = 0;
virtual IWorld *GetWorldPtr( HWorld hWorld ) = 0;
};
#endif

View File

@@ -0,0 +1,70 @@
//============ Copyright (c) Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//===============================================================================//
#ifndef WORLDNODE_SCHEMA_H
#define WORLDNODE_SCHEMA_H
#ifdef COMPILER_MSVC
#pragma once
#endif
#include <tier0/platform.h>
#include <mathlib/vector.h>
#include <mathlib/vector4d.h>
#include <mathlib/mathlib.h>
#include <mathlib/vmatrix.h>
#include "rendersystem/schema/renderable.g.h"
//--------------------------------------------------------------------------------------
// Light data
//--------------------------------------------------------------------------------------
schema struct WorldPointLightData_t
{
Vector m_vOrigin;
Vector4D m_vColorNRadius;
Vector m_vAttenuation;
};
schema struct WorldHemiLightData_t
{
Vector4D m_vTransform0; // Direction is z column
Vector4D m_vTransform1; // Direction is z column
Vector4D m_vTransform2; // Direction is z column
Vector4D m_vColorNRadius;
Vector m_vAttenuation;
};
schema struct WorldSpotLightData_t
{
Vector4D m_vTransform0; // Direction is z column
Vector4D m_vTransform1; // Direction is z column
Vector4D m_vTransform2; // Direction is z column
Vector4D m_vColorNRadius;
Vector4D m_vAttenuationNCosSpot;
};
schema struct SceneObject_t
{
Vector4D m_vTransform[3];
CResourceReference< Renderable_t > m_Renderable;
};
schema struct WorldNode_t
{
CResourceArray< SceneObject_t > m_SceneObjects; // List of scene objects in this node
CResourceArray< WorldPointLightData_t > m_PointLights; // TODO: These should actually become scene objects
CResourceArray< WorldHemiLightData_t > m_HemiLights; // TODO: These should actually become scene objects
CResourceArray< WorldSpotLightData_t > m_SpotLights; // TODO: These should actually become scene objects
};
class CWorldNode; // Forward declaration of associated runtime class
DEFINE_RESOURCE_CLASS_TYPE( WorldNode_t, CWorldNode, RESOURCE_TYPE_WORLD_NODE );
typedef const ResourceBinding_t< CWorldNode > *HWorldNode;
typedef CStrongHandle< CWorldNode > HWorldNodeStrong;
#define WORLD_NODE_HANDLE_INVALID ( (HWorldNode)0 )
#endif // WORLDNODE_SCHEMA_H

View File

@@ -0,0 +1,84 @@
//============ Copyright (c) Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//===============================================================================//
#ifndef WORLD_SCHEMA_H
#define WORLD_SCHEMA_H
#ifdef COMPILER_MSVC
#pragma once
#endif
#include "worldnodeschema.h"
//--------------------------------------------------------------------------------------
// Enum related
//--------------------------------------------------------------------------------------
enum WorldNodeFlags_t
{
WORLD_NODE_SIMPLIFIED = 0x0001, // The geometry is simplified
WORLD_NODE_UNIQUE_UV = 0x0002, // The geometry is uniquely mapped (likely, we're a higher LOD)
WORLD_NODE_ATLASED = 0x0004, // This node was atlased but not uniquely mapped
WORLD_NODE_KDTREE = 0x0008, // Node contains a kd-tree for raycasts
WORLD_NODE_NODRAW = 0x0010, // Node has no actual draw calls... it's just a container for stuff and other nodes
WORLD_NODE_START_TRAVERSAL = 0x0020, // Start a traversal at this node (add a check to ensure that the KDTREE flag also exists with this one)
WORLD_NODE_CAN_SEE_SKY = 0x0040, // Can this node see the sky?
WORLD_NODE_MOST_DETAILED = 0x0080, // Node is the most detailed node containing the original geometry and textures
};
schema struct WorldBuilderParams_t
{
int32 m_nSizeBytesPerVoxel; // target size per-voxel
float m_flMinDrawVolumeSize; // minimum size of any draw call
float m_flMinDistToCamera; // minimum distance to camera for near objects
float m_flMinAtlasDist; // minimum distance at which any atlased node can be visible
float m_flMinSimplifiedDist; // minimum distance at which any simplified node can be visible
float m_flHorzFOV; // horizontal fov used for texel to screenspace calcs
float m_flHalfScreenWidth; // half target screen res used for texel to screenspace calcs
int32 m_nAtlasTextureSizeX; // X res of atlas textures
int32 m_nAtlasTextureSizeY; // Y res of atlas textures
int32 m_nUniqueTextureSizeX; // X res of uniquely atlased textures
int32 m_nUniqueTextureSizeY; // Y res of uniquely atlased textures
int32 m_nCompressedAtlasSize; // approx size of a compressed atlas texture
float m_flGutterSize; // gutter size (in texels)
float m_flUVMapThreshold; // cos( angle ) threshold between faces when creating a unique uv parameterization
Vector m_vWorldUnitsPerTile; // world units per tile for tiled coordinates
int32 m_nMaxTexScaleSlots; // maximum number of gpu registers we can take up with texture scaling
bool m_bWrapInAtlas; // true == handle wrapping texcoords by tiling the texture in the atlas
// false == handle wrapping by a frac in the pixel shader
uint8 m_padding[3]; // pad this structure out to a mutiple of 4 bytes
};
schema struct NodeData_t
{
int32 m_Flags; // One of WorldNodeFlags_t
int32 m_nParent; // Parent node index
Vector m_vOrigin; // Origin placing us in the world
Vector m_vMinBounds; // Axis-aligned bounding-box min
Vector m_vMaxBounds; // Axis-aligned bounding-box max
float m_flMinimumDistance; // Minimum camera distance at which this node renders (pull out and vectorize?)
CResourceArray< int32 > m_ChildNodeIndices; // List of indices of the child nodes
CResourceReference< WorldNode_t > m_hWorldNode; // Handle to the world node
};
schema struct World_t
{
WorldBuilderParams_t m_builderParams; // Original build parameters ( so we can potentially remake this file )
CResourceArray< NodeData_t > m_worldNodes; // World nodes
CResourceString m_entityString; // All of the entity text
// Placeholder for visibility
};
class CWorld; // Forward declaration of associated runtime class
DEFINE_RESOURCE_CLASS_TYPE( World_t, CWorld, RESOURCE_TYPE_WORLD );
typedef const ResourceBinding_t< CWorld > *HWorld;
typedef CStrongHandle< CWorld > HWorldStrong;
#define WORLD_HANDLE_INVALID ( (HWorld)0 )
#endif // WORLD_SCHEMA_H

View File

@@ -0,0 +1,207 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Byteswapping datadescs for the corresponding worldstructures. These
// must stay in sync with the stucts in worldstructures.h.
//
//===========================================================================//
#include "worldstructures.h"
//--------------------------------------------------------------------------------------
// Fake-material related
//--------------------------------------------------------------------------------------
BEGIN_BYTESWAP_DATADESC( MaterialResourceBinding_t )
DEFINE_FIELD( m_cBindStage, FIELD_CHARACTER ),
DEFINE_FIELD( m_cBindSlot, FIELD_CHARACTER ),
DEFINE_FIELD( m_cBindSampler, FIELD_CHARACTER ),
END_BYTESWAP_DATADESC()
BEGIN_BYTESWAP_DATADESC( Material_t )
DEFINE_ARRAY( m_szShaderVS, FIELD_CHARACTER, MAX_SHADER_NAME ),
DEFINE_ARRAY( m_szShaderPS, FIELD_CHARACTER, MAX_SHADER_NAME ),
DEFINE_FIELD( m_nBinds, FIELD_INTEGER ),
DEFINE_EMBEDDED_ARRAY( m_Binds, MAX_BINDS ),
DEFINE_FIELD( m_bAlphaTest, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bInstanced, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bUseAtlas, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bVertexColor, FIELD_BOOLEAN ),
END_BYTESWAP_DATADESC()
//--------------------------------------------------------------------------------------
// Tiled coordinate
//--------------------------------------------------------------------------------------
BEGIN_BYTESWAP_DATADESC( IntVector )
DEFINE_FIELD( x, FIELD_INTEGER ),
DEFINE_FIELD( y, FIELD_INTEGER ),
DEFINE_FIELD( z, FIELD_INTEGER ),
END_BYTESWAP_DATADESC()
BEGIN_BYTESWAP_DATADESC( TiledPosition_t )
DEFINE_EMBEDDED( m_vTile ),
DEFINE_FIELD( m_vLocal, FIELD_VECTOR ),
END_BYTESWAP_DATADESC()
//--------------------------------------------------------------------------------------
// AABB
//--------------------------------------------------------------------------------------
BEGIN_BYTESWAP_DATADESC( AABB_t )
DEFINE_FIELD( m_vMinBounds, FIELD_VECTOR ),
DEFINE_FIELD( m_vMaxBounds, FIELD_VECTOR ),
END_BYTESWAP_DATADESC()
//--------------------------------------------------------------------------------------
// Generic chunk descriptor
//--------------------------------------------------------------------------------------
BEGIN_BYTESWAP_DATADESC( BVHChunkDescriptor_t )
DEFINE_FIELD( m_nChunkType, FIELD_INTEGER ),
DEFINE_FIELD( m_nOffset, FIELD_INTEGER64 ), // TODO: Add int64 to datamap.h
DEFINE_FIELD( m_nSize, FIELD_INTEGER64 ), // TODO: Add int64 to datamap.h
END_BYTESWAP_DATADESC()
//--------------------------------------------------------------------------------------
// use this buffer desc instead of BufferDesc_t because BufferDesc_t has pointers
// that won't serialized consistently between 32 and 64bits
//--------------------------------------------------------------------------------------
BEGIN_BYTESWAP_DATADESC( BVHBufferDesc_t )
DEFINE_FIELD( m_nBufferType, FIELD_INTEGER ),
DEFINE_FIELD( m_nElementCount, FIELD_INTEGER ),
DEFINE_FIELD( m_nElementSizeInBytes, FIELD_INTEGER ),
END_BYTESWAP_DATADESC()
//--------------------------------------------------------------------------------------
// Dictionary related
//--------------------------------------------------------------------------------------
BEGIN_BYTESWAP_DATADESC( CBVHDictionaryEntry )
DEFINE_EMBEDDED( m_ChunkDesc ),
DEFINE_FIELD( m_nRefCount, FIELD_INTEGER ),
DEFINE_FIELD( m_nLastFrameUsed, FIELD_INTEGER ),
DEFINE_FIELD( m_nResourceType, FIELD_INTEGER ),
DEFINE_ARRAY( m_pName, FIELD_CHARACTER, MAX_RESOURCE_NAME ),
DEFINE_FIELD( m_Flags, FIELD_CHARACTER ),
DEFINE_FIELD( m_bInstanceData, FIELD_BOOLEAN ),
DEFINE_ARRAY( m_padding, FIELD_CHARACTER, 2 ),
END_BYTESWAP_DATADESC()
BEGIN_BYTESWAP_DATADESC( BVHResourceDictionaryHeader_t )
DEFINE_FIELD( m_nInputLayouts, FIELD_INTEGER ),
DEFINE_FIELD( m_nResources, FIELD_INTEGER ),
DEFINE_ARRAY( m_pPageFile, FIELD_CHARACTER, MAX_PAGE_FILE_NAME ),
END_BYTESWAP_DATADESC()
//--------------------------------------------------------------------------------------
// Input layout
//--------------------------------------------------------------------------------------
BEGIN_BYTESWAP_DATADESC( BVHInputLayoutDesc_t )
DEFINE_ARRAY( m_pName, FIELD_CHARACTER, RENDER_INPUT_LAYOUT_FIELD_SEMANTIC_NAME_SIZE ),
DEFINE_FIELD( m_nFields, FIELD_INTEGER ),
DEFINE_FIELD( m_64Bits, FIELD_INTEGER64 ), // TODO: Add int64 to datamap.h
END_BYTESWAP_DATADESC()
//--------------------------------------------------------------------------------------
// Draw-call related
//--------------------------------------------------------------------------------------
BEGIN_BYTESWAP_DATADESC( BVHResourceBinding_t )
DEFINE_FIELD( m_nResourceIndex, FIELD_INTEGER ),
DEFINE_FIELD( m_nBindOffset, FIELD_INTEGER ),
DEFINE_FIELD( m_nElementStride, FIELD_INTEGER ),
DEFINE_FIELD( m_cBindStage, FIELD_CHARACTER ),
DEFINE_FIELD( m_cBindSlot, FIELD_CHARACTER ),
DEFINE_ARRAY( m_padding, FIELD_CHARACTER, 2 ),
END_BYTESWAP_DATADESC()
BEGIN_BYTESWAP_DATADESC( CBVHDrawCall )
DEFINE_FIELD( m_Flags, FIELD_INTEGER ),
DEFINE_EMBEDDED( m_Bounds ),
DEFINE_FIELD( m_nInputLayout, FIELD_INTEGER ),
DEFINE_FIELD( m_nResourceBindings, FIELD_INTEGER ),
DEFINE_FIELD( m_nPrimitiveType, FIELD_INTEGER ),
DEFINE_FIELD( m_nBaseVertex, FIELD_INTEGER ),
DEFINE_FIELD( m_nVertexCount, FIELD_INTEGER ),
DEFINE_FIELD( m_nStartIndex, FIELD_INTEGER ),
DEFINE_FIELD( m_nIndexCount, FIELD_INTEGER ),
DEFINE_FIELD( m_nStartInstance, FIELD_INTEGER ),
DEFINE_FIELD( m_nInstanceCount, FIELD_INTEGER ),
DEFINE_FIELD( m_64Bits, FIELD_INTEGER64 ), // TODO: Add int64 to datamap.h
END_BYTESWAP_DATADESC()
//--------------------------------------------------------------------------------------
// BVHNode related
//--------------------------------------------------------------------------------------
BEGIN_BYTESWAP_DATADESC( BVHNodeHeader_t )
DEFINE_FIELD( m_nID, FIELD_INTEGER ),
DEFINE_FIELD( m_Flags, FIELD_INTEGER ),
DEFINE_FIELD( m_nParent, FIELD_INTEGER ),
DEFINE_EMBEDDED( m_Origin ),
DEFINE_EMBEDDED( m_Bounds ),
DEFINE_FIELD( m_flMinimumDistance, FIELD_FLOAT ),
DEFINE_FIELD( m_nChildren, FIELD_INTEGER ),
DEFINE_FIELD( m_nResources, FIELD_INTEGER ),
DEFINE_FIELD( m_nDrawCalls, FIELD_INTEGER ),
END_BYTESWAP_DATADESC()
//--------------------------------------------------------------------------------------
// World related
//--------------------------------------------------------------------------------------
BEGIN_BYTESWAP_DATADESC( BVHBuilderParams_t )
DEFINE_FIELD( m_nSizeBytesPerVoxel, FIELD_INTEGER ),
DEFINE_FIELD( m_flMinDrawVolumeSize, FIELD_FLOAT ),
DEFINE_FIELD( m_flMinDistToCamera, FIELD_FLOAT ),
DEFINE_FIELD( m_flMinAtlasDist, FIELD_FLOAT ),
DEFINE_FIELD( m_flMinSimplifiedDist, FIELD_FLOAT ),
DEFINE_FIELD( m_flHorzFOV, FIELD_FLOAT ),
DEFINE_FIELD( m_flHalfScreenWidth, FIELD_FLOAT ),
DEFINE_FIELD( m_nAtlasTextureSizeX, FIELD_INTEGER ),
DEFINE_FIELD( m_nAtlasTextureSizeY, FIELD_INTEGER ),
DEFINE_FIELD( m_nUniqueTextureSizeX, FIELD_INTEGER ),
DEFINE_FIELD( m_nUniqueTextureSizeY, FIELD_INTEGER ),
DEFINE_FIELD( m_nCompressedAtlasSize, FIELD_INTEGER ),
DEFINE_FIELD( m_flGutterSize, FIELD_FLOAT ),
DEFINE_FIELD( m_flUVMapThreshold, FIELD_FLOAT ),
DEFINE_FIELD( m_vWorldUnitsPerTile, FIELD_VECTOR ),
DEFINE_FIELD( m_nMaxTexScaleSlots, FIELD_INTEGER ),
DEFINE_FIELD( m_bWrapInAtlas, FIELD_BOOLEAN ),
DEFINE_ARRAY( m_padding, FIELD_CHARACTER, 3 ),
END_BYTESWAP_DATADESC()
//--------------------------------------------------------------------------------------
// File header
//--------------------------------------------------------------------------------------
BEGIN_BYTESWAP_DATADESC( WorldFileHeader_t )
DEFINE_FIELD( m_nFileVersion, FIELD_INTEGER ),
DEFINE_FIELD( m_vWorldUnitsPerTile, FIELD_VECTOR ),
DEFINE_FIELD( m_nChunks, FIELD_INTEGER ),
DEFINE_EMBEDDED( m_BuilderParams ),
END_BYTESWAP_DATADESC()
//--------------------------------------------------------------------------------------
// Known chunk headers
//--------------------------------------------------------------------------------------
BEGIN_BYTESWAP_DATADESC( HierarchyChunkHeader_t )
DEFINE_FIELD( m_nNodes, FIELD_INTEGER ),
DEFINE_FIELD( m_nMaxNodeSizeBytes, FIELD_INTEGER ),
DEFINE_FIELD( m_nAvgNodeSizeBytes, FIELD_INTEGER ),
END_BYTESWAP_DATADESC()
BEGIN_BYTESWAP_DATADESC( EntityChunkHeader_t )
DEFINE_FIELD( m_nEntities, FIELD_INTEGER ),
END_BYTESWAP_DATADESC()
BEGIN_BYTESWAP_DATADESC( VisibilityChunkHeader_t )
DEFINE_FIELD( m_nNodes, FIELD_INTEGER ),
DEFINE_FIELD( m_nDWORDS, FIELD_INTEGER ),
DEFINE_FIELD( m_nX, FIELD_INTEGER ),
DEFINE_FIELD( m_nY, FIELD_INTEGER ),
DEFINE_FIELD( m_nZ, FIELD_INTEGER ),
DEFINE_FIELD( m_vCellSize, FIELD_VECTOR ),
DEFINE_FIELD( m_vStart, FIELD_VECTOR ),
END_BYTESWAP_DATADESC()
BEGIN_BYTESWAP_DATADESC( RenderInputLayoutFieldProxy_t )
DEFINE_ARRAY( m_pSemanticName, FIELD_CHARACTER, RENDER_INPUT_LAYOUT_FIELD_SEMANTIC_NAME_SIZE ),
DEFINE_FIELD( m_nSemanticIndex, FIELD_INTEGER ),
DEFINE_FIELD( m_Format, FIELD_INTEGER ),
DEFINE_FIELD( m_nOffset, FIELD_INTEGER ),
DEFINE_FIELD( m_nSlot, FIELD_INTEGER ),
DEFINE_FIELD( m_nSlotType, FIELD_INTEGER ),
DEFINE_FIELD( m_nInstanceStepRate, FIELD_INTEGER ),
END_BYTESWAP_DATADESC()

View File

@@ -0,0 +1,424 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef WORLDSTRUCTURES_H
#define WORLDSTRUCTURES_H
#ifdef _WIN32
#pragma once
#endif
#define WORLD_FILE_VERSION 101
#include "tier0/platform.h"
#include "rendersystem/irenderdevice.h"
#include "rendersystem/irendercontext.h"
#include "bvhsupport.h"
//--------------------------------------------------------------------------------------
// Chunk types
//--------------------------------------------------------------------------------------
enum BVHChunkType_t
{
// Client-only resources
// GPU resources
CHUNK_TYPE_RESOURCE_DICTIONARY = 0, // Resource dictionary
CHUNK_TYPE_ENTITIES, // Entity lump
CHUNK_TYPE_HEIRARCHY, // Heirarchy
CHUNK_TYPE_VISIBILITY, // Visibility vectors
MAX_CHUNK_TYPES
};
//--------------------------------------------------------------------------------------
// Generic chunk descriptor
//--------------------------------------------------------------------------------------
struct BVHChunkDescriptor_t
{
DECLARE_BYTESWAP_DATADESC();
BVHChunkType_t m_nChunkType; // type for the chunk
uint64 m_nOffset; // Offset from the beginning of the file to this chunk
uint64 m_nSize; // Number of bytes taken up
};
//--------------------------------------------------------------------------------------
// Fake-material related
//--------------------------------------------------------------------------------------
enum ShaderComboVariation_t
{
VARIATION_DEFAULT = 0, // business as usual
VARIATION_DEPTH, // depth only
VARIATION_NORM_DEPTH_SPEC, // normal and specular power
VARIATION_SAMPLE_LIGHTING, // sampling lighting
VARIATION_SAMPLE_LIGHTING_LOW_TEXTURE, // sampling lighting and only add a little texture in
// Tools modes
VARIATION_BAKE_ALL, // bake albedo, normal, and specular
VARIATION_RENDER_UV, // Render position and normal to UV space
MAX_VARIATIONS
};
#define MAX_RUNTIME_VARIATIONS VARIATION_BAKE_ALL
//--------------------------------------------------------------------------------------
// Resource related
//--------------------------------------------------------------------------------------
enum BVHResourceType_t
{
// Client-only resources
// GPU resources
BVH_VERTEX_BUFFER = 0,
BVH_CONSTANT_BUFFER,
BVH_INDEX_BUFFER,
BVH_TEXTURE,
BVH_PRECOMP_CMD_BUFFER, // 360-only for now
// Cutoff for client-only resources
BVH_MAX_CLIENT_ONLY_RESOURCES = 16, // Make this a hard line in the sand?
// Non-client-only resources
BVH_MATERIAL, // Fake material class
BVH_KDTREE, // KD-tree for raycasts (normally stored in node0)
BVH_POINTLIGHT_DATA, // pointlight data
BVH_HEMILIGHT_DATA, // hemilight data
BVH_SPOTLIGHT_DATA, // spotlight data
BVH_PVS,
BVH_SOMETHING_ELSE,
};
//--------------------------------------------------------------------------------------
// use this buffer desc instead of BufferDesc_t because BufferDesc_t has pointers
// that won't serialized consistently between 32 and 64bits
//--------------------------------------------------------------------------------------
struct BVHBufferDesc_t
{
DECLARE_BYTESWAP_DATADESC();
RenderBufferType_t m_nBufferType;
int32 m_nElementCount; // Number of vertices/indices
int32 m_nElementSizeInBytes; // Size of a single vertex/index
};
//--------------------------------------------------------------------------------------
// Dictionary related
//--------------------------------------------------------------------------------------
enum BVHDictionaryEntryFlags_t
{
NON_PAGEABLE = 0x01, // Resource can never be evicted once loaded
USE_SYS_MEMORY = 0x02, // Use system memory to fulfill this request
USE_INSTANCE_DATA = 0x04, // Instance data is in this resource
//USE_GPU_MEMORY = 0x04, // Use GPU visible memory to fulfill this request
USE_TRANSIENT_MEMORY = 0x08, // Use transient memory ( reclaimed system memory )
};
#define MAX_RESOURCE_NAME 64
class CBVHDictionaryEntry
{
public:
DECLARE_BYTESWAP_DATADESC();
CBVHDictionaryEntry() :
m_nRefCount( 0 )
{
}
~CBVHDictionaryEntry()
{
}
int AddRef()
{
return ++m_nRefCount;
}
int Release()
{
m_nRefCount--;
if ( m_nRefCount == 0 )
{
// TODO: do we need to do anything here?
}
return m_nRefCount;
}
int GetRefCount()
{
return m_nRefCount;
}
uint8 GetFlags() { return m_Flags; }
uint64 GetOffset() const { return m_ChunkDesc.m_nOffset; }
uint64 GetSize() { return m_ChunkDesc.m_nSize; }
int GetResourceType() { return m_nResourceType; }
char *GetName() { return m_pName; }
bool GetInstanced() { return m_bInstanceData; }
void SetFlags( unsigned char Flags ) { m_Flags = Flags; }
void SetOffset( uint64 offset ) { m_ChunkDesc.m_nOffset = offset; }
void SetSize( uint64 size ) { m_ChunkDesc.m_nSize = size; }
void SetResourceType( int type ) { m_nResourceType = type; }
void SetName( char *pName ) { Q_strncpy( m_pName, pName, MAX_RESOURCE_NAME ); }
void SetInstanced( bool bInstanced ) { m_bInstanceData = bInstanced; }
private:
BVHChunkDescriptor_t m_ChunkDesc; // Chunk descriptor for the mapping in file
int32 m_nRefCount; // Reference count
uint32 m_nLastFrameUsed; // The last frame in which this resource was used
int32 m_nResourceType; // of type BVHResourceType_t
char m_pName[MAX_RESOURCE_NAME]; // unique name to help identify this resource or its origin
uint8 m_Flags; // of type DictionaryEntryFlags_t
bool m_bInstanceData; // is this data instanced?
uint8 m_padding[2]; // pad the struct out to a multiple of 4 bytes
};
#define MAX_PAGE_FILE_NAME 64
struct BVHResourceDictionaryHeader_t
{
DECLARE_BYTESWAP_DATADESC();
int32 m_nInputLayouts; // Number of pre-defined input layouts for this map
int32 m_nResources; // Number of instanced resources
char m_pPageFile[MAX_PAGE_FILE_NAME]; // name of our page file
};
//--------------------------------------------------------------------------------------
// Input layout
//--------------------------------------------------------------------------------------
struct BVHInputLayoutDesc_t
{
DECLARE_BYTESWAP_DATADESC();
char m_pName[RENDER_INPUT_LAYOUT_FIELD_SEMANTIC_NAME_SIZE];
int32 m_nFields;
union
{
RenderInputLayoutField_t *m_pFields;
uint64 m_64Bits; // force to 64bits
};
};
//--------------------------------------------------------------------------------------
// Draw-call related
//--------------------------------------------------------------------------------------
struct BVHResourceBinding_t
{
DECLARE_BYTESWAP_DATADESC();
int32 m_nResourceIndex; // Which resource in the resource dictionary to bind
int32 m_nBindOffset; // Byte offset for binding (only applicable for buffers)
int32 m_nElementStride; // Element stride (only applicable for buffers) (byte?, short?)
uint8 m_cBindStage; // Which stage to bind to (IA,SHADER)
uint8 m_cBindSlot;
uint8 m_padding[2]; // pad this structure out to a multiple of 4 bytes
};
enum BVHDrawCallFlags_t
{
DRAW_WHEN_NODE_LOADED = 0x00000001, // Wait for the entire node to load before drawing. Mutex with ASAP.
DRAW_ASAP = 0x00000002, // Draw as soon as we're loaded. Don't wait for anything.
DRAW_IF_PREVIOUS_DREW = 0x00000004, // Only draw if our previous draw happened
DRAW_TRANSPARENT = 0x00000008, // We have transparency
DRAW_WHEN_CAMERA_INSIDE = 0x00000010, // Only draw when the camera is in this node
DRAW_ALWAYS = 0x00000020, // Draw if any of the traversal hits this node
DRAW_CULL = 0x00000040, // Cull the draw individually using the draw's bounding box
DRAW_LIGHT = 0x00000080, // The draw call is bounding light geometry
};
enum BVHBindStage_t
{
BIND_STAGE_MATERIAL = 0x0,
BIND_STAGE_SHADER,
BIND_STAGE_IA,
};
class CBVHDrawCall
{
public:
bool Issue(); // issue the draw call
int32 GetFlags() { return m_Flags; }
int32 GetInputLayout() { return m_nInputLayout; }
int32 GetNumResourceBindings() { return m_nResourceBindings; }
public:
DECLARE_BYTESWAP_DATADESC();
int32 m_Flags; // One of BVHDrawCallFlags_t
AABB_t m_Bounds; // Bounding box for culling
int32 m_nInputLayout; // Index for the pre-defined input layout for the vertices
int32 m_nResourceBindings; // Number of resource bindings
// Draw call data
RenderPrimitiveType_t m_nPrimitiveType; // Type of primitive to draw
int32 m_nBaseVertex; // Base vertex to use when rendering
int32 m_nVertexCount; // Number of vertices
int32 m_nStartIndex; // First index to use
int32 m_nIndexCount; // Number of indices to draw ( or index count per instance if instancing )
int32 m_nStartInstance; // Location of the first instance
int32 m_nInstanceCount; // Number of instances ( if 0, instancing is disabled )
// Binding pointer stored in-file
union // TODO: are nameless unions ok in gcc?
{
BVHResourceBinding_t *m_pResourceBindings; // Resource bindings
uint64 m_64Bits; // pad to 64bits
};
};
//--------------------------------------------------------------------------------------
// BVHNode related
//--------------------------------------------------------------------------------------
enum BVHNodeFlags_t
{
NODE_SIMPLIFIED = 0x0001, // The geometry is simplified
NODE_UNIQUE_UV = 0x0002, // The geometry is uniquely mapped (likely, we're a higher LOD)
NODE_ATLASED = 0x0004, // This node was atlased but not uniquely mapped
NODE_KDTREE = 0x0008, // Node contains a kd-tree for raycasts
NODE_NODRAW = 0x0010, // Node has no actual draw calls... it's just a container for stuff and other nodes
NODE_START_TRAVERSAL = 0x0020, // Start a traversal at this node (add a check to ensure that the KDTREE flag also exists with this one)
NODE_CAN_SEE_SKY = 0x0040, // Can this node see the sky?
NODE_MOST_DETAILED = 0x0080, // Node is the most detailed node containing the original geometry and textures
};
struct BVHNodeHeader_t
{
DECLARE_BYTESWAP_DATADESC();
int32 m_nID; // Node ID
int32 m_Flags; // One of BVHNodeFlags_t
// hierarchy
int32 m_nParent; // Parent node
TiledPosition_t m_Origin; // Tiled-position origin placing us in the world
AABB_t m_Bounds; // Axis-aligned bounding-box (pull out and vectorize?)
float m_flMinimumDistance; // Minimum camera distance at which this node renders (pull out and vectorize?)
int32 m_nChildren; // Number of child nodes
// resources
int32 m_nResources; // Number of resources needed by this node (int16?)
int32 m_nDrawCalls; // Number of draw calls (int16?)
};
//--------------------------------------------------------------------------------------
// World related
//--------------------------------------------------------------------------------------
struct BVHBuilderParams_t
{
DECLARE_BYTESWAP_DATADESC();
int32 m_nSizeBytesPerVoxel; // target size per-voxel
float m_flMinDrawVolumeSize; // minimum size of any draw call
float m_flMinDistToCamera; // minimum distance to camera for near objects
float m_flMinAtlasDist; // minimum distance at which any atlased node can be visible
float m_flMinSimplifiedDist; // minimum distance at which any simplified node can be visible
float m_flHorzFOV; // horizontal fov used for texel to screenspace calcs
float m_flHalfScreenWidth; // half target screen res used for texel to screenspace calcs
int32 m_nAtlasTextureSizeX; // X res of atlas textures
int32 m_nAtlasTextureSizeY; // Y res of atlas textures
int32 m_nUniqueTextureSizeX; // X res of uniquely atlased textures
int32 m_nUniqueTextureSizeY; // Y res of uniquely atlased textures
int32 m_nCompressedAtlasSize; // approx size of a compressed atlas texture
float m_flGutterSize; // gutter size (in texels)
float m_flUVMapThreshold; // cos( angle ) threshold between faces when creating a unique uv parameterization
Vector m_vWorldUnitsPerTile; // world units per tile for tiled coordinates
int32 m_nMaxTexScaleSlots; // maximum number of gpu registers we can take up with texture scaling
bool m_bWrapInAtlas; // true == handle wrapping texcoords by tiling the texture in the atlas
// false == handle wrapping by a frac in the pixel shader
uint8 m_padding[3]; // pad this structure out to a mutiple of 4 bytes
};
//--------------------------------------------------------------------------------------
// File header
//--------------------------------------------------------------------------------------
struct WorldFileHeader_t
{
DECLARE_BYTESWAP_DATADESC();
uint32 m_nFileVersion; // Versioning
Vector m_vWorldUnitsPerTile; // World units per-tile that this map was built against
int32 m_nChunks; // Number of chunks
BVHBuilderParams_t m_BuilderParams; // Original build parameters ( so we can potentially remake this file )
};
//--------------------------------------------------------------------------------------
// Known chunk headers
//--------------------------------------------------------------------------------------
struct HierarchyChunkHeader_t
{
DECLARE_BYTESWAP_DATADESC();
int32 m_nNodes; // Number of nodes in this world
int32 m_nMaxNodeSizeBytes; // Maximum size of a node in bytes (Average instead?)
int32 m_nAvgNodeSizeBytes; // Average size of a node in bytes (Average instead?)
};
struct EntityChunkHeader_t
{
DECLARE_BYTESWAP_DATADESC();
int32 m_nEntities; // Entity count
};
struct VisibilityChunkHeader_t
{
DECLARE_BYTESWAP_DATADESC();
int32 m_nNodes; // Num nodes accounted for
int32 m_nDWORDS; // Num dwords per visibility chunk
int32 m_nX; // Num grid points in X
int32 m_nY; // Num grid points in Y
int32 m_nZ; // Num grid points in Z
Vector m_vCellSize; // Cell size
Vector m_vStart; // Cell start
};
struct RenderInputLayoutFieldProxy_t
{
DECLARE_BYTESWAP_DATADESC();
char m_pSemanticName[RENDER_INPUT_LAYOUT_FIELD_SEMANTIC_NAME_SIZE];
int m_nSemanticIndex;
ColorFormat_t m_Format;
int m_nOffset;
int m_nSlot;
RenderSlotType_t m_nSlotType;
int m_nInstanceStepRate;
};
//--------------------------------------------------------------------------------------
// Light data
//--------------------------------------------------------------------------------------
struct PointLightData_t
{
Vector m_vOrigin;
Vector4D m_vColorNRadius;
Vector m_vAttenuation;
};
struct HemiLightData_t
{
Vector4D m_vTransform0; // Direction is z column
Vector4D m_vTransform1; // Direction is z column
Vector4D m_vTransform2; // Direction is z column
Vector4D m_vColorNRadius;
Vector m_vAttenuation;
};
struct SpotLightData_t
{
Vector4D m_vTransform0; // Direction is z column
Vector4D m_vTransform1; // Direction is z column
Vector4D m_vTransform2; // Direction is z column
Vector4D m_vColorNRadius;
Vector4D m_vAttenuationNCosSpot;
};
#endif