2 * Copyright © 2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Ian Romanick <ian.d.romanick@intel.com>
29 * Simple test of the API for GL_ARB_sync.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config
.supports_gl_compat_version
= 10;
38 config
.window_width
= 400;
39 config
.window_height
= 300;
40 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
;
42 PIGLIT_GL_TEST_CONFIG_END
44 #define FAIL_ON_ERROR(string) \
46 const GLenum err = glGetError(); \
47 if (err != GL_NO_ERROR) { \
48 fprintf(stderr, "%s generated error %s\n", \
49 string, piglit_get_gl_error_name(err)); \
56 piglit_init(int argc
, char **argv
)
58 piglit_require_extension("GL_ARB_sync");
60 glClearColor(0.1, 0.1, 0.3, 0.0);
61 piglit_gen_ortho_projection(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0, GL_FALSE
);
65 test_GetSynciv(GLsync sync
, GLenum pname
, GLint expect
)
67 GLboolean pass
= GL_TRUE
;
71 glGetSynciv(sync
, pname
, 1, & len
, & val
);
72 FAIL_ON_ERROR("glGetSynciv");
74 fprintf(stderr
, "glGetSynciv length of %s was %d\n",
75 piglit_get_gl_enum_name(pname
), len
);
77 } else if (val
!= expect
) {
79 "glGetSynciv of %s expected 0x%08x got 0x%08x\n",
80 piglit_get_gl_enum_name(pname
), expect
, val
);
91 GLboolean pass
= GL_TRUE
;
95 glClear(GL_COLOR_BUFFER_BIT
);
97 glBegin(GL_TRIANGLES
);
99 glVertex3f(-0.9, -0.9, -30.0);
101 glVertex3f( 0.9, -0.9, -30.0);
103 glVertex3f( 0.0, 0.9, -30.0);
108 sync
= glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE
, 0);
109 FAIL_ON_ERROR("glFenceSync");
111 if (!glIsSync(sync
)) {
112 fprintf(stderr
, "IsSync(%p) failed\n", sync
);
116 FAIL_ON_ERROR("glIsSync");
118 if (! test_GetSynciv(sync
, GL_SYNC_CONDITION
,
119 GL_SYNC_GPU_COMMANDS_COMPLETE
)) {
124 if (! test_GetSynciv(sync
, GL_SYNC_FLAGS
, 0)) {
131 /* After the glFinish, the sync *must* be signaled!
133 if (! test_GetSynciv(sync
, GL_SYNC_STATUS
, GL_SIGNALED
)) {
139 /* Since the sync has already been signaled, the wait should return
140 * GL_ALREADY_SIGNALED.
142 wait_val
= glClientWaitSync(sync
, 0, 1);
143 FAIL_ON_ERROR("glClientWaitSync");
145 if (wait_val
!= GL_ALREADY_SIGNALED
) {
147 "glClientWaitSync expected GL_ALREADY_SIGNALED, "
148 "got %s\n", piglit_get_gl_enum_name(wait_val
));
153 FAIL_ON_ERROR("glDeleteSync");
156 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;