diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 3f4450b04..96c23982e 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -241,7 +241,8 @@ ShaderStage *Graphics::newShaderStage(ShaderStageType stage, const std::string & if (s == nullptr) { - std::string glsl = Shader::createShaderStageCode(this, stage, source, info); + bool gles = getRenderer() == Graphics::RENDERER_OPENGLES; + std::string glsl = Shader::createShaderStageCode(this, stage, source, info, gles, true); s = newShaderStageInternal(stage, cachekey, glsl, getRenderer() == RENDERER_OPENGLES); if (!cachekey.empty()) cachedShaderStages[stage][cachekey] = s; @@ -363,7 +364,7 @@ bool Graphics::validateShader(bool gles, const std::vector &stagess if (info.stages[i] != Shader::ENTRYPOINT_NONE) { isanystage = true; - std::string glsl = Shader::createShaderStageCode(this, stype, source, info); + std::string glsl = Shader::createShaderStageCode(this, stype, source, info, gles, false); stages[i].set(new ShaderStageForValidation(this, stype, glsl, gles), Acquire::NORETAIN); } } diff --git a/src/modules/graphics/Shader.cpp b/src/modules/graphics/Shader.cpp index c2cd06c24..b3ab0d493 100644 --- a/src/modules/graphics/Shader.cpp +++ b/src/modules/graphics/Shader.cpp @@ -514,7 +514,7 @@ Shader::SourceInfo Shader::getSourceInfo(const std::string &src) return info; } -std::string Shader::createShaderStageCode(Graphics *gfx, ShaderStageType stage, const std::string &code, const Shader::SourceInfo &info) +std::string Shader::createShaderStageCode(Graphics *gfx, ShaderStageType stage, const std::string &code, const Shader::SourceInfo &info, bool gles, bool checksystemfeatures) { if (info.language == Shader::LANGUAGE_MAX_ENUM) throw love::Exception("Invalid shader language"); @@ -528,19 +528,23 @@ std::string Shader::createShaderStageCode(Graphics *gfx, ShaderStageType stage, if (stage == SHADERSTAGE_COMPUTE && info.language != LANGUAGE_GLSL4) throw love::Exception("Compute shaders must use GLSL 4."); - const auto &features = gfx->getCapabilities().features; + bool glsl1on3 = info.language == LANGUAGE_GLSL1; - if (stage == SHADERSTAGE_COMPUTE && !features[Graphics::FEATURE_GLSL4]) - throw love::Exception("Compute shaders require GLSL 4 which is not supported on this system."); + if (checksystemfeatures) + { + const auto &features = gfx->getCapabilities().features; - if (info.language == LANGUAGE_GLSL3 && !features[Graphics::FEATURE_GLSL3]) - throw love::Exception("GLSL 3 shaders are not supported on this system."); + if (stage == SHADERSTAGE_COMPUTE && !features[Graphics::FEATURE_GLSL4]) + throw love::Exception("Compute shaders require GLSL 4 which is not supported on this system."); - if (info.language == LANGUAGE_GLSL4 && !features[Graphics::FEATURE_GLSL4]) - throw love::Exception("GLSL 4 shaders are not supported on this system."); + if (info.language == LANGUAGE_GLSL3 && !features[Graphics::FEATURE_GLSL3]) + throw love::Exception("GLSL 3 shaders are not supported on this system."); - bool gles = gfx->getRenderer() == Graphics::RENDERER_OPENGLES; - bool glsl1on3 = info.language == LANGUAGE_GLSL1 && features[Graphics::FEATURE_GLSL3]; + if (info.language == LANGUAGE_GLSL4 && !features[Graphics::FEATURE_GLSL4]) + throw love::Exception("GLSL 4 shaders are not supported on this system."); + + glsl1on3 = info.language == LANGUAGE_GLSL1 && features[Graphics::FEATURE_GLSL3]; + } Language lang = info.language; if (glsl1on3) diff --git a/src/modules/graphics/Shader.h b/src/modules/graphics/Shader.h index 93074c7ab..38cdb5a29 100644 --- a/src/modules/graphics/Shader.h +++ b/src/modules/graphics/Shader.h @@ -219,7 +219,7 @@ public: void getLocalThreadgroupSize(int *x, int *y, int *z); static SourceInfo getSourceInfo(const std::string &src); - static std::string createShaderStageCode(Graphics *gfx, ShaderStageType stage, const std::string &code, const SourceInfo &info); + static std::string createShaderStageCode(Graphics *gfx, ShaderStageType stage, const std::string &code, const SourceInfo &info, bool gles, bool checksystemfeatures); static bool validate(StrongRef stages[], std::string &err);