draw_pipe_unfilled.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00033 /* Authors:  Keith Whitwell <keith@tungstengraphics.com>
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 /* Unfilled tri:  
00109  *
00110  * Note edgeflags in the vertex struct is not sufficient as we will
00111  * need to manipulate them when decomposing primitives.  
00112  * 
00113  * We currently keep the vertex edgeflag and primitive edgeflag mask
00114  * separate until the last possible moment.
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; /* front */
00144    unfilled->mode[1] = stage->draw->rasterizer->fill_cw;  /* back */
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 }

Generated on Tue Sep 29 06:25:14 2009 for Gallium3D by  doxygen 1.5.4