Browse Source

Nuke totally unnesecary vector pointer

Adam Johnson 10 years ago
parent
commit
f48a80ab60
  1. 72
      Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp
  2. 6
      Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h

72
Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp

@ -205,9 +205,6 @@ void plGBufferGroup::CleanUp( void )
delete [] fColorBuffStorage[ i ]; delete [] fColorBuffStorage[ i ];
} }
for (auto i : fCells)
delete i;
fVertBuffStorage.clear(); fVertBuffStorage.clear();
fVertBuffSizes.clear(); fVertBuffSizes.clear();
fVertBuffStarts.clear(); fVertBuffStarts.clear();
@ -440,16 +437,15 @@ void plGBufferGroup::Read( hsStream *s )
} }
/// Read in cell arrays, one per vBuffer /// Read in cell arrays, one per vBuffer
fCells.reserve(fVertBuffStorage.size()); fCells.resize(fVertBuffStorage.size());
for( i = 0; i < fVertBuffStorage.size(); i++ ) for( i = 0; i < fVertBuffStorage.size(); i++ )
{ {
temp = s->ReadLE32(); temp = s->ReadLE32();
fCells.push_back( new std::vector<plGBufferCell> ); fCells[ i ].resize( temp );
fCells[ i ]->resize( temp );
for( j = 0; j < temp; j++ ) for( j = 0; j < temp; j++ )
(*fCells[ i ])[ j ].Read( s ); fCells[ i ][ j ].Read( s );
} }
} }
@ -488,7 +484,7 @@ void plGBufferGroup::Write( hsStream *s )
{ {
#ifdef MF_VERTCODE_ENABLED #ifdef MF_VERTCODE_ENABLED
hsAssert(fCells[i]->size() == 1, "Data must be interleaved for compression"); hsAssert(fCells[i].size() == 1, "Data must be interleaved for compression");
uint32_t numVerts = fVertBuffSizes[i] / fStride; uint32_t numVerts = fVertBuffSizes[i] / fStride;
s->WriteLE16((uint16_t)numVerts); s->WriteLE16((uint16_t)numVerts);
coder.Write(s, fVertBuffStorage[i], fFormat, fStride, (uint16_t)numVerts); coder.Write(s, fVertBuffStorage[i], fFormat, fStride, (uint16_t)numVerts);
@ -528,9 +524,9 @@ void plGBufferGroup::Write( hsStream *s )
/// Write out cell arrays /// Write out cell arrays
for (i = 0; i < fVertBuffStorage.size(); i++) for (i = 0; i < fVertBuffStorage.size(); i++)
{ {
s->WriteLE32( fCells[ i ]->size() ); s->WriteLE32( fCells[ i ].size() );
for( j = 0; j < fCells[ i ]->size(); j++ ) for( j = 0; j < fCells[ i ].size(); j++ )
(*fCells[ i ])[ j ].Write( s ); fCells[ i ][ j ].Write( s );
} }
#ifdef VERT_LOG #ifdef VERT_LOG
@ -557,10 +553,10 @@ void plGBufferGroup::DeleteVertsFromStorage( uint32_t which, uint32_t start,
uint32_t amount; uint32_t amount;
hsAssert( fCells[ which ]->size() == 1, "Cannot delete verts on a mixed buffer group" ); hsAssert( fCells[ which ].size() == 1, "Cannot delete verts on a mixed buffer group" );
// Adjust cell 0 // Adjust cell 0
(*fCells[ which ])[ 0 ].fLength -= length; fCells[ which ][ 0 ].fLength -= length;
start *= fStride; start *= fStride;
length *= fStride; length *= fStride;
@ -656,7 +652,7 @@ uint32_t plGBufferGroup::GetNumVertsLeft( uint32_t idx ) const
return kMaxNumVertsPerBuffer; return kMaxNumVertsPerBuffer;
uint32_t total = kMaxNumVertsPerBuffer; uint32_t total = kMaxNumVertsPerBuffer;
for( const auto& i : *fCells[ idx ] ) for( const auto& i : fCells[ idx ] )
total -= i.fLength; total -= i.fLength;
return total; return total;
@ -667,7 +663,7 @@ uint32_t plGBufferGroup::GetNumVertsLeft( uint32_t idx ) const
uint32_t plGBufferGroup::IMakeCell( uint32_t vbIndex, uint8_t flags, uint32_t vStart, uint32_t cStart, uint32_t len, uint32_t *offset ) uint32_t plGBufferGroup::IMakeCell( uint32_t vbIndex, uint8_t flags, uint32_t vStart, uint32_t cStart, uint32_t len, uint32_t *offset )
{ {
std::vector<plGBufferCell>* cells = fCells[ vbIndex ]; std::vector<plGBufferCell>& cells = fCells[ vbIndex ];
if( !(flags & kReserveInterleaved) ) if( !(flags & kReserveInterleaved) )
@ -678,27 +674,27 @@ uint32_t plGBufferGroup::IMakeCell( uint32_t vbIndex, uint8_t flags, uint32_t v
/// we never merge any separated cells /// we never merge any separated cells
if( flags & kReserveSeparated ) if( flags & kReserveSeparated )
cells->emplace_back(vStart, cStart, len); cells.emplace_back(vStart, cStart, len);
else else
cells->emplace_back((uint32_t)-1, cStart, len); cells.emplace_back((uint32_t)-1, cStart, len);
*offset = 0; *offset = 0;
} }
else else
{ {
/// Merge if the last cell was an interleaved cell /// Merge if the last cell was an interleaved cell
if( !cells->empty() && cells->back().fColorStart == (uint32_t)-1 ) if( !cells.empty() && cells.back().fColorStart == (uint32_t)-1 )
{ {
*offset = cells->back().fLength; *offset = cells.back().fLength;
cells->back().fLength += len; cells.back().fLength += len;
} }
else else
{ {
cells->emplace_back(vStart, (uint32_t)-1, len); cells.emplace_back(vStart, (uint32_t)-1, len);
*offset = 0; *offset = 0;
} }
} }
return cells->size() - 1; return cells.size() - 1;
} }
//// ReserveVertStorage /////////////////////////////////////////////////////// //// ReserveVertStorage ///////////////////////////////////////////////////////
@ -746,7 +742,7 @@ bool plGBufferGroup::ReserveVertStorage( uint32_t numVerts, uint32_t *vbIndex
fColorBuffStorage.push_back(nullptr); fColorBuffStorage.push_back(nullptr);
fColorBuffCounts.push_back(0); fColorBuffCounts.push_back(0);
fCells.push_back( new std::vector<plGBufferCell> ); fCells.emplace_back();
} }
*vbIndex = i; *vbIndex = i;
@ -852,7 +848,7 @@ void plGBufferGroup::AppendToColorStorage( plGeometrySpan *srcSpan, uint32_t
if( !ReserveVertStorage( srcSpan->fNumVerts, vbIndex, cell, offset, kReserveColors ) ) if( !ReserveVertStorage( srcSpan->fNumVerts, vbIndex, cell, offset, kReserveColors ) )
return; return;
(*fCells[ *vbIndex ])[ *cell ].fVtxStart = (*fCells[ *vbIndex ])[ origCell ].fVtxStart; fCells[ *vbIndex ][ *cell ].fVtxStart = fCells[ *vbIndex ][ origCell ].fVtxStart;
StuffToVertStorage( srcSpan, *vbIndex, *cell, *offset, kReserveColors ); StuffToVertStorage( srcSpan, *vbIndex, *cell, *offset, kReserveColors );
} }
@ -863,17 +859,17 @@ void plGBufferGroup::AppendToColorStorage( plGeometrySpan *srcSpan, uint32_t
void plGBufferGroup::IGetStartVtxPointer( uint32_t vbIndex, uint32_t cell, uint32_t offset, uint8_t *&tempPtr, plGBufferColor *&cPtr ) void plGBufferGroup::IGetStartVtxPointer( uint32_t vbIndex, uint32_t cell, uint32_t offset, uint8_t *&tempPtr, plGBufferColor *&cPtr )
{ {
hsAssert( vbIndex < fVertBuffStorage.size(), "Invalid vbIndex in StuffToVertStorage()" ); hsAssert( vbIndex < fVertBuffStorage.size(), "Invalid vbIndex in StuffToVertStorage()" );
hsAssert( cell < fCells[ vbIndex ]->size(), "Invalid cell in StuffToVertStorage()" ); hsAssert( cell < fCells[ vbIndex ].size(), "Invalid cell in StuffToVertStorage()" );
tempPtr = fVertBuffStorage[ vbIndex ]; tempPtr = fVertBuffStorage[ vbIndex ];
cPtr = fColorBuffStorage[ vbIndex ]; cPtr = fColorBuffStorage[ vbIndex ];
tempPtr += (*fCells[ vbIndex ])[ cell ].fVtxStart; tempPtr += fCells[ vbIndex ][ cell ].fVtxStart;
cPtr += (*fCells[ vbIndex ])[ cell ].fColorStart; cPtr += fCells[ vbIndex ][ cell ].fColorStart;
if( offset > 0 ) if( offset > 0 )
{ {
tempPtr += offset * ( ( (*fCells[ vbIndex ])[ cell ].fColorStart == (uint32_t)-1 ) ? fStride : fLiteStride ); tempPtr += offset * ( ( fCells[ vbIndex ][ cell ].fColorStart == (uint32_t)-1 ) ? fStride : fLiteStride );
cPtr += offset; cPtr += offset;
} }
} }
@ -882,7 +878,7 @@ void plGBufferGroup::IGetStartVtxPointer( uint32_t vbIndex, uint32_t cell, ui
uint32_t plGBufferGroup::GetVertBufferCount( uint32_t idx ) const uint32_t plGBufferGroup::GetVertBufferCount( uint32_t idx ) const
{ {
return GetVertStartFromCell( idx, fCells[ idx ]->size(), 0 ); return GetVertStartFromCell( idx, fCells[ idx ].size(), 0 );
} }
//// GetVertStartFromCell ///////////////////////////////////////////////////// //// GetVertStartFromCell /////////////////////////////////////////////////////
@ -893,11 +889,11 @@ uint32_t plGBufferGroup::GetVertStartFromCell( uint32_t vbIndex, uint32_t cell,
hsAssert( vbIndex < fVertBuffStorage.size(), "Invalid vbIndex in StuffToVertStorage()" ); hsAssert( vbIndex < fVertBuffStorage.size(), "Invalid vbIndex in StuffToVertStorage()" );
hsAssert( cell <= fCells[ vbIndex ]->size(), "Invalid cell in StuffToVertStorage()" ); hsAssert( cell <= fCells[ vbIndex ].size(), "Invalid cell in StuffToVertStorage()" );
numVerts = 0; numVerts = 0;
for( i = 0; i < cell; i++ ) for( i = 0; i < cell; i++ )
numVerts += (*fCells[ vbIndex ])[ i ].fLength; numVerts += fCells[ vbIndex ][ i ].fLength;
numVerts += offset; numVerts += offset;
@ -917,10 +913,10 @@ void plGBufferGroup::StuffToVertStorage( plGeometrySpan *srcSpan, uint32_t vb
hsAssert( vbIndex < fVertBuffStorage.size(), "Invalid vbIndex in StuffToVertStorage()" ); hsAssert( vbIndex < fVertBuffStorage.size(), "Invalid vbIndex in StuffToVertStorage()" );
hsAssert( cell < fCells[ vbIndex ]->size(), "Invalid cell in StuffToVertStorage()" ); hsAssert( cell < fCells[ vbIndex ].size(), "Invalid cell in StuffToVertStorage()" );
IGetStartVtxPointer( vbIndex, cell, offset, tempPtr, cPtr ); IGetStartVtxPointer( vbIndex, cell, offset, tempPtr, cPtr );
cellPtr = &(*fCells[ vbIndex ])[ cell ]; cellPtr = &fCells[ vbIndex ][ cell ];
stride = ( cellPtr->fColorStart != (uint32_t)-1 ) ? fLiteStride : fStride; stride = ( cellPtr->fColorStart != (uint32_t)-1 ) ? fLiteStride : fStride;
numVerts = srcSpan->fNumVerts; numVerts = srcSpan->fNumVerts;
@ -1119,7 +1115,7 @@ plGBufferTriangle *plGBufferGroup::ConvertToTriList( int16_t spanIndex, uint32
hsAssert( whichVtx < fVertBuffStorage.size(), "Invalid vertex buffer ID to ConvertToTriList()" ); hsAssert( whichVtx < fVertBuffStorage.size(), "Invalid vertex buffer ID to ConvertToTriList()" );
hsAssert( start < fIdxBuffCounts[ whichIdx ], "Invalid start index to ConvertToTriList()" ); hsAssert( start < fIdxBuffCounts[ whichIdx ], "Invalid start index to ConvertToTriList()" );
hsAssert( start + numTriangles * 3 <= fIdxBuffCounts[ whichIdx ], "Invalid count to ConvertToTriList()" ); hsAssert( start + numTriangles * 3 <= fIdxBuffCounts[ whichIdx ], "Invalid count to ConvertToTriList()" );
hsAssert( whichCell < fCells[ whichVtx ]->size(), "Invalid cell to ConvertToTriList()" ); hsAssert( whichCell < fCells[ whichVtx ].size(), "Invalid cell to ConvertToTriList()" );
/// Create the array and fill it /// Create the array and fill it
array = new plGBufferTriangle[ numTriangles ]; array = new plGBufferTriangle[ numTriangles ];
@ -1128,7 +1124,7 @@ plGBufferTriangle *plGBufferGroup::ConvertToTriList( int16_t spanIndex, uint32
storagePtr = fIdxBuffStorage[ whichIdx ]; storagePtr = fIdxBuffStorage[ whichIdx ];
IGetStartVtxPointer( whichVtx, whichCell, 0, vertStgPtr, wastePtr ); IGetStartVtxPointer( whichVtx, whichCell, 0, vertStgPtr, wastePtr );
offsetBy = GetVertStartFromCell( whichVtx, whichCell, 0 ); offsetBy = GetVertStartFromCell( whichVtx, whichCell, 0 );
stride = ( (*fCells[ whichVtx ])[ whichCell ].fColorStart == (uint32_t)-1 ) ? fStride : fLiteStride; stride = ( fCells[ whichVtx ][ whichCell ].fColorStart == (uint32_t)-1 ) ? fStride : fLiteStride;
for( i = 0, j = 0; i < numTriangles; i++, j += 3 ) for( i = 0, j = 0; i < numTriangles; i++, j += 3 )
{ {
@ -1246,7 +1242,7 @@ uint32_t &plGBufferGroup::Color( int iBuff, uint32_t cell, int iVtx )
IGetStartVtxPointer( iBuff, cell, iVtx, vertStgPtr, cPtr ); IGetStartVtxPointer( iBuff, cell, iVtx, vertStgPtr, cPtr );
if( (*fCells[ iBuff ])[ cell ].fColorStart != (uint32_t)-1 ) if( fCells[ iBuff ][ cell ].fColorStart != (uint32_t)-1 )
return *(uint32_t *)( &cPtr->fDiffuse ); return *(uint32_t *)( &cPtr->fDiffuse );
else else
return *(uint32_t *)( vertStgPtr + 2 * sizeof( hsPoint3 ) ); return *(uint32_t *)( vertStgPtr + 2 * sizeof( hsPoint3 ) );
@ -1259,7 +1255,7 @@ uint32_t &plGBufferGroup::Specular( int iBuff, uint32_t cell, int iVtx )
IGetStartVtxPointer( iBuff, cell, iVtx, vertStgPtr, cPtr ); IGetStartVtxPointer( iBuff, cell, iVtx, vertStgPtr, cPtr );
if( (*fCells[ iBuff ])[ cell ].fColorStart != (uint32_t)-1 ) if( fCells[ iBuff ][ cell ].fColorStart != (uint32_t)-1 )
return *(uint32_t *)( &cPtr->fSpecular ); return *(uint32_t *)( &cPtr->fSpecular );
else else
return *(uint32_t *)( vertStgPtr + 2 * sizeof( hsPoint3 ) ); return *(uint32_t *)( vertStgPtr + 2 * sizeof( hsPoint3 ) );
@ -1274,7 +1270,7 @@ hsPoint3 &plGBufferGroup::UV( int iBuff, uint32_t cell, int iVtx, int channel
vertStgPtr += 2 * sizeof( hsPoint3 ) + channel * sizeof( hsPoint3 ); vertStgPtr += 2 * sizeof( hsPoint3 ) + channel * sizeof( hsPoint3 );
if( (*fCells[ iBuff ])[ cell ].fColorStart != (uint32_t)-1 ) if( fCells[ iBuff ][ cell ].fColorStart != (uint32_t)-1 )
return *(hsPoint3 *)( vertStgPtr ); return *(hsPoint3 *)( vertStgPtr );
else else
return *(hsPoint3 *)( vertStgPtr + 2 * sizeof( uint32_t ) ); return *(hsPoint3 *)( vertStgPtr + 2 * sizeof( uint32_t ) );

6
Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h

@ -138,7 +138,7 @@ class plGBufferGroup
std::vector<plGBufferColor*> fColorBuffStorage; std::vector<plGBufferColor*> fColorBuffStorage;
std::vector<std::vector<plGBufferCell>*> fCells; std::vector<std::vector<plGBufferCell>> fCells;
virtual void ISendStorageToBuffers( plPipeline *pipe, bool adjustForNvidiaLighting ); virtual void ISendStorageToBuffers( plPipeline *pipe, bool adjustForNvidiaLighting );
@ -241,8 +241,8 @@ class plGBufferGroup
hsGDeviceRef *GetVertexBufferRef( uint32_t i ); hsGDeviceRef *GetVertexBufferRef( uint32_t i );
hsGDeviceRef *GetIndexBufferRef( uint32_t i ); hsGDeviceRef *GetIndexBufferRef( uint32_t i );
size_t GetNumCells( size_t idx ) const { return fCells[ idx ]->size(); } size_t GetNumCells( size_t idx ) const { return fCells[ idx ].size(); }
plGBufferCell *GetCell( size_t idx, size_t cell ) { return &( (*fCells[ idx ])[ cell ] ); } plGBufferCell *GetCell( size_t idx, size_t cell ) { return &(fCells[ idx ][ cell ]); }
void SetVertexBufferRef( uint32_t index, hsGDeviceRef *vb ); void SetVertexBufferRef( uint32_t index, hsGDeviceRef *vb );
void SetIndexBufferRef( uint32_t index, hsGDeviceRef *ib ); void SetIndexBufferRef( uint32_t index, hsGDeviceRef *ib );

Loading…
Cancel
Save