]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/SGSceneFeatures.cxx
Work around apparent OSG 3.2.0 normal binding bug.
[simgear.git] / simgear / scene / util / SGSceneFeatures.cxx
1 /* -*-c++-*-
2  *
3  * Copyright (C) 2006-2007 Mathias Froehlich 
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  * MA 02110-1301, USA.
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #  include <simgear_config.h>
24 #endif
25
26 #include "SGSceneFeatures.hxx"
27
28 #include <osg/FragmentProgram>
29 #include <osg/VertexProgram>
30 #include <osg/Point>
31 #include <osg/PointSprite>
32 #include <osg/Texture>
33
34 #include <OpenThreads/Mutex>
35 #include <OpenThreads/ScopedLock>
36
37 #include <simgear/structure/SGSharedPtr.hxx>
38
39 SGSceneFeatures::SGSceneFeatures() :
40   _textureCompression(UseARBCompression),
41   _shaderLights(true),
42   _pointSpriteLights(true),
43   _distanceAttenuationLights(true),
44   _textureFilter(1)
45 {
46 }
47
48 static OpenThreads::Mutex mutexSGSceneFeatures_instance;
49 SGSceneFeatures*
50 SGSceneFeatures::instance()
51 {
52   static SGSharedPtr<SGSceneFeatures> sceneFeatures;
53   if (sceneFeatures)
54     return sceneFeatures;
55   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutexSGSceneFeatures_instance);
56   if (sceneFeatures)
57     return sceneFeatures;
58   sceneFeatures = new SGSceneFeatures;
59   return sceneFeatures;
60 }
61
62 void
63 SGSceneFeatures::setTextureCompression(osg::Texture* texture) const
64 {
65   switch (_textureCompression) {
66   case UseARBCompression:
67     texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION);
68     break;
69   case UseDXT1Compression:
70     texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT1_COMPRESSION);
71     break;
72   case UseDXT3Compression:
73     texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT3_COMPRESSION);
74     break;
75   case UseDXT5Compression:
76     texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT5_COMPRESSION);
77     break;
78   default:
79     texture->setInternalFormatMode(osg::Texture::USE_IMAGE_DATA_FORMAT);
80     break;
81   }
82 }
83
84 bool
85 SGSceneFeatures::getHavePointSprites(unsigned contextId) const
86 {
87   return osg::PointSprite::isPointSpriteSupported(contextId);
88 }
89
90 bool
91 SGSceneFeatures::getHaveFragmentPrograms(unsigned contextId) const
92 {
93   const osg::FragmentProgram::Extensions* fpe;
94   fpe = osg::FragmentProgram::getExtensions(contextId, true);
95   if (!fpe)
96     return false;
97   if (!fpe->isFragmentProgramSupported())
98     return false;
99   
100   return true;
101 }
102
103 bool
104 SGSceneFeatures::getHaveVertexPrograms(unsigned contextId) const
105 {
106   const osg::VertexProgram::Extensions* vpe;
107   vpe = osg::VertexProgram::getExtensions(contextId, true);
108   if (!vpe)
109     return false;
110   if (!vpe->isVertexProgramSupported())
111     return false;
112   
113   return true;
114 }
115
116 bool
117 SGSceneFeatures::getHaveShaderPrograms(unsigned contextId) const
118 {
119   if (!getHaveFragmentPrograms(contextId))
120     return false;
121   return getHaveVertexPrograms(contextId);
122 }
123
124 bool
125 SGSceneFeatures::getHavePointParameters(unsigned contextId) const
126 {
127   const osg::Point::Extensions* pe;
128   pe = osg::Point::getExtensions(contextId, true);
129   if (!pe)
130     return false;
131   if (!pe->isPointParametersSupported())
132     return false;
133   return true;
134 }
135