batch_manager.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #ifndef RVE_RENDER_SERVER_BATCH_MANAGER_H
00031 #define RVE_RENDER_SERVER_BATCH_MANAGER_H
00032 
00033 #include <rve_common/uuid.h>
00034 #include <map>
00035 
00036 namespace Ogre
00037 {
00038 class SceneManager;
00039 }
00040 
00041 namespace rve_render_server
00042 {
00043 
00044 template<typename Child, typename Input, typename Renderer, typename Description>
00045 class BatchManager
00046 {
00047 private:
00048   struct InputInfo
00049   {
00050     rve_common::UUID id;
00051     uint32_t internal_id;
00052     Renderer* renderer;
00053   };
00054   typedef std::map<rve_common::UUID, InputInfo> M_InputInfo;
00055 
00056 public:
00057   BatchManager(Ogre::SceneManager* scene_manager)
00058   : scene_manager_(scene_manager)
00059   {
00060 
00061   }
00062 
00063   ~BatchManager()
00064   {
00065     typename M_DescToRenderer::iterator it = renderers_.begin();
00066     typename M_DescToRenderer::iterator end = renderers_.end();
00067     for (; it != end; ++it)
00068     {
00069       delete it->second;
00070     }
00071 
00072     renderers_.clear();
00073   }
00074 
00075   void add(const rve_common::UUID& id, const Input& input)
00076   {
00077     Renderer* renderer = getOrCreateRenderer(input);
00078     uint32_t internal_id = renderer->add(id, input);
00079     InputInfo info;
00080     info.id = id;
00081     info.internal_id = internal_id;
00082     info.renderer = renderer;
00083     input_to_renderer_[id] = info;
00084   }
00085 
00086   void remove(const rve_common::UUID& id)
00087   {
00088     typename M_InputInfo::iterator it = input_to_renderer_.find(id);
00089 
00090     const InputInfo& info = it->second;
00091     info.renderer->remove(info.internal_id);
00092 
00093     input_to_renderer_.erase(it);
00094   }
00095 
00096 private:
00097   Renderer* getOrCreateRenderer(const Input& input)
00098   {
00099     Description desc = static_cast<Child*>(this)->createDescription(input);
00100     typename M_DescToRenderer::iterator it = renderers_.find(desc);
00101     if (it != renderers_.end())
00102     {
00103       return it->second;
00104     }
00105 
00106     Renderer* rend = new Renderer(scene_manager_, desc);
00107 
00108     renderers_.insert(std::make_pair(desc, rend));
00109     return rend;
00110   }
00111 
00112   M_InputInfo input_to_renderer_;
00113 
00114   typedef std::map<Description, Renderer*> M_DescToRenderer;
00115   M_DescToRenderer renderers_;
00116 
00117   Ogre::SceneManager* scene_manager_;
00118 };
00119 
00120 } // namespace rve_render_server
00121 
00122 #endif // RVE_RENDER_SERVER_BATCH_MANAGER_H
00123 


rve_render_server
Author(s): Josh Faust
autogenerated on Wed Dec 11 2013 14:31:15