love.graphics.newGeometry now takes an optional draw mode argument ("fan", "strip", or "triangles".) "fan" is the default.

This allows for more diverse and complex Geometries, provided the lover understands how to use each mode. See http://escience.anu.edu.au/lecture/cg/surfaceModeling/image/surfaceModeling015.png

Changed love.graphics.newGeometry to optionally accept vertices as individual arguments instead of just a table of vertices (resolves issue #651).
Changed Geometry:setVertex to optionally accept a table containing x,y,u,v,r,g,b,a instead of just individual arguments.

Added Geometry:set/getDrawMode.

Removed the convex-check in love.graphics.newGeometry (all geometry modes have at least some form of concavity support, lovers can do their own check if needed with love.math.isConvex.)

Added an optional "vertex map" table argument to love.graphics.newGeometry (AKA a vertex index array / element array in graphics programming lingo.)
This allows lovers to change the order in which the vertices are used when drawing, or re-use a single vertex multiple times for different parts of the Geometry.
This is especially useful in the "triangles" Geometry draw mode. The vertex map lets you draw very complex (and concave) shapes / meshes without duplicating vertex data.

Added Geometry:set/getVertexMap.
This commit is contained in:
Alex Szpakowski
2013-07-10 15:34:10 -03:00
parent 12c5bbfb9a
commit 454ba9d968
12 changed files with 407 additions and 62 deletions
+22 -3
View File
@@ -120,7 +120,22 @@ void Image::drawg(love::graphics::Geometry *geom, float x, float y, float angle,
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid *) &v[0].r);
}
drawv(t, v, geom->getVertexCount(), GL_TRIANGLE_FAN);
GLenum glmode;
switch (geom->getDrawMode())
{
case Geometry::DRAW_MODE_FAN:
default:
glmode = GL_TRIANGLE_FAN;
break;
case Geometry::DRAW_MODE_STRIP:
glmode = GL_TRIANGLE_STRIP;
break;
case Geometry::DRAW_MODE_TRIANGLES:
glmode = GL_TRIANGLES;
break;
}
drawv(t, v, geom->getVertexCount(), glmode, geom->getElementArray(), geom->getElementCount());
if (geom->hasVertexColors())
{
@@ -536,7 +551,7 @@ bool Image::refresh()
return true;
}
void Image::drawv(const Matrix &t, const vertex *v, GLsizei count, GLenum mode) const
void Image::drawv(const Matrix &t, const vertex *v, GLsizei count, GLenum mode, const uint16 *e, GLsizei ecount) const
{
bind();
@@ -553,7 +568,11 @@ void Image::drawv(const Matrix &t, const vertex *v, GLsizei count, GLenum mode)
// glDrawArrays(), drawg() needs to be updated accordingly!
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].x);
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].s);
glDrawArrays(mode, 0, count);
if (e != 0 && ecount > 0)
glDrawElements(mode, ecount, GL_UNSIGNED_SHORT, (GLvoid *) e);
else
glDrawArrays(mode, 0, count);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);