Maerge in default

--HG--
branch : minor
This commit is contained in:
Bart van Strien
2012-11-18 19:28:57 +01:00
13 changed files with 122 additions and 33 deletions
+23 -9
View File
@@ -304,13 +304,13 @@ Canvas::Canvas(int width, int height, TextureType texture_type)
// texture coordinates
vertices[0].s = 0;
vertices[0].t = 1;
vertices[0].t = 0;
vertices[1].s = 0;
vertices[1].t = 0;
vertices[1].t = 1;
vertices[2].s = 1;
vertices[2].t = 0;
vertices[2].t = 1;
vertices[3].s = 1;
vertices[3].t = 1;
vertices[3].t = 0;
getStrategy();
@@ -364,7 +364,7 @@ void Canvas::startGrab()
glLoadIdentity();
// Set up orthographic view (no depth)
glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
// Switch back to modelview matrix
glMatrixMode(GL_MODELVIEW);
@@ -413,18 +413,26 @@ void Canvas::draw(float x, float y, float angle, float sx, float sy, float ox, f
void Canvas::drawq(love::graphics::Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
{
static Matrix t;
const vertex *v = quad->getVertices();
// mirror quad on x axis
vertex w[4];
memcpy(w, v, sizeof(vertex)*4);
for (size_t i = 0; i < 4; ++i)
w[i].t = 1. - w[i].t;
static Matrix t;
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
drawv(t, v);
drawv(t, w);
}
love::image::ImageData *Canvas::getImageData(love::image::Image *image)
{
int row = 4 * width;
int size = row * height;
GLubyte *pixels = new GLubyte[size];
GLubyte *pixels = new GLubyte[size];
GLubyte *flipped = new GLubyte[size];
strategy->bindFBO(fbo);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
@@ -433,7 +441,13 @@ love::image::ImageData *Canvas::getImageData(love::image::Image *image)
else
strategy->bindFBO(0);
love::image::ImageData *img = image->newImageData(width, height, (void *)pixels);
GLubyte *src = pixels, *dst = flipped + size - row;
for (int i = 0; i < height; ++i, dst -= row, src += row)
{
memcpy(dst, src, row);
}
love::image::ImageData *img = image->newImageData(width, height, (void *)flipped);
delete[] pixels;
+56 -12
View File
@@ -62,6 +62,7 @@ ParticleSystem::ParticleSystem(Image *sprite, unsigned int buffer)
: pStart(0)
, pLast(0)
, pEnd(0)
, particleVerts(0)
, active(true)
, emissionRate(0)
, emitCounter(0)
@@ -104,6 +105,9 @@ ParticleSystem::~ParticleSystem()
if (pStart != 0)
delete [] pStart;
if (particleVerts != 0)
delete [] particleVerts;
}
void ParticleSystem::add()
@@ -197,11 +201,18 @@ void ParticleSystem::setSprite(Image *image)
void ParticleSystem::setBufferSize(unsigned int size)
{
// delete previous data
delete [] pStart;
if (pStart != 0)
delete [] pStart;
pLast = pStart = new particle[size];
pEnd = pStart + size;
if (particleVerts != 0)
delete [] particleVerts;
// each particle has 4 vertices
particleVerts = new vertex[size*4];
}
void ParticleSystem::setEmissionRate(int rate)
@@ -457,25 +468,58 @@ bool ParticleSystem::isFull() const
void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
{
if (sprite == 0) return; // just in case of failure
int numParticles = count();
if (numParticles == 0) return; // don't bother if there's nothing to do
glPushMatrix();
glPushAttrib(GL_CURRENT_BIT);
Matrix t;
static Matrix t;
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
glMultMatrixf((const GLfloat *)t.getElements());
particle *p = pStart;
while (p != pLast)
const vertex * imageVerts = sprite->getVertices();
// set the vertex data for each particle (transformation, texcoords, color)
for (int i = 0; i < numParticles; i++)
{
glPushMatrix();
glColor4f(p->color.r, p->color.g, p->color.b, p->color.a);
sprite->draw(p->position[0], p->position[1], p->rotation, p->size, p->size, offsetX, offsetY, 0.0f, 0.0f);
glPopMatrix();
p++;
particle * p = pStart + i;
// particle vertices are sprite vertices transformed by particle information
t.setTransformation(p->position[0], p->position[1], p->rotation, p->size, p->size, offsetX, offsetY, 0.0f, 0.0f);
t.transform(&particleVerts[i*4], &imageVerts[0], 4);
// set the texture coordinate and color data for particle vertices
for (int v = 0; v < 4; v++) {
int vi = (i * 4) + v; // current vertex index for particle
particleVerts[vi].s = imageVerts[v].s;
particleVerts[vi].t = imageVerts[v].t;
// particle colors are stored as floats (0-1) but vertex colors are stored as unsigned bytes (0-255)
particleVerts[vi].r = p->color.r*255;
particleVerts[vi].g = p->color.g*255;
particleVerts[vi].b = p->color.b*255;
particleVerts[vi].a = p->color.a*255;
}
}
sprite->bind();
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid *)&particleVerts[0].r);
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&particleVerts[0].x);
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&particleVerts[0].s);
glDrawArrays(GL_QUADS, 0, numParticles*4);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glPopAttrib();
glPopMatrix();
@@ -406,6 +406,9 @@ protected:
// Pointer to the end of the memory allocation.
particle *pEnd;
// array of transformed vertex data for all particles, for drawing
vertex * particleVerts;
// The sprite to be drawn.
Image *sprite;
+6 -3
View File
@@ -139,9 +139,12 @@ void *VBO::map()
void VBO::unmap()
{
glBufferSubDataARB(getTarget(), 0, getSize(), mapped);
free(mapped);
mapped = 0;
if (mapped)
{
glBufferSubDataARB(getTarget(), 0, getSize(), mapped);
free(mapped);
mapped = 0;
}
}
void VBO::bind()
@@ -647,7 +647,7 @@ int w_setDefaultImageFilter(lua_State *L)
Image::FilterMode min;
Image::FilterMode mag;
const char *minstr = luaL_checkstring(L, 1);
const char *magstr = luaL_checkstring(L, 2);
const char *magstr = luaL_optstring(L, 2, minstr);
if (!Image::getConstant(minstr, min))
return luaL_error(L, "Invalid filter mode: %s", minstr);
if (!Image::getConstant(magstr, mag))
+2 -2
View File
@@ -54,7 +54,7 @@ int w_Image_setFilter(lua_State *L)
Image::FilterMode min;
Image::FilterMode mag;
const char *minstr = luaL_checkstring(L, 2);
const char *magstr = luaL_checkstring(L, 3);
const char *magstr = luaL_optstring(L, 3, minstr);
if (!Image::getConstant(minstr, min))
return luaL_error(L, "Invalid filter mode: %s", minstr);
if (!Image::getConstant(magstr, mag))
@@ -88,7 +88,7 @@ int w_Image_setWrap(lua_State *L)
Image::WrapMode s;
Image::WrapMode t;
const char *sstr = luaL_checkstring(L, 2);
const char *tstr = luaL_checkstring(L, 3);
const char *tstr = luaL_optstring(L, 3, sstr);
if (!Image::getConstant(sstr, s))
return luaL_error(L, "Invalid wrap mode: %s", sstr);
if (!Image::getConstant(tstr, t))
@@ -112,7 +112,14 @@ int w_SpriteBatch_clear(lua_State *L)
int w_SpriteBatch_bind(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
t->lock();
try
{
t->lock();
}
catch (love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
return 0;
}