#pragma once
#include "../stdafx.h"
#include "glLibFBO.h"
#include "glLibLight.h"
#include "glLibShader.h"
#include "glLibView.h"

namespace glLib {

template <typename type_float> void set_alpha(type_float alpha) {
	GLfloat current_color[4]; glGetFloatv(GL_CURRENT_COLOR,current_color);
	glColor4f(current_color[0],current_color[1],current_color[2],alpha);
}

void scene_to_texture(int rect[4], Texture::texture_2D* texture);
void scene_to_texture(glLibFlag rect, Texture::texture_2D* texture);

void set_camera(const View::glLibInternal_glLibView* view, const double* eye, const double* center, const   double*   up);
void set_camera(const View::glLibInternal_glLibView* view, const double* eye, const double* center, const glLibFlag flag);
void get_camera_frustum_points(
	const View::glLibInternal_glLibView* view,
	const double* eye, const double* center, const double* up,
	double data[2][4][3]);

void get_matrices_projection_view(float* proj_mat, float* view_mat);

void glLibInternal_make_depthmap( void(*draw_objects)(void), float offset ); //TODO: const on the function?
void update_depth_map(const Texture::texture_2D*  depthmap, void(*draw_objects)(void), float offset=1.0f); //TODO: here too?
void update_depth_map(                const FBO* depth_fbo, void(*draw_objects)(void), float offset=1.0f);

const GLfloat glLibInternal_matrix_depthmap_scale_and_bias[] = {
	0.5f, 0.0f, 0.0f, 0.0f,
	0.0f, 0.5f, 0.0f, 0.0f,
	0.0f, 0.0f, 0.5f, 0.0f,
	0.5f, 0.5f, 0.5f, 1.0f};
void update_depth_maps( //TODO: const correct all arguments!
	Texture::texture_2D** depthmaps,
	const float*const* projection_matrices, const float*const* view_matrices,
	int number_of_depthmaps,
	int starting_number_effect,
	int starting_number_texture,
	shader* shader,
	void(*transform_objects)(void) );

void glLibInternal_update_cubemap(
	Texture::texture_cube* cubemap, const View::view_3D* cubemap_view,
	double x, double y, double z,
	void(*draw_reflectees)(void), //TODO: const?
	const bool update[6]);
//TODO: Add FBO override
void update_cube_map(
	Texture::texture_cube* cubemap, const View::view_3D* cubemap_view, const double center[3],
	void(*draw_reflectees)(void), //TODO: const?
	const glLibFlag update_flag=GLLIB_ALL);

void set_transform( shader* shader, void(*transform_function)(void) ); //TODO: const?

bool check_extension(const char *extension);

void set_draw_mode(const glLibFlagType mode);

void glTranslatefv(const GLfloat vec[3]);
void glTranslatedv(const GLdouble vec[3]); //TODO document these

};