- use separate vertex buffers per model to avoid large memory usage peaks. Also delete the geometry data for the models once it has been copied into the vertex buffer.
This commit is contained in:
parent
bca47bb9bc
commit
e5cd90f323
8 changed files with 281 additions and 101 deletions
|
|
@ -206,65 +206,97 @@ bool FDMDModel::Load(const char * path, int, const char * buffer, int length)
|
|||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
FDMDModel::~FDMDModel()
|
||||
{
|
||||
int i;
|
||||
CleanTempData();
|
||||
|
||||
// clean up
|
||||
if (skins != NULL)
|
||||
{
|
||||
// skins are managed by the texture manager so they must not be deleted here.
|
||||
delete [] skins;
|
||||
}
|
||||
// skins are managed by the texture manager so they must not be deleted here.
|
||||
if (skins != NULL) delete [] skins;
|
||||
if (frames != NULL) delete [] frames;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Deletes everything that's no longer needed after building the vertex buffer
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FDMDModel::CleanTempData()
|
||||
{
|
||||
int i;
|
||||
|
||||
if (frames != NULL)
|
||||
{
|
||||
for (i=0;i<info.numFrames;i++)
|
||||
{
|
||||
delete [] frames[i].vertices;
|
||||
delete [] frames[i].normals;
|
||||
if (frames[i].vertices != NULL) delete [] frames[i].vertices;
|
||||
if (frames[i].normals != NULL) delete [] frames[i].normals;
|
||||
|
||||
frames[i].vertices = NULL;
|
||||
frames[i].normals = NULL;
|
||||
}
|
||||
delete [] frames;
|
||||
}
|
||||
|
||||
for(i = 0; i < info.numLODs; i++)
|
||||
{
|
||||
if (lods[i].triangles != NULL) delete[] lods[i].triangles;
|
||||
lods[i].triangles = NULL;
|
||||
}
|
||||
|
||||
if (texCoords != NULL) delete[] texCoords;
|
||||
texCoords = NULL;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void FDMDModel::BuildVertexBuffer(FModelVertexBuffer *buf)
|
||||
void FDMDModel::BuildVertexBuffer()
|
||||
{
|
||||
for (int i = 0; i < info.numFrames; i++)
|
||||
if (mVBuf == NULL)
|
||||
{
|
||||
ModelFrame *frame = &frames[i];
|
||||
DMDModelVertex *vert = frame->vertices;
|
||||
DMDModelVertex *norm = frame->normals;
|
||||
int VertexBufferSize = info.numFrames * lodInfo[0].numTriangles * 3;
|
||||
unsigned int vindex = 0;
|
||||
|
||||
frame->vindex = buf->vbo_shadowdata.Size();
|
||||
mVBuf = new FModelVertexBuffer(false);
|
||||
FModelVertex *vertptr = mVBuf->LockVertexBuffer(VertexBufferSize);
|
||||
|
||||
|
||||
FTriangle *tri = lods[0].triangles;
|
||||
|
||||
for (int i = 0; i < lodInfo[0].numTriangles; i++)
|
||||
for (int i = 0; i < info.numFrames; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
ModelFrame *frame = &frames[i];
|
||||
DMDModelVertex *vert = frame->vertices;
|
||||
DMDModelVertex *norm = frame->normals;
|
||||
|
||||
frame->vindex = vindex;
|
||||
|
||||
|
||||
FTriangle *tri = lods[0].triangles;
|
||||
|
||||
for (int i = 0; i < lodInfo[0].numTriangles; i++)
|
||||
{
|
||||
FModelVertex bvert;
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
|
||||
int ti = tri->textureIndices[j];
|
||||
int vi = tri->vertexIndices[j];
|
||||
int ti = tri->textureIndices[j];
|
||||
int vi = tri->vertexIndices[j];
|
||||
|
||||
bvert.Set(vert[vi].xyz[0], vert[vi].xyz[1], vert[vi].xyz[2], (float)texCoords[ti].s /info.skinWidth, (float)texCoords[ti].t/info.skinHeight);
|
||||
bvert.SetNormal(norm[vi].xyz[0], norm[vi].xyz[1], norm[vi].xyz[2]);
|
||||
buf->vbo_shadowdata.Push(bvert);
|
||||
FModelVertex *bvert = &vertptr[vindex++];
|
||||
bvert->Set(vert[vi].xyz[0], vert[vi].xyz[1], vert[vi].xyz[2], (float)texCoords[ti].s / info.skinWidth, (float)texCoords[ti].t / info.skinHeight);
|
||||
bvert->SetNormal(norm[vi].xyz[0], norm[vi].xyz[1], norm[vi].xyz[2]);
|
||||
}
|
||||
tri++;
|
||||
}
|
||||
tri++;
|
||||
}
|
||||
|
||||
mVBuf->UnlockVertexBuffer();
|
||||
CleanTempData();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -307,7 +339,7 @@ void FDMDModel::RenderFrame(FTexture * skin, int frameno, int frameno2, double i
|
|||
gl_RenderState.SetInterpolationFactor((float)inter);
|
||||
|
||||
gl_RenderState.Apply();
|
||||
GLRenderer->mModelVBO->SetupFrame(frames[frameno].vindex, frames[frameno2].vindex);
|
||||
mVBuf->SetupFrame(frames[frameno].vindex, frames[frameno2].vindex);
|
||||
glDrawArrays(GL_TRIANGLES, 0, lodInfo[0].numTriangles * 3);
|
||||
gl_RenderState.SetInterpolationFactor(0.f);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue