Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions trinity/Eve/EveInstancedMeshManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,38 @@ ITriRenderBatchAccumulator* FindBatchAccumulator( const T& batches, TriBatchType
}
}

EveInstancedMeshManager::~EveInstancedMeshManager()
{
for( auto& [key, mesh] : m_meshInstances )
{
for( auto& group : mesh.meshGroups )
{
if( group.handle )
{
group.handle->index = MeshGroupHandle::InvalidIndex;
group.handle->owner = nullptr;
}
}
}

for( auto& [data, handle] : m_perObjectData )
{
if( handle )
{
handle->index = PerObjectDataHandle::InvalidIndex;
handle->owner = nullptr;
}
}

for( auto& group : m_sphereGroups )
{
if( group.handle )
{
group.handle->index = BoundingSphereHandle::InvalidIndex;
group.handle->owner = nullptr;
}
}
}

void EveInstancedMeshManager::CollectMeshes( EveComponentRegistry& registry )
{
Expand Down Expand Up @@ -811,16 +843,22 @@ void EveInstancedMeshManager::GetPickingBatches( EvePendingPickingReadback& read
{
continue;
}
InstanceBuffer::Allocation allocation = AllocateInstanceData( uint32_t( meshInfo.lodIndices[lod].size() ), mesh.isDynamic );
UploadLodData( mesh, meshInfo, lod, allocation );

auto lodData = mesh.geometry->GetMeshLod( mesh.meshIndex, int( lod ) );
if( !lodData || !lodData->m_allocationsValid )
{
continue;
}

auto primCount = GetPrimitiveCount( *lodData, mesh.areaIndex, mesh.areaCount );
if( !primCount )
{
continue;
}

InstanceBuffer::Allocation allocation = AllocateInstanceData( uint32_t( meshInfo.lodIndices[lod].size() ), mesh.isDynamic );
UploadLodData( mesh, meshInfo, lod, allocation );

uint32_t stride = uint32_t( mesh.isDynamic ? sizeof( DynamicPerInstanceBufferElement ) : sizeof( StaticPerInstanceBufferElement ) );

Tr2RenderBatch batch;
Expand Down Expand Up @@ -905,10 +943,16 @@ size_t EveInstancedMeshManager::GetBatches( const std::initializer_list<std::pai
}

auto lodData = mesh.geometry->GetMeshLod( mesh.meshIndex, int( lod ) );
if( !lodData || !lodData->m_allocationsValid )
{
instanceOffset += static_cast<uint32_t>( meshInfo.lodIndices[lod].size() );
continue;
}

auto primCount = GetPrimitiveCount( *lodData, mesh.areaIndex, mesh.areaCount );
if( !primCount )
{
instanceOffset += static_cast<uint32_t>( meshInfo.lodIndices[lod].size() );
continue;
}

Expand Down
4 changes: 3 additions & 1 deletion trinity/Eve/EveInstancedMeshManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ BLUE_DECLARE( Tr2GpuStructuredBuffer );
class EveInstancedMeshManager
{
public:
~EveInstancedMeshManager();

struct InstanceFlags
{
void AddBatchType( TriBatchType type );
Expand Down Expand Up @@ -226,7 +228,7 @@ class EveInstancedMeshManager
{
std::vector<MeshGroup> meshGroups;

Tr2Effect* material = nullptr;
Tr2EffectPtr material = nullptr;
float radius = 0.0f;
float maxScreenSize = 0.0f;
uint32_t totalVisibleInstances = 0;
Expand Down
3 changes: 2 additions & 1 deletion trinity/Eve/SpaceObject/Children/EveChildInstancedMeshes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ EveChildInstancedMeshes::EveChildInstancedMeshes( IRoot* lockobj )

EveChildInstancedMeshes::~EveChildInstancedMeshes()
{
UnregisterFromMeshManager();
for( Mesh& mesh : m_meshes )
{
if( mesh.geometry )
Expand Down Expand Up @@ -735,7 +736,7 @@ void EveChildInstancedMeshes::AddMeshesToManager( EveInstancedMeshManager& manag
{
UnregisterFromMeshManager();
}
if( m_allRegistered )
if( m_allRegistered && m_perObjectDataHandle )
{
return;
}
Expand Down
Loading