#ifndef RENDERTOTEXTURE_H
#define RENDERTOTEXTURE_H

#include "./../../lib/GLee/GLee.h"	



template <typename T> void renderToTexture(unsigned int textureId,unsigned int textureSize, T& renderFunctor )
{
	int viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport); //GL_MAX_VIEWPORT_DIMS mozna se ma volat s timto parametrem
	glViewport(0, 0, textureSize, textureSize);// Nastavení viewportu (odpovídá velikosti textury)
		
		renderFunctor();
	
	glBindTexture(GL_TEXTURE_2D, textureId);// Zvolí texturu
	glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
	glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);// Obnovení viewportu
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Smaže obrazovku a hloubkový buffer
}



#endif