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,35 +1,41 @@
/*
QGLEngineShaders
Ivan Pelipenko peri4ko@yandex.ru
QGLEngineShaders
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 "glshaders.h"
#include "glshaders_headers.h"
#include "gltypes.h"
#include "qglview.h"
#include "glshaders.h"
#include "glshaders_headers.h"
using namespace QGLEngineShaders;
bool addShader(QOpenGLShaderProgram * prog, QOpenGLShader::ShaderType type, QString & content, const QString & file, bool add_qgl, const QString & defs) {
bool addShader(QOpenGLShaderProgram * prog,
QOpenGLShader::ShaderType type,
QString & content,
const QString & file,
bool add_qgl,
const QString & defs) {
if (type == 0 || content.isEmpty()) {
content.clear();
return true;
}
//qDebug() << "[QGLEngine] Shader" << file << "found" << (QOpenGLShader::ShaderTypeBit)(int)type << "section ...";
// qDebug() << "[QGLEngine] Shader" << file << "found" << (QOpenGLShader::ShaderTypeBit)(int)type << "section ...";
if (add_qgl) {
switch (type) {
case QOpenGLShader::Fragment:
@@ -37,12 +43,8 @@ bool addShader(QOpenGLShaderProgram * prog, QOpenGLShader::ShaderType type, QStr
content.prepend(qgl_uniform);
content.prepend(qgl_structs);
break;
case QOpenGLShader::Vertex :
content.prepend(qgl_vertex_head );
break;
case QOpenGLShader::Geometry:
content.prepend(qgl_geometry_head);
break;
case QOpenGLShader::Vertex: content.prepend(qgl_vertex_head); break;
case QOpenGLShader::Geometry: content.prepend(qgl_geometry_head); break;
}
}
content.prepend(defs);
@@ -57,15 +59,14 @@ bool addShader(QOpenGLShaderProgram * prog, QOpenGLShader::ShaderType type, QStr
QString prepareDefines(const QStringList & defines) {
if (defines.isEmpty()) return QString();
QString ret;
foreach (QString s, defines)
foreach(QString s, defines)
ret.append("#define " + s + "\n");
return ret;
}
bool QGLEngineShaders::loadShadersMulti(QOpenGLShaderProgram *& prog, const QString & file, bool add_qgl, const QStringList & defines) {
if (!prog)
prog = new QOpenGLShaderProgram();
if (!prog) prog = new QOpenGLShaderProgram();
QFile f(file);
if (!f.open(QIODevice::ReadOnly)) {
qDebug() << "[QGLEngine] Shader" << file << "Error: can`t open file!";
@@ -76,7 +77,7 @@ bool QGLEngineShaders::loadShadersMulti(QOpenGLShaderProgram *& prog, const QStr
QOpenGLShader::ShaderType type = QOpenGLShader::ShaderType();
while (!ts.atEnd()) {
line = ts.readLine();
pl = line.trimmed().remove(' ').remove('\t').mid(2).toLower();
pl = line.trimmed().remove(' ').remove('\t').mid(2).toLower();
pl.chop(2);
if (pl == "vertex" || pl == "vert") {
if (!addShader(prog, type, cur_shader, file, add_qgl, defs)) return false;
@@ -117,14 +118,13 @@ bool QGLEngineShaders::loadShadersMulti(QOpenGLShaderProgram *& prog, const QStr
bool QGLEngineShaders::loadShaders(QOpenGLShaderProgram *& prog, const QStringList & files, bool add_qgl, const QStringList & defines) {
if (!prog)
prog = new QOpenGLShaderProgram();
if (!prog) prog = new QOpenGLShaderProgram();
prog->removeAllShaders();
QString cur_shader, defs = prepareDefines(defines);
foreach (QString f, files) {
foreach(QString f, files) {
QFileInfo fi(f);
QOpenGLShader::ShaderType type = QOpenGLShader::ShaderType();
if (fi.suffix().toLower() == "vert") type = QOpenGLShader::Vertex ;
if (fi.suffix().toLower() == "vert") type = QOpenGLShader::Vertex;
if (fi.suffix().toLower() == "frag") type = QOpenGLShader::Fragment;
if (fi.suffix().toLower() == "geom") type = QOpenGLShader::Geometry;
if (type == 0) continue;