]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/SGSceneFeatures.cxx
Off-by-one error in the OSG_VERSION_LESS_THAN macro
[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/Version>
29 #include <osg/FragmentProgram>
30 #include <osg/VertexProgram>
31 #include <osg/Point>
32 #include <osg/PointSprite>
33 #include <osg/Texture>
34 #include <osg/GLExtensions>
35
36 #include <OpenThreads/Mutex>
37 #include <OpenThreads/ScopedLock>
38
39 #include <simgear/structure/SGSharedPtr.hxx>
40
41 SGSceneFeatures::SGSceneFeatures() :
42   _textureCompression(UseARBCompression),
43   _shaderLights(true),
44   _pointSpriteLights(true),
45   _distanceAttenuationLights(true),
46   _textureFilter(1)
47 {
48 }
49
50 static OpenThreads::Mutex mutexSGSceneFeatures_instance;
51 SGSceneFeatures*
52 SGSceneFeatures::instance()
53 {
54   static SGSharedPtr<SGSceneFeatures> sceneFeatures;
55   if (sceneFeatures)
56     return sceneFeatures;
57   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutexSGSceneFeatures_instance);
58   if (sceneFeatures)
59     return sceneFeatures;
60   sceneFeatures = new SGSceneFeatures;
61   return sceneFeatures;
62 }
63
64 void
65 SGSceneFeatures::setTextureCompression(osg::Texture* texture) const
66 {
67   switch (_textureCompression) {
68   case UseARBCompression:
69     texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION);
70     break;
71   case UseDXT1Compression:
72     texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT1_COMPRESSION);
73     break;
74   case UseDXT3Compression:
75     texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT3_COMPRESSION);
76     break;
77   case UseDXT5Compression:
78     texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT5_COMPRESSION);
79     break;
80   default:
81     texture->setInternalFormatMode(osg::Texture::USE_IMAGE_DATA_FORMAT);
82     break;
83   }
84 }
85
86 bool
87 SGSceneFeatures::getHavePointSprites(unsigned contextId) const
88 {
89 #if OSG_VERSION_LESS_THAN(3,3,4)
90   return osg::PointSprite::isPointSpriteSupported(contextId);
91 #else
92   const osg::GLExtensions* ex = osg::GLExtensions::Get(contextId, true);
93   return ex && ex->isPointSpriteSupported;
94 #endif
95 }
96
97 bool
98 SGSceneFeatures::getHaveFragmentPrograms(unsigned contextId) const
99 {
100 #if OSG_VERSION_LESS_THAN(3,3,4)
101   const osg::FragmentProgram::Extensions* fpe;
102   fpe = osg::FragmentProgram::getExtensions(contextId, true);
103   if (!fpe)
104     return false;
105   if (!fpe->isFragmentProgramSupported())
106     return false;
107   
108   return true;
109 #else
110   const osg::GLExtensions* ex = osg::GLExtensions::Get(contextId, true);
111   return ex && ex->isFragmentProgramSupported;
112 #endif
113 }
114
115 bool
116 SGSceneFeatures::getHaveVertexPrograms(unsigned contextId) const
117 {
118 #if OSG_VERSION_LESS_THAN(3,3,4)
119   const osg::VertexProgram::Extensions* vpe;
120   vpe = osg::VertexProgram::getExtensions(contextId, true);
121   if (!vpe)
122     return false;
123   if (!vpe->isVertexProgramSupported())
124     return false;
125   
126   return true;
127 #else
128   const osg::GLExtensions* ex = osg::GLExtensions::Get(contextId, true);
129   return ex && ex->isVertexProgramSupported;
130 #endif
131 }
132
133 bool
134 SGSceneFeatures::getHaveShaderPrograms(unsigned contextId) const
135 {
136   if (!getHaveFragmentPrograms(contextId))
137     return false;
138   return getHaveVertexPrograms(contextId);
139 }
140
141 bool
142 SGSceneFeatures::getHavePointParameters(unsigned contextId) const
143 {
144 #if OSG_VERSION_LESS_THAN(3,3,4)
145   const osg::Point::Extensions* pe;
146   pe = osg::Point::getExtensions(contextId, true);
147   if (!pe)
148     return false;
149   if (!pe->isPointParametersSupported())
150     return false;
151   return true;
152 #else
153   const osg::GLExtensions* ex = osg::GLExtensions::Get(contextId, true);
154   return ex && ex->isPointParametersSupported;
155 #endif
156 }
157