[Piglit] [PATCH] EGL_NOK_texture_from_pixmap test for OpenGL ES 2.0
Tapani Pälli
tapani.palli at intel.com
Mon Feb 10 05:36:13 PST 2014
Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
---
tests/egl/CMakeLists.gles2.txt | 15 ++
tests/egl/egl-nok-texture-from-pixmap-gles2.c | 249 ++++++++++++++++++++++++++
2 files changed, 264 insertions(+)
create mode 100644 tests/egl/CMakeLists.gles2.txt
create mode 100644 tests/egl/egl-nok-texture-from-pixmap-gles2.c
diff --git a/tests/egl/CMakeLists.gles2.txt b/tests/egl/CMakeLists.gles2.txt
new file mode 100644
index 0000000..1a2a700
--- /dev/null
+++ b/tests/egl/CMakeLists.gles2.txt
@@ -0,0 +1,15 @@
+
+include_directories(
+ ${GLEXT_INCLUDE_DIR}
+ ${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+ piglitutil_gles2
+ ${EGL_LDFLAGS}
+ ${OPENGL_gles2_LIBRARY}
+)
+
+piglit_add_executable (egl-nok-texture-from-pixmap-gles2 egl-nok-texture-from-pixmap-gles2.c egl-util.c)
+
+# vim: ft=cmake:
diff --git a/tests/egl/egl-nok-texture-from-pixmap-gles2.c b/tests/egl/egl-nok-texture-from-pixmap-gles2.c
new file mode 100644
index 0000000..f7bc3c2
--- /dev/null
+++ b/tests/egl/egl-nok-texture-from-pixmap-gles2.c
@@ -0,0 +1,249 @@
+/*
+ * Copyright © 2014 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: Tapani Palli <tapani.palli at intel.com>
+ */
+
+/** @file egl-nok-texture-from-pixmap-gles2.c
+ *
+ * Test EGL_NOK_texture_from_pixmap with OpenGL ES 2.0
+ * http://www.khronos.org/registry/egl/extensions/NOK/EGL_NOK_texture_from_pixmap.txt
+ */
+
+#include "piglit-util-gl-common.h"
+#include "piglit-util-egl.h"
+#include "egl-util.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+ config.supports_gl_es_version = 20;
+PIGLIT_GL_TEST_CONFIG_END
+
+const char *extensions[] = { "EGL_NOK_texture_from_pixmap", NULL };
+
+const char *vert = "attribute vec4 vertex;\n\
+attribute vec4 uvcoord;\n\
+varying mediump vec2 texc;\n\
+void main()\n\
+{\n\
+gl_Position = vertex;\n\
+texc = uvcoord.st;\n\
+}\n";
+
+const char *frag = "uniform sampler2D tex0;\n\
+varying mediump vec2 texc;\n\
+void main()\n\
+{\n\
+gl_FragColor = texture2D(tex0, texc);\n\
+}\n";
+
+#define W 157
+#define H 203
+
+/*
+ * Creates a test pixmap that has red rectangle on top-right corner and
+ * a blue one on bottom-left
+ */
+static EGLSurface *
+create_test_pixmap(struct egl_state *state,
+ int w, int h, const EGLint texture_format)
+{
+ static EGLint pixmap_attribs[] = {
+ EGL_TEXTURE_FORMAT, 0,
+ EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
+ EGL_NONE
+ };
+
+ int x, y, bpp;
+
+ Pixmap pixmap = XCreatePixmap(state->dpy, state->win, w, h,
+ state->depth);
+
+ XImage *ximg = XGetImage(state->dpy, pixmap, 0, 0, w, h, 0, ZPixmap);
+
+ if (!ximg)
+ return NULL;
+
+ bpp = ximg->bits_per_pixel/8;
+
+ for (y = 0; y < ximg->height; y++) {
+ char *p = ximg->data + y * ximg->bytes_per_line;
+ for (x = 0; x < ximg->width; x++, p += bpp) {
+ int32_t color = ((y < ximg->height / 2) ?
+ 0xffff0000 : 0xff0000ff) |
+ ((x < ximg->width / 2) ?
+ 0xff0000ff : 0xffff0000);
+ memcpy(p, &color, sizeof(int32_t));
+ }
+ }
+
+ XPutImage(state->dpy, pixmap,
+ DefaultGC(state->dpy, DefaultScreen(state->dpy)),
+ ximg, 0, 0, 0, 0, w, h);
+ XFlush(state->dpy);
+ XDestroyImage(ximg);
+
+ pixmap_attribs[1] = texture_format;
+
+ return eglCreatePixmapSurface(state->egl_dpy,
+ state->cfg, pixmap, pixmap_attribs);
+}
+
+
+static enum piglit_result
+draw(struct egl_state *state)
+{
+ EGLSurface *pixmap;
+ GLuint texture;
+ GLint program;
+ EGLint invert;
+
+ float red[] = {
+ 1.0, 0.0, 0.0, 1.0
+ };
+
+ float blue[] = {
+ 0.0, 0.0, 1.0, 1.0
+ };
+
+ GLfloat vertices[] = {
+ -1.0, 1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0
+ };
+
+ GLfloat tex_coords[] = {
+ 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0
+ };
+
+ GLfloat yinv_tex_coords[] = {
+ 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0
+ };
+
+ GLfloat *coords;
+
+ GLint formats[] = { EGL_TEXTURE_RGB, EGL_TEXTURE_RGBA, 0 };
+ GLint *format = formats;
+
+ program = piglit_build_simple_program(vert, frag);
+
+ if (!program) {
+ fprintf(stderr, "failed to create shader\n");
+ return PIGLIT_FAIL;
+ }
+ glUseProgram(program);
+
+ if (!eglGetConfigAttrib(state->egl_dpy, state->cfg,
+ EGL_Y_INVERTED_NOK, &invert)) {
+ fprintf(stderr,
+ "eglGetConfigAttrib(EGL_Y_INVERTED_NOK) failed\n");
+ return PIGLIT_FAIL;
+ }
+
+ if (!eglMakeCurrent(state->egl_dpy,
+ state->surf, state->surf, state->ctx)) {
+ fprintf(stderr, "eglMakeCurrent() state->surf failed\n");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ /* create texture object */
+ glGenTextures(1, &texture);
+ glBindTexture(GL_TEXTURE_2D, texture);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glActiveTexture(GL_TEXTURE0);
+
+ /* choose which coordinates to use when rendering, y inverted or not */
+ coords = (invert == EGL_TRUE) ? yinv_tex_coords : tex_coords;
+
+ /* prepare for rendering */
+ glViewport(0, 0, state->width, state->height);
+ glEnableVertexAttribArray(0);
+ glEnableVertexAttribArray(1);
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, coords);
+ glUniform1i(glGetUniformLocation(program, "tex0"), 0);
+
+ /* for each supported format (RGB, RGBA) */
+ while (*format != 0) {
+ pixmap = create_test_pixmap(state, W, H, *format++);
+
+ eglWaitNative(EGL_CORE_NATIVE_ENGINE);
+
+ /* bind pixmap buffer with texture */
+ eglBindTexImage(state->egl_dpy, pixmap, EGL_BACK_BUFFER);
+ if (!piglit_check_egl_error(EGL_SUCCESS))
+ return PIGLIT_FAIL;
+
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ eglSwapBuffers(state->egl_dpy, state->surf);
+
+ /* probe for red and blue corners */
+ if (!piglit_probe_pixel_rgba(W - 1, H - 1, red) ||
+ !piglit_probe_pixel_rgba(1, 1, blue))
+ return PIGLIT_FAIL;
+
+ eglReleaseTexImage(state->egl_dpy, pixmap, EGL_BACK_BUFFER);
+ if (!piglit_check_egl_error(EGL_SUCCESS))
+ return PIGLIT_FAIL;
+
+ eglDestroySurface(state->egl_dpy, pixmap);
+ }
+
+ glDeleteTextures(1, &texture);
+ glDeleteProgram(program);
+
+ return PIGLIT_PASS;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+}
+
+
+/* initialize EGL with OpenGL ES 2 */
+enum piglit_result
+piglit_display(void)
+{
+ struct egl_test test;
+
+ EGLint attribs[] = {
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE,
+ EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE,
+ EGL_NONE
+ };
+
+ egl_init_test(&test);
+
+ test.extensions = extensions;
+ test.draw = draw;
+ test.config_attribs = attribs;
+ test.window_width = W;
+ test.window_height = H;
+
+ return egl_util_run(&test, 0, NULL);
+}
+
--
1.8.3.1
More information about the Piglit
mailing list