Added instancing support to Meshes via Mesh:setInstanceCount. Added a new built-in variable to vertex shaders: int love_InstanceID.

love.graphics.draw(mesh) will draw the mesh instancecount times, using hardware instancing when available. The only way to draw individual instances differently from each other is to use the love_InstanceID variable in a vertex shader.

Added love.graphics.isSupported(“instancing”). Hardware instancing is supported if true, otherwise a (slower) pseudo-instancing fallback is used internally when drawing instanced meshes.
This commit is contained in:
Alex Szpakowski
2014-01-21 06:01:50 -04:00
parent 81d9810ed8
commit 73f1ce0d40
13 changed files with 217 additions and 13 deletions
+24
View File
@@ -63,6 +63,17 @@ public:
VENDOR_UNKNOWN
};
// Vertex attributes used in shaders by LOVE. The values map to OpenGL
// generic vertex attribute indices, when applicable.
// LOVE uses the old hard-coded attribute APIs for positions, colors, etc.
// (for now.)
enum VertexAttrib
{
// Instance ID when pseudo-instancing is used.
ATTRIB_PSEUDO_INSTANCE_ID = 1,
ATTRIB_MAX_ENUM
};
// A rectangle representing an OpenGL viewport or a scissor box.
struct Viewport
{
@@ -99,6 +110,16 @@ public:
**/
void prepareDraw();
/**
* glDrawArraysInstanced with a pseudo-instancing fallback.
**/
void drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei primcount);
/**
* glDrawElementsInstanced with a pseudo-instancing fallback.
**/
void drawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
/**
* Sets the current constant color.
**/
@@ -230,6 +251,9 @@ private:
Viewport viewport;
Viewport scissor;
// The last ID value used for pseudo-instancing.
int lastPseudoInstanceID;
} state;
}; // OpenGL