VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
visutwin::canvas::BatchManager Class Reference

#include <framework/batching/batchManager.h>

Public Member Functions

void addGroup (const BatchGroup &group)
const std::vector< std::unique_ptr< Batch > > & batches () const
 BatchManager (GraphicsDevice *device)
void destroy (Scene *scene=nullptr)
const BatchGroupgetGroupById (int groupId) const
void prepare (Scene *scene=nullptr)
void removeGroup (int groupId)
void updateAll ()

Detailed Description

Glues many mesh instances into a single one for better performance.

BatchManager merges mesh instances that share the same material into a single combined Mesh with one draw call. This dramatically reduces CPU overhead in scenes with many static objects.

Usage:

  1. addGroup() — register a BatchGroup configuration.
  2. Tag RenderComponents with setBatchGroupId(groupId).
  3. prepare() — build batches (merges geometry, hides originals).
  4. destroy() — tear down batches, restore originals.

Supports both static and dynamic batching:

  • Static: geometry baked to world space once.
  • Dynamic: geometry in local space + per-vertex bone index, with a per-frame matrix palette providing world transforms (SkinBatchInstance).

Definition at line 41 of file batchManager.h.

Constructor & Destructor Documentation

◆ BatchManager()

visutwin::canvas::BatchManager::BatchManager ( GraphicsDevice * device)
explicit

Definition at line 59 of file batchManager.cpp.

Member Function Documentation

◆ addGroup()

void visutwin::canvas::BatchManager::addGroup ( const BatchGroup & group)

Register a batch group configuration.

Definition at line 61 of file batchManager.cpp.

References visutwin::canvas::BatchGroup::id.

◆ batches()

const std::vector< std::unique_ptr< Batch > > & visutwin::canvas::BatchManager::batches ( ) const
inline

Definition at line 73 of file batchManager.h.

◆ destroy()

void visutwin::canvas::BatchManager::destroy ( Scene * scene = nullptr)

Destroy all batches, restoring original mesh instances to visible. If scene is provided, batched MeshInstances are removed from layers.

Definition at line 179 of file batchManager.cpp.

References getGroupById(), and visutwin::canvas::Scene::layers().

Referenced by prepare().

◆ getGroupById()

const BatchGroup * visutwin::canvas::BatchManager::getGroupById ( int groupId) const

Get a batch group by id. Returns nullptr if not found.

Definition at line 83 of file batchManager.cpp.

Referenced by destroy(), and prepare().

◆ prepare()

void visutwin::canvas::BatchManager::prepare ( Scene * scene = nullptr)

Build batches for all registered groups. Called once after scene setup (or when meshes change). Collects MeshInstances by (groupId, material), merges geometry, hides originals, and creates combined MeshInstances.

If scene is provided, batched MeshInstances are automatically registered with the appropriate layers. If nullptr, the caller must manually add batch->meshInstance to the desired layers.

Definition at line 92 of file batchManager.cpp.

References destroy(), getGroupById(), visutwin::canvas::RenderComponent::instances(), and visutwin::canvas::Scene::layers().

◆ removeGroup()

void visutwin::canvas::BatchManager::removeGroup ( int groupId)

Remove a batch group and destroy its batches.

Definition at line 66 of file batchManager.cpp.

◆ updateAll()

void visutwin::canvas::BatchManager::updateAll ( )

Per-frame update: refresh matrix palettes and AABBs for dynamic batches. Call from Engine::update() each frame.

Definition at line 415 of file batchManager.cpp.


The documentation for this class was generated from the following files: