#pragma once
#include "../stdafx.h"

#include "glLibTexturing/glLibTexture.h"
#include "glLibTexturing/glLibTexture1D.h"
#include "glLibTexturing/glLibTexture2D.h"
#include "glLibTexturing/glLibTexture3D.h"
#include "glLibTexturing/glLibTexturing.h"

class glLibFBO {
	public:
		int size[2];

		map<int,glLibInternal_texture*> textures;
		map<int,GLint> render_buffers;

		GLuint framebuffer;
		GLuint renderbuffer;

		bool currently_using[8];

		int numof_render_targets;
	private:
		int _dimensions;

		GLuint depth;

		string status_string;
	public:
		glLibFBO(int new_size[], int depthsize=8, int samples=1, int dimensions=2);
		~glLibFBO();
		
		//the min filter and mag filter can't have default arguments, because the compiler won't know which overload to use.
		void add_render_target(int number, glLibFlagTextureFormat type,            bool filter_min,            bool filter_mag, int precision=8);
		void add_render_target(int number, glLibFlagTextureFormat type,            bool filter_min, glLibFlagFilter filter_mag, int precision=8);
		void add_render_target(int number, glLibFlagTextureFormat type, glLibFlagFilter filter_min,            bool filter_mag, int precision=8);
		void add_render_target(int number, glLibFlagTextureFormat type, glLibFlagFilter filter_min, glLibFlagFilter filter_mag, int precision=8);

		void set_render_target(int number, glLibTexture2D* new_texture);
		void remove_render_target(int number);

		//TODO: add FBO copying methods:
		//.copy(glLibLocal src_rect, glLibLocal dst_rect, glLibLocal buffers)
		//.copy(int src_rect[4], int dst_rect[4], glLibLocal buffers)
		//glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, this->framebuffer);
		//glBlitFramebufferEXT(
		//	0,0,w,h,
		//	0,0,w,h,
		//buffer,GL_NEAREST); //GL_DEPTH_BUFFER_BIT
		//glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
			private:
		void glLibInternal_remove_target(int number);

	public:
		void check_status(void);

		void enable(int target);
		void enable(int target_list[], int number);
		void enable(glLibFlag target);
		void disable(void);

		//glLibInternal_texture* get_texture(int rendertarget);
		//map<int,glLibInternal_texture> get_textures(void);
	private:
		void glLibInternal_add_render_target(int number, glLibFlagTextureFormat type, glLibFlagFilter filter_min, glLibFlagFilter filter_mag, int precision);

		void glLibInternal_status_parse(GLint status);
		void glLibInternal_select_layer(int layer);
};