csplugincommon/rendermanager/rendergroupinghandler.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

csplugincommon/rendermanager/rendergroupinghandler.h
Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2010 by Frank Richter
    00003
    00004     This library is free software; you can redistribute it and/or
    00005     modify it under the terms of the GNU Library General Public
    00006     License as published by the Free Software Foundation; either
    00007     version 2 of the License, or (at your option) any later version.
    00008
    00009     This library is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012     Library General Public License for more details.
    00013
    00014     You should have received a copy of the GNU Library General Public
    00015     License along with this library; if not, write to the Free
    00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00017 */
    00018
    00019 #ifndef __CS_CSPLUGINCOMMON_RENDERMANAGER_RENDERGROUPINGHANDLER_H__
    00020 #define __CS_CSPLUGINCOMMON_RENDERMANAGER_RENDERGROUPINGHANDLER_H__
    00021
    00026 namespace CS
    00027 {
    00028   namespace RenderManager
    00029   {
    00030     template<typename RenderTree, typename ContextSetup>
    00031     class RenderGroupingHandler
    00032     {
    00033     public:
    00034       typedef typename RenderTree::ContextNode ContextNode;
    00035
    00036       RenderGroupingHandler (iEngine* engine, RenderTree& renderTree, ContextSetup& contextSetup)
    00037        : engine (engine), renderTree (renderTree), contextSetup (contextSetup) {}
    00038
    00039       void operator() (ContextNode* context)
    00040       {
    00041         typename RenderTree::MeshNodeTreeType::Iterator meshNodeIter (
    00042           context->meshNodes.GetIterator());
    00043         int lastGrouping = -1;
    00044         ContextNode* targetContext = nullptr;
    00045
    00046         while (meshNodeIter.HasNext ())
    00047         {
    00048           typename RenderTree::TreeTraitsType::MeshNodeKeyType key;
    00049           meshNodeIter.PeekNext (key);
    00050
    00051           CS::RenderPriorityGrouping newGrouping = engine->GetRenderPriorityGrouping (
    00052             CS::Graphics::RenderPriority (uint (key.priority)));
    00053           if (lastGrouping == -1)
    00054           {
    00055             lastGrouping = newGrouping;
    00056             context->renderGrouping = newGrouping;
    00057           }
    00058           else if (lastGrouping != newGrouping)
    00059           {
    00060             lastGrouping = newGrouping;
    00061
    00062             // Set up last context
    00063             if (targetContext)
    00064               contextSetup (*targetContext);
    00065
    00066             // Create new context to add coming mesh nodes to
    00067             ContextNode* newContext =
    00068               renderTree.CloneContext (targetContext ? targetContext : context);
    00069             targetContext = newContext;
    00070             targetContext->renderGrouping = newGrouping;
    00071           }
    00072
    00073           if (targetContext)
    00074             context->MoveRenderMeshes (meshNodeIter, targetContext);
    00075           else
    00076             meshNodeIter.Next ();
    00077         }
    00078         // Set up last context
    00079         if (targetContext)
    00080           contextSetup (*targetContext);
    00081       }
    00082     protected:
    00083       iEngine* engine;
    00084       RenderTree& renderTree;
    00085       ContextSetup& contextSetup;
    00086     };
    00087   } // namespace RenderManager
    00088 } // namespace CS
    00089
    00090 #endif // __CS_CSPLUGINCOMMON_RENDERMANAGER_RENDERGROUPINGHANDLER_H__