From: Ander Conselvan de Oliveira <[email protected]>
Test creating an EGL image from a renderbuffer with a few different formats. Signed-off-by: Ander Conselvan de Oliveira <[email protected]> --- tests/all.tests | 3 + tests/spec/CMakeLists.txt | 1 + .../khr_gl_renderbuffer_image/CMakeLists.gles2.txt | 18 ++ .../spec/khr_gl_renderbuffer_image/CMakeLists.txt | 1 + .../khr_gl_renderbuffer_image.c | 194 ++++++++++++++++++++ 5 files changed, 217 insertions(+) create mode 100644 tests/spec/khr_gl_renderbuffer_image/CMakeLists.gles2.txt create mode 100644 tests/spec/khr_gl_renderbuffer_image/CMakeLists.txt create mode 100644 tests/spec/khr_gl_renderbuffer_image/khr_gl_renderbuffer_image.c diff --git a/tests/all.tests b/tests/all.tests index 5b0c9e8..30c4a28 100644 --- a/tests/all.tests +++ b/tests/all.tests @@ -3268,6 +3268,9 @@ egl_khr_gl_image = Group() spec['EGL_KHR_gl_image'] = egl_khr_gl_image egl_khr_gl_image['EGL_KHR_gl_texture_2D_image'] = plain_test('khr_gl_texture_image_gles2 -2d') egl_khr_gl_image['EGL_KHR_gl_texture_cubemap_image'] = plain_test('khr_gl_texture_image_gles2 -cubemap') +egl_khr_gl_image['EGL_KHR_gl_renderbuffer_image_rgba8'] = plain_test('khr_gl_renderbuffer_image_gles2 -rgba8') +egl_khr_gl_image['EGL_KHR_gl_renderbuffer_image_rgba4'] = plain_test('khr_gl_renderbuffer_image_gles2 -rgba4') +egl_khr_gl_image['EGL_KHR_gl_renderbuffer_image_rgb8'] = plain_test('khr_gl_renderbuffer_image_gles2 -rgb8') gles30 = Group() spec['!OpenGL ES 3.0'] = gles30 diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt index 2874314..3aee008 100644 --- a/tests/spec/CMakeLists.txt +++ b/tests/spec/CMakeLists.txt @@ -89,3 +89,4 @@ add_subdirectory (arb_blend_func_extended) add_subdirectory (ext_unpack_subimage) add_subdirectory (arb_vertex_array_object) add_subdirectory (khr_gl_texture_image) +add_subdirectory (khr_gl_renderbuffer_image) diff --git a/tests/spec/khr_gl_renderbuffer_image/CMakeLists.gles2.txt b/tests/spec/khr_gl_renderbuffer_image/CMakeLists.gles2.txt new file mode 100644 index 0000000..3909871 --- /dev/null +++ b/tests/spec/khr_gl_renderbuffer_image/CMakeLists.gles2.txt @@ -0,0 +1,18 @@ +#add_definitions(-DSOURCE_DIR="${piglit_SOURCE_DIR}/") + +include_directories( + ${OPENGL_INCLUDE_PATH} + ) + +link_libraries( + ${OPENGL_gles2_LIBRARY} + ${OPENGL_egl_LIBRARY} + piglitutil_gles2 + ) + +piglit_add_executable(khr_gl_renderbuffer_image_gles2 + khr_gl_renderbuffer_image.c + ) + +# vim: ft=cmake: + diff --git a/tests/spec/khr_gl_renderbuffer_image/CMakeLists.txt b/tests/spec/khr_gl_renderbuffer_image/CMakeLists.txt new file mode 100644 index 0000000..144a306 --- /dev/null +++ b/tests/spec/khr_gl_renderbuffer_image/CMakeLists.txt @@ -0,0 +1 @@ +piglit_include_target_api() diff --git a/tests/spec/khr_gl_renderbuffer_image/khr_gl_renderbuffer_image.c b/tests/spec/khr_gl_renderbuffer_image/khr_gl_renderbuffer_image.c new file mode 100644 index 0000000..9256c9d --- /dev/null +++ b/tests/spec/khr_gl_renderbuffer_image/khr_gl_renderbuffer_image.c @@ -0,0 +1,194 @@ +/* + * Copyright © 2012-2013 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. + * + * Authors: + * Ander Conselvan de Oliveira <[email protected]> + * + */ + +#define EGL_EGLEXT_PROTOTYPES 1 +#define GL_GLEXT_PROTOTYPES 1 +#include "piglit-util-gl-common.h" +#include "piglit-util-egl.h" + +#include <EGL/eglext.h> + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_es_version = 20; + + config.window_width = 256; + config.window_height = 256; + config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE; + +PIGLIT_GL_TEST_CONFIG_END + +static GLfloat green[4] = { + 0.0, 1.0, 0.0, 1.0 +}; + +static GLenum test_format = GL_RGBA8; + +static const char +vertex_shader[] = + "attribute vec4 pos_attrib;\n" + "attribute vec2 tex_attrib;\n" + "varying vec2 tex_coord;\n" + "void main () {\n" + "gl_Position = pos_attrib;\n" + "tex_coord = tex_attrib;\n" + "}\n"; + +static const char +fragment_shader[] = + "precision mediump float;\n" + "uniform sampler2D tex;\n" + "varying vec2 tex_coord;\n" + "void main () {\n" + "gl_FragColor = texture2D(tex, tex_coord);\n" + "}\n"; + +static void +make_program(const char *vertex_source, + const char *fragment_source) +{ + GLuint program, shader; + GLuint uniform; + + program = glCreateProgram(); + shader = piglit_compile_shader_text(GL_VERTEX_SHADER, vertex_source); + glAttachShader(program, shader); + shader = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fragment_source); + glAttachShader(program, shader); + + glBindAttribLocation(program, PIGLIT_ATTRIB_POS, "pos_attrib"); + glBindAttribLocation(program, PIGLIT_ATTRIB_TEX, "tex_attrib"); + + glLinkProgram(program); + if (!piglit_link_check_status(program)) + piglit_report_result(PIGLIT_FAIL); + + uniform = glGetUniformLocation(program, "tex"); + glUseProgram(program); + glUniform1i(uniform, 0); +} + +static GLuint +create_egl_image_target(GLuint renderbuffer) +{ + GLuint target_texture; + + EGLDisplay dpy = eglGetCurrentDisplay(); + EGLContext ctx = eglGetCurrentContext(); + EGLImageKHR image; + + image = eglCreateImageKHR(dpy, ctx, EGL_GL_RENDERBUFFER_KHR, + (EGLClientBuffer) (uintptr_t) renderbuffer, + NULL); + if (image == EGL_NO_IMAGE_KHR) + return 0; + + glGenTextures(1, &target_texture); + glBindTexture(GL_TEXTURE_2D, target_texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, + GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_NEAREST); + glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image); + + return target_texture; +} + +enum piglit_result +piglit_display(void) +{ + bool pass = true; + + GLenum status; + GLuint fb, rb; + GLuint tex; + + /* Clear the window to red */ + glClearColor(1.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + glGenFramebuffers(1, &fb); + glGenRenderbuffers(1, &rb); + + glBindFramebuffer(GL_FRAMEBUFFER, fb); + glBindRenderbuffer(GL_RENDERBUFFER, rb); + glRenderbufferStorage(GL_RENDERBUFFER, test_format, + piglit_width, piglit_height); + + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + GL_RENDERBUFFER, rb); + + status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) + pass = false; + + /* Clear the renderbuffer to green */ + glClearColor(0.0, 1.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + glBindFramebuffer(GL_FRAMEBUFFER, 0); + + glActiveTexture(GL_TEXTURE0); + make_program(vertex_shader, fragment_shader); + if (!piglit_check_gl_error(GL_NO_ERROR)) + pass = false; + + tex = create_egl_image_target(rb); + if (tex == 0) { + pass = false; + } else { + glBindTexture(GL_TEXTURE_2D, tex); + piglit_draw_rect_tex(-1, -1, 2, 2, 0, 0, 1, 1); + } + + if (!piglit_check_gl_error(GL_NO_ERROR)) + pass = false; + piglit_present_results(); + + glBindFramebuffer(GL_FRAMEBUFFER, 0); + pass = pass && piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + +void +piglit_init(int argc, char **argv) +{ + EGLDisplay dpy = eglGetCurrentDisplay(); + int i; + + if (!piglit_is_egl_extension_supported(dpy, "EGL_KHR_gl_renderbuffer_image")) + piglit_report_result(PIGLIT_SKIP); + + for (i = 1; i < argc; i++) + if (strcmp(argv[i], "-rgba4") == 0) + test_format = GL_RGBA4; + else if (strcmp(argv[i], "-rbga8") == 0) + test_format = GL_RGBA8; + else if (strcmp(argv[i], "-rbg8") == 0) + test_format = GL_RGB8; +} -- 1.7.9.5 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
