// © Copyright 2008 Vladimir Frolov, Moscow State University Graphics & Media Lab
#pragma once

#include "IGraphicsEngine.h"
#include "Common_Graphics_Engine.h"
#include "Fonts.h"

using MGML_MATH::SSE_Aligned_Object;

class DLL_API OpenGL_Render: public Common_Graphics_Engine // : public Singleton
{
	typedef IGraphicsEngine		   Interface;
	typedef Common_Graphics_Engine Realisation;

public:

	typedef Common_Graphics_Engine Base;
	typedef unsigned int uint;

  OpenGL_Render(int w, int h);
	~OpenGL_Render();


	void BeginDrawScene(unsigned int trace_depth,bool shadows);			// account multithreading
	void EndDrawScene();			// account multithreading

	uint AddTexture(const void* memory, unsigned int w, unsigned int h, unsigned int format);

	enum {MAX_NUM_VERTICES = 1000000,
		  MAX_NUM_SPHERES  = 1024,
		  MAX_NUM_POINT_LIGHTS = 8};

protected:

	void setLights();
	void drawLights();

	virtual OpenGL_Render& operator=(const OpenGL_Render& x)
	{ 
		throw Error("OpenGL_Render:: Atempt to call protected operator=() "); 
		return (OpenGL_Render&)x;
	}

	GLUquadricObj* QuadrObj; 

	struct GL_List
	{

		enum {	MAX_LISTS_NUM = 64,
				MAX_TRIANGLE_NUM = 1000000};

		GL_List()
		{
			lists_num	= 1;
			render		= 0;
		}

		virtual ~GL_List()
		{
			//delete [] lists;
			render		= 0;
			lists_num	= 1;
		}

		void Init(	const uint* indices,	uint num_ind,
					const OpenGL_Render* a_render);

		inline void Draw()
		{
			//glCallLists(lists_num,GL_UNSIGNED_INT,lists);

			for(uint i=1;i<lists_num;i++)
				glCallList(i);
		}

		uint	lists_num;
		const OpenGL_Render* render;
	};

	GL_List all_scene_list;
	bool init_scene_list;

};