Support for DDS Texture Cache
- pass texture cache control properties to simgear - /sim/rendering/texture-cache/cache-enabled - /sim/rendering/texture-cache/compress-transparent - /sim/rendering/texture-cache/compress-solid - /sim/rendering/texture-cache/compress - support --texture-cache-dir command line option - set max reported supported texture size during splashscreen.
This commit is contained in:
parent
8742fee23d
commit
1e636ce4cf
7 changed files with 111 additions and 11 deletions
|
@ -279,6 +279,12 @@ void FGGlobals::set_fg_home (const SGPath &home)
|
|||
fg_home = home.realpath();
|
||||
}
|
||||
|
||||
void FGGlobals::set_texture_cache_dir(const SGPath &textureCache)
|
||||
{
|
||||
texture_cache_dir = textureCache.realpath();
|
||||
}
|
||||
|
||||
|
||||
PathList FGGlobals::get_data_paths() const
|
||||
{
|
||||
PathList r(additional_data_paths);
|
||||
|
|
|
@ -103,6 +103,8 @@ private:
|
|||
|
||||
// Users home directory for data
|
||||
SGPath fg_home;
|
||||
|
||||
SGPath texture_cache_dir;
|
||||
// Download directory
|
||||
SGPath download_dir;
|
||||
// Terrasync directory
|
||||
|
@ -199,7 +201,8 @@ public:
|
|||
inline void set_sim_time_sec (double t) { sim_time_sec = t; }
|
||||
|
||||
const SGPath &get_fg_root () const { return fg_root; }
|
||||
void set_fg_root (const SGPath&root);
|
||||
void set_fg_root(const SGPath&root);
|
||||
void set_texture_cache_dir(const SGPath&textureCache);
|
||||
|
||||
/**
|
||||
* Get list of data locations. fg_root is always the final item in the
|
||||
|
@ -232,6 +235,8 @@ public:
|
|||
// place.
|
||||
void set_download_dir (const SGPath &path);
|
||||
|
||||
const SGPath &get_texture_cache_dir() const { return texture_cache_dir; }
|
||||
|
||||
const SGPath &get_terrasync_dir () const { return terrasync_dir; }
|
||||
// The 'path' argument to set_terrasync_dir() must come from trustworthy
|
||||
// code, because the method grants read permissions to Nasal code for all
|
||||
|
|
|
@ -1731,6 +1731,7 @@ struct OptionDesc {
|
|||
{"enable-terrasync", false, OPTION_BOOL, "/sim/terrasync/enabled", true, "", 0 },
|
||||
{"terrasync-dir", true, OPTION_IGNORE, "", false, "", 0 },
|
||||
{"download-dir", true, OPTION_IGNORE, "", false, "", 0 },
|
||||
{"texture-cache-dir", true, OPTION_IGNORE, "", false, "", 0 },
|
||||
{"allow-nasal-read", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptAllowNasalRead },
|
||||
{"geometry", true, OPTION_FUNC, "", false, "", fgOptGeometry },
|
||||
{"bpp", true, OPTION_FUNC, "", false, "", fgOptBpp },
|
||||
|
@ -2460,17 +2461,23 @@ SGPath defaultDownloadDir()
|
|||
{
|
||||
#if defined(SG_WINDOWS)
|
||||
SGPath p(SGPath::documents());
|
||||
if (p.isNull()) {
|
||||
SG_LOG(SG_IO, SG_ALERT, "Failed to locate user's Documents directory, will default to FG_HOME");
|
||||
// fall through to standard get_fg_home codepath
|
||||
} else {
|
||||
return p / "FlightGear";
|
||||
}
|
||||
if (p.isNull()) {
|
||||
SG_LOG(SG_IO, SG_ALERT, "Failed to locate user's Documents directory, will default to FG_HOME");
|
||||
// fall through to standard get_fg_home codepath
|
||||
}
|
||||
else {
|
||||
return p / "FlightGear";
|
||||
}
|
||||
#endif
|
||||
|
||||
return globals->get_fg_home();
|
||||
}
|
||||
|
||||
SGPath defaultTextureCacheDir()
|
||||
{
|
||||
return defaultDownloadDir() / "TextureCache";
|
||||
}
|
||||
|
||||
OptionResult Options::processOptions()
|
||||
{
|
||||
// establish locale before showing help (this selects the default locale,
|
||||
|
@ -2553,6 +2560,29 @@ OptionResult Options::processOptions()
|
|||
// via a Nasal-writable place such as the property tree.
|
||||
globals->set_download_dir(downloadDir);
|
||||
|
||||
// Texture Cache directory handling
|
||||
SGPath textureCacheDir = SGPath::fromLocal8Bit(
|
||||
valueForOption("texture-cache-dir").c_str());
|
||||
if (textureCacheDir.isNull()) {
|
||||
textureCacheDir = defaultTextureCacheDir();
|
||||
SG_LOG(SG_GENERAL, SG_INFO,
|
||||
"Using default texture cache directory: " << textureCacheDir);
|
||||
}
|
||||
else {
|
||||
SG_LOG(SG_GENERAL, SG_INFO,
|
||||
"Using explicit texture cache directory: " << textureCacheDir);
|
||||
}
|
||||
|
||||
simgear::Dir tcd(textureCacheDir);
|
||||
if (!tcd.exists()) {
|
||||
SG_LOG(SG_GENERAL, SG_INFO,
|
||||
"Creating texture cache directory: " << textureCacheDir);
|
||||
tcd.create(0755);
|
||||
}
|
||||
|
||||
globals->set_texture_cache_dir(textureCacheDir);
|
||||
|
||||
|
||||
// TerraSync directory fixup
|
||||
SGPath terrasyncDir = SGPath::fromLocal8Bit(
|
||||
valueForOption("terrasync-dir").c_str());
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include <simgear/scene/util/SGSceneUserData.hxx>
|
||||
#include <simgear/scene/model/CheckSceneryVisitor.hxx>
|
||||
#include <simgear/scene/sky/sky.hxx>
|
||||
#include <simgear/scene/util/SGSceneFeatures.hxx>
|
||||
|
||||
#include <simgear/bvh/BVHNode.hxx>
|
||||
#include <simgear/bvh/BVHLineSegmentVisitor.hxx>
|
||||
|
@ -224,6 +225,49 @@ private:
|
|||
const simgear::BVHMaterial* _material;
|
||||
bool _haveHit;
|
||||
};
|
||||
class FGScenery::TextureCacheListener : public SGPropertyChangeListener
|
||||
{
|
||||
protected:
|
||||
const char* root_node_path = "/sim/rendering/texture-cache";
|
||||
public:
|
||||
TextureCacheListener()
|
||||
{
|
||||
SGPropertyNode_ptr textureCacheNode = fgGetNode(root_node_path, true);
|
||||
setupPropertyListener(textureCacheNode, "cache-enabled");
|
||||
setupPropertyListener(textureCacheNode, "compress-transparent");
|
||||
setupPropertyListener(textureCacheNode, "compress-solid");
|
||||
setupPropertyListener(textureCacheNode, "compress");
|
||||
}
|
||||
|
||||
~TextureCacheListener()
|
||||
{
|
||||
SGPropertyNode_ptr maskNode = fgGetNode(root_node_path);
|
||||
for (int i = 0; i < maskNode->nChildren(); ++i) {
|
||||
maskNode->getChild(i)->removeChangeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
void setupPropertyListener(SGPropertyNode_ptr textureCacheNode, const char *node)
|
||||
{
|
||||
textureCacheNode->getChild(node, 0, true)->addChangeListener(this, true);
|
||||
}
|
||||
|
||||
virtual void valueChanged(SGPropertyNode * node)
|
||||
{
|
||||
bool b = node->getBoolValue();
|
||||
std::string name(node->getNameString());
|
||||
|
||||
if (name == "cache-enabled") {
|
||||
SGSceneFeatures::instance()->setTextureCacheActive(b);
|
||||
}
|
||||
else if (name == "compress-transparent" || name == "compress") {
|
||||
SGSceneFeatures::instance()->setTextureCacheCompressionActiveTransparent(b);
|
||||
}
|
||||
else if (name == "compress-solid" || name == "compress") {
|
||||
SGSceneFeatures::instance()->setTextureCacheCompressionActive(b);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class FGScenery::ScenerySwitchListener : public SGPropertyChangeListener
|
||||
{
|
||||
|
@ -285,7 +329,7 @@ private:
|
|||
|
||||
// Scenery Management system
|
||||
FGScenery::FGScenery() :
|
||||
_listener(NULL)
|
||||
_listener(nullptr), _textureCacheListener(nullptr)
|
||||
{
|
||||
// keep reference to pager singleton, so it cannot be destroyed while FGScenery lives
|
||||
_pager = FGScenery::getPagerSingleton();
|
||||
|
@ -297,6 +341,7 @@ FGScenery::FGScenery() :
|
|||
FGScenery::~FGScenery()
|
||||
{
|
||||
delete _listener;
|
||||
delete _textureCacheListener;
|
||||
}
|
||||
|
||||
|
||||
|
@ -364,7 +409,7 @@ void FGScenery::init() {
|
|||
_terrain->init( terrain_branch.get() );
|
||||
|
||||
_listener = new ScenerySwitchListener(this);
|
||||
|
||||
_textureCacheListener = new TextureCacheListener();
|
||||
// Toggle the setup flag.
|
||||
_inited = true;
|
||||
}
|
||||
|
|
|
@ -65,6 +65,9 @@ class FGScenery : public SGSubsystem
|
|||
osg::ref_ptr<flightgear::SceneryPager> _pager;
|
||||
ScenerySwitchListener* _listener;
|
||||
|
||||
class TextureCacheListener;
|
||||
friend class TextureCacheListener;
|
||||
TextureCacheListener* _textureCacheListener;
|
||||
public:
|
||||
FGScenery();
|
||||
~FGScenery();
|
||||
|
|
|
@ -547,8 +547,8 @@ FGRenderer::init( void )
|
|||
SG_LOG(SG_VIEW, SG_WARN, "Unknown texture compression setting!");
|
||||
}
|
||||
}
|
||||
|
||||
// create sky, but can't build until setupView, since we depend
|
||||
SGSceneFeatures::instance()->setTextureCompressionPath(globals->get_texture_cache_dir());
|
||||
// create sky, but can't build until setupView, since we depend
|
||||
// on other subsystems to be inited, eg Ephemeris
|
||||
_sky = new SGSky;
|
||||
|
||||
|
@ -1554,6 +1554,14 @@ FGRenderer::update( ) {
|
|||
if (!_position_finalized || !_scenery_loaded->getBoolValue())
|
||||
{
|
||||
_splash_alpha->setDoubleValue(1.0);
|
||||
|
||||
GLint max_texture_size;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
|
||||
// abritrary range change as sometimes during init the device reports somewhat dubious values, so
|
||||
// we know that the size must be greater than size and that probably 9999999 is unreasonably large
|
||||
if (max_texture_size > 0 && max_texture_size < 9999999)
|
||||
SGSceneFeatures::instance()->setMaxTextureSize(max_texture_size);
|
||||
|
||||
return;
|
||||
}
|
||||
osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
|
||||
|
|
|
@ -207,6 +207,9 @@ main(int argc, char** argv)
|
|||
options->setPluginStringData("SimGear::FG_ROOT", fg_root.local8BitStr());
|
||||
// Omit building bounding volume trees, as the viewer will not run a simulation
|
||||
options->setPluginStringData("SimGear::BOUNDINGVOLUMES", "OFF");
|
||||
GLint max_texture_size;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
|
||||
options->setPluginStringData("SimGear::MAXTEXTURESIZE", std::to_string(max_texture_size? max_texture_size:8192));
|
||||
viewer.setReaderWriterOptions(options.get());
|
||||
|
||||
// Here, all arguments are processed
|
||||
|
|
Loading…
Add table
Reference in a new issue