]> git.tdb.fi Git - libs/gl.git/blobdiff - source/rendertarget.cpp
Remove the deprecated ProgramBuilder class
[libs/gl.git] / source / rendertarget.cpp
index 376af04877a4b324dd53518203b489c662b034c2..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!=RGB && unsized!=RGBA)
+               if(comp!=RED && comp!=RG && comp!=RGB && comp!=RGBA)
                        throw invalid_argument("RenderTargetformat::operator,");
                if(size>3)
                        --size;
@@ -59,7 +61,7 @@ RenderTargetFormat RenderTargetFormat::operator,(PixelFormat f) const
        return result;
 }
 
-int RenderTargetFormat::index(RenderOutput o)
+int RenderTargetFormat::index(RenderOutput o) const
 {
        unsigned type = get_output_type(o);
        unsigned i = 0;
@@ -72,29 +74,31 @@ int RenderTargetFormat::index(RenderOutput o)
 
 PixelFormat get_output_pixelformat(unsigned char o)
 {
-       unsigned ncomp = (o&3)+1;
-       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
        {
-               base = (ncomp==4 ? RGBA : RGB);
-               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);
 }
 
 
+RenderTarget::RenderTarget(unsigned w, unsigned h, RenderOutput o)
+{
+       init(w, h, 0, o);
+}
+
 RenderTarget::RenderTarget(unsigned w, unsigned h, const RenderTargetFormat &f)
 {
        init(w, h, 0, f);
@@ -133,9 +137,10 @@ void RenderTarget::init(unsigned w, unsigned h, unsigned s, const RenderTargetFo
                else
                {
                        tgt.texture = new Texture2D;
-                       tgt.texture->storage(pf, width, height);
-                       tgt.texture->set_filter(NEAREST);
-                       tgt.texture->set_wrap(CLAMP_TO_EDGE);
+                       tgt.texture->storage(pf, width, height, 1);
+                       Sampler &sampler = tgt.texture->get_default_sampler();
+                       sampler.set_filter(NEAREST);
+                       sampler.set_wrap(CLAMP_TO_EDGE);
                        fbo.attach(att, *tgt.texture);
                }
                buffers.push_back(tgt);
@@ -155,7 +160,16 @@ RenderTarget::~RenderTarget()
        }
 }
 
-const Texture2D &RenderTarget::get_target_texture(unsigned i)
+void RenderTarget::set_texture_filter(TextureFilter filt)
+{
+       if(!samples)
+       {
+               for(vector<TargetBuffer>::iterator i=buffers.begin(); i!=buffers.end(); ++i)
+                       i->texture->get_default_sampler().set_filter(filt);
+       }
+}
+
+const Texture2D &RenderTarget::get_target_texture(unsigned i) const
 {
        if(i>=buffers.size())
                throw out_of_range("RenderTarget::get_target_texture");
@@ -165,7 +179,7 @@ const Texture2D &RenderTarget::get_target_texture(unsigned i)
        return *buffers[i].texture;
 }
 
-const Texture2D &RenderTarget::get_target_texture(RenderOutput o)
+const Texture2D &RenderTarget::get_target_texture(RenderOutput o) const
 {
        int index = format.index(o);
        if(index<0)