1 /**************************************************************************
3 * Copyright 2012 Marek Olšák <maraeo@gmail.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE AUTHORS AND/OR THEIR SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "util/u_helpers.h"
29 #include "util/u_inlines.h"
32 * This function is used to copy an array of pipe_vertex_buffer structures,
33 * while properly referencing the pipe_vertex_buffer::buffer member.
35 * enabled_buffers is updated such that the bits corresponding to the indices
36 * of disabled buffers are set to 0 and the enabled ones are set to 1.
38 * \sa util_copy_framebuffer_state
40 void util_set_vertex_buffers_mask(struct pipe_vertex_buffer
*dst
,
41 uint32_t *enabled_buffers
,
42 const struct pipe_vertex_buffer
*src
,
43 unsigned start_slot
, unsigned count
)
51 for (i
= 0; i
< count
; i
++) {
52 if (src
[i
].buffer
|| src
[i
].user_buffer
) {
55 pipe_resource_reference(&dst
[i
].buffer
, src
[i
].buffer
);
58 /* Copy over the other members of pipe_vertex_buffer. */
59 memcpy(dst
, src
, count
* sizeof(struct pipe_vertex_buffer
));
61 *enabled_buffers
&= ~(((1ull << count
) - 1) << start_slot
);
62 *enabled_buffers
|= bitmask
<< start_slot
;
65 /* Unreference the buffers. */
66 for (i
= 0; i
< count
; i
++) {
67 pipe_resource_reference(&dst
[i
].buffer
, NULL
);
68 dst
[i
].user_buffer
= NULL
;
71 *enabled_buffers
&= ~(((1ull << count
) - 1) << start_slot
);
76 * Same as util_set_vertex_buffers_mask, but it only returns the number
79 void util_set_vertex_buffers_count(struct pipe_vertex_buffer
*dst
,
81 const struct pipe_vertex_buffer
*src
,
82 unsigned start_slot
, unsigned count
)
85 uint32_t enabled_buffers
= 0;
87 for (i
= 0; i
< *dst_count
; i
++) {
88 if (dst
[i
].buffer
|| dst
[i
].user_buffer
)
89 enabled_buffers
|= (1ull << i
);
92 util_set_vertex_buffers_mask(dst
, &enabled_buffers
, src
, start_slot
,
95 *dst_count
= util_last_bit(enabled_buffers
);
100 util_set_index_buffer(struct pipe_index_buffer
*dst
,
101 const struct pipe_index_buffer
*src
)
104 pipe_resource_reference(&dst
->buffer
, src
->buffer
);
105 memcpy(dst
, src
, sizeof(*dst
));
108 pipe_resource_reference(&dst
->buffer
, NULL
);
109 memset(dst
, 0, sizeof(*dst
));