[Piglit] [PATCH V2] util: Add multiple shader version of piglit_build_simple_program functions

Jacob Penner jkpenner91 at gmail.com
Wed Sep 4 16:45:01 PDT 2013


Add piglit_link_simple_program_multiple_shader()
Add piglit_build_simple_program_multiple_shader()
Add piglit_build_simple_program_unlinked_multiple_shader()
---
 tests/util/piglit-shader.c | 126 +++++++++++++++++++++++++++++++++++++++++++++
 tests/util/piglit-shader.h |   7 +++
 2 files changed, 133 insertions(+)

diff --git a/tests/util/piglit-shader.c b/tests/util/piglit-shader.c
index f7bd06f..2635a90 100644
--- a/tests/util/piglit-shader.c
+++ b/tests/util/piglit-shader.c
@@ -322,3 +322,129 @@ piglit_build_simple_program(const char *vs_source, const char *fs_source)
 
 	return prog;
 }
+
+GLint piglit_link_simple_program_multiple_shaders(GLint shader1, ...)
+{
+	va_list ap;
+	GLint prog, sh;
+
+	piglit_require_GLSL();
+
+	prog = glCreateProgram();
+
+	va_start(ap, shader1);
+	sh = shader1;
+
+	while(sh != 0) {
+		glAttachShader(prog, sh);
+		sh = va_arg(ap, GLint);
+	}
+
+	va_end(ap);
+
+	/* If the shaders reference piglit_vertex or piglit_tex, bind
+	 * them to some fixed attribute locations so they can be used
+	 * with piglit_draw_rect_tex() in GLES.
+	 */
+	glBindAttribLocation(prog, PIGLIT_ATTRIB_POS, "piglit_vertex");
+	glBindAttribLocation(prog, PIGLIT_ATTRIB_TEX, "piglit_texcoord");
+
+	glLinkProgram(prog);
+
+	if (!piglit_link_check_status(prog)) {
+		glDeleteProgram(prog);
+		prog = 0;
+	}
+
+	return prog;
+}
+
+/**
+ * Builds and links a program from optional sources,  but does not link
+ * it. Requires to pass 0 as the final argument. If there is a compile failure,
+ * the test is terminated.
+ */
+GLint
+piglit_build_simple_program_unlinked_multiple_shader(GLenum target1,
+						     const char *source1,
+						     ...)
+{
+	va_list ap;
+	GLuint prog;
+	const char *sh;
+	GLenum t;
+
+	piglit_require_GLSL();
+	prog = glCreateProgram();
+
+	va_start(ap, source1);
+
+	sh = source1;
+	t = target1;
+
+	while(t != 0) {
+		GLuint shader = piglit_compile_shader_text(t, sh);
+
+		glAttachShader(prog, shader);
+		glDeleteShader(shader);
+
+		t  = va_arg(ap, GLenum);
+		sh = va_arg(ap, char*);
+	}
+
+	va_end(ap);
+
+	return prog;
+}
+
+/**
+ * Builds and links a program from optional sources, requires
+ * to pass 0 as the final argument, throwing PIGLIT_FAIL on error.
+ */
+GLint
+piglit_build_simple_program_multiple_shader(GLenum target1,
+					    const char *source1,
+					    ...)
+{
+	va_list ap;
+	GLuint prog;
+	const char *sh;
+	GLenum t;
+
+	piglit_require_GLSL();
+	prog = glCreateProgram();
+
+	va_start(ap, source1);
+
+	sh = source1;
+	t = target1;
+
+	while(t != 0) {
+		GLuint shader = piglit_compile_shader_text(t, sh);
+
+		glAttachShader(prog, shader);
+		glDeleteShader(shader);
+
+		t  = va_arg(ap, GLenum);
+		sh = va_arg(ap, char*);
+	}
+
+	va_end(ap);
+
+	/* If the shaders reference piglit_vertex or piglit_tex, bind
+	 * them to some fixed attribute locations so they can be used
+	 * with piglit_draw_rect_tex() in GLES.
+	 */
+	glBindAttribLocation(prog, PIGLIT_ATTRIB_POS, "piglit_vertex");
+	glBindAttribLocation(prog, PIGLIT_ATTRIB_TEX, "piglit_texcoord");
+
+	glLinkProgram(prog);
+
+	if (!piglit_link_check_status(prog)) {
+		glDeleteProgram(prog);
+		prog = 0;
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	return prog;
+}
diff --git a/tests/util/piglit-shader.h b/tests/util/piglit-shader.h
index 8f18f0a..5b7c0cd 100644
--- a/tests/util/piglit-shader.h
+++ b/tests/util/piglit-shader.h
@@ -38,6 +38,13 @@ GLint piglit_link_simple_program(GLint vs, GLint fs);
 GLint piglit_build_simple_program(const char *vs_source, const char *fs_source);
 GLuint piglit_build_simple_program_unlinked(const char *vs_source,
 					    const char *fs_source);
+GLint piglit_link_simple_program_multiple_shaders(GLint shader1, ...);
+GLint piglit_build_simple_program_unlinked_multiple_shader(GLenum target1,
+							   const char *source1,
+							   ...);
+GLint piglit_build_simple_program_multiple_shader(GLenum target1,
+						  const char *source1,
+						  ...);
 
 #if defined(PIGLIT_USE_OPENGL_ES1)
 #define glAttachShader assert(!"glAttachShader does not exist in ES1")
-- 
1.8.3.1



More information about the Piglit mailing list