diff options
author | Pauli Nieminen <pauli.nieminen@linux.intel.com> | 2012-06-15 15:04:32 +0300 |
---|---|---|
committer | Pauli Nieminen <pauli.nieminen@linux.intel.com> | 2012-06-15 15:32:27 +0300 |
commit | 6c2d6aeecd600504b69f329fabd7122d08f19b6f (patch) | |
tree | 4eb25dd1b5f8c654eb7e874622a436bdc7cbfa66 | |
parent | 7b6ccaae3c45051c3dc311ff16551f70d16abf4e (diff) |
image_external: Tests GL texture support for YUV formatsexternal_image4
-rw-r--r-- | tests/spec/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/spec/oes_egl_image_external/CMakeLists.gl.txt | 13 | ||||
-rw-r--r-- | tests/spec/oes_egl_image_external/CMakeLists.gles1.txt | 15 | ||||
-rw-r--r-- | tests/spec/oes_egl_image_external/CMakeLists.gles2.txt | 15 | ||||
-rw-r--r-- | tests/spec/oes_egl_image_external/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tests/spec/oes_egl_image_external/oes_egl_image_external_420.c | 394 |
6 files changed, 441 insertions, 0 deletions
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt index 2907a8e2..01e2d44f 100644 --- a/tests/spec/CMakeLists.txt +++ b/tests/spec/CMakeLists.txt @@ -53,3 +53,4 @@ add_subdirectory (oes_draw_texture) add_subdirectory (arb_blend_func_extended) add_subdirectory (ext_unpack_subimage) add_subdirectory (khr_gl_texture_image) +add_subdirectory (oes_egl_image_external) diff --git a/tests/spec/oes_egl_image_external/CMakeLists.gl.txt b/tests/spec/oes_egl_image_external/CMakeLists.gl.txt new file mode 100644 index 00000000..fded120d --- /dev/null +++ b/tests/spec/oes_egl_image_external/CMakeLists.gl.txt @@ -0,0 +1,13 @@ +include_directories( + ${OPENGL_INCLUDE_PATH} + ) + +link_libraries( + piglitutil + ) + +piglit_add_executable(oes_egl_image_external_420 + oes_egl_image_external_420.c + ) + +# vim: ft=cmake: diff --git a/tests/spec/oes_egl_image_external/CMakeLists.gles1.txt b/tests/spec/oes_egl_image_external/CMakeLists.gles1.txt new file mode 100644 index 00000000..b05ca4bd --- /dev/null +++ b/tests/spec/oes_egl_image_external/CMakeLists.gles1.txt @@ -0,0 +1,15 @@ +#add_definitions(-DSOURCE_DIR="${piglit_SOURCE_DIR}/") + +include_directories( + ${OPENGL_INCLUDE_PATH} + ) + +link_libraries( + piglitutil_gles1 + ) + +piglit_add_executable(oes_egl_image_external_420_gles1 + oes_egl_image_external_420.c + ) + +# vim: ft=cmake: diff --git a/tests/spec/oes_egl_image_external/CMakeLists.gles2.txt b/tests/spec/oes_egl_image_external/CMakeLists.gles2.txt new file mode 100644 index 00000000..5edf84c9 --- /dev/null +++ b/tests/spec/oes_egl_image_external/CMakeLists.gles2.txt @@ -0,0 +1,15 @@ +#add_definitions(-DSOURCE_DIR="${piglit_SOURCE_DIR}/") + +include_directories( + ${OPENGL_INCLUDE_PATH} + ) + +link_libraries( + piglitutil_gles2 + ) + +piglit_add_executable(oes_egl_image_external_420_gles2 + oes_egl_image_external_420.c + ) + +# vim: ft=cmake: diff --git a/tests/spec/oes_egl_image_external/CMakeLists.txt b/tests/spec/oes_egl_image_external/CMakeLists.txt new file mode 100644 index 00000000..d9d41f22 --- /dev/null +++ b/tests/spec/oes_egl_image_external/CMakeLists.txt @@ -0,0 +1,3 @@ +if(OPENGL_egl_LIBRARY) + piglit_include_target_api() +endif(OPENGL_egl_LIBRARY) diff --git a/tests/spec/oes_egl_image_external/oes_egl_image_external_420.c b/tests/spec/oes_egl_image_external/oes_egl_image_external_420.c new file mode 100644 index 00000000..5a630567 --- /dev/null +++ b/tests/spec/oes_egl_image_external/oes_egl_image_external_420.c @@ -0,0 +1,394 @@ +/* + * 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. + * + * Author: Pauli Nieminen <pauli.nieminen@linux.intel.com> + */ + +#include "piglit-util.h" +#include "piglit-util-egl.h" + +#include <assert.h> +#include <libgen.h> + +#define NR_TEXS 6.0f + +static const float nr_textures = NR_TEXS; +int piglit_width = 32*NR_TEXS, piglit_height = 32; +int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE; + +static const float red[] = {1.0, 0.0, 0.0, 1.0}; +static const float green[] = {0.0, 1.0, 0.0, 1.0}; +static const float blue[] = {0.0, 0.0, 1.0, 1.0}; +static const float white[] = {1.0, 1.0, 1.0, 1.0}; + +static void +ycbcr_to_rgb(const float y, const float cb, const float cr, float rgb[3]) +{ + const float in[2][4] = { + {-.5f, -.0625f, -.5f, 1.164f}, + {1.596f, -0.813f, 2.018f, -.391f}, + }; + float temp[4]; + + temp[0] = in[0][0] + cr/255.0f; + temp[1] = in[0][1] + y/255.0f; + temp[2] = in[0][2] + cb/255.0f; + temp[1] = in[0][3] * temp[1]; + rgb[0] = temp[0] * in[1][0] + temp[1]; + rgb[1] = temp[0] * in[1][1] + temp[1]; + rgb[2] = temp[2] * in[1][2] + temp[1]; + rgb[1] = temp[2] * in[1][3] + rgb[1]; +} + +static void +rgb_to_ycbcr(const float rgb[3], GLubyte ycbcr[3], bool prin) +{ + const float kb = 0.114f; + const float kr = 0.299f; + float y, cb, cr; + float r[3]; + + y = rgb[0] * kr + (1.0f - kr - kb) * rgb[1] + kb * rgb[2]; + cb = 0.5f * ((rgb[2] - y) / (1 - kb)); + cr = 0.5f * ((rgb[0] - y) / (1 - kr)); + + y = 16.0f + 219.0f * y; + cb = 128.0f + 224.0f * cb; + cr = 128.0f + 224.0f * cr; + ycbcr_to_rgb(y, cb, cr, r); + + ycbcr[0] = y; + ycbcr[1] = cb; + ycbcr[2] = cr; +} + +#define TEXTURE_SIZE 64 + +static bool +draw_and_check(GLfloat x, GLfloat y, GLfloat w, GLfloat h, float rgb_data[][4], GLuint wt, GLuint ht) +{ + bool pass = true; + GLuint i, j; + + + GLint ix = (x + 1.0) * piglit_width / 2; + GLint iy = (y + 1.0) * piglit_height / 2; + + GLint iw = w * piglit_width / wt; + GLint ih = h * piglit_height / ht; + + wt /= 2; + ht /= 2; + + piglit_draw_rect_tex(x, y, w, h, + 0, 0, 1.0, 1.0); + + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + for (j = 0; j < ht; j++) { + for (i = 0; i < wt; i++) { + pass = piglit_probe_pixel_rgba(ix + iw * i + iw/2, + iy + ih * j + ih/2, + rgb_data[i + j*wt]) && pass; + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + } + } + + return pass; + +} + +static void +set_ycbcr(GLubyte *data, GLsizei planes, GLsizei x, GLsizei y, GLsizei w, GLsizei h, float rgb_data[][4]) +{ + GLubyte ycbcr[3]; + float *rgb; + GLsizei offset; + GLsizei uv_order = planes == 4 ? 1 : 0; + if (planes == 4) + planes = 2; + rgb = rgb_data[x/2 + y/2*w/2]; + rgb_to_ycbcr(rgb, ycbcr, (x&1) && (y&1)); + + data[x + y*w] = ycbcr[0]; + offset = w*h; + if (planes == 2) { + data[offset + (x&(~1)) + y/2*w + uv_order] = ycbcr[1]; + data[offset + (x&(~1)) + y/2*w + 1 - uv_order] = ycbcr[2]; + } else { + data[offset + x/2 + y/2*w/2] = ycbcr[1]; + offset += w*h/4; + data[offset + x/2 + y/2*w/2] = ycbcr[2]; + } +} + +static void +set_ycbcr_422(GLubyte *data, GLsizei planes, GLsizei x, GLsizei y, GLsizei w, GLsizei h, float rgb_data[][4]) +{ + GLubyte ycbcr[3]; + float *rgb; + rgb = rgb_data[x/2 + y/2*w/2]; + rgb_to_ycbcr(rgb, ycbcr, (x&1) && (y&1)); + + data[x*2 + y*w*2 + planes] = ycbcr[0]; + if (x & 1) + data[x*2 + y*w*2 + 1 - planes] = ycbcr[2]; + else + data[x*2 + y*w*2 + 1 - planes] = ycbcr[1]; +} + +enum piglit_result +piglit_display(void) +{ + GLuint tex; + bool pass = true; + const GLsizei w = 8, h = 8; + float i = 0.0; + GLsizei x, y; + GLubyte data[MAX2(w*h + w*h/2*2, w/2*h/2*4)]; +#if 1 + float rgb_data[][4] = { + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + {rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, rand()/(float)RAND_MAX, 1.0}, + }; +#else + float rgb_data[][4] = { + {1.0, 0.0, 0.0, 1.0}, + {1.0, 0.0, 0.0, 1.0}, + {0.0, 1.0, 0.0, 1.0}, + {0.0, 1.0, 0.0, 1.0}, + {1.0, 0.0, 0.0, 1.0}, + {1.0, 0.0, 0.0, 1.0}, + {0.0, 1.0, 0.0, 1.0}, + {0.0, 1.0, 0.0, 1.0}, + {0.0, 0.0, 1.0, 1.0}, + {0.0, 0.0, 1.0, 1.0}, + {1.0, 1.0, 1.0, 1.0}, + {1.0, 1.0, 1.0, 1.0}, + {0.0, 0.0, 1.0, 1.0}, + {0.0, 0.0, 1.0, 1.0}, + {1.0, 1.0, 1.0, 1.0}, + {1.0, 1.0, 1.0, 1.0}, + }; +#endif + + printf("Formats from left to right RGBA, YUYV422, YV12, UYVY422, NV12, NV21\n"); + glClear(GL_COLOR_BUFFER_BIT); + + glGenTextures(1, &tex); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + glBindTexture(GL_TEXTURE_2D, tex); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + if (!piglit_is_gles()) { + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w/2, h/2, 0, GL_RGBA, GL_FLOAT, rgb_data); + } else { + for (y = 0; y < ARRAY_SIZE(rgb_data); y++) { + for (x = 0; x < ARRAY_SIZE(rgb_data[0]); x++) + data[x + y * ARRAY_SIZE(rgb_data[0])] = rgb_data[y][x] * 255; + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w/2, h/2, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); + } + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + /* Test sampling */ + piglit_use_shader(PIGLIT_SHADER_TEX); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + pass = draw_and_check(-1 + i*2.0/nr_textures , -1, + 2.0/nr_textures, 2.0, rgb_data, w, h) && pass; + + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + i+=1.0; + + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + set_ycbcr_422(data, 0, x, y, w, h, rgb_data); + } + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_YCBCR_MESA, w, h, 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_REV_MESA, data); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + + /* Test sampling */ + piglit_use_shader(PIGLIT_SHADER_TEX); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + pass = draw_and_check(-1 + i*2.0/nr_textures , -1, + 2.0/nr_textures, 2.0, rgb_data, w, h) && pass; + + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + pass = piglit_probe_rect_halves_equal_rgba((i-1.0)*piglit_width/nr_textures, + 0, + 2*piglit_width/nr_textures, + piglit_height) && pass; + i+=1.0; + + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + set_ycbcr(data, 3, x, y, w, h, rgb_data); + } + } + +#define GL_YCBCR_420_2PLANE_MESA 0xAE23 +#define GL_YCBCR_420_3PLANE_MESA 0xAE24 + + glTexImage2D(GL_TEXTURE_2D, 0, GL_YCBCR_420_3PLANE_MESA, w, h, 0, GL_YCBCR_420_3PLANE_MESA, GL_UNSIGNED_SHORT_8_8_MESA, data); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + + /* Test sampling */ + piglit_use_shader(PIGLIT_SHADER_TEX); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + pass = draw_and_check(-1 + i*2.0/nr_textures , -1, + 2.0/nr_textures, 2.0, rgb_data, w, h) && pass; + + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + pass = piglit_probe_rect_halves_equal_rgba((i-1.0)*piglit_width/nr_textures, + 0, + 2*piglit_width/nr_textures, + piglit_height) + && pass; + + i += 1.0; + + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + set_ycbcr_422(data, 1, x, y, w, h, rgb_data); + } + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_YCBCR_MESA, w, h, 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, data); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + + /* Test sampling */ + piglit_use_shader(PIGLIT_SHADER_TEX); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + pass = draw_and_check(-1 + i*2.0/nr_textures , -1, + 2.0/nr_textures, 2.0, rgb_data, w, h) && pass; + + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + pass = piglit_probe_rect_halves_equal_rgba((i-1.0)*piglit_width/nr_textures, + 0, + 2*piglit_width/nr_textures, + piglit_height) + && pass; + i+=1.0; + + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + set_ycbcr(data, 2, x, y, w, h, rgb_data); + } + } + +#define GL_YCBCR_420_2PLANE_MESA 0xAE23 +#define GL_YCBCR_420_3PLANE_MESA 0xAE24 + + glTexImage2D(GL_TEXTURE_2D, 0, GL_YCBCR_420_2PLANE_MESA, w, h, 0, GL_YCBCR_420_2PLANE_MESA, GL_UNSIGNED_SHORT_8_8_MESA, data); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + + /* Test sampling */ + piglit_use_shader(PIGLIT_SHADER_TEX); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + pass = draw_and_check(-1 + i*2.0/nr_textures , -1, + 2.0/nr_textures, 2.0, rgb_data, w, h) && pass; + + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + pass = piglit_probe_rect_halves_equal_rgba((i-1.0)*piglit_width/nr_textures, + 0, + 2*piglit_width/nr_textures, + piglit_height) + && pass; + + i+=1.0; + + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + set_ycbcr(data, 4, x, y, w, h, rgb_data); + } + } + +#define GL_YCBCR_420_2PLANE_MESA 0xAE23 +#define GL_YCBCR_420_3PLANE_MESA 0xAE24 + + glTexImage2D(GL_TEXTURE_2D, 0, GL_YCBCR_420_2PLANE_MESA, w, h, 0, GL_YCBCR_420_2PLANE_MESA, GL_UNSIGNED_SHORT_8_8_REV_MESA, data); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + + /* Test sampling */ + piglit_use_shader(PIGLIT_SHADER_TEX); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + pass = draw_and_check(-1 + i*2.0/nr_textures , -1, + 2.0/nr_textures, 2.0, rgb_data, w, h) && pass; + + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + pass = piglit_probe_rect_halves_equal_rgba((i-1.0)*piglit_width/nr_textures, + 0, + 2*piglit_width/nr_textures, + piglit_height) + && pass; + + glDeleteTextures(1, &tex); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + piglit_present_results(); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + +void +piglit_init(int argc, char **argv) +{ +} |