[Piglit] [PATCH 4/4] Add a test for rendering to a renderbuffer sibling of a GL texture.
Eric Anholt
eric at anholt.net
Wed May 8 14:02:02 PDT 2013
---
tests/all.tests | 2 +
tests/spec/CMakeLists.txt | 1 +
.../khr_gl_renderbuffer_image/CMakeLists.gles2.txt | 11 ++
.../spec/khr_gl_renderbuffer_image/CMakeLists.txt | 1 +
.../renderbuffer-texture.c | 210 +++++++++++++++++++++
5 files changed, 225 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/renderbuffer-texture.c
diff --git a/tests/all.tests b/tests/all.tests
index f04c77a..02eb855 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -2821,6 +2821,8 @@ egl_khr_create_context['3.2 core profile required'] = plain_test('egl-create-con
egl_khr_create_context['pre-GL3.2 profile'] = plain_test('egl-create-context-pre-GL32-profile')
egl_khr_create_context['verify GL flavor'] = plain_test('egl-create-context-verify-gl-flavor')
+spec['EGL_KHR_gl_renderbuffer_image/renderbuffer-texture'] = plain_test('khr_gl_renderbuffer_image-renderbuffer-texture')
+
gles20 = Group()
spec['!OpenGL ES 2.0'] = gles20
gles20['glsl-fs-pointcoord'] = concurrent_test('glsl-fs-pointcoord_gles2')
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index a1492cc..81b3ac6 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -63,6 +63,7 @@ add_subdirectory (gles-3.0)
add_subdirectory (glx_arb_create_context)
add_subdirectory (glx_ext_import_context)
add_subdirectory (glx_oml_sync_control)
+add_subdirectory (khr_gl_renderbuffer_image)
add_subdirectory (arb_vertex_type_2_10_10_10_rev)
add_subdirectory (ext_texture_array)
add_subdirectory (ext_texture_integer)
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..ff73255
--- /dev/null
+++ b/tests/spec/khr_gl_renderbuffer_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(khr_gl_renderbuffer_image-renderbuffer-texture renderbuffer-texture.c)
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/renderbuffer-texture.c b/tests/spec/khr_gl_renderbuffer_image/renderbuffer-texture.c
new file mode 100644
index 0000000..7fd827a
--- /dev/null
+++ b/tests/spec/khr_gl_renderbuffer_image/renderbuffer-texture.c
@@ -0,0 +1,210 @@
+/*
+ * 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
+ *
+ * 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.
+ */
+
+#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_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 RB we'll render to. */
+ glGenRenderbuffers(1, &rb);
+ glBindRenderbuffer(GL_RENDERBUFFER, rb);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16);
+
+ /* Wrap it in an FB */
+ glGenFramebuffers(1, &fb);
+ glBindFramebuffer(GL_FRAMEBUFFER, fb);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+ GL_RENDERBUFFER, rb);
+ /* Make the EGL image out of the RB */
+ img = eglCreateImageKHR(eglGetCurrentDisplay(),
+ eglGetCurrentContext(),
+ EGL_GL_RENDERBUFFER_KHR,
+ (EGLClientBuffer)(uintptr_t)rb,
+ attr);
+
+ if (!img) {
+ fprintf(stderr, "Failed to create EGL iamge\n");
+ return PIGLIT_FAIL;
+ }
+
+ /* Make the GL texture out of the EGL image. This will be an
+ * EGL image sibling, but the contents at the moment are
+ * undefined.
+ */
+ 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);
+ glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)img);
+
+ 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 an RB into an EGL image */
+ piglit_require_egl_extension("GL_KHR_gl_renderbuffer_image");
+ /* Turns an EGL image into a texture. */
+ piglit_require_extension("GL_OES_EGL_image");
+}
--
1.8.3.rc0
More information about the Piglit
mailing list