git-svn-id: svn://db.shs.com.ru/libs@626 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
98
qglengine/glmesh.h
Normal file
98
qglengine/glmesh.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLMESH_H
|
||||
#define GLMESH_H
|
||||
|
||||
#include <chunkstream.h>
|
||||
#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<QGLEngineShaders::Object> & objects);
|
||||
void loadSelections(QOpenGLExtraFunctions * f, const QVector<uchar> & 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<QVector3D> & vertices () {changed = hash_changed = true; return vertices_;}
|
||||
QVector<QVector3D> & normals () {changed = hash_changed = true; return normals_;}
|
||||
QVector<QVector2D> & 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<QVector3D> vertices_, normals_, tangents_, bitangents_;
|
||||
QVector<QVector2D> texcoords_;
|
||||
QVector< Vector3i> triangles_;
|
||||
|
||||
QVector<QGLEngineShaders::Vertex> 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
|
||||
Reference in New Issue
Block a user