diff --git a/simgear/scene/util/OrthophotoManager.cxx b/simgear/scene/util/OrthophotoManager.cxx index 9dca6ac2..4363349c 100644 --- a/simgear/scene/util/OrthophotoManager.cxx +++ b/simgear/scene/util/OrthophotoManager.cxx @@ -18,6 +18,7 @@ // Boston, MA 02110-1301, USA. #include "OrthophotoManager.hxx" +#include "SGSceneFeatures.hxx" #include namespace simgear { @@ -303,6 +304,30 @@ namespace simgear { composite_image->copySubImage(s_offset, t_offset, 0, sub_image); } + int max_texture_size = SGSceneFeatures::instance()->getMaxTextureSize(); + int new_width = total_width; + int new_height = total_height; + if (new_width > max_texture_size) { + int factor = new_width / max_texture_size; + new_width /= factor; + new_height /= factor; + } + if (new_height > max_texture_size) { + int factor = new_height / max_texture_size; + new_width /= factor; + new_height /= factor; + } + if (total_width != new_width || total_height != new_height) { + SG_LOG(SG_OSG, SG_INFO, "Composite orthophoto exceeds the maximum texture size of your GPU. Automatic scaling will be performed."); + ImageRef scaled_image; + bool success = ImageUtils::resizeImage(composite_image, new_width, new_height, scaled_image); + if (success) { + composite_image = scaled_image; + } else { + SG_LOG(SG_OSG, SG_ALERT, "Failed to scale composite orthophoto."); + } + } + _texture = textureFromImage(composite_image); } diff --git a/simgear/scene/util/OrthophotoManager.hxx b/simgear/scene/util/OrthophotoManager.hxx index ba2cc880..f53730f7 100644 --- a/simgear/scene/util/OrthophotoManager.hxx +++ b/simgear/scene/util/OrthophotoManager.hxx @@ -36,6 +36,7 @@ #include #include "SGSceneFeatures.hxx" #include "OsgSingleton.hxx" +#include "SGImageUtils.hxx" namespace simgear { @@ -108,4 +109,4 @@ namespace simgear { }; } -#endif \ No newline at end of file +#endif