Fix SpriteBatch.

Broken in my last commit (6e0f6a4).
This commit is contained in:
vrld
2013-04-21 20:01:03 +02:00
parent 27bbfaac42
commit 1e54049fbb
2 changed files with 27 additions and 27 deletions
+26 -26
View File
@@ -107,7 +107,6 @@ int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, fl
if (color) if (color)
setColorv(sprite, *color); setColorv(sprite, *color);
addv(sprite, (index == -1) ? next : index); addv(sprite, (index == -1) ? next : index);
@@ -124,19 +123,29 @@ int SpriteBatch::addg(Geometry *geom, float x, float y, float a, float sx, float
if ((index == -1 && next >= size) || index < -1 || index >= next) if ((index == -1 && next >= size) || index < -1 || index >= next)
return -1; return -1;
// Needed for colors. if (geom->getNumVertices() != 4)
size_t vcount = geom->getVertexArraySize(); throw love::Exception("Can only add quadliteral geometries to SpriteBatch");
memcpy(sprite, geom->getVertexArray(), vcount * sizeof(vertex));
sprite[0] = geom->getVertex(0);
sprite[1] = geom->getVertex(1);
sprite[2] = geom->getVertex(2);
sprite[3] = geom->getVertex(3);
// Transform. // Transform.
Matrix t; Matrix t;
t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky); t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky);
t.transform(sprite, sprite, vcount); t.transform(sprite, sprite, 4);
if (color) // color modulation
setColorv(sprite, *color); for (size_t i = 0; color && (i < 4); ++i)
{
sprite[i].r = (unsigned char)(double(sprite[i].r) * color->r / 255.);
sprite[i].g = (unsigned char)(double(sprite[i].g) * color->g / 255.);
sprite[i].b = (unsigned char)(double(sprite[i].b) * color->b / 255.);
sprite[i].a = (unsigned char)(double(sprite[i].a) * color->a / 255.);
}
addv(sprite, (index == -1) ? next : index, vcount); addv(sprite, (index == -1) ? next : index);
// Increment counter. // Increment counter.
if (index == -1) if (index == -1)
@@ -248,31 +257,22 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
glPopMatrix(); glPopMatrix();
} }
void SpriteBatch::addv(const vertex *v, int index, int sprite_size) void SpriteBatch::addv(const vertex *v, int index)
{ {
sprite_size *= sizeof(vertex); // bytecount static const int sprite_size = 4 * sizeof(vertex); // bytecount
VertexBuffer::Bind bind(*array_buf); VertexBuffer::Bind bind(*array_buf);
array_buf->fill(index * sprite_size, sprite_size, v); array_buf->fill(index * sprite_size, sprite_size, v);
} }
void SpriteBatch::setColorv(vertex *v, const Color &color) void SpriteBatch::setColorv(vertex *v, const Color &color)
{ {
v[0].r = color.r; for (size_t i = 0; i < 4; ++i)
v[0].g = color.g; {
v[0].b = color.b; v[i].r = color.r;
v[0].a = color.a; v[i].g = color.g;
v[1].r = color.r; v[i].b = color.b;
v[1].g = color.g; v[i].a = color.a;
v[1].b = color.b; }
v[1].a = color.a;
v[2].r = color.r;
v[2].g = color.g;
v[2].b = color.b;
v[2].a = color.a;
v[3].r = color.r;
v[3].g = color.g;
v[3].b = color.b;
v[3].a = color.a;
} }
bool SpriteBatch::getConstant(const char *in, UsageHint &out) bool SpriteBatch::getConstant(const char *in, UsageHint &out)
+1 -1
View File
@@ -104,7 +104,7 @@ public:
private: private:
void addv(const vertex *v, int index, int sprite_size = 4); void addv(const vertex *v, int index);
/** /**
* Set the color for vertices. * Set the color for vertices.