3 * Copyright (C) 2006-2007 Mathias Froehlich
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.
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.
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,
23 # include <simgear_config.h>
26 #include "SGSceneFeatures.hxx"
28 #include <osg/Version>
29 #include <osg/FragmentProgram>
30 #include <osg/VertexProgram>
32 #include <osg/PointSprite>
33 #include <osg/Texture>
34 #include <osg/GLExtensions>
36 #include <OpenThreads/Mutex>
37 #include <OpenThreads/ScopedLock>
39 #include <simgear/structure/SGSharedPtr.hxx>
41 SGSceneFeatures::SGSceneFeatures() :
42 _textureCompression(UseARBCompression),
44 _pointSpriteLights(true),
45 _distanceAttenuationLights(true),
50 static OpenThreads::Mutex mutexSGSceneFeatures_instance;
52 SGSceneFeatures::instance()
54 static SGSharedPtr<SGSceneFeatures> sceneFeatures;
57 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutexSGSceneFeatures_instance);
60 sceneFeatures = new SGSceneFeatures;
65 SGSceneFeatures::setTextureCompression(osg::Texture* texture) const
67 switch (_textureCompression) {
68 case UseARBCompression:
69 texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION);
71 case UseDXT1Compression:
72 texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT1_COMPRESSION);
74 case UseDXT3Compression:
75 texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT3_COMPRESSION);
77 case UseDXT5Compression:
78 texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT5_COMPRESSION);
81 texture->setInternalFormatMode(osg::Texture::USE_IMAGE_DATA_FORMAT);
87 SGSceneFeatures::getHavePointSprites(unsigned contextId) const
89 #if OSG_VERSION_LESS_THAN(3,3,4)
90 return osg::PointSprite::isPointSpriteSupported(contextId);
92 const osg::GLExtensions* ex = osg::GLExtensions::Get(contextId, true);
93 return ex && ex->isPointSpriteSupported;
98 SGSceneFeatures::getHaveFragmentPrograms(unsigned contextId) const
100 #if OSG_VERSION_LESS_THAN(3,3,4)
101 const osg::FragmentProgram::Extensions* fpe;
102 fpe = osg::FragmentProgram::getExtensions(contextId, true);
105 if (!fpe->isFragmentProgramSupported())
110 const osg::GLExtensions* ex = osg::GLExtensions::Get(contextId, true);
111 return ex && ex->isFragmentProgramSupported;
116 SGSceneFeatures::getHaveVertexPrograms(unsigned contextId) const
118 #if OSG_VERSION_LESS_THAN(3,3,4)
119 const osg::VertexProgram::Extensions* vpe;
120 vpe = osg::VertexProgram::getExtensions(contextId, true);
123 if (!vpe->isVertexProgramSupported())
128 const osg::GLExtensions* ex = osg::GLExtensions::Get(contextId, true);
129 return ex && ex->isVertexProgramSupported;
134 SGSceneFeatures::getHaveShaderPrograms(unsigned contextId) const
136 if (!getHaveFragmentPrograms(contextId))
138 return getHaveVertexPrograms(contextId);
142 SGSceneFeatures::getHavePointParameters(unsigned contextId) const
144 #if OSG_VERSION_LESS_THAN(3,3,4)
145 const osg::Point::Extensions* pe;
146 pe = osg::Point::getExtensions(contextId, true);
149 if (!pe->isPointParametersSupported())
153 const osg::GLExtensions* ex = osg::GLExtensions::Get(contextId, true);
154 return ex && ex->isPointParametersSupported;