1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS AND/OR ITS 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 **************************************************************************/
34 #include "pipe/p_defines.h"
35 #include "pipe/p_context.h"
36 #include "pipe/p_winsys.h"
38 #include "cell_context.h"
39 #include "cell_draw_arrays.h"
40 #include "cell_state.h"
41 #include "cell_flush.h"
43 #include "draw/draw_context.h"
48 cell_map_constant_buffers(struct cell_context
*sp
)
50 struct pipe_winsys
*ws
= sp
->pipe
.winsys
;
52 for (i
= 0; i
< 2; i
++) {
53 if (sp
->constants
[i
].size
) {
54 sp
->mapped_constants
[i
] = ws
->buffer_map(ws
, sp
->constants
[i
].buffer
,
55 PIPE_BUFFER_USAGE_CPU_READ
);
56 cell_flush_buffer_range(sp
, sp
->mapped_constants
[i
],
57 sp
->constants
[i
].buffer
->size
);
61 draw_set_mapped_constant_buffer(sp
->draw
,
62 sp
->mapped_constants
[PIPE_SHADER_VERTEX
],
63 sp
->constants
[PIPE_SHADER_VERTEX
].size
);
67 cell_unmap_constant_buffers(struct cell_context
*sp
)
69 struct pipe_winsys
*ws
= sp
->pipe
.winsys
;
71 for (i
= 0; i
< 2; i
++) {
72 if (sp
->constants
[i
].size
)
73 ws
->buffer_unmap(ws
, sp
->constants
[i
].buffer
);
74 sp
->mapped_constants
[i
] = NULL
;
80 cell_draw_arrays(struct pipe_context
*pipe
, unsigned mode
,
81 unsigned start
, unsigned count
)
83 return cell_draw_elements(pipe
, NULL
, 0, mode
, start
, count
);
89 * Draw vertex arrays, with optional indexing.
90 * Basically, map the vertex buffers (and drawing surfaces), then hand off
91 * the drawing to the 'draw' module.
93 * XXX should the element buffer be specified/bound with a separate function?
96 cell_draw_range_elements(struct pipe_context
*pipe
,
97 struct pipe_buffer
*indexBuffer
,
101 unsigned mode
, unsigned start
, unsigned count
)
103 struct cell_context
*sp
= cell_context(pipe
);
104 struct draw_context
*draw
= sp
->draw
;
108 cell_update_derived( sp
);
111 cell_map_surfaces(sp
);
113 cell_map_constant_buffers(sp
);
118 for (i
= 0; i
< sp
->num_vertex_buffers
; i
++) {
119 void *buf
= pipe
->winsys
->buffer_map(pipe
->winsys
,
120 sp
->vertex_buffer
[i
].buffer
,
121 PIPE_BUFFER_USAGE_CPU_READ
);
122 cell_flush_buffer_range(sp
, buf
, sp
->vertex_buffer
[i
].buffer
->size
);
123 draw_set_mapped_vertex_buffer(draw
, i
, buf
);
125 /* Map index buffer, if present */
127 void *mapped_indexes
= pipe
->winsys
->buffer_map(pipe
->winsys
,
129 PIPE_BUFFER_USAGE_CPU_READ
);
130 draw_set_mapped_element_buffer(draw
, indexSize
, mapped_indexes
);
133 /* no index/element buffer */
134 draw_set_mapped_element_buffer(draw
, 0, NULL
);
139 draw_arrays(draw
, mode
, start
, count
);
142 * unmap vertex/index buffers - will cause draw module to flush
144 for (i
= 0; i
< sp
->num_vertex_buffers
; i
++) {
145 draw_set_mapped_vertex_buffer(draw
, i
, NULL
);
146 pipe
->winsys
->buffer_unmap(pipe
->winsys
, sp
->vertex_buffer
[i
].buffer
);
149 draw_set_mapped_element_buffer(draw
, 0, NULL
);
150 pipe
->winsys
->buffer_unmap(pipe
->winsys
, indexBuffer
);
153 /* Note: leave drawing surfaces mapped */
154 cell_unmap_constant_buffers(sp
);
161 cell_draw_elements(struct pipe_context
*pipe
,
162 struct pipe_buffer
*indexBuffer
,
164 unsigned mode
, unsigned start
, unsigned count
)
166 return cell_draw_range_elements( pipe
, indexBuffer
,
169 mode
, start
, count
);
175 cell_set_edgeflags(struct pipe_context
*pipe
, const unsigned *edgeflags
)
177 struct cell_context
*cell
= cell_context(pipe
);
178 draw_set_edgeflags(cell
->draw
, edgeflags
);