]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/model.cxx
More include SGMath.hxx to keep MSVC happy
[simgear.git] / simgear / scene / model / model.cxx
1 // model.cxx - manage a 3D aircraft model.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain, and comes with no warranty.
5
6 #ifdef HAVE_CONFIG_H
7 #include <simgear_config.h>
8 #endif
9
10 #include <osg/ref_ptr>
11 #include <osgDB/ReadFile>
12 #include <osgDB/SharedStateManager>
13
14 #include <simgear/math/SGMath.hxx>
15 #include <simgear/scene/util/SGSceneFeatures.hxx>
16
17 #include <simgear/structure/exception.hxx>
18 #include <simgear/props/props.hxx>
19 #include <simgear/props/props_io.hxx>
20 #include <simgear/props/condition.hxx>
21
22 #include "model.hxx"
23
24 using std::vector;
25
26 osg::Texture2D*
27 SGLoadTexture2D(bool staticTexture, const std::string& path,
28                 const osgDB::ReaderWriter::Options* options,
29                 bool wrapu, bool wrapv, int)
30 {
31   osg::Image* image;
32   if (options)
33     image = osgDB::readImageFile(path, options);
34   else
35     image = osgDB::readImageFile(path);
36   osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
37   texture->setImage(image);
38   if (staticTexture)
39     texture->setDataVariance(osg::Object::STATIC);
40   if (wrapu)
41     texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
42   else
43     texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP);
44   if (wrapv)
45     texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
46   else
47     texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP);
48
49   if (image) {
50     int s = image->s();
51     int t = image->t();
52
53     if (s <= t && 32 <= s) {
54       SGSceneFeatures::instance()->setTextureCompression(texture.get());
55     } else if (t < s && 32 <= t) {
56       SGSceneFeatures::instance()->setTextureCompression(texture.get());
57     }
58   }
59
60   return texture.release();
61 }
62
63 // end of model.cxx