1 #include "deviceinfo.h"
3 #include "frameformat.h"
10 FrameFormat::FrameFormat():
15 FrameFormat::FrameFormat(FrameAttachment fa):
22 FrameFormat FrameFormat::operator,(FrameAttachment fa) const
24 if(count>=MAX_ATTACHMENTS)
25 throw invalid_operation("FrameFormat::operator,");
27 FrameFormat result = *this;
28 result.attachments[result.count++] = fa;
33 FrameFormat FrameFormat::operator,(PixelFormat pf) const
36 throw invalid_operation("FrameFormat::operator,");
38 FrameFormat r = *this;
39 UInt16 &fa = r.attachments[r.count-1];
40 fa = make_typed_attachment(static_cast<FrameAttachment>(fa), pf);
45 FrameFormat FrameFormat::operator,(unsigned index) const
48 throw invalid_operation("FrameFormat::operator,");
50 FrameFormat r = *this;
51 UInt16 &fa = r.attachments[r.count-1];
52 fa = make_indexed_attachment(static_cast<FrameAttachment>(fa), index);
57 FrameFormat &FrameFormat::set_samples(unsigned s)
63 int FrameFormat::index(FrameAttachment fa) const
65 for(unsigned i=0; i<count; ++i)
66 if(get_attach_point(attachments[i])==get_attach_point(fa))
72 FrameAttachment make_typed_attachment(FrameAttachment fa, PixelFormat pf)
74 PixelComponents comp = get_components(pf);
75 if(get_attach_point(fa)==get_attach_point(DEPTH_ATTACHMENT))
77 if(comp!=DEPTH_COMPONENT)
78 throw invalid_argument("make_typed_attachment");
80 else if(get_attach_point(fa)==get_attach_point(STENCIL_ATTACHMENT))
82 if(comp!=STENCIL_INDEX)
83 throw invalid_argument("make_typed_attachment");
87 if(comp!=RED && comp!=RG && comp!=RGB && comp!=RGBA)
88 throw invalid_argument("make_typed_attachment");
91 DataType type = get_component_type(pf);
92 return static_cast<FrameAttachment>((fa&0xFC00) | (is_float(type)*0x100) | get_type_size(type)<<4 | get_component_count(comp));
95 FrameAttachment make_indexed_attachment(FrameAttachment fa, unsigned i)
97 if(get_attach_point(fa)==get_attach_point(COLOR_ATTACHMENT))
100 throw out_of_range("make_indexed_attachment");
101 return static_cast<FrameAttachment>(fa+(i<<10));
104 throw invalid_argument("make_indexed_attachment");
107 PixelFormat get_attachment_pixelformat(UInt16 fa)
109 PixelComponents comp;
110 if(get_attach_point(fa)==get_attach_point(DEPTH_ATTACHMENT))
111 comp = DEPTH_COMPONENT;
112 else if(get_attach_point(fa)==get_attach_point(STENCIL_ATTACHMENT))
113 comp = STENCIL_INDEX;
115 comp = static_cast<PixelComponents>(fa&7);
119 type = static_cast<DataType>((fa&0x70)>>4 | 0x300);
121 type = static_cast<DataType>((fa&0x70)>>4);
123 return make_pixelformat(comp, type);
126 GLenum get_gl_attachment(FrameAttachment fa)
128 if(get_attach_point(fa)==get_attach_point(DEPTH_ATTACHMENT))
129 return GL_DEPTH_ATTACHMENT;
130 else if(get_attach_point(fa)==get_attach_point(STENCIL_ATTACHMENT))
131 return GL_STENCIL_ATTACHMENT;
133 return GL_COLOR_ATTACHMENT0+get_attach_point(fa);