code format

This commit is contained in:
2022-12-14 14:14:44 +03:00
parent 1dfca0aeab
commit cb944b62e4
85 changed files with 4451 additions and 3744 deletions

View File

@@ -1,23 +1,24 @@
/*
QGL CubeTexture
Ivan Pelipenko peri4ko@yandex.ru
QGL CubeTexture
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 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.
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 <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gltypes.h"
#include "glcubemap.h"
#include "gltypes.h"
#include "hdr_p.h"
using namespace QGLEngineShaders;
@@ -51,9 +52,9 @@ QVector<QVector3D> loadFileHDR(const QString & path, QSize * size) {
qDebug() << "[QGLEngine] File" << path << "has unknown size!";
return ret;
}
sz.setWidth (sl[3].toInt());
sz.setWidth(sl[3].toInt());
sz.setHeight(sl[1].toInt());
//qDebug() << "found size" << sz;
// qDebug() << "found size" << sz;
break;
}
}
@@ -61,26 +62,23 @@ QVector<QVector3D> loadFileHDR(const QString & path, QSize * size) {
f.seek(ts.pos());
QDataStream ds(&f);
int count = sz.width() * sz.height();
QVector<float> data(count*3);
if (!RGBE_ReadPixels_RLE(&ds, data.data(), sz.width(), sz.height()))
return ret;
QVector<float> data(count * 3);
if (!RGBE_ReadPixels_RLE(&ds, data.data(), sz.width(), sz.height())) return ret;
if (size) *size = sz;
ret.resize(count);
//QColor col;
//QImage im(sz, QImage::Format_ARGB32);
//QRgb * imdata = (QRgb*)im.bits();
// QColor col;
// QImage im(sz, QImage::Format_ARGB32);
// QRgb * imdata = (QRgb*)im.bits();
for (int i = 0; i < count; ++i) {
QVector3D p(pow(data[i*3 + 2], 1. / 2.2),
pow(data[i*3 + 1], 1. / 2.2),
pow(data[i*3 + 0], 1. / 2.2));
QVector3D p(pow(data[i * 3 + 2], 1. / 2.2), pow(data[i * 3 + 1], 1. / 2.2), pow(data[i * 3 + 0], 1. / 2.2));
ret[i] = p;
//col = QColor::fromRgbF(piClamp(p[0], 0.f, 1.f),
// col = QColor::fromRgbF(piClamp(p[0], 0.f, 1.f),
// piClamp(p[1], 0.f, 1.f),
// piClamp(p[2], 0.f, 1.f));
//imdata[i] = col.rgb();
// imdata[i] = col.rgb();
}
//im.save("_hdr.png");
// im.save("_hdr.png");
return ret;
}
@@ -90,72 +88,71 @@ QVector<QVector3D> faceHDR(const QVector<QVector3D> & data, QSize sz, QSize & fs
QVector<QVector3D> ret;
if (data.isEmpty() || sz.isNull()) return ret;
QRect fr;
int fw = sz.width () / 4;
int fw = sz.width() / 4;
int fh = sz.height() / 3;
fsz = QSize(fw, fh);
fsz = QSize(fw, fh);
ret.reserve(fw * fh);
switch (face) {
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
fr.setRect(fw, fh, fw, fh);
for (int x = fr.left(); x <= fr.right(); ++x) {
for (int y = fr.top(); y <= fr.bottom(); ++y) {
ret << data[y*sz.width() + x];
ret << data[y * sz.width() + x];
}
}
break;
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
fr.setRect(fw*3, fh, fw, fh);
fr.setRect(fw * 3, fh, fw, fh);
for (int x = fr.right(); x >= fr.left(); --x) {
for (int y = fr.bottom(); y >= fr.top(); --y) {
ret << data[y*sz.width() + x];
ret << data[y * sz.width() + x];
}
}
break;
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
fr.setRect( 0, fh, fw, fh);
fr.setRect(0, fh, fw, fh);
for (int y = fr.bottom(); y >= fr.top(); --y) {
for (int x = fr.left(); x <= fr.right(); ++x) {
ret << data[y*sz.width() + x];
ret << data[y * sz.width() + x];
}
}
break;
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
fr.setRect(fw*2, fh, fw, fh);
fr.setRect(fw * 2, fh, fw, fh);
for (int y = fr.top(); y <= fr.bottom(); ++y) {
for (int x = fr.right(); x >= fr.left(); --x) {
ret << data[y*sz.width() + x];
ret << data[y * sz.width() + x];
}
}
break;
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
fr.setRect(fw, 0, fw, fh);
fr.setRect(fw, 0, fw, fh);
for (int x = fr.left(); x <= fr.right(); ++x) {
for (int y = fr.top(); y <= fr.bottom(); ++y) {
ret << data[y*sz.width() + x];
ret << data[y * sz.width() + x];
}
}
break;
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
fr.setRect(fw, fh*2, fw, fh);
fr.setRect(fw, fh * 2, fw, fh);
for (int x = fr.left(); x <= fr.right(); ++x) {
for (int y = fr.top(); y <= fr.bottom(); ++y) {
ret << data[y*sz.width() + x];
ret << data[y * sz.width() + x];
}
}
break;
default: break;
}
if (fr.isEmpty()) return ret;
//qDebug() << ret.size() << fr;
// qDebug() << ret.size() << fr;
return ret;
}
CubeTexture::CubeTexture(QOpenGLExtraFunctions * f_, int _size, const GLenum & _format): f(f_) {
size = _size;
format_ = _format;
id_ = 0;
size = _size;
format_ = _format;
id_ = 0;
changed_ = false;
}
@@ -199,9 +196,17 @@ void CubeTexture::loadHDR(const QVector<QVector3D> & data, QSize sz) {
QVector<QVector3D> fd;
for (int i = 0; i < 6; ++i) {
fd = faceHDR(data, sz, fsz, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
//qDebug() << "load cube" << fd[0];
f->glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format_, fsz.width(), fsz.height(), 0, GL_RGB, GL_FLOAT, fd.isEmpty() ? 0 : fd.constData());
//qDebug() << QString::number(GetLastError(), 16);
// qDebug() << "load cube" << fd[0];
f->glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
0,
format_,
fsz.width(),
fsz.height(),
0,
GL_RGB,
GL_FLOAT,
fd.isEmpty() ? 0 : fd.constData());
// qDebug() << QString::number(GetLastError(), 16);
}
f->glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
}
@@ -230,4 +235,3 @@ void CubeTexture::load() {
}
changed_ = false;
}