6 #include <unordered_map>
92 Mesh( ) : m_positions(), m_texcoords(), m_normals(), m_colors(), m_indices(),
93 m_color(
White()), m_primitives(GL_POINTS), m_vao(0), m_program(0), m_update_buffers(false) {}
96 Mesh(
const GLenum primitives ) : m_positions(), m_texcoords(), m_normals(), m_colors(), m_indices(),
97 m_color(
White()), m_primitives(primitives), m_vao(0), m_program(0), m_update_buffers(false) {}
100 int create(
const GLenum primitives );
114 Mesh&
color(
const float r,
const float g,
const float b,
const float a= 1) {
return color(
Color(r, g, b, a)); }
133 unsigned int vertex(
const float x,
const float y,
const float z ) {
return vertex(
vec3(x, y, z)); }
144 Mesh&
triangle(
const unsigned int a,
const unsigned int b,
const unsigned int c );
165 Mesh&
color(
const unsigned int id,
const float r,
const float g,
const float b,
const float a= 1) {
return color(
id,
vec4(r, g, b, a)); }
172 Mesh&
normal(
const unsigned int id,
const float x,
const float y,
const float z ) {
return normal(
id,
vec3(x, y, z)); }
180 void vertex(
const unsigned int id,
const vec3& p );
184 void vertex(
const unsigned int id,
const float x,
const float y,
const float z ) {
vertex(
id,
vec3(x, y, z)); }
235 const std::vector<vec3>& positions( )
const {
return m_positions; }
236 const std::vector<vec2>& texcoords( )
const {
return m_texcoords; }
237 const std::vector<vec3>& normals( )
const {
return m_normals; }
238 const std::vector<vec4>& colors( )
const {
return m_colors; }
239 const std::vector<unsigned int>& indices( )
const {
return m_indices; }
240 GLenum primitives( )
const {
return m_primitives; }
256 bool operator== (
const Mesh& m )
const
269 const bool use_light,
const Point& light,
const Color& light_color,
270 const bool use_texture,
const GLuint texture );
274 GLuint
create_buffers(
const bool use_texcoord=
true,
const bool use_normal=
true,
const bool use_color=
true );
291 GLuint
create_program(
const bool use_texcoord=
true,
const bool use_normal=
true,
const bool use_color=
true,
const bool use_light=
false );
293 int update_buffers(
const bool use_texcoord,
const bool use_normal,
const bool use_color );
296 std::vector<vec3> m_positions;
297 std::vector<vec2> m_texcoords;
298 std::vector<vec3> m_normals;
299 std::vector<vec4> m_colors;
301 std::vector<unsigned int> m_indices;
303 std::unordered_map<unsigned int, GLuint> m_state_map;
304 unsigned int m_state;
312 bool m_update_buffers;
Mesh & restart_strip()
demarre un nouveau strip. a utiliser avec un objet composes de GL_TRIANGLE_STRIP, doit aussi fonction...
const float * normal_buffer() const
renvoie l'adresse de la normale du premier sommet. par convention, la normale est un vec3...
std::size_t index_buffer_size() const
renvoie la taille (en octets) de l'index buffer.
Mesh & color(const float r, const float g, const float b, const float a=1)
definit la couleur du prochain sommet.
Mesh & color(const unsigned int id, const Color &c)
modifie la couleur du sommet d'indice id.
const float * vertex_buffer() const
renvoie l'adresse de la position du premier sommet. permet de construire les vertex buffers openGL...
int index_count() const
renvoie le nombre d'indices de sommets.
void bounds(Point &pmin, Point &pmax)
renvoie min et max les coordonnees des extremites des positions des sommets de l'objet (boite engloba...
Mesh & color(const unsigned int id, const float r, const float g, const float b, const float a=1)
modifie la couleur du sommet d'indice id.
vecteur generique, utilitaire.
Mesh & color(const Color &c)
definit la couleur du prochain sommet.
void draw(const Transform &model, const Transform &view, const Transform &projection, const bool use_light, const Point &light, const Color &light_color, const bool use_texture, const GLuint texture)
vecteur generique, utilitaire.
std::size_t normal_buffer_size() const
renvoie la longueur (en octets) du normal buffer.
Mesh & color(const vec4 &c)
definit la couleur du prochain sommet.
representation d'un objet / maillage.
representation d'une couleur (rgba) transparente ou opaque.
unsigned int vertex(const float x, const float y, const float z)
insere un sommet de position p, et ses attributs (s'ils sont definis par color(), texcoord()...
std::size_t vertex_buffer_size() const
renvoie la longueur (en octets) du vertex buffer.
unsigned int vertex(const Point &p)
insere un sommet de position p, et ses attributs (s'ils sont definis par color(), texcoord()...
Mesh & triangle(const unsigned int a, const unsigned int b, const unsigned int c)
GLuint create_program(const bool use_texcoord=true, const bool use_normal=true, const bool use_color=true, const bool use_light=false)
construit un shader program configure.
GLuint create_buffers(const bool use_texcoord=true, const bool use_normal=true, const bool use_color=true)
const float * texcoord_buffer() const
renvoie l'adresse des coordonnees de textures du premier sommet. par convention, c'est un vec2...
Mesh & texcoord(const unsigned int id, const float x, const float y)
modifie les coordonnees du sommet d'indice id.
unsigned int vertex(const vec3 &p)
insere un sommet de position p, et ses attributs (s'ils sont definis par color(), texcoord()...
vecteur generique 4d, ou 3d homogene, utilitaire.
std::size_t attribute_buffer_size(const unsigned int id) const
renvoie la taille (en octets) d'un attribut.
const void * attribute_buffer(const unsigned int id) const
int create(const GLenum primitives)
construit les objets openGL.
std::size_t color_buffer_size() const
renvoie la taille (en octets) du color buffer.
Mesh & texcoord(const float x, const float y)
definit les coordonnees de texture du prochain sommet.
representation d'un vecteur 3d.
Color White()
utilitaire. renvoie une couleur blanche.
void release()
detruit les objets openGL.
const void * index_buffer() const
renvoie l'adresse du premier indice du premier triangle. par convention c'est un uint, 1, GL_UNSIGNED_INT.
std::size_t texcoord_buffer_size() const
renvoie la taille (en octets) du texcoord buffer.
Mesh & triangle_last(const int a, const int b, const int c)
representation d'un point 3d.
void vertex(const unsigned int id, const float x, const float y, const float z)
modifie la position du sommet d'indice id.
Mesh & normal(const vec3 &n)
definit la normale du prochain sommet.
Mesh & normal(const unsigned int id, const Vector &n)
modifie la normale du sommet d'indice id.
int vertex_count() const
renvoie le nombre de sommets.
Mesh(const GLenum primitives)
constructeur.
Mesh & normal(const Vector &n)
definit la normale du prochain sommet.
Mesh & normal(const unsigned int id, const float x, const float y, const float z)
modifie la normale du sommet d'indice id.
Mesh()
constructeur par defaut.
Mesh & texcoord(const vec2 &uv)
definit les coordonnees de texture du prochain sommet.
Mesh & normal(const float x, const float y, const float z)
definit la normale du prochain sommet.
void vertex(const unsigned int id, const Point &p)
modifie la position du sommet d'indice id.
const float * color_buffer() const
renvoie l'adresse de la couleur du premier sommet. par convention, la couleur est un vec4...
Color default_color() const
renvoie la couleur par defaut du mesh, utilisee si les sommets n'ont pas de couleur associee...