Dynamic Mesh Batching

Hello,

I have question about MESH_COMMAND Batching. The function
void Renderer::processRenderCommand(RenderCommand* command)

has the following code:
if (cmd->isSkipBatching() || _lastBatchedMeshCommand == nullptr || _lastBatchedMeshCommand->getMaterialID() != cmd->getMaterialID())

If you see to the
MeshCommand::genMaterialID(GLuint texID, void* glProgramState, GLuint vertexBuffer, GLuint indexBuffer, BlendFunc blend)
you will find that it use glProgramState pointer when hash is calculated.

But this pointer is different for each MESH. Thus butching does not work for mesh even it has the same material as previouse in the rendering cycle.

Could you please confirm that, or I miss something?

I really do not undrestand, what you mean under ‘batching’, after that code:

void MeshCommand::batchDraw()
{
    if (_material)
    {
        for(const auto& pass: _material->_currentTechnique->_passes)
        {
            pass->bind(_mv);

            glDrawElements(_primitive, (GLsizei)_indexCount, _indexFormat, 0);
            CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, _indexCount);

            pass->unbind();
        }
    }

pass->bind(_mv) calls _vertexAttribBinding->bind(); which calls

glBindBuffer(GL_ARRAY_BUFFER, meshVertexData->getVertexBuffer()->getVBO());

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _meshIndexData->getIndexBuffer()->getVBO());

every frame.

What do you consider as mesh ‘batching’ an how it use ?

Yes, the dynamic auto-batching is meant and was designed mostly for 2D sprites that reside in texture atlases.

Your issue is for rendering either 3D model mesh, or some custom mesh you created, is that correct?

While they could be batched in some, but not all, situations you are noticing the designed architecture for mesh rendering that each mesh is drawn separately.

This engine wasn’t really built for 3D model rendering. You could write your own derived from PrimitiveCommand (or CustomCommand), or change the engine code itself for MeshCommand, to suit your needs. Or you could combine multiple meshes into a single mesh as a means of a workaround.

1 Like

Thanks for reply,

You are right, I render 3D models. Some of your advises are implemented already (ex. combine multiple meshes - but not everything can be combined by design reason). I wanted only clarify about engine implementation.

One notice. In my opinion cocos2d-x is good choice for simple 3d games and platformers. It has many basic 3d conceptions where skeletal animation and shaders with lights are the main, with acceptable fps.
I really hope you do not abandon this theme.

1 Like

Cool. Hope it’s working well enough for your needs.

(p.s. I’m not a core developer, beyond getting a few PRs accepted, just a user of the engine)

Ok, nevertheless=)