/*
PolyGun

Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef POLYGUN_RENDERER_MASTER_RENDERER_HPP
#define POLYGUN_RENDERER_MASTER_RENDERER_HPP

#include <memory>
#include <functional>
#include <config.hpp>

#include "game/renderer/mesh_renderer.hpp"
#include "game/renderer/gui_renderer.hpp"

namespace polygun::window {
	class Window;
}

namespace polygun::renderer {
	class Shader;
	class Mesh;
	class Texture;
#if defined(RENDERER_GL)
	class GLContext;
#endif
	enum RendererType {
		RENDERER_TYPE_GL
	};
	class MasterRenderer final {
	public:
		MasterRenderer();
		~MasterRenderer();

		void init(RendererType renderer_type, window::Window* window);
		void clear_screen(float r, float g, float b);

		RendererType get_renderer_type() const { return m_renderer_type; }
		MeshRenderer* get_mesh_renderer() { return m_mesh_renderer.get(); }
		GUIRenderer* get_gui_renderer() { return m_gui_renderer.get(); }

		Shader* create_shader() const;
		Mesh* create_mesh() const;
		Texture* create_texture() const;

	private:
		RendererType m_renderer_type;
		std::function<void(float, float, float)> m_clear_screen_impl;
#if defined(RENDERER_GL)
		GLContext* m_gl_context;
#endif
		std::unique_ptr<MeshRenderer> m_mesh_renderer;
		std::unique_ptr<GUIRenderer> m_gui_renderer;

	private:
#if defined(RENDERER_GL)
		void create_opengl_renderer(window::Window* window);
#endif
	};
}

#endif // POLYGUN_RENDERER_MASTER_RENDERER_HPP
