00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifdef HAVE_CONFIG_H
00023 # include <simgear_config.h>
00024 #endif
00025
00026 #include "SGSceneFeatures.hxx"
00027
00028 #include <osg/FragmentProgram>
00029 #include <osg/VertexProgram>
00030 #include <osg/Point>
00031 #include <osg/PointSprite>
00032 #include <osg/Texture>
00033
00034 #include <OpenThreads/Mutex>
00035 #include <OpenThreads/ScopedLock>
00036
00037 #include <simgear/structure/SGSharedPtr.hxx>
00038
00039 SGSceneFeatures::SGSceneFeatures() :
00040 _textureCompression(UseARBCompression),
00041 _shaderLights(true),
00042 _pointSpriteLights(true),
00043 _distanceAttenuationLights(true),
00044 _textureFilter(1)
00045 {
00046 }
00047
00048 static OpenThreads::Mutex mutexSGSceneFeatures_instance;
00049 SGSceneFeatures*
00050 SGSceneFeatures::instance()
00051 {
00052 static SGSharedPtr<SGSceneFeatures> sceneFeatures;
00053 if (sceneFeatures)
00054 return sceneFeatures;
00055 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutexSGSceneFeatures_instance);
00056 if (sceneFeatures)
00057 return sceneFeatures;
00058 sceneFeatures = new SGSceneFeatures;
00059 return sceneFeatures;
00060 }
00061
00062 void
00063 SGSceneFeatures::setTextureCompression(osg::Texture* texture) const
00064 {
00065 switch (_textureCompression) {
00066 case UseARBCompression:
00067 texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION);
00068 break;
00069 case UseDXT1Compression:
00070 texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT1_COMPRESSION);
00071 break;
00072 case UseDXT3Compression:
00073 texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT3_COMPRESSION);
00074 break;
00075 case UseDXT5Compression:
00076 texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT5_COMPRESSION);
00077 break;
00078 default:
00079 texture->setInternalFormatMode(osg::Texture::USE_IMAGE_DATA_FORMAT);
00080 break;
00081 }
00082 }
00083
00084 bool
00085 SGSceneFeatures::getHavePointSprites(unsigned contextId) const
00086 {
00087 return osg::PointSprite::isPointSpriteSupported(contextId);
00088 }
00089
00090 bool
00091 SGSceneFeatures::getHaveFragmentPrograms(unsigned contextId) const
00092 {
00093 const osg::FragmentProgram::Extensions* fpe;
00094 fpe = osg::FragmentProgram::getExtensions(contextId, true);
00095 if (!fpe)
00096 return false;
00097 if (!fpe->isFragmentProgramSupported())
00098 return false;
00099
00100 return true;
00101 }
00102
00103 bool
00104 SGSceneFeatures::getHaveVertexPrograms(unsigned contextId) const
00105 {
00106 const osg::VertexProgram::Extensions* vpe;
00107 vpe = osg::VertexProgram::getExtensions(contextId, true);
00108 if (!vpe)
00109 return false;
00110 if (!vpe->isVertexProgramSupported())
00111 return false;
00112
00113 return true;
00114 }
00115
00116 bool
00117 SGSceneFeatures::getHaveShaderPrograms(unsigned contextId) const
00118 {
00119 if (!getHaveFragmentPrograms(contextId))
00120 return false;
00121 return getHaveVertexPrograms(contextId);
00122 }
00123
00124 bool
00125 SGSceneFeatures::getHavePointParameters(unsigned contextId) const
00126 {
00127 const osg::Point::Extensions* pe;
00128 pe = osg::Point::getExtensions(contextId, true);
00129 if (!pe)
00130 return false;
00131 if (!pe->isPointParametersSupported())
00132 return false;
00133 return true;
00134 }
00135