From 99ce0bc5e08c0ae74fe4d070d53cafa0b4357590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 8 Dec 2012 23:30:44 +0100 Subject: [PATCH] SceneGraph: document performance tricks with DrawableGroup. --- src/SceneGraph/Drawable.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/SceneGraph/Drawable.h b/src/SceneGraph/Drawable.h index 6852e7b1b..99148d2f2 100644 --- a/src/SceneGraph/Drawable.h +++ b/src/SceneGraph/Drawable.h @@ -79,6 +79,32 @@ void MyApplication::drawEvent() { } @endcode +@section Drawable-performance Using drawable groups to improve performance + +You can organize your drawables to multiple groups to minimize OpenGL state +changes - for example put all objects using the same shader, the same light +setup etc into one group, then put all transparent into another and set common +parameters once for whole group instead of setting them again in each draw() +implementation. Example: +@code +Shaders::PhongShader* shader; +SceneGraph::DrawableGroup3D<> phongObjects, transparentObjects; + +void MyApplication::drawEvent() { + shader->setProjectionMatrix(camera->projectionMatrix()) + ->setLightPosition(lightPosition) + ->setLightColor(lightColor) + ->setAmbientColor(ambientColor); + camera.draw(phongObjects); + + Renderer::setFeature(Renderer::Feature::Blending, true); + camera.draw(transparentObjects); + Renderer::setFeature(Renderer::Feature::Blending, false); + + // ... +} +@endcode + @see @ref scenegraph, Drawable2D, Drawable3D, DrawableGroup2D, DrawableGroup3D */ #ifndef DOXYGEN_GENERATING_OUTPUT