| 1 | /* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Mesa 3-D graphics library
|
|---|
| 5 | * Version: 3.3
|
|---|
| 6 | *
|
|---|
| 7 | * Copyright (C) 1999 Brian Paul All Rights Reserved.
|
|---|
| 8 | *
|
|---|
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a
|
|---|
| 10 | * copy of this software and associated documentation files (the "Software"),
|
|---|
| 11 | * to deal in the Software without restriction, including without limitation
|
|---|
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|---|
| 13 | * and/or sell copies of the Software, and to permit persons to whom the
|
|---|
| 14 | * Software is furnished to do so, subject to the following conditions:
|
|---|
| 15 | *
|
|---|
| 16 | * The above copyright notice and this permission notice shall be included
|
|---|
| 17 | * in all copies or substantial portions of the Software.
|
|---|
| 18 | *
|
|---|
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|---|
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|---|
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|---|
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|---|
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|---|
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|---|
| 25 | *
|
|---|
| 26 | *
|
|---|
| 27 | * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
|
|---|
| 28 | * terms stated above.
|
|---|
| 29 | *
|
|---|
| 30 | * Thank you for your contribution, David!
|
|---|
| 31 | *
|
|---|
| 32 | * Please make note of the above copyright/license statement. If you
|
|---|
| 33 | * contributed code or bug fixes to this code under the previous (GNU
|
|---|
| 34 | * Library) license and object to the new license, your code will be
|
|---|
| 35 | * removed at your request. Please see the Mesa docs/COPYRIGHT file
|
|---|
| 36 | * for more information.
|
|---|
| 37 | *
|
|---|
| 38 | * Additional Mesa/3Dfx driver developers:
|
|---|
| 39 | * Daryll Strauss <daryll@precisioninsight.com>
|
|---|
| 40 | * Keith Whitwell <keith@precisioninsight.com>
|
|---|
| 41 | *
|
|---|
| 42 | * See fxapi.h for more revision/author details.
|
|---|
| 43 | */
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | #define V1 VARS_XYZW
|
|---|
| 47 | #define S1 DO_SETUP_XYZW
|
|---|
| 48 | #define T1 COPY_XYZW_STRIDE
|
|---|
| 49 | #define Z1 4
|
|---|
| 50 |
|
|---|
| 51 | #if (IND & SETUP_RGBA)
|
|---|
| 52 | #define V2 V1 VARS_RGBA
|
|---|
| 53 | #define S2 S1 DO_SETUP_RGBA
|
|---|
| 54 | #define T2 T1 COPY_RGBA_STRIDE
|
|---|
| 55 | #define Z2 (Z1 + 4)
|
|---|
| 56 | #else
|
|---|
| 57 | #define V2 V1
|
|---|
| 58 | #define S2 S1
|
|---|
| 59 | #define T2 T1
|
|---|
| 60 | #define Z2 Z1
|
|---|
| 61 | #endif
|
|---|
| 62 |
|
|---|
| 63 | #if (IND & SETUP_TMU0)
|
|---|
| 64 | #define V3 V2 VARS_TMU0
|
|---|
| 65 | #define S3 S2 DO_SETUP_TMU0(Z2)
|
|---|
| 66 | #define T3 T2 COPY_TMU0_STRIDE(Z2)
|
|---|
| 67 | #define Z3 (Z2 + 2)
|
|---|
| 68 | #else
|
|---|
| 69 | #define V3 V2
|
|---|
| 70 | #define S3 S2
|
|---|
| 71 | #define T3 T2
|
|---|
| 72 | #define Z3 Z2
|
|---|
| 73 | #endif
|
|---|
| 74 |
|
|---|
| 75 | #if (IND & SETUP_TMU1)
|
|---|
| 76 | #define V4 V3 VARS_TMU1
|
|---|
| 77 | #define S4 S3 DO_SETUP_TMU1(Z3)
|
|---|
| 78 | #define T4 T3 COPY_TMU1_STRIDE(Z3)
|
|---|
| 79 | #define Z4 (Z3 + 2)
|
|---|
| 80 | #else
|
|---|
| 81 | #define V4 V3
|
|---|
| 82 | #define S4 S3
|
|---|
| 83 | #define T4 T3
|
|---|
| 84 | #define Z4 Z3
|
|---|
| 85 | #endif
|
|---|
| 86 |
|
|---|
| 87 | #if (Z4 & 2)
|
|---|
| 88 | #define SIZE (Z4+2)
|
|---|
| 89 | #define COPY_STRIDE T4 COPY_NIL(Z4)
|
|---|
| 90 | #else
|
|---|
| 91 | #define SIZE Z4
|
|---|
| 92 | #define COPY_STRIDE T4
|
|---|
| 93 | #endif
|
|---|
| 94 |
|
|---|
| 95 | #define VARS V4
|
|---|
| 96 | #define SETUP S4
|
|---|
| 97 |
|
|---|
| 98 | #define DRAW_LINE(tmp0, tmp1, width) \
|
|---|
| 99 | do { \
|
|---|
| 100 | GrVertex verts[4]; \
|
|---|
| 101 | float dx, dy, ix, iy; \
|
|---|
| 102 | \
|
|---|
| 103 | dx = tmp0->x - tmp1->x; \
|
|---|
| 104 | dy = tmp0->y - tmp1->y; \
|
|---|
| 105 | \
|
|---|
| 106 | if (dx * dx > dy * dy) { \
|
|---|
| 107 | iy = width * .5; \
|
|---|
| 108 | ix = 0; \
|
|---|
| 109 | } else { \
|
|---|
| 110 | iy = 0; \
|
|---|
| 111 | ix = width * .5; \
|
|---|
| 112 | } \
|
|---|
| 113 | \
|
|---|
| 114 | verts[0] = *tmp0; \
|
|---|
| 115 | verts[1] = *tmp0; \
|
|---|
| 116 | verts[2] = *tmp1; \
|
|---|
| 117 | verts[3] = *tmp1; \
|
|---|
| 118 | \
|
|---|
| 119 | verts[0].x = tmp0->x - ix; \
|
|---|
| 120 | verts[0].y = tmp0->y - iy; \
|
|---|
| 121 | \
|
|---|
| 122 | verts[1].x = tmp0->x + ix; \
|
|---|
| 123 | verts[1].y = tmp0->y + iy; \
|
|---|
| 124 | \
|
|---|
| 125 | verts[2].x = tmp1->x + ix; \
|
|---|
| 126 | verts[2].y = tmp1->y + iy; \
|
|---|
| 127 | \
|
|---|
| 128 | verts[3].x = tmp1->x - ix; \
|
|---|
| 129 | verts[3].y = tmp1->y - iy; \
|
|---|
| 130 | \
|
|---|
| 131 | FX_grDrawPolygonVertexList(4, verts); \
|
|---|
| 132 | } while (0)
|
|---|
| 133 |
|
|---|
| 134 | static void TAG(fx_tri_view_clip)( struct vertex_buffer *VB,
|
|---|
| 135 | GLuint v[],
|
|---|
| 136 | GLubyte mask )
|
|---|
| 137 | {
|
|---|
| 138 | GLcontext *ctx = VB->ctx;
|
|---|
| 139 | fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx;
|
|---|
| 140 | GLfloat data[VB_MAX_CLIPPED_VERTS*12];
|
|---|
| 141 | GLfloat *vlist[VB_MAX_CLIPPED_VERTS];
|
|---|
| 142 | GrVertex *verts[VB_MAX_CLIPPED_VERTS];
|
|---|
| 143 | fxVertex *gWin = FX_DRIVER_DATA(VB)->verts;
|
|---|
| 144 | GLfloat *out = data;
|
|---|
| 145 | GLfloat *mat = ctx->Viewport.WindowMap.m;
|
|---|
| 146 | GLuint i, n;
|
|---|
| 147 | GLubyte *clipmask = VB->ClipMask;
|
|---|
| 148 |
|
|---|
| 149 | GLuint tmu0_source = fxMesa->tmu_source[0];
|
|---|
| 150 | GLuint tmu1_source = fxMesa->tmu_source[1];
|
|---|
| 151 | GLvector4f *tc0_vec = VB->TexCoordPtr[tmu0_source];
|
|---|
| 152 | GLvector4f *tc1_vec = VB->TexCoordPtr[tmu1_source];
|
|---|
| 153 |
|
|---|
| 154 | (void) fxMesa;
|
|---|
| 155 | (void) tmu0_source; (void) tc0_vec;
|
|---|
| 156 | (void) tmu1_source; (void) tc1_vec;
|
|---|
| 157 |
|
|---|
| 158 | for (i = 0 ; i < 3 ; i++) {
|
|---|
| 159 | GLuint e = v[i];
|
|---|
| 160 | verts[i] = 0;
|
|---|
| 161 | if (!clipmask[e]) verts[i] = (GrVertex *)gWin[e].f;
|
|---|
| 162 | vlist[i] = out;
|
|---|
| 163 | COPY_STRIDE;
|
|---|
| 164 | out += SIZE;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | if ((n = fx_view_clip_triangle( ctx, vlist, verts, SIZE, mask )) >= 3)
|
|---|
| 168 | {
|
|---|
| 169 | GrVertex tmp[VB_MAX_CLIPPED_VERTS];
|
|---|
| 170 | GrVertex *v = tmp, *v2, *v3;
|
|---|
| 171 | VARS;
|
|---|
| 172 |
|
|---|
| 173 | for (i = 0 ; i < n ; i++)
|
|---|
| 174 | if (!verts[i]) {
|
|---|
| 175 | GLfloat *data = vlist[i];
|
|---|
| 176 | SETUP;
|
|---|
| 177 | verts[i] = v++;
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | v = verts[0];
|
|---|
| 181 | v2 = verts[1];
|
|---|
| 182 | v3 = verts[2];
|
|---|
| 183 |
|
|---|
| 184 | for (i = 2 ; i < n ; v2 = v3, v3=verts[++i])
|
|---|
| 185 | FX_grDrawTriangle(v, v2, v3);
|
|---|
| 186 | }
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 | static void TAG(fx_tri_clip_stride)( struct vertex_buffer *VB,
|
|---|
| 194 | GLuint v[],
|
|---|
| 195 | GLuint mask )
|
|---|
| 196 | {
|
|---|
| 197 | GLcontext *ctx = VB->ctx;
|
|---|
| 198 | fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx;
|
|---|
| 199 | GLfloat data[VB_MAX_CLIPPED_VERTS*12];
|
|---|
| 200 | GLfloat *vlist[VB_MAX_CLIPPED_VERTS];
|
|---|
| 201 | GrVertex *verts[VB_MAX_CLIPPED_VERTS];
|
|---|
| 202 | fxVertex *gWin = FX_DRIVER_DATA(VB)->verts;
|
|---|
| 203 | GLfloat *out = data;
|
|---|
| 204 | GLfloat *mat = ctx->Viewport.WindowMap.m;
|
|---|
| 205 | GLuint i, n;
|
|---|
| 206 | GLubyte *clipmask = VB->ClipMask;
|
|---|
| 207 |
|
|---|
| 208 | GLuint tmu0_source = fxMesa->tmu_source[0];
|
|---|
| 209 | GLuint tmu1_source = fxMesa->tmu_source[1];
|
|---|
| 210 | GLvector4f *tc0_vec = VB->TexCoordPtr[tmu0_source];
|
|---|
| 211 | GLvector4f *tc1_vec = VB->TexCoordPtr[tmu1_source];
|
|---|
| 212 |
|
|---|
| 213 | (void) fxMesa;
|
|---|
| 214 | (void) tmu0_source; (void) tc0_vec;
|
|---|
| 215 | (void) tmu1_source; (void) tc1_vec;
|
|---|
| 216 |
|
|---|
| 217 | for (i = 0 ; i < 3 ; i++) {
|
|---|
| 218 | GLuint e = v[i];
|
|---|
| 219 | verts[i] = 0;
|
|---|
| 220 | if (!clipmask[e]) verts[i] = (GrVertex *)gWin[e].f;
|
|---|
| 221 | vlist[i] = out;
|
|---|
| 222 | COPY_STRIDE;
|
|---|
| 223 | out += SIZE;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | if (VB->ClipPtr->size < 4) {
|
|---|
| 227 | vlist[0][3] = vlist[1][3] = vlist[2][3] = 1.0;
|
|---|
| 228 | if (VB->ClipPtr->size == 2)
|
|---|
| 229 | vlist[0][2] = vlist[1][2] = vlist[2][2] = 0.0;
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | if ((n = fx_clip_triangle( ctx, vlist, verts, SIZE, mask )) >= 3)
|
|---|
| 233 | {
|
|---|
| 234 | GrVertex tmp[VB_MAX_CLIPPED_VERTS];
|
|---|
| 235 | GrVertex *v = tmp, *v2, *v3;
|
|---|
| 236 | VARS;
|
|---|
| 237 |
|
|---|
| 238 | for (i = 0 ; i < n ; i++)
|
|---|
| 239 | if (!verts[i]) {
|
|---|
| 240 | GLfloat *data = vlist[i];
|
|---|
| 241 | SETUP;
|
|---|
| 242 | verts[i] = v++;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | v = verts[0];
|
|---|
| 246 | v2 = verts[1];
|
|---|
| 247 | v3 = verts[2];
|
|---|
| 248 |
|
|---|
| 249 | for (i = 2 ; i < n ; v2 = v3, v3=verts[++i])
|
|---|
| 250 | FX_grDrawTriangle(v, v2, v3);
|
|---|
| 251 | }
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 | static void TAG(fx_line_clip)( struct vertex_buffer *VB,
|
|---|
| 257 | GLuint v1, GLuint v2,
|
|---|
| 258 | GLubyte mask )
|
|---|
| 259 | {
|
|---|
| 260 | GLcontext *ctx = VB->ctx;
|
|---|
| 261 | fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx;
|
|---|
| 262 | GLfloat data[VB_MAX_CLIPPED_VERTS*12];
|
|---|
| 263 | GLfloat *vlist[VB_MAX_CLIPPED_VERTS];
|
|---|
| 264 | GLfloat *out = data;
|
|---|
| 265 | GLfloat *mat = ctx->Viewport.WindowMap.m;
|
|---|
| 266 | GLfloat w = ctx->Line.Width*.5;
|
|---|
| 267 | GLuint e, n;
|
|---|
| 268 |
|
|---|
| 269 | GLuint tmu0_source = fxMesa->tmu_source[0];
|
|---|
| 270 | GLuint tmu1_source = fxMesa->tmu_source[1];
|
|---|
| 271 | GLvector4f *tc0_vec = VB->TexCoordPtr[tmu0_source];
|
|---|
| 272 | GLvector4f *tc1_vec = VB->TexCoordPtr[tmu1_source];
|
|---|
| 273 |
|
|---|
| 274 | VARS;
|
|---|
| 275 |
|
|---|
| 276 | (void) fxMesa;
|
|---|
| 277 | (void) tmu0_source; (void) tc0_vec;
|
|---|
| 278 | (void) tmu1_source; (void) tc1_vec;
|
|---|
| 279 |
|
|---|
| 280 | vlist[0] = out;
|
|---|
| 281 | e = v1;
|
|---|
| 282 | COPY_STRIDE;
|
|---|
| 283 | out += SIZE;
|
|---|
| 284 |
|
|---|
| 285 | vlist[1] = out;
|
|---|
| 286 | e = v2;
|
|---|
| 287 | COPY_STRIDE;
|
|---|
| 288 | out += SIZE;
|
|---|
| 289 |
|
|---|
| 290 | if (VB->ClipPtr->size < 4) {
|
|---|
| 291 | vlist[0][3] = vlist[1][3] = 1.0;
|
|---|
| 292 | if (VB->ClipPtr->size == 2)
|
|---|
| 293 | vlist[0][2] = vlist[1][2] = 0.0;
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | if ((n = fx_clip_line( ctx, vlist, SIZE, mask )) != 0)
|
|---|
| 297 | {
|
|---|
| 298 | GrVertex gWin[2];
|
|---|
| 299 | GrVertex *v;
|
|---|
| 300 | GLfloat *data;
|
|---|
| 301 |
|
|---|
| 302 | v = gWin;
|
|---|
| 303 | data = vlist[0];
|
|---|
| 304 | SETUP;
|
|---|
| 305 |
|
|---|
| 306 | v++;
|
|---|
| 307 | data = vlist[1];
|
|---|
| 308 | SETUP;
|
|---|
| 309 |
|
|---|
| 310 | DRAW_LINE(gWin, v, w);
|
|---|
| 311 | }
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 | #undef V1
|
|---|
| 317 | #undef S1
|
|---|
| 318 | #undef C1
|
|---|
| 319 | #undef Z1
|
|---|
| 320 | #undef T1
|
|---|
| 321 |
|
|---|
| 322 | #undef V2
|
|---|
| 323 | #undef S2
|
|---|
| 324 | #undef C2
|
|---|
| 325 | #undef Z2
|
|---|
| 326 | #undef T2
|
|---|
| 327 |
|
|---|
| 328 | #undef V3
|
|---|
| 329 | #undef S3
|
|---|
| 330 | #undef C3
|
|---|
| 331 | #undef Z3
|
|---|
| 332 | #undef T3
|
|---|
| 333 |
|
|---|
| 334 | #undef V4
|
|---|
| 335 | #undef S4
|
|---|
| 336 | #undef C4
|
|---|
| 337 | #undef Z4
|
|---|
| 338 | #undef T4
|
|---|
| 339 |
|
|---|
| 340 | #undef VARS
|
|---|
| 341 | #undef SETUP
|
|---|
| 342 | #undef COPY
|
|---|
| 343 | #undef COPY_STRIDE
|
|---|
| 344 | #undef SIZE
|
|---|
| 345 | #undef IND
|
|---|
| 346 | #undef TAG
|
|---|