Skip to content

Commit b8faa19

Browse files
committed
Move GLSL version check to ProjectM class constructor
Log a fatal error if it fails.
1 parent c502eda commit b8faa19

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

src/libprojectM/MilkdropPreset/MilkdropStaticShaders.cpp.in

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,6 @@ namespace MilkdropPreset {
1313
MilkdropStaticShaders::MilkdropStaticShaders(bool useGLES)
1414
: m_useGLES(useGLES)
1515
{
16-
m_GLSLVersion = Renderer::Shader::GetShaderLanguageVersion();
17-
18-
if (m_GLSLVersion.major == 0)
19-
{
20-
throw std::runtime_error("Could not retrieve OpenGL shader language version. Is OpenGL available and the context initialized?");
21-
}
22-
if (m_GLSLVersion.major < 3)
23-
{
24-
throw std::runtime_error("OpenGL shader language version 3 or higher is required, but not available in the current context.");
25-
}
26-
2716
if (m_useGLES)
2817
{
2918
// If GLES is enabled, use the embedded specification language variant.

src/libprojectM/MilkdropPreset/MilkdropStaticShaders.hpp.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ private:
6464
std::string AddVersionHeader(std::string shader_text);
6565

6666
bool m_useGLES{false}; //!< Whether or not to use GLES shaders.
67-
Renderer::Shader::GlslVersion m_GLSLVersion{}; //!< The queried GLSL version.
6867
std::string m_versionHeader; //!< The version header to prepended by AddVersionHeader.
6968
M4::GLSLGenerator::Version m_GLSLGeneratorVersion; //!< The GLSL generator version to pass to the hlslparser generator.
7069
};

src/libprojectM/ProjectM.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
#include <Renderer/CopyTexture.hpp>
3232
#include <Renderer/PresetTransition.hpp>
33-
#include <Renderer/TextureManager.hpp>
3433
#include <Renderer/ShaderCache.hpp>
34+
#include <Renderer/TextureManager.hpp>
3535
#include <Renderer/TransitionShaderManager.hpp>
3636

3737
#include <UserSprites/SpriteManager.hpp>
@@ -184,24 +184,22 @@ void ProjectM::RenderFrame(uint32_t targetFramebufferObject /*= 0*/)
184184
}
185185

186186
// Draw user sprites
187-
m_spriteManager->Draw(audioData, renderContext, targetFramebufferObject, { m_activePreset, m_transitioningPreset });
187+
m_spriteManager->Draw(audioData, renderContext, targetFramebufferObject, {m_activePreset, m_transitioningPreset});
188188

189189
m_frameCount++;
190190
m_previousFrameVolume = audioData.vol;
191191
}
192192

193193
void ProjectM::Initialize()
194194
{
195-
/** Initialise start time */
195+
// Check OpenGL first before allocating any additional memory.
196+
CheckGLSLVersion();
197+
196198
m_timeKeeper = std::make_unique<TimeKeeper>(m_presetDuration,
197199
m_softCutDuration,
198200
m_hardCutDuration,
199201
m_easterEgg);
200202

201-
/** Nullify frame stash */
202-
203-
/** Initialise per-pixel matrix calculations */
204-
/** We need to initialise this before the builtin param db otherwise bass/mid etc won't bind correctly */
205203
m_textureManager = std::make_unique<Renderer::TextureManager>(m_textureSearchPaths);
206204
m_shaderCache = std::make_unique<Renderer::ShaderCache>();
207205

@@ -213,14 +211,38 @@ void ProjectM::Initialize()
213211

214212
m_presetFactoryManager->initialize();
215213

216-
/* Set the seed to the current time in seconds */
217-
srand(time(nullptr));
218-
219214
LoadIdlePreset();
220215

221216
m_timeKeeper->StartPreset();
222217
}
223218

219+
void ProjectM::CheckGLSLVersion()
220+
{
221+
auto glslVersion = Renderer::Shader::GetShaderLanguageVersion();
222+
223+
if (glslVersion.major == 0)
224+
{
225+
std::string error = "Could not retrieve OpenGL shader language version. Is OpenGL available and the context initialized?";
226+
LOG_FATAL(error);
227+
throw std::runtime_error(error);
228+
}
229+
#ifdef USE_GLES
230+
if (glslVersion.major < 3)
231+
{
232+
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) + ".";
233+
LOG_FATAL(error);
234+
throw std::runtime_error(error);
235+
}
236+
#else
237+
if (glslVersion.major < 3 || (glslVersion.major == 3 && glslVersion.minor < 30))
238+
{
239+
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) + ".";
240+
LOG_FATAL(error);
241+
throw std::runtime_error(error);
242+
}
243+
#endif
244+
}
245+
224246
void ProjectM::LoadIdlePreset()
225247
{
226248
LoadPresetFile("idle://Geiss & Sperl - Feedback (projectM idle HDR mix).milk", false);

src/libprojectM/ProjectM.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ class PROJECTM_EXPORT ProjectM
249249
private:
250250
void Initialize();
251251

252+
void CheckGLSLVersion();
253+
252254
void StartPresetTransition(std::unique_ptr<Preset>&& preset, bool hardCut);
253255

254256
void LoadIdlePreset();

0 commit comments

Comments
 (0)