Implement automatic batching for points, lines, shapes, and images/quads.

The above are batched together into a single draw call when called without other drawing calls in between, as long as the following criteria are met:

- The texture is the same.
- The primitive type is the same (points cannot be batched with non-points).
- The love.graphics state is the same (aside from the current color - i.e. setColor - and the transform state).
- The active shader’s uniform values are the same.

You can examine the ‘drawcalls’ field of love.graphics.getStats() to help determine if your code is allowing for optimum batching.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2016-12-27 21:02:58 -04:00
parent f98b7ce1ed
commit 0d2e08baff
43 changed files with 1245 additions and 511 deletions
+3 -15
View File
@@ -21,6 +21,7 @@
#include "GLBuffer.h"
#include "common/Exception.h"
#include "graphics/vertex.h"
#include <cstdlib>
#include <cstring>
@@ -362,22 +363,9 @@ const void *QuadIndices::getIndices(size_t offset) const
template <typename T>
void QuadIndices::fill()
{
T *inds = (T *) indices;
using namespace love::graphics::vertex;
// 0----2
// | / |
// | / |
// 1----3
for (size_t i = 0; i < maxSize; ++i)
{
inds[i*6+0] = T(i * 4 + 0);
inds[i*6+1] = T(i * 4 + 1);
inds[i*6+2] = T(i * 4 + 2);
inds[i*6+3] = T(i * 4 + 2);
inds[i*6+4] = T(i * 4 + 1);
inds[i*6+5] = T(i * 4 + 3);
}
fillIndices(TriangleIndexMode::QUADS, 0, maxSize * 4, (T *) indices);
indexBuffer->fill(0, indexBuffer->getSize(), indices);
}