root/OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/VertexPaletteManager.h @ 13041

Revision 13041, 3.2 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1/*
2 * This library is open source and may be redistributed and/or modified under
3 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or (at
4 * your option) any later version. The full license is in the LICENSE file
5 * included with this distribution, and on the openscenegraph.org website.
6 *
7 * This library is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * OpenSceneGraph Public License for more details.
11*/
12
13//
14// Copyright(c) 2008 Skew Matrix Software LLC.
15//
16
17#ifndef __FLTEXP_VERTEX_PALETTE_MANAGER_H__
18#define __FLTEXP_VERTEX_PALETTE_MANAGER_H__ 1
19
20
21#include "DataOutputStream.h"
22#include "ExportOptions.h"
23#include <osg/Array>
24#include <osgDB/fstream>
25#include <map>
26
27namespace osg {
28    class Geometry;
29}
30
31
32namespace flt
33{
34
35
36/*!
37   Manages writing the Vertex Palette record during export.
38   Maintains a map to ensure that instanced VertexArray data is only
39   written once to the palette. Writes the palette record to a temp
40   file and copies it to FltExportVisitor::_dos after the scene graph
41   has been completely walked.
42 */
43class VertexPaletteManager
44{
45public:
46    VertexPaletteManager( const ExportOptions& fltOpt );
47    ~VertexPaletteManager();
48
49    void add( const osg::Geometry& geom );
50    void add( const osg::Array* key,
51        const osg::Vec3dArray* v, const osg::Vec4Array* c,
52        const osg::Vec3Array* n, const osg::Vec2Array* t,
53        bool colorPerVertex, bool normalPerVertex, bool allowSharing=true );
54
55    unsigned int byteOffset( unsigned int idx ) const;
56
57    void write( DataOutputStream& dos ) const;
58
59    /*!
60       Static utility routines for handling the morass of array
61       types that could be found in a Geometry object's vertex/
62       normal/texcoord/color data. */
63    static osg::ref_ptr< const osg::Vec2Array > asVec2Array( const osg::Array* in, const unsigned int n );
64    static osg::ref_ptr< const osg::Vec3Array > asVec3Array( const osg::Array* in, const unsigned int n );
65    static osg::ref_ptr< const osg::Vec3dArray > asVec3dArray( const osg::Array* in, const unsigned int n );
66    static osg::ref_ptr< const osg::Vec4Array > asVec4Array( const osg::Array* in, const unsigned int n );
67
68protected:
69    typedef enum {
70        VERTEX_C,
71        VERTEX_CN,
72        VERTEX_CNT,
73        VERTEX_CT
74    } PaletteRecordType;
75
76    static PaletteRecordType recordType( const osg::Array* v, const osg::Array* c,
77        const osg::Array* n, const osg::Array* t );
78    unsigned int recordSize( PaletteRecordType recType );
79
80    void writeRecords( const osg::Vec3dArray* v, const osg::Vec4Array* c,
81        const osg::Vec3Array* n, const osg::Vec2Array* t,
82        bool colorPerVertex, bool normalPerVertex );
83
84    unsigned int _currentSizeBytes;
85
86    struct ArrayInfo {
87        ArrayInfo();
88
89        unsigned int _byteStart;
90        unsigned int _idxSizeBytes;
91        unsigned int _idxCount;
92    };
93    ArrayInfo* _current;
94    ArrayInfo _nonShared;
95
96    typedef std::map< const osg::Array*, ArrayInfo > ArrayMap;
97    ArrayMap _arrayMap;
98
99    mutable osgDB::ofstream _verticesStr;
100    DataOutputStream* _vertices;
101    std::string _verticesTempName;
102
103    const ExportOptions& _fltOpt;
104};
105
106
107}
108
109#endif
Note: See TracBrowser for help on using the browser.