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 "sp_context.h"
41 #include "draw/draw_context.h"
46 softpipe_map_constant_buffers(struct softpipe_context
*sp
)
48 struct pipe_winsys
*ws
= sp
->pipe
.winsys
;
50 for (i
= 0; i
< 2; i
++) {
51 if (sp
->constants
[i
].size
)
52 sp
->mapped_constants
[i
] = ws
->buffer_map(ws
, sp
->constants
[i
].buffer
,
53 PIPE_BUFFER_USAGE_CPU_READ
);
56 draw_set_mapped_constant_buffer(sp
->draw
,
57 sp
->mapped_constants
[PIPE_SHADER_VERTEX
]);
61 softpipe_unmap_constant_buffers(struct softpipe_context
*sp
)
63 struct pipe_winsys
*ws
= sp
->pipe
.winsys
;
65 for (i
= 0; i
< 2; i
++) {
66 if (sp
->constants
[i
].size
)
67 ws
->buffer_unmap(ws
, sp
->constants
[i
].buffer
);
68 sp
->mapped_constants
[i
] = NULL
;
74 softpipe_draw_arrays(struct pipe_context
*pipe
, unsigned mode
,
75 unsigned start
, unsigned count
)
77 return softpipe_draw_elements(pipe
, NULL
, 0, mode
, start
, count
);
83 * Draw vertex arrays, with optional indexing.
84 * Basically, map the vertex buffers (and drawing surfaces), then hand off
85 * the drawing to the 'draw' module.
87 * XXX should the element buffer be specified/bound with a separate function?
90 softpipe_draw_elements(struct pipe_context
*pipe
,
91 struct pipe_buffer
*indexBuffer
,
93 unsigned mode
, unsigned start
, unsigned count
)
95 struct softpipe_context
*sp
= softpipe_context(pipe
);
96 struct draw_context
*draw
= sp
->draw
;
99 /* first, check that the primitive is not malformed. It is the
100 * state tracker's responsibility to do send only correctly formed
101 * primitives down. It currently isn't doing that though...
104 count
= draw_trim_prim( mode
, count
);
106 if (!draw_validate_prim( mode
, count
))
112 softpipe_update_derived( sp
);
114 softpipe_map_surfaces(sp
);
115 softpipe_map_constant_buffers(sp
);
120 for (i
= 0; i
< PIPE_ATTRIB_MAX
; i
++) {
121 if (sp
->vertex_buffer
[i
].buffer
) {
123 = pipe
->winsys
->buffer_map(pipe
->winsys
,
124 sp
->vertex_buffer
[i
].buffer
,
125 PIPE_BUFFER_USAGE_CPU_READ
);
126 draw_set_mapped_vertex_buffer(draw
, i
, buf
);
129 /* Map index buffer, if present */
132 = pipe
->winsys
->buffer_map(pipe
->winsys
, indexBuffer
,
133 PIPE_BUFFER_USAGE_CPU_READ
);
134 draw_set_mapped_element_buffer(draw
, indexSize
, mapped_indexes
);
137 /* no index/element buffer */
138 draw_set_mapped_element_buffer(draw
, 0, NULL
);
143 draw_arrays(draw
, mode
, start
, count
);
146 * unmap vertex/index buffers - will cause draw module to flush
148 for (i
= 0; i
< PIPE_ATTRIB_MAX
; i
++) {
149 if (sp
->vertex_buffer
[i
].buffer
) {
150 draw_set_mapped_vertex_buffer(draw
, i
, NULL
);
151 pipe
->winsys
->buffer_unmap(pipe
->winsys
, sp
->vertex_buffer
[i
].buffer
);
155 draw_set_mapped_element_buffer(draw
, 0, NULL
);
156 pipe
->winsys
->buffer_unmap(pipe
->winsys
, indexBuffer
);
160 /* Note: leave drawing surfaces mapped */
161 softpipe_unmap_constant_buffers(sp
);