mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
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:
@@ -587,6 +587,9 @@ const Shader::UniformInfo *Shader::getUniformInfo(const std::string &name) const
|
||||
|
||||
void Shader::updateUniform(const UniformInfo *info, int count, bool internalUpdate)
|
||||
{
|
||||
if (!internalUpdate)
|
||||
flushStreamDraws();
|
||||
|
||||
TemporaryAttacher attacher(this, !internalUpdate);
|
||||
|
||||
int location = info->location;
|
||||
@@ -679,6 +682,9 @@ void Shader::sendTextures(const UniformInfo *info, Texture **textures, int count
|
||||
if (info->baseType != UNIFORM_SAMPLER)
|
||||
return;
|
||||
|
||||
if (!internalUpdate)
|
||||
flushStreamDraws();
|
||||
|
||||
count = std::min(count, info->count);
|
||||
bool updateuniform = false;
|
||||
|
||||
@@ -713,7 +719,7 @@ void Shader::sendTextures(const UniformInfo *info, Texture **textures, int count
|
||||
|
||||
if (textures[i] != nullptr)
|
||||
{
|
||||
GLuint gltex = *(GLuint *) textures[i]->getHandle();
|
||||
GLuint gltex = (GLuint) textures[i]->getHandle();
|
||||
|
||||
gl.bindTextureToUnit(gltex, texunit, false);
|
||||
|
||||
@@ -722,13 +728,23 @@ void Shader::sendTextures(const UniformInfo *info, Texture **textures, int count
|
||||
}
|
||||
else
|
||||
{
|
||||
gl.bindTextureToUnit(0, texunit, false);
|
||||
gl.bindTextureToUnit((GLuint) 0, texunit, false);
|
||||
textureUnits[texunit].texture = 0;
|
||||
textureUnits[texunit].active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::flushStreamDraws() const
|
||||
{
|
||||
if (current == this)
|
||||
{
|
||||
auto gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
|
||||
if (gfx != nullptr)
|
||||
gfx->flushStreamDraws();
|
||||
}
|
||||
}
|
||||
|
||||
bool Shader::hasUniform(const std::string &name) const
|
||||
{
|
||||
return uniforms.find(name) != uniforms.end();
|
||||
@@ -871,9 +887,10 @@ void Shader::checkSetBuiltinUniforms()
|
||||
{
|
||||
checkSetPointSize(gl.getPointSize());
|
||||
|
||||
const Matrix4 &curxform = gl.matrices.transform.back();
|
||||
const Matrix4 &curproj = gl.matrices.projection;
|
||||
auto gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
|
||||
const Matrix4 &curproj = gfx->getProjection();
|
||||
|
||||
const Matrix4 &curxform = gfx->getTransform();
|
||||
TemporaryAttacher attacher(this, true);
|
||||
|
||||
bool tpmatrixneedsupdate = false;
|
||||
|
||||
Reference in New Issue
Block a user