From 4a0fa11f0fd0b15225d017f2f9ad07fc8a1d4f00 Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Fri, 5 Dec 2025 12:28:15 +0100 Subject: [PATCH] Move GLSL version check to ProjectM class constructor Log a fatal error if it fails. --- .../MilkdropStaticShaders.cpp.in | 11 ------ .../MilkdropStaticShaders.hpp.in | 1 - src/libprojectM/ProjectM.cpp | 38 +++++++++++++++---- src/libprojectM/ProjectM.hpp | 2 + 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/libprojectM/MilkdropPreset/MilkdropStaticShaders.cpp.in b/src/libprojectM/MilkdropPreset/MilkdropStaticShaders.cpp.in index 8648ed413..973ca8571 100644 --- a/src/libprojectM/MilkdropPreset/MilkdropStaticShaders.cpp.in +++ b/src/libprojectM/MilkdropPreset/MilkdropStaticShaders.cpp.in @@ -13,17 +13,6 @@ namespace MilkdropPreset { MilkdropStaticShaders::MilkdropStaticShaders(bool useGLES) : m_useGLES(useGLES) { - m_GLSLVersion = Renderer::Shader::GetShaderLanguageVersion(); - - if (m_GLSLVersion.major == 0) - { - throw std::runtime_error("Could not retrieve OpenGL shader language version. Is OpenGL available and the context initialized?"); - } - if (m_GLSLVersion.major < 3) - { - throw std::runtime_error("OpenGL shader language version 3 or higher is required, but not available in the current context."); - } - if (m_useGLES) { // If GLES is enabled, use the embedded specification language variant. diff --git a/src/libprojectM/MilkdropPreset/MilkdropStaticShaders.hpp.in b/src/libprojectM/MilkdropPreset/MilkdropStaticShaders.hpp.in index 5e5942fb7..6f4a0414f 100644 --- a/src/libprojectM/MilkdropPreset/MilkdropStaticShaders.hpp.in +++ b/src/libprojectM/MilkdropPreset/MilkdropStaticShaders.hpp.in @@ -64,7 +64,6 @@ private: std::string AddVersionHeader(std::string shader_text); bool m_useGLES{false}; //!< Whether or not to use GLES shaders. - Renderer::Shader::GlslVersion m_GLSLVersion{}; //!< The queried GLSL version. std::string m_versionHeader; //!< The version header to prepended by AddVersionHeader. M4::GLSLGenerator::Version m_GLSLGeneratorVersion; //!< The GLSL generator version to pass to the hlslparser generator. }; diff --git a/src/libprojectM/ProjectM.cpp b/src/libprojectM/ProjectM.cpp index 9486e2c17..4c6a70237 100644 --- a/src/libprojectM/ProjectM.cpp +++ b/src/libprojectM/ProjectM.cpp @@ -192,16 +192,14 @@ void ProjectM::RenderFrame(uint32_t targetFramebufferObject /*= 0*/) void ProjectM::Initialize() { - /** Initialise start time */ + // Check OpenGL first before allocating any additional memory. + CheckGLSLVersion(); + m_timeKeeper = std::make_unique(m_presetDuration, m_softCutDuration, m_hardCutDuration, m_easterEgg); - /** Nullify frame stash */ - - /** Initialise per-pixel matrix calculations */ - /** We need to initialise this before the builtin param db otherwise bass/mid etc won't bind correctly */ m_textureManager = std::make_unique(m_textureSearchPaths); m_shaderCache = std::make_unique(); @@ -213,14 +211,38 @@ void ProjectM::Initialize() m_presetFactoryManager->initialize(); - /* Set the seed to the current time in seconds */ - srand(time(nullptr)); - LoadIdlePreset(); m_timeKeeper->StartPreset(); } +void ProjectM::CheckGLSLVersion() +{ + auto glslVersion = Renderer::Shader::GetShaderLanguageVersion(); + + if (glslVersion.major == 0) + { + std::string error = "Could not retrieve OpenGL shader language version. Is OpenGL available and the context initialized?"; + LOG_FATAL(error); + throw std::runtime_error(error); + } +#ifdef USE_GLES + if (glslVersion.major < 3) + { + std::string error = "OpenGL ES shading language version 3.00 or higher is required, but the current context only provides version " + std::to_string(glslVersion.major) + "." + std::to_string(glslVersion.minor) + "."; + LOG_FATAL(error); + throw std::runtime_error(error); + } +#else + if (glslVersion.major < 3 || (glslVersion.major == 3 && glslVersion.minor < 30)) + { + std::string error = "OpenGL shading language version 3.30 or higher is required, but the current context only provides version " + std::to_string(glslVersion.major) + "." + std::to_string(glslVersion.minor) + "."; + LOG_FATAL(error); + throw std::runtime_error(error); + } +#endif +} + void ProjectM::LoadIdlePreset() { LoadPresetFile("idle://Geiss & Sperl - Feedback (projectM idle HDR mix).milk", false); diff --git a/src/libprojectM/ProjectM.hpp b/src/libprojectM/ProjectM.hpp index ca9afa6f6..1a1c53de8 100644 --- a/src/libprojectM/ProjectM.hpp +++ b/src/libprojectM/ProjectM.hpp @@ -259,6 +259,8 @@ public: private: void Initialize(); + void CheckGLSLVersion(); + void StartPresetTransition(std::unique_ptr&& preset, bool hardCut); void LoadIdlePreset();