]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/SGSceneFeatures.cxx
Modified Files:
[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 <simgear/structure/SGSharedPtr.hxx>
35 #include <simgear/threads/SGThread.hxx>
36 #include <simgear/threads/SGGuard.hxx>
37
38 SGSceneFeatures::SGSceneFeatures() :
39   _textureCompression(UseARBCompression),
40   _shaderLights(true),
41   _pointSpriteLights(true),
42   _distanceAttenuationLights(true)
43 {
44 }
45
46 SGSceneFeatures*
47 SGSceneFeatures::instance()
48 {
49   static SGSharedPtr<SGSceneFeatures> sceneFeatures;
50   if (sceneFeatures)
51     return sceneFeatures;
52   static SGMutex mutex;
53   SGGuard<SGMutex> guard(mutex);
54   if (sceneFeatures)
55     return sceneFeatures;
56   sceneFeatures = new SGSceneFeatures;
57   return sceneFeatures;
58 }
59
60 void
61 SGSceneFeatures::setTextureCompression(osg::Texture* texture) const
62 {
63   switch (_textureCompression) {
64   case UseARBCompression:
65     texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION);
66     break;
67   case UseDXT1Compression:
68     texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT1_COMPRESSION);
69     break;
70   case UseDXT3Compression:
71     texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT3_COMPRESSION);
72     break;
73   case UseDXT5Compression:
74     texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT5_COMPRESSION);
75     break;
76   default:
77     texture->setInternalFormatMode(osg::Texture::USE_IMAGE_DATA_FORMAT);
78     break;
79   }
80 }
81
82 bool
83 SGSceneFeatures::getHavePointSprites(unsigned contextId) const
84 {
85   return osg::PointSprite::isPointSpriteSupported(contextId);
86 }
87
88 bool
89 SGSceneFeatures::getHaveFragmentPrograms(unsigned contextId) const
90 {
91   const osg::FragmentProgram::Extensions* fpe;
92   fpe = osg::FragmentProgram::getExtensions(contextId, true);
93   if (!fpe)
94     return false;
95   if (!fpe->isFragmentProgramSupported())
96     return false;
97   
98   return true;
99 }
100
101 bool
102 SGSceneFeatures::getHaveVertexPrograms(unsigned contextId) const
103 {
104   const osg::VertexProgram::Extensions* vpe;
105   vpe = osg::VertexProgram::getExtensions(contextId, true);
106   if (!vpe)
107     return false;
108   if (!vpe->isVertexProgramSupported())
109     return false;
110   
111   return true;
112 }
113
114 bool
115 SGSceneFeatures::getHaveShaderPrograms(unsigned contextId) const
116 {
117   if (!getHaveFragmentPrograms(contextId))
118     return false;
119   return getHaveVertexPrograms(contextId);
120 }
121
122 bool
123 SGSceneFeatures::getHavePointParameters(unsigned contextId) const
124 {
125   const osg::Point::Extensions* pe;
126   pe = osg::Point::getExtensions(contextId, true);
127   if (!pe)
128     return false;
129   if (!pe->isPointParametersSupported())
130     return false;
131   return true;
132 }
133