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,47 +1,50 @@
/*
QGL TonemappingProc
Ivan Pelipenko peri4ko@yandex.ru
QGL TonemappingProc
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/>.
*/
#define GL_GLEXT_PROTOTYPES
#include <QOpenGLExtraFunctions>
#include "tonemapping_proc.h"
#include "qglview.h"
#include <QOpenGLExtraFunctions>
#include <qad_types.h>
using namespace QGLEngineShaders;
TonemappingProc::TonemappingProc(Renderer * rend): QThread(), r(rend),
fbo_1x1(r->view, 1, false, GL_RGB32F),
fbomm(r->fbo_out, Renderer::obrSum, 3),
buffer_vbo(GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW) {
shader_sum = 0;
TonemappingProc::TonemappingProc(Renderer * rend)
: QThread()
, r(rend)
, fbo_1x1(r->view, 1, false, GL_RGB32F)
, fbomm(r->fbo_out, Renderer::obrSum, 3)
, buffer_vbo(GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW) {
shader_sum = 0;
timer_delim = 0;
frame_max = cur_max = 1.;
need_render_sum = exit_ = false;
enabled = false;
timer_tone = startTimer(10);
enabled = false;
timer_tone = startTimer(10);
}
TonemappingProc::~TonemappingProc() {
exit_ = true;
if (!wait(1000))
terminate();
if (!wait(1000)) terminate();
killTimer(timer_tone);
if (shader_sum) delete shader_sum;
}
@@ -70,13 +73,13 @@ void TonemappingProc::init() {
void TonemappingProc::resize() {
QOpenGLExtraFunctions * f = r->view;
fbomm.resize();
int pcnt = fbomm.width(fbomm.lastLevel()) * fbomm.height(fbomm.lastLevel());
int pcnt = fbomm.width(fbomm.lastLevel()) * fbomm.height(fbomm.lastLevel());
QVector<Vector2i> _data;
_data.resize(pcnt);
pcnt = -1;
for (int x = 0; x < fbomm.width(fbomm.lastLevel()); ++x)
for (int y = 0; y < fbomm.height(fbomm.lastLevel()); ++y)
_data[++pcnt] = Vector2i(x,y);
_data[++pcnt] = Vector2i(x, y);
buffer_vbo.bind(f);
buffer_vbo.resize(f, _data.size() * sizeof(Vector2i));
buffer_vbo.load(f, _data.constData(), _data.size() * sizeof(Vector2i));
@@ -85,8 +88,7 @@ void TonemappingProc::resize() {
void TonemappingProc::timerEvent(QTimerEvent * e) {
if (!fbo_1x1.isInit() || !enabled) return;
if (timer_delim == 0)
need_render_sum = true;
if (timer_delim == 0) need_render_sum = true;
timer_delim = (timer_delim + 1) % 10;
mutex.lock();
float fmax = frame_max;
@@ -98,7 +100,7 @@ void TonemappingProc::timerEvent(QTimerEvent * e) {
void TonemappingProc::renderSum(Framebuffer & fbo_src, int index) {
QOpenGLExtraFunctions * f = r->view;
int pcnt = fbo_src.width() * fbo_src.height();
int pcnt = fbo_src.width() * fbo_src.height();
fbo_src.bindColorTexture(index);
fbo_1x1.bind();
glClearFramebuffer();
@@ -139,8 +141,7 @@ void TonemappingProc::run() {
mutex.unlock();
float max = calcHistogram(data);
last_max << max;
if (last_max.size() > 5)
last_max.removeAt(0);
if (last_max.size() > 5) last_max.removeAt(0);
float cm = last_max[0];
for (int i = 1; i < last_max.size(); ++i)
cm += last_max[i];
@@ -156,9 +157,9 @@ float TonemappingProc::calcHistogram(const QVector<QVector4D> & data) {
if (data.isEmpty()) return 1.f;
float max = 0.;
QVector3D luma(0.299, 0.587, 0.114);
foreach (const QVector4D & p, data) {
foreach(const QVector4D & p, data) {
float l = QVector3D::dotProduct(p.toVector3D(), luma);
max = qMax(max, l);
max = qMax(max, l);
}
return max;
}