git-svn-id: svn://db.shs.com.ru/libs@664 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2019-12-09 20:36:54 +00:00
parent 1a210defb1
commit 86f4e0ad78
4 changed files with 48 additions and 23 deletions

View File

@@ -57,17 +57,22 @@ Mesh * Mesh::clone() {
void Mesh::init(QOpenGLExtraFunctions * f) {
if (!isInit()) {
buffer_geom.init(f);
buffer_ind .init(f);
vao.bindBuffers(f, buffer_geom, buffer_ind);
changed = true;
}
}
void Mesh::destroy(QOpenGLExtraFunctions * f) {
buffer_geom.destroy(f);
buffer_ind .destroy(f);
vao.destroy(f);
QList<VertexObject*> vaol = vao_map.values();
foreach (VertexObject* vao, vaol)
vao->destroy(f);
qDeleteAll(vao_map);
vao_map.clear();
}
@@ -119,6 +124,15 @@ void Mesh::calculateTangents() {
}
VertexObject * Mesh::vaoByType(int type) {
VertexObject *& vao(vao_map[type]);
if (!vao) {
vao = new VertexObject();
}
return vao;
}
bool Mesh::rebuffer(QOpenGLExtraFunctions * f) {
changed = false;
if (vertices_.isEmpty()) return true;
@@ -159,15 +173,18 @@ bool Mesh::rebuffer(QOpenGLExtraFunctions * f) {
}
void Mesh::draw(QOpenGLExtraFunctions * f, int count) {
void Mesh::draw(QOpenGLExtraFunctions * f, int count, int type) {
if (isEmpty()) return;
if (!isInit()) init(f);
if (changed) rebuffer(f);
//qDebug() << "draw" << geom_type << vert_count << count;
VertexObject * vao = vaoByType(type);
vao->bindBuffers(f, buffer_geom, buffer_ind);
if (geom_type == GL_TRIANGLES)
vao.draw(f, geom_type, triangles_.size() * 3, count);
vao->draw(f, geom_type, triangles_.size() * 3, count);
else
vao.draw(f, geom_type, lines_.size() * 2, count);
vao->draw(f, geom_type, lines_.size() * 2, count);
}
@@ -184,19 +201,21 @@ void Mesh::clear() {
}
void Mesh::loadObject(QOpenGLExtraFunctions * f, const Object & object) {
vao.loadObject(f, object);
void Mesh::loadObject(QOpenGLExtraFunctions * f, const Object & object, int type) {
VertexObject * vao = vaoByType(type);
vao->loadObject(f, object);
}
void Mesh::loadObjects(QOpenGLExtraFunctions * f, const QVector<Object> & objects) {
vao.loadObjects(f, objects);
void Mesh::loadObjects(QOpenGLExtraFunctions * f, const QVector<Object> & objects, int type) {
VertexObject * vao = vaoByType(type);
vao->loadObjects(f, objects);
}
void Mesh::loadSelections(QOpenGLExtraFunctions * f, const QVector<uchar> & sels) {
//qDebug() << "loadSelections" << sels;
vao.loadSelections(f, sels);
void Mesh::loadSelections(QOpenGLExtraFunctions * f, const QVector<uchar> & sels, int type) {
VertexObject * vao = vaoByType(type);
vao->loadSelections(f, sels);
}

View File

@@ -41,16 +41,16 @@ public:
void init (QOpenGLExtraFunctions * f);
void destroy (QOpenGLExtraFunctions * f);
bool rebuffer(QOpenGLExtraFunctions * f);
void draw (QOpenGLExtraFunctions * f, int count);
void draw (QOpenGLExtraFunctions * f, int count, int type = 0);
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);
void loadObject (QOpenGLExtraFunctions * f, const QGLEngineShaders::Object & object, int type = 0);
void loadObjects (QOpenGLExtraFunctions * f, const QVector<QGLEngineShaders::Object> & objects, int type = 0);
void loadSelections(QOpenGLExtraFunctions * f, const QVector<uchar> & sels, int type = 0);
int verticesCount() const {return vertices_.size();}
int trianglesCount() const {return triangles_.size();}
int linesCount() const {return lines_.size();}
bool isInit() const {return vao.isInit();}
bool isInit() const {return buffer_geom.isInit();}
bool isEmpty() const {return vertices_.isEmpty();}
uint hash() const;
@@ -78,6 +78,7 @@ public:
private:
void calculateNormals();
void calculateTangents();
VertexObject * vaoByType(int type);
QVector<QVector3D> vertices_, normals_, tangents_, bitangents_;
QVector<QVector2D> texcoords_;
@@ -87,7 +88,7 @@ private:
QVector<QGLEngineShaders::Vertex> data_;
GLenum geom_type;
Buffer buffer_geom, buffer_ind;
VertexObject vao;
QMap<int, VertexObject * > vao_map;
mutable uint hash_;
mutable bool hash_changed;
int vert_count;

View File

@@ -27,6 +27,7 @@ VertexObject::VertexObject():
buffer_obj (GL_ARRAY_BUFFER, GL_STREAM_DRAW),
buffer_sel (GL_ARRAY_BUFFER, GL_STREAM_DRAW) {
vao_ = 0;
buffers_binded = false;
}
@@ -64,7 +65,10 @@ void VertexObject::release(QOpenGLExtraFunctions * f) {
}
void VertexObject::bindBuffers(QOpenGLExtraFunctions * f, Buffer & geom, Buffer & elem) {
void VertexObject::bindBuffers(QOpenGLExtraFunctions * f, Buffer & geom, Buffer & elem, bool force) {
if (!force && buffers_binded) return;
buffers_binded = true;
init(f);
bind(f);

View File

@@ -36,7 +36,7 @@ public:
void bind (QOpenGLExtraFunctions * f);
void release (QOpenGLExtraFunctions * f);
void bindBuffers (QOpenGLExtraFunctions * f, Buffer & geom, Buffer & elem);
void bindBuffers (QOpenGLExtraFunctions * f, Buffer & geom, Buffer & elem, bool force = false);
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);
@@ -51,6 +51,7 @@ private:
GLuint vao_;
Buffer buffer_obj, buffer_sel;
bool buffers_binded;
};