-
-PixelFormat get_output_pixelformat(unsigned char o)
-{
- PixelComponents comp;
- DataType type;
- if(get_output_type(o)>=get_output_type(RENDER_DEPTH))
- {
- static DataType types[4] = { UNSIGNED_SHORT, UNSIGNED_SHORT, UNSIGNED_INT, FLOAT };
- comp = DEPTH_COMPONENT;
- type = types[(o>>2)&3];
- }
- else
- {
- 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];
- }
-
- 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);
-}
-
-RenderTarget::RenderTarget(unsigned w, unsigned h, unsigned s, const RenderTargetFormat &f)
-{
- init(w, h, s, f);
-}
-
-void RenderTarget::init(unsigned w, unsigned h, unsigned s, const RenderTargetFormat &f)
-{
- width = w;
- height = h;
- samples = s;
- format = f;
-
- for(const unsigned char *i=format.begin(); i!=format.end(); ++i)
- {
- unsigned type = get_output_type(*i);
- FramebufferAttachment att;
- if(type>=get_output_type(RENDER_DEPTH))
- att = DEPTH_ATTACHMENT;
- else
- att = static_cast<FramebufferAttachment>(COLOR_ATTACHMENT0+type);
-
- PixelFormat pf = get_output_pixelformat(*i);
-
- TargetBuffer tgt;
- if(samples)