#pragma once

#include <string>
#include <vector>

#include <assimp/Importer.hpp>      // C++ importer interface
#include <assimp/scene.h>           // Output data structure
#include <assimp/postprocess.h>     // Post processing flags

#include <epoxy/gl.h>
#include <epoxy/glx.h>

#include "glclasses.hpp"

// TODO: hide assimp inside
// and enable/disable
// to use own binary format without assimp for speed/compatibiblity

// TODO: add lod-options
// TODO: add generate from openscad options if models missing
namespace endofthejedi {
    class PolygonModel {
        public:
            PolygonModel(const std::string &filename);

			// (re) load data from file
            bool import();

			// connect stuff with the shader for rendering
			// supply the current shader that should be used for this model.
			// when it recompiles, call setup() again.
			void setup(Shader *shader);

			// upload model data to GPU
            bool uploadToOpenGl();

			// call bind before rendering
            bool bind();

			// call to render
            bool render();

			// clear everything and delete data
			void clear();

        private:
            bool copyVertices(const aiScene *scene);

            const std::string &filename() const { return m_filename; }

        private:
            std::string m_filename;
            bool        m_loaded_from_file;
            bool        m_loaded_to_opengl;
            bool        m_binding_active;

            // both will hold 3 * numVertices floats
            std::vector<float> m_data_position;
            std::vector<float> m_data_normal;

            size_t      m_numVertices;

			// TODO: watch for shader recompile
			GLint       m_attr_locations[2];
            GLuint      m_vbo_id[2];
			Shader     *m_shader;
    };
}
