X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpixelformat.cpp;h=3fdf6942c63cc606c04babdf54316330878ec1f9;hb=194f960f91041ebee44e2745627d5e480e893d82;hp=b8180b2fb75e559477c0388eddc53509f35263ba;hpb=e37851b98dde5082ee92570354746f2f92e21940;p=libs%2Fgl.git diff --git a/source/pixelformat.cpp b/source/pixelformat.cpp index b8180b2f..3fdf6942 100644 --- a/source/pixelformat.cpp +++ b/source/pixelformat.cpp @@ -10,20 +10,10 @@ namespace GL { void operator>>(const LexicalConverter &conv, PixelFormat &fmt) { - if(conv.get()=="COLOR_INDEX") - fmt = COLOR_INDEX; - else if(conv.get()=="STENCIL_INDEX") + if(conv.get()=="STENCIL_INDEX") fmt = STENCIL_INDEX; else if(conv.get()=="DEPTH_COMPONENT") fmt = DEPTH_COMPONENT; - else if(conv.get()=="RED") - fmt = RED; - else if(conv.get()=="GREEN") - fmt = GREEN; - else if(conv.get()=="BLUE") - fmt = BLUE; - else if(conv.get()=="ALPHA") - fmt = ALPHA; else if(conv.get()=="RGB") fmt = RGB; else if(conv.get()=="RGBA") @@ -52,7 +42,6 @@ PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf) { switch(pf) { - case Graphics::COLOR_INDEX: return COLOR_INDEX; case Graphics::LUMINANCE: return LUMINANCE; case Graphics::LUMINANCE_ALPHA: return LUMINANCE_ALPHA; case Graphics::RGB: return RGB; @@ -65,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) @@ -101,6 +96,30 @@ PixelFormat get_base_pixelformat(PixelFormat pf) case LUMINANCE_ALPHA32F: case SLUMINANCE_ALPHA: case SLUMINANCE8_ALPHA8: return LUMINANCE_ALPHA; + case DEPTH_COMPONENT16: + case DEPTH_COMPONENT24: + case DEPTH_COMPONENT32: return DEPTH_COMPONENT; + default: return pf; + } +} + +PixelFormat get_sized_pixelformat(PixelFormat pf) +{ + switch(pf) + { + case RGB: return RGB8; + case RGBA: return RGBA8; + case SRGB: return SRGB8; + case SRGB_ALPHA: return SRGB8_ALPHA8; + case LUMINANCE: return LUMINANCE8; + case SLUMINANCE: return SLUMINANCE8; + case LUMINANCE_ALPHA: return LUMINANCE8_ALPHA8; + case SLUMINANCE_ALPHA: return SLUMINANCE8_ALPHA8; + case DEPTH_COMPONENT: + if(get_gl_api()==OPENGL_ES2) + return DEPTH_COMPONENT16; + else + return DEPTH_COMPONENT32; default: return pf; } } @@ -125,12 +144,8 @@ 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: case SLUMINANCE: return 1; @@ -144,10 +159,38 @@ unsigned get_component_count(PixelFormat pf) case BGRA: return 4; default: - throw invalid_argument("get_pixelformat_component_count"); + throw invalid_argument("get_component_count"); + } +} + +unsigned get_component_size(PixelFormat pf) +{ + switch(pf) + { + case RGB16F: + case RGBA16F: + case LUMINANCE16F: + case LUMINANCE_ALPHA16F: + case DEPTH_COMPONENT16: + return 2; + case DEPTH_COMPONENT24: + return 3; + case RGB32F: + case RGBA32F: + case LUMINANCE32F: + case LUMINANCE_ALPHA32F: + case DEPTH_COMPONENT32: + return 4; + default: + return 1; } } +unsigned get_pixel_size(PixelFormat pf) +{ + return get_component_count(pf)*get_component_size(pf); +} + void require_pixelformat(PixelFormat pf) { switch(pf) @@ -176,6 +219,12 @@ void require_pixelformat(PixelFormat pf) case BGRA: { static Require _req(EXT_bgra); } break; + case DEPTH_COMPONENT: + case DEPTH_COMPONENT16: + case DEPTH_COMPONENT24: + case DEPTH_COMPONENT32: + { static Require _req(ARB_depth_texture); } + break; default: break; }