[Piglit] [PATCH] util: Add geometry shader version of piglit_build_simple_program functions
Jacob Penner
jkpenner91 at gmail.com
Wed Sep 4 11:08:03 PDT 2013
Add piglit_link_simple_program_with_gs()
Add piglit_build_simple_program_with_gs()
Add piglit_build_simple_program_unlinked_with_gs()
---
tests/util/piglit-shader.c | 102 +++++++++++++++++++++++++++++++++++++++++++++
tests/util/piglit-shader.h | 7 ++++
2 files changed, 109 insertions(+)
diff --git a/tests/util/piglit-shader.c b/tests/util/piglit-shader.c
index f7bd06f..227f80c 100644
--- a/tests/util/piglit-shader.c
+++ b/tests/util/piglit-shader.c
@@ -322,3 +322,105 @@ piglit_build_simple_program(const char *vs_source, const char *fs_source)
return prog;
}
+
+GLint piglit_link_simple_program_with_gs(GLint vs, GLint gs, GLint fs)
+{
+ GLint prog;
+
+ piglit_require_GLSL();
+
+ prog = glCreateProgram();
+ if (vs)
+ glAttachShader(prog, vs);
+ if (gs)
+ glAttachShader(prog, gs);
+ if (fs)
+ glAttachShader(prog, fs);
+
+ /* 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 a program from optional VS, GS and FS sources, but does not link
+ * it. If there is a compile failure, the test is terminated.
+ */
+GLint
+piglit_build_simple_program_unlinked_with_gs(const char *vs_source,
+ const char *gs_source,
+ const char *fs_source)
+{
+ GLuint prog;
+
+ piglit_require_GLSL();
+ prog = glCreateProgram();
+ if (vs_source) {
+ GLuint vs = piglit_compile_shader_text(GL_VERTEX_SHADER,
+ vs_source);
+ glAttachShader(prog, vs);
+ glDeleteShader(vs);
+ }
+ if (gs_source) {
+ GLuint gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER,
+ gs_source);
+ glAttachShader(prog, gs);
+ glDeleteShader(gs);
+ }
+ if (fs_source) {
+ GLuint fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER,
+ fs_source);
+ glAttachShader(prog, fs);
+ glDeleteShader(fs);
+ }
+ return prog;
+}
+
+/**
+ * Builds and links a program from optional VS, GS and FS sources,
+ * throwing PIGLIT_FAIL on error.
+ */
+GLint
+piglit_build_simple_program_with_gs(const char *vs_source,
+ const char *gs_source,
+ const char *fs_source)
+{
+ GLuint vs = 0, gs = 0, fs = 0, prog;
+
+ if (vs_source) {
+ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
+ }
+
+ if (gs_source) {
+ gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gs_source);
+ }
+
+ if (fs_source) {
+ fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
+ }
+
+ prog = piglit_link_simple_program_with_gs(vs, gs, fs);
+ if (!prog)
+ piglit_report_result(PIGLIT_FAIL);
+
+ if (fs)
+ glDeleteShader(fs);
+ if (gs)
+ glDeleteShader(gs);
+ if (vs)
+ glDeleteShader(vs);
+
+ return prog;
+}
diff --git a/tests/util/piglit-shader.h b/tests/util/piglit-shader.h
index 8f18f0a..91acbe8 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_with_gs(GLint vs, GLint gs, GLint fs);
+GLint piglit_build_simple_program_with_gs(const char *vs_source,
+ const char *gs_source,
+ const char *fs_source);
+GLint piglit_build_simple_program_unlinked_with_gs(const char *vs_source,
+ const char *gs_source,
+ const char *fs_source);
#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