Fixed Geometry texture coordinates when using Geometry to draw auto-padded NPOT images (resolves issue #696)

This commit is contained in:
Alex Szpakowski
2013-08-01 17:14:20 -03:00
parent d7802b053b
commit 2128ba321e
4 changed files with 66 additions and 3 deletions
@@ -114,6 +114,9 @@ int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, fl
if (color)
setColorv(sprite, *color);
// Auto-padded NPOT images require texcoord scaling for their vertices.
scaleNPOT(sprite, 4);
addv(sprite, (index == -1) ? next : index);
// Increment counter.
@@ -158,6 +161,9 @@ int SpriteBatch::addg(Geometry *geom, float x, float y, float a, float sx, float
if (color && !geom->hasVertexColors())
setColorv(sprite, *color);
// Auto-padded NPOT images require texcoord scaling for their vertices.
scaleNPOT(sprite, 4);
addv(sprite, (index == -1) ? next : index);
// Make sure SpriteBatch colors are enabled if the Geometry has custom colors.
@@ -334,6 +340,23 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
glPopMatrix();
}
void SpriteBatch::scaleNPOT(vertex *v, size_t count)
{
if (Image::hasNpot())
return;
love::Vector scale = image->getTexCoordScale();
if (scale.x == 1.0f && scale.y == 1.0f)
return;
for (size_t i = 0; i < count; i++)
{
v[i].s *= scale.x;
v[i].t *= scale.y;
}
}
void SpriteBatch::addv(const vertex *v, int index)
{
static const int sprite_size = 4 * sizeof(vertex); // bytecount