summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2013-05-07 12:49:29 -0700
committerEric Anholt <eric@anholt.net>2013-05-14 10:52:01 -0700
commit25b440c9689e7fc55c993dff407832afccd159e8 (patch)
tree064e12bdb8cbbcfbd8138137aee166d5e9c5b648
parent678cd5dfc20366be326201210f0beefe6094efd2 (diff)
util: Make an even simpler interface for building simple shaders.
The previous piglit_link_simple_program() interface required you to compile your shaders up front, and tests routinely have issues with either not checking that the component shaders compiled, or not checking that the program linked, and then confusingly fail later in the test. This one enforces that the program actually compiled and linked before continuing, so you don't need to worry about error checking. Reviewed-by: Brian Paul <brianp@vmware.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
-rw-r--r--tests/util/piglit-shader.c35
-rw-r--r--tests/util/piglit-shader.h1
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/util/piglit-shader.c b/tests/util/piglit-shader.c
index ca48f4178..d715babb7 100644
--- a/tests/util/piglit-shader.c
+++ b/tests/util/piglit-shader.c
@@ -263,3 +263,38 @@ GLint piglit_link_simple_program(GLint vs, GLint fs)
return prog;
}
+
+/**
+ * Builds and links a program from optional VS and FS sources,
+ * throwing PIGLIT_FAIL on error.
+ */
+GLint
+piglit_build_simple_program(const char *vs_source, const char *fs_source)
+{
+ GLuint vs = 0, fs = 0, prog;
+
+ if (vs_source) {
+ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
+ if (!vs) {
+ piglit_report_result(PIGLIT_FAIL);
+ }
+ }
+
+ if (fs_source) {
+ fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
+ if (!fs) {
+ piglit_report_result(PIGLIT_FAIL);
+ }
+ }
+
+ prog = piglit_link_simple_program(vs, fs);
+ if (!prog)
+ piglit_report_result(PIGLIT_FAIL);
+
+ if (fs)
+ glDeleteShader(fs);
+ if (vs)
+ glDeleteShader(vs);
+
+ return prog;
+}
diff --git a/tests/util/piglit-shader.h b/tests/util/piglit-shader.h
index 12cf731b2..425eab374 100644
--- a/tests/util/piglit-shader.h
+++ b/tests/util/piglit-shader.h
@@ -35,6 +35,7 @@ GLuint piglit_compile_shader_text(GLenum target, const char *text);
GLboolean piglit_link_check_status(GLint prog);
GLboolean piglit_link_check_status_quiet(GLint prog);
GLint piglit_link_simple_program(GLint vs, GLint fs);
+GLint piglit_build_simple_program(const char *vs_source, const char *fs_source);
#if defined(PIGLIT_USE_OPENGL_ES1)
#define glAttachShader assert(!"glAttachShader does not exist in ES1")