summaryrefslogtreecommitdiff
path: root/tests/glx
diff options
context:
space:
mode:
authorAdel Gadllah <adel.gadllah@gmail.com>2014-02-22 02:08:49 +0100
committerEric Anholt <eric@anholt.net>2014-03-13 14:36:05 -0700
commit0425d36f8d2a2209dbd57872a90f5a1779aadcce (patch)
treec394efac6bdadd060be6718c90174a358e2f4ea6 /tests/glx
parente56381e4a6b6e5756a18fbfd15ce6dce2e6911ba (diff)
glx: Add a testcase for GLX_EXT_buffer_age
v2: Indent according to piglit style, fix copyright message, drop redundant glReadBuffer() setting. (changes by anholt). Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Adel Gadllah <adel.gadllah@gmail.com> (v2)
Diffstat (limited to 'tests/glx')
-rw-r--r--tests/glx/CMakeLists.gl.txt1
-rw-r--r--tests/glx/glx-buffer-age.c117
2 files changed, 118 insertions, 0 deletions
diff --git a/tests/glx/CMakeLists.gl.txt b/tests/glx/CMakeLists.gl.txt
index 7f3a71391..eeb1d7ad8 100644
--- a/tests/glx/CMakeLists.gl.txt
+++ b/tests/glx/CMakeLists.gl.txt
@@ -70,6 +70,7 @@ IF(PIGLIT_BUILD_GLX_TESTS)
piglit_add_executable (glx-copy-sub-buffer glx-copy-sub-buffer.c)
piglit_add_executable (glx-query-drawable glx-query-drawable.c)
+ piglit_add_executable (glx-buffer-age glx-buffer-age.c)
piglit_add_executable (glx-string-sanity glx-string-sanity.c)
ENDIF(PIGLIT_BUILD_GLX_TESTS)
diff --git a/tests/glx/glx-buffer-age.c b/tests/glx/glx-buffer-age.c
new file mode 100644
index 000000000..35a9e0c22
--- /dev/null
+++ b/tests/glx/glx-buffer-age.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
+ * Copyright 2010 Red Hat, Inc.
+ * Copyright 2014 Adel Gadllah <adel.gadllah@gmail.com>
+ *
+ * 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:
+ * Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
+ * Adam Jackson <ajax@redhat.com>
+ * Adel Gadllah <adel.gadllah@gmail.com>
+ *
+ * Derived from glx-copy-sub-buffer.c
+ *
+ */
+
+/** @file glx-buffer-age.c
+ *
+ * Test that GLX_EXT_buffer_age works as advertised
+ */
+
+#include "piglit-util-gl-common.h"
+#include "piglit-glx-util.h"
+
+#ifndef GLX_BACK_BUFFER_AGE_EXT
+#define GLX_BACK_BUFFER_AGE_EXT 0x20F4
+#endif
+
+int piglit_width = 100, piglit_height = 100;
+static Display *dpy;
+static Window window;
+static XVisualInfo *visinfo;
+
+enum piglit_result
+draw(Display *dpy)
+{
+ GLXContext ctx;
+ GLboolean pass;
+ unsigned int age;
+ int i;
+ static GLfloat colors[3][4] = {{1.0, 0.0, 0.0, 1.0},
+ {0.0, 1.0, 0.0, 1.0},
+ {0.0, 0.0, 1.0, 1.0}};
+ GLfloat probe[4];
+ enum piglit_result result;
+
+ ctx = piglit_get_glx_context(dpy, visinfo);
+ glXMakeCurrent(dpy, window, ctx);
+ piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
+
+ for (i = 0; i < 3; i++) {
+ glClearColor(colors[i][0],
+ colors[i][1],
+ colors[i][2],
+ colors[i][3]);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glXSwapBuffers(dpy, window);
+ }
+
+ glXQueryDrawable(dpy, window, GLX_BACK_BUFFER_AGE_EXT, &age);
+
+ if (age == 0 || age > 3) {
+ result = PIGLIT_SKIP;
+ goto out;
+ }
+
+ pass = piglit_probe_pixel_rgba_silent(0, 0, colors[3 - age], probe);
+ result = pass ? PIGLIT_PASS : PIGLIT_FAIL;
+
+out:
+ glXMakeCurrent(dpy, None, NULL);
+ glXDestroyContext(dpy, ctx);
+
+ return result;
+}
+
+
+int
+main(int argc, char **argv)
+{
+ int i;
+
+ for(i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "-auto"))
+ piglit_automatic = 1;
+ else
+ fprintf(stderr, "Unknown option: %s\n", argv[i]);
+ }
+
+ dpy = piglit_get_glx_display();
+ piglit_require_glx_extension(dpy, "EXT_buffer_age");
+ visinfo = piglit_get_glx_visual(dpy);
+ window = piglit_get_glx_window(dpy, visinfo);
+
+ XMapWindow(dpy, window);
+
+ piglit_glx_event_loop(dpy, draw);
+
+ return 0;
+}