/// Copyright (c) 2009 Ruben Penalva. All rights reserved.
/// Redistribution and use in source and binary forms, with or without modification, 
/// are permitted provided that the following conditions are met:
///    1. Redistributions of source code must retain the above copyright notice, this 
///    list of conditions and the following disclaimer.
///    2. Redistributions in binary form must reproduce the above copyright notice,
///    this list of conditions and the following disclaimer in the documentation and/or
///    other materials provided with the distribution.
///    3. The name of the author may not be used to endorse or promote products derived
///    from this software without specific prior written permission.
///
/// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
/// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
/// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 
/// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
/// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
/// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
/// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
/// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

/// @file Render.h
/// This source file is part of Gpu Quadratic Curve Render Test.
/// The file holds the Render class interface.
/// @author Ruben Penalva (ruben.penalva@rpenalva.com)
#ifndef _Render_H_
#define _Render_H_

#include <vector>

#include "Point.h"
#include "Line.h"

namespace GpuQuadraticCurveRender
{

class OpenglGpuProgram;

/// @brief  Opengl Render tailored specifically for 
///	GpuQuadraticCurveRender test.
/// It can render these 2d geometry:
///		- Points
///		- Lines
///		- Curves
/// It only supports a material being a configurable 
///	emissive color.
class Render
{
public:
	/// Constructor
	Render(void);

	/// Destructor
	~Render(void);

	/// @brief Loads a default opengl configuration
	/// @param width render window width
	/// @param height render window height
	/// @note It's very ugly to have a separete method
	/// for initialization and don't use the constructor.
	void Initialize(int width, int height);

	/// @brief Reshapes opengl viewport and initialize states
	/// @param width render window width
	/// @param height render window height
	void Reshape(int width, int height);

	/// @brief Begins render frame
	void BeginFrame(void);

	/// @brief Sets the only material: emissive color
	/// @param red red channel
	/// @param green green channel
	/// @param blue blue channel
	void SetMaterial(float red, float green, float blue);

	/// @brief Draws a vector of points in 2d with a fixed
	/// point size
	/// @param points the vector of points
	void DrawPoints(const std::vector<Point>& points);

	/// @brief Draws a vector of lines in 2d
	/// @param lines the vector of lines
	void DrawLines(const std::vector<Line>& lines);

	/// @brief Draws a set of triangles
	/// @param points vertices position
	/// @param indices indices
	void DrawTriangles(const std::vector<Point>& points, const std::vector<int>& indices);

	/// @brief Draws a quadratic spline using GLSL shaders
	/// @param points the control points
	void DrawQuadraticSpline(const std::vector<Point>& points);

	/// @brief Ends render frame
	void EndFrame(void);

	/// @brief unproject a point
	/// @param screenPoint point to be unprojected
	/// @param x
	/// @param y
	/// @param z
	void UnProjectScreenPoint(const Point& screenPoint, double& x, double& y, double& z);

	/// @brief gets point size
	/// @return points size
	float GetPointSize(void) const;

private:
	/// Depth at wich objects are
	const float m_depth;

	/// Fixed point size
	const float m_pointSize;

	/// Quadratic vertex shader file path
	const std::wstring quadraticVertexShaderFile;

	/// Quadratic pixel shader file path
	const std::wstring quadraticPixelShaderFile;

	/// Quadratic glsl program
	OpenglGpuProgram* m_quadraticGpuProgram;

	/// @note hide copy constructor from interface user
	Render(const Render&);

	/// @note hide assignment operator from interface user
	Render& operator=(const Render&);
};

}

#endif
