Add OpenGL information to about page

Tue, 28 Jun 2022 19:21:37 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 28 Jun 2022 19:21:37 +0300
changeset 293
9f85a54ead29
parent 292
f071ec94c022
child 294
70b69a15c736

Add OpenGL information to about page

src/about.ui file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
--- a/src/about.ui	Tue Jun 28 18:02:51 2022 +0300
+++ b/src/about.ui	Tue Jun 28 19:21:37 2022 +0300
@@ -36,11 +36,18 @@
 &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'EPSONEXT 丸ゴシック体M'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
 &lt;h1 style=&quot; margin-top:18px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;img src=&quot;:/icons/appicon.png&quot; height=&quot;64&quot; /&gt;&lt;span style=&quot; font-size:xx-large; font-weight:600;&quot;&gt; %APPNAME% %VERSION%&lt;/span&gt;&lt;/h1&gt;
 &lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Qt version: %QTVERSION%&lt;/p&gt;
+&lt;hr /&gt;
+&lt;h2 style=&quot; margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:x-large; font-weight:600;&quot;&gt;Build time information&lt;/span&gt;&lt;/h2&gt;
+&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;The following information was gathered during the build of this program.&lt;/p&gt;
 &lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%GLMVERSIONSTRING%&lt;/p&gt;
 &lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Build type: %BUILDTYPE%&lt;/p&gt;
 &lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Compiler: %COMPILER_ID% %COMPILER_VERSION%&lt;/p&gt;
 &lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Compiler system: %COMPILER_SYSTEM% (%COMPILER_CPU%)&lt;/p&gt;
-&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Compiler flags: %COMPILER_FLAGS%&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Compiler flags: %COMPILER_FLAGS%&lt;/p&gt;
+&lt;hr /&gt;
+&lt;h2 style=&quot; margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:x-large; font-weight:600;&quot;&gt;OpenGL information&lt;/span&gt;&lt;/h2&gt;
+&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;OpenGL version: %GL_VERSION%&lt;/p&gt;
+&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;OpenGL Extensions: %GL_EXTENSIONS%&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
         </widget>
        </item>
--- a/src/main.cpp	Tue Jun 28 18:02:51 2022 +0300
+++ b/src/main.cpp	Tue Jun 28 19:21:37 2022 +0300
@@ -20,6 +20,7 @@
 #include "src/ui/objecteditor.h"
 #include "src/version.h"
 #include "src/widgets/colorselectdialog.h"
+#include <GL/glew.h>
 
 static const QDir LOCALE_DIR {":/locale"};
 
@@ -380,6 +381,17 @@
 	QDialog dialog{parent};
 	Ui_About ui;
 	ui.setupUi(&dialog);
+	const char* glVersion = reinterpret_cast<const char*>(glGetString(GL_VERSION));
+	const QString extensions = []{
+		GLint numExtensions;
+		glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
+		QStringList extensionsList;
+		for (GLint i = 0; i < numExtensions; i++) {
+			const GLubyte* ext = glGetStringi(GL_EXTENSIONS, i);
+			extensionsList.push_back(reinterpret_cast<const char*>(ext));
+		}
+		return extensionsList.join(" ");
+	}();
 	for (QTextBrowser* browser : dialog.findChildren<QTextBrowser*>()) {
 		browser->setHtml(
 			browser->toHtml()
@@ -395,6 +407,8 @@
 			.replace("%COMPILER_CPU%", CMAKE_SYSTEM_PROCESSOR)
 			.replace("%COMPILER_SYSTEM%", CMAKE_SYSTEM)
 			.replace("%GLMVERSIONSTRING%", GLM_VERSION_MESSAGE)
+			.replace("%GL_VERSION%", glVersion)
+			.replace("%GL_EXTENSIONS%", extensions)
 		);
 	}
 	dialog.setWindowTitle(QObject::tr("About %1").arg(CMAKE_PROJECT_NAME));
@@ -775,7 +789,14 @@
 	QObject::connect(
 		ui.actionAbout,
 		&QAction::triggered,
-		[&mainWindow]{about(&mainWindow);}
+		[&mainWindow, &ui]{
+			// Make sure that there's an OpenGL context active, otherwise
+			// we cannot obtain OpenGL information
+			if (ui.mdiArea->findChildren<ModelSubWindow*>().empty()) {
+				ui.actionNew->trigger();
+			}
+			about(&mainWindow);
+		}
 	);
 	mainWindow.tabifyDockWidget(ui.messageLogDock, ui.toolOptionsDock);
 	mainWindow.restoreGeometry(setting<Setting::MainWindowGeometry>());

mercurial