/*
	Copyright (C) 2021-2025 Mark Tyler

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program in the file COPYING.
*/

#ifndef MTLANTER_BE_TERRASCENE_H_
#define MTLANTER_BE_TERRASCENE_H_

#include "lanter_be.h"



// Functions return: 0 = success, NULL = fail; unless otherwise stated.



#ifdef __cplusplus
extern "C" {
#endif

// C API




#ifdef __cplusplus
}

// C++ API

class CubeCorners;
class CubeLines;

class LandLines;
class LandPoints;
class LandTriangles;

template < typename T >
class LandBase;



template < typename T >
class LandBase
{
public:
	LandBase () = default;
	virtual ~LandBase () { clear(); }

	T const * get_data () const { return m_data; }
	size_t get_vertex_count () const { return m_vertex_count; }

	virtual int init ( TerraMap const & map )		= 0;

protected:
	void clear ()
	{
		free ( m_data );
		m_data = nullptr;
		m_vertex_count = 0;
	}

/// ----------------------------------------------------------------------------

	T		* m_data = nullptr;
	size_t		m_vertex_count = 0;

	MTKIT_RULE_OF_FIVE( LandBase )
};



class LandTriangles : public LandBase< mtGin::GL::VertexRGBnormal >
{
public:
	int init ( TerraMap const & map )		override;
};

class LandLines : public LandBase< mtGin::GL::VertexRGB >
{
public:
	int init ( TerraMap const & map )		override;
};

class LandPoints : public LandBase< mtGin::GL::VertexRGB >
{
public:
	int init ( TerraMap const & map )		override;
};



class CubeLines
{
public:
	explicit CubeLines ( float size );

	mtGin::GL::VertexRGB const * get_data () const { return point; }
	static size_t get_data_size () { return point_tot; }

private:
	// Cube = 12 lines is 24 vertices
	static size_t const point_tot = 24;
	mtGin::GL::VertexRGB point[ point_tot ];
};



class CubeCorners
{
public:
	CubeCorners ( GLfloat size, GLfloat r, GLfloat g, GLfloat b );

	mtGin::GL::VertexRGB point[ 8 ];
/*
  6-----7
 /|    /|
4-----5 |
| |   | |
| 2---|-3
|/    |/
0-----1
*/
};




#endif		// C++ API



#endif		// MTLANTER_BE_TERRASCENE_H_

