]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/rendertarget.cpp
Remove default sampler from Texture
[libs/gl.git] / source / render / rendertarget.cpp
index 1349944b862ff969f6347d5ca070696bb597f09b..7bdac6703e3554e60162a90839139c1f4efba4f3 100644 (file)
@@ -1,4 +1,5 @@
 #include <msp/core/maputils.h>
+#include <msp/strings/format.h>
 #include "error.h"
 #include "renderbuffer.h"
 #include "rendertarget.h"
@@ -35,23 +36,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);
@@ -138,9 +148,6 @@ void RenderTarget::init(unsigned w, unsigned h, unsigned s, const RenderTargetFo
                {
                        tgt.texture = new Texture2D;
                        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,15 +167,6 @@ RenderTarget::~RenderTarget()
        }
 }
 
-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())
@@ -193,5 +191,30 @@ void RenderTarget::blit_from(const RenderTarget &other)
        fbo.blit_from(other.fbo, COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT, false);
 }
 
+void RenderTarget::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       fbo.set_debug_name(name+" [FBO]");
+       unsigned i = 0;
+       for(const unsigned char *j=format.begin(); j!=format.end(); ++i, ++j)
+       {
+               unsigned type = get_output_type(*j);
+
+               string buf_name;
+               if(type>=get_output_type(RENDER_DEPTH))
+                       buf_name = name+"/depth";
+               else
+                       buf_name = Msp::format("%s/color%d", name, type);
+
+               if(samples)
+                       buffers[i].buffer->set_debug_name(buf_name+".tex2d");
+               else
+                       buffers[i].texture->set_debug_name(buf_name+".rbuf");
+       }
+#else
+       (void)name;
+#endif
+}
+
 } // namespace GL
 } // namespace Msp