This extends the fogscale test to test a gl_FogFragCoord value passed via a geometry shader. --- tests/shaders/glsl-fs-fogscale.c | 100 +++++++++++++++++++++++++------ 1 file changed, 82 insertions(+), 18 deletions(-)
diff --git a/tests/shaders/glsl-fs-fogscale.c b/tests/shaders/glsl-fs-fogscale.c index e5f28eaf7..076092d07 100644 --- a/tests/shaders/glsl-fs-fogscale.c +++ b/tests/shaders/glsl-fs-fogscale.c @@ -39,13 +39,34 @@ PIGLIT_GL_TEST_CONFIG_BEGIN PIGLIT_GL_TEST_CONFIG_END -enum piglit_result -piglit_display(void) +static const char vs_source[] = + "void main()\n" + "{\n" + " gl_Position = gl_Vertex;\n" + " gl_FogFragCoord = gl_Position.x;\n" + "}\n"; + +static const char *dummy_vs_source = + "void main()\n" + "{\n" + " gl_Position = gl_Vertex;\n" + "}\n"; + +static const char fs_source[] = + "void main()\n" + "{\n" + " gl_FragColor = vec4(gl_FogFragCoord * gl_Fog.scale * vec2(1.0, -1.0), 0.0, 1.0);\n" + "}\n"; + +static bool +test_prog(unsigned prog, const char *test_name) { static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f}; static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f}; bool pass = true; + glUseProgram(prog); + glClearColor(0.0, 0.0, 1.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); @@ -57,30 +78,73 @@ piglit_display(void) piglit_width / 2, piglit_height, red) && pass; - piglit_present_results(); + piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL, "%s", + test_name); - return pass ? PIGLIT_PASS : PIGLIT_FAIL; + return pass; } -void -piglit_init(int argc, char **argv) +static void +create_gs_source(char **gs_source, char *fogFragCoordValue) { - static const char vs_source[] = + (void)!asprintf(gs_source, + "#version 150 compatibility\n" + "layout(triangles) in;\n" + "layout(triangle_strip, max_vertices = 3) out;\n" + "\n" "void main()\n" "{\n" - " gl_Position = gl_Vertex;\n" - " gl_FogFragCoord = gl_Position.x;\n" - "}\n"; - static const char fs_source[] = - "void main()\n" - "{\n" - " gl_FragColor = vec4(gl_FogFragCoord * gl_Fog.scale * vec2(1.0, -1.0), 0.0, 1.0);\n" - "}\n"; - GLuint prog; + " for (int i = 0; i < 3; i++) {\n" + " gl_Position = gl_in[i].gl_Position;\n" + " gl_FogFragCoord = %s;\n" + " EmitVertex();\n" + " }\n" + "}\n", + fogFragCoordValue); +} + +enum piglit_result +piglit_display(void) +{ + bool pass = true; + char *gs_source; + char *gs_source2; + + /* Test simple vs and fs program */ + GLuint prog = piglit_build_simple_program(vs_source, fs_source); + test_prog(prog, "vs and fs"); + + /* Test passing gl_FogFragCoord via the Geometry Shader */ + if (piglit_get_gl_version() >= 32) { + /* Test gl_FogFragCoord gs output only */ + create_gs_source(&gs_source, "gl_Position.x"); + prog = piglit_build_simple_program_multiple_shaders( + GL_VERTEX_SHADER, dummy_vs_source, + GL_GEOMETRY_SHADER, gs_source, + GL_FRAGMENT_SHADER, fs_source, + 0); + pass = pass && test_prog(prog, "gs-out and fs"); + + /* Test gl_FogFragCoord both as a gs output and input */ + create_gs_source(&gs_source2, "gl_in[i].gl_FogFragCoord"); + prog = piglit_build_simple_program_multiple_shaders( + GL_VERTEX_SHADER, vs_source, + GL_GEOMETRY_SHADER, gs_source2, + GL_FRAGMENT_SHADER, fs_source, + 0); + pass = pass && test_prog(prog, "vs, gs and fs"); - prog = piglit_build_simple_program(vs_source, fs_source); + } else { + piglit_report_subtest_result(PIGLIT_SKIP, "gs-out and fs"); + piglit_report_subtest_result(PIGLIT_SKIP, "vs, gs and fs"); + } + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + +void +piglit_init(int argc, char **argv) +{ glFogf(GL_FOG_START, 0.0f); glFogf(GL_FOG_END, 0.0f); - glUseProgram(prog); } -- 2.17.0 _______________________________________________ Piglit mailing list Piglit@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/piglit