Merge branch 'next' of https://git.code.sf.net/p/flightgear/simgear into next
This commit is contained in:
@@ -262,85 +262,87 @@ ModelRegistry::readImage(const string& fileName,
|
|||||||
if (!fileExists(newName)) {
|
if (!fileExists(newName)) {
|
||||||
res = registry->readImageImplementation(absFileName, opt);
|
res = registry->readImageImplementation(absFileName, opt);
|
||||||
|
|
||||||
osg::ref_ptr<osg::Image> srcImage = res.getImage();
|
if (res.validImage()) {
|
||||||
int width = srcImage->s();
|
osg::ref_ptr<osg::Image> srcImage = res.getImage();
|
||||||
bool transparent = srcImage->isImageTranslucent();
|
int width = srcImage->s();
|
||||||
int height = srcImage->t();
|
bool transparent = srcImage->isImageTranslucent();
|
||||||
|
int height = srcImage->t();
|
||||||
|
|
||||||
if (height >= max_texture_size)
|
if (height >= max_texture_size)
|
||||||
{
|
{
|
||||||
SG_LOG(SG_IO, SG_WARN, "Image texture too high " << width << "," << height << absFileName);
|
SG_LOG(SG_IO, SG_WARN, "Image texture too high " << width << "," << height << absFileName);
|
||||||
osg::ref_ptr<osg::Image> resizedImage;
|
osg::ref_ptr<osg::Image> resizedImage;
|
||||||
int factor = height / max_texture_size;
|
int factor = height / max_texture_size;
|
||||||
if (ImageUtils::resizeImage(srcImage, width / factor, height / factor, resizedImage))
|
if (ImageUtils::resizeImage(srcImage, width / factor, height / factor, resizedImage))
|
||||||
srcImage = resizedImage;
|
srcImage = resizedImage;
|
||||||
width = srcImage->s();
|
width = srcImage->s();
|
||||||
height = srcImage->t();
|
height = srcImage->t();
|
||||||
}
|
}
|
||||||
if (width >= max_texture_size)
|
if (width >= max_texture_size)
|
||||||
{
|
{
|
||||||
SG_LOG(SG_IO, SG_WARN, "Image texture too wide " << width << "," << height << absFileName);
|
SG_LOG(SG_IO, SG_WARN, "Image texture too wide " << width << "," << height << absFileName);
|
||||||
osg::ref_ptr<osg::Image> resizedImage;
|
osg::ref_ptr<osg::Image> resizedImage;
|
||||||
int factor = width / max_texture_size;
|
int factor = width / max_texture_size;
|
||||||
if (ImageUtils::resizeImage(srcImage, width / factor, height / factor, resizedImage))
|
if (ImageUtils::resizeImage(srcImage, width / factor, height / factor, resizedImage))
|
||||||
srcImage = resizedImage;
|
srcImage = resizedImage;
|
||||||
width = srcImage->s();
|
width = srcImage->s();
|
||||||
height = srcImage->t();
|
height = srcImage->t();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// only cache power of two textures that are of a reasonable size
|
// only cache power of two textures that are of a reasonable size
|
||||||
if (width >= 64 && height >= 64 && isPowerOfTwo(width, height)) {
|
if (width >= 64 && height >= 64 && isPowerOfTwo(width, height)) {
|
||||||
simgear::effect::MipMapTuple mipmapFunctions(simgear::effect::AVERAGE, simgear::effect::AVERAGE, simgear::effect::AVERAGE, simgear::effect::AVERAGE);
|
simgear::effect::MipMapTuple mipmapFunctions(simgear::effect::AVERAGE, simgear::effect::AVERAGE, simgear::effect::AVERAGE, simgear::effect::AVERAGE);
|
||||||
|
|
||||||
SGPath filePath(newName);
|
SGPath filePath(newName);
|
||||||
filePath.create_dir();
|
filePath.create_dir();
|
||||||
|
|
||||||
// setup the options string for saving the texture as we don't want OSG to auto flip the texture
|
// setup the options string for saving the texture as we don't want OSG to auto flip the texture
|
||||||
// as this complicates loading as it requires a flag to flip it back which will preclude the
|
// as this complicates loading as it requires a flag to flip it back which will preclude the
|
||||||
// image from being cached because we will have to clone the options to set the flag and thus lose
|
// image from being cached because we will have to clone the options to set the flag and thus lose
|
||||||
// the link to the cache in the options from the caller.
|
// the link to the cache in the options from the caller.
|
||||||
osg::ref_ptr<Options> nopt;
|
osg::ref_ptr<Options> nopt;
|
||||||
nopt = opt->cloneOptions();
|
nopt = opt->cloneOptions();
|
||||||
std::string optionstring = nopt->getOptionString();
|
std::string optionstring = nopt->getOptionString();
|
||||||
|
|
||||||
if (!optionstring.empty())
|
if (!optionstring.empty())
|
||||||
optionstring += " ";
|
optionstring += " ";
|
||||||
|
|
||||||
nopt->setOptionString(optionstring + "ddsNoAutoFlipWrite");
|
nopt->setOptionString(optionstring + "ddsNoAutoFlipWrite");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* decide if we need to compress this.
|
* decide if we need to compress this.
|
||||||
*/
|
*/
|
||||||
bool compress = (transparent && compress_transparent) || (!transparent && compress_solid);
|
bool compress = (transparent && compress_transparent) || (!transparent && compress_solid);
|
||||||
|
|
||||||
if (compress) {
|
if (compress) {
|
||||||
if (processor)
|
if (processor)
|
||||||
{
|
{
|
||||||
if (transparent)
|
if (transparent)
|
||||||
processor->compress(*srcImage, osg::Texture::USE_S3TC_DXT5_COMPRESSION, true, true, osgDB::ImageProcessor::USE_CPU, osgDB::ImageProcessor::PRODUCTION);
|
processor->compress(*srcImage, osg::Texture::USE_S3TC_DXT5_COMPRESSION, true, true, osgDB::ImageProcessor::USE_CPU, osgDB::ImageProcessor::PRODUCTION);
|
||||||
else
|
else
|
||||||
processor->compress(*srcImage, osg::Texture::USE_S3TC_DXT1_COMPRESSION, true, true, osgDB::ImageProcessor::USE_CPU, osgDB::ImageProcessor::PRODUCTION);
|
processor->compress(*srcImage, osg::Texture::USE_S3TC_DXT1_COMPRESSION, true, true, osgDB::ImageProcessor::USE_CPU, osgDB::ImageProcessor::PRODUCTION);
|
||||||
//processor->generateMipMap(*srcImage, true, osgDB::ImageProcessor::USE_CPU);
|
//processor->generateMipMap(*srcImage, true, osgDB::ImageProcessor::USE_CPU);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
simgear::effect::MipMapTuple mipmapFunctions(simgear::effect::AVERAGE, simgear::effect::AVERAGE, simgear::effect::AVERAGE, simgear::effect::AVERAGE);
|
simgear::effect::MipMapTuple mipmapFunctions(simgear::effect::AVERAGE, simgear::effect::AVERAGE, simgear::effect::AVERAGE, simgear::effect::AVERAGE);
|
||||||
SG_LOG(SG_IO, SG_WARN, "Texture compression plugin (osg_nvtt) not available; storing uncompressed image: " << newName);
|
SG_LOG(SG_IO, SG_WARN, "Texture compression plugin (osg_nvtt) not available; storing uncompressed image: " << newName);
|
||||||
srcImage = simgear::effect::computeMipmap(srcImage, mipmapFunctions);
|
srcImage = simgear::effect::computeMipmap(srcImage, mipmapFunctions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (processor) {
|
if (processor) {
|
||||||
processor->generateMipMap(*srcImage, true, osgDB::ImageProcessor::USE_CPU);
|
processor->generateMipMap(*srcImage, true, osgDB::ImageProcessor::USE_CPU);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
simgear::effect::MipMapTuple mipmapFunctions(simgear::effect::AVERAGE, simgear::effect::AVERAGE, simgear::effect::AVERAGE, simgear::effect::AVERAGE);
|
simgear::effect::MipMapTuple mipmapFunctions(simgear::effect::AVERAGE, simgear::effect::AVERAGE, simgear::effect::AVERAGE, simgear::effect::AVERAGE);
|
||||||
srcImage = simgear::effect::computeMipmap(srcImage, mipmapFunctions);
|
srcImage = simgear::effect::computeMipmap(srcImage, mipmapFunctions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
registry->writeImage(*srcImage, newName, nopt);
|
registry->writeImage(*srcImage, newName, nopt);
|
||||||
absFileName = newName;
|
absFileName = newName;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
absFileName = newName;
|
absFileName = newName;
|
||||||
|
|||||||
Reference in New Issue
Block a user