X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpixelformat.cpp;h=dcc6b4eea70d7c38eb07020d53b9f4aa107a9242;hb=d42c443d24a8e428c43f849b218c9e1a1dca4189;hp=d866bcf8094b9f9d677ccea8c00bf36db8842cd7;hpb=8f373af3e375799dd739fe932bc697e8595756b4;p=libs%2Fgl.git diff --git a/source/pixelformat.cpp b/source/pixelformat.cpp index d866bcf8..dcc6b4ee 100644 --- a/source/pixelformat.cpp +++ b/source/pixelformat.cpp @@ -34,10 +34,6 @@ void operator>>(const LexicalConverter &conv, PixelFormat &fmt) fmt = LUMINANCE; else if(conv.get()=="LUMINANCE_ALPHA") fmt = LUMINANCE_ALPHA; - else if(conv.get()=="SLUMINANCE") - fmt = SLUMINANCE; - else if(conv.get()=="SLUMINANCE_ALPHA") - fmt = SLUMINANCE_ALPHA; else throw lexical_error(format("conversion of '%s' to PixelFormat", conv.get())); } @@ -83,8 +79,6 @@ PixelFormat get_base_pixelformat(PixelFormat pf) { case SRGB: return RGB; case SRGB_ALPHA: return RGBA; - case SLUMINANCE: return LUMINANCE; - case SLUMINANCE_ALPHA: return LUMINANCE_ALPHA; default: return unsized; } } @@ -107,13 +101,10 @@ PixelFormat get_unsized_pixelformat(PixelFormat pf) case RGBA16F: case RGBA32F: return RGBA; case SRGB8_ALPHA8: return SRGB_ALPHA; - case LUMINANCE8: return LUMINANCE; - case SLUMINANCE8: return SLUMINANCE; - case LUMINANCE_ALPHA8: return LUMINANCE_ALPHA; - case SLUMINANCE8_ALPHA8: return SLUMINANCE_ALPHA; case DEPTH_COMPONENT16: case DEPTH_COMPONENT24: - case DEPTH_COMPONENT32: return DEPTH_COMPONENT; + case DEPTH_COMPONENT32: + case DEPTH_COMPONENT32F: return DEPTH_COMPONENT; default: return pf; } } @@ -123,14 +114,7 @@ PixelFormat get_sized_pixelformat(PixelFormat pf, unsigned size) if(!size || size>4) throw invalid_argument("get_sized_pixelformat"); - switch(pf) - { - case SRGB: - case SRGB_ALPHA: break; - case SRGB8: pf = SRGB; break; - case SRGB8_ALPHA8: pf = SRGB_ALPHA; break; - default: pf = get_base_pixelformat(pf); - } + pf = get_unsized_pixelformat(pf); switch(size) { @@ -143,10 +127,6 @@ PixelFormat get_sized_pixelformat(PixelFormat pf, unsigned size) 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; default: throw invalid_argument("get_sized_pixelformat"); } case 2: @@ -171,7 +151,7 @@ PixelFormat get_sized_pixelformat(PixelFormat pf, unsigned size) case RG: return RG32F; case RGB: return RGB32F; case RGBA: return RGBA32F; - case DEPTH_COMPONENT: return DEPTH_COMPONENT32; + case DEPTH_COMPONENT: return ARB_depth_buffer_float ? DEPTH_COMPONENT32F : DEPTH_COMPONENT32; default: throw invalid_argument("get_sized_pixelformat"); } default: @@ -179,6 +159,20 @@ PixelFormat get_sized_pixelformat(PixelFormat pf, unsigned size) } } +PixelFormat get_default_sized_pixelformat(PixelFormat pf) +{ + pf = get_unsized_pixelformat(pf); + unsigned size = 1; + if(pf==DEPTH_COMPONENT) + { + if(get_gl_api()==OPENGL_ES2 && !ARB_depth_buffer_float) + size = 2; + else + size = 4; + } + return get_sized_pixelformat(pf, size); +} + PixelFormat get_srgb_pixelformat(PixelFormat pf) { switch(pf) @@ -187,10 +181,6 @@ PixelFormat get_srgb_pixelformat(PixelFormat pf) case RGBA: return SRGB_ALPHA; case RGB8: return SRGB8; case RGBA8: return SRGB8_ALPHA8; - case LUMINANCE: return SLUMINANCE; - case LUMINANCE8: return SLUMINANCE8; - case LUMINANCE_ALPHA: return SLUMINANCE_ALPHA; - case LUMINANCE_ALPHA8: return SLUMINANCE8_ALPHA8; default: return pf; } } @@ -203,11 +193,9 @@ unsigned get_component_count(PixelFormat pf) case DEPTH_COMPONENT: case RED: case LUMINANCE: - case SLUMINANCE: return 1; case RG: case LUMINANCE_ALPHA: - case SLUMINANCE_ALPHA: return 2; case RGB: case BGR: @@ -230,10 +218,6 @@ unsigned get_component_size(PixelFormat pf) case RGBA8: case SRGB8: case SRGB8_ALPHA8: - case LUMINANCE8: - case LUMINANCE8_ALPHA8: - case SLUMINANCE8: - case SLUMINANCE8_ALPHA8: return 1; case R16F: case RG16F: @@ -248,6 +232,7 @@ unsigned get_component_size(PixelFormat pf) case RGB32F: case RGBA32F: case DEPTH_COMPONENT32: + case DEPTH_COMPONENT32F: return 4; default: return 0; @@ -261,8 +246,17 @@ unsigned get_pixel_size(PixelFormat pf) void require_pixelformat(PixelFormat pf) { + /* TODO These checks are only accurate for textures. On OpenGL ES some + formats are allowed for render buffers earlier than textures. In particular + it's possible to create a 16-bit depth renderbuffer on OpenGL ES 2.0 but + depth textures are only available with 3.0 or the OES_depth_texture + extension.*/ switch(pf) { + case RGB8: + case RGBA8: + { static Require _req(OES_required_internalformat); } + break; case RED: case R8: case RG: @@ -286,10 +280,6 @@ void require_pixelformat(PixelFormat pf) case SRGB8: case SRGB_ALPHA: case SRGB8_ALPHA8: - case SLUMINANCE: - case SLUMINANCE8: - case SLUMINANCE_ALPHA: - case SLUMINANCE8_ALPHA8: { static Require _req(EXT_texture_sRGB); } break; case BGR: @@ -297,10 +287,19 @@ void require_pixelformat(PixelFormat pf) { static Require _req(EXT_bgra); } break; case DEPTH_COMPONENT: + { static Require _req(ARB_depth_texture); } + break; case DEPTH_COMPONENT16: case DEPTH_COMPONENT24: case DEPTH_COMPONENT32: { static Require _req(ARB_depth_texture); } + { static Require _req(OES_required_internalformat); } + break; + case DEPTH_COMPONENT32F: + { static Require _req(ARB_depth_buffer_float); } + break; + case STENCIL_INDEX: + { static Require _req(OES_texture_stencil8); } break; default: break;