Skip to content
Merged
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
6 changes: 4 additions & 2 deletions trinity/Eve/SpaceObject/Children/EveChildMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,8 @@ void EveChildMesh::GetBatches( ITriRenderBatchAccumulator* batches, TriBatchType
{
if( m_mesh )
{
m_mesh->GetBatches( batches, m_mesh->GetAreas( batchType ), perObjectData, min( m_currentInstanceScreenSize, m_currentScreenSize ) );
const bool reverseWinding = Determinant( m_worldTransform ) < 0.0f;
m_mesh->GetBatches( batches, m_mesh->GetAreas( batchType ), perObjectData, min( m_currentInstanceScreenSize, m_currentScreenSize ), reverseWinding );
}

if( m_activationStrength != 0.0 )
Expand All @@ -674,7 +675,8 @@ void EveChildMesh::GetShadowBatches( ITriRenderBatchAccumulator* batches, const
// Fix asap <Logi 27. aug 2015>
if( m_display && m_mesh && m_hasUpdated )
{
m_mesh->GetBatches( batches, m_mesh->GetAreas( TRIBATCHTYPE_OPAQUE ), perObjectData, shadowPixelSize );
const bool reverseWinding = Determinant( m_worldTransform ) < 0.0f;
m_mesh->GetBatches( batches, m_mesh->GetAreas( TRIBATCHTYPE_OPAQUE ), perObjectData, shadowPixelSize, reverseWinding );
}
}

Expand Down
7 changes: 0 additions & 7 deletions trinity/Eve/SpaceObject/Children/EveChildParticleSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,6 @@ Tr2PerObjectData* EveChildParticleSystem::GetPerObjectData( ITriRenderBatchAccum

void EveChildParticleSystem::UpdateSyncronous( const EveUpdateContext& updateContext, const EveChildUpdateParams& )
{
if( m_mesh )
{
if( EntityComponents::ShouldReflect( m_reflectionMode ) )
{
m_mesh->ReverseIndexBuffers();
}
}
}

void EveChildParticleSystem::UpdateAsyncronous( const EveUpdateContext& updateContext, const EveChildUpdateParams& params )
Expand Down
209 changes: 34 additions & 175 deletions trinity/Resources/TriGeometryRes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,69 +178,6 @@ uint32_t GetPrimitiveCount( const TriGeometryResLodData& lod, uint32_t index, ui
}


namespace
{
#if WITH_GRANNY
ALResult ReverseIndexBuffer( TriGeometryResLodData& lod, granny_mesh& grannyMesh, Tr2RenderContext& renderContext )
{
uint32_t bytesPerIndex = 2;
auto indexCount = grannyMesh.PrimaryTopology->Index16Count;
if( indexCount == 0 )
{
indexCount = grannyMesh.PrimaryTopology->IndexCount;
if( indexCount == 0 )
{
return S_OK;
}
if( grannyMesh.PrimaryVertexData->VertexCount > 65535 )
{
bytesPerIndex = 4;
}
}

std::vector<uint8_t> tempBuffer( indexCount * bytesPerIndex );
GrannyCopyMeshIndices( &grannyMesh, bytesPerIndex, tempBuffer.data() );

if( bytesPerIndex == 2 )
{
std::reverse( reinterpret_cast<uint16_t*>( tempBuffer.data() ), reinterpret_cast<uint16_t*>( tempBuffer.data() + tempBuffer.size() ) );
}
else
{
std::reverse( reinterpret_cast<uint32_t*>( tempBuffer.data() ), reinterpret_cast<uint32_t*>( tempBuffer.data() + tempBuffer.size() ) );
}

CR_RETURN_HR( g_sharedBuffer.Allocate( bytesPerIndex, indexCount, tempBuffer.data(), renderContext, lod.m_reversedIndexAllocation ) );
lod.m_reversedIndicesValid = true;
return S_OK;
}
#endif

ALResult ReverseIndexBuffer( TriGeometryResLodData& lod, const void* ibData, const cmf::MeshLod& cmfMeshLod, Tr2RenderContext& renderContext )
{
uint32_t bytesPerIndex = cmfMeshLod.ib.stride;
auto indexCount = cmf::GetStreamElementCount( cmfMeshLod.ib );

std::vector<uint8_t> tempBuffer( indexCount * bytesPerIndex );
memcpy( tempBuffer.data(), ibData, indexCount * bytesPerIndex );

if( bytesPerIndex == 2 )
{
std::reverse( reinterpret_cast<uint16_t*>( tempBuffer.data() ), reinterpret_cast<uint16_t*>( tempBuffer.data() + tempBuffer.size() ) );
}
else
{
std::reverse( reinterpret_cast<uint32_t*>( tempBuffer.data() ), reinterpret_cast<uint32_t*>( tempBuffer.data() + tempBuffer.size() ) );
}

CR_RETURN_HR( g_sharedBuffer.Allocate( bytesPerIndex, indexCount, tempBuffer.data(), renderContext, lod.m_reversedIndexAllocation ) );
lod.m_reversedIndicesValid = true;
return S_OK;
}

}


TriGeometryRes::TriGeometryRes( IRoot* lockobj ) :
#if WITH_GRANNY
m_pGrannyFile( NULL ),
Expand Down Expand Up @@ -1862,76 +1799,6 @@ TriGeometryResMeshData::TriGeometryResMeshData() :
{
}

void TriGeometryRes::RequestReversedIndexBuffers()
{
if( !m_isGood )
{
return;
}
if( m_reversedIndexBuffersRequested )
{
return;
}
m_reversedIndexBuffersRequested = true;
if( !m_isPrepared )
{
return;
}

if( IsUsingCMF() && m_sourceGranny )
{
if( !m_sourceGranny->GetCMFData() )
{
return;
}

USE_MAIN_THREAD_RENDER_CONTEXT();

CCP_ASSERT_M( m_meshes.size() == m_sourceGranny->GetCMFData()->meshes.size(), "Amount of meshes should match!" );
for( uint32_t i = 0; i < m_meshes.size(); i++ )
{
auto& mesh = m_meshes[i];
auto& cmfMesh = m_sourceGranny->GetCMFData()->meshes[i];

// this assertion assumes that gTriDev->GetMinimumModelLOD() has not changed since last call to SetupMeshes. Not sure if this holds true.
int minimumLOD = gTriDev->GetMinimumModelLOD() < 0 ? 0 : min( gTriDev->GetMinimumModelLOD(), (int)cmfMesh.lods.size() - 1 );
CCP_ASSERT_M( mesh->m_lods.size() == cmfMesh.lods.size() - minimumLOD, "Amount of mesh lods should match!" );

for( const auto& lod : mesh->m_lods )
{
auto& cmfLod = cmfMesh.lods[lod->m_originalLodIndex];
ReverseIndexBuffer( *lod, m_sourceGranny->GetCMFViewData( cmfLod.ib ), cmfLod, renderContext );
}
}
}
#if WITH_GRANNY
else if( !IsUsingCMF() && m_sourceGranny )
{
granny_file* f = m_sourceGranny->GetGrannyFile();
if( !f )
{
return;
}
granny_file_info* gi = GrannyGetFileInfo( f );

USE_MAIN_THREAD_RENDER_CONTEXT();

for( auto& mesh : m_meshes )
{
for( auto& lod : mesh->m_lods )
{
auto grannyMesh = gi->Meshes[lod->m_grannyMeshIndex];
ReverseIndexBuffer( *lod, *grannyMesh, renderContext );
}
}
}
#endif
else
{
Reload();
}
}

bool TriGeometryRes::RenderAreas( unsigned int meshIx, unsigned int areaIx, unsigned int areaCount, Tr2RenderContext& renderContext, bool reversed )
{
return RenderAreas( std::numeric_limits<float>::max(), meshIx, areaIx, areaCount, renderContext, reversed );
Expand Down Expand Up @@ -2087,27 +1954,24 @@ bool TriGeometryRes::CreateLodFromCMFMesh( Tr2CmfContents& cmfContents, const cm
return false;
}

if( m_reversedIndexBuffersRequested )
std::vector<uint8_t> tempBuffer( indexCount * bytesPerIndex );
memcpy( tempBuffer.data(), pSrcIB, tempBuffer.size() );
if( bytesPerIndex == 2 )
{
std::vector<uint8_t> tempBuffer( indexCount * bytesPerIndex );
memcpy( tempBuffer.data(), pSrcIB, tempBuffer.size() );
if( bytesPerIndex == 2 )
{
std::reverse( reinterpret_cast<uint16_t*>( tempBuffer.data() ), reinterpret_cast<uint16_t*>( tempBuffer.data() + cmfMeshLod.ib.size ) );
}
else
{
std::reverse( reinterpret_cast<uint32_t*>( tempBuffer.data() ), reinterpret_cast<uint32_t*>( tempBuffer.data() + cmfMeshLod.ib.size ) );
}
std::reverse( reinterpret_cast<uint16_t*>( tempBuffer.data() ), reinterpret_cast<uint16_t*>( tempBuffer.data() + cmfMeshLod.ib.size ) );
Comment thread
JohnGreenFC marked this conversation as resolved.
}
else
{
std::reverse( reinterpret_cast<uint32_t*>( tempBuffer.data() ), reinterpret_cast<uint32_t*>( tempBuffer.data() + cmfMeshLod.ib.size ) );
}

if( FAILED( g_sharedBuffer.Allocate( bytesPerIndex, indexCount, tempBuffer.data(), renderContext, lod->m_reversedIndexAllocation ) ) )
{
g_sharedBuffer.Free( lod->m_vertexAllocation );
g_sharedBuffer.Free( lod->m_indexAllocation );
return false;
}
lod->m_reversedIndicesValid = true;
if( FAILED( g_sharedBuffer.Allocate( bytesPerIndex, indexCount, tempBuffer.data(), renderContext, lod->m_reversedIndexAllocation ) ) )
{
g_sharedBuffer.Free( lod->m_vertexAllocation );
g_sharedBuffer.Free( lod->m_indexAllocation );
return false;
}
lod->m_reversedIndicesValid = true;
}

lod->m_morphVertexDeclaration = -1;
Expand Down Expand Up @@ -2170,10 +2034,9 @@ bool TriGeometryRes::CreateLodFromCMFMesh( Tr2CmfContents& cmfContents, const cm
lod->m_allocationsValid = true;

m_memoryUse += vbSize + ibSize; // Memory use is only approximate as a hint for the resource cache
if( m_reversedIndexBuffersRequested )
{
m_memoryUse += ibSize;
}

// Append reversed index buffer size also
m_memoryUse += ibSize;
Comment thread
JohnGreenFC marked this conversation as resolved.

return true;
}
Expand Down Expand Up @@ -2242,25 +2105,22 @@ bool TriGeometryRes::CreateLodFromGrannyMesh( granny_mesh* grannyMesh, TriGeomet
return false;
}

if( m_reversedIndexBuffersRequested )
if( bytesPerIndex == 2 )
{
if( bytesPerIndex == 2 )
{
std::reverse( reinterpret_cast<uint16_t*>( tempBuffer.data() ), reinterpret_cast<uint16_t*>( tempBuffer.data() + tempBuffer.size() ) );
}
else
{
std::reverse( reinterpret_cast<uint32_t*>( tempBuffer.data() ), reinterpret_cast<uint32_t*>( tempBuffer.data() + tempBuffer.size() ) );
}
std::reverse( reinterpret_cast<uint16_t*>( tempBuffer.data() ), reinterpret_cast<uint16_t*>( tempBuffer.data() + tempBuffer.size() ) );
}
else
Comment thread
JohnGreenFC marked this conversation as resolved.
{
std::reverse( reinterpret_cast<uint32_t*>( tempBuffer.data() ), reinterpret_cast<uint32_t*>( tempBuffer.data() + tempBuffer.size() ) );
}

if( FAILED( g_sharedBuffer.Allocate( bytesPerIndex, indexCount, tempBuffer.data(), renderContext, lod->m_reversedIndexAllocation ) ) )
{
g_sharedBuffer.Free( lod->m_vertexAllocation );
g_sharedBuffer.Free( lod->m_indexAllocation );
return false;
}
lod->m_reversedIndicesValid = true;
if( FAILED( g_sharedBuffer.Allocate( bytesPerIndex, indexCount, tempBuffer.data(), renderContext, lod->m_reversedIndexAllocation ) ) )
{
g_sharedBuffer.Free( lod->m_vertexAllocation );
g_sharedBuffer.Free( lod->m_indexAllocation );
return false;
}
lod->m_reversedIndicesValid = true;
}

lod->m_morphVertexDeclaration = -1;
Expand Down Expand Up @@ -2333,10 +2193,9 @@ bool TriGeometryRes::CreateLodFromGrannyMesh( granny_mesh* grannyMesh, TriGeomet
lod->m_allocationsValid = true;

m_memoryUse += vbSize + ibSize; // Memory use is only approximate as a hint for the resource cache
if( m_reversedIndexBuffersRequested )
{
m_memoryUse += ibSize;
}

// Append reversed index buffer size also
m_memoryUse += ibSize;
Comment thread
JohnGreenFC marked this conversation as resolved.

return true;
}
Expand Down
3 changes: 0 additions & 3 deletions trinity/Resources/TriGeometryRes.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ BLUE_CLASS( TriGeometryRes ) :
typedef void ( *PerTriangleCallback )( void* context, const Vector3& p1, const Vector3& p2, const Vector3& p3 );
void ProcessMeshTriangles( int meshIx, PerTriangleCallback cb, void* cbContext );

void RequestReversedIndexBuffers();

void Reload();

// name for logging/debugging
Expand All @@ -375,7 +373,6 @@ BLUE_CLASS( TriGeometryRes ) :

int32_t m_forcedLodIndex = -1;
bool m_forceLod = false;
bool m_reversedIndexBuffersRequested = false;

private:
// Provide the functions that do the actual work of loading and preparing.
Expand Down
9 changes: 0 additions & 9 deletions trinity/Tr2InstancedMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,6 @@ void Tr2InstancedMesh::SetInstanceGeometryRes( ITr2InstanceData* res )
// areas - Vector of mesh areas for which batches need to be added
// data - Per-object data
// --------------------------------------------------------------------------------------
void Tr2InstancedMesh::GetBatches( ITriRenderBatchAccumulator* batches,
const Tr2MeshAreaVector* areas,
const Tr2PerObjectData* data,
float screenSize ) const
{
GetBatches( batches, areas, data, screenSize, false );
}


void Tr2InstancedMesh::GetBatches( ITriRenderBatchAccumulator* batches,
const Tr2MeshAreaVector* areas,
const Tr2PerObjectData* data,
Expand Down
10 changes: 2 additions & 8 deletions trinity/Tr2InstancedMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,8 @@ BLUE_CLASS( Tr2InstancedMesh ) :
void GetBatches( ITriRenderBatchAccumulator * batches,
const Tr2MeshAreaVector* areas,
const Tr2PerObjectData* data,
float screenSize = std::numeric_limits<float>::max() ) const override;


void GetBatches( ITriRenderBatchAccumulator * batches,
const Tr2MeshAreaVector* areas,
const Tr2PerObjectData* data,
float screenSize,
bool reverseAreas ) const;
float screenSize = std::numeric_limits<float>::max(),
bool reverseAreas = false ) const override;

CcpMath::AxisAlignedBox GetBounds( const Matrix* boneTransforms = nullptr, const int32_t* meshBindingIndices = nullptr, size_t boneCount = 0, const Tr2MorphTargetAnimationData* morphTargets = nullptr, size_t morphTargetsCount = 0 ) const override;
CcpMath::AxisAlignedBox GetAreaBounds( unsigned int areaIx, const Matrix* boneTransforms = nullptr ) const override;
Expand Down
20 changes: 0 additions & 20 deletions trinity/Tr2Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ void Tr2Mesh::SetGeometryRes( TriGeometryRes* res )
if( m_geometryResource )
{
m_geometryResource->AddNotifyTarget( this );
if( HasReversedAreas() )
{
m_geometryResource->RequestReversedIndexBuffers();
}
}
}

Expand All @@ -90,10 +86,6 @@ void Tr2Mesh::SetLowResGeometryRes( TriGeometryRes* res )
if( m_lowResGeometryResource )
{
m_lowResGeometryResource->AddNotifyTarget( this );
if( HasReversedAreas() )
{
m_lowResGeometryResource->RequestReversedIndexBuffers();
}
}
}

Expand Down Expand Up @@ -232,18 +224,6 @@ bool Tr2Mesh::IsLoading() const
return !m_loadFence.IsReached();
}

void Tr2Mesh::ReverseIndexBuffers()
{
if( m_geometryResource )
{
m_geometryResource->RequestReversedIndexBuffers();
}
if( m_lowResGeometryResource )
{
m_lowResGeometryResource->RequestReversedIndexBuffers();
}
}

std::vector<std::string>* Tr2Mesh::GetMorphTargetNames() const
{
if( !GetGeometryResource() )
Expand Down
1 change: 0 additions & 1 deletion trinity/Tr2Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ BLUE_CLASS( Tr2Mesh ) :
void SetGeometryRes( TriGeometryRes * res );

bool IsLoading() const override;
void ReverseIndexBuffers() override;

/////////////////////////////////////////////////////////////////////////////////////
// INotify
Expand Down
Loading