2 #include "frameformat.h"
10 FrameFormat::FrameFormat(FrameAttachment fa):
17 FrameFormat FrameFormat::operator,(FrameAttachment fa) const
19 if(count>=MAX_ATTACHMENTS)
20 throw invalid_operation("FrameFormat::operator,");
22 FrameFormat result = *this;
23 result.attachments[result.count++] = fa;
28 FrameFormat FrameFormat::operator,(PixelFormat pf) const
31 throw invalid_operation("FrameFormat::operator,");
33 FrameFormat r = *this;
34 FrameAttachment &fa = r.attachments[r.count-1];
35 fa = make_typed_attachment(fa, pf);
40 FrameFormat FrameFormat::operator,(unsigned index) const
43 throw invalid_operation("FrameFormat::operator,");
45 FrameFormat r = *this;
46 FrameAttachment &fa = r.attachments[r.count-1];
47 fa = make_indexed_attachment(fa, index);
52 FrameFormat &FrameFormat::set_samples(unsigned s)
58 int FrameFormat::index(FrameAttachment fa) const
60 for(unsigned i=0; i<count; ++i)
61 if(get_attach_point(attachments[i])==get_attach_point(fa))
67 FrameAttachment make_typed_attachment(FrameAttachment fa, PixelFormat pf)
69 PixelComponents comp = get_components(pf);
70 if(get_attach_point(fa)==get_attach_point(DEPTH_ATTACHMENT))
72 if(comp!=DEPTH_COMPONENT)
73 throw invalid_argument("make_typed_attachment");
75 else if(get_attach_point(fa)==get_attach_point(STENCIL_ATTACHMENT))
77 if(comp!=STENCIL_INDEX)
78 throw invalid_argument("make_typed_attachment");
82 if(comp!=RED && comp!=RG && comp!=RGB && comp!=RGBA)
83 throw invalid_argument("make_typed_attachment");
86 DataType type = get_component_type(pf);
87 return static_cast<FrameAttachment>((fa&0xFC00) | (is_float(type)*0x100) | get_type_size(type)<<4 | get_component_count(comp));
90 FrameAttachment make_indexed_attachment(FrameAttachment fa, unsigned i)
92 if(get_attach_point(fa)==get_attach_point(COLOR_ATTACHMENT))
95 throw out_of_range("make_indexed_attachment");
96 return static_cast<FrameAttachment>(fa+(i<<10));
99 throw invalid_argument("make_indexed_attachment");
102 PixelFormat get_attachment_pixelformat(FrameAttachment fa)
104 PixelComponents comp;
105 if(get_attach_point(fa)==get_attach_point(DEPTH_ATTACHMENT))
106 comp = DEPTH_COMPONENT;
107 else if(get_attach_point(fa)==get_attach_point(STENCIL_ATTACHMENT))
108 comp = STENCIL_INDEX;
110 comp = static_cast<PixelComponents>(fa&7);
114 type = static_cast<DataType>((fa&0x70)>>4 | 0x300);
116 type = static_cast<DataType>((fa&0x70)>>4);
118 return make_pixelformat(comp, type);