Browse Source

love.graphics.validateShader no longer errors if the system doesn't support the shader

Alex Szpakowski 4 years ago
parent
commit
92d0d1d60f
3 changed files with 18 additions and 13 deletions
  1. 3 2
      src/modules/graphics/Graphics.cpp
  2. 14 10
      src/modules/graphics/Shader.cpp
  3. 1 1
      src/modules/graphics/Shader.h

+ 3 - 2
src/modules/graphics/Graphics.cpp

@@ -241,7 +241,8 @@ ShaderStage *Graphics::newShaderStage(ShaderStageType stage, const std::string &
 
 
 	if (s == nullptr)
 	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);
 		s = newShaderStageInternal(stage, cachekey, glsl, getRenderer() == RENDERER_OPENGLES);
 		if (!cachekey.empty())
 		if (!cachekey.empty())
 			cachedShaderStages[stage][cachekey] = s;
 			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)
 			if (info.stages[i] != Shader::ENTRYPOINT_NONE)
 			{
 			{
 				isanystage = true;
 				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);
 				stages[i].set(new ShaderStageForValidation(this, stype, glsl, gles), Acquire::NORETAIN);
 			}
 			}
 		}
 		}

+ 14 - 10
src/modules/graphics/Shader.cpp

@@ -514,7 +514,7 @@ Shader::SourceInfo Shader::getSourceInfo(const std::string &src)
 	return info;
 	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)
 	if (info.language == Shader::LANGUAGE_MAX_ENUM)
 		throw love::Exception("Invalid shader language");
 		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)
 	if (stage == SHADERSTAGE_COMPUTE && info.language != LANGUAGE_GLSL4)
 		throw love::Exception("Compute shaders must use GLSL 4.");
 		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 (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_GLSL3 && !features[Graphics::FEATURE_GLSL3])
-		throw love::Exception("GLSL 3 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.");
 
 
-	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_GLSL4 && !features[Graphics::FEATURE_GLSL4])
+			throw love::Exception("GLSL 4 shaders are not supported on this system.");
 
 
-	bool gles = gfx->getRenderer() == Graphics::RENDERER_OPENGLES;
-	bool glsl1on3 = info.language == LANGUAGE_GLSL1 && features[Graphics::FEATURE_GLSL3];
+		glsl1on3 = info.language == LANGUAGE_GLSL1 && features[Graphics::FEATURE_GLSL3];
+	}
 
 
 	Language lang = info.language;
 	Language lang = info.language;
 	if (glsl1on3)
 	if (glsl1on3)

+ 1 - 1
src/modules/graphics/Shader.h

@@ -219,7 +219,7 @@ public:
 	void getLocalThreadgroupSize(int *x, int *y, int *z);
 	void getLocalThreadgroupSize(int *x, int *y, int *z);
 
 
 	static SourceInfo getSourceInfo(const std::string &src);
 	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);
 	static bool validate(StrongRef<ShaderStage> stages[], std::string &err);