X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2Frender.cpp;h=d1913ad3e77b18d3a20aa51c4d6af7326982827b;hb=d2f4c8720ae2326fac4203fa4984d835e875b355;hp=fdf751e4248390e6f2b37a80a9707b139953e5cc;hpb=be3a81656b8493010d2329fa00da617e24293438;p=blank.git diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index fdf751e..d1913ad 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -261,8 +262,11 @@ void Texture::Data(const SDL_Surface &srf, bool pad2) noexcept { UnpackRowLength(0); } else if (srf.w > (1 << 30) || srf.h > (1 << 30)) { + // That's at least one gigapixel in either or both dimensions. + // If this is not an error, that's an insanely large or high + // resolution texture. #ifndef NDEBUG - throw std::runtime_error("texture too large"); + std::cerr << "texture size exceeds 2^30, aborting data import" << std::endl; #endif } else { GLsizei width = 1, height = 1; @@ -424,8 +428,28 @@ CubeMap &CubeMap::operator =(CubeMap &&other) noexcept { } -void CubeMap::Data(Face f, const SDL_Surface &srf) noexcept { - Data(f, srf.w, srf.h, Format(*srf.format), srf.pixels); +void CubeMap::Data(Face f, const SDL_Surface &srf) { + Format format; + Format fmt(*srf.format); + if (format.Compatible(fmt)) { + Data(f, srf.w, srf.h, fmt, srf.pixels); + } else { + SDL_Surface *converted = SDL_ConvertSurface( + const_cast(&srf), + &format.sdl_format, + 0 + ); + if (!converted) { + throw SDLError("SDL_ConvertSurface"); + } + Format new_fmt(*converted->format); + if (!format.Compatible(new_fmt)) { + SDL_FreeSurface(converted); + throw std::runtime_error("unable to convert texture input"); + } + Data(f, converted->w, converted->h, new_fmt, converted->pixels); + SDL_FreeSurface(converted); + } } void CubeMap::Data(Face face, GLsizei w, GLsizei h, const Format &f, GLvoid *data) noexcept {