]> git.tdb.fi Git - libs/gl.git/blobdiff - source/rendertarget.cpp
Remove the deprecated ProgramBuilder class
[libs/gl.git] / source / rendertarget.cpp
index 8a53e66d2bac06b7adead7bebac9c7d3104f26ef..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;
@@ -72,29 +74,31 @@ int RenderTargetFormat::index(RenderOutput o) const
 
 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);
@@ -160,7 +165,7 @@ void RenderTarget::set_texture_filter(TextureFilter filt)
        if(!samples)
        {
                for(vector<TargetBuffer>::iterator i=buffers.begin(); i!=buffers.end(); ++i)
-                       i->texture->set_filter(filt);
+                       i->texture->get_default_sampler().set_filter(filt);
        }
 }