forked from azagaya/laigter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
222 lines (187 loc) · 7.12 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* Laigter: an automatic map generator for lighting effects.
* Copyright (C) 2019 Pablo Ivan Fonovich
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* Contact: azagaya.games@gmail.com
*/
#include "gui/presets_manager.h"
#include "main_window.h"
#include "src/image_processor.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QOpenGLContext>
#include <QSplashScreen>
#include <QStandardPaths>
#include <QTranslator>
#define cimg_use_openmp 1
QCoreApplication *createApplication(int &argc, char *argv[])
{
for (int i = 1; i < argc; ++i)
if (!qstrcmp(argv[i], "--no-gui"))
return new QCoreApplication(argc, argv);
return new QApplication(argc, argv);
}
int main(int argc, char *argv[])
{
QCoreApplication::setApplicationName("laigter");
QCoreApplication::setApplicationVersion("1.10.2-beta");
//QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
#ifndef PORTABLE
QString appData =
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
QDir dir(appData);
if (!dir.exists())
dir.mkpath(".");
dir = QDir(appData + "/presets");
if (!dir.exists())
dir.mkpath(".");
dir = QDir(appData + "/plugins");
if (!dir.exists())
dir.mkpath(".");
#else
QDir dir("./presets");
if (!dir.exists())
dir.mkpath(".");
#endif
QCommandLineParser argsParser;
argsParser.setApplicationDescription("Test helper");
argsParser.addHelpOption();
argsParser.addVersionOption();
QCommandLineOption softOpenGl(QStringList() << "s"
<< "software-opengl",
"Use software opengl renderer.");
argsParser.addOption(softOpenGl);
QCommandLineOption noGuiOption(QStringList() << "g"
<< "no-gui",
"do not start graphical interface");
argsParser.addOption(noGuiOption);
QCommandLineOption inputDiffuseTextureOption(QStringList() << "d"
<< "diffuse",
"diffuse texture to load",
"diffuse texture path");
argsParser.addOption(inputDiffuseTextureOption);
QCommandLineOption outputNormalTextureOption(QStringList() << "n"
<< "normal",
"generate normals");
argsParser.addOption(outputNormalTextureOption);
QCommandLineOption outputSpecularTextureOption(QStringList() << "c"
<< "specular",
"generate specular");
argsParser.addOption(outputSpecularTextureOption);
QCommandLineOption outputOcclusionTextureOption(QStringList()
<< "o"
<< "occlusion",
"generate occlusion");
argsParser.addOption(outputOcclusionTextureOption);
QCommandLineOption outputParallaxTextureOption(QStringList() << "p"
<< "parallax",
"generate parallax");
argsParser.addOption(outputParallaxTextureOption);
QCommandLineOption pressetOption(QStringList() << "r"
<< "preset",
"presset to load", "preset file path");
argsParser.addOption(pressetOption);
QSurfaceFormat fmt;
fmt.setDepthBufferSize(24);
fmt.setSamples(16);
fmt.setProfile(QSurfaceFormat::CompatibilityProfile);
QSurfaceFormat::setDefaultFormat(fmt);
QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
argsParser.process(*app.data());
QImage auximage;
ImageProcessor *processor = new ImageProcessor();
bool success = false;
QString inputDiffuseTextureOptionValue =
argsParser.value(inputDiffuseTextureOption);
if (!inputDiffuseTextureOptionValue.trimmed().isEmpty())
{
QFileInfo info(inputDiffuseTextureOptionValue);
QString suffix =
info.suffix(); // just the last suffix, not the complete one
QString pressetOptionValue = argsParser.value(pressetOption);
ImageLoader il;
auximage = il.loadImage(inputDiffuseTextureOptionValue, &success);
auximage =
auximage.convertToFormat(QImage::Format_RGBA8888_Premultiplied);
if (!pressetOptionValue.trimmed().isEmpty())
{
processor->recalculate_timer.stop();
PresetsManager::applyPresets(pressetOptionValue, *processor);
}
processor->loadImage(inputDiffuseTextureOptionValue, auximage);
QString pathWithoutExtension =
info.absoluteFilePath().remove("." + suffix);
if (argsParser.isSet(outputNormalTextureOption))
{
QImage normal = *processor->get_normal();
QString name = pathWithoutExtension + "_n." + suffix;
normal.save(name);
}
if (argsParser.isSet(outputSpecularTextureOption))
{
QImage specular = *processor->get_specular();
QString name = pathWithoutExtension + "_s." + suffix;
specular.save(name);
}
if (argsParser.isSet(outputOcclusionTextureOption))
{
QImage occlusion = *processor->get_occlusion();
QString name = pathWithoutExtension + "_o." + suffix;
occlusion.save(name);
}
if (argsParser.isSet(outputParallaxTextureOption))
{
QImage parallax = *processor->get_parallax();
QString name = pathWithoutExtension + "_p." + suffix;
parallax.save(name);
}
}
QApplication *a = qobject_cast<QApplication *>(app.data());
int returnCode;
if (a)
{
bool softOpenGlValue = argsParser.isSet(softOpenGl);
if (softOpenGlValue)
{
a->setAttribute(Qt::AA_UseSoftwareOpenGL);
qDebug() << "Soft OpenGL";
}
MainWindow w;
QGuiApplication::setWindowIcon(QIcon(":/images/laigter_icon.png"));
w.show();
qRegisterMetaType<ProcessedImage>("ProcessedImage");
if (success)
w.add_processor(processor);
else
delete processor;
/* Load Project if dropped. Only supports one project */
if (argsParser.positionalArguments().count() > 0)
{
QString project_path = argsParser.positionalArguments().at(0);
w.LoadProject(project_path);
}
returnCode = app->exec();
}
else
{
// do CLI only things here
returnCode = 0;
}
return returnCode;
}