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:
Alex Szpakowski
2017-01-22 20:52:11 -04:00
parent 731b5d5cf0
commit bea7cfdaab
11 changed files with 162 additions and 31 deletions
+7
View File
@@ -490,6 +490,11 @@ void Graphics::flushStreamDraws()
streamBufferState.indexCount = 0;
}
void Graphics::drawInstanced(Mesh *mesh, const love::Matrix4 &m, int instancecount)
{
mesh->drawInstanced(this, m, instancecount);
}
static void APIENTRY debugCB(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei /*len*/, const GLchar *msg, const GLvoid* /*usr*/)
{
// Human-readable strings for the debug info.
@@ -1487,6 +1492,8 @@ bool Graphics::isSupported(Feature feature) const
return gl.isPixelShaderHighpSupported();
case FEATURE_GLSL3:
return GLAD_ES_VERSION_3_0 || gl.isCoreProfile();
case FEATURE_INSTANCING:
return gl.isInstancingSupported();
default:
return false;
}