From 25e3ac903556b1c9b44fd861884a570ba29390b8 Mon Sep 17 00:00:00 2001 From: hidefuku Date: Thu, 24 Nov 2016 22:22:03 +0900 Subject: [PATCH] Added version and device information --- src/AnimeEffects.pro | 2 +- src/common.pri | 8 ++++++- src/ctrl/Exporter.cpp | 2 +- src/ctrl/ProjectLoader.cpp | 4 ++-- src/ctrl/ProjectSaver.cpp | 4 ++-- src/ctrl/System.cpp | 15 +++++------- src/ctrl/System.h | 2 -- src/gl/DeviceInfo.cpp | 44 ++++++++++++++++++++++------------- src/gl/DeviceInfo.h | 8 ++++++- src/gui/Main.cpp | 8 +++---- src/gui/MainDisplayWidget.cpp | 7 ++++-- src/gui/MainDisplayWidget.h | 1 + src/gui/MainMenuBar.cpp | 25 +++++++++++++------- 13 files changed, 81 insertions(+), 49 deletions(-) diff --git a/src/AnimeEffects.pro b/src/AnimeEffects.pro index 53438413..d61277d6 100644 --- a/src/AnimeEffects.pro +++ b/src/AnimeEffects.pro @@ -21,7 +21,7 @@ export(copydata.commands) export(copytools.commands) QMAKE_EXTRA_TARGETS += first copydata copytools } -unix { +unix|macx { copydata.commands = rsync -ru $$shell_path($$PWD/../data) $$shell_path($$OUT_PWD) copytools.commands = rsync -ru $$shell_path($$PWD/../tools) $$shell_path($$OUT_PWD) first.depends = $(first) copydata copytools diff --git a/src/common.pri b/src/common.pri index 328e6040..6ede6ea4 100644 --- a/src/common.pri +++ b/src/common.pri @@ -13,7 +13,13 @@ HEADERS += \ $$PWD/XC.h \ $$PWD/XCAssert.h +DEFINES += "AE_MAJOR_VERSION=0" +DEFINES += "AE_MINOR_VERSION=8" + +DEFINES += "AE_PROJECT_FORMAT_MAJOR_VERSION=0" +DEFINES += "AE_PROJECT_FORMAT_MINOR_VERSION=1" + # OpenGL CoreProfile Option -unix { +unix|macx { DEFINES += USE_GL_CORE_PROFILE } diff --git a/src/ctrl/Exporter.cpp b/src/ctrl/Exporter.cpp index 6a450792..25fc9b14 100644 --- a/src/ctrl/Exporter.cpp +++ b/src/ctrl/Exporter.cpp @@ -151,7 +151,7 @@ bool Exporter::execute(const CommonParam& aCommon, const VideoParam& aVideo) mIsCanceled = false; { -#if defined(_WIN32) || defined(_WIN64) +#if defined(Q_OS_WIN) const QFileInfo localEncoderInfo("./tools/ffmpeg.exe"); const bool hasLocalEncoder = localEncoderInfo.exists() && localEncoderInfo.isExecutable(); const QString program = hasLocalEncoder ? QString(".\\tools\\ffmpeg") : QString("ffmpeg"); diff --git a/src/ctrl/ProjectLoader.cpp b/src/ctrl/ProjectLoader.cpp index 0923d3b3..9d7b15c9 100644 --- a/src/ctrl/ProjectLoader.cpp +++ b/src/ctrl/ProjectLoader.cpp @@ -126,11 +126,11 @@ bool ProjectLoader::readHeader(util::LEStreamReader& aIn) // major version const int majorVersion = aIn.readUInt32(); - if (majorVersion > 0) return false; + if (majorVersion > AE_PROJECT_FORMAT_MAJOR_VERSION) return false; // minor version const int minorVersion = aIn.readUInt32(); - if (minorVersion > 1) return false; + if (minorVersion > AE_PROJECT_FORMAT_MINOR_VERSION) return false; // reserved if (!aIn.skipZeroArea(16)) return false; diff --git a/src/ctrl/ProjectSaver.cpp b/src/ctrl/ProjectSaver.cpp index 705f1307..0d7e3b03 100644 --- a/src/ctrl/ProjectSaver.cpp +++ b/src/ctrl/ProjectSaver.cpp @@ -57,8 +57,8 @@ bool ProjectSaver::writeHeader(util::StreamWriter& aOut) { static const std::array kSignature{ 'A', 'N', 'I', 'M', 'F', 'X' }; static const std::array kEndian{ 0xff, 0x00 }; - static const uint32 kMajorVersion = 0; - static const uint32 kMinorVersion = 1; + static const uint32 kMajorVersion = AE_PROJECT_FORMAT_MAJOR_VERSION; + static const uint32 kMinorVersion = AE_PROJECT_FORMAT_MINOR_VERSION; static const int kReserveSize = 16; // signature diff --git a/src/ctrl/System.cpp b/src/ctrl/System.cpp index 50b65a5f..4de7534d 100644 --- a/src/ctrl/System.cpp +++ b/src/ctrl/System.cpp @@ -1,6 +1,7 @@ #include #include #include "gl/Global.h" +#include "gl/DeviceInfo.h" #include "ctrl/System.h" #include "ctrl/ProjectSaver.h" #include "ctrl/ProjectLoader.h" @@ -21,7 +22,6 @@ System::System(const QString& aResourceDir, const QString& aCacheDir) , mCacheDir(aCacheDir) , mProjects() , mAnimator() - , mGLDeviceInfo() { } @@ -35,11 +35,6 @@ void System::setAnimator(Animator& aAnimator) mAnimator = &aAnimator; } -void System::setGLDeviceInfo(const gl::DeviceInfo& aInfo) -{ - mGLDeviceInfo = aInfo; -} - core::Project* System::newProject( const QString& aFileName, const core::Project::Attribute& aAttr, @@ -50,6 +45,8 @@ core::Project* System::newProject( QScopedPointer hookScope(aHookGrabbed); XC_ASSERT(mAnimator); + XC_ASSERT(gl::DeviceInfo::validInstanceExists()); + gl::Global::makeCurrent(); QScopedPointer projectScope; @@ -57,7 +54,7 @@ core::Project* System::newProject( projectScope->attribute() = aAttr; projectScope->resourceHolder().setRootPath(QFileInfo(aFileName).path()); - ctrl::ImageFileLoader loader(mGLDeviceInfo); + ctrl::ImageFileLoader loader(gl::DeviceInfo::instance()); loader.setCanvasSize(aAttr.imageSize(), aSpecifiesCanvasSize); if (loader.load(aFileName, *projectScope, aReporter)) @@ -78,7 +75,7 @@ core::Project* System::openProject( QScopedPointer hookScope(aHookGrabbed); XC_ASSERT(mAnimator); - XC_ASSERT(mGLDeviceInfo.isValid()); + XC_ASSERT(gl::DeviceInfo::validInstanceExists()); gl::Global::makeCurrent(); @@ -88,7 +85,7 @@ core::Project* System::openProject( projectScope.reset(new Project(aFileName, *mAnimator, hookScope.take())); ctrl::ProjectLoader loader; - if (loader.load(aFileName, *projectScope, mGLDeviceInfo, aReporter)) + if (loader.load(aFileName, *projectScope, gl::DeviceInfo::instance(), aReporter)) { mProjects.push_back(projectScope.take()); return mProjects.back(); diff --git a/src/ctrl/System.h b/src/ctrl/System.h index edfaddc4..447c919e 100644 --- a/src/ctrl/System.h +++ b/src/ctrl/System.h @@ -17,7 +17,6 @@ class System : private util::NonCopyable ~System(); void setAnimator(core::Animator& aAnimator); - void setGLDeviceInfo(const gl::DeviceInfo& aInfo); core::Project* newProject( const QString& aFileName, @@ -51,7 +50,6 @@ class System : private util::NonCopyable const QString mCacheDir; QVector mProjects; core::Animator* mAnimator; - gl::DeviceInfo mGLDeviceInfo; }; } // namespace ctrl diff --git a/src/gl/DeviceInfo.cpp b/src/gl/DeviceInfo.cpp index 69d9bf66..5989921b 100644 --- a/src/gl/DeviceInfo.cpp +++ b/src/gl/DeviceInfo.cpp @@ -4,8 +4,7 @@ namespace { -static bool sIsDeviceInfoInitialized = false; -static gl::DeviceInfo sDeviceInfo; +static const gl::DeviceInfo* sDeviceInfoPtr; } // namespace namespace gl @@ -13,21 +12,40 @@ namespace gl const DeviceInfo& DeviceInfo::instance() { - XC_PTR_ASSERT(sIsDeviceInfoInitialized); - return sDeviceInfo; + XC_PTR_ASSERT(sDeviceInfoPtr); + return *sDeviceInfoPtr; } -void DeviceInfo::createInstance() +void DeviceInfo::setInstance(const DeviceInfo* aInstance) +{ + sDeviceInfoPtr = aInstance; +} + +bool DeviceInfo::validInstanceExists() +{ + return sDeviceInfoPtr && sDeviceInfoPtr->isValid(); +} + +DeviceInfo::DeviceInfo() + : vender() + , renderer() + , version() + , maxTextureSize(0) + , maxRenderBufferSize(0) +{ +} + +void DeviceInfo::load() { Global::makeCurrent(); auto& ggl = Global::functions(); - DeviceInfo info; - ggl.glGetIntegerv(GL_MAX_TEXTURE_SIZE, &info.maxTextureSize); - ggl.glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &info.maxRenderBufferSize); + vender = std::string((const char*)ggl.glGetString(GL_VENDOR)); + renderer = std::string((const char*)ggl.glGetString(GL_RENDERER)); + version = std::string((const char*)ggl.glGetString(GL_VERSION)); - sDeviceInfo = info; - sIsDeviceInfoInitialized = true; + ggl.glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); + ggl.glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxRenderBufferSize); #if 0 GLint val = 0; @@ -58,12 +76,6 @@ void DeviceInfo::createInstance() #endif } -DeviceInfo::DeviceInfo() - : maxTextureSize(0) - , maxRenderBufferSize(0) -{ -} - bool DeviceInfo::isValid() const { return maxTextureSize > 0 && maxRenderBufferSize > 0; diff --git a/src/gl/DeviceInfo.h b/src/gl/DeviceInfo.h index c679d05d..5295aef9 100644 --- a/src/gl/DeviceInfo.h +++ b/src/gl/DeviceInfo.h @@ -1,6 +1,7 @@ #ifndef GL_DEVICEINFO_H #define GL_DEVICEINFO_H +#include #include namespace gl @@ -8,12 +9,17 @@ namespace gl struct DeviceInfo { + static void setInstance(const DeviceInfo* aInstance); + static bool validInstanceExists(); static const DeviceInfo& instance(); - static void createInstance(); DeviceInfo(); + void load(); bool isValid() const; + std::string vender; + std::string renderer; + std::string version; GLint maxTextureSize; GLint maxRenderBufferSize; }; diff --git a/src/gui/Main.cpp b/src/gui/Main.cpp index 63d4f769..030b0255 100644 --- a/src/gui/Main.cpp +++ b/src/gui/Main.cpp @@ -508,6 +508,7 @@ int entryPoint(int argc, char *argv[]) // create qt application QApplication app(argc, argv); + // unicode argments const QStringList uniArgs = app.arguments(); @@ -529,6 +530,7 @@ int entryPoint(int argc, char *argv[]) // language QString preferFont; + QScopedPointer translator; { QString locAbb; #if 1 @@ -541,9 +543,9 @@ int entryPoint(int argc, char *argv[]) if (!locAbb.isEmpty()) { - auto translator = new QTranslator(); + translator.reset(new QTranslator()); translator->load("translation_" + locAbb, "data/locale"); - app.installTranslator(translator); + app.installTranslator(translator.data()); } { @@ -586,8 +588,6 @@ int entryPoint(int argc, char *argv[]) qDebug() << "show main window"; // show main window mainWindow->showWithSettings(); - // set opengl device info - system->setGLDeviceInfo(gl::DeviceInfo::instance()); #if !defined(QT_NO_DEBUG) qDebug() << "test new project"; diff --git a/src/gui/MainDisplayWidget.cpp b/src/gui/MainDisplayWidget.cpp index 35418322..586eb913 100644 --- a/src/gui/MainDisplayWidget.cpp +++ b/src/gui/MainDisplayWidget.cpp @@ -20,6 +20,7 @@ namespace gui MainDisplayWidget::MainDisplayWidget(ViaPoint& aViaPoint, QWidget* aParent) : QOpenGLWidget(aParent) , mViaPoint(aViaPoint) + , mGLDeviceInfo() , mProject() , mGLRoot() , mGLContextAccessor(this) @@ -119,6 +120,7 @@ MainDisplayWidget::~MainDisplayWidget() mFramebuffer.reset(); mDefaultVAO.reset(); + gl::DeviceInfo::setInstance(nullptr); gl::Global::clearFunctions(); } @@ -203,8 +205,9 @@ void MainDisplayWidget::initializeGL() mGLRoot.setFunctions(*functions); // initialize opengl device info - gl::DeviceInfo::createInstance(); - mViaPoint.setGLDeviceInfo(gl::DeviceInfo::instance()); + mGLDeviceInfo.load(); + gl::DeviceInfo::setInstance(&mGLDeviceInfo); + mViaPoint.setGLDeviceInfo(mGLDeviceInfo); #ifdef USE_GL_CORE_PROFILE // initialize default vao diff --git a/src/gui/MainDisplayWidget.h b/src/gui/MainDisplayWidget.h index 2b93d504..b0cef1a8 100644 --- a/src/gui/MainDisplayWidget.h +++ b/src/gui/MainDisplayWidget.h @@ -76,6 +76,7 @@ class MainDisplayWidget : public QOpenGLWidget void updatePenInfo(QEvent::Type aType, const QPoint& aPos, float aPressure); ViaPoint& mViaPoint; + gl::DeviceInfo mGLDeviceInfo; util::LinkPointer mProject; gl::Root mGLRoot; GLContextAccessor mGLContextAccessor; diff --git a/src/gui/MainMenuBar.cpp b/src/gui/MainMenuBar.cpp index b1153658..6d1b7152 100644 --- a/src/gui/MainMenuBar.cpp +++ b/src/gui/MainMenuBar.cpp @@ -141,18 +141,27 @@ MainMenuBar::MainMenuBar(MainWindow& aMainWindow, ViaPoint& aViaPoint, QWidget* QMenu* helpMenu = new QMenu(tr("Help"), this); { - QAction* aboutMe = new QAction("About Anime Effects...", this); + QAction* aboutMe = new QAction("About AnimeEffects...", this); connect(aboutMe, &QAction::triggered, [=]() { QMessageBox msgBox; msgBox.setIcon(QMessageBox::Information); - msgBox.setText("Anime Effects (Version 0.9.0)"); - - QString infoText; - infoText += "Build ABI : " + QSysInfo::buildAbi() + "\n"; - //infoText += "Build CPU : " + QSysInfo::buildCpuArchitecture() + "\n"; - //infoText += "Current CPU : " + QSysInfo::currentCpuArchitecture() + "\n"; - msgBox.setInformativeText(infoText); + auto versionString = QString::number(AE_MAJOR_VERSION) + "." + QString::number(AE_MINOR_VERSION); + auto formatVersionString = QString::number(AE_PROJECT_FORMAT_MAJOR_VERSION) + "." + QString::number(AE_PROJECT_FORMAT_MINOR_VERSION); + auto platform = QSysInfo::productType(); + msgBox.setText(QString("AnimeEffects for ") + platform + " version " + versionString); + + QString detail; + detail += "Version: " + versionString + "\n"; + detail += "Platform: " + platform + " " + QSysInfo::productVersion() + "\n"; + detail += "Build ABI: " + QSysInfo::buildAbi() + "\n"; + detail += "Build CPU: " + QSysInfo::buildCpuArchitecture() + "\n"; + detail += "Current CPU: " + QSysInfo::currentCpuArchitecture() + "\n"; + detail += "Current GPU: " + QString(this->mViaPoint.glDeviceInfo().renderer.c_str()) + "\n"; + detail += "GPU Vender: " + QString(this->mViaPoint.glDeviceInfo().vender.c_str()) + "\n"; + detail += "OpenGL Version: " + QString(this->mViaPoint.glDeviceInfo().version.c_str()) + "\n"; + detail += "Format Version: " + formatVersionString + "\n"; + msgBox.setDetailedText(detail); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok);