VR-Forces 4.0.4 Class Documentation
include/vrvOsg/DtOsgShapeCache.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 ** Copyright (c) 2010 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 ******************************************************************************/
00005 /******************************************************************************
00006 ** $RCSfile:  $ $Revision:  $ $State:  $
00007 ******************************************************************************/
00008 
00012 
00013 #pragma once
00014 #include <vrvOsg/vrvOsg.h>
00015 #include <vrvUtil/DtVirtualBaseClass.h>
00016 #include <osg/ref_ptr>
00017 #include <osg/PrimitiveSet>
00018 #include <boost/unordered_map.hpp>
00019 #include <functional>
00020 
00021 namespace osg
00022 {
00023    class Drawable;
00024 }
00025 
00026 namespace makVrv
00027 {
00028 
00032    class DT_DLL_VRVOSG DtOsgShapeCache : public DtVirtualBaseClass
00033    {
00034    public:
00035 
00037       static DtOsgShapeCache& instance(DtDe& de);
00038 
00040       DtOsgShapeCache();
00041 
00043       virtual ~DtOsgShapeCache();
00044 
00045       enum ShapeType
00046       {
00047          ShadedCube,
00048          ShadedCylinder,
00049       };
00050 
00052       void releaseResources();
00053 
00055       void ts_clearInstancingCache();
00056 
00058       osg::Drawable* getShapeInstance(ShapeType,unsigned int faceCount);
00059 
00064       osg::DrawElementsUInt* getCircularIndexBuffer(int vertexCount, 
00065          int firstIndex, int indexStep);
00066 
00067    protected:
00068 
00070       virtual osg::Drawable* createShapeInstance(ShapeType,unsigned int faceCount);
00071 
00072       struct ShapeKey
00073       {
00074          ShapeType type;
00075          unsigned int faceCount;
00076 
00077          bool operator == (const ShapeKey& other) const
00078          {
00079             return type == other.type && faceCount == other.faceCount;
00080          }
00081       };
00082 
00083       struct ShapeKey_hash : std::unary_function<ShapeKey, std::size_t>
00084       {
00085          std::size_t operator()(ShapeKey const& p) const
00086          {
00087             std::size_t seed = 0;
00088             boost::hash_combine(seed, p.type);
00089             boost::hash_combine(seed, p.faceCount);
00090             return seed;
00091          }
00092       };
00093 
00094       //Use map rather than unordered_map due to hash difficulties.
00095       typedef boost::unordered_map<ShapeKey, osg::ref_ptr<osg::Drawable>,
00096          ShapeKey_hash  > ShapeMap;
00097       ShapeMap myShapeMap;
00098 
00099 
00100       struct IndexBufferKey
00101       {
00102          unsigned int count;
00103          unsigned int initial;
00104          unsigned int step;
00105 
00106          bool operator == (const IndexBufferKey& other) const
00107          {
00108             return count == other.count && initial == other.initial &&
00109                step == other.step;
00110          }
00111       };
00112 
00113 
00114       struct IndexBufferKey_hash : std::unary_function<IndexBufferKey, std::size_t>
00115       {
00116          std::size_t operator()(IndexBufferKey const& p) const
00117          {
00118             std::size_t seed = 0;
00119             boost::hash_combine(seed, p.count);
00120             boost::hash_combine(seed, p.initial);
00121             boost::hash_combine(seed, p.step);
00122             return seed;
00123          }
00124       };
00125 
00126       typedef boost::unordered_map<IndexBufferKey, osg::ref_ptr<osg::DrawElementsUInt>,
00127          IndexBufferKey_hash > IndexBufferMap;
00128       IndexBufferMap myIndexBufferMap;
00129 
00130    };
00131 }
00132 

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)