|
VisuTwin Canvas
C++ 3D Engine — Metal Backend
|
#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 BatchGroup * | getGroupById (int groupId) const |
| void | prepare (Scene *scene=nullptr) |
| void | removeGroup (int groupId) |
| void | updateAll () |
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:
Supports both static and dynamic batching:
Definition at line 41 of file batchManager.h.
|
explicit |
Definition at line 59 of file batchManager.cpp.
| 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.
|
inline |
Definition at line 73 of file batchManager.h.
| 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().
| 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.
| 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().
| void visutwin::canvas::BatchManager::removeGroup | ( | int | groupId | ) |
Remove a batch group and destroy its batches.
Definition at line 66 of file batchManager.cpp.
| 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.