Move GLSL version check to ProjectM class constructor

Log a fatal error if it fails.
This commit is contained in:
Kai Blaschke
2025-12-05 12:28:15 +01:00
parent 3c80d89337
commit 4a0fa11f0f
4 changed files with 32 additions and 20 deletions

View File

@ -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.

View File

@ -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.
};

View File

@ -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<TimeKeeper>(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<Renderer::TextureManager>(m_textureSearchPaths);
m_shaderCache = std::make_unique<Renderer::ShaderCache>();
@ -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);

View File

@ -259,6 +259,8 @@ public:
private:
void Initialize();
void CheckGLSLVersion();
void StartPresetTransition(std::unique_ptr<Preset>&& preset, bool hardCut);
void LoadIdlePreset();