| 31 | } |
| 32 | |
| 33 | void Tr2Model::GetBatches( ITriRenderBatchAccumulator* batches, |
| 34 | TriBatchType batchType, |
| 35 | const Matrix& m, |
| 36 | const Tr2PerObjectData* data ) |
| 37 | { |
| 38 | Matrix* pm = batches->Allocate<Matrix>(); |
| 39 | |
| 40 | CCP_ASSERT_M( pm, "No memory available for opaque batches." ); |
| 41 | if( pm == NULL ) |
| 42 | { |
| 43 | return; |
| 44 | } |
| 45 | *pm = m; |
| 46 | |
| 47 | // Transparent batches are sorted by the mesh bounding box order |
| 48 | if( batchType == TRIBATCHTYPE_TRANSPARENT ) |
| 49 | { |
| 50 | Tr2MeshItemList meshesToSort( "Tr2Model/GetBatches" ); |
| 51 | |
| 52 | const Vector3 viewPos = Tr2Renderer::GetViewPosition(); |
| 53 | |
| 54 | unsigned int meshCount = (unsigned int)m_meshes.size(); |
| 55 | for( unsigned int meshIx = 0; meshIx < meshCount; ++meshIx ) |
| 56 | { |
| 57 | Tr2Mesh* pMesh = m_meshes[meshIx]; |
| 58 | if( pMesh->GetDisplay() ) |
| 59 | { |
| 60 | Tr2MeshItem item; |
| 61 | item.m_mesh = pMesh; |
| 62 | |
| 63 | auto center = TransformCoord( pMesh->GetBounds().Center(), m ); |
| 64 | item.m_distance = LengthSq( center - viewPos ); |
| 65 | meshesToSort.push_back( item ); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // Sort the list back to front |
| 70 | std::sort( meshesToSort.begin(), meshesToSort.end() ); |
| 71 | |
| 72 | // Now get the batches in order |
| 73 | for( Tr2MeshItemList::iterator meshIt = meshesToSort.begin(); |
| 74 | meshIt != meshesToSort.end(); |
| 75 | ++meshIt ) |
| 76 | { |
| 77 | Tr2Mesh* mesh = meshIt->m_mesh; |
| 78 | GetBatchesFromMesh( mesh, batchType, batches, pm, data ); |
| 79 | } |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | // In all other cases, we just get the batches in order |
| 84 | for( Tr2MeshVector::iterator meshIt = m_meshes.begin(); |
| 85 | meshIt != m_meshes.end(); |
| 86 | ++meshIt ) |
| 87 | { |
| 88 | Tr2Mesh* mesh = *meshIt; |
| 89 | GetBatchesFromMesh( mesh, batchType, batches, pm, data ); |
| 90 | } |
no test coverage detected