Debian Codegraph @

src/tools.hpp

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 #pragma once
22
23 #include <QUrl>
24 #include <QString>
25 #include <QSurfaceFormat>
26 #include <QOpenGLExtraFunctions>
27
28 // Global boolean variable that tells if the OpenGL flavor is OpenGL ES or desktop GL
29 typedef enum {
30 OpenGL_Type_WebGL, OpenGL_Type_OpenGLES, OpenGL_Type_Desktop
31 } OpenGL_Type;
32 extern OpenGL_Type OpenGLType;
33 void initializeOpenGLType(const QSurfaceFormat& format);
34
35 // Read a complete file into a QString (without error checking;
36 // intended to be used for resource files)
37 QString readFile(const char* fileName);
38
39 // Check for OpenGL errors
40 #define CHECK_GL() \
41 { \
42 GLenum err = glGetError(); \
43 if (err != GL_NO_ERROR) { \
44 LOG_FATAL("%s:%d: OpenGL error 0x%04X in function %s", __FILE__, __LINE__, err, Q_FUNC_INFO); \
45 std::exit(1); \
46 } \
47 }
48
49 // Check for existence of GL_ARB_texture_filter_anisotropic
50 // or GL_EXT_texture_filter_anisotropic (which does the same)
51 #ifndef GL_TEXTURE_MAX_ANISOTROPY
52 # define GL_TEXTURE_MAX_ANISOTROPY 0x84FE
53 #endif
54 bool checkTextureAnisotropicFilterAvailability();
55
56 // Mipmap generation does not work on MacOS OpenGL 4.1, see https://github.com/marlam/bino/issues/25
57 // Simply disable all use of mipmaps as a crude workaround.
58 #if __APPLE__
59 #undef GL_LINEAR_MIPMAP_LINEAR
60 #define GL_LINEAR_MIPMAP_LINEAR GL_LINEAR
61 #endif
62
63 // Some fixups for WebGL
64 // TODO: these are not correct; each case hase to be fixed individually
65 #ifdef Q_OS_WASM
66 # define GL_CLAMP_TO_BORDER GL_CLAMP_TO_EDGE
67 # define GL_RGBA16 GL_RGBA
68 # define GL_RGB16 GL_RGB
69 # define GL_RG16 GL_RG
70 # define GL_R16 GL_RED
71 # define GL_BGRA GL_RGBA
72 #endif
73
74 // Shortcut to get a string from OpenGL
75 const char* getOpenGLString(QOpenGLExtraFunctions* gl, GLenum p);
76
77 // Shortcut to get an extension from a file name
78 QString getExtension(const QString& fileName);
79 QString getExtension(const QUrl& url);