Add delete vertex buffer to save memory for no graphics
This commit is contained in:
parent
930c2c004d
commit
37cf5ac459
@ -66,6 +66,10 @@ namespace scene
|
||||
indices have changed. Otherwise, changes won't be updated
|
||||
on the GPU in the next render cycle. */
|
||||
virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) = 0;
|
||||
|
||||
/** This is used in server without graphics to free all mesh vertex buffer if
|
||||
possible, for example: kart, attachment and power model (because they are not used in physics). */
|
||||
virtual void freeMeshVertexBuffer() {}
|
||||
};
|
||||
|
||||
} // end namespace scene
|
||||
|
@ -23,7 +23,7 @@ CSkinnedMesh::CSkinnedMesh()
|
||||
LastAnimatedFrame(-1), SkinnedLastFrame(false),
|
||||
InterpolationMode(EIM_LINEAR),
|
||||
HasAnimation(false), PreparedForSkinning(false),
|
||||
AnimateNormals(true), HardwareSkinning(false)
|
||||
AnimateNormals(true), m_deleted_vertex_buffer(false)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("CSkinnedMesh");
|
||||
@ -74,12 +74,8 @@ void CSkinnedMesh::setAnimationSpeed(f32 fps)
|
||||
//! returns the animated mesh based on a detail level. 0 is the lowest, 255 the highest detail. Note, that some Meshes will ignore the detail level.
|
||||
IMesh* CSkinnedMesh::getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop, s32 endFrameLoop)
|
||||
{
|
||||
const bool is_hw_skinning_before = HardwareSkinning;
|
||||
if (is_hw_skinning_before)
|
||||
{
|
||||
HardwareSkinning = false;
|
||||
LastAnimatedFrame = -1;
|
||||
}
|
||||
if (m_deleted_vertex_buffer)
|
||||
return this;
|
||||
//animate(frame,startFrameLoop, endFrameLoop);
|
||||
if (frame==-1)
|
||||
return this;
|
||||
@ -87,9 +83,6 @@ IMesh* CSkinnedMesh::getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop, s32
|
||||
animateMesh((f32)frame, 1.0f);
|
||||
skinMesh();
|
||||
|
||||
if (is_hw_skinning_before)
|
||||
HardwareSkinning = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -103,7 +96,7 @@ IMesh* CSkinnedMesh::getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop, s32
|
||||
//! blend: {0-old position, 1-New position}
|
||||
void CSkinnedMesh::animateMesh(f32 frame, f32 blend)
|
||||
{
|
||||
if (HardwareSkinning && LastAnimatedFrame==frame)
|
||||
if (LastAnimatedFrame==frame)
|
||||
{
|
||||
SkinnedLastFrame=false;
|
||||
return;
|
||||
@ -732,20 +725,6 @@ const core::array<CSkinnedMesh::SJoint*> &CSkinnedMesh::getAllJoints() const
|
||||
return AllJoints;
|
||||
}
|
||||
|
||||
|
||||
//! (This feature is not implementated in irrlicht yet)
|
||||
bool CSkinnedMesh::setHardwareSkinning(bool on)
|
||||
{
|
||||
if (HardwareSkinning!=on)
|
||||
{
|
||||
if (on)
|
||||
toStaticPose();
|
||||
|
||||
HardwareSkinning=on;
|
||||
}
|
||||
return HardwareSkinning;
|
||||
}
|
||||
|
||||
void CSkinnedMesh::toStaticPose()
|
||||
{
|
||||
for (u32 i=0; i<AllJoints.size(); ++i)
|
||||
@ -1154,7 +1133,7 @@ void CSkinnedMesh::finalize()
|
||||
|
||||
void CSkinnedMesh::updateBoundingBox(void)
|
||||
{
|
||||
if(HardwareSkinning || !SkinningBuffers)
|
||||
if (!SkinningBuffers)
|
||||
return;
|
||||
|
||||
core::array<SSkinMeshBuffer*> & buffer = *SkinningBuffers;
|
||||
@ -1397,6 +1376,27 @@ void CSkinnedMesh::addJoints(core::array<IBoneSceneNode*> &jointChildSceneNodes,
|
||||
SkinnedLastFrame=false;
|
||||
}
|
||||
|
||||
void CSkinnedMesh::freeMeshVertexBuffer()
|
||||
{
|
||||
if (m_deleted_vertex_buffer)
|
||||
return;
|
||||
for (u32 i=0; i<AllJoints.size(); ++i)
|
||||
delete AllJoints[i];
|
||||
|
||||
for (u32 j=0; j<LocalBuffers.size(); ++j)
|
||||
{
|
||||
if (LocalBuffers[j])
|
||||
{
|
||||
LocalBuffers[j]->Vertices_Tangents.clear();
|
||||
LocalBuffers[j]->Vertices_2TCoords.clear();
|
||||
LocalBuffers[j]->Vertices_Standard.clear();
|
||||
LocalBuffers[j]->Indices.clear();
|
||||
}
|
||||
}
|
||||
AllJoints.clear();
|
||||
m_deleted_vertex_buffer = true;
|
||||
}
|
||||
|
||||
} // end namespace scene
|
||||
} // end namespace irr
|
||||
|
||||
|
@ -117,7 +117,7 @@ namespace scene
|
||||
virtual bool isStatic();
|
||||
|
||||
//! (This feature is not implemented in irrlicht yet)
|
||||
virtual bool setHardwareSkinning(bool on);
|
||||
virtual bool setHardwareSkinning(bool on) { return false; }
|
||||
|
||||
//Interface for the mesh loaders (finalize should lock these functions, and they should have some prefix like loader_
|
||||
//these functions will use the needed arrays, set values, etc to help the loaders
|
||||
@ -176,6 +176,8 @@ namespace scene
|
||||
|
||||
core::array<SJoint*> RootJoints;
|
||||
|
||||
virtual void freeMeshVertexBuffer();
|
||||
|
||||
private:
|
||||
void toStaticPose();
|
||||
|
||||
@ -222,7 +224,7 @@ private:
|
||||
bool HasAnimation;
|
||||
bool PreparedForSkinning;
|
||||
bool AnimateNormals;
|
||||
bool HardwareSkinning;
|
||||
bool m_deleted_vertex_buffer;
|
||||
};
|
||||
|
||||
} // end namespace scene
|
||||
|
Loading…
Reference in New Issue
Block a user