2 * Copyright © 2014 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
27 * Common routines to fill or check array buffer data.
30 #include "piglit-util-gl.h"
32 /* Check that the range of ARRAY_BUFFER specified with <ofs> and <length>
33 * is filled with chunks of data of length <expected_data_size>.
36 check_array_buffer_sub_data(const int ofs
, const int length
,
37 const int expected_data_size
, const void *const expected_data
)
42 char *buffer_data
= glMapBuffer(GL_ARRAY_BUFFER
, GL_READ_ONLY
);
43 glGetBufferParameteriv(GL_ARRAY_BUFFER
, GL_BUFFER_SIZE
, &buffer_size
);
45 assert(length
% expected_data_size
== 0);
49 assert(ofs
+ length
<= buffer_size
);
51 for (i
= ofs
; i
< ofs
+ length
; i
+= expected_data_size
) {
52 pass
= memcmp(buffer_data
+ i
, expected_data
,
53 expected_data_size
) == 0 && pass
;
56 glUnmapBuffer(GL_ARRAY_BUFFER
);
62 /* As above, but for entire buffer. */
64 check_array_buffer_data(const int expected_data_size
,
65 const void *const expected_data
)
68 glGetBufferParameteriv(GL_ARRAY_BUFFER
, GL_BUFFER_SIZE
, &buffer_size
);
70 return check_array_buffer_sub_data(0, buffer_size
, expected_data_size
,
74 /* Fill the entire ARRAY_BUFFER with chunks of data of <data_size> length.
77 fill_array_buffer(const int data_size
, const void *const data
)
81 char *buffer_data
= glMapBuffer(GL_ARRAY_BUFFER
, GL_WRITE_ONLY
);
82 glGetBufferParameteriv(GL_ARRAY_BUFFER
, GL_BUFFER_SIZE
, &buffer_size
);
84 assert (buffer_size
% data_size
== 0);
86 for (i
= 0; i
< buffer_size
; i
+= data_size
) {
87 memcpy(buffer_data
+ i
, data
, data_size
);
90 glUnmapBuffer(GL_ARRAY_BUFFER
);