ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / spec / arb_clear_buffer_object / common.c
blobb0e75fcc90da37d02bd86297005bf31bd32e554a
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
24 /**
25 * \file common.c
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>.
35 bool
36 check_array_buffer_sub_data(const int ofs, const int length,
37 const int expected_data_size, const void *const expected_data)
39 bool pass = true;
40 int i;
41 int buffer_size;
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);
47 assert(ofs >= 0);
48 assert(length >= 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);
58 return pass;
62 /* As above, but for entire buffer. */
63 bool
64 check_array_buffer_data(const int expected_data_size,
65 const void *const expected_data)
67 int buffer_size;
68 glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &buffer_size);
70 return check_array_buffer_sub_data(0, buffer_size, expected_data_size,
71 expected_data);
74 /* Fill the entire ARRAY_BUFFER with chunks of data of <data_size> length.
76 void
77 fill_array_buffer(const int data_size, const void *const data)
79 int i;
80 int buffer_size;
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);