cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / general / timer_query.c
blob08c8d17b01cb0205c9da9ae2b770bbb1f3dcae34
1 /*
2 * Copyright © 2009 Intel Corporation
3 * Copyright © 2010 Mathias Fröhlich
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
24 * Authors:
25 * Ian Romanick <ian.d.romanick@intel.com>
26 * Mathias Fröhlich <m.froehlich@web.de>
29 /**
30 * \file timer_query.c
31 * Simple test for GL_EXT_timer_query.
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config.supports_gl_compat_version = 10;
40 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_DEPTH;
42 PIGLIT_GL_TEST_CONFIG_END
44 static GLuint timer_query;
46 void
47 piglit_init(int argc, char **argv)
49 GLint query_bits;
51 piglit_require_extension("GL_EXT_timer_query");
53 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
55 /* It is legal for a driver to support the query API but not have
56 * any query bits. I wonder how many applications actually check for
57 * this case...
59 (*glGetQueryivARB)(GL_TIME_ELAPSED, GL_QUERY_COUNTER_BITS, &query_bits);
60 if (query_bits == 0) {
61 piglit_report_result(PIGLIT_SKIP);
64 (*glGenQueriesARB)(1, &timer_query);
67 enum piglit_result
68 piglit_display(void)
70 GLint available = 0;
71 GLint nsecs;
72 GLint64 nsecs64;
73 GLuint64 nsecs64u;
75 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
77 /* Start a query */
78 (*glBeginQueryARB)(GL_TIME_ELAPSED_EXT, timer_query);
80 /* Paint something */
81 glColor3ub(0xff, 0xff, 0xff);
83 glBegin(GL_QUADS);
84 glVertex3f(0, 0, 0);
85 glVertex3f(piglit_width, 0, 0);
86 glVertex3f(piglit_width, piglit_height, 0);
87 glVertex3f(0, piglit_height, 0);
88 glEnd();
90 /* Stop a query */
91 (*glEndQueryARB)(GL_TIME_ELAPSED_EXT);
93 /* In this case poll until available */
94 while (!available)
95 (*glGetQueryObjectivARB)(timer_query, GL_QUERY_RESULT_AVAILABLE, &available);
97 /* Get the result */
98 (*glGetQueryObjectivARB)(timer_query, GL_QUERY_RESULT, &nsecs);
99 (*glGetQueryObjecti64vEXT)(timer_query, GL_QUERY_RESULT, &nsecs64);
100 (*glGetQueryObjectui64vEXT)(timer_query, GL_QUERY_RESULT, &nsecs64u);
102 if ((nsecs & 0xffffffff) != (nsecs64 & 0xffffffff)) {
103 printf("timer_query: 32 and 64-bit results differ!\n");
104 return PIGLIT_FAIL;
107 if ((nsecs & 0xffffffff) != (nsecs64u & 0xffffffff)) {
108 printf("timer_query: 32 and 64-bit unsigned results differ!\n");
109 return PIGLIT_FAIL;
112 /*printf("nsecs = %d %ld\n", nsecs, (long int) nsecs64);*/
114 piglit_present_results();
116 return PIGLIT_PASS;