Does InstanceNode use glDrawElementsInstanced calls or what does it use?
I miss instance drawing. For simple Particle instance, it is far better. I could push out over 100k meshes with no performance issues but with JME not doing it, I couldn’t do 20% of that without it effecting performance.
In my own engine I was doing the following for instancing batching.
private void renderChunkInstanced(List<GameItem> gameItems, Transformation transformation, Matrix4f viewMatrix, boolean view3d)
{
this.modelViewBuffer.clear();
this.colorMatrixBuffer.clear();
this.modelPosBuffer.clear();
this.textureAtlasBuffer.clear();
int i = 0;
Texture text = gameItems.get(0).getTexture();
for (GameItem gameItem : gameItems) {
// Update projection Matrix
Matrix4f modelViewMatrix;
if (view3d)
modelViewMatrix = transformation.getModelViewMatrix(gameItem, viewMatrix);
else
modelViewMatrix = transformation.getOrtoProjModelMatrix(gameItem, viewMatrix);
modelViewMatrix.get(MATRIX_SIZE_FLOATS * i, modelViewBuffer);
i++;
Vector4f color = new Vector4f(gameItem.getColor().x,gameItem.getColor().y, gameItem.getColor().z,gameItem.getTranslusentLevel());
color.get(FLOAT_SIZE_BYTES * i, colorMatrixBuffer );
Vector4f pos = new Vector4f(gameItem.getPosition().x,gameItem.getPosition().y, gameItem.getPosition().z,1.0f);
pos.get(FLOAT_SIZE_BYTES * i, modelPosBuffer );
if (text != null)
{
int col = gameItem.getTextPos() % text.getNumCols();
int row = gameItem.getTextPos() / text.getNumCols();
float textXOffset = (float) col / text.getNumCols();
float textYOffset = (float) row / text.getNumRows();
Vector2f pos2f = new Vector2f(textXOffset,textYOffset);
pos2f.get(2 * i, textureAtlasBuffer );
} else {
Vector2f pos2f = new Vector2f(1.0f, 1.0f);
pos2f.get(2 * i, textureAtlasBuffer );
}
}
glBindBuffer(GL_ARRAY_BUFFER, modelViewVBO);
glBufferData(GL_ARRAY_BUFFER, modelViewBuffer, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, colorMatrixVBO);
glBufferData(GL_ARRAY_BUFFER, colorMatrixBuffer, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, modelPosVBO);
glBufferData(GL_ARRAY_BUFFER, modelPosBuffer, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, textureAtlasVBO);
glBufferData(GL_ARRAY_BUFFER, textureAtlasBuffer, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_id);
glDrawElementsInstanced(GL_TRIANGLES, draw_count, GL_UNSIGNED_INT, 0, gameItems.size());
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
It would allow 100k+ instances without performance hits. If I could convert particles emitter to use InstanceNode if it used the DrawElementInstance, it would be worth it.