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/FragmentProgram>
29 #include <osg/VertexProgram>
31 #include <osg/PointSprite>
32 #include <osg/Texture>
34 #include <OpenThreads/Mutex>
35 #include <OpenThreads/ScopedLock>
37 #include <simgear/structure/SGSharedPtr.hxx>
39 SGSceneFeatures::SGSceneFeatures() :
40 _textureCompression(UseARBCompression),
42 _pointSpriteLights(true),
43 _distanceAttenuationLights(true),
48 static OpenThreads::Mutex mutexSGSceneFeatures_instance;
50 SGSceneFeatures::instance()
52 static SGSharedPtr<SGSceneFeatures> sceneFeatures;
55 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutexSGSceneFeatures_instance);
58 sceneFeatures = new SGSceneFeatures;
63 SGSceneFeatures::setTextureCompression(osg::Texture* texture) const
65 switch (_textureCompression) {
66 case UseARBCompression:
67 texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION);
69 case UseDXT1Compression:
70 texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT1_COMPRESSION);
72 case UseDXT3Compression:
73 texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT3_COMPRESSION);
75 case UseDXT5Compression:
76 texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT5_COMPRESSION);
79 texture->setInternalFormatMode(osg::Texture::USE_IMAGE_DATA_FORMAT);
85 SGSceneFeatures::getHavePointSprites(unsigned contextId) const
87 return osg::PointSprite::isPointSpriteSupported(contextId);
91 SGSceneFeatures::getHaveFragmentPrograms(unsigned contextId) const
93 const osg::FragmentProgram::Extensions* fpe;
94 fpe = osg::FragmentProgram::getExtensions(contextId, true);
97 if (!fpe->isFragmentProgramSupported())
104 SGSceneFeatures::getHaveVertexPrograms(unsigned contextId) const
106 const osg::VertexProgram::Extensions* vpe;
107 vpe = osg::VertexProgram::getExtensions(contextId, true);
110 if (!vpe->isVertexProgramSupported())
117 SGSceneFeatures::getHaveShaderPrograms(unsigned contextId) const
119 if (!getHaveFragmentPrograms(contextId))
121 return getHaveVertexPrograms(contextId);
125 SGSceneFeatures::getHavePointParameters(unsigned contextId) const
127 const osg::Point::Extensions* pe;
128 pe = osg::Point::getExtensions(contextId, true);
131 if (!pe->isPointParametersSupported())