2 #include "frameformat.h"
9 FrameFormat::FrameFormat(FrameAttachment fa):
16 FrameFormat FrameFormat::operator,(FrameAttachment fa) const
18 if(count>=MAX_ATTACHMENTS)
19 throw invalid_operation("FrameFormat::operator,");
21 FrameFormat result = *this;
22 result.attachments[result.count++] = fa;
27 FrameFormat FrameFormat::operator,(PixelFormat pf) const
30 throw invalid_operation("FrameFormat::operator,");
32 FrameFormat r = *this;
33 FrameAttachment &fa = r.attachments[r.count-1];
34 fa = make_typed_attachment(fa, pf);
39 FrameFormat FrameFormat::operator,(unsigned index) const
42 throw invalid_operation("FrameFormat::operator,");
44 FrameFormat r = *this;
45 FrameAttachment &fa = r.attachments[r.count-1];
46 fa = make_indexed_attachment(fa, index);
51 FrameFormat &FrameFormat::set_samples(unsigned s)
57 int FrameFormat::index(FrameAttachment fa) const
59 for(unsigned i=0; i<count; ++i)
60 if(get_attach_point(attachments[i])==get_attach_point(fa))
66 FrameAttachment make_typed_attachment(FrameAttachment fa, PixelFormat pf)
68 PixelComponents comp = get_components(pf);
69 if(get_attach_point(fa)==get_attach_point(DEPTH_ATTACHMENT))
71 if(comp!=DEPTH_COMPONENT)
72 throw invalid_argument("make_typed_attachment");
74 else if(get_attach_point(fa)==get_attach_point(STENCIL_ATTACHMENT))
76 if(comp!=STENCIL_INDEX)
77 throw invalid_argument("make_typed_attachment");
81 if(comp!=RED && comp!=RG && comp!=RGB && comp!=RGBA && comp!=BGR && comp!=BGRA)
82 throw invalid_argument("make_typed_attachment");
83 if(get_required_swizzle(comp))
84 throw invalid_argument("make_typed_attachment");
87 DataType type = get_component_type(pf);
88 return static_cast<FrameAttachment>((fa&0xFC00) | (is_float(type)*0x100) | get_type_size(type)<<4 | ((comp&0x20)>>2) | get_component_count(comp));
91 FrameAttachment make_indexed_attachment(FrameAttachment fa, unsigned i)
93 if(get_attach_point(fa)==get_attach_point(COLOR_ATTACHMENT))
96 throw out_of_range("make_indexed_attachment");
97 return static_cast<FrameAttachment>(fa+(i<<10));
100 throw invalid_argument("make_indexed_attachment");
103 PixelFormat get_attachment_pixelformat(FrameAttachment fa)
105 PixelComponents comp;
106 if(get_attach_point(fa)==get_attach_point(DEPTH_ATTACHMENT))
107 comp = DEPTH_COMPONENT;
108 else if(get_attach_point(fa)==get_attach_point(STENCIL_ATTACHMENT))
109 comp = STENCIL_INDEX;
111 comp = static_cast<PixelComponents>((fa&7) | (fa&8)<<2);
115 type = static_cast<DataType>((fa&0x70)>>4 | 0x300);
117 type = static_cast<DataType>((fa&0x70)>>4);
119 return make_pixelformat(comp, type);