]> git.tdb.fi Git - libs/gl.git/commitdiff
Move srgb handling to storage_pixelformat_from_graphics
authorMikko Rasa <tdb@tdb.fi>
Thu, 27 Oct 2016 07:06:16 +0000 (10:06 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 27 Oct 2016 07:06:16 +0000 (10:06 +0300)
source/pixelformat.cpp
source/pixelformat.h
source/texture2d.cpp
source/texturecube.cpp

index cd3bb2aa78e30709293dd8dfb13f4d42cd4c481d..679c6467503e3d4d059668890b1eb2922eb54426 100644 (file)
@@ -54,16 +54,22 @@ PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf)
        }
 }
 
-PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat pf)
+PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat pf, bool srgb)
 {
+       PixelFormat result;
        switch(pf)
        {
        case Graphics::RGBX:
        case Graphics::BGR:
-       case Graphics::BGRX: return RGB;
-       case Graphics::BGRA: return RGBA;
-       default: return pixelformat_from_graphics(pf);
+       case Graphics::BGRX: result = RGB; break;
+       case Graphics::BGRA: result = RGBA; break;
+       default: result = pixelformat_from_graphics(pf);
        }
+
+       if(srgb)
+               return get_srgb_pixelformat(result);
+       else
+               return result;
 }
 
 PixelFormat get_base_pixelformat(PixelFormat pf)
index 0fa6609a1ead97d061ad7f45c9e2a97ff0c805ba..7a562cc948408bccf0eaaba9982df73edc7307e7 100644 (file)
@@ -49,7 +49,7 @@ enum PixelFormat
 void operator>>(const LexicalConverter &, PixelFormat &);
 
 PixelFormat pixelformat_from_graphics(Graphics::PixelFormat);
-PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat);
+PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat, bool = false);
 
 PixelFormat get_base_pixelformat(PixelFormat);
 PixelFormat get_srgb_pixelformat(PixelFormat);
index 64ad124f97a1952f19307d429c8f9acd427d76c1..d435a356a9ef3f215c6f11d912e1c76fade17959 100644 (file)
@@ -118,12 +118,7 @@ void Texture2D::image(const Graphics::Image &img, bool srgb, bool from_buffer)
        unsigned h = img.get_height();
        PixelFormat fmt = pixelformat_from_graphics(img.get_format());
        if(width==0)
-       {
-               PixelFormat f = storage_pixelformat_from_graphics(img.get_format());
-               if(srgb)
-                       f = get_srgb_pixelformat(f);
-               storage(f, w, h);
-       }
+               storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h);
        else if(w!=width || h!=height)
                throw incompatible_data("Texture2D::image");
 
index 24d02f4022b2aeac380410ea481a2e392181f8af..576f1c718b3848aa043cb165b04a578f83500a70 100644 (file)
@@ -86,10 +86,7 @@ void TextureCube::image(TextureCubeFace face, const Graphics::Image &img, bool s
                if(w!=h)
                        throw incompatible_data("TextureCube::image");
 
-               PixelFormat f = storage_pixelformat_from_graphics(img.get_format());
-               if(srgb)
-                       f = get_srgb_pixelformat(f);
-               storage(f, w);
+               storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w);
        }
        else if(w!=size || h!=size)
                throw incompatible_data("TextureCube::image");