]> git.tdb.fi Git - libs/gl.git/commitdiff
Separate abstract pixel compositions from concrete pixel formats
authorMikko Rasa <tdb@tdb.fi>
Mon, 1 Feb 2021 19:08:29 +0000 (21:08 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 1 Feb 2021 19:31:44 +0000 (21:31 +0200)
Texture and renderbuffer storage must now be specified using a sized
pixel format.  The PixelFormat API has also been refactored.

26 files changed:
extensions/msp_luminance_formats.glext [new file with mode: 0644]
gl.msp.xml
source/ambientocclusion.cpp
source/colorcurve.cpp
source/datatype.h
source/environmentmap.cpp
source/pipeline.cpp
source/pixelformat.cpp
source/pixelformat.h
source/pixelstore.cpp
source/renderbuffer.cpp
source/renderbuffer.h
source/rendertarget.cpp
source/shadowmap.cpp
source/texture.cpp
source/texture.h
source/texture1d.cpp
source/texture1d.h
source/texture2d.cpp
source/texture2d.h
source/texture2darray.cpp
source/texture2darray.h
source/texture3d.cpp
source/texture3d.h
source/texturecube.cpp
source/texturecube.h

diff --git a/extensions/msp_luminance_formats.glext b/extensions/msp_luminance_formats.glext
new file mode 100644 (file)
index 0000000..c513e08
--- /dev/null
@@ -0,0 +1 @@
+extension MSP_luminance_formats
index 0309a61d9b21bbc35156a98fd4deba00e0b12d12..7895a806ae486559e873c77885a57f7b3f591045 100644 (file)
                 <command name="glPrimitiveRestartIndex" />
             </require>
         </extension>
+
+        <extension name="GL_MSP_luminance_formats" supported="gl">
+            <require>
+                <enum name="GL_LUMINANCE" />
+                <enum name="GL_LUMINANCE_ALPHA" />
+                <enum name="GL_LUMINANCE8" />
+                <enum name="GL_LUMINANCE8_ALPHA8" />
+            </require>
+        </extension>
     </extensions>
 </registry>
index 8826964a8223f65941e0f0a40467f80191cd5442..b1dccc0e4c632ea8dd55ad5390c7fea5135413d4 100644 (file)
@@ -12,7 +12,7 @@ namespace Msp {
 namespace GL {
 
 AmbientOcclusion::AmbientOcclusion(unsigned w, unsigned h, float):
-       occlude_target(w, h, (RENDER_COLOR,RED)),
+       occlude_target(w, h, (RENDER_COLOR,R8)),
        occlude_shader("ambientocclusion_occlude.glsl"),
        combine_shader("ambientocclusion_combine.glsl"),
        quad(get_fullscreen_quad())
@@ -21,7 +21,7 @@ AmbientOcclusion::AmbientOcclusion(unsigned w, unsigned h, float):
        texturing.attach(2, occlude_target.get_target_texture(RENDER_COLOR));
 
        unsigned seed = 1;
-       rotate_lookup.storage(RGBA, 4, 4, 1);
+       rotate_lookup.storage(RGBA8, 4, 4, 1);
        rotate_lookup.get_default_sampler().set_filter(NEAREST);
        unsigned char data[64];
        for(unsigned i=0; i<16; ++i)
index 8983df2bb7fb1b943d88decca8305cff95c176f5..1f6f7bf9ec1f77df01f8db326b4bafa9c5e94ce8 100644 (file)
@@ -18,7 +18,7 @@ ColorCurve::ColorCurve():
        shdata.uniform("source", 0);
        shdata.uniform("curve", 1);
 
-       curve.storage(LUMINANCE, 256, 1);
+       curve.storage(LUMINANCE8, 256, 1);
        Sampler &sampler = curve.get_default_sampler();
        sampler.set_min_filter(LINEAR);
        sampler.set_wrap(CLAMP_TO_EDGE);
index 0d52408a6b21764fbfad86eaccc26a47c89ac678..2d783f6142cdc1dadfb0e8acb5411ddaa41c4221 100644 (file)
@@ -2,6 +2,7 @@
 #define MSP_GL_DATATYPE_H_
 
 #include "gl.h"
+#include <msp/gl/extensions/nv_half_float.h>
 
 namespace Msp {
 namespace GL {
@@ -14,9 +15,12 @@ enum DataType
        UNSIGNED_SHORT = GL_UNSIGNED_SHORT,
        INT            = GL_INT,
        UNSIGNED_INT   = GL_UNSIGNED_INT,
-       FLOAT          = GL_FLOAT
+       FLOAT          = GL_FLOAT,
+       HALF_FLOAT     = GL_HALF_FLOAT
 };
 
+unsigned get_type_size(DataType);
+
 } // namespace GL
 } // namespace Msp
 
index ac68ff99a892572a4042dd96adb93748c6424bd0..f4000c768cd2f3c77e8462e37655d4f10b3ed066 100644 (file)
@@ -17,11 +17,11 @@ EnvironmentMap::EnvironmentMap(unsigned s, Renderable &r, Renderable &e):
        update_interval(1),
        update_delay(0)
 {
-       env_tex.storage(RGB, size, 1);
+       env_tex.storage(RGB8, size, 1);
        Sampler &env_samp = env_tex.get_default_sampler();
        env_samp.set_wrap(CLAMP_TO_EDGE);
        env_samp.set_min_filter(LINEAR);
-       depth_buf.storage(DEPTH_COMPONENT, size, size);
+       depth_buf.storage(DEPTH_COMPONENT32F, size, size);
        for(unsigned i=0; i<6; ++i)
        {
                fbo[i].attach(COLOR_ATTACHMENT0, env_tex, TextureCube::enumerate_faces(i), 0);
index 26073549d9451f943a05b1c183a2b09c6fd30d3f..a7f4130bbab1fffd2605521426f562dbf42a92bf 100644 (file)
@@ -234,7 +234,7 @@ void Pipeline::create_targets(unsigned recreate)
                target_ms = 0;
        }
 
-       PixelFormat color_pf = (hdr ? (alpha ? RGBA16F : RGB16F) : (alpha ? RGBA : RGB));
+       PixelFormat color_pf = (hdr ? (alpha ? RGBA16F : RGB16F) : (alpha ? RGBA8 : RGB8));
        RenderTargetFormat fmt = (RENDER_COLOR,color_pf, RENDER_DEPTH);
        if(!postproc.empty() || samples)
        {
index dcc6b4eea70d7c38eb07020d53b9f4aa107a9242..cc6a6d007067a671dd8e849ba8e9ad4951787e74 100644 (file)
@@ -1,5 +1,5 @@
 #include <msp/gl/extensions/arb_texture_float.h>
-#include <msp/gl/extensions/ext_bgra.h>
+#include <msp/io/print.h>
 #include <msp/strings/format.h>
 #include "pixelformat.h"
 
@@ -8,37 +8,84 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-void operator>>(const LexicalConverter &conv, PixelFormat &fmt)
+void operator>>(const LexicalConverter &conv, PixelComponents &comp)
 {
        if(conv.get()=="STENCIL_INDEX")
-               fmt = STENCIL_INDEX;
+               comp = STENCIL_INDEX;
        else if(conv.get()=="DEPTH_COMPONENT")
-               fmt = DEPTH_COMPONENT;
+               comp = DEPTH_COMPONENT;
        else if(conv.get()=="RED")
-               fmt = RED;
+               comp = RED;
        else if(conv.get()=="RG")
-               fmt = RG;
+               comp = RG;
        else if(conv.get()=="RGB")
-               fmt = RGB;
+               comp = RGB;
        else if(conv.get()=="RGBA")
-               fmt = RGBA;
+               comp = RGBA;
        else if(conv.get()=="BGR")
-               fmt = BGR;
+               comp = BGR;
        else if(conv.get()=="BGRA")
-               fmt = BGRA;
-       else if(conv.get()=="SRGB")
-               fmt = SRGB;
-       else if(conv.get()=="SRGB_ALPHA")
-               fmt = SRGB_ALPHA;
+               comp = BGRA;
        else if(conv.get()=="LUMINANCE")
-               fmt = LUMINANCE;
+               comp = LUMINANCE;
        else if(conv.get()=="LUMINANCE_ALPHA")
-               fmt = LUMINANCE_ALPHA;
+               comp = LUMINANCE_ALPHA;
        else
                throw lexical_error(format("conversion of '%s' to PixelFormat", conv.get()));
 }
 
-PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf)
+void operator>>(const LexicalConverter &conv, PixelFormat &fmt)
+{
+       if(conv.get()=="R8")
+               fmt = R8;
+       else if(conv.get()=="R16F")
+               fmt = R16F;
+       else if(conv.get()=="R32F")
+               fmt = R32F;
+       else if(conv.get()=="RG8")
+               fmt = RG8;
+       else if(conv.get()=="RG16F")
+               fmt = RG16F;
+       else if(conv.get()=="RG32F")
+               fmt = RG32F;
+       else if(conv.get()=="RGB8")
+               fmt = RGB8;
+       else if(conv.get()=="RGB16F")
+               fmt = RGB16F;
+       else if(conv.get()=="RGB32F")
+               fmt = RGB32F;
+       else if(conv.get()=="RGBA8")
+               fmt = RGBA8;
+       else if(conv.get()=="RGBA16F")
+               fmt = RGBA16F;
+       else if(conv.get()=="RGBA32F")
+               fmt = RGBA32F;
+       else if(conv.get()=="SRGB8")
+               fmt = SRGB8;
+       else if(conv.get()=="SRGB8_ALPHA8")
+               fmt = SRGB8_ALPHA8;
+       else if(conv.get()=="LUMINANCE8")
+               fmt = LUMINANCE8;
+       else if(conv.get()=="LUMINANCE8_ALPHA8")
+               fmt = LUMINANCE8_ALPHA8;
+       else if(conv.get()=="DEPTH_COMPONENT16")
+               fmt = DEPTH_COMPONENT16;
+       else if(conv.get()=="DEPTH_COMPONENT24")
+               fmt = DEPTH_COMPONENT24;
+       else if(conv.get()=="DEPTH_COMPONENT32")
+               fmt = DEPTH_COMPONENT32;
+       else if(conv.get()=="DEPTH_COMPONENT32F")
+               fmt = DEPTH_COMPONENT32F;
+       else
+       {
+               PixelComponents comp;
+               conv >> comp;
+               fmt = make_pixelformat(comp, (comp==DEPTH_COMPONENT ? FLOAT : UNSIGNED_BYTE));
+               IO::print(IO::cerr, "Warning: deprecated conversion of '%s' to PixelFormat\n", conv.get());
+       }
+}
+
+PixelComponents pixelformat_from_graphics(Graphics::PixelFormat pf)
 {
        switch(pf)
        {
@@ -54,36 +101,105 @@ PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf)
        }
 }
 
-PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat pf, bool srgb)
+PixelComponents storage_pixelformat_from_graphics(Graphics::PixelFormat pf)
 {
-       PixelFormat result;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
        switch(pf)
        {
        case Graphics::RGBX:
        case Graphics::BGR:
-       case Graphics::BGRX: result = RGB; break;
-       case Graphics::BGRA: result = RGBA; break;
-       default: result = pixelformat_from_graphics(pf);
+       case Graphics::BGRX: return RGB;
+       case Graphics::BGRA: return RGBA;
+       default: return pixelformat_from_graphics(pf);
        }
+#pragma GCC diagnostic pop
+}
 
-       if(srgb)
-               return get_srgb_pixelformat(result);
-       else
-               return result;
+PixelFormat pixelformat_from_image(const Graphics::Image &image)
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+       PixelComponents comp = pixelformat_from_graphics(image.get_format());
+#pragma GCC diagnostic pop
+       return make_pixelformat(comp, UNSIGNED_BYTE);
+}
+
+PixelFormat make_pixelformat(PixelComponents comp, DataType type, bool srgb)
+{
+       if(srgb && type!=UNSIGNED_BYTE && comp!=RGB && comp!=RGBA)
+               throw invalid_argument("make_pixelformat");
+
+       switch(comp)
+       {
+       case RED:
+               switch(type)
+               {
+               case UNSIGNED_BYTE: return R8;
+               case HALF_FLOAT: return R16F;
+               case FLOAT: return R32F;
+               default: throw invalid_argument("make_pixelformat");
+               }
+       case RG:
+               switch(type)
+               {
+               case UNSIGNED_BYTE: return RG8;
+               case HALF_FLOAT: return RG16F;
+               case FLOAT: return RG32F;
+               default: throw invalid_argument("make_pixelformat");
+               }
+       case RGB:
+               switch(type)
+               {
+               case UNSIGNED_BYTE: return (srgb ? SRGB8 : RGB8);
+               case HALF_FLOAT: return RGB16F;
+               case FLOAT: return RGB32F;
+               default: throw invalid_argument("make_pixelformat");
+               }
+       case RGBA:
+               switch(type)
+               {
+               case UNSIGNED_BYTE: return (srgb ? SRGB8_ALPHA8 : RGBA8);
+               case HALF_FLOAT: return RGBA16F;
+               case FLOAT: return RGBA32F;
+               default: throw invalid_argument("make_pixelformat");
+               }
+       case LUMINANCE:
+               if(type!=UNSIGNED_BYTE)
+                       throw invalid_argument("make_pixelformat");
+               return LUMINANCE8;
+       case LUMINANCE_ALPHA:
+               if(type!=UNSIGNED_BYTE)
+                       throw invalid_argument("make_pixelformat");
+               return LUMINANCE8;
+       case STENCIL_INDEX:
+               if(type!=UNSIGNED_BYTE)
+                       throw invalid_argument("make_pixelformat");
+               return STENCIL_INDEX8;
+       case DEPTH_COMPONENT:
+               switch(type)
+               {
+               case UNSIGNED_SHORT: return DEPTH_COMPONENT16;
+               case UNSIGNED_INT: return DEPTH_COMPONENT32;
+               case FLOAT: return DEPTH_COMPONENT32F;
+               default: throw invalid_argument("make_pixelformat");
+               }
+       default:
+               throw invalid_argument("make_pixelformat");
+       }
 }
 
 PixelFormat get_base_pixelformat(PixelFormat pf)
 {
-       PixelFormat unsized = get_unsized_pixelformat(pf);
-       switch(unsized)
+       switch(pf)
        {
-       case SRGB: return RGB;
-       case SRGB_ALPHA: return RGBA;
-       default: return unsized;
+       case SRGB8: return RGB8;
+       case SRGB8_ALPHA8: return RGBA8;
+       default: return pf;
        }
 }
 
-PixelFormat get_unsized_pixelformat(PixelFormat pf)
+PixelComponents get_components(PixelFormat pf)
 {
        switch(pf)
        {
@@ -95,99 +211,49 @@ PixelFormat get_unsized_pixelformat(PixelFormat pf)
        case RG32F: return RG;
        case RGB8:
        case RGB16F:
-       case RGB32F: return RGB;
-       case SRGB8: return SRGB;
+       case RGB32F:
+       case SRGB8: return RGB;
        case RGBA8:
        case RGBA16F:
-       case RGBA32F: return RGBA;
-       case SRGB8_ALPHA8: return SRGB_ALPHA;
+       case RGBA32F:
+       case SRGB8_ALPHA8: return RGBA;
+       case LUMINANCE8: return LUMINANCE;
+       case LUMINANCE8_ALPHA8: return LUMINANCE_ALPHA;
+       case STENCIL_INDEX8: return STENCIL_INDEX;
        case DEPTH_COMPONENT16:
        case DEPTH_COMPONENT24:
        case DEPTH_COMPONENT32:
        case DEPTH_COMPONENT32F: return DEPTH_COMPONENT;
-       default: return pf;
-       }
-}
-
-PixelFormat get_sized_pixelformat(PixelFormat pf, unsigned size)
-{
-       if(!size || size>4)
-               throw invalid_argument("get_sized_pixelformat");
-
-       pf = get_unsized_pixelformat(pf);
-
-       switch(size)
-       {
-       case 1:
-               switch(pf)
-               {
-               case RED: return R8;
-               case RG: return RG8;
-               case RGB: return RGB8;
-               case RGBA: return RGBA8;
-               case SRGB: return SRGB8;
-               case SRGB_ALPHA: return SRGB8_ALPHA8;
-               default: throw invalid_argument("get_sized_pixelformat");
-               }
-       case 2:
-               switch(pf)
-               {
-               case RED: return R16F;
-               case RG: return RG16F;
-               case RGB: return RGB16F;
-               case RGBA: return RGBA16F;
-               case DEPTH_COMPONENT: return DEPTH_COMPONENT16;
-               default: throw invalid_argument("get_sized_pixelformat");
-               }
-       case 3:
-               if(pf==DEPTH_COMPONENT)
-                       return DEPTH_COMPONENT24;
-               else
-                       throw invalid_argument("get_sized_pixelformat");
-       case 4:
-               switch(pf)
-               {
-               case RED: return R32F;
-               case RG: return RG32F;
-               case RGB: return RGB32F;
-               case RGBA: return RGBA32F;
-               case DEPTH_COMPONENT: return ARB_depth_buffer_float ? DEPTH_COMPONENT32F : DEPTH_COMPONENT32;
-               default: throw invalid_argument("get_sized_pixelformat");
-               }
-       default:
-               throw invalid_argument("get_sized_pixelformat");
+       default: throw invalid_argument("get_components");
        }
 }
 
-PixelFormat get_default_sized_pixelformat(PixelFormat pf)
+PixelFormat get_default_sized_pixelformat(PixelComponents comp)
 {
-       pf = get_unsized_pixelformat(pf);
-       unsigned size = 1;
-       if(pf==DEPTH_COMPONENT)
+       DataType type = UNSIGNED_BYTE;
+       if(comp==DEPTH_COMPONENT)
        {
                if(get_gl_api()==OPENGL_ES2 && !ARB_depth_buffer_float)
-                       size = 2;
+                       type = UNSIGNED_SHORT;
                else
-                       size = 4;
+                       type = FLOAT;
        }
-       return get_sized_pixelformat(pf, size);
+       return make_pixelformat(comp, type);
 }
 
 PixelFormat get_srgb_pixelformat(PixelFormat pf)
 {
        switch(pf)
        {
-       case RGB: return SRGB;
-       case RGBA: return SRGB_ALPHA;
        case RGB8: return SRGB8;
        case RGBA8: return SRGB8_ALPHA8;
        default: return pf;
        }
 }
 
-unsigned get_component_count(PixelFormat pf)
+unsigned get_component_count(PixelComponents comp)
 {
-       switch(get_base_pixelformat(pf))
+       switch(comp)
        {
        case STENCIL_INDEX:
        case DEPTH_COMPONENT:
@@ -208,7 +274,7 @@ unsigned get_component_count(PixelFormat pf)
        }
 }
 
-unsigned get_component_size(PixelFormat pf)
+DataType get_component_type(PixelFormat pf)
 {
        switch(pf)
        {
@@ -218,30 +284,34 @@ unsigned get_component_size(PixelFormat pf)
        case RGBA8:
        case SRGB8:
        case SRGB8_ALPHA8:
-               return 1;
+       case LUMINANCE8:
+       case LUMINANCE8_ALPHA8:
+               return UNSIGNED_BYTE;
        case R16F:
        case RG16F:
        case RGB16F:
        case RGBA16F:
+               return HALF_FLOAT;
        case DEPTH_COMPONENT16:
-               return 2;
-       case DEPTH_COMPONENT24:
-               return 3;
+               return UNSIGNED_SHORT;
        case R32F:
        case RG32F:
        case RGB32F:
        case RGBA32F:
        case DEPTH_COMPONENT32:
+               return UNSIGNED_INT;
        case DEPTH_COMPONENT32F:
-               return 4;
+               return FLOAT;
+       case DEPTH_COMPONENT24:
+               // There's no DataType value with 24-bit size
        default:
-               return 0;
+               throw invalid_argument("get_component_type");
        }
 }
 
 unsigned get_pixel_size(PixelFormat pf)
 {
-       return get_component_count(pf)*max(get_component_size(pf), 1U);
+       return get_component_count(pf)*get_type_size(get_component_type(pf));
 }
 
 void require_pixelformat(PixelFormat pf)
@@ -257,9 +327,7 @@ void require_pixelformat(PixelFormat pf)
        case RGBA8:
                { static Require _req(OES_required_internalformat); }
                break;
-       case RED:
        case R8:
-       case RG:
        case RG8:
                { static Require _req(ARB_texture_rg); }
                break;
@@ -276,19 +344,10 @@ void require_pixelformat(PixelFormat pf)
        case RGBA32F:
                { static Require _req(ARB_texture_float); }
                break;
-       case SRGB:
        case SRGB8:
-       case SRGB_ALPHA:
        case SRGB8_ALPHA8:
                { static Require _req(EXT_texture_sRGB); }
                break;
-       case BGR:
-       case BGRA:
-               { 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:
@@ -298,11 +357,11 @@ void require_pixelformat(PixelFormat pf)
        case DEPTH_COMPONENT32F:
                { static Require _req(ARB_depth_buffer_float); }
                break;
-       case STENCIL_INDEX:
+       case STENCIL_INDEX8:
                { static Require _req(OES_texture_stencil8); }
                break;
        default:
-               break;
+               throw invalid_argument("require_pixelformat");
        }
 }
 
index 377335f25fd901900046cf703cf97b9b6ac865ab..9dec8234988e30e68d34f5d0a41a33cd225a21a6 100644 (file)
@@ -1,7 +1,8 @@
 #ifndef MSP_GL_PIXELFORMAT_H_
 #define MSP_GL_PIXELFORMAT_H_
 
-#include <msp/graphics/pixelformat.h>
+#include <msp/core/attributes.h>
+#include <msp/graphics/image.h>
 #include <msp/strings/lexicalcast.h>
 #include "gl.h"
 #include <msp/gl/extensions/arb_depth_buffer_float.h>
 #include <msp/gl/extensions/ext_texture_srgb.h>
 #include <msp/gl/extensions/oes_required_internalformat.h>
 #include <msp/gl/extensions/oes_texture_stencil8.h>
+#include <msp/gl/extensions/msp_luminance_formats.h>
+#include "datatype.h"
 
 namespace Msp {
 namespace GL {
 
-enum PixelFormat
+enum PixelComponents
 {
        STENCIL_INDEX   = GL_STENCIL_INDEX,
        DEPTH_COMPONENT = GL_DEPTH_COMPONENT,
-       DEPTH_COMPONENT16 = GL_DEPTH_COMPONENT16,
-       DEPTH_COMPONENT24 = GL_DEPTH_COMPONENT24,
-       DEPTH_COMPONENT32 = GL_DEPTH_COMPONENT32,
-       DEPTH_COMPONENT32F = GL_DEPTH_COMPONENT32F,
        RED             = GL_RED,
        RG              = GL_RG,
        RGB             = GL_RGB,
        RGBA            = GL_RGBA,
+       BGR             = GL_BGR,
+       BGRA            = GL_BGRA,
+       LUMINANCE       = GL_LUMINANCE,
+       LUMINANCE_ALPHA = GL_LUMINANCE_ALPHA
+};
+
+enum PixelFormat
+{
        R8              = GL_R8,
        R16F            = GL_R16F,
        R32F            = GL_R32F,
@@ -40,32 +47,48 @@ enum PixelFormat
        RGBA8           = GL_RGBA8,
        RGBA16F         = GL_RGBA16F,
        RGBA32F         = GL_RGBA32F,
-       SRGB            = GL_SRGB,
-       SRGB_ALPHA      = GL_SRGB_ALPHA,
        SRGB8           = GL_SRGB8,
        SRGB8_ALPHA8    = GL_SRGB8_ALPHA8,
-       BGR             = GL_BGR,
-       BGRA            = GL_BGRA,
-       LUMINANCE       = GL_LUMINANCE,
-       LUMINANCE_ALPHA = GL_LUMINANCE_ALPHA
+       LUMINANCE8      = GL_LUMINANCE8,
+       LUMINANCE8_ALPHA8 = GL_LUMINANCE8_ALPHA8,
+       DEPTH_COMPONENT16 = GL_DEPTH_COMPONENT16,
+       DEPTH_COMPONENT24 = GL_DEPTH_COMPONENT24,
+       DEPTH_COMPONENT32 = GL_DEPTH_COMPONENT32,
+       DEPTH_COMPONENT32F = GL_DEPTH_COMPONENT32F,
+       STENCIL_INDEX8 = GL_STENCIL_INDEX8
 };
 
+void operator>>(const LexicalConverter &, PixelComponents &);
 void operator>>(const LexicalConverter &, PixelFormat &);
 
-PixelFormat pixelformat_from_graphics(Graphics::PixelFormat);
-PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat, bool = false);
+DEPRECATED PixelComponents pixelformat_from_graphics(Graphics::PixelFormat);
+DEPRECATED PixelComponents storage_pixelformat_from_graphics(Graphics::PixelFormat, bool);
+PixelFormat pixelformat_from_image(const Graphics::Image &);
+
+PixelFormat make_pixelformat(PixelComponents, DataType, bool = false);
+DEPRECATED PixelFormat get_base_pixelformat(PixelFormat);
+PixelComponents get_components(PixelFormat);
+DEPRECATED PixelFormat get_default_sized_pixelformat(PixelComponents);
+DEPRECATED PixelFormat get_srgb_pixelformat(PixelFormat);
+
+unsigned get_component_count(PixelComponents);
+inline unsigned get_component_count(PixelFormat f)
+{ return get_component_count(get_components(f)); }
+
+DataType get_component_type(PixelFormat);
+inline unsigned get_component_size(PixelFormat f)
+{ return get_type_size(get_component_type(f)); }
 
-PixelFormat get_base_pixelformat(PixelFormat);
-PixelFormat get_unsized_pixelformat(PixelFormat);
-PixelFormat get_sized_pixelformat(PixelFormat, unsigned = 1);
-PixelFormat get_default_sized_pixelformat(PixelFormat);
-PixelFormat get_srgb_pixelformat(PixelFormat);
-unsigned get_component_count(PixelFormat);
-unsigned get_component_size(PixelFormat);
 unsigned get_pixel_size(PixelFormat);
 
 void require_pixelformat(PixelFormat);
 
+DEPRECATED inline PixelFormat get_sized_pixelformat(PixelComponents c, unsigned s = 1)
+{ return make_pixelformat(c, (s==2 ? HALF_FLOAT : s==4 ? FLOAT : UNSIGNED_BYTE)); }
+
+DEPRECATED inline PixelComponents get_unsized_pixelformat(PixelFormat f)
+{ return get_components(f); }
+
 } // namespace GL
 } // namespace Msp
 
index e1a7cc0ef9ea378bce5db24f7035500b00829a36..409f0f9a862e3582c975a486188452a60544dfb6 100644 (file)
@@ -23,7 +23,7 @@ PixelStore PixelStore::from_image(const Graphics::Image &img)
 {
        PixelStore pstore;
        unsigned stride = img.get_stride();
-       unsigned ncomp = get_component_count(pixelformat_from_graphics(img.get_format()));
+       unsigned ncomp = get_component_count(pixelformat_from_image(img));
        pstore.set_canvas_size(img.get_stride()/ncomp, 0);
        pstore.set_alignment(min(stride&~(stride-1), 8U));
        return pstore;
index 5bea07fc81e60a70c26c7744f3e7d5a6434bc621..e86a97a50b63393d3220c02dd96e9d0e5037b85c 100644 (file)
@@ -24,17 +24,8 @@ Renderbuffer::~Renderbuffer()
        glDeleteRenderbuffers(1, &id);
 }
 
-PixelFormat Renderbuffer::normalize_format(PixelFormat fmt)
-{
-       if(!get_component_size(fmt) && OES_required_internalformat)
-               return get_default_sized_pixelformat(fmt);
-
-       return fmt;
-}
-
 void Renderbuffer::storage(PixelFormat fmt, unsigned wd, unsigned ht)
 {
-       fmt = normalize_format(fmt);
        require_pixelformat(fmt);
        width = wd;
        height = ht;
@@ -62,7 +53,6 @@ void Renderbuffer::storage_multisample(unsigned samples, PixelFormat fmt, unsign
        if(samples>get_max_samples())
                throw out_of_range("Renderbuffer::storage_multisample");
 
-       fmt = normalize_format(fmt);
        require_pixelformat(fmt);
 
        width = wd;
index 751374bd4a4258f70ca9afa74d1e16bf543b49a3..afc6ed204298a7bbcfe02d6c95a87af83c6a1bba 100644 (file)
@@ -31,10 +31,6 @@ public:
        unsigned get_width() const { return width; }
        unsigned get_height() const { return height; }
 
-private:
-       static PixelFormat normalize_format(PixelFormat);
-
-public:
        /** Allocates storage for the renderbuffer. */
        void storage(PixelFormat fmt, unsigned wd, unsigned ht);
 
index 74b4f32214e0bfe33ca54935b45d6d749a628de7..1349944b862ff969f6347d5ca070696bb597f09b 100644 (file)
@@ -34,19 +34,21 @@ RenderTargetFormat RenderTargetFormat::operator,(PixelFormat f) const
        if(!count)
                throw invalid_operation("RenderTargetFormat::operator,");
 
-       PixelFormat unsized = get_unsized_pixelformat(f);
+       PixelComponents comp = get_components(f);
        unsigned size = get_component_size(f);
        unsigned char out = outputs[count-1];
        if(get_output_type(out)>=get_output_type(RENDER_DEPTH))
        {
-               if(unsized!=DEPTH_COMPONENT)
-                       throw invalid_argument("RenderTargetformat::operator,");
+               if(comp!=DEPTH_COMPONENT)
+                       throw invalid_argument("RenderTargetFormat::operator,");
                if(size>1)
                        --size;
+               if(get_component_type(f)==UNSIGNED_INT)
+                       --size;
        }
        else
        {
-               if(unsized!=RED && unsized!=RG && unsized!=RGB && unsized!=RGBA)
+               if(comp!=RED && comp!=RG && comp!=RGB && comp!=RGBA)
                        throw invalid_argument("RenderTargetformat::operator,");
                if(size>3)
                        --size;
@@ -72,26 +74,23 @@ int RenderTargetFormat::index(RenderOutput o) const
 
 PixelFormat get_output_pixelformat(unsigned char o)
 {
-       unsigned size = ((o>>2)&3);
-       PixelFormat base;
+       PixelComponents comp;
+       DataType type;
        if(get_output_type(o)>=get_output_type(RENDER_DEPTH))
        {
-               base = DEPTH_COMPONENT;
-               if(size)
-                       ++size;
+               static DataType types[4] = { UNSIGNED_SHORT, UNSIGNED_SHORT, UNSIGNED_INT, FLOAT };
+               comp = DEPTH_COMPONENT;
+               type = types[(o>>2)&3];
        }
        else
        {
-               static PixelFormat base_formats[4] = { RED, RG, RGB, RGBA };
-               base = base_formats[o&3];
-               if(size==3)
-                       ++size;
+               static PixelComponents components[4] = { RED, RG, RGB, RGBA };
+               static DataType types[4] = { UNSIGNED_BYTE, UNSIGNED_SHORT, HALF_FLOAT, FLOAT };
+               comp = components[o&3];
+               type = types[(o>>2)&3];
        }
 
-       if(size)
-               return get_sized_pixelformat(base, size);
-       else
-               return base;
+       return make_pixelformat(comp, type);
 }
 
 
index 5d658807122d36e2e88cf78cbda8ee77dbada796..6250f899005b23684f0397b324609a174a858631 100644 (file)
@@ -24,7 +24,7 @@ ShadowMap::ShadowMap(unsigned s, Renderable &r, const Light &l):
        depth_samp.set_min_filter(LINEAR);
        depth_samp.set_compare(LEQUAL);
        depth_samp.set_wrap(CLAMP_TO_EDGE);
-       depth_buf.storage(DEPTH_COMPONENT, size, size, 1);
+       depth_buf.storage(DEPTH_COMPONENT32F, size, size, 1);
        fbo.attach(DEPTH_ATTACHMENT, depth_buf, 0);
        fbo.require_complete();
 
index 772f2d16e8b578fac2fbadbb6ef0f3da6f6f8954..f0c55999250263f641e546341e22b7545177748b 100644 (file)
@@ -24,7 +24,7 @@ int Texture::swizzle_orders[] =
 Texture::Texture(GLenum t, ResourceManager *m):
        id(0),
        target(t),
-       ifmt(RGB),
+       ifmt(RGB8),
        swizzle(NO_SWIZZLE),
        auto_gen_mipmap(false),
        default_sampler(*this)
@@ -46,30 +46,24 @@ Texture::~Texture()
                glDeleteTextures(1, &id);
 }
 
-DataType Texture::get_alloc_type(PixelFormat fmt)
-{
-       return (get_base_pixelformat(fmt)==DEPTH_COMPONENT ? UNSIGNED_SHORT : UNSIGNED_BYTE);
-}
-
 void Texture::set_internal_format(PixelFormat fmt)
 {
+       PixelComponents comp = get_components(fmt);
        FormatSwizzle swiz = NO_SWIZZLE;
-       switch(get_base_pixelformat(fmt))
+       switch(comp)
        {
        case LUMINANCE:
-               fmt = RED;
+               comp = RED;
                swiz = R_TO_LUMINANCE;
                break;
        case LUMINANCE_ALPHA:
-               fmt = RG;
+               comp = RG;
                swiz = RG_TO_LUMINANCE_ALPHA;
                break;
        default:;
        }
 
-       if(!get_component_size(fmt) && OES_required_internalformat)
-               fmt = get_default_sized_pixelformat(fmt);
-
+       fmt = make_pixelformat(comp, get_component_type(fmt));
        require_pixelformat(fmt);
        if(swiz!=NO_SWIZZLE)
                static Require _req(ARB_texture_swizzle);
@@ -77,12 +71,12 @@ void Texture::set_internal_format(PixelFormat fmt)
        swizzle = swiz;
 }
 
-PixelFormat Texture::get_upload_format(PixelFormat fmt) const
+PixelComponents Texture::get_upload_components(PixelComponents comp) const
 {
-       if(fmt==LUMINANCE || fmt==LUMINANCE_ALPHA)
-               return get_base_pixelformat(ifmt);
+       if(comp==LUMINANCE || comp==LUMINANCE_ALPHA)
+               return get_components(ifmt);
        else
-               return fmt;
+               return comp;
 }
 
 void Texture::apply_swizzle()
index adcfa76b7245276078af013622f343dca8ac65f0..71192fef06c42416b8a9dadc26f1fe2109626a67 100644 (file)
@@ -83,9 +83,8 @@ public:
        ~Texture();
 
 protected:
-       static DataType get_alloc_type(PixelFormat);
        void set_internal_format(PixelFormat);
-       PixelFormat get_upload_format(PixelFormat) const;
+       PixelComponents get_upload_components(PixelComponents) const;
        void apply_swizzle();
        void set_parameter_i(GLenum, int) const;
 
index b50f8cf444c0c9fb1435ce97e756ffc1330b59c2..24266150672a90fab1f1a5acd4fd8cb4d16f849a 100644 (file)
@@ -53,13 +53,10 @@ void Texture1D::allocate(unsigned level)
                allocated |= (1<<levels)-1;
        }
        else
-       {
-               PixelFormat base_fmt = get_base_pixelformat(ifmt);
-               image(level, base_fmt, get_alloc_type(base_fmt), 0);
-       }
+               image(level, get_components(ifmt), get_component_type(ifmt), 0);
 }
 
-void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
+void Texture1D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
 {
        if(width==0)
                throw invalid_operation("Texture1D::image");
@@ -67,7 +64,7 @@ void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void
        unsigned w = get_level_size(level);
 
        if(ARB_texture_storage)
-               return sub_image(level, 0, w, fmt, type, data);
+               return sub_image(level, 0, w, comp, type, data);
 
        BindRestore _bind(this);
 
@@ -76,7 +73,7 @@ void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void
                glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
                apply_swizzle();
        }
-       glTexImage1D(target, level, ifmt, w, 0, get_upload_format(fmt), type, data);
+       glTexImage1D(target, level, ifmt, w, 0, get_upload_components(comp), type, data);
 
        allocated |= 1<<level;
        if(auto_gen_mipmap && level==0)
@@ -86,7 +83,7 @@ void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void
        }
 }
 
-void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelFormat fmt, DataType type, const void *data)
+void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelComponents comp, DataType type, const void *data)
 {
        if(width==0)
                throw invalid_operation("Texture3D::image");
@@ -94,11 +91,11 @@ void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelFormat fmt, D
        Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
        allocate(level);
 
-       fmt = get_upload_format(fmt);
+       comp = get_upload_components(comp);
        if(ARB_direct_state_access)
-               glTextureSubImage1D(id, level, x, wd, fmt, type, data);
+               glTextureSubImage1D(id, level, x, wd, comp, type, data);
        else
-               glTexSubImage1D(target, level, x, wd, fmt, type, data);
+               glTexSubImage1D(target, level, x, wd, comp, type, data);
 
        if(auto_gen_mipmap && level==0)
                generate_mipmap();
@@ -110,13 +107,15 @@ void Texture1D::image(const Graphics::Image &img, unsigned lv, bool srgb)
                throw incompatible_data("Texture1D::image");
 
        unsigned w = img.get_width();
-       PixelFormat fmt = pixelformat_from_graphics(img.get_format());
+       PixelFormat fmt = pixelformat_from_image(img);
+       PixelComponents comp = get_components(fmt);
+       DataType type = get_component_type(fmt);
        if(width==0)
-               storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, lv);
+               storage(make_pixelformat(comp, type, srgb), w, lv);
        else if(w!=width)
                throw incompatible_data("Texture1D::image");
 
-       image(0, fmt, UNSIGNED_BYTE, img.get_data());
+       image(0, comp, type, img.get_data());
 }
 
 unsigned Texture1D::get_n_levels() const
@@ -158,7 +157,7 @@ void Texture1D::Loader::init()
 
 void Texture1D::Loader::raw_data(const string &data)
 {
-       obj.image(0, get_base_pixelformat(obj.ifmt), UNSIGNED_BYTE, data.data());
+       obj.image(0, get_components(obj.ifmt), get_component_type(obj.ifmt), data.data());
 }
 
 void Texture1D::Loader::storage(PixelFormat fmt, unsigned w)
index eb16696f988811ca237d7c0bebd2e158622c6cbb..b0a9c681e2c4917d05d3a108289d9515a308515b 100644 (file)
@@ -31,9 +31,13 @@ public:
        Texture1D();
 
        void storage(PixelFormat, unsigned, unsigned = 0);
+
+       DEPRECATED void storage(PixelComponents c, unsigned w, unsigned l = 0)
+       { storage(make_pixelformat(c, UNSIGNED_BYTE), w, l); }
+
        void allocate(unsigned);
-       void image(unsigned, PixelFormat, DataType, const void *);
-       void sub_image(unsigned, int, unsigned, PixelFormat, DataType, const void *);
+       void image(unsigned, PixelComponents, DataType, const void *);
+       void sub_image(unsigned, int, unsigned, PixelComponents, DataType, const void *);
        virtual void image(const Graphics::Image &, unsigned, bool = false);
        using Texture::image;
        unsigned get_width() const { return width; }
index 559167f8ba4d5eefc017e6e158d76dec55127cf6..8846a555d6437f6554c46e316a6f40be0b1c9728 100644 (file)
@@ -81,13 +81,10 @@ void Texture2D::allocate(unsigned level)
                allocated |= (1<<levels)-1;
        }
        else
-       {
-               PixelFormat base_fmt = get_base_pixelformat(ifmt);
-               image(level, base_fmt, get_alloc_type(base_fmt), 0);
-       }
+               image(level, get_components(ifmt), get_component_type(ifmt), 0);
 }
 
-void Texture2D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
+void Texture2D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
 {
        if(width==0 || height==0)
                throw invalid_operation("Texture2D::image");
@@ -97,7 +94,7 @@ void Texture2D::image(unsigned level, PixelFormat fmt, DataType type, const void
        get_level_size(level, w, h);
 
        if(ARB_texture_storage)
-               return sub_image(level, 0, 0, w, h, fmt, type, data);
+               return sub_image(level, 0, 0, w, h, comp, type, data);
 
        BindRestore _bind(this);
 
@@ -106,7 +103,7 @@ void Texture2D::image(unsigned level, PixelFormat fmt, DataType type, const void
                glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
                apply_swizzle();
        }
-       glTexImage2D(target, level, ifmt, w, h, 0, get_upload_format(fmt), type, data);
+       glTexImage2D(target, level, ifmt, w, h, 0, get_upload_components(comp), type, data);
 
        allocated |= 1<<level;
        if(auto_gen_mipmap && level==0)
@@ -116,7 +113,7 @@ void Texture2D::image(unsigned level, PixelFormat fmt, DataType type, const void
        }
 }
 
-void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, PixelFormat fmt, DataType type, const void *data)
+void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, PixelComponents comp, DataType type, const void *data)
 {
        if(width==0 || height==0)
                throw invalid_operation("Texture2D::sub_image");
@@ -124,11 +121,11 @@ void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht
        Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
        allocate(level);
 
-       fmt = get_upload_format(fmt);
+       comp = get_upload_components(comp);
        if(ARB_direct_state_access)
-               glTextureSubImage2D(id, level, x, y, wd, ht, fmt, type, data);
+               glTextureSubImage2D(id, level, x, y, wd, ht, comp, type, data);
        else
-               glTexSubImage2D(target, level, x, y, wd, ht, fmt, type, data);
+               glTexSubImage2D(target, level, x, y, wd, ht, comp, type, data);
 
        if(auto_gen_mipmap && level==0)
                generate_mipmap();
@@ -143,16 +140,18 @@ void Texture2D::image(const Graphics::Image &img, unsigned lv, bool srgb, bool f
 {
        unsigned w = img.get_width();
        unsigned h = img.get_height();
-       PixelFormat fmt = pixelformat_from_graphics(img.get_format());
+       PixelFormat fmt = pixelformat_from_image(img);
+       PixelComponents comp = get_components(fmt);
+       DataType type = get_component_type(fmt);
        if(width==0)
-               storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h, lv);
+               storage(make_pixelformat(comp, type, srgb), w, h, lv);
        else if(w!=width || h!=height || (lv && lv!=levels))
                throw incompatible_data("Texture2D::image");
 
        PixelStore pstore = PixelStore::from_image(img);
        BindRestore _bind_ps(pstore);
 
-       image(0, fmt, UNSIGNED_BYTE, from_buffer ? 0 : img.get_data());
+       image(0, comp, type, from_buffer ? 0 : img.get_data());
 }
 
 unsigned Texture2D::get_n_levels() const
@@ -216,7 +215,7 @@ void Texture2D::Loader::init()
 
 void Texture2D::Loader::raw_data(const string &data)
 {
-       obj.image(0, get_base_pixelformat(obj.ifmt), UNSIGNED_BYTE, data.data());
+       obj.image(0, get_components(obj.ifmt), get_component_type(obj.ifmt), data.data());
 }
 
 void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h)
index 092f12ba47aaa77167aaf8ee67648045dc0f8328..801d18dd339524c15b945544d8e895aacd024d94 100644 (file)
@@ -48,6 +48,9 @@ public:
        it can't be changed. */
        void storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned lv = 0);
 
+       DEPRECATED void storage(PixelComponents cm, unsigned wd, unsigned ht, unsigned lv = 0)
+       { storage(make_pixelformat(cm, UNSIGNED_BYTE), wd, ht, lv); }
+
        /** Allocates storage for the texture.  The contents are initially
        undefined.  If storage has already been allocated, does nothing. */
        void allocate(unsigned level);
@@ -55,13 +58,13 @@ public:
        /** Uploads an image to the texture.  Storage must be defined beforehand.
        The image data must have dimensions and format compatible with the defined
        storage. */
-       void image(unsigned level, PixelFormat fmt, DataType type, const void *data);
+       void image(unsigned level, PixelComponents fmt, DataType type, const void *data);
 
        /** Updates a rectangular region of the texture.  Storage must be defined
        and allocated beforehand.  The update region must be fully inside the
        texture. */
        void sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht,
-               PixelFormat fmt, DataType type, const void *data);
+               PixelComponents fmt, DataType type, const void *data);
 
        /** Uploads an image to the texture.  If storage has not been defined, it
        will be set to match the image.  Otherwise the image must be compatible with
index 1a085ed8e73bbe6c89c5361b7839a5fe32180c32..34b9532d3e80965dbc6777a2ff4d0e60a191d8ab 100644 (file)
@@ -15,14 +15,14 @@ Texture2DArray::Texture2DArray():
        static Require _req(EXT_texture_array);
 }
 
-void Texture2DArray::layer_image(unsigned level, unsigned z, PixelFormat fmt, DataType type, const void *data)
+void Texture2DArray::layer_image(unsigned level, unsigned z, PixelComponents comp, DataType type, const void *data)
 {
        unsigned w = get_width();
        unsigned h = get_height();
        unsigned d = get_depth();
        get_level_size(level, w, h, d);
 
-       sub_image(level, 0, 0, z, w, h, 1, fmt, type, data);
+       sub_image(level, 0, 0, z, w, h, 1, comp, type, data);
 }
 
 void Texture2DArray::layer_image(unsigned level, unsigned z, const Graphics::Image &img)
@@ -32,14 +32,14 @@ void Texture2DArray::layer_image(unsigned level, unsigned z, const Graphics::Ima
 
        unsigned w = img.get_width();
        unsigned h = img.get_height();
-       PixelFormat fmt = pixelformat_from_graphics(img.get_format());
+       PixelFormat fmt = pixelformat_from_image(img);
        if(w!=get_width() || h!=get_height())
                throw incompatible_data("Texture2DArray::layer_image");
 
        PixelStore pstore = PixelStore::from_image(img);
        BindRestore _bind_ps(pstore);
 
-       layer_image(level, z, fmt, UNSIGNED_BYTE, img.get_data());
+       layer_image(level, z, get_components(fmt), get_component_type(fmt), img.get_data());
 }
 
 
index 5e0969aa200ec5c5869934e2525af75bd01048cd..6aa4886c1584f966eda461a5f0290b9a8dcec83a 100644 (file)
@@ -27,7 +27,7 @@ public:
 
        Texture2DArray();
 
-       void layer_image(unsigned, unsigned, PixelFormat, DataType, const void *);
+       void layer_image(unsigned, unsigned, PixelComponents, DataType, const void *);
        void layer_image(unsigned, unsigned, const Graphics::Image &);
 
        unsigned get_layers() const { return get_depth(); }
index 5c09f1ea4249919bf526703365c730c48b11d4e7..010609a8e7a098c092524366990a9057efba1986 100644 (file)
@@ -69,13 +69,10 @@ void Texture3D::allocate(unsigned level)
                allocated |= (1<<levels)-1;
        }
        else
-       {
-               PixelFormat base_fmt = get_base_pixelformat(ifmt);
-               image(level, base_fmt, get_alloc_type(base_fmt), 0);
-       }
+               image(level, get_components(ifmt), get_component_type(ifmt), 0);
 }
 
-void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void *data)
+void Texture3D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
 {
        if(width==0 || height==0 || depth==0)
                throw invalid_operation("Texture3D::image");
@@ -86,7 +83,7 @@ void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void
        get_level_size(level, w, h, d);
 
        if(ARB_texture_storage)
-               return sub_image(level, 0, 0, 0, w, h, d, fmt, type, data);
+               return sub_image(level, 0, 0, 0, w, h, d, comp, type, data);
 
        BindRestore _bind(this);
 
@@ -95,7 +92,7 @@ void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void
                glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
                apply_swizzle();
        }
-       glTexImage3D(target, level, ifmt, width, height, depth, 0, get_upload_format(fmt), type, data);
+       glTexImage3D(target, level, ifmt, width, height, depth, 0, get_upload_components(comp), type, data);
 
        allocated |= 1<<level;
        if(auto_gen_mipmap && level==0)
@@ -105,7 +102,7 @@ void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void
        }
 }
 
-void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, PixelFormat fmt, DataType type, const void *data)
+void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, PixelComponents comp, DataType type, const void *data)
 {
        if(width==0 || height==0 || depth==0)
                throw invalid_operation("Texture3D::image");
@@ -113,11 +110,11 @@ void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsi
        Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
        allocate(level);
 
-       fmt = get_upload_format(fmt);
+       comp = get_upload_components(comp);
        if(ARB_direct_state_access)
-               glTextureSubImage3D(id, level, x, y, z, wd, ht, dp, fmt, type, data);
+               glTextureSubImage3D(id, level, x, y, z, wd, ht, dp, comp, type, data);
        else
-               glTexSubImage3D(target, level, x, y, z, wd, ht, dp, fmt, type, data);
+               glTexSubImage3D(target, level, x, y, z, wd, ht, dp, comp, type, data);
 
        if(auto_gen_mipmap && level==0)
                generate_mipmap();
@@ -144,16 +141,18 @@ void Texture3D::image(const Graphics::Image &img, unsigned lv, bool srgb)
                h = w;
        }
 
-       PixelFormat fmt = pixelformat_from_graphics(img.get_format());
+       PixelFormat fmt = pixelformat_from_image(img);
+       PixelComponents comp = get_components(fmt);
+       DataType type = get_component_type(fmt);
        if(width==0)
-               storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h, d, lv);
+               storage(make_pixelformat(comp, type, srgb), w, h, d, lv);
        else if(w!=width || h!=height || d!=depth)
                throw incompatible_data("Texture3D::load_image");
 
        PixelStore pstore = PixelStore::from_image(img);
        BindRestore _bind_ps(pstore);
 
-       image(0, fmt, UNSIGNED_BYTE, img.get_data());
+       image(0, comp, type, img.get_data());
 }
 
 unsigned Texture3D::get_n_levels() const
@@ -208,7 +207,7 @@ void Texture3D::Loader::init()
 
 void Texture3D::Loader::raw_data(const string &data)
 {
-       obj.image(0, get_base_pixelformat(obj.ifmt), UNSIGNED_BYTE, data.data());
+       obj.image(0, get_components(obj.ifmt), get_component_type(obj.ifmt), data.data());
 }
 
 void Texture3D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h, unsigned d)
index 0808471624db87d3f64d00ed5481171457bd9068..ecdff9d6c90549ae7e958e815e67e8493a4b050c 100644 (file)
@@ -46,6 +46,9 @@ public:
        it can't be changed. */
        void storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp, unsigned lv = 0);
 
+       DEPRECATED void storage(PixelComponents c, unsigned w, unsigned h, unsigned d, unsigned l = 0)
+       { storage(make_pixelformat(c, UNSIGNED_BYTE), w, h, d, l); }
+
        /** Allocates storage for the texture.  The contents are initially
        undefined.  If storage has already been allocated, does nothing. */
        void allocate(unsigned level);
@@ -53,14 +56,14 @@ public:
        /** Uploads an image to the texture.  Storage must be defined beforehand.
        The image data must have dimensions and format compatible with the defined
        storage. */
-       void image(unsigned level, PixelFormat fmt, DataType type, const void *data);
+       void image(unsigned level, PixelComponents, DataType type, const void *data);
 
        /** Updates a cuboid-shaped region of the texture.  Storage must be defined
        and allocated beforehand.  The update region must be fully inside the
        texture. */
        void sub_image(unsigned level,
                int x, int y, int z, unsigned wd, unsigned ht, unsigned dp,
-               PixelFormat fmt, DataType type, const void *data);
+               PixelComponents comp, DataType type, const void *data);
 
        /** Uploads an image to the texture.  If storage has not been defined, it
        will be set to match the image.  In this case the image will be treated as
index 8d194c42028bb6a4c6eb56cf2e9c0cb9567eba71..b0887ca85b1e4fca0e88769da87e4621f0d3af54 100644 (file)
@@ -83,14 +83,14 @@ void TextureCube::allocate(unsigned level)
        }
        else
        {
-               PixelFormat base_fmt = get_base_pixelformat(ifmt);
-               DataType type = get_alloc_type(base_fmt);
+               PixelComponents comp = get_components(ifmt);
+               DataType type = get_component_type(ifmt);
                for(unsigned i=0; i<6; ++i)
-                       image(enumerate_faces(i), level, base_fmt, type, 0);
+                       image(enumerate_faces(i), level, comp, type, 0);
        }
 }
 
-void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, DataType type, const void *data)
+void TextureCube::image(TextureCubeFace face, unsigned level, PixelComponents comp, DataType type, const void *data)
 {
        if(size==0)
                throw invalid_operation("TextureCube::image");
@@ -100,7 +100,7 @@ void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, D
                throw out_of_range("TextureCube::image");
 
        if(ARB_texture_storage)
-               return sub_image(face, level, 0, 0, s, s, fmt, type, data);
+               return sub_image(face, level, 0, 0, s, s, comp, type, data);
 
        BindRestore _bind(this);
 
@@ -109,7 +109,7 @@ void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, D
                glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
                apply_swizzle();
        }
-       glTexImage2D(face, level, ifmt, s, s, 0, get_upload_format(fmt), type, data);
+       glTexImage2D(face, level, ifmt, s, s, 0, get_upload_components(comp), type, data);
 
        if(level==0)
        {
@@ -128,13 +128,13 @@ void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, D
        {
                for(unsigned i=0; i<6; ++i)
                        if(enumerate_faces(i)!=face)
-                               glTexImage2D(enumerate_faces(i), level, ifmt, s, s, 0, get_upload_format(fmt), type, 0);
+                               glTexImage2D(enumerate_faces(i), level, ifmt, s, s, 0, comp, type, 0);
 
                allocated |= 64<<level;
        }
 }
 
-void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y, unsigned wd, unsigned ht, PixelFormat fmt, DataType type, const void *data)
+void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y, unsigned wd, unsigned ht, PixelComponents comp, DataType type, const void *data)
 {
        if(size==0)
                throw invalid_operation("TextureCube::sub_image");
@@ -142,7 +142,7 @@ void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y,
        BindRestore _bind(this);
        allocate(level);
 
-       glTexSubImage2D(face, level, x, y, wd, ht, get_upload_format(fmt), type, data);
+       glTexSubImage2D(face, level, x, y, wd, ht, get_upload_components(comp), type, data);
 
        if(auto_gen_mipmap && level==0)
                generate_mipmap();
@@ -152,13 +152,13 @@ void TextureCube::image(TextureCubeFace face, const Graphics::Image &img, bool s
 {
        unsigned w = img.get_width();
        unsigned h = img.get_height();
-       PixelFormat fmt = pixelformat_from_graphics(img.get_format());
+       PixelFormat fmt = pixelformat_from_image(img);
        if(size==0)
        {
                if(w!=h)
                        throw incompatible_data("TextureCube::image");
 
-               storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w);
+               storage(make_pixelformat(get_components(fmt), get_component_type(fmt), srgb), w);
        }
        else if(w!=size || h!=size)
                throw incompatible_data("TextureCube::image");
@@ -166,7 +166,7 @@ void TextureCube::image(TextureCubeFace face, const Graphics::Image &img, bool s
        PixelStore pstore = PixelStore::from_image(img);
        BindRestore _bind_ps(pstore);
 
-       image(face, 0, fmt, UNSIGNED_BYTE, img.get_data());
+       image(face, 0, get_components(fmt), get_component_type(fmt), img.get_data());
 }
 
 void TextureCube::image(const Graphics::Image &img, unsigned lv, bool srgb)
@@ -178,9 +178,11 @@ void TextureCube::image(const Graphics::Image &img, unsigned lv, bool srgb)
                throw incompatible_data("TextureCube::image");
        h /= 6;
 
-       PixelFormat fmt = pixelformat_from_graphics(img.get_format());
+       PixelFormat fmt = pixelformat_from_image(img);
+       PixelComponents comp = get_components(fmt);
+       DataType type = get_component_type(fmt);
        if(size==0)
-               storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, lv);
+               storage(make_pixelformat(comp, type, srgb), w, lv);
        else if(w!=size || h!=size)
                throw incompatible_data("TextureCube::image");
 
@@ -190,7 +192,7 @@ void TextureCube::image(const Graphics::Image &img, unsigned lv, bool srgb)
        const char *cdata = reinterpret_cast<const char *>(img.get_data());
        unsigned face_size = img.get_stride()*size;
        for(unsigned i=0; i<6; ++i)
-               image(enumerate_faces(i), 0, fmt, UNSIGNED_BYTE, cdata+i*face_size);
+               image(enumerate_faces(i), 0, comp, type, cdata+i*face_size);
 }
 
 unsigned TextureCube::get_n_levels() const
@@ -298,7 +300,7 @@ void TextureCube::Loader::image_data(TextureCubeFace face, const string &data)
 
 void TextureCube::Loader::raw_data(TextureCubeFace face, const string &data)
 {
-       obj.image(face, 0, get_base_pixelformat(obj.ifmt), UNSIGNED_BYTE, data.data());
+       obj.image(face, 0, get_components(obj.ifmt), get_component_type(obj.ifmt), data.data());
 }
 
 void TextureCube::Loader::storage(PixelFormat fmt, unsigned s)
index 7659917dadec259a27281c8774679d85175aba68..f716098329cf09fc1a3a663c2de34501c5f25f16 100644 (file)
@@ -70,6 +70,9 @@ public:
        it can't be changed. */
        void storage(PixelFormat fmt, unsigned size, unsigned lv = 0);
 
+       DEPRECATED void storage(PixelComponents c, unsigned s, unsigned l = 0)
+       { storage(make_pixelformat(c, UNSIGNED_BYTE), s, l); }
+
        /** Allocates storage for the cube faces.  The contents are initially
        undefined.  If storage has already been allocated, does nothing. */
        void allocate(unsigned level);
@@ -78,14 +81,14 @@ public:
        image data must have dimensions and format compatible with the defined
        storage. */
        void image(TextureCubeFace face, unsigned level,
-               PixelFormat fmt, DataType type, const void *data);
+               PixelComponents comp, DataType type, const void *data);
 
        /** Updates a rectangular region of a face.  Storage must be defined and
        allocated beforehand.  The update region must be fully inside the texture.
        The data format must be compatible with the defined storage. */
        void sub_image(TextureCubeFace face, unsigned level,
                int x, int y, unsigned w, unsigned h,
-               PixelFormat fmt, DataType type, const void *data);
+               PixelComponents comp, DataType type, const void *data);
 
        void image(TextureCubeFace, const Graphics::Image &, bool = false);