| VRS - The Virtual Rendering System |
| version 3.3 |
00001 #ifndef GREENSPACECOMPOSITEPAINTER_H 00002 #define GREENSPACECOMPOSITEPAINTER_H 00003 00004 #include <vrs/environment/config.h> 00005 #include <vrs/shapepainter.h> 00006 #include <vrs/container/dictionary.h> 00007 #include <vector> 00008 00009 00010 namespace VRS { 00011 class Engine; 00012 class Shape; 00013 class Engine; 00014 class Image; 00015 class MonoAttribute; 00016 class Facet; 00017 class PolygonSet; 00018 class ImageTexture2DGL; 00019 template<typename T> class NonPersistentArray; 00020 } 00021 00022 namespace EnvironmentRenderer { 00023 00024 class GreenSpaceComposite; 00025 class GreenSpace; 00026 00028 class VRS_ENV_API GreenSpaceCompositePainter : public VRS::ShapePainter { 00029 public: 00030 00032 virtual VRS::ID target() const; 00033 00035 virtual bool render(VRS::Engine*, const VRS::Shape*); 00036 00037 VRS_TYPEINFO(GreenSpaceCompositePainter, VRS::ShapePainter); 00038 00039 protected: 00040 struct GreenSpaceCompositeData 00041 { 00042 VRS::SO<VRS::MonoAttribute> atlasTexture; 00043 VRS::SO<VRS::MonoAttribute> tussockGeometry; 00044 }; 00045 00046 VRS::SO<VRS::Iterator<VRS::SO<VRS::Facet> > > getSurfacePolygons(VRS::SO<VRS::Iterator<VRS::SO<VRS::Facet> > > surface); 00047 //unsigned int createGrass(VRS::SO<VRS::PolygonSet> surface, 00048 // VRS::SO<GreenSpace> gs, 00049 // VRS::SO<VRS::NonPersistentArray<VRS::SO<VRS::PolygonSet> > > tussocksArray, 00050 // VRS::SO<VRS::NonPersistentArray<VRS::SO<VRS::Image> > > texturesArray); 00051 00052 unsigned int createGrass(VRS::SO<VRS::Iterator<VRS::SO<VRS::Facet> > > surface, 00053 VRS::SO<GreenSpace> gs, 00054 VRS::SO<VRS::NonPersistentArray<VRS::SO<VRS::PolygonSet> > > tussocksArray, 00055 VRS::SO<VRS::NonPersistentArray<VRS::SO<VRS::Image> > > texturesArray); 00056 00057 00058 VRS::SO<VRS::NonPersistentDictionary<GreenSpaceComposite*, GreenSpaceCompositeData> > m_compositeData; 00059 00060 // to avoid memory-leaks, a GSComposite's geometry is removed from the painter, if the 00061 // GSComposite is destroyed 00062 VRS::SO<VRS::Callback1<VRS::SharedObj*> > m_compositeDestructionCallback; 00063 void removeCompositeFromPainter(VRS::SharedObj* s); 00064 00065 00066 void updateComposite(VRS::SO<GreenSpaceComposite> gsc, GreenSpaceCompositeData &data); 00067 VRS::SO<VRS::ImageTexture2DGL> createTextureAtlas(VRS::SO<VRS::Iterator<VRS::SO<VRS::PolygonSet> > > tussocks, 00068 VRS::SO<VRS::Iterator<VRS::SO<VRS::Image> > > tussockTextures); 00069 00070 // GreenSpaces used by GSComposites are cached. There are two advantages caching the 00071 // geometry: 00072 // 1. recreationtime reduces, as geometry is generated only for those GreenSpaces 00073 // that were modified 00074 // 2. GreenSpaces that were not modified remain uneffected by the recreation process. 00075 // Without caching, 'replanting' the grass occured for all GreenSpaces, thus 00076 // the tussock positions altered across the whole GSComposite which can be 00077 // confusing if you do not expect it. 00078 struct GreenSpaceData 00079 { 00080 VRS::SO<VRS::NonPersistentArray<VRS::SO<VRS::PolygonSet> > > tussocks; 00081 VRS::SO<VRS::NonPersistentArray<VRS::SO<VRS::Image> > > textures; 00082 }; 00083 00084 VRS::SO<VRS::NonPersistentDictionary<GreenSpace*, GreenSpaceData> > m_gsData; 00085 00086 // stores which tussocks were newly created and need texCoord-transformation due to the 00087 // textureatlas 00088 std::vector<bool> m_updateTextureCoordinates; 00089 00090 // same purpose as for GSComposites 00091 VRS::SO<VRS::Callback1<VRS::SharedObj*> > m_gsDestructionCallback; 00092 void removeGreenSpaceFromPainter(VRS::SharedObj* s); 00093 00094 }; 00095 00096 } // namepsace EnvironmentRenderer 00097 00098 #endif // GREENSPACECOMPOSITEPAINTER_H 00099