code format

This commit is contained in:
2022-12-14 14:14:33 +03:00
parent 09e5342956
commit cdb02fc9be
278 changed files with 15371 additions and 12176 deletions

View File

@@ -21,21 +21,21 @@
GLVBO::GLVBO(GLenum usage_) {
buffer_ = 0;
va_ = 0;
usage = usage_;
va_ = 0;
usage = usage_;
changed = true;
}
GLVBO::~GLVBO() {
//destroy();
// destroy();
}
void GLVBO::init() {
initializeOpenGLFunctions();
if (!isInit()) {
//glGenVertexArrays(1, &va_);
// glGenVertexArrays(1, &va_);
glGenBuffers(1, &buffer_);
}
changed = true;
@@ -45,8 +45,8 @@ void GLVBO::init() {
void GLVBO::destroy() {
if (buffer_ != 0) glDeleteFramebuffers(1, &buffer_);
buffer_ = 0;
// if (va_ != 0) glDeleteVertexArrays(1, &va_);
// va_ = 0;
// if (va_ != 0) glDeleteVertexArrays(1, &va_);
// va_ = 0;
}
@@ -57,9 +57,9 @@ void GLVBO::calculateBinormals() {
int vcnt = vertices_.size() / 3;
if (texcoords_.size() != vcnt * 2) return;
int tcnt = vcnt / 3;
//qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
// qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
for (int t = 0; t < tcnt; ++t) {
int vi = t*9, ti = t*6;
int vi = t * 9, ti = t * 6;
Vector3d v0(vertices_[vi + 0], vertices_[vi + 1], vertices_[vi + 2]);
Vector3d v1(vertices_[vi + 3], vertices_[vi + 4], vertices_[vi + 5]);
Vector3d v2(vertices_[vi + 6], vertices_[vi + 7], vertices_[vi + 8]);
@@ -70,49 +70,53 @@ void GLVBO::calculateBinormals() {
Vector2d dt1 = t1 - t0, dt2 = t2 - t0;
Vector3d tan;
Vector3d bitan;
tan = (dv1 * dt2.y - dv2 * dt1.y).normalize();
tan = (dv1 * dt2.y - dv2 * dt1.y).normalize();
bitan = (dv2 * dt1.x - dv1 * dt2.x).normalize();
for (int i = 0; i < 3; ++i) {
tangents_ << tan.x << tan.y << tan.z;
bitangents_ << bitan.x << bitan.y << bitan.z;
}
//qDebug() << " t" << t << vi << ti << dv1.toQVector3D() << "...";
// qDebug() << " t" << t << vi << ti << dv1.toQVector3D() << "...";
}
//qDebug() << "calculateBinormals" << vcnt << tcnt << tangents_.size();
// qDebug() << "calculateBinormals" << vcnt << tcnt << tangents_.size();
}
bool GLVBO::rebuffer(bool clear_) {
initializeOpenGLFunctions();
QVector<GLfloat> data;
//data.clear();
// data.clear();
calculateBinormals();
data << vertices_;
if (!normals_.isEmpty()) {
data << normals_;
has_normals = true;
} else has_normals = false;
} else
has_normals = false;
if (!texcoords_.isEmpty()) {
data << texcoords_;
has_texcoords = true;
} else has_texcoords = false;
} else
has_texcoords = false;
if (!colors_.isEmpty()) {
data << colors_;
has_colors = true;
} else has_colors = false;
} else
has_colors = false;
if (!tangents_.isEmpty()) {
data << tangents_ << bitangents_;
has_binormals = true;
} else has_binormals = false;
//glBindVertexArray(va_);
//qDebug() << "load buffer" << data.size() << buffer_;
} else
has_binormals = false;
// glBindVertexArray(va_);
// qDebug() << "load buffer" << data.size() << buffer_;
glBindBuffer(GL_ARRAY_BUFFER, buffer_);
glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(GLfloat), data.constData(), usage);
glBindBuffer(GL_ARRAY_BUFFER, 0);
//glBindVertexArray(0);
// glBindVertexArray(0);
vert_count = vertices_.size() / 3;
changed = false;
//qDebug() << "rebuff" << buffer_ << vert_count;
changed = false;
// qDebug() << "rebuff" << buffer_ << vert_count;
if (clear_) clear();
return !isEmpty();
}
@@ -121,26 +125,26 @@ bool GLVBO::rebuffer(bool clear_) {
void GLVBO::draw(GLenum type, QOpenGLShaderProgram * prog, bool simplest) {
if (buffer_ == 0 || vert_count == 0) return;
if (changed) rebuffer();
//qDebug() << "draw" << vert_count;
void * offset = (void*)(vert_count * 3 * sizeof(GLfloat));
//glBindVertexArray(va_);
// qDebug() << "draw" << vert_count;
void * offset = (void *)(vert_count * 3 * sizeof(GLfloat));
// glBindVertexArray(va_);
void * offsets[5] = {0, 0, 0, 0, 0};
if (!simplest) {
if (has_normals) {
offsets[0] = offset;
offset = (void*)(llong(offset) + vert_count * 3 * sizeof(GLfloat));
offset = (void *)(llong(offset) + vert_count * 3 * sizeof(GLfloat));
}
if (has_texcoords) {
offsets[1] = offset;
offset = (void*)(llong(offset) + vert_count * 2 * sizeof(GLfloat));
offset = (void *)(llong(offset) + vert_count * 2 * sizeof(GLfloat));
}
if (has_colors) {
offsets[2] = offset;
offset = (void*)(llong(offset) + vert_count * 4 * sizeof(GLfloat));
offset = (void *)(llong(offset) + vert_count * 4 * sizeof(GLfloat));
}
if (has_binormals) {
offsets[3] = offset;
offset = (void*)(llong(offset) + vert_count * 3 * sizeof(GLfloat));
offset = (void *)(llong(offset) + vert_count * 3 * sizeof(GLfloat));
offsets[4] = offset;
}
}
@@ -178,7 +182,7 @@ void GLVBO::draw(GLenum type, QOpenGLShaderProgram * prog, bool simplest) {
locs << loc;
} else
glDisableVertexAttribArray(loc);
loc = prog->attributeLocation("qgl_Tangent");
loc = prog->attributeLocation("qgl_Tangent");
int loc2 = prog->attributeLocation("qgl_Bitangent");
if (has_binormals) {
glEnableVertexAttribArray(loc);
@@ -198,22 +202,25 @@ void GLVBO::draw(GLenum type, QOpenGLShaderProgram * prog, bool simplest) {
if (has_normals) {
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, offsets[0]);
} else glDisableClientState(GL_NORMAL_ARRAY);
} else
glDisableClientState(GL_NORMAL_ARRAY);
if (has_texcoords) {
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, offsets[1]);
} else glDisableClientState(GL_TEXTURE_COORD_ARRAY);
} else
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
if (has_colors) {
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_FLOAT, 0, offsets[2]);
} else glDisableClientState(GL_COLOR_ARRAY);
} else
glDisableClientState(GL_COLOR_ARRAY);
}
}
//qDebug() << "draw" << vert_count << buffer_ << offsets[0] << offsets[1] << offsets[3];
// qDebug() << "draw" << vert_count << buffer_ << offsets[0] << offsets[1] << offsets[3];
glDrawArrays(type, 0, vert_count);
//qDebug() << "draw" << vert_count << buffer_ << "done";
// qDebug() << "draw" << vert_count << buffer_ << "done";
glBindBuffer(GL_ARRAY_BUFFER, 0);
foreach (int l, locs)
foreach(int l, locs)
glDisableVertexAttribArray(l);
}
@@ -290,7 +297,7 @@ bool GLVBO::loadFromFile(const QString & filename) {
Box3D GLVBO::boundingBox() const {
if (vertices_.size() < 3) return Box3D();
int vcnt = vertices_.size() / 3;
//qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
// qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
GLfloat mix, miy, miz, max, may, maz;
Vector3d v0(vertices_[0], vertices_[1], vertices_[2]);
mix = max = v0.x;
@@ -298,7 +305,7 @@ Box3D GLVBO::boundingBox() const {
miz = maz = v0.z;
Box3D bound;
for (int t = 1; t < vcnt; ++t) {
int vi = t*3;
int vi = t * 3;
Vector3d v(vertices_[vi + 0], vertices_[vi + 1], vertices_[vi + 2]);
if (mix > v.x) mix = v.x;
if (max < v.x) max = v.x;
@@ -307,9 +314,9 @@ Box3D GLVBO::boundingBox() const {
if (miz > v.z) miz = v.z;
if (maz < v.z) maz = v.z;
}
bound.x = mix;
bound.y = miy;
bound.z = miz;
bound.x = mix;
bound.y = miy;
bound.z = miz;
bound.length = max - mix;
bound.width = may - miy;
bound.height = maz - miz;