1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
* Copyright © 2009 Intel Corporation
* Copyright © 2010 Mathias Fröhlich
*
* 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:
* Ian Romanick <ian.d.romanick@intel.com>
* Mathias Fröhlich <m.froehlich@web.de>
*/
/**
* \file timer_query.c
* Simple test for GL_EXT_timer_query.
*/
#include "piglit-util.h"
PIGLIT_GL_TEST_MAIN(
180 /*window_width*/,
100 /*window_height*/,
GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH)
static GLuint timer_query;
void
piglit_init(int argc, char **argv)
{
GLint query_bits;
piglit_require_extension("GL_EXT_timer_query");
piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
/* It is legal for a driver to support the query API but not have
* any query bits. I wonder how many applications actually check for
* this case...
*/
(*glGetQueryivARB)(GL_TIME_ELAPSED, GL_QUERY_COUNTER_BITS, &query_bits);
if (query_bits == 0) {
piglit_report_result(PIGLIT_SKIP);
}
(*glGenQueriesARB)(1, &timer_query);
}
enum piglit_result
piglit_display(void)
{
GLint available = 0;
GLint nsecs;
GLint64 nsecs64;
GLuint64 nsecs64u;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* Start a query */
(*glBeginQueryARB)(GL_TIME_ELAPSED_EXT, timer_query);
/* Paint something */
glColor3ub(0xff, 0xff, 0xff);
glBegin(GL_QUADS);
glVertex3f(0, 0, 0);
glVertex3f(piglit_width, 0, 0);
glVertex3f(piglit_width, piglit_height, 0);
glVertex3f(0, piglit_height, 0);
glEnd();
/* Stop a query */
(*glEndQueryARB)(GL_TIME_ELAPSED_EXT);
/* In this case poll until available */
while (!available)
(*glGetQueryObjectivARB)(timer_query, GL_QUERY_RESULT_AVAILABLE, &available);
/* Get the result */
(*glGetQueryObjectivARB)(timer_query, GL_QUERY_RESULT, &nsecs);
(*glGetQueryObjecti64vEXT)(timer_query, GL_QUERY_RESULT, &nsecs64);
(*glGetQueryObjectui64vEXT)(timer_query, GL_QUERY_RESULT, &nsecs64u);
if ((nsecs & 0xffffffff) != (nsecs64 & 0xffffffff)) {
printf("timer_query: 32 and 64-bit results differ!\n");
return PIGLIT_FAIL;
}
if ((nsecs & 0xffffffff) != (nsecs64u & 0xffffffff)) {
printf("timer_query: 32 and 64-bit unsigned results differ!\n");
return PIGLIT_FAIL;
}
/*printf("nsecs = %d %ld\n", nsecs, (long int) nsecs64);*/
glutSwapBuffers();
return PIGLIT_PASS;
}
|