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
21 * DEALINGS IN THE SOFTWARE.
25 * \file get-buffer-state.c
27 * Test that "Get" functions can be used to query the state of
28 * transform feedback buffers.
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 10;
37 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGB
;
38 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
40 PIGLIT_GL_TEST_CONFIG_END
42 #define XFB_BUFFER_SIZE 12
49 static struct test_desc
56 { "main_binding", MAIN
, GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
},
57 { "indexed_binding", INDEXED
, GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
},
58 { "buffer_start", INDEXED
, GL_TRANSFORM_FEEDBACK_BUFFER_START
},
59 { "buffer_size", INDEXED
, GL_TRANSFORM_FEEDBACK_BUFFER_SIZE
},
63 check_integer(const struct test_desc
*test
, GLenum param
, GLint expected
)
66 const char *param_string
= piglit_get_gl_enum_name(param
);
68 if (test
->mode
== MAIN
&& test
->param
== param
) {
69 glGetIntegerv(param
, &get_result
);
70 if (get_result
!= expected
) {
71 printf("%s == %i, expected %i\n", param_string
,
72 get_result
, expected
);
80 check_indexed(const struct test_desc
*test
, GLenum param
, GLuint index
,
84 const char *param_string
= piglit_get_gl_enum_name(param
);
86 if (test
->mode
== INDEXED
&& test
->param
== param
) {
87 glGetIntegeri_v(param
, index
, &get_result
);
88 if (get_result
!= expected
) {
89 printf("%s[%u] == %i, expected %i\n", param_string
,
90 index
, get_result
, expected
);
98 do_test(const struct test_desc
*test
)
101 GLboolean pass
= GL_TRUE
;
102 GLint max_separate_attribs
;
103 float initial_xfb_buffer_contents
[XFB_BUFFER_SIZE
];
106 glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS
,
107 &max_separate_attribs
);
108 printf("MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTIBS=%i\n",
109 max_separate_attribs
);
111 bufs
= malloc(max_separate_attribs
* sizeof(GLuint
));
112 glGenBuffers(max_separate_attribs
, bufs
);
113 memset(initial_xfb_buffer_contents
, 0,
114 sizeof(initial_xfb_buffer_contents
));
116 /* Main GL_TRANSFORM_FEEDBACK_BUFFER_BINDING should still be
117 * set to its default value.
119 pass
= check_integer(test
, GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
, 0) &&
122 /* Set up buffers. */
123 for (i
= 0; i
< max_separate_attribs
; ++i
) {
124 printf("BindBuffer(TRANSFORM_FEEDBACK_BUFFER, %u)\n", bufs
[i
]);
125 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, bufs
[i
]);
126 pass
= check_integer(test
,
127 GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
,
129 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER
,
130 sizeof(initial_xfb_buffer_contents
),
131 initial_xfb_buffer_contents
, GL_STREAM_READ
);
134 /* Indexed bindings should still be set to their default values. */
135 for (i
= 0; i
< max_separate_attribs
; ++i
) {
136 pass
= check_indexed(test
,
137 GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
, i
,
139 pass
= check_indexed(test
, GL_TRANSFORM_FEEDBACK_BUFFER_START
,
141 pass
= check_indexed(test
, GL_TRANSFORM_FEEDBACK_BUFFER_SIZE
,
145 /* Bind buffers, setting various offsets and sizes. */
146 for (i
= 0; i
< max_separate_attribs
; ++i
) {
147 int offset
= 4 * (i
% 4);
148 int size
= 4 * ((i
% 3) + 1);
149 printf("BindBufferRange(TRANSFORM_FEEDBACK_BUFFER, %i, %u, %i, %i)\n",
150 i
, bufs
[i
], offset
, size
);
151 glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER
, i
,
152 bufs
[i
], offset
, size
);
153 pass
= check_integer(test
,
154 GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
,
158 /* Check indexed bindings. */
159 for (i
= 0; i
< max_separate_attribs
; ++i
) {
160 int offset
= 4 * (i
% 4);
161 int size
= 4 * ((i
% 3) + 1);
162 pass
= check_indexed(test
,
163 GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
, i
,
165 pass
= check_indexed(test
, GL_TRANSFORM_FEEDBACK_BUFFER_START
,
167 pass
= check_indexed(test
, GL_TRANSFORM_FEEDBACK_BUFFER_SIZE
,
175 print_usage_and_exit(const char *prog_name
)
179 printf("Usage: %s <test_name>\n"
180 " where <test_name> is one of:\n", prog_name
);
181 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
182 printf(" %s\n", tests
[i
].name
);
186 const struct test_desc
*
187 find_matching_test(const char *prog_name
, const char *test_name
)
190 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
191 if (strcmp(tests
[i
].name
, test_name
) == 0)
194 print_usage_and_exit(prog_name
);
195 return NULL
; /* won't actually be reached */
199 piglit_init(int argc
, char **argv
)
201 const struct test_desc
*test
;
205 print_usage_and_exit(argv
[0]);
206 test
= find_matching_test(argv
[0], argv
[1]);
208 piglit_require_transform_feedback();
210 piglit_report_result(do_test(test
) ? PIGLIT_PASS
: PIGLIT_FAIL
);
216 /* Should never be reached */