1 #include "deviceinfo.h"
3 #include "frameformat.h"
11 FrameFormat::FrameFormat(FrameAttachment fa):
18 FrameFormat FrameFormat::operator,(FrameAttachment fa) const
20 if(count>=MAX_ATTACHMENTS)
21 throw invalid_operation("FrameFormat::operator,");
23 FrameFormat result = *this;
24 result.attachments[result.count++] = fa;
29 FrameFormat FrameFormat::operator,(PixelFormat pf) const
32 throw invalid_operation("FrameFormat::operator,");
34 FrameFormat r = *this;
35 FrameAttachment &fa = r.attachments[r.count-1];
36 fa = make_typed_attachment(fa, pf);
41 FrameFormat FrameFormat::operator,(unsigned index) const
44 throw invalid_operation("FrameFormat::operator,");
46 FrameFormat r = *this;
47 FrameAttachment &fa = r.attachments[r.count-1];
48 fa = make_indexed_attachment(fa, index);
53 FrameFormat &FrameFormat::set_samples(unsigned s)
59 int FrameFormat::index(FrameAttachment fa) const
61 for(unsigned i=0; i<count; ++i)
62 if(get_attach_point(attachments[i])==get_attach_point(fa))
68 FrameAttachment make_typed_attachment(FrameAttachment fa, PixelFormat pf)
70 PixelComponents comp = get_components(pf);
71 if(get_attach_point(fa)==get_attach_point(DEPTH_ATTACHMENT))
73 if(comp!=DEPTH_COMPONENT)
74 throw invalid_argument("make_typed_attachment");
76 else if(get_attach_point(fa)==get_attach_point(STENCIL_ATTACHMENT))
78 if(comp!=STENCIL_INDEX)
79 throw invalid_argument("make_typed_attachment");
83 if(comp!=RED && comp!=RG && comp!=RGB && comp!=RGBA)
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 | 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);
115 type = static_cast<DataType>((fa&0x70)>>4 | 0x300);
117 type = static_cast<DataType>((fa&0x70)>>4);
119 return make_pixelformat(comp, type);