Browse Source

plGBufferGroup vertex storage to std::vector

Adam Johnson 10 years ago
parent
commit
a94fc1bf0b
  1. 82
      Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp
  2. 10
      Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h

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

@ -112,7 +112,7 @@ void plGBufferCell::Write( hsStream *s )
plGBufferGroup::plGBufferGroup( uint8_t format, bool vertsVolatile, bool idxVolatile, int LOD ) plGBufferGroup::plGBufferGroup( uint8_t format, bool vertsVolatile, bool idxVolatile, int LOD )
{ {
fVertBuffStorage.Reset(); fVertBuffStorage.clear();
fIdxBuffStorage.Reset(); fIdxBuffStorage.Reset();
fColorBuffStorage.clear(); fColorBuffStorage.clear();
fVertexBufferRefs.Reset(); fVertexBufferRefs.Reset();
@ -202,16 +202,13 @@ void plGBufferGroup::PurgeIndexBuffer(uint32_t idx)
void plGBufferGroup::CleanUp( void ) void plGBufferGroup::CleanUp( void )
{ {
int i;
// Clean up the storage // Clean up the storage
for( i = 0; i < fVertBuffStorage.GetCount(); i++ ) for (size_t i = 0; i < fVertBuffSizes.size(); ++i)
{ {
plProfile_DelMem(MemBufGrpVertex, fVertBuffSizes[i]); plProfile_DelMem(MemBufGrpVertex, fVertBuffSizes[i]);
delete [] fVertBuffStorage[ i ]; delete [] fVertBuffStorage[ i ];
} }
for( i = 0; i < fIdxBuffStorage.GetCount(); i++ ) for (size_t i = 0; i < fIdxBuffStorage.GetCount(); i++)
{ {
plProfile_DelMem(MemBufGrpIndex, fIdxBuffCounts[i] * sizeof(uint16_t)); plProfile_DelMem(MemBufGrpIndex, fIdxBuffCounts[i] * sizeof(uint16_t));
delete [] fIdxBuffStorage[ i ]; delete [] fIdxBuffStorage[ i ];
@ -225,10 +222,10 @@ void plGBufferGroup::CleanUp( void )
for (auto i : fCells) for (auto i : fCells)
delete i; delete i;
fVertBuffStorage.Reset(); fVertBuffStorage.clear();
fVertBuffSizes.Reset(); fVertBuffSizes.clear();
fVertBuffStarts.Reset(); fVertBuffStarts.clear();
fVertBuffEnds.Reset(); fVertBuffEnds.clear();
fIdxBuffStorage.Reset(); fIdxBuffStorage.Reset();
fIdxBuffCounts.Reset(); fIdxBuffCounts.Reset();
fIdxBuffStarts.Reset(); fIdxBuffStarts.Reset();
@ -309,19 +306,14 @@ void plGBufferGroup::ISendStorageToBuffers( plPipeline *pipe, bool adjustForN
plProfile_BeginTiming(DrawRefillVertex); plProfile_BeginTiming(DrawRefillVertex);
/// Creating or refreshing? /// Creating or refreshing?
int i; for (size_t i = 0; i < fVertBuffStorage.size(); i++)
for( i = 0; i < fVertBuffStorage.GetCount(); i++ )
{
pipe->CheckVertexBufferRef(this, i); pipe->CheckVertexBufferRef(this, i);
}
plProfile_EndTiming(DrawRefillVertex); plProfile_EndTiming(DrawRefillVertex);
plProfile_BeginTiming(DrawRefillIndex); plProfile_BeginTiming(DrawRefillIndex);
for( i = 0; i < fIdxBuffStorage.GetCount(); i++ ) for (size_t i = 0; i < fIdxBuffStorage.GetCount(); i++)
{
pipe->CheckIndexBufferRef(this, i); pipe->CheckIndexBufferRef(this, i);
}
plProfile_EndTiming(DrawRefillIndex); plProfile_EndTiming(DrawRefillIndex);
} }
@ -371,14 +363,14 @@ void plGBufferGroup::Read( hsStream *s )
totalDynSize = s->ReadLE32(); totalDynSize = s->ReadLE32();
fStride = ICalcVertexSize( fLiteStride ); fStride = ICalcVertexSize( fLiteStride );
fVertBuffSizes.Reset(); fVertBuffSizes.clear();
fVertBuffStarts.Reset(); fVertBuffStarts.clear();
fVertBuffEnds.Reset(); fVertBuffEnds.clear();
fColorBuffCounts.clear(); fColorBuffCounts.clear();
fIdxBuffCounts.Reset(); fIdxBuffCounts.Reset();
fIdxBuffStarts.Reset(); fIdxBuffStarts.Reset();
fIdxBuffEnds.Reset(); fIdxBuffEnds.Reset();
fVertBuffStorage.Reset(); fVertBuffStorage.clear();
fIdxBuffStorage.Reset(); fIdxBuffStorage.Reset();
plVertCoder coder; plVertCoder coder;
@ -391,12 +383,12 @@ void plGBufferGroup::Read( hsStream *s )
const uint16_t numVerts = s->ReadLE16(); const uint16_t numVerts = s->ReadLE16();
const uint32_t size = numVerts * fStride; const uint32_t size = numVerts * fStride;
fVertBuffSizes.Append(size); fVertBuffSizes.push_back(size);
fVertBuffStarts.Append(0); fVertBuffStarts.push_back(0);
fVertBuffEnds.Append(-1); fVertBuffEnds.push_back(-1);
vData = new uint8_t[size]; vData = new uint8_t[size];
fVertBuffStorage.Append( vData ); fVertBuffStorage.push_back( vData );
plProfile_NewMem(MemBufGrpVertex, temp); plProfile_NewMem(MemBufGrpVertex, temp);
coder.Read(s, vData, fFormat, fStride, numVerts); coder.Read(s, vData, fFormat, fStride, numVerts);
@ -409,14 +401,14 @@ void plGBufferGroup::Read( hsStream *s )
{ {
temp = s->ReadLE32(); temp = s->ReadLE32();
fVertBuffSizes.Append( temp ); fVertBuffSizes.push_back( temp );
fVertBuffStarts.Append(0); fVertBuffStarts.push_back(0);
fVertBuffEnds.Append(-1); fVertBuffEnds.push_back(-1);
vData = new uint8_t[ temp ]; vData = new uint8_t[ temp ];
hsAssert( vData != nil, "Not enough memory to read in vertices" ); hsAssert(vData, "Not enough memory to read in vertices");
s->Read( temp, (void *)vData ); s->Read( temp, (void *)vData );
fVertBuffStorage.Append( vData ); fVertBuffStorage.push_back( vData );
plProfile_NewMem(MemBufGrpVertex, temp); plProfile_NewMem(MemBufGrpVertex, temp);
temp = s->ReadLE32(); temp = s->ReadLE32();
@ -451,7 +443,7 @@ void plGBufferGroup::Read( hsStream *s )
} }
/// Read in cell arrays, one per vBuffer /// Read in cell arrays, one per vBuffer
for( i = 0; i < fVertBuffStorage.GetCount(); i++ ) for( i = 0; i < fVertBuffStorage.size(); i++ )
{ {
temp = s->ReadLE32(); temp = s->ReadLE32();
@ -482,9 +474,9 @@ void plGBufferGroup::Write( hsStream *s )
/// Calc total dynamic data size, for fun /// Calc total dynamic data size, for fun
totalDynSize = 0; totalDynSize = 0;
for( i = 0; i < fVertBuffSizes.GetCount(); i++ ) for (auto it : fVertBuffSizes)
totalDynSize += fVertBuffSizes[ i ]; totalDynSize += it;
for( i = 0; i < fIdxBuffCounts.GetCount(); i++ ) for ( i = 0; i < fIdxBuffCounts.GetCount(); i++ )
totalDynSize += sizeof( uint16_t ) * fIdxBuffCounts[ i ]; totalDynSize += sizeof( uint16_t ) * fIdxBuffCounts[ i ];
s->WriteLE( fFormat ); s->WriteLE( fFormat );
@ -493,8 +485,8 @@ void plGBufferGroup::Write( hsStream *s )
plVertCoder coder; plVertCoder coder;
/// Write out dyanmic data /// Write out dyanmic data
s->WriteLE32( (uint32_t)fVertBuffStorage.GetCount() ); s->WriteLE32( (uint32_t)fVertBuffStorage.size() );
for( i = 0; i < fVertBuffStorage.GetCount(); i++ ) for (i = 0; i < fVertBuffStorage.size(); ++i)
{ {
#ifdef MF_VERTCODE_ENABLED #ifdef MF_VERTCODE_ENABLED
@ -536,7 +528,7 @@ void plGBufferGroup::Write( hsStream *s )
} }
/// Write out cell arrays /// Write out cell arrays
for( i = 0; i < fVertBuffStorage.GetCount(); 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++ )
@ -733,7 +725,7 @@ bool plGBufferGroup::ReserveVertStorage( uint32_t numVerts, uint32_t *vbIndex
/// Find a spot /// Find a spot
if( !(flags & kReserveIsolate) ) if( !(flags & kReserveIsolate) )
{ {
for( i = 0; i < fVertBuffStorage.GetCount(); i++ ) for( i = 0; i < fVertBuffStorage.size(); i++ )
{ {
if( GetNumVertsLeft( i ) >= numVerts ) if( GetNumVertsLeft( i ) >= numVerts )
break; break;
@ -741,17 +733,17 @@ bool plGBufferGroup::ReserveVertStorage( uint32_t numVerts, uint32_t *vbIndex
} }
else else
{ {
i = fVertBuffStorage.GetCount(); i = fVertBuffStorage.size();
} }
if( i == fVertBuffStorage.GetCount() ) if( i == fVertBuffStorage.size() )
{ {
if( (flags & kReserveInterleaved) || (flags & kReserveSeparated) ) if( (flags & kReserveInterleaved) || (flags & kReserveSeparated) )
{ {
fVertBuffStorage.Append( nil ); fVertBuffStorage.push_back(nullptr);
fVertBuffSizes.Append( 0 ); fVertBuffSizes.push_back(0);
} }
fVertBuffStarts.Append(0); fVertBuffStarts.push_back(0);
fVertBuffEnds.Append(-1); fVertBuffEnds.push_back(-1);
fColorBuffStorage.push_back(nullptr); fColorBuffStorage.push_back(nullptr);
fColorBuffCounts.push_back(0); fColorBuffCounts.push_back(0);
@ -1126,7 +1118,7 @@ plGBufferTriangle *plGBufferGroup::ConvertToTriList( int16_t spanIndex, uint32
/// Sanity checks /// Sanity checks
hsAssert( whichIdx < fIdxBuffStorage.GetCount(), "Invalid index buffer ID to ConvertToTriList()" ); hsAssert( whichIdx < fIdxBuffStorage.GetCount(), "Invalid index buffer ID to ConvertToTriList()" );
hsAssert( whichVtx < fVertBuffStorage.GetCount(), "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()" );

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

@ -125,14 +125,14 @@ class plGBufferGroup
hsTArray<hsGDeviceRef *> fVertexBufferRefs; hsTArray<hsGDeviceRef *> fVertexBufferRefs;
hsTArray<hsGDeviceRef *> fIndexBufferRefs; hsTArray<hsGDeviceRef *> fIndexBufferRefs;
hsTArray<uint32_t> fVertBuffSizes; std::vector<uint32_t> fVertBuffSizes;
hsTArray<uint32_t> fIdxBuffCounts; hsTArray<uint32_t> fIdxBuffCounts;
std::vector<uint32_t> fColorBuffCounts; std::vector<uint32_t> fColorBuffCounts;
hsTArray<uint8_t *> fVertBuffStorage; std::vector<uint8_t *> fVertBuffStorage;
hsTArray<uint16_t *> fIdxBuffStorage; hsTArray<uint16_t *> fIdxBuffStorage;
hsTArray<uint32_t> fVertBuffStarts; std::vector<uint32_t> fVertBuffStarts;
hsTArray<int32_t> fVertBuffEnds; std::vector<int32_t> fVertBuffEnds;
hsTArray<uint32_t> fIdxBuffStarts; hsTArray<uint32_t> fIdxBuffStarts;
hsTArray<int32_t> fIdxBuffEnds; hsTArray<int32_t> fIdxBuffEnds;
@ -231,7 +231,7 @@ class plGBufferGroup
void SetIndexBufferEnd(uint32_t idx, uint32_t e) { fIdxBuffEnds[idx] = e; } void SetIndexBufferEnd(uint32_t idx, uint32_t e) { fIdxBuffEnds[idx] = e; }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
uint32_t GetNumVertexBuffers( void ) const { return fVertBuffStorage.GetCount(); } uint32_t GetNumVertexBuffers( void ) const { return fVertBuffStorage.size(); }
uint32_t GetNumIndexBuffers( void ) const { return fIdxBuffStorage.GetCount(); } uint32_t GetNumIndexBuffers( void ) const { return fIdxBuffStorage.GetCount(); }
uint8_t *GetVertBufferData( uint32_t idx ) { return fVertBuffStorage[ idx ]; } uint8_t *GetVertBufferData( uint32_t idx ) { return fVertBuffStorage[ idx ]; }

Loading…
Cancel
Save