X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2Frender.cpp;h=9468b68b794b8640558c986870f885c5e171c26d;hb=2e3774eb3f2d5d23a08731175b168566457e2192;hp=fdf751e4248390e6f2b37a80a9707b139953e5cc;hpb=be3a81656b8493010d2329fa00da617e24293438;p=blank.git diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index fdf751e..9468b68 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -424,8 +424,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 {