/*
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_GL_MESH_HPP
#define POLYGUN_RENDERER_GL_MESH_HPP

#include "game/renderer/mesh.hpp"

namespace polygun::renderer {
	class GLMesh final : public Mesh {
		friend class GLMeshRenderer;
	public:
		GLMesh();
		virtual ~GLMesh() override;

		virtual void add_custom_buffer(const void* data, unsigned size, unsigned char data_length, misc::VarType data_type) override;

	private:
		struct MeshBuffer {
			unsigned m_id;
			unsigned char m_length;
			misc::VarType m_data_type;
		};
	private:
		unsigned m_vao, m_vbo, m_tbo, m_nbo, m_ebo;
		unsigned m_element_count;
		std::vector<MeshBuffer> m_custom_buffers;

	private:
		unsigned calculate_custom_buffer_attribute_index(unsigned buffer_index);

	protected:
		virtual void load_vertices(const std::vector<float>& vertices) override;
		virtual void load_indices(const std::vector<unsigned>& indices) override;
		virtual void load_uvs(const std::vector<float>& uvs) override;
		virtual void load_normals(const std::vector<float>& normals) override;
	};
}

#endif // POLYGUN_RENDERER_GL_MESH_HPP
