/*
    QGL FramebufferMipmap
    Ivan Pelipenko peri4ko@yandex.ru

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef GLFRAMEBUFFER_MIPMAP_H
#define GLFRAMEBUFFER_MIPMAP_H

#include "glframebuffer.h"


class QGLENGINE_CORE_EXPORT FramebufferMipmap {
public:
	FramebufferMipmap(const Framebuffer & fb, int index_from_, int levels = 2);
	virtual ~FramebufferMipmap();

	int levelsCount() const { return fbo.size(); }
	int lastLevel() const { return fbo.size() - 1; }
	Framebuffer & plane(int level) { return *fbo[level]; }
	Framebuffer & lastPlane() { return *fbo[lastLevel()]; }
	int width(int level) const { return fbo[level]->wid; }
	int height(int level) const { return fbo[level]->hei; }
	QSize size(int level) const { return fbo[level]->size(); }
	QRect rect(int level) const { return fbo[level]->rect(); }
	void setIndexFrom(int index);

	void resize();
	void create();
	void reinit();

private:
	int index_from;
	const Framebuffer & src_fb;
	QVector<Framebuffer *> fbo;
};

#endif // GLFRAMEBUFFER_MIPMAP_H
