[Piglit] [PATCH 2/4] util: Make an even simpler interface for building simple shaders.
Eric Anholt
eric at anholt.net
Wed May 8 14:02:00 PDT 2013
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.
---
tests/util/piglit-shader.c | 35 +++++++++++++++++++++++++++++++++++
tests/util/piglit-shader.h | 1 +
2 files changed, 36 insertions(+)
diff --git a/tests/util/piglit-shader.c b/tests/util/piglit-shader.c
index ca48f41..d715bab 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 12cf731..425eab3 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")
--
1.8.3.rc0
More information about the Piglit
mailing list