root/OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/TexturePaletteManager.cpp @ 13041

Revision 13041, 2.5 kB (checked in by robert, 2 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#include "TexturePaletteManager.h"
18#include "FltExportVisitor.h"
19#include "ExportOptions.h"
20#include "DataOutputStream.h"
21#include "Opcodes.h"
22#include <osg/Notify>
23#include <osg/Texture2D>
24#include <osgDB/FileNameUtils>
25#include <map>
26
27
28namespace flt
29{
30
31
32TexturePaletteManager::TexturePaletteManager( const FltExportVisitor& nv, const ExportOptions& fltOpt )
33  : _currIndex( 0 ),
34    _nv( nv ),
35    _fltOpt( fltOpt )
36{
37}
38
39int
40TexturePaletteManager::add( int unit, const osg::Texture2D* texture )
41{
42    if( (!texture) ||
43        (!texture->getImage()) )
44        return -1;
45
46    int index( -1 );
47    TextureIndexMap::const_iterator it = _indexMap.find( texture );
48    if (it != _indexMap.end())
49        index = it->second;
50    else
51    {
52        index = _currIndex++;
53        _indexMap[ texture ] = index;
54
55        // If there is no .attr file, write one
56        _nv.writeATTRFile( unit, texture );
57    }
58
59    return index;
60}
61
62void
63TexturePaletteManager::write( DataOutputStream& dos ) const
64{
65    int x( 0 ), y( 0 ), height( 0 );
66    TextureIndexMap::const_iterator it = _indexMap.begin();
67    while (it != _indexMap.end())
68    {
69        const osg::Texture2D* texture = it->first;
70        int index = it->second;
71
72        std::string fileName;
73        if ( _fltOpt.getStripTextureFilePath() )
74            fileName = osgDB::getSimpleFileName( texture->getImage()->getFileName() );
75        else
76            fileName = texture->getImage()->getFileName();
77
78        dos.writeInt16( (int16) TEXTURE_PALETTE_OP );
79        dos.writeUInt16( 216 );
80        dos.writeString( fileName, 200 );
81        dos.writeInt32( index );
82        dos.writeInt32( x );
83        dos.writeInt32( y );
84        it++;
85
86        x += texture->getImage()->s();
87        if (texture->getImage()->t() > height)
88            height = texture->getImage()->t();
89        if (x > 1024)
90        {
91            x = 0;
92            y += height;
93            height = 0;
94        }
95    }
96}
97
98
99}
Note: See TracBrowser for help on using the browser.