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 "cell_context.h"
00040 #include "cell_draw_arrays.h"
00041 #include "cell_state.h"
00042 #include "cell_flush.h"
00043
00044 #include "draw/draw_context.h"
00045
00046
00047
00048 static void
00049 cell_map_constant_buffers(struct cell_context *sp)
00050 {
00051 struct pipe_winsys *ws = sp->pipe.winsys;
00052 uint i;
00053 for (i = 0; i < 2; i++) {
00054 if (sp->constants[i].size) {
00055 sp->mapped_constants[i] = ws->buffer_map(ws, sp->constants[i].buffer,
00056 PIPE_BUFFER_USAGE_CPU_READ);
00057 cell_flush_buffer_range(sp, sp->mapped_constants[i],
00058 sp->constants[i].buffer->size);
00059 }
00060 }
00061
00062 draw_set_mapped_constant_buffer(sp->draw,
00063 sp->mapped_constants[PIPE_SHADER_VERTEX],
00064 sp->constants[PIPE_SHADER_VERTEX].size);
00065 }
00066
00067 static void
00068 cell_unmap_constant_buffers(struct cell_context *sp)
00069 {
00070 struct pipe_winsys *ws = sp->pipe.winsys;
00071 uint i;
00072 for (i = 0; i < 2; i++) {
00073 if (sp->constants[i].size)
00074 ws->buffer_unmap(ws, sp->constants[i].buffer);
00075 sp->mapped_constants[i] = NULL;
00076 }
00077 }
00078
00079
00080
00088 static boolean
00089 cell_draw_range_elements(struct pipe_context *pipe,
00090 struct pipe_buffer *indexBuffer,
00091 unsigned indexSize,
00092 unsigned min_index,
00093 unsigned max_index,
00094 unsigned mode, unsigned start, unsigned count)
00095 {
00096 struct cell_context *sp = cell_context(pipe);
00097 struct draw_context *draw = sp->draw;
00098 unsigned i;
00099
00100 if (sp->dirty)
00101 cell_update_derived( sp );
00102
00103 #if 0
00104 cell_map_surfaces(sp);
00105 #endif
00106 cell_map_constant_buffers(sp);
00107
00108
00109
00110
00111 for (i = 0; i < sp->num_vertex_buffers; i++) {
00112 void *buf = pipe_buffer_map(pipe->screen,
00113 sp->vertex_buffer[i].buffer,
00114 PIPE_BUFFER_USAGE_CPU_READ);
00115 cell_flush_buffer_range(sp, buf, sp->vertex_buffer[i].buffer->size);
00116 draw_set_mapped_vertex_buffer(draw, i, buf);
00117 }
00118
00119 if (indexBuffer) {
00120 void *mapped_indexes = pipe_buffer_map(pipe->screen,
00121 indexBuffer,
00122 PIPE_BUFFER_USAGE_CPU_READ);
00123 draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
00124 }
00125 else {
00126
00127 draw_set_mapped_element_buffer(draw, 0, NULL);
00128 }
00129
00130
00131
00132 draw_arrays(draw, mode, start, count);
00133
00134
00135
00136
00137 for (i = 0; i < sp->num_vertex_buffers; i++) {
00138 draw_set_mapped_vertex_buffer(draw, i, NULL);
00139 pipe_buffer_unmap(pipe->screen, sp->vertex_buffer[i].buffer);
00140 }
00141 if (indexBuffer) {
00142 draw_set_mapped_element_buffer(draw, 0, NULL);
00143 pipe_buffer_unmap(pipe->screen, indexBuffer);
00144 }
00145
00146
00147 cell_unmap_constant_buffers(sp);
00148
00149 return TRUE;
00150 }
00151
00152
00153 static boolean
00154 cell_draw_elements(struct pipe_context *pipe,
00155 struct pipe_buffer *indexBuffer,
00156 unsigned indexSize,
00157 unsigned mode, unsigned start, unsigned count)
00158 {
00159 return cell_draw_range_elements( pipe, indexBuffer,
00160 indexSize,
00161 0, 0xffffffff,
00162 mode, start, count );
00163 }
00164
00165
00166 static boolean
00167 cell_draw_arrays(struct pipe_context *pipe, unsigned mode,
00168 unsigned start, unsigned count)
00169 {
00170 return cell_draw_elements(pipe, NULL, 0, mode, start, count);
00171 }
00172
00173
00174 static void
00175 cell_set_edgeflags(struct pipe_context *pipe, const unsigned *edgeflags)
00176 {
00177 struct cell_context *cell = cell_context(pipe);
00178 draw_set_edgeflags(cell->draw, edgeflags);
00179 }
00180
00181
00182
00183 void
00184 cell_init_draw_functions(struct cell_context *cell)
00185 {
00186 cell->pipe.draw_arrays = cell_draw_arrays;
00187 cell->pipe.draw_elements = cell_draw_elements;
00188 cell->pipe.draw_range_elements = cell_draw_range_elements;
00189 cell->pipe.set_edgeflags = cell_set_edgeflags;
00190 }
00191