The previous test did RB -> image -> texture, and this does texture ->
image -> RB, hitting different driver paths in mesa.
---
 tests/all.tests                                    |   3 +
 tests/spec/CMakeLists.txt                          |   1 +
 .../renderbuffer-texture.c                         |   4 +
 tests/spec/oes_egl_image/CMakeLists.gles2.txt      |  11 ++
 tests/spec/oes_egl_image/CMakeLists.txt            |   1 +
 tests/spec/oes_egl_image/renderbuffer-texture.c    | 219 +++++++++++++++++++++
 6 files changed, 239 insertions(+)
 create mode 100644 tests/spec/oes_egl_image/CMakeLists.gles2.txt
 create mode 100644 tests/spec/oes_egl_image/CMakeLists.txt
 create mode 100644 tests/spec/oes_egl_image/renderbuffer-texture.c

diff --git a/tests/all.tests b/tests/all.tests
index ea115b3..ee78e1d 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -2187,6 +2187,9 @@ spec['OES_compressed_paletted_texture'] = 
oes_compressed_paletted_texture
 oes_compressed_paletted_texture['invalid formats'] = 
PlainExecTest(['arb_texture_compression-invalid-formats', 'paletted'])
 oes_compressed_paletted_texture['invalid formats'].runConcurrent = True
 
+spec['OES_EGL_image/renderbuffer-texture'] = 
plain_test('oes_egl_image-renderbuffer-texture')
+
+
 spec['OES_standard_derivatives'] = Group()
 import_glsl_parser_tests(spec['OES_standard_derivatives'],
                         os.path.join(testsDir, 'spec', 
'oes_standard_derivatives'),
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 81b3ac6..54dd9fd 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -43,6 +43,7 @@ add_subdirectory (nv_conditional_render)
 add_subdirectory (nv_texture_barrier)
 add_subdirectory (oes_compressed_etc1_rgb8_texture)
 add_subdirectory (oes_compressed_paletted_texture)
+add_subdirectory (oes_egl_image)
 add_subdirectory (arb_draw_elements_base_vertex)
 add_subdirectory (arb_fragment_program)
 add_subdirectory (arb_vertex_buffer_object)
diff --git a/tests/spec/khr_gl_renderbuffer_image/renderbuffer-texture.c 
b/tests/spec/khr_gl_renderbuffer_image/renderbuffer-texture.c
index 03e13f7..2963eda 100644
--- a/tests/spec/khr_gl_renderbuffer_image/renderbuffer-texture.c
+++ b/tests/spec/khr_gl_renderbuffer_image/renderbuffer-texture.c
@@ -30,6 +30,10 @@
  * Outside of EGL, GL renderbuffers could never be textured from, so
  * the i965 driver had a bug in this path where the render target and
  * texture caches didn't get flushed.
+ *
+ * See also KHR_gl_renderbuffer_image/renderbuffer-texture for a
+ * similar test (doing texture -> image -> RB, instead of RB -> image
+ * -> texture).
  */
 
 #include "piglit-util-gl-common.h"
diff --git a/tests/spec/oes_egl_image/CMakeLists.gles2.txt 
b/tests/spec/oes_egl_image/CMakeLists.gles2.txt
new file mode 100644
index 0000000..99a739a
--- /dev/null
+++ b/tests/spec/oes_egl_image/CMakeLists.gles2.txt
@@ -0,0 +1,11 @@
+include_directories(
+       ${GLEXT_INCLUDE_DIR}
+       ${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries(
+        piglitutil_${piglit_target_api}
+        ${OPENGL_gles2_LIBRARY}
+        )
+
+piglit_add_executable(oes_egl_image-renderbuffer-texture 
renderbuffer-texture.c)
diff --git a/tests/spec/oes_egl_image/CMakeLists.txt 
b/tests/spec/oes_egl_image/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/oes_egl_image/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/oes_egl_image/renderbuffer-texture.c 
b/tests/spec/oes_egl_image/renderbuffer-texture.c
new file mode 100644
index 0000000..f08e33d
--- /dev/null
+++ b/tests/spec/oes_egl_image/renderbuffer-texture.c
@@ -0,0 +1,219 @@
+/*
+ * Copyright © 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.
+ */
+
+
+/** @file renderbuffer-texture.c
+ *
+ * Tests that we can repeatedly render to a GL renderbuffer that is an
+ * EGL image sibling of a GL texture and sample correctly from it.
+ *
+ * Outside of EGL, GL renderbuffers could never be textured from, so
+ * the i965 driver had a bug in this path where the render target and
+ * texture caches didn't get flushed.
+ *
+ * See also KHR_gl_renderbuffer_image/renderbuffer-texture for a
+ * similar test (doing RB -> image -> texture, instead of texture ->
+ * image -> RB).
+ */
+
+#include "piglit-util-gl-common.h"
+#define GL_GLEXT_PROTOTYPES 1
+#include "piglit-util-egl.h"
+#define EGL_EGLEXT_PROTOTYPES 1
+#include <EGL/eglext.h>
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+       config.supports_gl_es_version = 20;
+
+       config.window_width = 100;
+       config.window_height = 100;
+       config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const float colors[][4] = {
+               {1, 0, 0, 1},
+               {0, 1, 0, 1},
+               {0, 0, 1, 1},
+               {1, 1, 1, 1},
+};
+
+static GLuint
+build_color_prog(void)
+{
+       const char *vs_source =
+               "#version 100\n"
+               "\n"
+               "attribute vec4 piglit_vertex;\n"
+               "\n"
+               "void main()\n"
+               "{\n"
+               "       gl_Position = piglit_vertex;\n"
+               "}\n";
+       const char *fs_source =
+               "#version 100\n"
+               "\n"
+               "uniform vec4 color;\n"
+               "\n"
+               "void main()\n"
+               "{\n"
+               "       gl_FragColor = color;\n"
+               "}\n";
+
+       return piglit_build_simple_program(vs_source, fs_source);
+}
+
+static GLuint
+build_sample_prog(void)
+{
+       const char *vs_source =
+               "#version 100\n"
+               "\n"
+               "attribute vec4 piglit_vertex;\n"
+               "attribute vec4 piglit_texcoord;\n"
+               "varying vec2 texcoord;\n"
+               "\n"
+               "void main()\n"
+               "{\n"
+               "       gl_Position = piglit_vertex;\n"
+               "       texcoord = piglit_texcoord.xy;\n"
+               "}\n";
+       const char *fs_source =
+               "#version 100\n"
+               "\n"
+               "varying vec2 texcoord;\n"
+               "uniform sampler2D s; /* defaults to 0, so unit 0 */\n"
+               "\n"
+               "void main()\n"
+               "{\n"
+               "       gl_FragColor = texture2D(s, texcoord);\n"
+               "}\n";
+
+       return piglit_build_simple_program(vs_source, fs_source);
+}
+
+static void
+draw_and_sample(int draw_index, GLuint fb,
+               GLuint color_prog, GLuint sample_prog)
+{
+       float x = draw_index & 1 ? 0 : -1;
+       float y = draw_index & 2 ? 0 : -1;
+       GLint color_loc;
+
+       glBindFramebuffer(GL_FRAMEBUFFER, fb);
+       glUseProgram(color_prog);
+       color_loc = glGetUniformLocation(color_prog, "color");
+       assert(color_loc != -1);
+       glUniform4fv(color_loc, 1, colors[draw_index]);
+       piglit_draw_rect(-1, -1, 2, 2);
+
+       glBindFramebuffer(GL_FRAMEBUFFER, 0);
+       glUseProgram(sample_prog);
+       piglit_draw_rect_tex(x, y, 1, 1,
+                            0, 0, 1, 1);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+       GLuint rb, tex, fb;
+       bool pass = true;
+       int attr[] = {
+               EGL_GL_TEXTURE_LEVEL_KHR, 0,
+               EGL_NONE
+       };
+       EGLImageKHR img;
+       GLuint color_prog, sample_prog;
+       int i;
+       int rect_w = piglit_width / 2;
+       int rect_h = piglit_height / 2;
+
+       color_prog = build_color_prog();
+       sample_prog = build_sample_prog();
+
+       /* Make the GL texture we'll read from.
+        */
+       glGenTextures(1, &tex);
+       glBindTexture(GL_TEXTURE_2D, tex);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB565,
+                    16, 16, 0,
+                    GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL);
+
+       /* Make the EGL image out of the texture*/
+       img = eglCreateImageKHR(eglGetCurrentDisplay(),
+                               eglGetCurrentContext(),
+                               EGL_GL_TEXTURE_2D_KHR,
+                               (EGLClientBuffer)(uintptr_t)tex,
+                               attr);
+
+       /* Make the RB we'll render to. */
+       glGenRenderbuffers(1, &rb);
+       glBindRenderbuffer(GL_RENDERBUFFER, rb);
+       glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER,
+                                              (GLeglImageOES)img);
+
+       /* Wrap it in an FB */
+       glGenFramebuffers(1, &fb);
+       glBindFramebuffer(GL_FRAMEBUFFER, fb);
+       glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+                                 GL_RENDERBUFFER, rb);
+
+       if (!img) {
+               fprintf(stderr, "Failed to create EGL iamge\n");
+               return PIGLIT_FAIL;
+       }
+
+       for (i = 0; i < 4; i++)
+               draw_and_sample(i, fb, color_prog, sample_prog);
+
+       pass = pass && piglit_probe_rect_rgba(0, 0, rect_w, rect_h,
+                                             colors[0]);
+       pass = pass && piglit_probe_rect_rgba(rect_w, 0, rect_w, rect_h,
+                                             colors[1]);
+       pass = pass && piglit_probe_rect_rgba(0, rect_h, rect_w, rect_h,
+                                             colors[2]);
+       pass = pass && piglit_probe_rect_rgba(rect_w, rect_h, rect_w, rect_h,
+                                             colors[3]);
+
+       glDeleteTextures(1, &tex);
+       glDeleteRenderbuffers(1, &rb);
+       glDeleteFramebuffers(1, &fb);
+       glDeleteProgram(color_prog);
+       glDeleteProgram(sample_prog);
+
+       piglit_present_results();
+
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+       /* Turns a texture into an EGL image */
+       piglit_require_egl_extension("GL_KHR_gl_texture_2D_image");
+       /* Turns an EGL image into a RB. */
+       piglit_require_extension("GL_OES_EGL_image");
+}
-- 
1.8.3.rc0

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to