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
00033
00034
00035
00036 #include "util/u_memory.h"
00037 #include "pipe/p_defines.h"
00038 #include "draw_private.h"
00039 #include "draw_pipe.h"
00040
00041
00042 struct unfilled_stage {
00043 struct draw_stage stage;
00044
00049 unsigned mode[2];
00050 };
00051
00052
00053 static INLINE struct unfilled_stage *unfilled_stage( struct draw_stage *stage )
00054 {
00055 return (struct unfilled_stage *)stage;
00056 }
00057
00058
00059
00060 static void point( struct draw_stage *stage,
00061 struct vertex_header *v0 )
00062 {
00063 struct prim_header tmp;
00064 tmp.v[0] = v0;
00065 stage->next->point( stage->next, &tmp );
00066 }
00067
00068 static void line( struct draw_stage *stage,
00069 struct vertex_header *v0,
00070 struct vertex_header *v1 )
00071 {
00072 struct prim_header tmp;
00073 tmp.v[0] = v0;
00074 tmp.v[1] = v1;
00075 stage->next->line( stage->next, &tmp );
00076 }
00077
00078
00079 static void points( struct draw_stage *stage,
00080 struct prim_header *header )
00081 {
00082 struct vertex_header *v0 = header->v[0];
00083 struct vertex_header *v1 = header->v[1];
00084 struct vertex_header *v2 = header->v[2];
00085
00086 if ((header->flags & DRAW_PIPE_EDGE_FLAG_0) && v0->edgeflag) point( stage, v0 );
00087 if ((header->flags & DRAW_PIPE_EDGE_FLAG_1) && v1->edgeflag) point( stage, v1 );
00088 if ((header->flags & DRAW_PIPE_EDGE_FLAG_2) && v2->edgeflag) point( stage, v2 );
00089 }
00090
00091
00092 static void lines( struct draw_stage *stage,
00093 struct prim_header *header )
00094 {
00095 struct vertex_header *v0 = header->v[0];
00096 struct vertex_header *v1 = header->v[1];
00097 struct vertex_header *v2 = header->v[2];
00098
00099 if (header->flags & DRAW_PIPE_RESET_STIPPLE)
00100 stage->next->reset_stipple_counter( stage->next );
00101
00102 if ((header->flags & DRAW_PIPE_EDGE_FLAG_2) && v2->edgeflag) line( stage, v2, v0 );
00103 if ((header->flags & DRAW_PIPE_EDGE_FLAG_0) && v0->edgeflag) line( stage, v0, v1 );
00104 if ((header->flags & DRAW_PIPE_EDGE_FLAG_1) && v1->edgeflag) line( stage, v1, v2 );
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 static void unfilled_tri( struct draw_stage *stage,
00117 struct prim_header *header )
00118 {
00119 struct unfilled_stage *unfilled = unfilled_stage(stage);
00120 unsigned mode = unfilled->mode[header->det >= 0.0];
00121
00122 switch (mode) {
00123 case PIPE_POLYGON_MODE_FILL:
00124 stage->next->tri( stage->next, header );
00125 break;
00126 case PIPE_POLYGON_MODE_LINE:
00127 lines( stage, header );
00128 break;
00129 case PIPE_POLYGON_MODE_POINT:
00130 points( stage, header );
00131 break;
00132 default:
00133 assert(0);
00134 }
00135 }
00136
00137
00138 static void unfilled_first_tri( struct draw_stage *stage,
00139 struct prim_header *header )
00140 {
00141 struct unfilled_stage *unfilled = unfilled_stage(stage);
00142
00143 unfilled->mode[0] = stage->draw->rasterizer->fill_ccw;
00144 unfilled->mode[1] = stage->draw->rasterizer->fill_cw;
00145
00146 stage->tri = unfilled_tri;
00147 stage->tri( stage, header );
00148 }
00149
00150
00151
00152 static void unfilled_flush( struct draw_stage *stage,
00153 unsigned flags )
00154 {
00155 stage->next->flush( stage->next, flags );
00156
00157 stage->tri = unfilled_first_tri;
00158 }
00159
00160
00161 static void unfilled_reset_stipple_counter( struct draw_stage *stage )
00162 {
00163 stage->next->reset_stipple_counter( stage->next );
00164 }
00165
00166
00167 static void unfilled_destroy( struct draw_stage *stage )
00168 {
00169 draw_free_temp_verts( stage );
00170 FREE( stage );
00171 }
00172
00173
00177 struct draw_stage *draw_unfilled_stage( struct draw_context *draw )
00178 {
00179 struct unfilled_stage *unfilled = CALLOC_STRUCT(unfilled_stage);
00180 if (unfilled == NULL)
00181 goto fail;
00182
00183 if (!draw_alloc_temp_verts( &unfilled->stage, 0 ))
00184 goto fail;
00185
00186 unfilled->stage.draw = draw;
00187 unfilled->stage.next = NULL;
00188 unfilled->stage.tmp = NULL;
00189 unfilled->stage.point = draw_pipe_passthrough_point;
00190 unfilled->stage.line = draw_pipe_passthrough_line;
00191 unfilled->stage.tri = unfilled_first_tri;
00192 unfilled->stage.flush = unfilled_flush;
00193 unfilled->stage.reset_stipple_counter = unfilled_reset_stipple_counter;
00194 unfilled->stage.destroy = unfilled_destroy;
00195
00196 return &unfilled->stage;
00197
00198 fail:
00199 if (unfilled)
00200 unfilled->stage.destroy( &unfilled->stage );
00201
00202 return NULL;
00203 }