realXtend/naali — pull request #680 by jonnenauha (2013-06-03 13:52:03+00:00)
Title: Adminotech - Implement Ogre Instancing

Implements Ogre instancing support for Tundra in `EC_Mesh` and `OgreWorld`.

Implemented now

* New `useInstancing` attribute for EC_Mesh.
* Handles toggling instancing on/off during runtime.
* No other visible changes to external code, except `OgreEntity()` may return null if instancing is used. Created new `OgreInstancedEntity()` for these situations. I've checked all core c++ code that nothing blindly uses the OgreEntity() ptr.
* EC_Placeable attaching and EC_Mesh node transform keep working just like before instancing.
* OgreWorld implements `CreateInstance()` and `DestroyInstances()` functions that must be used by eg. `EC_Mesh` in pair to keep OgreWorld internal state in sync.
* Implements automatically injecting VS and PS programs into the input materials if they are not already defined. This logic will not modify the existing material but clone it and put changes there, so non instanced meshes can use the material at the same time. It will also replace shaders if there already are existing shaders, in this case it will prints a helpful warning log line that tells the author what we should do to fix the situation.
* Implements visual debugging on instance batch bounding boxes (utilizes an existing Ogre feature) via `IsDebugInstancingEnabled()` and `SetDebugInstancingEnabled(enabled)` and a qt property (just like PhysicsWorld does).
* Enables script logic to define static instancing for a particular mesh ref via `IsInstancingStatic(meshRef)` and `SetInstancingStatic(meshRef, static)`. This can make the rendering dramatically faster in cases where the instances are not moved. This must be decided by a inworld script, it is too bug prone to automate in OgreWorld. If you know a) you have huge amount of instances b) you are not going to move them via EC_Mesh transform or EC_Placeacble, either for scripts or via clients, you should go ahead and set static to true.
* Example scene `bin/scenes/Instancing/scene.txml`
* Test instanced and non-instanced runs with your own instance row/column count.
* UI can toggle static/non-static intancing.
* UI can toggle instancing debugging.

Needs work?

* Test all kinds of input materials and how they will behave. Also test multi submesh meshes.
* Integrate instancing VS part to Tundra super shader?

---------

I've sent this pull request in good time so people have time to review it before merging talk becomes relevant. Any feedback on the code in general and API in OgreWorld would be appreciated!