X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fpixelformat.cpp;h=26600b33661fca3c7e73729702278f0aa4664feb;hb=61ff840cd211f10d45dca8c4dad2cca5f68aaa42;hp=60fdc111e427c5e6ba563bfe0b849b1f4976537f;hpb=3d6188a7f48566398e7ad7548dbd47a68bc73bdc;p=libs%2Fgl.git diff --git a/source/pixelformat.cpp b/source/pixelformat.cpp index 60fdc111..26600b33 100644 --- a/source/pixelformat.cpp +++ b/source/pixelformat.cpp @@ -1,3 +1,5 @@ +#include +#include #include #include "pixelformat.h" @@ -46,13 +48,27 @@ PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf) case Graphics::LUMINANCE: return LUMINANCE; case Graphics::LUMINANCE_ALPHA: return LUMINANCE_ALPHA; case Graphics::RGB: return RGB; + case Graphics::RGBX: case Graphics::RGBA: return RGBA; case Graphics::BGR: return BGR; + case Graphics::BGRX: case Graphics::BGRA: return BGRA; default: throw invalid_argument("pixelformat_from_graphics"); } } +PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat pf) +{ + switch(pf) + { + case Graphics::RGBX: + case Graphics::BGR: + case Graphics::BGRX: return RGB; + case Graphics::BGRA: return RGBA; + default: return pixelformat_from_graphics(pf); + } +} + PixelFormat get_base_pixelformat(PixelFormat pf) { switch(pf) @@ -73,5 +89,53 @@ PixelFormat get_base_pixelformat(PixelFormat pf) } } +unsigned get_component_count(PixelFormat pf) +{ + switch(get_base_pixelformat(pf)) + { + case COLOR_INDEX: + case STENCIL_INDEX: + case DEPTH_COMPONENT: + case RED: + case GREEN: + case BLUE: + case LUMINANCE: + return 1; + case LUMINANCE_ALPHA: + return 2; + case RGB: + case BGR: + return 3; + case RGBA: + case BGRA: + return 4; + default: + throw invalid_argument("get_pixelformat_component_count"); + } +} + +void require_pixelformat(PixelFormat pf) +{ + switch(pf) + { + case RGB16F: + case RGB32F: + case RGBA16F: + case RGBA32F: + case LUMINANCE16F: + case LUMINANCE32F: + case LUMINANCE_ALPHA16F: + case LUMINANCE_ALPHA32F: + { static Require _req(ARB_texture_float); } + break; + case BGR: + case BGRA: + { static Require _req(EXT_bgra); } + break; + default: + break; + } +} + } // namespace GL } // namespace Msp