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