ss_triangle.c revision b51b0a847d7e7daaea69f77ab569086ef81c24a2
1/* 2 * Mesa 3-D graphics library 3 * Version: 3.5 4 * 5 * Copyright (C) 1999 Brian Paul All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the "Software"), 9 * to deal in the Software without restriction, including without limitation 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 * and/or sell copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included 15 * in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: 25 * Keith Whitwell <keithw@valinux.com> 26 */ 27 28#include "glheader.h" 29#include "colormac.h" 30#include "macros.h" 31#include "mtypes.h" 32 33#include "tnl/t_context.h" 34 35#include "ss_triangle.h" 36#include "ss_context.h" 37 38#define SS_RGBA_BIT 0x1 39#define SS_OFFSET_BIT 0x2 40#define SS_TWOSIDE_BIT 0x4 41#define SS_UNFILLED_BIT 0x8 42#define SS_MAX_TRIFUNC 0x10 43 44static triangle_func tri_tab[SS_MAX_TRIFUNC]; 45static quad_func quad_tab[SS_MAX_TRIFUNC]; 46 47 48static void _swsetup_render_line_tri( GLcontext *ctx, 49 GLuint e0, GLuint e1, GLuint e2 ) 50{ 51 SScontext *swsetup = SWSETUP_CONTEXT(ctx); 52 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; 53 GLubyte *ef = VB->EdgeFlag; 54 SWvertex *verts = swsetup->verts; 55 SWvertex *v0 = &verts[e0]; 56 SWvertex *v1 = &verts[e1]; 57 SWvertex *v2 = &verts[e2]; 58 GLchan c[2][4]; 59 GLchan s[2][4]; 60 GLuint i[2]; 61 62 if (ctx->_TriangleCaps & DD_FLATSHADE) { 63 COPY_CHAN4(c[0], v0->color); 64 COPY_CHAN4(c[1], v1->color); 65 COPY_CHAN4(s[0], v0->specular); 66 COPY_CHAN4(s[1], v1->specular); 67 i[0] = v0->index; 68 i[1] = v1->index; 69 70 COPY_CHAN4(v0->color, v2->color); 71 COPY_CHAN4(v1->color, v2->color); 72 COPY_CHAN4(v0->specular, v2->specular); 73 COPY_CHAN4(v1->specular, v2->specular); 74 v0->index = v2->index; 75 v1->index = v2->index; 76 } 77 78 if (swsetup->render_prim == GL_POLYGON) { 79 if (ef[e2]) _swrast_Line( ctx, v2, v0 ); 80 if (ef[e0]) _swrast_Line( ctx, v0, v1 ); 81 if (ef[e1]) _swrast_Line( ctx, v1, v2 ); 82 } else { 83 if (ef[e0]) _swrast_Line( ctx, v0, v1 ); 84 if (ef[e1]) _swrast_Line( ctx, v1, v2 ); 85 if (ef[e2]) _swrast_Line( ctx, v2, v0 ); 86 } 87 88 if (ctx->_TriangleCaps & DD_FLATSHADE) { 89 COPY_CHAN4(v0->color, c[0]); 90 COPY_CHAN4(v1->color, c[1]); 91 COPY_CHAN4(v0->specular, s[0]); 92 COPY_CHAN4(v1->specular, s[1]); 93 v0->index = i[0]; 94 v1->index = i[1]; 95 } 96} 97 98static void _swsetup_render_point_tri( GLcontext *ctx, 99 GLuint e0, GLuint e1, GLuint e2 ) 100{ 101 SScontext *swsetup = SWSETUP_CONTEXT(ctx); 102 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; 103 GLubyte *ef = VB->EdgeFlag; 104 SWvertex *verts = swsetup->verts; 105 SWvertex *v0 = &verts[e0]; 106 SWvertex *v1 = &verts[e1]; 107 SWvertex *v2 = &verts[e2]; 108 GLchan c[2][4]; 109 GLchan s[2][4]; 110 GLuint i[2]; 111 112 if (ctx->_TriangleCaps & DD_FLATSHADE) { 113 COPY_CHAN4(c[0], v0->color); 114 COPY_CHAN4(c[1], v1->color); 115 COPY_CHAN4(s[0], v0->specular); 116 COPY_CHAN4(s[1], v1->specular); 117 i[0] = v0->index; 118 i[1] = v1->index; 119 120 COPY_CHAN4(v0->color, v2->color); 121 COPY_CHAN4(v1->color, v2->color); 122 COPY_CHAN4(v0->specular, v2->specular); 123 COPY_CHAN4(v1->specular, v2->specular); 124 v0->index = v2->index; 125 v1->index = v2->index; 126 } 127 128 if (ef[e0]) _swrast_Point( ctx, v0 ); 129 if (ef[e1]) _swrast_Point( ctx, v1 ); 130 if (ef[e2]) _swrast_Point( ctx, v2 ); 131 132 if (ctx->_TriangleCaps & DD_FLATSHADE) { 133 COPY_CHAN4(v0->color, c[0]); 134 COPY_CHAN4(v1->color, c[1]); 135 COPY_CHAN4(v0->specular, s[0]); 136 COPY_CHAN4(v1->specular, s[1]); 137 v0->index = i[0]; 138 v1->index = i[1]; 139 } 140} 141 142#define SS_COLOR(a,b) COPY_4UBV(a,b) 143#define SS_SPEC(a,b) COPY_4UBV(a,b) 144#define SS_IND(a,b) (a = b) 145 146#define IND (0) 147#define TAG(x) x 148#include "ss_tritmp.h" 149 150#define IND (SS_OFFSET_BIT) 151#define TAG(x) x##_offset 152#include "ss_tritmp.h" 153 154#define IND (SS_TWOSIDE_BIT) 155#define TAG(x) x##_twoside 156#include "ss_tritmp.h" 157 158#define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT) 159#define TAG(x) x##_offset_twoside 160#include "ss_tritmp.h" 161 162#define IND (SS_UNFILLED_BIT) 163#define TAG(x) x##_unfilled 164#include "ss_tritmp.h" 165 166#define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT) 167#define TAG(x) x##_offset_unfilled 168#include "ss_tritmp.h" 169 170#define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT) 171#define TAG(x) x##_twoside_unfilled 172#include "ss_tritmp.h" 173 174#define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT) 175#define TAG(x) x##_offset_twoside_unfilled 176#include "ss_tritmp.h" 177 178#define IND (0|SS_RGBA_BIT) 179#define TAG(x) x##_rgba 180#include "ss_tritmp.h" 181 182#define IND (SS_OFFSET_BIT|SS_RGBA_BIT) 183#define TAG(x) x##_offset_rgba 184#include "ss_tritmp.h" 185 186#define IND (SS_TWOSIDE_BIT|SS_RGBA_BIT) 187#define TAG(x) x##_twoside_rgba 188#include "ss_tritmp.h" 189 190#define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_RGBA_BIT) 191#define TAG(x) x##_offset_twoside_rgba 192#include "ss_tritmp.h" 193 194#define IND (SS_UNFILLED_BIT|SS_RGBA_BIT) 195#define TAG(x) x##_unfilled_rgba 196#include "ss_tritmp.h" 197 198#define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT) 199#define TAG(x) x##_offset_unfilled_rgba 200#include "ss_tritmp.h" 201 202#define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT) 203#define TAG(x) x##_twoside_unfilled_rgba 204#include "ss_tritmp.h" 205 206#define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT) 207#define TAG(x) x##_offset_twoside_unfilled_rgba 208#include "ss_tritmp.h" 209 210 211void _swsetup_trifuncs_init( GLcontext *ctx ) 212{ 213 (void) ctx; 214 215 init(); 216 init_offset(); 217 init_twoside(); 218 init_offset_twoside(); 219 init_unfilled(); 220 init_offset_unfilled(); 221 init_twoside_unfilled(); 222 init_offset_twoside_unfilled(); 223 224 init_rgba(); 225 init_offset_rgba(); 226 init_twoside_rgba(); 227 init_offset_twoside_rgba(); 228 init_unfilled_rgba(); 229 init_offset_unfilled_rgba(); 230 init_twoside_unfilled_rgba(); 231 init_offset_twoside_unfilled_rgba(); 232} 233 234 235static void swsetup_points( GLcontext *ctx, GLuint first, GLuint last ) 236{ 237 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; 238 SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts; 239 GLuint i; 240 241 if (VB->Elts) { 242 for (i = first; i < last; i++) 243 if (VB->ClipMask[VB->Elts[i]] == 0) 244 _swrast_Point( ctx, &verts[VB->Elts[i]] ); 245 } 246 else { 247 for (i = first; i < last; i++) 248 if (VB->ClipMask[i] == 0) 249 _swrast_Point( ctx, &verts[i] ); 250 } 251} 252 253static void swsetup_line( GLcontext *ctx, GLuint v0, GLuint v1 ) 254{ 255 SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts; 256 _swrast_Line( ctx, &verts[v0], &verts[v1] ); 257} 258 259 260 261void _swsetup_choose_trifuncs( GLcontext *ctx ) 262{ 263 SScontext *swsetup = SWSETUP_CONTEXT(ctx); 264 GLuint ind = 0; 265 266 if (ctx->Polygon._OffsetAny) 267 ind |= SS_OFFSET_BIT; 268 269 if (ctx->Light.Enabled && ctx->Light.Model.TwoSide) 270 ind |= SS_TWOSIDE_BIT; 271 272 if (ctx->_TriangleCaps & DD_TRI_UNFILLED) 273 ind |= SS_UNFILLED_BIT; 274 275 if (ctx->Visual.rgbMode) 276 ind |= SS_RGBA_BIT; 277 278 swsetup->Triangle = tri_tab[ind]; 279 swsetup->Quad = quad_tab[ind]; 280 swsetup->Line = swsetup_line; 281 swsetup->Points = swsetup_points; 282} 283 284