]> 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
33 #include <simgear/structure/SGSharedPtr.hxx>
34 #include <simgear/threads/SGThread.hxx>
35 #include <simgear/threads/SGGuard.hxx>
36
37 SGSceneFeatures::SGSceneFeatures() :
38   _shaderLights(true),
39   _pointSpriteLights(true),
40   _distanceAttenuationLights(true)
41 {
42 }
43
44 SGSceneFeatures*
45 SGSceneFeatures::instance()
46 {
47   static SGSharedPtr<SGSceneFeatures> sceneFeatures;
48   if (sceneFeatures)
49     return sceneFeatures;
50   static SGMutex mutex;
51   SGGuard<SGMutex> guard(mutex);
52   if (sceneFeatures)
53     return sceneFeatures;
54   sceneFeatures = new SGSceneFeatures;
55   return sceneFeatures;
56 }
57
58 bool
59 SGSceneFeatures::getHavePointSprites(unsigned contextId) const
60 {
61   return osg::PointSprite::isPointSpriteSupported(contextId);
62 }
63
64 bool
65 SGSceneFeatures::getHaveFragmentPrograms(unsigned contextId) const
66 {
67   const osg::FragmentProgram::Extensions* fpe;
68   fpe = osg::FragmentProgram::getExtensions(contextId, true);
69   if (!fpe)
70     return false;
71   if (!fpe->isFragmentProgramSupported())
72     return false;
73   
74   return true;
75 }
76
77 bool
78 SGSceneFeatures::getHaveVertexPrograms(unsigned contextId) const
79 {
80   const osg::VertexProgram::Extensions* vpe;
81   vpe = osg::VertexProgram::getExtensions(contextId, true);
82   if (!vpe)
83     return false;
84   if (!vpe->isVertexProgramSupported())
85     return false;
86   
87   return true;
88 }
89
90 bool
91 SGSceneFeatures::getHaveShaderPrograms(unsigned contextId) const
92 {
93   if (!getHaveFragmentPrograms(contextId))
94     return false;
95   return getHaveVertexPrograms(contextId);
96 }
97
98 bool
99 SGSceneFeatures::getHavePointParameters(unsigned contextId) const
100 {
101   const osg::Point::Extensions* pe;
102   pe = osg::Point::getExtensions(contextId, true);
103   if (!pe)
104     return false;
105   if (!pe->isPointParametersSupported())
106     return false;
107   return true;
108 }
109