diff options
author | Anuj Phogat <anuj.phogat@gmail.com> | 2012-07-12 14:58:42 -0700 |
---|---|---|
committer | Anuj Phogat <anuj.phogat@gmail.com> | 2012-07-18 10:50:56 -0700 |
commit | 526278fb1200a455d2c5982c3975002d95614b66 (patch) | |
tree | e7d6b77f982e926f00cee01f0613d9270bd84624 /tests/spec/ext_framebuffer_multisample | |
parent | 5a00f29d2ab4d6f7f927d9625563bb0a9d4e6202 (diff) |
msaa: Share visualize_image function by moving it to common.cpp
visualize_image function is utilized by multiple msaa test cases.
Reviewed-by: Paul Berry<stereotype441@gmail.com>
Diffstat (limited to 'tests/spec/ext_framebuffer_multisample')
-rw-r--r-- | tests/spec/ext_framebuffer_multisample/common.cpp | 82 | ||||
-rw-r--r-- | tests/spec/ext_framebuffer_multisample/common.h | 5 | ||||
-rw-r--r-- | tests/spec/ext_framebuffer_multisample/formats.cpp | 79 |
3 files changed, 99 insertions, 67 deletions
diff --git a/tests/spec/ext_framebuffer_multisample/common.cpp b/tests/spec/ext_framebuffer_multisample/common.cpp index 77129261e..412bf01d6 100644 --- a/tests/spec/ext_framebuffer_multisample/common.cpp +++ b/tests/spec/ext_framebuffer_multisample/common.cpp @@ -1693,3 +1693,85 @@ create_test(test_type_enum test_type, int n_samples, bool small, pattern_height, supersample_factor); return test; } + +/** + * Convert the image into a format that can be easily understood by + * visual inspection, and display it on the screen. + * + * Luminance and intensity values are converted to a grayscale value. + * Alpha values are visualized by blending the image with a grayscale + * checkerboard. + * + * Pass image_count = 0 to disable drawing multiple images to window + * system framebuffer. + */ +void +visualize_image(float *img, GLenum base_internal_format, + int image_width, int image_height, + int image_count, bool rhs) +{ + unsigned components = piglit_num_components(base_internal_format); + float *visualization = + (float *) malloc(sizeof(float)*3*image_width*image_height); + for (int y = 0; y < image_height; ++y) { + for (int x = 0; x < image_width; ++x) { + float r = 0, g = 0, b = 0, a = 1; + float *pixel = + &img[(y * image_width + x) * components]; + switch (base_internal_format) { + case GL_ALPHA: + a = pixel[0]; + break; + case GL_RGBA: + a = pixel[3]; + /* Fall through */ + case GL_RGB: + b = pixel[2]; + /* Fall through */ + case GL_RG: + g = pixel[1]; + /* Fall through */ + case GL_RED: + r = pixel[0]; + break; + case GL_LUMINANCE_ALPHA: + a = pixel[1]; + /* Fall through */ + case GL_INTENSITY: + case GL_LUMINANCE: + r = pixel[0]; + g = pixel[0]; + b = pixel[0]; + break; + } + float checker = ((x ^ y) & 0x10) ? 0.75 : 0.25; + r = r * a + checker * (1 - a); + g = g * a + checker * (1 - a); + b = b * a + checker * (1 - a); + visualization[(y * image_width + x) * 3] = r; + visualization[(y * image_width + x) * 3 + 1] = g; + visualization[(y * image_width + x) * 3 + 2] = b; + } + } + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glUseProgram(0); + + /* To simultaneously display multiple images on window system + * framebuffer. + */ + if(image_count) { + /* Use glWindowPos to directly update x, y coordinates of + * current raster position without getting transformed by + * modelview projection matrix and viewport-to-window + * transform. + */ + glWindowPos2f(rhs ? image_width : 0, + (image_count - 1) * image_height); + } + else { + glRasterPos2f(rhs ? 0 : -1, -1); + } + glDrawPixels(image_width, image_height, GL_RGB, GL_FLOAT, + visualization); + free(visualization); +} diff --git a/tests/spec/ext_framebuffer_multisample/common.h b/tests/spec/ext_framebuffer_multisample/common.h index 9d330b3cd..710d77ef9 100644 --- a/tests/spec/ext_framebuffer_multisample/common.h +++ b/tests/spec/ext_framebuffer_multisample/common.h @@ -576,3 +576,8 @@ Test * create_test(test_type_enum test_type, int n_samples, bool small, bool combine_depth_stencil, int pattern_width, int pattern_height, int supersample_factor); + +void +visualize_image(float *img, GLenum base_internal_format, + int image_width, int image_height, + int draw_buffer_count, bool rhs); diff --git a/tests/spec/ext_framebuffer_multisample/formats.cpp b/tests/spec/ext_framebuffer_multisample/formats.cpp index 960814d7f..f242c9918 100644 --- a/tests/spec/ext_framebuffer_multisample/formats.cpp +++ b/tests/spec/ext_framebuffer_multisample/formats.cpp @@ -396,70 +396,6 @@ PatternRenderer ref_renderer; /** - * Convert the image into a format that can be easily understood by - * visual inspection, and display it on the screen. - * - * Luminance and intensity values are converted to a grayscale value. - * Alpha values are visualized by blending the image with a grayscale - * checkerboard. - */ -void -visualize_image(float *img, GLenum base_internal_format, bool rhs) -{ - unsigned components = piglit_num_components(base_internal_format); - float *visualization = - (float *) malloc(sizeof(float)*3*pattern_width*pattern_height); - for (int y = 0; y < pattern_height; ++y) { - for (int x = 0; x < pattern_width; ++x) { - float r = 0, g = 0, b = 0, a = 1; - float *pixel = - &img[(y * pattern_width + x) * components]; - switch (base_internal_format) { - case GL_ALPHA: - a = pixel[0]; - break; - case GL_RGBA: - a = pixel[3]; - /* Fall through */ - case GL_RGB: - b = pixel[2]; - /* Fall through */ - case GL_RG: - g = pixel[1]; - /* Fall through */ - case GL_RED: - r = pixel[0]; - break; - case GL_LUMINANCE_ALPHA: - a = pixel[1]; - /* Fall through */ - case GL_INTENSITY: - case GL_LUMINANCE: - r = pixel[0]; - g = pixel[0]; - b = pixel[0]; - break; - } - float checker = ((x ^ y) & 0x10) ? 0.75 : 0.25; - r = r * a + checker * (1 - a); - g = g * a + checker * (1 - a); - b = b * a + checker * (1 - a); - visualization[(y * pattern_width + x) * 3] = r; - visualization[(y * pattern_width + x) * 3 + 1] = g; - visualization[(y * pattern_width + x) * 3 + 2] = b; - } - } - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); - glViewport(0, 0, piglit_width, piglit_height); - glUseProgram(0); - glRasterPos2f(rhs ? 0 : -1, -1); - glDrawPixels(pattern_width, pattern_height, GL_RGB, GL_FLOAT, - visualization); - free(visualization); -} - - -/** * Transform the reference image (which is in GL_RGBA format) to an * expected image for a given base internal format, using the the * transformation described in the GL 3.0 spec, table 3.15 (Conversion @@ -582,11 +518,20 @@ test_format(const struct format_desc *format) num_components, tolerance, expected_image, test_image); + /* Show both the test and expected images on screen so that - * the user can diagnose problems. + * the user can diagnose problems. Pass image_count = 0 to + * display image without any offset applied to raster position. */ - visualize_image(test_image, format->base_internal_format, false); - visualize_image(expected_image, format->base_internal_format, true); + glViewport(0, 0, piglit_width, piglit_height); + visualize_image(test_image, format->base_internal_format, + pattern_width, pattern_height, + 0 /* image_count */, + false /* rhs */); + visualize_image(expected_image, format->base_internal_format, + pattern_width, pattern_height, + 0 /* image_count */, + true /* rhs */); /* Finally, if any error occurred, count that as a failure. */ pass = piglit_check_gl_error(GL_NO_ERROR) && pass; |