/* $Id: clip.c,v 1.11 1997/02/13 21:16:09 brianp Exp $ */ /* * Mesa 3-D graphics library * Version: 2.2 * Copyright (C) 1995-1997 Brian Paul * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * $Log: clip.c,v $ * Revision 1.11 1997/02/13 21:16:09 brianp * if too many vertices in polygon return VB_SIZE-1, not VB_SIZE * * Revision 1.10 1997/02/10 21:16:12 brianp * added checks in polygon clippers to prevent array overflows * * Revision 1.9 1997/02/04 19:39:39 brianp * changed size of vlist2[] arrays to VB_SIZE per Randy Frank * * Revision 1.8 1996/12/02 20:10:07 brianp * changed the macros in gl_viewclip_polygon() to be like gl_viewclip_line() * * Revision 1.7 1996/10/29 02:55:02 brianp * fixed duplicate vertex bug in gl_viewclip_polygon() * * Revision 1.6 1996/10/07 23:48:33 brianp * changed temporaries to GLdouble in gl_viewclip_polygon() * * Revision 1.5 1996/10/03 01:43:45 brianp * changed INSIDE() macro in gl_viewclip_polygon() to work like other macros * * Revision 1.4 1996/10/03 01:36:33 brianp * changed COMPUTE_INTERSECTION macros in gl_viewclip_polygon to avoid * potential roundoff errors * * Revision 1.3 1996/09/27 01:24:23 brianp * removed unused variables * * Revision 1.2 1996/09/15 01:48:58 brianp * removed #define NULL 0 * * Revision 1.1 1996/09/13 01:38:16 brianp * Initial revision * */ #include #include "clip.h" #include "context.h" #include "dlist.h" #include "macros.h" #include "matrix.h" #include "types.h" #include "vb.h" #include "xform.h" /* Linear interpolation between A and B: */ #define LINTERP( T, A, B ) ( (A) + (T) * ( (B) - (A) ) ) #define EYE_SPACE 1 #define CLIP_SPACE 2 static GLuint Space; /* * This function is used to interpolate colors, indexes, and texture * coordinates when clipping has to be done. In general, we compute * aux[dst] = aux[in] + t * (aux[out] - aux[in]) * where aux is the quantity to be interpolated. * Input: dst - index of array position to store interpolated value * t - a value in [0,1] * in - index of array position corresponding to 'inside' vertex * out - index of array position corresponding to 'outside' vertex */ static void interpolate_aux( GLcontext* ctx, GLuint dst, GLfloat t, GLuint in, GLuint out ) { struct vertex_buffer* VB = ctx->VB; if (ctx->ClipMask & CLIP_FCOLOR_BIT) { VB->Fcolor[dst][0] = LINTERP( t, VB->Fcolor[in][0], VB->Fcolor[out][0] ); VB->Fcolor[dst][1] = LINTERP( t, VB->Fcolor[in][1], VB->Fcolor[out][1] ); VB->Fcolor[dst][2] = LINTERP( t, VB->Fcolor[in][2], VB->Fcolor[out][2] ); VB->Fcolor[dst][3] = LINTERP( t, VB->Fcolor[in][3], VB->Fcolor[out][3] ); } else if (ctx->ClipMask & CLIP_FINDEX_BIT) { VB->Findex[dst] = (GLuint) (GLint) LINTERP( t, (GLfloat) VB->Findex[in], (GLfloat) VB->Findex[out] ); } if (ctx->ClipMask & CLIP_BCOLOR_BIT) { VB->Bcolor[dst][0] = LINTERP( t, VB->Bcolor[in][0], VB->Bcolor[out][0] ); VB->Bcolor[dst][1] = LINTERP( t, VB->Bcolor[in][1], VB->Bcolor[out][1] ); VB->Bcolor[dst][2] = LINTERP( t, VB->Bcolor[in][2], VB->Bcolor[out][2] ); VB->Bcolor[dst][3] = LINTERP( t, VB->Bcolor[in][3], VB->Bcolor[out][3] ); } else if (ctx->ClipMask & CLIP_BINDEX_BIT) { VB->Bindex[dst] = (GLuint) (GLint) LINTERP( t, (GLfloat) VB->Bindex[in], (GLfloat) VB->Bindex[out] ); } if (ctx->ClipMask & CLIP_TEXTURE_BIT) { /* TODO: is more sophisticated texture coord interpolation needed?? */ if (Space==CLIP_SPACE) { /* also interpolate eye Z component */ VB->Eye[dst][2] = LINTERP( t, VB->Eye[in][2], VB->Eye[out][2] ); } VB->TexCoord[dst][0] = LINTERP(t,VB->TexCoord[in][0],VB->TexCoord[out][0]); VB->TexCoord[dst][1] = LINTERP(t,VB->TexCoord[in][1],VB->TexCoord[out][1]); VB->TexCoord[dst][2] = LINTERP(t,VB->TexCoord[in][2],VB->TexCoord[out][2]); VB->TexCoord[dst][3] = LINTERP(t,VB->TexCoord[in][3],VB->TexCoord[out][3]); } }