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/internal/p_winsys_screen.h"
37 #include "pipe/p_inlines.h"
39 #include "sp_context.h"
42 #include "draw/draw_context.h"
47 softpipe_map_constant_buffers(struct softpipe_context
*sp
)
49 struct pipe_winsys
*ws
= sp
->pipe
.winsys
;
52 for (i
= 0; i
< PIPE_SHADER_TYPES
; i
++) {
53 if (sp
->constants
[i
].buffer
&& sp
->constants
[i
].buffer
->size
)
54 sp
->mapped_constants
[i
] = ws
->buffer_map(ws
, sp
->constants
[i
].buffer
,
55 PIPE_BUFFER_USAGE_CPU_READ
);
58 if (sp
->constants
[PIPE_SHADER_VERTEX
].buffer
)
59 size
= sp
->constants
[PIPE_SHADER_VERTEX
].buffer
->size
;
63 draw_set_mapped_constant_buffer(sp
->draw
,
64 sp
->mapped_constants
[PIPE_SHADER_VERTEX
],
69 softpipe_unmap_constant_buffers(struct softpipe_context
*sp
)
71 struct pipe_winsys
*ws
= sp
->pipe
.winsys
;
74 /* really need to flush all prims since the vert/frag shaders const buffers
79 draw_set_mapped_constant_buffer(sp
->draw
, NULL
, 0);
81 for (i
= 0; i
< 2; i
++) {
82 if (sp
->constants
[i
].buffer
&& sp
->constants
[i
].buffer
->size
)
83 ws
->buffer_unmap(ws
, sp
->constants
[i
].buffer
);
84 sp
->mapped_constants
[i
] = NULL
;
89 static unsigned reduced_prim
[PIPE_PRIM_POLYGON
+ 1] = {
104 softpipe_draw_arrays(struct pipe_context
*pipe
, unsigned mode
,
105 unsigned start
, unsigned count
)
107 return softpipe_draw_elements(pipe
, NULL
, 0, mode
, start
, count
);
113 * Draw vertex arrays, with optional indexing.
114 * Basically, map the vertex buffers (and drawing surfaces), then hand off
115 * the drawing to the 'draw' module.
117 * XXX should the element buffer be specified/bound with a separate function?
121 softpipe_draw_range_elements(struct pipe_context
*pipe
,
122 struct pipe_buffer
*indexBuffer
,
126 unsigned mode
, unsigned start
, unsigned count
)
128 struct softpipe_context
*sp
= softpipe_context(pipe
);
129 struct draw_context
*draw
= sp
->draw
;
132 sp
->reduced_api_prim
= reduced_prim
[mode
];
135 softpipe_update_derived( sp
);
137 softpipe_map_surfaces(sp
);
138 softpipe_map_constant_buffers(sp
);
143 for (i
= 0; i
< sp
->num_vertex_buffers
; i
++) {
145 = pipe_buffer_map(pipe
->screen
,
146 sp
->vertex_buffer
[i
].buffer
,
147 PIPE_BUFFER_USAGE_CPU_READ
);
148 draw_set_mapped_vertex_buffer(draw
, i
, buf
);
150 /* Map index buffer, if present */
153 = pipe_buffer_map(pipe
->screen
, indexBuffer
,
154 PIPE_BUFFER_USAGE_CPU_READ
);
155 draw_set_mapped_element_buffer_range(draw
, indexSize
,
161 /* no index/element buffer */
162 draw_set_mapped_element_buffer_range(draw
, 0, start
, start
+ count
- 1, NULL
);
167 draw_arrays(draw
, mode
, start
, count
);
170 * unmap vertex/index buffers - will cause draw module to flush
172 for (i
= 0; i
< sp
->num_vertex_buffers
; i
++) {
173 draw_set_mapped_vertex_buffer(draw
, i
, NULL
);
174 pipe_buffer_unmap(pipe
->screen
, sp
->vertex_buffer
[i
].buffer
);
177 draw_set_mapped_element_buffer(draw
, 0, NULL
);
178 pipe_buffer_unmap(pipe
->screen
, indexBuffer
);
182 /* Note: leave drawing surfaces mapped */
183 softpipe_unmap_constant_buffers(sp
);
189 softpipe_draw_elements(struct pipe_context
*pipe
,
190 struct pipe_buffer
*indexBuffer
,
192 unsigned mode
, unsigned start
, unsigned count
)
194 return softpipe_draw_range_elements( pipe
, indexBuffer
,
197 mode
, start
, count
);
203 softpipe_set_edgeflags(struct pipe_context
*pipe
, const unsigned *edgeflags
)
205 struct softpipe_context
*sp
= softpipe_context(pipe
);
206 draw_set_edgeflags(sp
->draw
, edgeflags
);