/*
 * $Id: rendermanager.h 4661 2017-08-23 20:40:02Z antonin.misek-skoda-auto.cz $
 *
 * Description  : One line description of file.
 * Author       : Vaclav Kyba <mail/Jabber: vaseo1@gmail.com>  <ICQ: 98576293>
 * 
 * Purpose      :
 *     Long description of what the file is for.
 */


#ifndef __RENDERMANAGER_H__
#define __RENDERMANAGER_H__

#include "serverbase.h"
//#include "rendermodule.h"
#include "glwindow.h"

#include "VrutApi.h"

namespace VRUT
{
	class RenderModule;
	class GLWindow;
	///Server managing rendering modules
	class VRUT_CORE_API RenderManager : public ServerBase<RenderModule>
	{
		//void commonPredefSetup(const wxString &moduleName, SCENE_ID sceneID, NODE_ID cameraID);
		void commonSetup(RenderModule *module, GLWindow *glw, smart_pointer_v2<Scene> &scene, NODE_ID cameraID);
	protected:
		typedef std::vector<GLWindow *> WindowList;
		///Active \c GLWindow instances list
		WindowList windowList;
		///lock for parallel access to windowList
		ReadWriteMutex windowListLock;

		///Camera which can not be deleted
		NODE_ID protectedCameraID;

	public:
		///Class constructor
		RenderManager() : ServerBase<RenderModule>(RENDER_MANAGER), protectedCameraID(NODE_ID_NONE) {}
		///Class destructor
		virtual ~RenderManager();
		///Cleanup manager data to allow safe application exit
		virtual void ReleaseManagerData();

		///Get \c GLWindow
		GLWindow * GetGLWindow(RENDER_WINDOW_ID windowID);
		///Get module's \c GLWindow
		GLWindow * GetGLWindow(RenderModule * module);
		///Get active GLWindow
		GLWindow * GetActiveGLWindow();
		///Render scene to a window
		///\param[in] scene Scene to be rendered
		///\param[in] cameraID Camera ID to be associated with window
		///\param[in] windowID window ID to be used for this window
		///\return Id of window that was used, \c RENDER_WINDOW_ID_NONE if failed
		RENDER_WINDOW_ID RenderScene(smart_pointer_v2<Scene> &scene, NODE_ID cameraID, RENDER_WINDOW_ID windowID, bool activeStereo = false);

		///Release module instance connected to \c GLWindow instance
		void DestroyGLWindow(GLWindow * glWin);
		///Release module instance connected to \c GLWindow instance
		void DestroyGLWindow(RENDER_WINDOW_ID windowID);
		///Release module instance connected to render module
		void DestroyGLWindow(RenderModule * module);

		///Set camera which can not be deleted
		void SetProtectedCameraID(NODE_ID _protectedCameraID);

		friend class EventManager;
	};
}

#endif
