Skip to content

Commit

Permalink
Inline the initializer lists into vector::insert.
Browse files Browse the repository at this point in the history
Creating and deleting two std::vectors for every sprite draw during
every frame took a total of 7s over a profiling run of about 3 minutes.
  • Loading branch information
Quipyowert2 committed May 28, 2024
1 parent 2fbe5a9 commit e649a90
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions libgag/src/GraphicContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1697,16 +1697,15 @@ namespace GAGCore

// draw
glState.setTexture(surface->texture);
std::vector<float> vertices = { x, y, x + w, y, x + w, y + h, x, y + h };
std::vector<float> texCoords = { static_cast<float>(sx) * surface->texMultX, static_cast<float>(sy) * surface->texMultY,
static_cast<float>(sx + sw) * surface->texMultX, static_cast<float>(sy) * surface->texMultY,
static_cast<float>(sx + sw) * surface->texMultX, static_cast<float>(sy + sh) * surface->texMultY,
static_cast<float>(sx) * surface->texMultX, static_cast<float>(sy + sh) * surface->texMultY
};
if (surface->sprite && alpha == Color::ALPHA_OPAQUE)
{
surface->sprite->vertices.insert(surface->sprite->vertices.end(), vertices.begin(), vertices.end());
surface->sprite->texCoords.insert(surface->sprite->texCoords.end(), texCoords.begin(), texCoords.end());
surface->sprite->vertices.insert(surface->sprite->vertices.end(), { x, y, x + w, y, x + w, y + h, x, y + h });
surface->sprite->texCoords.insert(surface->sprite->texCoords.end(), {
static_cast<float>(sx) * surface->texMultX, static_cast<float>(sy) * surface->texMultY,
static_cast<float>(sx + sw) * surface->texMultX, static_cast<float>(sy) * surface->texMultY,
static_cast<float>(sx + sw) * surface->texMultX, static_cast<float>(sy + sh) * surface->texMultY,
static_cast<float>(sx) * surface->texMultX, static_cast<float>(sy + sh) * surface->texMultY
});
}
else
{
Expand Down

0 comments on commit e649a90

Please sign in to comment.