mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
The Vertex struct is now recognized as POD by C++, also fixed the name to be consistent with other love structs
This commit is contained in:
@@ -35,7 +35,7 @@ namespace love
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
Geometry::Geometry(const std::vector<vertex> &polygon, const std::vector<uint16> &elements, Geometry::DrawMode mode)
|
||||
Geometry::Geometry(const std::vector<Vertex> &polygon, const std::vector<uint16> &elements, Geometry::DrawMode mode)
|
||||
: vertexArray(NULL)
|
||||
, vertexCount(polygon.size())
|
||||
, elementArray(NULL)
|
||||
@@ -53,8 +53,8 @@ Geometry::Geometry(const std::vector<vertex> &polygon, const std::vector<uint16>
|
||||
throw love::Exception("Invalid vertex map value");
|
||||
}
|
||||
|
||||
vertexArray = new vertex[vertexCount];
|
||||
memcpy(vertexArray, &polygon[0], vertexCount * sizeof(vertex));
|
||||
vertexArray = new Vertex[vertexCount];
|
||||
memcpy(vertexArray, &polygon[0], vertexCount * sizeof(Vertex));
|
||||
|
||||
if (elementCount > 0)
|
||||
{
|
||||
@@ -71,12 +71,19 @@ Geometry::Geometry(float x, float y, float w, float h, float sw, float sh)
|
||||
, vertexColors(false)
|
||||
, drawMode(DRAW_MODE_FAN)
|
||||
{
|
||||
vertexArray = new vertex[4];
|
||||
float s0 = x/sw, s1 = (x+w)/sw, t0 = y/sh, t1 = (y+h)/sh;
|
||||
vertexArray[0] = vertex(0,0, s0,t0);
|
||||
vertexArray[1] = vertex(w,0, s1,t0);
|
||||
vertexArray[2] = vertex(w,h, s1,t1);
|
||||
vertexArray[3] = vertex(0,h, s0,t1);
|
||||
|
||||
Vertex verts[4] = {
|
||||
{0,0, s0,t0, 255, 255, 255, 255},
|
||||
{w,0, s1,t0, 255, 255, 255, 255},
|
||||
{w,h, s1,t1, 255, 255, 255, 255},
|
||||
{0,h, s0,t1, 255, 255, 255, 255}
|
||||
};
|
||||
|
||||
vertexArray = new Vertex[4];
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
vertexArray[i] = verts[i];
|
||||
}
|
||||
|
||||
Geometry::Geometry(const Geometry &other)
|
||||
@@ -85,8 +92,8 @@ Geometry::Geometry(const Geometry &other)
|
||||
, vertexColors(other.vertexColors)
|
||||
, drawMode(other.drawMode)
|
||||
{
|
||||
vertexArray = new vertex[vertexCount];
|
||||
memcpy(vertexArray, other.vertexArray, vertexCount * sizeof(vertex));
|
||||
vertexArray = new Vertex[vertexCount];
|
||||
memcpy(vertexArray, other.vertexArray, vertexCount * sizeof(Vertex));
|
||||
|
||||
if (elementCount > 0)
|
||||
{
|
||||
@@ -119,7 +126,7 @@ Geometry::~Geometry()
|
||||
delete[] elementArray;
|
||||
}
|
||||
|
||||
const vertex &Geometry::getVertex(size_t i) const
|
||||
const Vertex &Geometry::getVertex(size_t i) const
|
||||
{
|
||||
if (i >= vertexCount)
|
||||
throw Exception("Invalid vertex index");
|
||||
@@ -127,7 +134,7 @@ const vertex &Geometry::getVertex(size_t i) const
|
||||
return vertexArray[i];
|
||||
}
|
||||
|
||||
void Geometry::setVertex(size_t i, const vertex &v)
|
||||
void Geometry::setVertex(size_t i, const Vertex &v)
|
||||
{
|
||||
if (i >= vertexCount)
|
||||
throw Exception("Invalid vertex index");
|
||||
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
/**
|
||||
* Creates a new geometry object from a std::vector<vertex>.
|
||||
**/
|
||||
Geometry(const std::vector<vertex> &polygon, const std::vector<uint16> &elements, DrawMode mode = DRAW_MODE_FAN);
|
||||
Geometry(const std::vector<Vertex> &polygon, const std::vector<uint16> &elements, DrawMode mode = DRAW_MODE_FAN);
|
||||
|
||||
/**
|
||||
* Creates a new geometry from (texture) quad information.
|
||||
@@ -69,13 +69,13 @@ public:
|
||||
Geometry &operator=(const Geometry &other);
|
||||
virtual ~Geometry();
|
||||
|
||||
const vertex &getVertex(size_t i) const;
|
||||
void setVertex(size_t i, const vertex &v);
|
||||
const Vertex &getVertex(size_t i) const;
|
||||
void setVertex(size_t i, const Vertex &v);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the vertex array.
|
||||
**/
|
||||
inline const vertex *getVertexArray() const
|
||||
inline const Vertex *getVertexArray() const
|
||||
{
|
||||
return vertexArray;
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
vertex *vertexArray;
|
||||
Vertex *vertexArray;
|
||||
size_t vertexCount;
|
||||
|
||||
uint16 *elementArray;
|
||||
|
||||
@@ -614,8 +614,8 @@ void Canvas::drawg(love::graphics::Geometry *geom, float x, float y, float angle
|
||||
|
||||
// flip texture coordinates vertically
|
||||
size_t vcount = geom->getVertexCount();
|
||||
const vertex *w = geom->getVertexArray();
|
||||
vertex *v = new vertex[vcount];
|
||||
const Vertex *w = geom->getVertexArray();
|
||||
Vertex *v = new Vertex[vcount];
|
||||
for (size_t i = 0; i < vcount; ++i)
|
||||
{
|
||||
v[i] = w[i];
|
||||
@@ -626,7 +626,7 @@ void Canvas::drawg(love::graphics::Geometry *geom, float x, float y, float angle
|
||||
if (geom->hasVertexColors())
|
||||
{
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid *)&v->r);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), (GLvoid *)&v->r);
|
||||
}
|
||||
|
||||
GLenum glmode;
|
||||
@@ -785,7 +785,7 @@ int Canvas::getHeight()
|
||||
return height;
|
||||
}
|
||||
|
||||
void Canvas::drawv(const Matrix &t, const vertex *v, GLsizei count, GLenum mode, const uint16 *e, GLsizei ecount) const
|
||||
void Canvas::drawv(const Matrix &t, const Vertex *v, GLsizei count, GLenum mode, const uint16 *e, GLsizei ecount) const
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
@@ -800,8 +800,8 @@ void Canvas::drawv(const Matrix &t, const vertex *v, GLsizei count, GLenum mode,
|
||||
// defined in the geometry to draw itself.
|
||||
// if the drawing method below is changed to use something other than
|
||||
// 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);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vertex), (GLvoid *)&v[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), (GLvoid *)&v[0].s);
|
||||
|
||||
if (e != 0 && ecount > 0)
|
||||
glDrawElements(mode, ecount, GL_UNSIGNED_SHORT, (GLvoid *) e);
|
||||
|
||||
@@ -129,7 +129,7 @@ private:
|
||||
|
||||
TextureType texture_type;
|
||||
|
||||
vertex vertices[4];
|
||||
Vertex vertices[4];
|
||||
|
||||
GLenum status;
|
||||
|
||||
@@ -142,7 +142,7 @@ private:
|
||||
std::vector<Canvas *> attachedCanvases;
|
||||
|
||||
void setupGrab();
|
||||
void drawv(const Matrix &t, const vertex *v, GLsizei count = 4, GLenum mode = GL_QUADS, const uint16 *e = 0, GLsizei ecount = 0) const;
|
||||
void drawv(const Matrix &t, const Vertex *v, GLsizei count = 4, GLenum mode = GL_QUADS, const uint16 *e = 0, GLsizei ecount = 0) const;
|
||||
|
||||
static StringMap<TextureType, TYPE_MAX_ENUM>::Entry textureTypeEntries[];
|
||||
static StringMap<TextureType, TYPE_MAX_ENUM> textureTypes;
|
||||
|
||||
@@ -196,7 +196,7 @@ Font::Glyph *Font::addGlyph(uint32 glyph)
|
||||
g->texture = 0;
|
||||
g->spacing = gd->getAdvance();
|
||||
|
||||
memset(g->vertices, 0, sizeof(vertex) * 4);
|
||||
memset(g->vertices, 0, sizeof(GlyphVertex) * 4);
|
||||
|
||||
// don't waste space for empty glyphs. also fixes a division by zero bug with ati drivers
|
||||
if (w > 0 && h > 0)
|
||||
@@ -215,11 +215,11 @@ Font::Glyph *Font::addGlyph(uint32 glyph)
|
||||
|
||||
g->texture = t;
|
||||
|
||||
const vertex verts[4] = {
|
||||
vertex(0, 0, float(textureX)/float(textureWidth), float(textureY)/float(textureHeight)),
|
||||
vertex(w, 0, float(textureX+w)/float(textureWidth), float(textureY)/float(textureHeight)),
|
||||
vertex(w, h, float(textureX+w)/float(textureWidth), float(textureY+h)/float(textureHeight)),
|
||||
vertex(0, h, float(textureX)/float(textureWidth), float(textureY+h)/float(textureHeight)),
|
||||
const GlyphVertex verts[4] = {
|
||||
{0, 0, float(textureX)/float(textureWidth), float(textureY)/float(textureHeight)},
|
||||
{w, 0, float(textureX+w)/float(textureWidth), float(textureY)/float(textureHeight)},
|
||||
{w, h, float(textureX+w)/float(textureWidth), float(textureY+h)/float(textureHeight)},
|
||||
{0, h, float(textureX)/float(textureWidth), float(textureY+h)/float(textureHeight)},
|
||||
};
|
||||
|
||||
// copy vertex data to the glyph and set proper bearing
|
||||
@@ -270,7 +270,7 @@ void Font::print(const std::string &text, float x, float y, float extra_spacing,
|
||||
std::vector<GlyphArrayDrawInfo> glyphinfolist;
|
||||
|
||||
// Pre-allocate space for the maximum possible number of vertices.
|
||||
std::vector<vertex> glyphverts;
|
||||
std::vector<GlyphVertex> glyphverts;
|
||||
glyphverts.reserve(text.length() * 4);
|
||||
|
||||
int vertexcount = 0;
|
||||
@@ -348,8 +348,8 @@ void Font::print(const std::string &text, float x, float y, float extra_spacing,
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&glyphverts[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&glyphverts[0].s);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(GlyphVertex), (GLvoid *)&glyphverts[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(GlyphVertex), (GLvoid *)&glyphverts[0].s);
|
||||
|
||||
// We need to draw a new vertex array for every section of the string which
|
||||
// uses a different texture than the previous section.
|
||||
|
||||
@@ -146,11 +146,17 @@ private:
|
||||
FONT_UNKNOWN
|
||||
};
|
||||
|
||||
struct GlyphVertex
|
||||
{
|
||||
float x, y;
|
||||
float s, t;
|
||||
};
|
||||
|
||||
struct Glyph
|
||||
{
|
||||
GLuint texture;
|
||||
int spacing;
|
||||
vertex vertices[4];
|
||||
GlyphVertex vertices[4];
|
||||
};
|
||||
|
||||
// used to determine when to change textures in the vertex array generated when printing text
|
||||
|
||||
@@ -369,7 +369,7 @@ Image *Graphics::newImage(love::image::CompressedData *cdata)
|
||||
return image;
|
||||
}
|
||||
|
||||
Geometry *Graphics::newGeometry(const std::vector<vertex> &vertices, const std::vector<uint16> &vertexmap, Geometry::DrawMode mode)
|
||||
Geometry *Graphics::newGeometry(const std::vector<Vertex> &vertices, const std::vector<uint16> &vertexmap, Geometry::DrawMode mode)
|
||||
{
|
||||
return new Geometry(vertices, vertexmap, mode);
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ public:
|
||||
/**
|
||||
* Creates a Geometry object.
|
||||
**/
|
||||
Geometry *newGeometry(const std::vector<vertex> &vertices, const std::vector<uint16> &vertexmap, Geometry::DrawMode mode);
|
||||
Geometry *newGeometry(const std::vector<Vertex> &vertices, const std::vector<uint16> &vertexmap, Geometry::DrawMode mode);
|
||||
|
||||
/**
|
||||
* Creates a quadliteral Geometry object.
|
||||
|
||||
@@ -85,7 +85,7 @@ float Image::getHeight() const
|
||||
return height;
|
||||
}
|
||||
|
||||
const vertex *Image::getVertices() const
|
||||
const Vertex *Image::getVertices() const
|
||||
{
|
||||
return vertices;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ void Image::drawg(love::graphics::Geometry *geom, float x, float y, float angle,
|
||||
static Matrix t;
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
|
||||
const vertex *v = geom->getVertexArray();
|
||||
const Vertex *v = geom->getVertexArray();
|
||||
size_t vertcount = geom->getVertexCount();
|
||||
|
||||
// Padded NPOT images require texture coordinate scaling with Geometry.
|
||||
@@ -124,7 +124,7 @@ void Image::drawg(love::graphics::Geometry *geom, float x, float y, float angle,
|
||||
if (geom->hasVertexColors())
|
||||
{
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid *) &v[0].r);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), (GLvoid *) &v[0].r);
|
||||
}
|
||||
|
||||
GLenum glmode;
|
||||
@@ -326,7 +326,7 @@ void Image::bind() const
|
||||
|
||||
void Image::preload()
|
||||
{
|
||||
memset(vertices, 255, sizeof(vertex)*4);
|
||||
memset(vertices, 255, sizeof(Vertex)*4);
|
||||
|
||||
vertices[0].x = 0;
|
||||
vertices[0].y = 0;
|
||||
@@ -602,9 +602,9 @@ love::Vector Image::getTexCoordScale() const
|
||||
return love::Vector(vertices[2].s, vertices[2].t);
|
||||
}
|
||||
|
||||
vertex *Image::scaleNPOT(const love::vertex *v, size_t count) const
|
||||
Vertex *Image::scaleNPOT(const love::Vertex *v, size_t count) const
|
||||
{
|
||||
vertex *newverts = new vertex[count];
|
||||
Vertex *newverts = new Vertex[count];
|
||||
love::Vector scale = getTexCoordScale();
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
@@ -617,7 +617,7 @@ vertex *Image::scaleNPOT(const love::vertex *v, size_t count) const
|
||||
return newverts;
|
||||
}
|
||||
|
||||
void Image::drawv(const Matrix &t, const vertex *v, GLsizei count, GLenum mode, const uint16 *e, GLsizei ecount) const
|
||||
void Image::drawv(const Matrix &t, const Vertex *v, GLsizei count, GLenum mode, const uint16 *e, GLsizei ecount) const
|
||||
{
|
||||
bind();
|
||||
|
||||
@@ -632,8 +632,8 @@ void Image::drawv(const Matrix &t, const vertex *v, GLsizei count, GLenum mode,
|
||||
// defined in the geometry to draw itself.
|
||||
// if the drawing method below is changed to use something other than
|
||||
// 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);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vertex), (GLvoid *)&v[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), (GLvoid *)&v[0].s);
|
||||
|
||||
if (e != 0 && ecount > 0)
|
||||
glDrawElements(mode, ecount, GL_UNSIGNED_SHORT, (GLvoid *) e);
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
float getWidth() const;
|
||||
float getHeight() const;
|
||||
|
||||
const vertex *getVertices() const;
|
||||
const Vertex *getVertices() const;
|
||||
|
||||
love::image::ImageData *getImageData() const;
|
||||
love::image::CompressedData *getCompressedData() const;
|
||||
@@ -145,10 +145,10 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
vertex *scaleNPOT(const vertex *v, size_t count) const;
|
||||
Vertex *scaleNPOT(const Vertex *v, size_t count) const;
|
||||
void uploadDefaultTexture();
|
||||
|
||||
void drawv(const Matrix &t, const vertex *v, GLsizei count = 4, GLenum mode = GL_QUADS, const uint16 *e = 0, GLsizei ecount = 0) const;
|
||||
void drawv(const Matrix &t, const Vertex *v, GLsizei count = 4, GLenum mode = GL_QUADS, const uint16 *e = 0, GLsizei ecount = 0) const;
|
||||
|
||||
friend class Shader;
|
||||
GLuint getTextureName() const
|
||||
@@ -171,7 +171,7 @@ private:
|
||||
GLuint texture;
|
||||
|
||||
// The source vertices of the image.
|
||||
vertex vertices[4];
|
||||
Vertex vertices[4];
|
||||
|
||||
// Mipmap texture LOD bias (sharpness) value.
|
||||
float mipmapSharpness;
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
// STL
|
||||
#include <vector>
|
||||
|
||||
// The last argument to AttribPointer takes a buffer offset casted to a pointer.
|
||||
#define BUFFER_OFFSET(i) ((char *) NULL + (i))
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
|
||||
@@ -132,7 +132,7 @@ void ParticleSystem::createBuffers(size_t size)
|
||||
try
|
||||
{
|
||||
pFree = pMem = new particle[size];
|
||||
particleVerts = new love::vertex[size * 4];
|
||||
particleVerts = new love::Vertex[size * 4];
|
||||
maxParticles = (uint32) size;
|
||||
}
|
||||
catch (std::bad_alloc &)
|
||||
@@ -746,8 +746,8 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
glMultMatrixf((const GLfloat *)t.getElements());
|
||||
|
||||
const vertex *imageVerts = image->getVertices();
|
||||
vertex *pVerts = particleVerts;
|
||||
const Vertex *imageVerts = image->getVertices();
|
||||
Vertex *pVerts = particleVerts;
|
||||
particle *p = pHead;
|
||||
|
||||
// set the vertex data for each particle (transformation, texcoords, color)
|
||||
@@ -780,9 +780,9 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
|
||||
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);
|
||||
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, pCount * 4);
|
||||
|
||||
|
||||
@@ -524,7 +524,7 @@ protected:
|
||||
particle *pTail;
|
||||
|
||||
// array of transformed vertex data for all particles, for drawing
|
||||
vertex * particleVerts;
|
||||
Vertex *particleVerts;
|
||||
|
||||
// The image to be drawn.
|
||||
Image *image;
|
||||
|
||||
@@ -29,9 +29,12 @@
|
||||
#include "modules/graphics/Geometry.h"
|
||||
#include "VertexBuffer.h"
|
||||
|
||||
// stdlib
|
||||
// C++
|
||||
#include <algorithm>
|
||||
|
||||
// C
|
||||
#include <stddef.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
@@ -65,7 +68,7 @@ SpriteBatch::SpriteBatch(Image *image, int size, int usage)
|
||||
break;
|
||||
}
|
||||
|
||||
const size_t vertex_size = sizeof(vertex) * 4 * size;
|
||||
const size_t vertex_size = sizeof(Vertex) * 4 * size;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -104,7 +107,7 @@ int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, fl
|
||||
return -1;
|
||||
|
||||
// Needed for colors.
|
||||
memcpy(sprite, image->getVertices(), sizeof(vertex)*4);
|
||||
memcpy(sprite, image->getVertices(), sizeof(Vertex)*4);
|
||||
|
||||
// Transform.
|
||||
static Matrix t;
|
||||
@@ -245,7 +248,7 @@ void SpriteBatch::setBufferSize(int newsize)
|
||||
// Map (lock) the old VertexBuffer to get a pointer to its data.
|
||||
void *old_data = lock();
|
||||
|
||||
size_t vertex_size = sizeof(vertex) * 4 * newsize;
|
||||
size_t vertex_size = sizeof(Vertex) * 4 * newsize;
|
||||
|
||||
VertexBuffer *new_array_buf = 0;
|
||||
VertexIndex *new_element_buf = 0;
|
||||
@@ -269,7 +272,7 @@ void SpriteBatch::setBufferSize(int newsize)
|
||||
}
|
||||
|
||||
// Copy as much of the old data into the new VertexBuffer as can fit.
|
||||
memcpy(new_data, old_data, sizeof(vertex) * 4 * std::min(newsize, size));
|
||||
memcpy(new_data, old_data, sizeof(Vertex) * 4 * std::min(newsize, size));
|
||||
|
||||
// We don't need to unmap the old VertexBuffer since we're deleting it.
|
||||
delete array_buf;
|
||||
@@ -292,9 +295,9 @@ int SpriteBatch::getBufferSize() const
|
||||
|
||||
void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
||||
{
|
||||
const int color_offset = 0;
|
||||
const int vertex_offset = sizeof(unsigned char) * 4;
|
||||
const int texel_offset = sizeof(unsigned char) * 4 + sizeof(float) * 2;
|
||||
const size_t vertex_offset = offsetof(Vertex, x);
|
||||
const size_t texel_offset = offsetof(Vertex, s);
|
||||
const size_t color_offset = offsetof(Vertex, r);
|
||||
|
||||
if (next == 0)
|
||||
return;
|
||||
@@ -317,14 +320,14 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
|
||||
if (color)
|
||||
{
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), array_buf->getPointer(color_offset));
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), array_buf->getPointer(color_offset));
|
||||
}
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), array_buf->getPointer(vertex_offset));
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vertex), array_buf->getPointer(vertex_offset));
|
||||
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), array_buf->getPointer(texel_offset));
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), array_buf->getPointer(texel_offset));
|
||||
|
||||
glDrawElements(GL_TRIANGLES, element_buf->getIndexCount(next), element_buf->getType(), element_buf->getPointer(0));
|
||||
|
||||
@@ -340,7 +343,7 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void SpriteBatch::scaleNPOT(vertex *v, size_t count)
|
||||
void SpriteBatch::scaleNPOT(Vertex *v, size_t count)
|
||||
{
|
||||
if (Image::hasNpot())
|
||||
return;
|
||||
@@ -357,14 +360,14 @@ void SpriteBatch::scaleNPOT(vertex *v, size_t count)
|
||||
}
|
||||
}
|
||||
|
||||
void SpriteBatch::addv(const vertex *v, int index)
|
||||
void SpriteBatch::addv(const Vertex *v, int index)
|
||||
{
|
||||
static const int sprite_size = 4 * sizeof(vertex); // bytecount
|
||||
static const int sprite_size = 4 * sizeof(Vertex); // bytecount
|
||||
VertexBuffer::Bind bind(*array_buf);
|
||||
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)
|
||||
{
|
||||
for (size_t i = 0; i < 4; ++i)
|
||||
{
|
||||
|
||||
@@ -116,9 +116,9 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
void scaleNPOT(vertex *v, size_t count);
|
||||
void scaleNPOT(Vertex *v, size_t count);
|
||||
|
||||
void addv(const vertex *v, int index);
|
||||
void addv(const Vertex *v, int index);
|
||||
|
||||
/**
|
||||
* Set the color for vertices.
|
||||
@@ -127,7 +127,7 @@ private:
|
||||
* of size 4.
|
||||
* @param color The color to assign to each vertex.
|
||||
*/
|
||||
void setColorv(vertex *v, const Color &color);
|
||||
void setColorv(Vertex *v, const Color &color);
|
||||
|
||||
Image *image;
|
||||
|
||||
@@ -137,7 +137,7 @@ private:
|
||||
// The next free element.
|
||||
int next;
|
||||
|
||||
vertex sprite[4];
|
||||
Vertex sprite[4];
|
||||
|
||||
// Current color. This color, if present, will be applied to the next
|
||||
// added geometry.
|
||||
|
||||
@@ -232,7 +232,7 @@ void VBO::fill(size_t offset, size_t size, const void *data)
|
||||
|
||||
const void *VBO::getPointer(size_t offset) const
|
||||
{
|
||||
return reinterpret_cast<const void *>(offset);
|
||||
return BUFFER_OFFSET(offset);
|
||||
}
|
||||
|
||||
bool VBO::loadVolatile()
|
||||
|
||||
@@ -47,7 +47,7 @@ int w_Geometry_getVertex(lua_State *L)
|
||||
size_t i = size_t(luaL_checkinteger(L, 2));
|
||||
|
||||
EXCEPT_GUARD(
|
||||
const vertex &v = geom->getVertex(i-1);
|
||||
const Vertex &v = geom->getVertex(i-1);
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
lua_pushnumber(L, v.s);
|
||||
@@ -66,7 +66,7 @@ int w_Geometry_setVertex(lua_State *L)
|
||||
Geometry *geom = luax_checkgeometry(L, 1);
|
||||
size_t i = size_t(luaL_checkinteger(L, 2));
|
||||
|
||||
vertex v;
|
||||
Vertex v;
|
||||
|
||||
if (lua_istable(L, 3))
|
||||
{
|
||||
|
||||
@@ -270,12 +270,12 @@ int w_newGeometry(lua_State *L)
|
||||
|
||||
bool hasvertexcolors = false;
|
||||
|
||||
std::vector<vertex> vertices;
|
||||
std::vector<Vertex> vertices;
|
||||
vertices.reserve(vertexcount);
|
||||
|
||||
for (size_t i = 0; i < vertexcount; ++i)
|
||||
{
|
||||
vertex v;
|
||||
Vertex v;
|
||||
|
||||
if (is_table)
|
||||
{
|
||||
|
||||
@@ -30,19 +30,19 @@
|
||||
|
||||
using std::list;
|
||||
using std::vector;
|
||||
using love::vertex;
|
||||
using love::Vertex;
|
||||
|
||||
namespace
|
||||
{
|
||||
// check if an angle is oriented counter clockwise
|
||||
inline bool is_oriented_ccw(const vertex &a, const vertex &b, const vertex &c)
|
||||
inline bool is_oriented_ccw(const Vertex &a, const Vertex &b, const Vertex &c)
|
||||
{
|
||||
// return det(b-a, c-a) >= 0
|
||||
return ((b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)) >= 0;
|
||||
}
|
||||
|
||||
// check if a and b are on the same side of the line c->d
|
||||
bool on_same_side(const vertex &a, const vertex &b, const vertex &c, const vertex &d)
|
||||
bool on_same_side(const Vertex &a, const Vertex &b, const Vertex &c, const Vertex &d)
|
||||
{
|
||||
float px = d.x - c.x, py = d.y - c.y;
|
||||
// return det(p, a-c) * det(p, b-c) >= 0
|
||||
@@ -52,18 +52,18 @@ namespace
|
||||
}
|
||||
|
||||
// checks is p is contained in the triangle abc
|
||||
inline bool point_in_triangle(const vertex &p, const vertex &a, const vertex &b, const vertex &c)
|
||||
inline bool point_in_triangle(const Vertex &p, const Vertex &a, const Vertex &b, const Vertex &c)
|
||||
{
|
||||
return on_same_side(p,a, b,c) && on_same_side(p,b, a,c) && on_same_side(p,c, a,b);
|
||||
}
|
||||
|
||||
// checks if any vertex in `vertices' is in the triangle abc.
|
||||
bool any_point_in_triangle(const list<const vertex *> &vertices, const vertex &a, const vertex &b, const vertex &c)
|
||||
bool any_point_in_triangle(const list<const Vertex *> &vertices, const Vertex &a, const Vertex &b, const Vertex &c)
|
||||
{
|
||||
list<const vertex *>::const_iterator it, end = vertices.end();
|
||||
list<const Vertex *>::const_iterator it, end = vertices.end();
|
||||
for (it = vertices.begin(); it != end; ++it)
|
||||
{
|
||||
const vertex *p = *it;
|
||||
const Vertex *p = *it;
|
||||
if ((p != &a) && (p != &b) && (p != &c) && point_in_triangle(*p, a,b,c)) // oh god...
|
||||
return true;
|
||||
}
|
||||
@@ -71,7 +71,7 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool is_ear(const vertex &a, const vertex &b, const vertex &c, const list<const vertex *> &vertices)
|
||||
inline bool is_ear(const Vertex &a, const Vertex &b, const Vertex &c, const list<const Vertex *> &vertices)
|
||||
{
|
||||
return is_oriented_ccw(a,b,c) && !any_point_in_triangle(vertices, a,b,c);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ BezierCurve *Math::newBezierCurve(const vector<Vector> &points)
|
||||
return new BezierCurve(points);
|
||||
}
|
||||
|
||||
vector<Triangle> Math::triangulate(const vector<vertex> &polygon)
|
||||
vector<Triangle> Math::triangulate(const vector<Vertex> &polygon)
|
||||
{
|
||||
if (polygon.size() < 3)
|
||||
throw love::Exception("Not a ploygon");
|
||||
@@ -114,7 +114,7 @@ vector<Triangle> Math::triangulate(const vector<vertex> &polygon)
|
||||
size_t idx_lm = 0;
|
||||
for (size_t i = 0; i < polygon.size(); ++i)
|
||||
{
|
||||
const vertex &lm = polygon[idx_lm], &p = polygon[i];
|
||||
const Vertex &lm = polygon[idx_lm], &p = polygon[i];
|
||||
if (p.x < lm.x || (p.x == lm.x && p.y < lm.y))
|
||||
idx_lm = i;
|
||||
next_idx[i] = i+1;
|
||||
@@ -128,7 +128,7 @@ vector<Triangle> Math::triangulate(const vector<vertex> &polygon)
|
||||
next_idx.swap(prev_idx);
|
||||
|
||||
// collect list of concave polygons
|
||||
list<const vertex *> concave_vertices;
|
||||
list<const Vertex *> concave_vertices;
|
||||
for (size_t i = 0; i < polygon.size(); ++i)
|
||||
{
|
||||
if (!is_oriented_ccw(polygon[prev_idx[i]], polygon[i], polygon[next_idx[i]]))
|
||||
@@ -143,7 +143,7 @@ vector<Triangle> Math::triangulate(const vector<vertex> &polygon)
|
||||
{
|
||||
next = next_idx[current];
|
||||
prev = prev_idx[current];
|
||||
const vertex &a = polygon[prev], &b = polygon[current], &c = polygon[next];
|
||||
const Vertex &a = polygon[prev], &b = polygon[current], &c = polygon[next];
|
||||
if (is_ear(a,b,c, concave_vertices))
|
||||
{
|
||||
triangles.push_back(Triangle(a,b,c));
|
||||
@@ -166,7 +166,7 @@ vector<Triangle> Math::triangulate(const vector<vertex> &polygon)
|
||||
return triangles;
|
||||
}
|
||||
|
||||
bool Math::isConvex(const std::vector<vertex> &polygon)
|
||||
bool Math::isConvex(const std::vector<Vertex> &polygon)
|
||||
{
|
||||
if (polygon.size() < 3)
|
||||
return false;
|
||||
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
* @param polygon Polygon to triangulate. Must not intersect itself.
|
||||
* @return List of triangles the polygon is composed of.
|
||||
**/
|
||||
std::vector<Triangle> triangulate(const std::vector<vertex> &polygon);
|
||||
std::vector<Triangle> triangulate(const std::vector<Vertex> &polygon);
|
||||
|
||||
/**
|
||||
* Checks whether a polygon is convex.
|
||||
@@ -134,7 +134,7 @@ public:
|
||||
* @param polygon Polygon to test.
|
||||
* @return True if the polygon is convex, false otherwise.
|
||||
**/
|
||||
bool isConvex(const std::vector<vertex> &polygon);
|
||||
bool isConvex(const std::vector<Vertex> &polygon);
|
||||
|
||||
/**
|
||||
* Calculate Simplex noise for the specified coordinate(s).
|
||||
|
||||
@@ -133,7 +133,7 @@ int w_newBezierCurve(lua_State *L)
|
||||
|
||||
int w_triangulate(lua_State *L)
|
||||
{
|
||||
std::vector<vertex> vertices;
|
||||
std::vector<Vertex> vertices;
|
||||
if (lua_istable(L, 1))
|
||||
{
|
||||
size_t top = lua_objlen(L, 1);
|
||||
@@ -143,7 +143,7 @@ int w_triangulate(lua_State *L)
|
||||
lua_rawgeti(L, 1, i);
|
||||
lua_rawgeti(L, 1, i+1);
|
||||
|
||||
vertex v;
|
||||
Vertex v;
|
||||
v.x = luaL_checknumber(L, -2);
|
||||
v.y = luaL_checknumber(L, -1);
|
||||
vertices.push_back(v);
|
||||
@@ -157,7 +157,7 @@ int w_triangulate(lua_State *L)
|
||||
vertices.reserve(top / 2);
|
||||
for (size_t i = 1; i <= top; i += 2)
|
||||
{
|
||||
vertex v;
|
||||
Vertex v;
|
||||
v.x = luaL_checknumber(L, i);
|
||||
v.y = luaL_checknumber(L, i+1);
|
||||
vertices.push_back(v);
|
||||
@@ -203,7 +203,7 @@ int w_triangulate(lua_State *L)
|
||||
|
||||
int w_isConvex(lua_State *L)
|
||||
{
|
||||
std::vector<vertex> vertices;
|
||||
std::vector<Vertex> vertices;
|
||||
if (lua_istable(L, 1))
|
||||
{
|
||||
size_t top = lua_objlen(L, 1);
|
||||
@@ -213,7 +213,7 @@ int w_isConvex(lua_State *L)
|
||||
lua_rawgeti(L, 1, i);
|
||||
lua_rawgeti(L, 1, i+1);
|
||||
|
||||
vertex v;
|
||||
Vertex v;
|
||||
v.x = luaL_checknumber(L, -2);
|
||||
v.y = luaL_checknumber(L, -1);
|
||||
vertices.push_back(v);
|
||||
@@ -227,7 +227,7 @@ int w_isConvex(lua_State *L)
|
||||
vertices.reserve(top / 2);
|
||||
for (size_t i = 1; i <= top; i += 2)
|
||||
{
|
||||
vertex v;
|
||||
Vertex v;
|
||||
v.x = luaL_checknumber(L, i);
|
||||
v.y = luaL_checknumber(L, i+1);
|
||||
vertices.push_back(v);
|
||||
|
||||
Reference in New Issue
Block a user