-RenderTargetFormat::RenderTargetFormat():
- count(0)
-{ }
-
-RenderTargetFormat::RenderTargetFormat(RenderOutput o):
- count(1)
-{
- outputs[0] = o;
-}
-
-RenderTargetFormat RenderTargetFormat::operator,(RenderOutput o) const
-{
- if(count>=MAX_OUTPUTS)
- throw invalid_operation("RenderTargetFormat::operator,");
-
- RenderTargetFormat result = *this;
- result.outputs[result.count++] = o;
-
- return result;
-}
-
-RenderTargetFormat RenderTargetFormat::operator,(PixelFormat f) const
-{
- if(!count)
- throw invalid_operation("RenderTargetFormat::operator,");
-
- PixelComponents comp = get_components(f);
- DataType type = get_component_type(f);
- unsigned size = 0;
- unsigned char out = outputs[count-1];
- if(get_output_type(out)>=get_output_type(RENDER_DEPTH))
- {
- if(comp!=DEPTH_COMPONENT)
- throw invalid_argument("RenderTargetFormat::operator,");
- switch(type)
- {
- case UNSIGNED_SHORT: size = 0; break;
- case UNSIGNED_INT: size = 2; break;
- case FLOAT: size = 3; break;
- default: throw invalid_argument("RenderTargetFormat::operator,");
- }
- }
- else
- {
- if(comp!=RED && comp!=RG && comp!=RGB && comp!=RGBA)
- throw invalid_argument("RenderTargetformat::operator,");
- switch(type)
- {
- case UNSIGNED_BYTE: size = 0; break;
- case HALF_FLOAT: size = 2; break;
- case FLOAT: size = 3; break;
- default: throw invalid_argument("RenderTargetFormat::operator,");
- }
- }
-
- out = (out&~15) | (size<<2) | (get_component_count(f)-1);
- RenderTargetFormat result = *this;
- result.outputs[result.count-1] = out;
-
- return result;
-}
-
-int RenderTargetFormat::index(RenderOutput o) const
-{
- unsigned type = get_output_type(o);
- unsigned i = 0;
- for(const unsigned char *j=begin(); j!=end(); ++j, ++i)
- if(get_output_type(*j)==type)
- return i;
- return -1;
-}
-
-
-PixelFormat get_output_pixelformat(unsigned char o)
-{
- PixelComponents comp;
- DataType type;
- if(get_output_type(o)>=get_output_type(RENDER_DEPTH))
- {
- static DataType types[4] = { UNSIGNED_SHORT, UNSIGNED_SHORT, UNSIGNED_INT, FLOAT };
- comp = DEPTH_COMPONENT;
- type = types[(o>>2)&3];
- }
- else
- {
- static PixelComponents components[4] = { RED, RG, RGB, RGBA };
- static DataType types[4] = { UNSIGNED_BYTE, UNSIGNED_SHORT, HALF_FLOAT, FLOAT };
- comp = components[o&3];
- type = types[(o>>2)&3];
- }
-
- return make_pixelformat(comp, type);
-}
-
-
-RenderTarget::RenderTarget(unsigned w, unsigned h, RenderOutput o)
-{
- init(w, h, 0, o);
-}
-
-RenderTarget::RenderTarget(unsigned w, unsigned h, const RenderTargetFormat &f)