if(id)
throw invalid_argument("System framebuffer must have id 0");
- int viewport[4];
- glGetIntegerv(GL_VIEWPORT, viewport);
- width = viewport[2];
- height = viewport[3];
+ glGetIntegerv(GL_VIEWPORT, &view.left);
+ width = view.width;
+ height = view.height;
}
Framebuffer::Framebuffer():
void Framebuffer::check_size()
{
+ bool full_viewport = (view.left==0 && view.bottom==0 && view.width==width && view.height==height);
for(vector<Attachment>::iterator i=attachments.begin(); i!=attachments.end(); ++i)
if(i->type)
{
width = static_cast<TextureCube *>(i->tex)->get_size();
height = width;
}
- if(current()==this)
- glViewport(0, 0, width, height);
+ if(full_viewport)
+ reset_viewport();
break;
}
}
throw framebuffer_incomplete(status);
}
+void Framebuffer::viewport(int l, int b, unsigned w, unsigned h)
+{
+ view.left = l;
+ view.bottom = b;
+ view.width = w;
+ view.height = h;
+
+ if(current()==this)
+ glViewport(view.left, view.bottom, view.width, view.height);
+}
+
+void Framebuffer::reset_viewport()
+{
+ viewport(0, 0, width, height);
+}
+
void Framebuffer::clear(BufferBits bits)
{
BindRestore _bind(this);
update_attachment(dirty);
dirty = 0;
}
+
if(width && height)
- glViewport(0, 0, width, height);
+ glViewport(view.left, view.bottom, view.width, view.height);
}
}
type = 0;
}
+
+Framebuffer::Viewport::Viewport():
+ left(0),
+ bottom(0),
+ width(0),
+ height(0)
+{ }
+
} // namespace GL
} // namespace Msp
void clear();
};
+ struct Viewport
+ {
+ int left;
+ int bottom;
+ unsigned width;
+ unsigned height;
+
+ Viewport();
+ };
+
unsigned id;
std::vector<Attachment> attachments;
unsigned width;
unsigned height;
+ Viewport view;
mutable unsigned dirty;
Framebuffer(unsigned);
isn't. */
void require_complete() const;
+ void viewport(int, int, unsigned, unsigned);
+ void reset_viewport();
+
void clear(BufferBits);
/** Blits a region from another framebuffer into this one. If the source