~ubuntu-branches/ubuntu/trusty/openscenegraph/trusty

« back to all changes in this revision

Viewing changes to OpenSceneGraph/src/osgPlugins/OpenFlight/MaterialPaletteManager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-07-29 04:34:38 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20080729043438-no1h9h0dpsrlzp1y
* Non-maintainer upload.
* No longer try to detect (using /proc/cpuinfo when available) how many
  CPUs are available, fixing the FTBFS (due to -j0) on various platforms
  (Closes: #477353). The right way to do it is to support parallel=n in
  DEB_BUILD_OPTIONS (see Debian Policy §4.9.1), and adequate support has
  been implemented.
* Add patch to fix FTBFS due to the build system now refusing to handle
  whitespaces (Policy CMP0004 say the logs), thanks to Andreas Putzo who
  provided it (Closes: #482239):
   - debian/patches/fix-cmp0004-build-failure.dpatch
* Remove myself from Uploaders, as requested a while ago, done by Luk in
  his 2.2.0-2.1 NMU, which was never acknowledged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "MaterialPaletteManager.h"
 
18
#include "DataOutputStream.h"
 
19
#include "Opcodes.h"
 
20
#include <osg/Notify>
 
21
#include <osg/Material>
 
22
#include <osg/Vec4f>
 
23
#include <cassert>
 
24
#include <sstream>
 
25
 
 
26
namespace flt
 
27
{
 
28
 
 
29
 
 
30
MaterialPaletteManager::MaterialPaletteManager( ExportOptions& fltOpt )
 
31
  : _fltOpt( fltOpt ),
 
32
    _currIndex( -1 )
 
33
{
 
34
    // TODO: Pay attention to the version here(?)
 
35
}
 
36
 
 
37
 
 
38
int MaterialPaletteManager::add(osg::Material const* material)
 
39
{
 
40
    int index = -1;
 
41
    if (material == NULL) return -1;
 
42
 
 
43
 
 
44
    // If this material has already been cached, set 'index' to the cached value
 
45
    MaterialPalette::const_iterator it = _materialPalette.find(material);
 
46
    if ( it != _materialPalette.end() )
 
47
    {
 
48
        index = it->second.Index;
 
49
    }
 
50
 
 
51
    // New material? Add it to the cache...
 
52
    else
 
53
    {
 
54
        index = ++_currIndex;
 
55
        _materialPalette.insert(std::make_pair(material,
 
56
                                               MaterialRecord(material, index) ) );
 
57
    }
 
58
 
 
59
    return index;
 
60
}
 
61
 
 
62
void
 
63
MaterialPaletteManager::write( DataOutputStream& dos ) const
 
64
{
 
65
    using osg::Vec4f;
 
66
 
 
67
    MaterialPalette::const_iterator it = _materialPalette.begin();
 
68
    for ( ; it != _materialPalette.end(); ++it)
 
69
    {
 
70
        MaterialRecord m = it->second;
 
71
        Vec4f const& ambient = m.Material->getAmbient(osg::Material::FRONT);
 
72
        Vec4f const& diffuse = m.Material->getDiffuse(osg::Material::FRONT);
 
73
        Vec4f const& specular = m.Material->getSpecular(osg::Material::FRONT);
 
74
        Vec4f const& emissive = m.Material->getEmission(osg::Material::FRONT);
 
75
        float shininess = m.Material->getShininess(osg::Material::FRONT);
 
76
 
 
77
        dos.writeInt16( (int16) MATERIAL_PALETTE_OP );
 
78
        dos.writeInt16( 84 );            // Length - FIXME: hard-code/FLT version?
 
79
        dos.writeInt32( m.Index );
 
80
        dos.writeString( std::string( "" ), 12 ); // Name - FIXME: put a 'real' name here?
 
81
        dos.writeInt32( 0 );             // Flags
 
82
        dos.writeFloat32(ambient.r() );
 
83
        dos.writeFloat32(ambient.g() );
 
84
        dos.writeFloat32(ambient.b() );
 
85
        dos.writeFloat32(diffuse.r() );
 
86
        dos.writeFloat32(diffuse.g() );
 
87
        dos.writeFloat32(diffuse.b() );
 
88
        dos.writeFloat32(specular.r() );
 
89
        dos.writeFloat32(specular.g() );
 
90
        dos.writeFloat32(specular.b() );
 
91
        dos.writeFloat32(emissive.r() );
 
92
        dos.writeFloat32(emissive.g() );
 
93
        dos.writeFloat32(emissive.b() );
 
94
        dos.writeFloat32(shininess);
 
95
        dos.writeFloat32( diffuse.a() ); // alpha
 
96
        dos.writeFloat32(1.0f);       // 'Reserved' - unused
 
97
 
 
98
        if (m.Material->getAmbientFrontAndBack()   == false   ||
 
99
            m.Material->getDiffuseFrontAndBack()   == false   ||
 
100
            m.Material->getSpecularFrontAndBack()  == false   ||
 
101
            m.Material->getEmissionFrontAndBack()  == false   ||
 
102
            m.Material->getShininessFrontAndBack() == false )
 
103
 
 
104
        {
 
105
            std::string warning( "fltexp: No support for different front and back material properties." );
 
106
            osg::notify( osg::WARN ) << warning << std::endl;
 
107
           _fltOpt.getWriteResult().warn( warning );
 
108
        }
 
109
 
 
110
    }
 
111
}
 
112
 
 
113
 
 
114
 
 
115
}  // End namespace fltexp