mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
Add low-level hardware instancing support to Meshes.
Add “instancing” Graphics Feature constant. Add love.graphics.drawInstanced(mesh, instancecount, x, y, …) which draws the mesh multiple times in a single draw call. Each instance of the mesh will appear in the exact same spot unless one of the following are used: - Add an optional vertex attribute step type argument to Mesh:attachAttribute. “pervertex” is the default. “perinstance” causes the attribute to be per-instance instead of per-vertex, when the mesh is drawn. - Add love_InstanceID as a built-in read only int variable in GLSL 3 vertex shaders. It is always 0 except when a Mesh is drawn with more than 1 instance specified in the draw call. It can be used to manually compute or index into per-instance values in a shader. --HG-- branch : minor
This commit is contained in:
@@ -72,6 +72,13 @@ public:
|
||||
DATA_MAX_ENUM
|
||||
};
|
||||
|
||||
enum AttributeStep
|
||||
{
|
||||
STEP_PER_VERTEX,
|
||||
STEP_PER_INSTANCE,
|
||||
STEP_MAX_ENUM
|
||||
};
|
||||
|
||||
struct AttribFormat
|
||||
{
|
||||
std::string name;
|
||||
@@ -132,7 +139,7 @@ public:
|
||||
* Attaches a vertex attribute from another Mesh to this one. The attribute
|
||||
* will be used when drawing this Mesh.
|
||||
**/
|
||||
void attachAttribute(const std::string &name, Mesh *mesh, const std::string &attachname);
|
||||
void attachAttribute(const std::string &name, Mesh *mesh, const std::string &attachname, AttributeStep step = STEP_PER_VERTEX);
|
||||
bool detachAttribute(const std::string &name);
|
||||
|
||||
void *mapVertexData();
|
||||
@@ -192,6 +199,8 @@ public:
|
||||
|
||||
int bindAttributeToShaderInput(int attributeindex, const std::string &inputname);
|
||||
|
||||
void drawInstanced(Graphics *gfx, const Matrix4 &m, int instancecount);
|
||||
|
||||
// Implements Drawable.
|
||||
void draw(Graphics *gfx, const Matrix4 &m) override;
|
||||
|
||||
@@ -201,12 +210,16 @@ public:
|
||||
static bool getConstant(const char *in, DataType &out);
|
||||
static bool getConstant(DataType in, const char *&out);
|
||||
|
||||
static bool getConstant(const char *in, AttributeStep &out);
|
||||
static bool getConstant(AttributeStep in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
struct AttachedAttribute
|
||||
{
|
||||
Mesh *mesh;
|
||||
int index;
|
||||
AttributeStep step;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
@@ -254,6 +267,9 @@ private:
|
||||
static StringMap<DataType, DATA_MAX_ENUM>::Entry dataTypeEntries[];
|
||||
static StringMap<DataType, DATA_MAX_ENUM> dataTypes;
|
||||
|
||||
static StringMap<AttributeStep, STEP_MAX_ENUM>::Entry attributeStepEntries[];
|
||||
static StringMap<AttributeStep, STEP_MAX_ENUM> attributeSteps;
|
||||
|
||||
}; // Mesh
|
||||
|
||||
} // opengl
|
||||
|
||||
Reference in New Issue
Block a user