mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
love.graphics.validateShader no longer errors if the system doesn't support the shader
This commit is contained in:
@@ -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<std::string> &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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<ShaderStage> stages[], std::string &err);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user