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
94 changes: 94 additions & 0 deletions trinity/Eve/SpaceObject/Attachments/EveMeshOverlayEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "Shader/Tr2Effect.h"
#include "Curves/TriCurveSet.h"
#include "Controllers/ITr2Controller.h"
#include "Tr2MeshBase.h"
#include "Resources/TriGeometryRes.h"


// --------------------------------------------------------------------------------------
Expand Down Expand Up @@ -286,3 +288,95 @@ void EveMeshOverlayEffect::Update( Be::Time realTime, Be::Time simTime )
( *it )->Update( 0.5f );
}
}

void CollectOverlayAreaBlocks( Tr2MeshBase* mesh, std::vector<TriRenderBatchAreaBlock> ( &outAreaBlocks )[EveMeshOverlayEffect::TYPE_COUNT] )
{
for( int i = 0; i < EveMeshOverlayEffect::TYPE_COUNT; ++i )
{
outAreaBlocks[i].clear();
}

if( !mesh )
{
return;
}

mesh->CollectAreaBlocks( outAreaBlocks[EveMeshOverlayEffect::TYPE_ALL], TRIBATCHTYPE_OPAQUE );
mesh->CollectAreaBlocks( outAreaBlocks[EveMeshOverlayEffect::TYPE_ALL], TRIBATCHTYPE_TRANSPARENT );
mesh->CollectAreaBlocks( outAreaBlocks[EveMeshOverlayEffect::TYPE_ALL], TRIBATCHTYPE_DECAL );
mesh->CollectAreaBlocks( outAreaBlocks[EveMeshOverlayEffect::TYPE_OPAQUEONLY], TRIBATCHTYPE_OPAQUE );

// this list is too long, will hold one element for each mesharea at least... Optimize!
for( int i = 0; i < EveMeshOverlayEffect::TYPE_COUNT; ++i )
{
TriRenderBatchAreaBlock::Optimize( outAreaBlocks[i] );
}
}

template <typename OverlayEffectContainer>
static void EmitOverlayBatchesImpl(
ITriRenderBatchAccumulator* batches,
const Tr2PerObjectData* perObjectData,
TriBatchType batchType,
const OverlayEffectContainer& overlayEffects,
const std::vector<TriRenderBatchAreaBlock> ( &areaBlocks )[EveMeshOverlayEffect::TYPE_COUNT],
const TriGeometryResLodData& lod )
{
for( auto it = overlayEffects.begin(); it != overlayEffects.end(); ++it )
{
EveMeshOverlayEffectPtr overlay = *it;
bool success = false;
const PTr2EffectVector& effects = overlay->GetEffects( batchType, success );
if( !success )
{
continue;
}

EveMeshOverlayEffect::OverlayType overlayType = overlay->GetType( batchType );
for( auto eff = effects.begin(); eff != effects.end(); ++eff )
{
Tr2EffectPtr effect = *eff;

// add all mesh area blocks
for( auto& areaBlock : areaBlocks[overlayType] )
{
if( auto primCount = GetPrimitiveCount( lod, areaBlock.m_startIndex, areaBlock.m_count ) )
{
Tr2RenderBatch batch;
batch.SetMaterial( effect );
batch.SetGeometry( lod.m_mesh->m_vertexDeclarationHandle, lod.m_vertexAllocation, lod.m_indexAllocation );
batch.SetPerObjectData( perObjectData );
batch.SetDrawIndexedInstanced(
primCount * 3,
1,
lod.m_indexAllocation.GetStartIndex() + lod.m_areas[areaBlock.m_startIndex].m_firstIndex,
lod.m_vertexAllocation.GetOffset() / lod.m_vertexAllocation.GetStride(),
0 );
batches->Commit( batch );
}
}
}
}
}

void EmitOverlayBatches(
ITriRenderBatchAccumulator* batches,
const Tr2PerObjectData* perObjectData,
TriBatchType batchType,
const PEveMeshOverlayEffectVector& overlayEffects,
const std::vector<TriRenderBatchAreaBlock> ( &areaBlocks )[EveMeshOverlayEffect::TYPE_COUNT],
const TriGeometryResLodData& lod )
{
EmitOverlayBatchesImpl( batches, perObjectData, batchType, overlayEffects, areaBlocks, lod );
}

void EmitOverlayBatches(
ITriRenderBatchAccumulator* batches,
const Tr2PerObjectData* perObjectData,
TriBatchType batchType,
const std::vector<EveMeshOverlayEffectPtr>& overlayEffects,
const std::vector<TriRenderBatchAreaBlock> ( &areaBlocks )[EveMeshOverlayEffect::TYPE_COUNT],
const TriGeometryResLodData& lod )
{
EmitOverlayBatchesImpl( batches, perObjectData, batchType, overlayEffects, areaBlocks, lod );
}
24 changes: 24 additions & 0 deletions trinity/Eve/SpaceObject/Attachments/EveMeshOverlayEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@

#include "Tr2MeshArea.h"
#include "ITr2Renderable.h"
#include "TriRenderBatch.h"
#include "Controllers/ITr2ControllerOwner.h"
#include "ITr2CurveSetOwner.h"

BLUE_DECLARE( Tr2Effect );
BLUE_DECLARE( TriCurveSet );
BLUE_DECLARE( Tr2MeshBase );
BLUE_DECLARE_VECTOR( Tr2Effect );
BLUE_DECLARE_INTERFACE( ITr2Controller );
BLUE_DECLARE_IVECTOR( ITr2Controller );

struct TriGeometryResLodData;
class ITriRenderBatchAccumulator;
class Tr2PerObjectData;

// --------------------------------------------------------------------------------
// Description:
// This class holds curveSets and Tr2Effects used for overlay effects for SpaceObjects.
Expand Down Expand Up @@ -98,4 +104,22 @@ BLUE_CLASS( EveMeshOverlayEffect ) :
TYPEDEF_BLUECLASS( EveMeshOverlayEffect );
BLUE_DECLARE_VECTOR( EveMeshOverlayEffect );

void CollectOverlayAreaBlocks( Tr2MeshBase* mesh, std::vector<TriRenderBatchAreaBlock> ( &outAreaBlocks )[EveMeshOverlayEffect::TYPE_COUNT] );

void EmitOverlayBatches(
ITriRenderBatchAccumulator* batches,
const Tr2PerObjectData* perObjectData,
TriBatchType batchType,
const PEveMeshOverlayEffectVector& overlayEffects,
const std::vector<TriRenderBatchAreaBlock> ( &areaBlocks )[EveMeshOverlayEffect::TYPE_COUNT],
const TriGeometryResLodData& lod );

void EmitOverlayBatches(
ITriRenderBatchAccumulator* batches,
const Tr2PerObjectData* perObjectData,
TriBatchType batchType,
const std::vector<EveMeshOverlayEffectPtr>& overlayEffects,
const std::vector<TriRenderBatchAreaBlock> ( &areaBlocks )[EveMeshOverlayEffect::TYPE_COUNT],
const TriGeometryResLodData& lod );

#endif // EveMeshOverlayEffect_H
Loading