]> git.tdb.fi Git - libs/gl.git/commitdiff
Make RenderTargetFormat generation more robust
authorMikko Rasa <tdb@tdb.fi>
Sat, 20 Feb 2021 13:12:29 +0000 (15:12 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 20 Feb 2021 16:42:41 +0000 (18:42 +0200)
The functions here had accidentally gotten out of sync in 9087cc0.

source/render/rendertarget.cpp

index 1349944b862ff969f6347d5ca070696bb597f09b..5c4cc20ffdcbd05c477eacde748fb2a8a3170c8a 100644 (file)
@@ -35,23 +35,32 @@ RenderTargetFormat RenderTargetFormat::operator,(PixelFormat f) const
                throw invalid_operation("RenderTargetFormat::operator,");
 
        PixelComponents comp = get_components(f);
-       unsigned size = get_component_size(f);
+       DataType type = get_component_type(f);
+       unsigned size = 0;
        unsigned char out = outputs[count-1];
        if(get_output_type(out)>=get_output_type(RENDER_DEPTH))
        {
                if(comp!=DEPTH_COMPONENT)
                        throw invalid_argument("RenderTargetFormat::operator,");
-               if(size>1)
-                       --size;
-               if(get_component_type(f)==UNSIGNED_INT)
-                       --size;
+               switch(type)
+               {
+               case UNSIGNED_SHORT: size = 0; break;
+               case UNSIGNED_INT: size = 2; break;
+               case FLOAT: size = 3; break;
+               default: throw invalid_argument("RenderTargetFormat::operator,");
+               }
        }
        else
        {
                if(comp!=RED && comp!=RG && comp!=RGB && comp!=RGBA)
                        throw invalid_argument("RenderTargetformat::operator,");
-               if(size>3)
-                       --size;
+               switch(type)
+               {
+               case UNSIGNED_BYTE: size = 0; break;
+               case HALF_FLOAT: size = 2; break;
+               case FLOAT: size = 3; break;
+               default: throw invalid_argument("RenderTargetFormat::operator,");
+               }
        }
 
        out = (out&~15) | (size<<2) | (get_component_count(f)-1);