00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "pipe/p_defines.h"
00035 #include "pipe/p_context.h"
00036 #include "pipe/p_winsys.h"
00037 #include "pipe/p_inlines.h"
00038
00039 #include "sp_context.h"
00040 #include "sp_state.h"
00041
00042 #include "draw/draw_context.h"
00043
00044
00045
00046 static void
00047 softpipe_map_constant_buffers(struct softpipe_context *sp)
00048 {
00049 struct pipe_winsys *ws = sp->pipe.winsys;
00050 uint i;
00051 for (i = 0; i < PIPE_SHADER_TYPES; i++) {
00052 if (sp->constants[i].size)
00053 sp->mapped_constants[i] = ws->buffer_map(ws, sp->constants[i].buffer,
00054 PIPE_BUFFER_USAGE_CPU_READ);
00055 }
00056
00057 draw_set_mapped_constant_buffer(sp->draw,
00058 sp->mapped_constants[PIPE_SHADER_VERTEX],
00059 sp->constants[PIPE_SHADER_VERTEX].size);
00060 }
00061
00062 static void
00063 softpipe_unmap_constant_buffers(struct softpipe_context *sp)
00064 {
00065 struct pipe_winsys *ws = sp->pipe.winsys;
00066 uint i;
00067
00068
00069
00070
00071 draw_flush(sp->draw);
00072
00073 draw_set_mapped_constant_buffer(sp->draw, NULL, 0);
00074
00075 for (i = 0; i < 2; i++) {
00076 if (sp->constants[i].size)
00077 ws->buffer_unmap(ws, sp->constants[i].buffer);
00078 sp->mapped_constants[i] = NULL;
00079 }
00080 }
00081
00082
00083 static unsigned reduced_prim[PIPE_PRIM_POLYGON + 1] = {
00084 PIPE_PRIM_POINTS,
00085 PIPE_PRIM_LINES,
00086 PIPE_PRIM_LINES,
00087 PIPE_PRIM_LINES,
00088 PIPE_PRIM_TRIANGLES,
00089 PIPE_PRIM_TRIANGLES,
00090 PIPE_PRIM_TRIANGLES,
00091 PIPE_PRIM_TRIANGLES,
00092 PIPE_PRIM_TRIANGLES,
00093 PIPE_PRIM_TRIANGLES
00094 };
00095
00096
00097 boolean
00098 softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
00099 unsigned start, unsigned count)
00100 {
00101 return softpipe_draw_elements(pipe, NULL, 0, mode, start, count);
00102 }
00103
00104
00105
00114 boolean
00115 softpipe_draw_range_elements(struct pipe_context *pipe,
00116 struct pipe_buffer *indexBuffer,
00117 unsigned indexSize,
00118 unsigned min_index,
00119 unsigned max_index,
00120 unsigned mode, unsigned start, unsigned count)
00121 {
00122 struct softpipe_context *sp = softpipe_context(pipe);
00123 struct draw_context *draw = sp->draw;
00124 unsigned i;
00125
00126 sp->reduced_api_prim = reduced_prim[mode];
00127
00128 if (sp->dirty)
00129 softpipe_update_derived( sp );
00130
00131 softpipe_map_surfaces(sp);
00132 softpipe_map_constant_buffers(sp);
00133
00134
00135
00136
00137 for (i = 0; i < sp->num_vertex_buffers; i++) {
00138 void *buf
00139 = pipe_buffer_map(pipe->screen,
00140 sp->vertex_buffer[i].buffer,
00141 PIPE_BUFFER_USAGE_CPU_READ);
00142 draw_set_mapped_vertex_buffer(draw, i, buf);
00143 }
00144
00145 if (indexBuffer) {
00146 void *mapped_indexes
00147 = pipe_buffer_map(pipe->screen, indexBuffer,
00148 PIPE_BUFFER_USAGE_CPU_READ);
00149 draw_set_mapped_element_buffer_range(draw, indexSize,
00150 min_index,
00151 max_index,
00152 mapped_indexes);
00153 }
00154 else {
00155
00156 draw_set_mapped_element_buffer_range(draw, 0, start, start + count - 1, NULL);
00157 }
00158
00159
00160
00161 draw_arrays(draw, mode, start, count);
00162
00163
00164
00165
00166 for (i = 0; i < sp->num_vertex_buffers; i++) {
00167 draw_set_mapped_vertex_buffer(draw, i, NULL);
00168 pipe_buffer_unmap(pipe->screen, sp->vertex_buffer[i].buffer);
00169 }
00170 if (indexBuffer) {
00171 draw_set_mapped_element_buffer(draw, 0, NULL);
00172 pipe_buffer_unmap(pipe->screen, indexBuffer);
00173 }
00174
00175
00176
00177 softpipe_unmap_constant_buffers(sp);
00178
00179 return TRUE;
00180 }
00181
00182 boolean
00183 softpipe_draw_elements(struct pipe_context *pipe,
00184 struct pipe_buffer *indexBuffer,
00185 unsigned indexSize,
00186 unsigned mode, unsigned start, unsigned count)
00187 {
00188 return softpipe_draw_range_elements( pipe, indexBuffer,
00189 indexSize,
00190 0, 0xffffffff,
00191 mode, start, count );
00192 }
00193
00194
00195
00196 void
00197 softpipe_set_edgeflags(struct pipe_context *pipe, const unsigned *edgeflags)
00198 {
00199 struct softpipe_context *sp = softpipe_context(pipe);
00200 draw_set_edgeflags(sp->draw, edgeflags);
00201 }
00202