#include "AbstractRender.h"

AbstractRender::AbstractRender( Context& context): context( context )
{
}
AbstractRender::~AbstractRender(void)
{
}

void AbstractRender::beginFrame(void)
{
	this->bind();
	this->clearDepthbuffer();
	this->clearFramebuffer();
}

void AbstractRender::swapBuffer(void)
{
	this->context.swapBuffer();
}
void AbstractRender::endFrame(bool swapBuffer)
{
	this->context.makeCurrent();
	glFlush();

	if (swapBuffer==true)
	{
		this->swapBuffer();
	}

	this->context.doneCurrent();
}


void AbstractRender::bind(void)
{
	//POZOR tato metoda se nesmi odkazovat na nic co muze byt virtualni jinak hrozi zacykleni kvuli volani virtualnich funkci v kruhu!!!
	this->context.makeCurrent();
	glViewport( this->viewport.fromX, this->viewport.fromY, this->viewport.sizeX, this->viewport.sizeY );
}
void AbstractRender::clearFramebuffer(void)
{
	this->context.makeCurrent();
	glClear( GL_COLOR_BUFFER_BIT );
}
void AbstractRender::clearDepthbuffer(void)
{
	this->context.makeCurrent();
	glClear( GL_DEPTH_BUFFER_BIT );
}

void AbstractRender::setViewport(unsigned int fromX, unsigned int fromY, unsigned int sizeX, unsigned int sizeY)
{
	this->viewport.fromX=fromX;
	this->viewport.fromY=fromY;
	this->viewport.sizeX=sizeX;
	this->viewport.sizeY=sizeY;
}