Added the ability to have custom vertex attributes in Meshes (resolves issue #768.)

Added new love.graphics.newMesh variants: newMesh(vertexformat, vertices [, drawmode, meshusage]) and newMesh(vertexformat, numvertices [, drawmode, meshusage]).

Replaced the regular love.graphics.newMesh variants with newMesh(vertices [, drawmode, meshusage]) and newMesh(numvertices [, drawmode, meshusage]). To use an image or canvas with a mesh, use Mesh:setTexture.

vertexformat is a table with the following prototype:
{
  {attributename, datatype, components},
  {attributename, datatype, components},
  ...
}

Where attributename is the name of the vertex attribute (can be the built-in names 'VertexPosition', 'VertexTexCoord', or 'VertexColor', or a custom name for use in a vertex shader), datatype is the type of values used for the attribute ('float' or 'byte'), and components is the number of components in the vertex attribute (between 1 and 4.)

The vertex format is used to determine the layout of the vertices in the mesh, for example the 'regular' newMesh variants use this vertex format:
format = {
  {"VertexPosition", "float", 2},
  {"VertexTexCoord", "float", 2},
  {"VertexColor", "byte", 4},
}

The mesh usage parameter accepts the same constants as the spritebatch usage hint in love.graphics.newSpriteBatch - "dynamic", "static", and "stream".

Mesh:setVertex now sets *all* vertex attributes for a specific vertex in the Mesh.

Added Mesh:setVertexAttribute(vertexindex, attributeindex, attributevalue1, ...), which sets the values for a specific vertex attribute in a specific vertex in the Mesh (resolves issue #784.)

Added Mesh:getVertexFormat and Mesh:flush.

Added Mesh:setAttributeEnabled(attributename, enable) and Mesh:isAttributeEnabled(attributename), to enable or disable the use of a specific attribute when drawing the Mesh.

Added Mesh:attachAttribute(attributename, mesh), which makes the Mesh use a vertex attribute from another mesh when drawing the Mesh. This can be used to separate out vertex attributes which are updated at different rates into different meshes, and to share vertex data between multiple meshes.

Removed Mesh:setVertices, Mesh:getVertices, and Mesh:setVertexColors.
This commit is contained in:
Alex Szpakowski
2015-04-08 22:24:17 -03:00
parent f8ff50cfde
commit 2844499ef7
22 changed files with 1150 additions and 542 deletions
+9 -20
View File
@@ -47,17 +47,6 @@ class GLBuffer : public Volatile
{
public:
/**
* Create a new GLBuffer.
*
* @param size The size of the GLBuffer (in bytes).
* @param target GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER.
* @param usage GL_DYNAMIC_DRAW, etc.
* @param backing Determines what guarantees are placed on the data.
* @return A new GLBuffer.
*/
static GLBuffer *Create(size_t size, GLenum target, GLenum usage);
/**
* Constructor.
*
@@ -66,7 +55,7 @@ public:
* @param usage Usage hint, e.g. GL_DYNAMIC_DRAW.
* @param backing Determines what guarantees are placed on the data.
*/
GLBuffer(size_t size, GLenum target, GLenum usage);
GLBuffer(size_t size, const void *data, GLenum target, GLenum usage);
/**
* Destructor.
@@ -123,7 +112,7 @@ public:
*
* @return A pointer to memory which represents the buffer.
*/
virtual void *map();
void *map();
/**
* Unmap a previously mapped GLBuffer. The buffer must be unmapped
@@ -135,18 +124,18 @@ public:
* sub-range of data modified. Optional.
* @param usedSize The size of the sub-range of modified data. Optional.
*/
virtual void unmap(size_t usedOffset = 0, size_t usedSize = -1);
void unmap(size_t usedOffset = 0, size_t usedSize = -1);
/**
* Bind the GLBuffer to its specified target.
* (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, etc).
*/
virtual void bind();
void bind();
/**
* Unbind a prevously bound GLBuffer.
*/
virtual void unbind();
void unbind();
/**
* Fill a portion of the buffer with data.
@@ -157,7 +146,7 @@ public:
* @param size The size of the incoming data.
* @param data Pointer to memory to copy data from.
*/
virtual void fill(size_t offset, size_t size, const void *data);
void fill(size_t offset, size_t size, const void *data);
/**
* Get a pointer which represents the specified byte offset.
@@ -165,11 +154,11 @@ public:
* @param offset The byte offset. (0 is first byte).
* @return A pointer which represents the offset.
*/
virtual const void *getPointer(size_t offset) const;
const void *getPointer(size_t offset) const;
// Implements Volatile.
virtual bool loadVolatile();
virtual void unloadVolatile();
bool loadVolatile() override;
void unloadVolatile() override;
/**
* This helper class can bind a GLBuffer temporarily, and