
#ifndef TWOOD_H_INCLUDED
#define TWOOD_H_INCLUDED

/*
OBJET       forêt > instanciation pos+rot+scale avec defered shader

DATE        08/2025

AUTEUR      philippe Thebaud

COMMENTAIRE pour un bosquet, on peut utiliser Ttree
*/


#include <GL/glew.h>
#include <string>
#include <vector>
#include <fstream>

#include "../ECO/OUtils.h"
#include "../ECO/OTextureList.h"
#include "../ECO/defered/ODShader.h"
#include "../ECO/OSurface.h"
#include "../ECO/OCollision.h"
#include "../ECO/OMesh_obj.h"
#include "../ECO/OMesh_gltf.h"

#include "common.h"

// code flux load save
#define FLUX_WOOD1      "wood1"
#define FLUX_WOOD1_M    "wood1m"

bool Twood_make(std::string file);

class Twood_shader : public ODshader
{
public:

    Twood_shader();

    bool        create();

    void        setVP(const OMat4& vp);
    void        setTextures(uint32_t texture, uint32_t normal, uint32_t specular);
    void        setTime(float value);
    void        setVerticaleZ(bool mode);

private:

    uint32_t    m_vp;
	uint32_t    m_colorMap, m_normalMap, m_specularMap;
	uint32_t    m_time;
	uint32_t    m_verticaleZ;
};


class Twood
{
public:

    Twood();
    ~Twood();

    void        create(std::string flux);
    void    	create(std::ifstream& flux);

    void        draw(OMat4& vp);

    void        save(std::ofstream& flux);

private:

    void        _composition();

    void        _load_map(std::string file);
    int         _load_nb_line(std::string file);

    void        _make_vao_obj();
    void        _make_vao_glb();

private:

    OTextureList    textureList;
    Twood_shader    dshWood;
    std::string     m_code, m_path, m_file, m_file_map;
    bool            m_cull_face;

    OMesh_obj       mesh_obj;
    OMesh_gltf      mesh_glb;
    bool            m_type_obj;

    struct s_wood {
        OVec3_f position;
        OVec3_f rotation;
        float   scale;
        //float   windPhase;
    };

    std::vector<s_wood> m_wood;
    static const int m_vao_nbr_buffer = 5;
    struct s_part {
        uint32_t    vao, vao_buffer[5];
    };
    std::vector<s_part> m_part; // parties du mesh


};


#endif
