Skip to content

Commit

Permalink
Preallocate upfront each frame
Browse files Browse the repository at this point in the history
  • Loading branch information
JCash committed Mar 26, 2023
1 parent 4ada1fc commit 20c7ef4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion defold-spine/commonsrc/vertices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ uint32_t CalcVertexBufferSize(const spSkeleton* skeleton, uint32_t* out_max_tria
max_triangle_count = num_tri_vertices;
}
}
*out_max_triangle_count = max_triangle_count;
if (out_max_triangle_count)
*out_max_triangle_count = max_triangle_count;
return count;
}

Expand Down
1 change: 1 addition & 0 deletions defold-spine/include/common/vertices.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct SpineModelBounds
float maxY;
};

uint32_t CalcVertexBufferSize(const spSkeleton* skeleton, uint32_t* out_max_triangle_count);
uint32_t GenerateVertexData(dmArray<SpineVertex>& vertex_buffer, const spSkeleton* skeleton, const dmVMath::Matrix4& world);
void GetSkeletonBounds(const spSkeleton* skeleton, SpineModelBounds& bounds);

Expand Down
12 changes: 12 additions & 0 deletions defold-spine/src/comp_spine_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,18 @@ namespace dmSpine

uint32_t vertex_start = world->m_VertexBufferData.Size();
uint32_t vertex_count = 0;

for (uint32_t *i = begin; i != end; ++i)
{
component_index = (uint32_t)buf[*i].m_UserData;
const SpineModelComponent* component = (const SpineModelComponent*) components[component_index];
vertex_count += dmSpine::CalcVertexBufferSize(component->m_SkeletonInstance, 0);
}

if (vertex_count > world->m_VertexBufferData.Capacity())
world->m_VertexBufferData.SetCapacity(vertex_count);

vertex_count = 0;
for (uint32_t *i = begin; i != end; ++i)
{
component_index = (uint32_t)buf[*i].m_UserData;
Expand Down

0 comments on commit 20c7ef4

Please sign in to comment.