/*
QGLView
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
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. If not, see .
*/
#ifndef GLMESH_H
#define GLMESH_H
#include
#include "glbuffer.h"
#include "glshaders_types.h"
class Mesh
{
friend class ObjectBase;
friend class Scene;
friend class Renderer;
friend QDataStream & operator <<(QDataStream & s, const Mesh * m);
friend QDataStream & operator >>(QDataStream & s, Mesh *& m);
public:
Mesh();
~Mesh();
Mesh * clone();
//GLVBO & operator =(const GLVBO & o) {return *this;}
void init (QOpenGLExtraFunctions * f);
void destroy (QOpenGLExtraFunctions * f);
bool rebuffer(QOpenGLExtraFunctions * f);
void draw (QOpenGLExtraFunctions * f, int count);
void clear();
void loadObject (QOpenGLExtraFunctions * f, const QGLEngineShaders::Object & object);
void loadObjects (QOpenGLExtraFunctions * f, const QVector & objects);
void loadSelections(QOpenGLExtraFunctions * f, const QVector & sels);
int verticesCount() const {return vertices_.size();}
int trianglesCount() const {return triangles_.size();}
bool isInit() const {return vao != 0;}
bool isEmpty() const {return vertices_.isEmpty();}
uint hash() const;
QVector & vertices () {changed = hash_changed = true; return vertices_;}
QVector & normals () {changed = hash_changed = true; return normals_;}
QVector & texcoords() {changed = hash_changed = true; return texcoords_;}
QVector< Vector3i> & indices () {changed = hash_changed = true; return triangles_;}
void translatePoints(const QVector3D & dp);
void scalePoints (const QVector3D & dp);
void append(const Mesh * m);
bool saveToFile(const QString & filename);
bool loadFromFile(const QString & filename);
Box3D boundingBox() const;
static void prepareDrawGeom(QOpenGLExtraFunctions * f);
static void prepareDrawObj (QOpenGLExtraFunctions * f);
static void prepareDrawSel (QOpenGLExtraFunctions * f);
private:
void calculateNormals();
void calculateTangents();
void loadBuffer(QOpenGLExtraFunctions * f, Buffer & buf, const void * data, int size);
QVector vertices_, normals_, tangents_, bitangents_;
QVector texcoords_;
QVector< Vector3i> triangles_;
QVector data_;
GLenum vao;
Buffer buffer_geom, buffer_ind, buffer_obj, buffer_sel;
mutable uint hash_;
mutable bool hash_changed;
int vert_count;
bool changed, objects_changed, selected_changed;
};
QDataStream & operator <<(QDataStream & s, const Mesh * m);
QDataStream & operator >>(QDataStream & s, Mesh *& m);
#endif // GLMESH_H