X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frendertarget.cpp;h=74b4f32214e0bfe33ca54935b45d6d749a628de7;hb=78840e775c62c1b6e3f550bf8be1f0b828df91aa;hp=f575670ad3e581b574f89dfc41522385f5095b36;hpb=5f7d0a31de9ffe891af6eb43aeb6d37372b8ade7;p=libs%2Fgl.git diff --git a/source/rendertarget.cpp b/source/rendertarget.cpp index f575670a..74b4f322 100644 --- a/source/rendertarget.cpp +++ b/source/rendertarget.cpp @@ -46,7 +46,7 @@ RenderTargetFormat RenderTargetFormat::operator,(PixelFormat f) const } else { - if(unsized!=RGB && unsized!=RGBA) + if(unsized!=RED && unsized!=RG && unsized!=RGB && unsized!=RGBA) throw invalid_argument("RenderTargetformat::operator,"); if(size>3) --size; @@ -72,7 +72,6 @@ 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; if(get_output_type(o)>=get_output_type(RENDER_DEPTH)) @@ -83,7 +82,8 @@ PixelFormat get_output_pixelformat(unsigned char o) } else { - base = (ncomp==4 ? RGBA : RGB); + static PixelFormat base_formats[4] = { RED, RG, RGB, RGBA }; + base = base_formats[o&3]; if(size==3) ++size; } @@ -95,6 +95,11 @@ PixelFormat get_output_pixelformat(unsigned char o) } +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 +138,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,6 +161,15 @@ RenderTarget::~RenderTarget() } } +void RenderTarget::set_texture_filter(TextureFilter filt) +{ + if(!samples) + { + for(vector::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())