2 * Copyright 2009 Maciej Cencora <m.cencora@gmail.com>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 /* r300_vbo: Various helpers for emitting vertex buffers. Needs cleanup,
25 * refactoring, etc. */
29 #include "pipe/p_format.h"
32 #include "r300_context.h"
33 #include "r300_state_inlines.h"
36 #include "radeon_winsys.h"
38 static INLINE
int get_buffer_offset(struct r300_context
*r300
,
40 unsigned int elem_offset
)
42 return r300
->vertex_buffer
[buf_nr
].buffer_offset
+ elem_offset
;
45 /* XXX not called at all */
46 static void setup_vertex_buffers(struct r300_context
*r300
)
48 struct pipe_vertex_element
*vert_elem
;
51 for (i
= 0; i
< r300
->aos_count
; i
++)
53 vert_elem
= &r300
->vertex_element
[i
];
54 /* XXX use translate module to convert the data */
55 if (!format_is_supported(vert_elem
->src_format
,
56 vert_elem
->nr_components
)) {
59 struct pipe_buffer *buf;
60 const unsigned int max_index = r300->vertex_buffers[vert_elem->vertex_buffer_index].max_index;
61 buf = pipe_buffer_create(r300->context.screen, 4, usage, vert_elem->nr_components * max_index * sizeof(float));
65 if (get_buffer_offset(r300
,
66 vert_elem
->vertex_buffer_index
,
67 vert_elem
->src_offset
) % 4) {
68 /* XXX need to align buffer */
74 /* XXX these shouldn't be asserts since we can work around bad indexbufs */
75 void setup_index_buffer(struct r300_context
*r300
,
76 struct pipe_buffer
* indexBuffer
,
79 if (!r300
->winsys
->add_buffer(r300
->winsys
, indexBuffer
,
80 RADEON_GEM_DOMAIN_GTT
, 0)) {
84 if (!r300
->winsys
->validate(r300
->winsys
)) {