On 8 June 2012 14:46, <span dir="ltr"><<a href="mailto:anuj.phogat@gmail.com" target="_blank">anuj.phogat@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
From: Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>><br>
<br>
This test varifies that with GL_SAMPLE_ALPHA_TO_ONE enabled, each sample's<br>
alpha value is replaced by maximum alpha value i.e. 1.0.<br></blockquote><div><br>This test is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br><br>I would recommend adding two additional tests, preferably in separate files:<br>
<br>1. We should make sure that when both GL_SAMPLE_ALPHA_TO_ONE and GL_SAMPLE_ALPHA_TO_COVERAGE are enabled, GL_SAMPLE_ALPHA_TO_COVERAGE takes effect first (that is, the coverage value needs to be computed from the alpha value *before* the alpha value gets changed to 1).<br>
<br>2. We should make sure that if GL_SAMPLE_ALPHA_TO_ONE is enabled and GL_MULTISAMPLE is disabled, alpha values are not modified. Also, we should make sure that if GL_SAMPLE_ALPHA_TO_ONE is enabled and the buffer is single-sampled, alpha values are not modified.<br>
</div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Verified the test case using proprietary NVIDIA drivers.<br>
<br>
Signed-off-by: Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>><br>
---<br>
tests/all.tests | 6 +<br>
.../ext_framebuffer_multisample/CMakeLists.gl.txt | 1 +<br>
.../sample-alpha-to-one.cpp | 287 ++++++++++++++++++++<br>
3 files changed, 294 insertions(+), 0 deletions(-)<br>
create mode 100644 tests/spec/ext_framebuffer_multisample/sample-alpha-to-one.cpp<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index 0e531b8..946874c 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -1400,6 +1400,12 @@ for num_samples in (2, 4, 8, 16, 32):<br>
test_name)<br>
ext_framebuffer_multisample[test_name] = PlainExecTest(executable)<br>
<br>
+for num_samples in (2, 4, 8, 16, 32):<br>
+ test_name = ' ' .join(['sample-alpha-to-one', str(num_samples)])<br>
+ executable = 'ext_framebuffer_multisample-{0} -auto'.format(<br>
+ test_name)<br>
+ ext_framebuffer_multisample[test_name] = PlainExecTest(executable)<br>
+<br>
ext_framebuffer_object = Group()<br>
spec['EXT_framebuffer_object'] = ext_framebuffer_object<br>
add_fbo_stencil_tests(ext_framebuffer_object, 'GL_STENCIL_INDEX1')<br>
diff --git a/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt b/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt<br>
index a6595fa..f482581 100644<br>
--- a/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt<br>
+++ b/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt<br>
@@ -28,6 +28,7 @@ piglit_add_executable (ext_framebuffer_multisample-renderbufferstorage-samples r<br>
piglit_add_executable (ext_framebuffer_multisample-samples samples.c)<br>
piglit_add_executable (ext_framebuffer_multisample-sample-coverage common.cpp sample-coverage.cpp)<br>
piglit_add_executable (ext_framebuffer_multisample-sample-alpha-to-coverage common.cpp sample-alpha-to-coverage.cpp)<br>
+piglit_add_executable (ext_framebuffer_multisample-sample-alpha-to-one common.cpp sample-alpha-to-one.cpp)<br>
piglit_add_executable (ext_framebuffer_multisample-turn-on-off common.cpp turn-on-off.cpp)<br>
piglit_add_executable (ext_framebuffer_multisample-unaligned-blit common.cpp unaligned-blit.cpp)<br>
piglit_add_executable (ext_framebuffer_multisample-upsample common.cpp upsample.cpp)<br>
diff --git a/tests/spec/ext_framebuffer_multisample/sample-alpha-to-one.cpp b/tests/spec/ext_framebuffer_multisample/sample-alpha-to-one.cpp<br>
new file mode 100644<br>
index 0000000..76d288b<br>
--- /dev/null<br>
+++ b/tests/spec/ext_framebuffer_multisample/sample-alpha-to-one.cpp<br>
@@ -0,0 +1,287 @@<br>
+/*<br>
+ * Copyright © 2012 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+static float coverage[4];<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#include "common.h"<br>
+<br>
+/**<br>
+ * \file sample-alpha-to-one.cpp<br>
+ *<br>
+ * This test operates by computing the expected color values when<br>
+ * GL_SAMPLE_ALPHA_TO_ONE is disabled.<br>
+ *<br>
+ * Draw a test pattern with GL_SAMPLE_ALPHA_TO_ONE disabled and blit it to<br>
+ * the right half of window system framebuffer. Probe the right half of<br>
+ * framebuffer and compare with expected values.<br>
+ *<br>
+ * Compute the expected color values when GL_SAMPLE_ALPHA_TO_ONE is enabled.<br>
+ * Draws the same test pattern for the second time in multisample buffer with<br>
+ * GL_SAMPLE_ALPHA_TO_ONE enabled. Blits it in to left half of window system<br>
+ * framebuffer.<br>
+ *<br>
+ * Probe the left half of window syetem framebuffer and compare with expected<br>
+ * color values.<br>
+ *<br>
+ * Author: Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>><br>
+ */<br>
+<br>
+int piglit_width = 512; int piglit_height = 256;<br>
+int piglit_window_mode =<br>
+ GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA | GLUT_DEPTH;<br>
+const int pattern_width = 256; const int pattern_height = 256;<br>
+<br>
+static Fbo ms_fbo;<br>
+static GLint num_samples;<br>
+static float expected[4][4];<br>
+static GLbitfield buffer_to_test;<br>
+<br>
+static const float bg_color[4] =<br>
+ {0.0, 0.0, 1.0, 0.8};<br>
+<br>
+static const float color[4][4] = {<br>
+ /* Red */<br>
+ {1.0, 0.0, 0.0, 0.0},<br>
+ /* Green */<br>
+ {0.0, 1.0, 0.0, 0.25},<br>
+ /* Yellow */<br>
+ {1.0, 1.0, 0.0, 0.75},<br>
+ /* Cyan */<br>
+ {0.0, 1.0, 1.0, 1.0} };<br>
+<br>
+static GLint prog;<br>
+static GLint color_loc;<br>
+static GLint depth_loc;<br>
+<br>
+static const char *vert =<br>
+ "#version 130\n"<br>
+ "in vec2 pos;\n"<br>
+ "uniform float depth;\n"<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " vec4 eye_pos = gl_ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);\n"<br>
+ " gl_Position = vec4(eye_pos.xy, depth, 1.0);\n"<br>
+ "}\n";<br>
+<br>
+static const char *frag =<br>
+ "#version 130\n"<br>
+ "uniform vec4 color;\n"<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " gl_FragColor = color;\n"<br>
+ "}\n";<br>
+<br>
+void<br>
+shader_compile()<br>
+{<br>
+ /* Compile program */<br>
+ GLint vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert);<br>
+ GLint fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag);<br>
+ prog = piglit_link_simple_program(vs, fs);<br>
+<br>
+ if (!piglit_link_check_status(prog)) {<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ glBindAttribLocation(prog, 0, "pos");<br>
+ glEnableVertexAttribArray(0);<br>
+<br>
+ /* Set up uniforms */<br>
+ glUseProgram(prog);<br>
+ color_loc = glGetUniformLocation(prog, "color");<br>
+ depth_loc = glGetUniformLocation(prog, "depth");<br>
+}<br>
+<br>
+void<br>
+draw_pattern(bool sample_alpha_to_one)<br>
+{<br>
+ float vertex_data[10][2] = {<br>
+ { 0, 0 },<br>
+ { 0, pattern_height },<br>
+ { pattern_width / 4, pattern_height },<br>
+ { pattern_width / 4, 0 },<br>
+ { pattern_width / 2, pattern_height },<br>
+ { pattern_width / 2, 0 },<br>
+ { 3 * pattern_width / 4, pattern_height },<br>
+ { 3 * pattern_width / 4, 0 },<br>
+ { pattern_width, pattern_height },<br>
+ { pattern_width, 0 },<br>
+ };<br>
+<br>
+ unsigned int indices[24] = {0, 1, 2, 0, 2, 3,<br>
+ 3, 2, 4, 3, 4, 5,<br>
+ 5, 4, 6, 5, 6, 7,<br>
+ 7, 6, 8, 7, 8, 9};<br>
+ glUseProgram(prog);<br>
+<br>
+ glClearColor(bg_color[0], bg_color[1],<br>
+ bg_color[2], bg_color[3]);<br>
+ glClear(buffer_to_test);<br>
+<br>
+ if (sample_alpha_to_one)<br>
+ glEnable(GL_SAMPLE_ALPHA_TO_ONE);<br>
+<br>
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_data[0]),<br>
+ (void *) vertex_data);<br>
+<br>
+ for (int i = 0; i < 4; ++i) {<br>
+ glUniform4fv(color_loc, 1, color[i]);<br>
+ glUniform1f(depth_loc, 0.0);<br>
+ glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT,<br>
+ (void *) (indices + 6 * i));<br>
+<br>
+ }<br>
+ if (sample_alpha_to_one)<br>
+ glDisable (GL_SAMPLE_ALPHA_TO_ONE);<br>
+}<br>
+<br>
+void<br>
+print_usage_and_exit(char *prog_name)<br>
+{<br>
+ printf("Usage: %s <num_samples>\n", prog_name);<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+}<br>
+<br>
+void<br>
+compute_expected(void)<br>
+{<br>
+<br>
+ /* Page 242 (page 258 of the PDF) of the OpenGL 3.0 spec says:<br>
+ * Next, if SAMPLE ALPHA TO ONE is enabled, each alpha value is<br>
+ * replaced by the maximum representable alpha value. Otherwise,<br>
+ * the alpha values are not changed.<br>
+ */<br>
+ for(int i = 0; i < 4; i++) {<br>
+ expected[i][0] = color[i][0];<br>
+ expected[i][1] = color[i][1];<br>
+ expected[i][2] = color[i][2];<br>
+ expected[i][3] = 1.0 ;<br>
+ }<br>
+}<br>
+<br>
+bool probe_framebuffer_color(GLint x_offset, const float *expected)<br>
+{<br>
+ bool result = true;<br>
+<br>
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);<br>
+ for(int i = 0; i< 4; i++) {<br>
+ result = piglit_probe_rect_rgba(x_offset + i * (pattern_width / 4),<br>
+ 0,<br>
+ pattern_width / 4,<br>
+ pattern_height,<br>
+ expected + 4 * i)<br>
+ && result;<br>
+ }<br>
+ return result;<br>
+}<br>
+<br>
+bool<br>
+test_sample_alpha_to_one(void)<br>
+{<br>
+ bool result = true;<br>
+ compute_expected();<br>
+ /* Now draw test pattern in mulisample ms_fbo with GL_SAMPLE_COVERAGE<br>
+ * enabled<br>
+ */<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ms_fbo.handle);<br>
+ draw_pattern(true);<br>
+<br>
+ /* Blit ms_fbo to the left half of window system framebuffer. This<br>
+ * is the test image.<br>
+ */<br>
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, ms_fbo.handle);<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);<br>
+ glBlitFramebuffer(0, 0, pattern_width, pattern_height,<br>
+ 0, 0, pattern_width, pattern_height,<br>
+ buffer_to_test, GL_NEAREST);<br>
+<br>
+ /* Probe the left half of default framebuffer and compare to the<br>
+ * expected values */<br>
+ if (buffer_to_test == GL_COLOR_BUFFER_BIT)<br>
+ result = probe_framebuffer_color(0, expected[0]) && result;<br>
+<br>
+ result = piglit_check_gl_error(GL_NO_ERROR) && result;<br>
+ return result;<br>
+}<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+ if (argc < 2)<br>
+ print_usage_and_exit(argv[0]);<br>
+ {<br>
+ char *endptr = NULL;<br>
+ num_samples = strtol(argv[1], &endptr, 0);<br>
+ if (endptr != argv[1] + strlen(argv[1]))<br>
+ print_usage_and_exit(argv[0]);<br>
+ }<br>
+<br>
+ piglit_require_gl_version(30);<br>
+ piglit_ortho_projection(pattern_width, pattern_height, GL_TRUE);<br>
+<br>
+ /* Skip the test if num_samples > GL_MAX_SAMPLES or num_samples = 0 */<br>
+ GLint max_samples;<br>
+ glGetIntegerv(GL_MAX_SAMPLES, &max_samples);<br>
+<br>
+ if (num_samples > max_samples ||<br>
+ num_samples == 0)<br>
+ piglit_report_result(PIGLIT_SKIP);<br>
+<br>
+ ms_fbo.setup(FboConfig(num_samples, pattern_width, pattern_height));<br>
+ buffer_to_test = GL_COLOR_BUFFER_BIT;<br>
+ shader_compile();<br>
+}<br>
+<br>
+enum piglit_result<br>
+piglit_display()<br>
+{<br>
+ bool pass = true;<br>
+ glClearColor(0.0, 0.0, 0.0, 1.0);<br>
+ glClear(GL_COLOR_BUFFER_BIT);<br>
+<br>
+ /* Draw test pattern in multisample ms_fbo with GL_SAMPLE_ALPHA_TO_ONE<br>
+ * disabled.<br>
+ */<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ms_fbo.handle);<br>
+ ms_fbo.set_viewport();<br>
+ draw_pattern(false);<br>
+<br>
+ /* Blit ms_fbo to the right half of window system framebuffer. This<br>
+ * is a reference image to see the visual difference when compared<br>
+ * to the test image.<br>
+ */<br>
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, ms_fbo.handle);<br>
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);<br>
+ glBlitFramebuffer(0, 0, pattern_width, pattern_height,<br>
+ pattern_width, 0, 2 * pattern_width, pattern_height,<br>
+ buffer_to_test, GL_NEAREST);<br>
+ /* Probe the right half of default framebuffer and compare to the<br>
+ * expected values */<br>
+ pass = probe_framebuffer_color(pattern_width, color[0]) && pass;<br>
+<br>
+ /* Now test multisample fbo with GL_SAMPLE_ALPHA_TO_ONE enabled */<br>
+ pass = test_sample_alpha_to_one() && pass;<br>
+<br>
+ if (!piglit_automatic)<br>
+ piglit_present_results();<br>
+<br>
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.7.6<br>
<br>
</font></span><br>_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
<br></blockquote></div><br>