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

#ifndef MGML_GUARDIAN
	#include "../CSL/MGML.h"
#endif


#ifndef RTLIB_GUARDIAN
  #include "rtlib.h"
#endif

using namespace MGML;

#ifdef CERF_DLL_EXPORTS
	#define DLL_API __declspec(dllexport)
#else
	#define DLL_API __declspec(dllimport)
#endif


class DLL_API IGraphicsEngine
{
public:

	typedef unsigned int uint;
	enum {MAX_KD_TREE_NODES = 1000000};

	IGraphicsEngine(int w,int h){}
	virtual ~IGraphicsEngine() {}

	virtual void BeginDrawScene(unsigned int trace_depth, bool shadows) = 0;			// you can do some thing between this calls
	virtual void EndDrawScene() = 0;			                                      // \\ you can do some thing between this calls

	virtual void DrawScene(unsigned int trace_depth,bool shadows) 
    { BeginDrawScene(trace_depth,shadows); EndDrawScene(); }

	virtual void BuildAccelerationStructures(uint in_maxNodes = MAX_KD_TREE_NODES) = 0;

	virtual uint	AddPointLight(const RAYTR::PointLight& light) = 0;
  virtual uint	AddFlatLight(const FlatLight& light) = 0;

	virtual uint	AddMaterial(const RAYTR::Material& mat) = 0;
	virtual vec2ui	AddTriangles(const Vertex4f* v,int N_vertices,
								 const uint* indices,int N_indices) = 0;
	virtual uint	AddSpheres(const Sphere4f* s,int N_spheres) = 0;

	enum {RGBA32BIT_TEXTURE_FORMAT};
	virtual uint	AddTexture(const void* memory, uint w, uint h, uint format = RGBA32BIT_TEXTURE_FORMAT) = 0;

	virtual uint	AddScene() = 0;
	virtual void	SetActiveScene(uint scnIndex) = 0;

	virtual void SetPointLight(const RAYTR::PointLight& light,int index) = 0;	
  virtual void SetFlatLight(const FlatLight& light,int index) = 0;	
  virtual const RAYTR::PointLight&	GetPointLight(int index) const = 0;
	
  virtual void SetCamMatrix(const Matrix4x4f& mat) = 0;
  virtual const Matrix4x4f&	GetCamMatrix() const = 0;
	

	virtual const RAYTR::Material&		GetMaterial(int index) const = 0;
  virtual void SetMaterial(const RAYTR::Material& mat, unsigned int N) = 0;
	
	enum {  MAX_NUM_VERTICES = 5*1000000,
		      MAX_NUM_SPHERES  = 4096*2,
		      MAX_NUM_INDICES = MAX_NUM_VERTICES*3, 
          MAX_NUM_POINT_LIGHTS = 8,
          MAX_NUM_FLAT_LIGHTS = 32,
		      MAX_NUM_MATERIALS = 120,
		      MAX_NUM_TEXTURES  = 8};


private:
	IGraphicsEngine(const IGraphicsEngine& rhs){}
	IGraphicsEngine& operator=(const IGraphicsEngine& rhs)
		{return *this;}

};