[Piglit] [PATCH V3] util: Add multiple shader version of piglit_build_simple_program functions
Jacob Penner
jkpenner91 at gmail.com
Wed Sep 11 11:23:37 PDT 2013
Add piglit_link_simple_program_multiple_shader()
Add piglit_build_simple_program_multiple_shader_v()
Add piglit_build_simple_program_multiple_shader()
Add piglit_build_simple_program_unlinked_multiple_shader()
---
tests/util/piglit-shader.c | 134 +++++++++++++++++++++++++++++++++++++++++++++
tests/util/piglit-shader.h | 10 ++++
2 files changed, 144 insertions(+)
diff --git a/tests/util/piglit-shader.c b/tests/util/piglit-shader.c
index f7bd06f..8c2137a 100644
--- a/tests/util/piglit-shader.c
+++ b/tests/util/piglit-shader.c
@@ -322,3 +322,137 @@ 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;
+}
+
+GLint
+piglit_build_simple_program_unlinked_multiple_shader_v(GLenum target1,
+ const char*source1,
+ va_list ap)
+{
+ GLuint prog;
+ GLenum target;
+ const char *source;
+
+ piglit_require_GLSL();
+ prog = glCreateProgram();
+
+
+ source = source1;
+ target = target1;
+
+ while (target != 0) {
+ GLuint shader = piglit_compile_shader_text(target, source);
+
+ glAttachShader(prog, shader);
+ glDeleteShader(shader);
+
+ target = va_arg(ap, GLenum);
+ if (target != 0)
+ source = va_arg(ap, char*);
+ }
+
+ return prog;
+}
+
+/**
+ * Builds and links a program from optional sources, but does not link
+ * it. The last target must be 0. If there is a compile failure,
+ * the test is terminated.
+ *
+ * example:
+ * piglit_build_simple_program_unlinked_multiple_shader(
+ * GL_VERTEX_SHADER, vs,
+ * GL_GEOMETRY_SHADER, gs,
+ * GL_FRAGMENT_SHADER, fs,
+ * 0);
+ */
+GLint
+piglit_build_simple_program_unlinked_multiple_shader(GLenum target1,
+ const char *source1,
+ ...)
+{
+ GLuint prog;
+ va_list ap;
+
+ va_start(ap, source1);
+
+ prog = piglit_build_simple_program_unlinked_multiple_shader_v(target1,
+ source1,
+ ap);
+ va_end(ap);
+
+ return prog;
+}
+
+/**
+ * Builds and links a program from optional sources, throwing
+ * PIGLIT_FAIL on error. The last target must be 0.
+ */
+GLint
+piglit_build_simple_program_multiple_shader(GLenum target1,
+ const char *source1,
+ ...)
+{
+ va_list ap;
+ GLuint prog;
+
+ va_start(ap, source1);
+
+ prog = piglit_build_simple_program_unlinked_multiple_shader_v(target1,
+ source1,
+ ap);
+
+ 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..43fea5a 100644
--- a/tests/util/piglit-shader.h
+++ b/tests/util/piglit-shader.h
@@ -38,6 +38,16 @@ 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_v(GLenum target1,
+ const char*source1,
+ va_list ap);
+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