]> git.tdb.fi Git - libs/gl.git/blobdiff - source/pixelformat.cpp
Add compatibility support for slope-based animation interpolation
[libs/gl.git] / source / pixelformat.cpp
index d866bcf8094b9f9d677ccea8c00bf36db8842cd7..0b13f3ccefa7fe53cf2e5868b157a7d0c0e5588b 100644 (file)
@@ -113,7 +113,8 @@ PixelFormat get_unsized_pixelformat(PixelFormat pf)
        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 +124,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)
        {
@@ -171,7 +165,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 +173,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)
@@ -248,6 +256,7 @@ unsigned get_component_size(PixelFormat pf)
        case RGB32F:
        case RGBA32F:
        case DEPTH_COMPONENT32:
+       case DEPTH_COMPONENT32F:
                return 4;
        default:
                return 0;
@@ -261,8 +270,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:
@@ -297,10 +315,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;