Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions source/gl_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,13 +823,23 @@ void GLRenderer::flushCommands() {

while (i < verts.size()) {
size_t remaining = verts.size() - i;
size_t batchFree = STREAM_VBO_CAPACITY - batch.size();
// Number of vertices that still fit (rounded to a multiple of vertStep)
size_t canTake = (batchFree / vertStep) * vertStep;
size_t batchFreeVerts = STREAM_VBO_CAPACITY - batch.size();
size_t batchFreeIdx = STREAM_EBO_CAPACITY - indexBatch.size();
size_t canTakeStepsVerts = batchFreeVerts / vertStep;
size_t canTakeStepsIdx = batchFreeIdx / idxPerStep;
size_t canTake = std::min(canTakeStepsVerts, canTakeStepsIdx) * vertStep;

if (canTake == 0) {
flushBatch();
canTake = (STREAM_VBO_CAPACITY / vertStep) * vertStep;
batchFreeVerts = STREAM_VBO_CAPACITY - batch.size();
batchFreeIdx = STREAM_EBO_CAPACITY - indexBatch.size();
canTakeStepsVerts = batchFreeVerts / vertStep;
canTakeStepsIdx = batchFreeIdx / idxPerStep;
canTake = std::min(canTakeStepsVerts, canTakeStepsIdx) * vertStep;
Comment on lines +834 to +838

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since flushBatch() clears the current batch and index batch, both batch.size() and indexBatch.size() are guaranteed to be 0 at this point. We can simplify this block by directly using STREAM_VBO_CAPACITY and STREAM_EBO_CAPACITY instead of performing redundant subtractions and size queries.

				canTakeStepsVerts = STREAM_VBO_CAPACITY / vertStep;
				canTakeStepsIdx = STREAM_EBO_CAPACITY / idxPerStep;
				canTake = std::min(canTakeStepsVerts, canTakeStepsIdx) * vertStep;

}

if (canTake == 0) {
break;
}

size_t take = std::min(remaining, canTake);
Expand Down
Loading