2 * Copyright © 2012 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 DEALINGS
25 * \file pause-counting.c
26 * Verify behavior of XFB "counting" queries when pause and resume are used.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config
.supports_gl_compat_version
= 10;
34 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
;
35 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
37 PIGLIT_GL_TEST_CONFIG_END
45 static const float data
[] = {
52 static const char vstext
[] =
53 "varying vec4 x; void main() { gl_Position = gl_Vertex; x = vec4(0); }";
55 void piglit_init(int argc
, char **argv
)
57 static const char *varyings
[] = {"x"};
67 piglit_require_vertex_shader();
68 piglit_require_transform_feedback();
69 piglit_require_extension("GL_ARB_transform_feedback2");
71 /* This is all just the boot-strap work for the test.
73 glGenBuffers(2, buffers
);
74 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, buffers
[0]);
75 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER
, 1024, NULL
, GL_STREAM_READ
);
77 glBindBuffer(GL_ARRAY_BUFFER
, buffers
[1]);
78 glBufferData(GL_ARRAY_BUFFER
, sizeof(data
), data
, GL_STATIC_DRAW
);
79 glVertexAttribPointer(0, 2, GL_FLOAT
, GL_FALSE
, 2 * sizeof(GLfloat
), 0);
80 glEnableVertexAttribArray(0);
82 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vstext
);
83 prog
= glCreateProgram();
84 glAttachShader(prog
, vs
);
86 glTransformFeedbackVaryings(prog
, 1, varyings
, GL_INTERLEAVED_ATTRIBS
);
88 if (!piglit_link_check_status(prog
)) {
95 glGenTransformFeedbacks(1, &id
);
97 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK
, id
);
98 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER
, 0, buffers
[0]);
100 glGenQueries(2, queries
);
102 /* Here's the actual test. Start both kinds of query. Pause and
103 * resume transform feedback around some of the drawing. This should
104 * cause GL_PRIMITIVES_GENERATED to be larger than
105 * GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN.
107 glEnable(GL_RASTERIZER_DISCARD
);
108 glBeginQuery(GL_PRIMITIVES_GENERATED
, queries
[0]);
109 glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
, queries
[1]);
110 glBeginTransformFeedback(GL_TRIANGLES
);
112 glDrawArrays(GL_TRIANGLES
, 0, 4);
114 glPauseTransformFeedback();
116 glDrawArrays(GL_TRIANGLES
, 0, 4);
118 glResumeTransformFeedback();
120 glDrawArrays(GL_TRIANGLES
, 0, 4);
122 glEndTransformFeedback();
123 glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
);
124 glEndQuery(GL_PRIMITIVES_GENERATED
);
126 glGetQueryObjectuiv(queries
[0], GL_QUERY_RESULT
, &generated
);
127 glGetQueryObjectuiv(queries
[1], GL_QUERY_RESULT
, &written
);
129 if (generated
!= 3) {
131 "GL_PRIMITIVES_GENERATED: "
132 "Expected %d, got %d\n",
139 "GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: "
140 "Expected %d, got %d\n",
145 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK
, 0);
148 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, 0);
149 glDeleteBuffers(2, buffers
);
150 glDeleteQueries(2, queries
);
151 glDeleteTransformFeedbacks(1, &id
);
155 glDeleteProgram(prog
);
157 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);