/*
QGL VertexObject
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
#define GL_GLEXT_PROTOTYPES
#include "glvertexobject.h"
#include
using namespace QGLEngineShaders;
VertexObject::VertexObject(): buffer_obj(GL_ARRAY_BUFFER, GL_STREAM_DRAW), buffer_sel(GL_ARRAY_BUFFER, GL_STREAM_DRAW) {
vao_ = 0;
buffers_binded = false;
objects_changed = selected_changed = true;
}
VertexObject::~VertexObject() {}
void VertexObject::init(QOpenGLExtraFunctions * f) {
if (!isInit()) {
buffer_obj.init(f);
buffer_sel.init(f);
f->glGenVertexArrays(1, &vao_);
}
}
void VertexObject::destroy(QOpenGLExtraFunctions * f) {
if (vao_ != 0) {
buffer_obj.destroy(f);
buffer_sel.destroy(f);
f->glDeleteVertexArrays(1, &vao_);
}
vao_ = 0;
}
void VertexObject::reinit() {
vao_ = 0;
buffer_obj.reinit();
buffer_sel.reinit();
buffers_binded = false;
objects_changed = selected_changed = true;
}
void VertexObject::bind(QOpenGLExtraFunctions * f) {
// qDebug() << "bind" << target_ << buffer_;
f->glBindVertexArray(vao_);
}
void VertexObject::release(QOpenGLExtraFunctions * f) {
f->glBindVertexArray(0);
}
void VertexObject::bindBuffers(QOpenGLExtraFunctions * f, Buffer & geom, Buffer & elem, bool force) {
if (!force && buffers_binded) return;
buffers_binded = true;
init(f);
bind(f);
geom.bind(f);
prepareDrawGeom(f);
elem.bind(f);
buffer_obj.bind(f);
prepareDrawObj(f);
buffer_sel.bind(f);
prepareDrawSel(f);
release(f);
}
void VertexObject::loadObject(QOpenGLExtraFunctions * f, const Object & object) {
loadBuffer(f, buffer_obj, &object, sizeof(Object));
}
void VertexObject::loadObjects(QOpenGLExtraFunctions * f, const QVector