#include <osgDB/SharedStateManager>
#include <osgUtil/Optimizer>
+#include <simgear/scene/util/SGSceneFeatures.hxx>
#include <simgear/scene/util/SGStateAttributeVisitor.hxx>
#include <simgear/scene/util/SGTextureStateAttributeVisitor.hxx>
class SGTexCompressionVisitor : public SGTextureStateAttributeVisitor {
public:
- SGTexCompressionVisitor(osg::Texture::InternalFormatMode formatMode) :
- mFormatMode(formatMode)
- { }
-
virtual void apply(int, osg::StateSet::RefAttributePair& refAttr)
{
osg::Texture2D* texture;
int s = image->s();
int t = image->t();
+
if (s <= t && 32 <= s) {
- texture->setInternalFormatMode(mFormatMode);
+ SGSceneFeatures::instance()->setTextureCompression(texture);
} else if (t < s && 32 <= t) {
- texture->setInternalFormatMode(mFormatMode);
+ SGSceneFeatures::instance()->setTextureCompression(texture);
}
}
+};
-private:
- osg::Texture::InternalFormatMode mFormatMode;
+class SGTexDataVarianceVisitor : public SGTextureStateAttributeVisitor {
+public:
+ virtual void apply(int, osg::StateSet::RefAttributePair& refAttr)
+ {
+ osg::Texture* texture;
+ texture = dynamic_cast<osg::Texture*>(refAttr.first.get());
+ if (!texture)
+ return;
+
+ texture->setDataVariance(osg::Object::STATIC);
+ }
};
class SGAcMaterialCrippleVisitor : public SGStateAttributeVisitor {
if (needTristrip)
opts |= osgUtil::Optimizer::TRISTRIP_GEOMETRY;
// opts |= osgUtil::Optimizer::TESSELATE_GEOMETRY;
- opts |= osgUtil::Optimizer::OPTIMIZE_TEXTURE_SETTINGS;
+ // opts |= osgUtil::Optimizer::OPTIMIZE_TEXTURE_SETTINGS;
optimizer.optimize(res.getNode(), opts);
- // OSGFIXME
+ // Make sure the data variance of sharable objects is set to STATIC ...
+ SGTexDataVarianceVisitor dataVarianceVisitor;
+ res.getNode()->accept(dataVarianceVisitor);
+ // ... so that textures are now globally shared
registry->getSharedStateManager()->share(res.getNode());
- // OSGFIXME: guard that with a flag
- // OSGFIXME: in the long term it is unclear if we have an OpenGL
- // context here...
- osg::Texture::Extensions* e = osg::Texture::getExtensions(0, true);
- if (e->isTextureCompressionARBSupported()) {
- SGTexCompressionVisitor texComp(osg::Texture::USE_ARB_COMPRESSION);
- res.getNode()->accept(texComp);
- } else if (e->isTextureCompressionS3TCSupported()) {
- SGTexCompressionVisitor texComp(osg::Texture::USE_S3TC_DXT5_COMPRESSION);
- res.getNode()->accept(texComp);
- }
+ SGTexCompressionVisitor texComp;
+ res.getNode()->accept(texComp);
}
// Add an extra reference to the model stored in the database.
res = osgDB::ReaderWriter::ReadResult(osg::CopyOp(flags)(res.getNode()));
res.getNode()->addObserver(databaseReference);
+ // Update liveries
SGTextureUpdateVisitor liveryUpdate(osgDB::getDataFilePathList());
res.getNode()->accept(liveryUpdate);
- // OSGFIXME: don't forget that mutex here
+ // Make sure the data variance of sharable objects is set to STATIC ...
+ SGTexDataVarianceVisitor dataVarianceVisitor;
+ res.getNode()->accept(dataVarianceVisitor);
+ // ... so that textures are now globally shared
registry->getOrCreateSharedStateManager()->share(res.getNode(), 0);
return res;
int s = image->s();
int t = image->t();
- // OSGFIXME: guard with a flag
- if (osg::Texture::getExtensions(0, true)->isTextureCompressionARBSupported()) {
- if (s <= t && 32 <= s) {
- texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION);
- } else if (t < s && 32 <= t) {
- texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION);
- }
- } else if (osg::Texture::getExtensions(0, true)->isTextureCompressionS3TCSupported()) {
- if (s <= t && 32 <= s) {
- texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT5_COMPRESSION);
- } else if (t < s && 32 <= t) {
- texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT5_COMPRESSION);
- }
+ if (s <= t && 32 <= s) {
+ SGSceneFeatures::instance()->setTextureCompression(texture.get());
+ } else if (t < s && 32 <= t) {
+ SGSceneFeatures::instance()->setTextureCompression(texture.get());
}
}
#include <osg/VertexProgram>
#include <osg/Point>
#include <osg/PointSprite>
+#include <osg/Texture>
#include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/threads/SGThread.hxx>
#include <simgear/threads/SGGuard.hxx>
SGSceneFeatures::SGSceneFeatures() :
+ _textureCompression(UseARBCompression),
_shaderLights(true),
_pointSpriteLights(true),
_distanceAttenuationLights(true)
return sceneFeatures;
}
+void
+SGSceneFeatures::setTextureCompression(osg::Texture* texture) const
+{
+ switch (_textureCompression) {
+ case UseARBCompression:
+ texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION);
+ break;
+ case UseDXT1Compression:
+ texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT1_COMPRESSION);
+ break;
+ case UseDXT3Compression:
+ texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT3_COMPRESSION);
+ break;
+ case UseDXT5Compression:
+ texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT5_COMPRESSION);
+ break;
+ default:
+ texture->setInternalFormatMode(osg::Texture::USE_IMAGE_DATA_FORMAT);
+ break;
+ }
+}
+
bool
SGSceneFeatures::getHavePointSprites(unsigned contextId) const
{
#include <simgear/structure/SGReferenced.hxx>
+namespace osg { class Texture; }
+
class SGSceneFeatures : public SGReferenced {
public:
static SGSceneFeatures* instance();
+ enum TextureCompression {
+ DoNotUseCompression,
+ UseARBCompression,
+ UseDXT1Compression,
+ UseDXT3Compression,
+ UseDXT5Compression
+ };
+
+ void setTextureCompression(TextureCompression textureCompression)
+ { _textureCompression = textureCompression; }
+ TextureCompression getTextureCompression() const
+ { return _textureCompression; }
+ void setTextureCompression(osg::Texture* texture) const;
+
void setEnablePointSpriteLights(bool enable)
{ _pointSpriteLights = enable; }
bool getEnablePointSpriteLights(unsigned contextId) const
SGSceneFeatures(const SGSceneFeatures&);
SGSceneFeatures& operator=(const SGSceneFeatures&);
+ TextureCompression _textureCompression;
bool _shaderLights;
bool _pointSpriteLights;
bool _distanceAttenuationLights;