1 #include "deviceinfo.h"
3 #include "frameformat.h"
11 FrameFormat::FrameFormat():
16 FrameFormat::FrameFormat(FrameAttachment fa):
23 FrameFormat FrameFormat::operator,(FrameAttachment fa) const
25 if(count>=MAX_ATTACHMENTS)
26 throw invalid_operation("FrameFormat::operator,");
28 FrameFormat result = *this;
29 result.attachments[result.count++] = fa;
34 FrameFormat FrameFormat::operator,(PixelFormat pf) const
37 throw invalid_operation("FrameFormat::operator,");
39 FrameFormat r = *this;
40 FrameAttachment &fa = r.attachments[r.count-1];
41 fa = make_typed_attachment(fa, pf);
46 FrameFormat FrameFormat::operator,(unsigned index) const
49 throw invalid_operation("FrameFormat::operator,");
51 FrameFormat r = *this;
52 FrameAttachment &fa = r.attachments[r.count-1];
53 fa = make_indexed_attachment(fa, index);
58 FrameFormat &FrameFormat::set_samples(unsigned s)
64 int FrameFormat::index(FrameAttachment fa) const
66 for(unsigned i=0; i<count; ++i)
67 if(get_attach_point(attachments[i])==get_attach_point(fa))
73 FrameAttachment make_typed_attachment(FrameAttachment fa, PixelFormat pf)
75 PixelComponents comp = get_components(pf);
76 if(get_attach_point(fa)==get_attach_point(DEPTH_ATTACHMENT))
78 if(comp!=DEPTH_COMPONENT)
79 throw invalid_argument("make_typed_attachment");
81 else if(get_attach_point(fa)==get_attach_point(STENCIL_ATTACHMENT))
83 if(comp!=STENCIL_INDEX)
84 throw invalid_argument("make_typed_attachment");
88 if(comp!=RED && comp!=RG && comp!=RGB && comp!=RGBA)
89 throw invalid_argument("make_typed_attachment");
92 DataType type = get_component_type(pf);
93 return static_cast<FrameAttachment>((fa&0xFC00) | (is_float(type)*0x100) | get_type_size(type)<<4 | get_component_count(comp));
96 FrameAttachment make_indexed_attachment(FrameAttachment fa, unsigned i)
98 if(get_attach_point(fa)==get_attach_point(COLOR_ATTACHMENT))
101 throw out_of_range("make_indexed_attachment");
102 return static_cast<FrameAttachment>(fa+(i<<10));
105 throw invalid_argument("make_indexed_attachment");
108 PixelFormat get_attachment_pixelformat(FrameAttachment fa)
110 PixelComponents comp;
111 if(get_attach_point(fa)==get_attach_point(DEPTH_ATTACHMENT))
112 comp = DEPTH_COMPONENT;
113 else if(get_attach_point(fa)==get_attach_point(STENCIL_ATTACHMENT))
114 comp = STENCIL_INDEX;
116 comp = static_cast<PixelComponents>(fa&7);
120 type = static_cast<DataType>((fa&0x70)>>4 | 0x300);
122 type = static_cast<DataType>((fa&0x70)>>4);
124 return make_pixelformat(comp, type);
127 unsigned get_gl_attachment(FrameAttachment fa)
129 if(get_attach_point(fa)==get_attach_point(DEPTH_ATTACHMENT))
130 return GL_DEPTH_ATTACHMENT;
131 else if(get_attach_point(fa)==get_attach_point(STENCIL_ATTACHMENT))
132 return GL_STENCIL_ATTACHMENT;
134 return GL_COLOR_ATTACHMENT0+get_attach_point(fa);
137 unsigned get_gl_buffer_bits(const FrameFormat &format)
140 for(FrameAttachment a: format)
142 if(get_attach_point(a)==get_attach_point(DEPTH_ATTACHMENT))
143 bits |= GL_DEPTH_BUFFER_BIT;
144 else if(get_attach_point(a)==get_attach_point(STENCIL_ATTACHMENT))
145 bits |= GL_STENCIL_BUFFER_BIT;
147 bits |= GL_COLOR_BUFFER_BIT;