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"
38 #include "util/u_prim.h"
40 #include "sp_context.h"
43 #include "draw/draw_context.h"
48 softpipe_map_constant_buffers(struct softpipe_context
*sp
)
50 struct pipe_winsys
*ws
= sp
->pipe
.winsys
;
53 for (i
= 0; i
< PIPE_SHADER_TYPES
; i
++) {
54 if (sp
->constants
[i
].buffer
&& sp
->constants
[i
].buffer
->size
)
55 sp
->mapped_constants
[i
] = ws
->buffer_map(ws
, sp
->constants
[i
].buffer
,
56 PIPE_BUFFER_USAGE_CPU_READ
);
59 if (sp
->constants
[PIPE_SHADER_VERTEX
].buffer
)
60 size
= sp
->constants
[PIPE_SHADER_VERTEX
].buffer
->size
;
64 draw_set_mapped_constant_buffer(sp
->draw
,
65 sp
->mapped_constants
[PIPE_SHADER_VERTEX
],
71 softpipe_unmap_constant_buffers(struct softpipe_context
*sp
)
73 struct pipe_winsys
*ws
= sp
->pipe
.winsys
;
76 /* really need to flush all prims since the vert/frag shaders const buffers
81 draw_set_mapped_constant_buffer(sp
->draw
, NULL
, 0);
83 for (i
= 0; i
< 2; i
++) {
84 if (sp
->constants
[i
].buffer
&& sp
->constants
[i
].buffer
->size
)
85 ws
->buffer_unmap(ws
, sp
->constants
[i
].buffer
);
86 sp
->mapped_constants
[i
] = NULL
;
92 softpipe_draw_arrays(struct pipe_context
*pipe
, unsigned mode
,
93 unsigned start
, unsigned count
)
95 return softpipe_draw_elements(pipe
, NULL
, 0, mode
, start
, count
);
100 * Draw vertex arrays, with optional indexing.
101 * Basically, map the vertex buffers (and drawing surfaces), then hand off
102 * the drawing to the 'draw' module.
105 softpipe_draw_range_elements(struct pipe_context
*pipe
,
106 struct pipe_buffer
*indexBuffer
,
110 unsigned mode
, unsigned start
, unsigned count
)
112 struct softpipe_context
*sp
= softpipe_context(pipe
);
113 struct draw_context
*draw
= sp
->draw
;
116 sp
->reduced_api_prim
= u_reduced_prim(mode
);
119 softpipe_update_derived( sp
);
121 softpipe_map_transfers(sp
);
122 softpipe_map_constant_buffers(sp
);
127 for (i
= 0; i
< sp
->num_vertex_buffers
; i
++) {
129 = pipe_buffer_map(pipe
->screen
,
130 sp
->vertex_buffer
[i
].buffer
,
131 PIPE_BUFFER_USAGE_CPU_READ
);
132 draw_set_mapped_vertex_buffer(draw
, i
, buf
);
135 /* Map index buffer, if present */
138 = pipe_buffer_map(pipe
->screen
, indexBuffer
,
139 PIPE_BUFFER_USAGE_CPU_READ
);
140 draw_set_mapped_element_buffer_range(draw
, indexSize
,
146 /* no index/element buffer */
147 draw_set_mapped_element_buffer_range(draw
, 0, start
,
148 start
+ count
- 1, NULL
);
152 draw_arrays(draw
, mode
, start
, count
);
155 * unmap vertex/index buffers - will cause draw module to flush
157 for (i
= 0; i
< sp
->num_vertex_buffers
; i
++) {
158 draw_set_mapped_vertex_buffer(draw
, i
, NULL
);
159 pipe_buffer_unmap(pipe
->screen
, sp
->vertex_buffer
[i
].buffer
);
162 draw_set_mapped_element_buffer(draw
, 0, NULL
);
163 pipe_buffer_unmap(pipe
->screen
, indexBuffer
);
167 /* Note: leave drawing surfaces mapped */
168 softpipe_unmap_constant_buffers(sp
);
170 sp
->dirty_render_cache
= TRUE
;
177 softpipe_draw_elements(struct pipe_context
*pipe
,
178 struct pipe_buffer
*indexBuffer
,
180 unsigned mode
, unsigned start
, unsigned count
)
182 return softpipe_draw_range_elements( pipe
, indexBuffer
,
185 mode
, start
, count
);
190 softpipe_set_edgeflags(struct pipe_context
*pipe
, const unsigned *edgeflags
)
192 struct softpipe_context
*sp
= softpipe_context(pipe
);
193 draw_set_edgeflags(sp
->draw
, edgeflags
);