#pragma once
#include "effect.h"
#include "ER_Framework/FBO.h"
#include "ER_Framework/Texture.h"
#include "ER_Framework/TextureLoader.h"

class SSAO : public Effect
{
public:
	SSAO(void);
	~SSAO(void);

	void initSSAO(int resX, int resY);

	void setClippingPlane(float nearPlane, float farPlane);

	void BeginRenderToGBuffer();
	void EndRenderToGBuffer();
	void renderSSAOToGBuffer2();

	void saveMatrix();
	void showOnlySSAO(bool how){_onlySSAO = how;};
	bool isOnlySSAO(){ return _onlySSAO;}

	void activate();
	void deactivate();
	bool isActive(){return _active;};

	Texture* getNormalTexture() { return _texNormal; }
	Texture* getColorTexture() { return _texColor; }

private:
	Shader* _shader;
	Shader* _shader_combine;
	Shader* _mrtShader;
	Shader* _mrtShader2;

	Texture* _texPos;
	Texture* _texRandom;
	Texture* _texNormal;
	Texture* _texColor;
	Texture* _texSSAO; //Buffer2
	Texture* _texSSAOHalf;
	Texture* _texBlurredX;

	FBO* _gBuffer;
	FBO* _gBuffer2;

	GLint _varPosTexture;
	GLint _varRandomTexture;
	GLint _varNormalTexture;
	//GLint _varColorTexture;
	GLint _varPSphere;
	GLint _varColorTexture2;
	GLint _varPosTexture2;
	GLint _varNormalTexture2;
	GLint _varSSAOTexture; //Buffer2
	GLint _varMapResX;
	GLint _varMapResY;

	GLint _varonlySSAO;
	GLint _varXDirection;

	GLint _varMatrix;

	GLfloat _perspProjMatrix[16];

	GLint _nearPlane, _farPlane; //for mrt

	GLenum _varBuffers[3];
	GLenum _varBuffers2[2]; //Buffer2

   static const GLfloat pSphere[3*16];


	bool _active;
	bool _onlySSAO;

};
