root/OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/Document.h @ 10084

Revision 10084, 11.2 kB (checked in by robert, 6 years ago)

Refactored the subsurface PolygonOffset? code so that it uses sensible values and also moves management of the PolygonOffset? and Depth attribute objects into the Document object rather than using static vars.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[7748]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
[5038]14//
15// OpenFlight® loader for OpenSceneGraph
16//
[7748]17//  Copyright (C) 2005-2007  Brede Johansen
[5038]18//
19
20#ifndef FLT_FLIGHTDATA_H
21#define FLT_FLIGHTDATA_H 1
22
23#include <vector>
24#include <osg/Notify>
25#include <osg/Transform>
26#include <osg/Geometry>
[10084]27#include <osg/PolygonOffset>
28#include <osg/Depth>
[5038]29#include <osgDB/ReaderWriter>
30
[8003]31#include "Types.h"
[5038]32#include "Record.h"
33#include "Pools.h"
34
35
36namespace flt {
37
38class Header;
39class PushLevel;
40class PopLevel;
41
42enum Version
43{
44    VERSION_11      = 11,
45    VERSION_12      = 12,
46    VERSION_13      = 13,
47    VERSION_14      = 14,
48    VERSION_14_1    = 14,
49    VERSION_14_2    = 1420,
50    VERSION_15_1    = 1510,
51    VERSION_15_4    = 1540,
52    VERSION_15_5    = 1550,
53    VERSION_15_6    = 1560,
54    VERSION_15_7    = 1570,
55    VERSION_15_8    = 1580,
[5145]56    VERSION_16_0    = 1600,
57    VERSION_16_1    = 1610
[5038]58};
59
60enum CoordUnits {
61    METERS = 0,
62    KILOMETERS = 1,
63    FEET = 4,
64    INCHES = 5,
65    NAUTICAL_MILES = 8
66};
67
68double unitsToMeters(CoordUnits unit);
69
70
71enum Projection {
72    FLAT_EARTH = 0,
73    TRAPEZOIDAL = 1,
74    ROUND_EARTH = 2,
75    LAMBERT = 3,
76    UTM = 4,
77    GEODETIC = 5,
78    GEOCENTRIC = 6
79};
80
81enum Ellipsoid {
82    WGS_1984 = 0,
83    WGS_1972 = 1,
84    BESSEL = 2,
85    CLARKE_1866 = 3,
86    NAD_1927 = 4
87};
88
89
90class Document
91{
92    public:
93
[5145]94        Document();
95        virtual ~Document();
[5038]96
97        void setOptions(const osgDB::ReaderWriter::Options* options) { _options = options; }
98        const osgDB::ReaderWriter::Options* getOptions() const { return _options.get(); }
99
[8563]100        // Current primary record
[7756]101        void setCurrentPrimaryRecord(PrimaryRecord* record) { _currentPrimaryRecord=record; }
[5038]102        PrimaryRecord* getCurrentPrimaryRecord() { return _currentPrimaryRecord.get(); }
103        const PrimaryRecord* getCurrentPrimaryRecord() const { return _currentPrimaryRecord.get(); }
104
105        // Level stack
106        PrimaryRecord* getTopOfLevelStack();
107        void pushLevel();
108        void popLevel();
109
110        // Subface stack
111        void pushSubface();
112        void popSubface();
113
114        // Extension stack
115        void pushExtension();
116        void popExtension();
117
118        void setHeaderNode(osg::Node* node) { _osgHeader = node; }
119        osg::Node* getHeaderNode() { return _osgHeader.get(); }
120
121        // Instance definitions
122        void setInstanceDefinition(int no, osg::Node* node) { _instanceDefinitionMap[no] = node; }
123        osg::Node* getInstanceDefinition(int no);
124
125        uint32 version() const { return _version; }
126        bool done() const { return _done; }
127        int level() const { return _level; }
128        int subfaceLevel() const { return _subfaceLevel; }
129        double unitScale() const { return _unitScale; }
130
131        // Pools
132        void setVertexPool(VertexPool* vp) { _vertexPool = vp; }
133        VertexPool* getVertexPool() { return _vertexPool.get(); }
134        const VertexPool* getVertexPool() const { return _vertexPool.get(); }
135
[5236]136        void setColorPool(ColorPool* cp, bool parent=false) { _colorPool = cp; _colorPoolParent=parent; }
[5038]137        ColorPool* getColorPool() { return _colorPool.get(); }
138        const ColorPool* getColorPool() const { return _colorPool.get(); }
[5236]139        bool getColorPoolParent() const { return _colorPoolParent; }
[5038]140
[5236]141        void setTexturePool(TexturePool* tp, bool parent=false) { _texturePool = tp; _texturePoolParent=parent; }
[6091]142        TexturePool* getTexturePool() { return _texturePool.get(); }
[5038]143        TexturePool* getOrCreateTexturePool();
[5236]144        bool getTexturePoolParent() const { return _texturePoolParent; }
145
146        void setMaterialPool(MaterialPool* mp, bool parent=false) { _materialPool = mp; _materialPoolParent=parent; }
[6091]147        MaterialPool* getMaterialPool() { return _materialPool.get(); }
[5038]148        MaterialPool* getOrCreateMaterialPool();
[5236]149        bool getMaterialPoolParent() const { return _materialPoolParent; }
150
[6091]151        void setLightSourcePool(LightSourcePool* lsp, bool parent=false) { _lightSourcePool = lsp; _lightSourcePoolParent=parent; }
152        LightSourcePool* getLightSourcePool() { return _lightSourcePool.get(); }
153        LightSourcePool* getOrCreateLightSourcePool();
154        bool getLightSourcePoolParent() const { return _lightSourcePoolParent; }
155
[5236]156        void setLightPointAppearancePool(LightPointAppearancePool* lpap, bool parent=false) { _lightPointAppearancePool = lpap; _lightPointAppearancePoolParent=parent; }
[6091]157        LightPointAppearancePool* getLightPointAppearancePool() { return _lightPointAppearancePool.get(); }
[5038]158        LightPointAppearancePool* getOrCreateLightPointAppearancePool();
[5236]159        bool getLightPointAppearancePoolParent() const { return _lightPointAppearancePoolParent; }
160
[6759]161        void setLightPointAnimationPool(LightPointAnimationPool* lpap, bool parent=false) { _lightPointAnimationPool = lpap; _lightPointAnimationPoolParent=parent; }
162        LightPointAnimationPool* getLightPointAnimationPool() { return _lightPointAnimationPool.get(); }
163        LightPointAnimationPool* getOrCreateLightPointAnimationPool();
164        bool getLightPointAnimationPoolParent() const { return _lightPointAnimationPoolParent; }
165
[5236]166        void setShaderPool(ShaderPool* cp, bool parent=false) { _shaderPool = cp; _shaderPoolParent=parent; }
[6091]167        ShaderPool* getShaderPool() { return _shaderPool.get(); }
[5038]168        ShaderPool* getOrCreateShaderPool();
[5236]169        bool getShaderPoolParent() const { return _shaderPoolParent; }
[5038]170
[10084]171        void setSubSurfacePolygonOffset(int level, osg::PolygonOffset* po);
172        osg::PolygonOffset* getSubSurfacePolygonOffset(int level);
[5236]173
[10084]174        void setSubSurfaceDepth(osg::Depth* depth) { _subsurfaceDepth = depth; }
175        osg::Depth* getSubSurfaceDepth() { return _subsurfaceDepth.get(); }
176
177
[5038]178        // Options
[5794]179        void setReplaceClampWithClampToEdge(bool flag) { _replaceClampWithClampToEdge = flag; }
180        bool getReplaceClampWithClampToEdge() const { return _replaceClampWithClampToEdge; }
[5205]181        void setPreserveFace(bool flag) { _preserveFace = flag; }
182        bool getPreserveFace() const { return _preserveFace; }
[5528]183        void setPreserveObject(bool flag) { _preserveObject = flag; }
184        bool getPreserveObject() const { return _preserveObject; }
[5038]185        void setDefaultDOFAnimationState(bool state) { _defaultDOFAnimationState = state; }
186        bool getDefaultDOFAnimationState() const { return _defaultDOFAnimationState; }
187        void setUseTextureAlphaForTransparancyBinning(bool flag) { _useTextureAlphaForTransparancyBinning=flag; }
188        bool getUseTextureAlphaForTransparancyBinning() const { return _useTextureAlphaForTransparancyBinning; }
[5610]189        void setUseBillboardCenter(bool flag) { _useBillboardCenter=flag; }
190        bool getUseBillboardCenter() const { return _useBillboardCenter; }
[5038]191        void setDoUnitsConversion(bool flag) { _doUnitsConversion=flag; }
192        bool getDoUnitsConversion() const { return _doUnitsConversion; }
193        void setDesiredUnits(CoordUnits units ) { _desiredUnits=units; }
194        CoordUnits getDesiredUnits() const { return _desiredUnits; }
[10084]195
[7931]196        void setKeepExternalReferences( bool flag) { _keepExternalReferences=flag; }
[5461]197        bool getKeepExternalReferences() const { return _keepExternalReferences; }
[5038]198
[7931]199        void setReadObjectRecordData(bool flag) { _readObjectRecordData = flag; }
200        bool getReadObjectRecordData() const { return _readObjectRecordData; }
201
[5038]202    protected:
203
204        // Options
205        osg::ref_ptr<const osgDB::ReaderWriter::Options> _options;
[5794]206        bool                        _replaceClampWithClampToEdge;
[5205]207        bool                        _preserveFace;
[5528]208        bool                        _preserveObject;
[5038]209        bool                        _defaultDOFAnimationState;
210        bool                        _useTextureAlphaForTransparancyBinning;
[5610]211        bool                        _useBillboardCenter;
[5038]212        bool                        _doUnitsConversion;
[7931]213        bool                        _readObjectRecordData;
[5038]214        CoordUnits                  _desiredUnits;
[5461]215       
216        bool                        _keepExternalReferences;
[5038]217
218        friend class Header;
219        bool _done;
220        int _level;
221        int _subfaceLevel;
222        double _unitScale;
223        uint32 _version;
224
225        // Header data
226        osg::ref_ptr<osg::Node> _osgHeader;
227
228        osg::ref_ptr<VertexPool> _vertexPool;
229        osg::ref_ptr<ColorPool> _colorPool;
230        osg::ref_ptr<TexturePool> _texturePool;
231        osg::ref_ptr<MaterialPool> _materialPool;
[6091]232        osg::ref_ptr<LightSourcePool> _lightSourcePool;
[5038]233        osg::ref_ptr<LightPointAppearancePool> _lightPointAppearancePool;
[6759]234        osg::ref_ptr<LightPointAnimationPool> _lightPointAnimationPool;
[5038]235        osg::ref_ptr<ShaderPool> _shaderPool;
[10084]236
237        typedef std::map<int, osg::ref_ptr<osg::PolygonOffset> > SubSurfacePolygonOffsets;
238        SubSurfacePolygonOffsets _subsurfacePolygonOffsets;
239        osg::ref_ptr<osg::Depth> _subsurfaceDepth;
240
[5236]241        bool _colorPoolParent;
242        bool _texturePoolParent;
243        bool _materialPoolParent;
[6091]244        bool _lightSourcePoolParent;
[5236]245        bool _lightPointAppearancePoolParent;
[6759]246        bool _lightPointAnimationPoolParent;
[5236]247        bool _shaderPoolParent;
[5038]248
249        osg::ref_ptr<PrimaryRecord> _currentPrimaryRecord;
250
251        typedef std::vector<osg::ref_ptr<PrimaryRecord> > LevelStack;
252        LevelStack _levelStack;
253        LevelStack _extensionStack;
254
255        typedef std::map<int,osg::ref_ptr<osg::Node> > InstanceDefinitionMap;
256        InstanceDefinitionMap _instanceDefinitionMap;
257};
258
259
260inline TexturePool* Document::getOrCreateTexturePool()
261{
262    if (!_texturePool.valid())
263        _texturePool = new TexturePool;
264    return _texturePool.get();
265}
266
267
268inline MaterialPool* Document::getOrCreateMaterialPool()
269{
270    if (!_materialPool.valid())
271        _materialPool = new MaterialPool;
272    return _materialPool.get();
273}
274
275
[6091]276inline LightSourcePool* Document::getOrCreateLightSourcePool()
277{
278    if (!_lightSourcePool.valid())
279        _lightSourcePool = new LightSourcePool;
280    return _lightSourcePool.get();
281}
282
283
[5038]284inline LightPointAppearancePool* Document::getOrCreateLightPointAppearancePool()
285{
286    if (!_lightPointAppearancePool.valid())
287        _lightPointAppearancePool = new LightPointAppearancePool;
288    return _lightPointAppearancePool.get();
289}
290
[6759]291inline LightPointAnimationPool* Document::getOrCreateLightPointAnimationPool()
292{
293    if (!_lightPointAnimationPool.valid())
294        _lightPointAnimationPool = new LightPointAnimationPool;
295    return _lightPointAnimationPool.get();
296}
[5038]297
[6759]298
[5038]299inline ShaderPool* Document::getOrCreateShaderPool()
300{
301    if (!_shaderPool.valid())
302        _shaderPool = new ShaderPool;
303    return _shaderPool.get();
304}
305
306
307inline PrimaryRecord* Document::getTopOfLevelStack()
308{
309    // Anything on the level stack?
310    if (_levelStack.empty())
311        return NULL;
312
313    return _levelStack.back().get();
314}
315
316
317} // end namespace
318
319#endif
Note: See TracBrowser for help on using the browser.