Debian Codegraph @

src/tools.cpp

raw
1 /*
2 * This file is part of Bino, a 3D video player.
3 *
4 * Copyright (C) 2022, 2023, 2024, 2025
5 * Martin Lambers <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <QFile>
22 #include <QTextStream>
23 #include <QOpenGLContext>
24 #include <QOpenGLExtraFunctions>
25
26 #include "tools.hpp"
27
28
29 OpenGL_Type OpenGLType;
30 void initializeOpenGLType(const QSurfaceFormat& format)
31 {
32 #ifdef Q_OS_WASM
33 OpenGLType = OpenGL_Type_WebGL;
34 #else
35 OpenGLType = (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES
36 || format.renderableType() == QSurfaceFormat::OpenGLES)
37 ? OpenGL_Type_OpenGLES : OpenGL_Type_Desktop;
38 #endif
39 }
40
41 QString readFile(const char* fileName)
42 {
43 QString s;
44 QFile f(fileName);
45 bool ok = f.open(QIODevice::ReadOnly);
46 if (ok) {
47 QTextStream in(&f);
48 s = in.readAll();
49 }
50 return s;
51 }
52
53 bool checkTextureAnisotropicFilterAvailability()
54 {
55 return QOpenGLContext::currentContext()->hasExtension("GL_ARB_texture_filter_anisotropic")
56 || QOpenGLContext::currentContext()->hasExtension("GL_EXT_texture_filter_anisotropic");
57 }
58
59 const char* getOpenGLString(QOpenGLExtraFunctions* gl, GLenum p)
60 {
61 return reinterpret_cast<const char*>(gl->glGetString(p));
62 }
63
64 QString getExtension(const QString& fileName)
65 {
66 QString extension;
67 int lastDot = fileName.lastIndexOf('.');
68 if (lastDot > 0)
69 extension = (fileName.right(fileName.length() - lastDot - 1)).toLower();
70 return extension;
71 }
72
73 QString getExtension(const QUrl& url)
74 {
75 return getExtension(url.fileName());
76 }