[Piglit] [PATCH] Add "#version 300 es" by glShaderSource when the shader is based on GLSL ES30, and the shader it self do not contained the token "#version 300 es"

Wang Shuo shuo.wang at intel.com
Tue Nov 11 01:31:10 PST 2014


---
 tests/glslparsertest/glslparsertest.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/tests/glslparsertest/glslparsertest.c b/tests/glslparsertest/glslparsertest.c
index b969eff..39704ac 100644
--- a/tests/glslparsertest/glslparsertest.c
+++ b/tests/glslparsertest/glslparsertest.c
@@ -214,13 +214,15 @@ test(void)
 {
 	GLint prog;
 	GLint ok;
-	GLchar *prog_string;
+	GLchar *prog_string[2];
 	FILE *out;
 	GLboolean pass;
 	GLchar *info;
 	GLint size;
 	GLenum type;
 	char *failing_stage = NULL;
+	GLint ISGLSLES30VersionContained = 0;
+	char *glslES30Version = "#version 300 es\n";
 
 	if (strcmp(filename + strlen(filename) - 4, "frag") == 0)
 		type = GL_FRAGMENT_SHADER;
@@ -264,15 +266,25 @@ test(void)
 		}
 	}
 
-	prog_string = piglit_load_text_file(filename, NULL);
-	if (prog_string == NULL) {
+	prog_string[1] = piglit_load_text_file(filename, NULL);
+	if (prog_string[1] == NULL) {
 		fprintf(stderr, "Couldn't open program %s: %s\n",
 			filename, strerror(errno));
 		exit(1);
 	}
 
+	if (strstr(filename, "glsl-es-3.00") != NULL){
+		if (strstr(prog_string[1], "#version 300 es") == NULL){
+			ISGLSLES30VersionContained = 1;
+		}
+	}
+
+	prog_string[0] = glslES30Version;
 	prog = glCreateShader(type);
-	glShaderSource(prog, 1, (const GLchar **)&prog_string, NULL);
+	if(ISGLSLES30VersionContained == 0)
+		glShaderSource(prog, 1, (const GLchar **)&(prog_string[1]), NULL);
+	else
+		glShaderSource(prog, 2, (const GLchar **)prog_string, NULL);
 	glCompileShader(prog);
 	ok = get_shader_compile_status(prog);
 
@@ -336,7 +348,7 @@ test(void)
 			filename, info);
 		if (expected_pass) {
 			printf("Shader source:\n");
-			printf("%s\n", prog_string);
+			printf("%s\n", prog_string[1]);
 		}
 	} else {
 		fprintf(out, "Successfully %s %s shader %s: %s\n",
@@ -345,13 +357,13 @@ test(void)
 			filename, info);
 		if (!expected_pass) {
 			printf("Shader source:\n");
-			printf("%s\n", prog_string);
+			printf("%s\n", prog_string[1]);
 		}
 	}
 
 	if (size != 0)
 		free(info);
-	free(prog_string);
+	free(prog_string[1]);
 	glDeleteShader(prog);
 	piglit_report_result (pass ? PIGLIT_PASS : PIGLIT_FAIL);
 }
-- 
1.8.3.2



More information about the Piglit mailing list