Files
qglengine/formats/loader_qgl.cpp
2020-08-25 21:57:31 +03:00

68 lines
1.9 KiB
C++

/*
QGL Loader QGL
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 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/>.
*/
#include "loader_qgl.h"
#include "glscene.h"
#include <chunkstream.h>
Scene * loadFromQGLFile(const QString & filepath) {
QFile f(filepath);
if (!f.exists()) {
qDebug() << "[Loader QGL] Error: can`t open \"" + filepath + "\"";
return 0;
}
f.open(QIODevice::ReadOnly);
QDataStream s(&f);
s.setVersion(QDataStream::Qt_5_0);
char sign[4];
s.readRawData(sign, 4);
if ((sign[0] != 'Q') || (sign[1] != 'G') || (sign[2] != 'L') || (sign[3] != 'E')) {
qDebug() << "[Loader QGL] Error: \"" + filepath + "\" is not valid QGLEngine file!";
return 0;
}
ushort version = 0x1;
f.peek((char*)&version, 2);
if (version != 1) {
qDebug() << "[Loader QGL] Error: \"" + filepath + "\" unsupported version!";
return 0;
}
Scene * ret = 0;
s.skipRawData(2);
s >> ret;
//root->buildTransform();
qDebug() << "[Loader QGL] Loaded" << ret->objectsCount(true) << "objects from" << filepath;
return ret;
}
bool saveToQGLFile(const QString & filepath, const Scene * scene) {
QFile f(filepath);
if (!f.open(QIODevice::ReadWrite))
return false;
f.resize(0);
QDataStream s(&f);
s.setVersion(QDataStream::Qt_5_0);
char sign[4] = {'Q', 'G', 'L', 'E'};
ushort version = 0x1;
s.writeRawData(sign, 4);
s.writeRawData((char*)&version, 2);
s << scene;
return true;
}