This test varifies that alpha value is not changed with
GL_SAMPLE_ALPHA_TO_ONE enabled if GL_MULTISAMPLE is disabled
or buffer is not a multisample buffer.

Signed-off-by: Anuj Phogat <[email protected]>
---
 tests/all.tests                                    |    6 +
 .../ext_framebuffer_multisample/CMakeLists.gl.txt  |    1 +
 .../negative-sample-alpha-to-one.cpp               |  296 ++++++++++++++++++++
 3 files changed, 303 insertions(+), 0 deletions(-)
 create mode 100644 
tests/spec/ext_framebuffer_multisample/negative-sample-alpha-to-one.cpp

diff --git a/tests/all.tests b/tests/all.tests
index 215ac9c..f6a9a9e 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1423,6 +1423,12 @@ for num_samples in MSAA_SAMPLE_COUNTS:
         ext_framebuffer_multisample[test_name] = PlainExecTest(executable)
 
 for num_samples in MSAA_SAMPLE_COUNTS:
+        test_name = ' '.join(['negative-sample-alpha-to-one', 
str(num_samples)])
+        executable = 'ext_framebuffer_multisample-{0} -auto'.format(
+                test_name)
+        ext_framebuffer_multisample[test_name] = PlainExecTest(executable)
+
+for num_samples in MSAA_SAMPLE_COUNTS:
         test_name = ' '.join(['bitmap', str(num_samples)])
         executable = 'ext_framebuffer_multisample-{0} -auto'.format(
                 test_name)
diff --git a/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt 
b/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt
index 338a5e8..74db2a5 100644
--- a/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt
+++ b/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt
@@ -26,6 +26,7 @@ piglit_add_executable 
(ext_framebuffer_multisample-negative-copyteximage negativ
 piglit_add_executable (ext_framebuffer_multisample-negative-max-samples 
negative-max-samples.c)
 piglit_add_executable (ext_framebuffer_multisample-negative-mismatched-samples 
negative-mismatched-samples.c)
 piglit_add_executable (ext_framebuffer_multisample-negative-readpixels 
negative-readpixels.c)
+piglit_add_executable 
(ext_framebuffer_multisample-negative-sample-alpha-to-one common.cpp 
negative-sample-alpha-to-one.cpp)
 piglit_add_executable (ext_framebuffer_multisample-point-smooth common.cpp 
point-smooth.cpp)
 piglit_add_executable (ext_framebuffer_multisample-polygon-smooth common.cpp 
polygon-smooth.cpp)
 piglit_add_executable (ext_framebuffer_multisample-polygon-stipple common.cpp 
polygon-stipple.cpp)
diff --git 
a/tests/spec/ext_framebuffer_multisample/negative-sample-alpha-to-one.cpp 
b/tests/spec/ext_framebuffer_multisample/negative-sample-alpha-to-one.cpp
new file mode 100644
index 0000000..7429223
--- /dev/null
+++ b/tests/spec/ext_framebuffer_multisample/negative-sample-alpha-to-one.cpp
@@ -0,0 +1,296 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "common.h"
+
+/**
+ * \file negative-sample-alpha-to-one.cpp
+ *
+ * Verify that alpha values are not modified if GL_SAMPLE_ALPHA_TO_ONE is
+ * enabled and GL_MULTISAMPLE is disabled in a multisample buffer.
+ *
+ * Also, verify that alpha values are not modified if GL_SAMPLE_ALPHA_TO_ONE
+ * is enabled and the buffer is single-sampled.
+ *
+ * Author: Anuj Phogat <[email protected]>
+ */
+
+PIGLIT_GL_TEST_MAIN(512 /*window_width*/,
+                   256 /*window_height*/,
+                   GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA)
+
+const int pattern_width = 256; const int pattern_height = 256;
+static Fbo ms_fbo, resolve_fbo;
+static GLbitfield buffer_to_test;
+
+static GLfloat *color = NULL;
+static GLint num_samples;
+static GLint num_rects;
+static GLint prog;
+static GLint color_loc;
+static GLint depth_loc;
+
+static const float bg_color[4] =
+       {0.4, 0.2, 0.6, 0.8};
+
+
+static const char *vert =
+       "#version 130\n"
+       "in vec2 pos;\n"
+       "uniform float depth;\n"
+       "void main()\n"
+       "{\n"
+       "  vec4 eye_pos = gl_ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);\n"
+       "  gl_Position = vec4(eye_pos.xy, depth, 1.0);\n"
+       "}\n";
+
+static const char *frag =
+       "#version 130\n"
+       "uniform vec4 color;\n"
+       "void main()\n"
+       "{\n"
+       "  gl_FragColor = color;\n"
+       "}\n";
+
+void
+shader_compile()
+{
+       /* Compile program */
+       GLint vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert);
+       GLint fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag);
+       prog = piglit_link_simple_program(vs, fs);
+
+       if (!piglit_link_check_status(prog)) {
+               piglit_report_result(PIGLIT_FAIL);
+       }
+
+       glBindAttribLocation(prog, 0, "pos");
+       glEnableVertexAttribArray(0);
+
+       /* Set up uniforms */
+       glUseProgram(prog);
+       color_loc = glGetUniformLocation(prog, "color");
+       depth_loc = glGetUniformLocation(prog, "depth");
+}
+
+void
+draw_pattern(bool sample_alpha_to_one)
+{
+       glUseProgram(prog);
+       glClearColor(bg_color[0], bg_color[1],
+                    bg_color[2], bg_color[3]);
+
+       glClear(buffer_to_test);
+       if (sample_alpha_to_one)
+               glEnable (GL_SAMPLE_ALPHA_TO_ONE);
+
+       unsigned int indices[6] = {0, 1, 2, 0, 2, 3};
+
+       for (int i = 0; i < num_rects; i++) {
+
+               float vertex_data[4][2] = {
+               { 0.0f + i * (pattern_width / num_rects),   0.0f           },
+               { 0.0f + i * (pattern_width / num_rects),   pattern_height },
+               { (i + 1.0f) * (pattern_width / num_rects), pattern_height },
+               { (i + 1.0f) * (pattern_width / num_rects), 0.0f           } };
+
+               glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE,
+                                     sizeof(vertex_data[0]),
+                                     (void *) vertex_data);
+
+               glUniform4fv(color_loc, 1, (color + i * 4));
+               glUniform1f(depth_loc, 0.0f);
+               glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT,
+                              (void *) indices);
+       }
+       if(sample_alpha_to_one)
+               glDisable (GL_SAMPLE_ALPHA_TO_ONE);
+}
+
+void
+print_usage_and_exit(char *prog_name)
+{
+       printf("Usage: %s <num_samples>\n", prog_name);
+       piglit_report_result(PIGLIT_FAIL);
+}
+
+
+bool
+test_sample_alpha_to_one(Fbo *test_fbo)
+{
+       bool result = true;
+       /* Draw test pattern in multisample ms_fbo with GL_SAMPLE_COVERAGE
+        * enabled
+        */
+       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, test_fbo->handle);
+       draw_pattern(true);
+
+       if (test_fbo->handle == ms_fbo.handle) {
+               /* Blit test_fbo to resolve_fbo */
+               glBindFramebuffer(GL_READ_FRAMEBUFFER, test_fbo->handle);
+               glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolve_fbo.handle);
+               glBlitFramebuffer(0, 0, pattern_width, pattern_height,
+                                 0, 0, pattern_width, pattern_height,
+                                 buffer_to_test, GL_NEAREST);
+       }
+
+       /* Blit resolve_fbo to the left half of window system framebuffer.
+        * This is the test image.
+        */
+       glBindFramebuffer(GL_READ_FRAMEBUFFER, resolve_fbo.handle);
+       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+       glBlitFramebuffer(0, 0, pattern_width, pattern_height,
+                         0, 0, pattern_width, pattern_height,
+                         buffer_to_test, GL_NEAREST);
+
+       glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
+       result = piglit_probe_rect_halves_equal_rgba(0, 0, piglit_width,
+                                                  piglit_height) && result;
+
+       result = piglit_check_gl_error(GL_NO_ERROR) && result;
+       return result;
+}
+
+void
+draw_reference_image(void)
+{
+       /* Draw test pattern in  multisample ms_fbo with GL_SAMPLE_ALPHA_TO_ONE
+        * disabled.
+        */
+       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ms_fbo.handle);
+       ms_fbo.set_viewport();
+       draw_pattern(false);
+
+       /* Blit ms_fbo to resolve_fbo */
+       glBindFramebuffer(GL_READ_FRAMEBUFFER, ms_fbo.handle);
+       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolve_fbo.handle);
+       glBlitFramebuffer(0, 0, pattern_width, pattern_height,
+                         0, 0, pattern_width, pattern_height,
+                         buffer_to_test, GL_NEAREST);
+
+       /* Blit ms_fbo to the right half of window system framebuffer. This
+        * is a reference image to see the visual difference when compared
+        * to the test image.
+        */
+       glBindFramebuffer(GL_READ_FRAMEBUFFER, resolve_fbo.handle);
+       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+       glBlitFramebuffer(0, 0, pattern_width, pattern_height,
+                         pattern_width, 0, 2 * pattern_width, pattern_height,
+                         buffer_to_test, GL_NEAREST);
+}
+
+void
+allocate_data_arrays(void)
+{
+       /* Draw 2N + 1 rectangles for N samples, each with a unique color */
+       num_rects = 2 * num_samples + 1;
+
+       /* Allocate data arrays based on number of samples used */
+       color = (float *) malloc(num_rects * 4 * sizeof(float));
+
+       for(int i = 0; i < num_rects; i++) {
+               color[i * 4 + 0] = (sin(i * 4 + 0) + 1) / 2;
+               color[i * 4 + 1] = (sin(i * 4 + 1) + 1) / 2;
+               color[i * 4 + 2] = (sin(i * 4 + 2) + 1) / 2;
+               color[i * 4 + 3] = (sin(i * 4 + 3) + 1) / 2;
+       }
+}
+
+void
+free_data_arrays(void)
+{
+       if(color != NULL) {
+               free(color);
+               color = NULL;
+       }
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+       if (argc < 2)
+               print_usage_and_exit(argv[0]);
+       {
+               char *endptr = NULL;
+               num_samples = strtol(argv[1], &endptr, 0);
+               if (endptr != argv[1] + strlen(argv[1]))
+                       print_usage_and_exit(argv[0]);
+       }
+
+       piglit_require_gl_version(30);
+       piglit_ortho_projection(pattern_width, pattern_height, GL_TRUE);
+
+       /* Skip the test if num_samples > GL_MAX_SAMPLES */
+       GLint max_samples;
+       glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
+
+       if (num_samples > max_samples)
+               piglit_report_result(PIGLIT_SKIP);
+
+       ms_fbo.setup(FboConfig(num_samples, pattern_width, pattern_height));
+       resolve_fbo.setup(FboConfig(0, pattern_width, pattern_height));
+
+       if (!piglit_check_gl_error(GL_NO_ERROR)) {
+                printf("Error setting up frame buffer objects\n");
+               piglit_report_result(PIGLIT_FAIL);
+       }
+
+       buffer_to_test = GL_COLOR_BUFFER_BIT;
+
+       /* Enable blending to easily detect any change in alpha values
+        * caused by GL_SAMPLE_ALPHA_TO_ONE
+        */
+       glEnable(GL_BLEND);
+       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+       shader_compile();
+}
+
+enum piglit_result
+piglit_display()
+{
+       bool pass = true;
+       glClearColor(0.0, 0.0, 0.0, 1.0);
+       glClear(GL_COLOR_BUFFER_BIT);
+
+       allocate_data_arrays();
+       draw_reference_image();
+
+       /* Test multisample fbo with GL_SAMPLE_ALPHA_TO_ONE enabled but
+        * GL_MULTISAMPLE disabled */
+       glDisable(GL_MULTISAMPLE);
+
+       pass = test_sample_alpha_to_one(&ms_fbo) && pass;
+
+       glEnable(GL_MULTISAMPLE);
+
+       /* Test singlesample fbo with GL_SAMPLE_ALPHA_TO_ONE enabled */
+       pass = test_sample_alpha_to_one(&resolve_fbo) && pass;
+
+       free_data_arrays();
+
+       if (!piglit_automatic)
+               piglit_present_results();
+
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
-- 
1.7.7.6

_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to