mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
gl_engine: Fix memory leak in the IndexBuffer object
The CPU buffer cache in the IndexBuffer object needs to be cleared, otherwise it will cause memory leaks and reduce performance per frame
This commit is contained in:
parent
4aaa0dafc4
commit
95d99ee74b
3 changed files with 14 additions and 6 deletions
|
@ -117,9 +117,13 @@ uint32_t GlStageBuffer::pushIndex(void *data, uint32_t size)
|
|||
return offset;
|
||||
}
|
||||
|
||||
void GlStageBuffer::flushToGPU()
|
||||
bool GlStageBuffer::flushToGPU()
|
||||
{
|
||||
if (mStageBuffer.empty()) return;
|
||||
if (mStageBuffer.empty() || mIndexBuffer.empty()) {
|
||||
mStageBuffer.clear();
|
||||
mIndexBuffer.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
mGpuBuffer.bind(GlGpuBuffer::Target::ARRAY_BUFFER);
|
||||
|
@ -131,6 +135,9 @@ void GlStageBuffer::flushToGPU()
|
|||
mGpuIndexBuffer.unbind(GlGpuBuffer::Target::ELEMENT_ARRAY_BUFFER);
|
||||
|
||||
mStageBuffer.clear();
|
||||
mIndexBuffer.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GlStageBuffer::bind()
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
|
||||
uint32_t pushIndex(void* data, uint32_t size);
|
||||
|
||||
void flushToGPU();
|
||||
bool flushToGPU();
|
||||
|
||||
void bind();
|
||||
|
||||
|
|
|
@ -863,10 +863,11 @@ bool GlRenderer::sync()
|
|||
task->mClearBuffer = mClearBuffer;
|
||||
task->setTargetViewport({0, 0, static_cast<int32_t>(surface.w), static_cast<int32_t>(surface.h)});
|
||||
|
||||
mGpuBuffer->flushToGPU();
|
||||
mGpuBuffer->bind();
|
||||
if (mGpuBuffer->flushToGPU()) {
|
||||
mGpuBuffer->bind();
|
||||
|
||||
task->run();
|
||||
task->run();
|
||||
}
|
||||
|
||||
mGpuBuffer->unbind();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue