X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Frendertarget.cpp;h=1349944b862ff969f6347d5ca070696bb597f09b;hp=239180f5e52b9032807a6a9943ecf468e736bc18;hb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;hpb=c44c350892a4955c7457abe1cbb81bbf0a22a86c diff --git a/source/rendertarget.cpp b/source/rendertarget.cpp index 239180f5..1349944b 100644 --- a/source/rendertarget.cpp +++ b/source/rendertarget.cpp @@ -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,29 +74,31 @@ 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); } +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); @@ -134,8 +138,9 @@ void RenderTarget::init(unsigned w, unsigned h, unsigned s, const RenderTargetFo { tgt.texture = new Texture2D; tgt.texture->storage(pf, width, height, 1); - tgt.texture->set_filter(NEAREST); - tgt.texture->set_wrap(CLAMP_TO_EDGE); + 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::iterator i=buffers.begin(); i!=buffers.end(); ++i) - i->texture->set_filter(filt); + i->texture->get_default_sampler().set_filter(filt); } }