Ensure programs don't overflow allocated instruction store.
[mesa.git] / src / mesa / tnl / t_vb_cliptmp.h
index 6ecd1c3c605103131769790573b673e6c011e14a..1e3a6b02ee226789c87f86a1348002852a4ab371 100644 (file)
@@ -1,4 +1,3 @@
-/* $Id: t_vb_cliptmp.h,v 1.10 2001/03/19 02:25:37 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -24,7 +23,7 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *    Keith Whitwell <keithw@valinux.com>
+ *    Keith Whitwell <keith@tungstengraphics.com>
  */
 
 
@@ -44,7 +43,7 @@ do {                                                                  \
         GLfloat dp = CLIP_DOTPROD(idx, A, B, C, D );                   \
                                                                        \
          clipmask[idxPrev] |= PLANE;                                   \
-        if (!NEGATIVE(dpPrev)) {                                       \
+        if (!IS_NEGATIVE(dpPrev)) {                                    \
            outlist[outcount++] = idxPrev;                              \
            clipmask[idxPrev] &= ~PLANE;                                \
         }                                                              \
@@ -53,18 +52,18 @@ do {                                                                        \
             GLuint newvert = VB->LastClipped++;                                \
             VB->ClipMask[newvert] = 0;                                 \
             outlist[outcount++] = newvert;                             \
-           if (NEGATIVE(dp)) {                                         \
+           if (IS_NEGATIVE(dp)) {                                      \
               /* Going out of bounds.  Avoid division by zero as we    \
                * know dp != dpPrev from DIFFERENT_SIGNS, above.        \
                */                                                      \
               GLfloat t = dp / (dp - dpPrev);                          \
-               LINTERP_4F( t, coord, newvert, idx, idxPrev, SIZE );    \
+               INTERP_4F( t, coord[newvert], coord[idx], coord[idxPrev]); \
               interp( ctx, t, newvert, idx, idxPrev, GL_TRUE );        \
            } else {                                                    \
               /* Coming back in.                                       \
                */                                                      \
               GLfloat t = dpPrev / (dpPrev - dp);                      \
-               LINTERP_4F( t, coord, newvert, idxPrev, idx, SIZE );    \
+               INTERP_4F( t, coord[newvert], coord[idxPrev], coord[idx]); \
               interp( ctx, t, newvert, idxPrev, idx, GL_FALSE );       \
            }                                                           \
         }                                                              \
@@ -86,49 +85,48 @@ do {                                                                        \
 } while (0)
 
 
-#define LINE_CLIP(PLANE, A, B, C, D )                          \
-do {                                                           \
-   if (mask & PLANE) {                                         \
-      GLfloat dpI = CLIP_DOTPROD( ii, A, B, C, D );            \
-      GLfloat dpJ = CLIP_DOTPROD( jj, A, B, C, D );            \
-                                                               \
-      if (DIFFERENT_SIGNS(dpI, dpJ)) {                         \
-         GLuint newvert = VB->LastClipped++;                   \
-         VB->ClipMask[newvert] = 0;                            \
-        if (NEGATIVE(dpJ)) {                                   \
-           GLfloat t = dpI / (dpI - dpJ);                      \
-            VB->ClipMask[jj] |= PLANE;                         \
-            LINTERP_4F( t, coord, newvert, ii, jj, SIZE );     \
-           interp( ctx, t, newvert, ii, jj, GL_FALSE );        \
-            jj = newvert;                                      \
-        } else {                                               \
-           GLfloat t = dpJ / (dpJ - dpI);                      \
-            VB->ClipMask[ii] |= PLANE;                         \
-            LINTERP_4F( t, coord, newvert, jj, ii, SIZE );     \
-           interp( ctx, t, newvert, jj, ii, GL_FALSE );        \
-            ii = newvert;                                      \
-        }                                                      \
-      }                                                                \
-      else if (NEGATIVE(dpI))                                  \
-        return;                                                \
-  }                                                            \
+#define LINE_CLIP(PLANE, A, B, C, D )                                  \
+do {                                                                   \
+   if (mask & PLANE) {                                                 \
+      GLfloat dpI = CLIP_DOTPROD( ii, A, B, C, D );                    \
+      GLfloat dpJ = CLIP_DOTPROD( jj, A, B, C, D );                    \
+                                                                       \
+      if (DIFFERENT_SIGNS(dpI, dpJ)) {                                 \
+         GLuint newvert = VB->LastClipped++;                           \
+         VB->ClipMask[newvert] = 0;                                    \
+        if (IS_NEGATIVE(dpJ)) {                                        \
+           GLfloat t = dpI / (dpI - dpJ);                              \
+            VB->ClipMask[jj] |= PLANE;                                 \
+            INTERP_4F( t, coord[newvert], coord[ii], coord[jj] );      \
+           interp( ctx, t, newvert, ii, jj, GL_FALSE );                \
+            jj = newvert;                                              \
+        } else {                                                       \
+           GLfloat t = dpJ / (dpJ - dpI);                              \
+            VB->ClipMask[ii] |= PLANE;                                 \
+            INTERP_4F( t, coord[newvert], coord[jj], coord[ii] );      \
+           interp( ctx, t, newvert, jj, ii, GL_FALSE );                \
+            ii = newvert;                                              \
+        }                                                              \
+      }                                                                        \
+      else if (IS_NEGATIVE(dpI))                                       \
+        return;                                                        \
+  }                                                                    \
 } while (0)
 
 
 
 /* Clip a line against the viewport and user clip planes.
  */
-static __inline void TAG(clip_line)( GLcontext *ctx,
-                                    GLuint i, GLuint j,
-                                    GLubyte mask )
+static INLINE void
+TAG(clip_line)( GLcontext *ctx, GLuint i, GLuint j, GLubyte mask )
 {
    TNLcontext *tnl = TNL_CONTEXT(ctx);
    struct vertex_buffer *VB = &tnl->vb;
-   interp_func interp = tnl->Driver.RenderInterp;
+   tnl_interp_func interp = tnl->Driver.Render.Interp;
    GLfloat (*coord)[4] = VB->ClipPtr->data;
    GLuint ii = i, jj = j, p;
 
-   VB->LastClipped = VB->FirstClipped;
+   VB->LastClipped = VB->Count;
 
    if (mask & 0x3f) {
       LINE_CLIP( CLIP_RIGHT_BIT,  -1,  0,  0, 1 );
@@ -141,43 +139,42 @@ static __inline void TAG(clip_line)( GLcontext *ctx,
 
    if (mask & CLIP_USER_BIT) {
       for (p=0;p<MAX_CLIP_PLANES;p++) {
-        if (ctx->Transform.ClipEnabled[p]) {
-           GLfloat a = ctx->Transform._ClipUserPlane[p][0];
-           GLfloat b = ctx->Transform._ClipUserPlane[p][1];
-           GLfloat c = ctx->Transform._ClipUserPlane[p][2];
-           GLfloat d = ctx->Transform._ClipUserPlane[p][3];
+        if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
+            const GLfloat a = ctx->Transform._ClipUserPlane[p][0];
+            const GLfloat b = ctx->Transform._ClipUserPlane[p][1];
+            const GLfloat c = ctx->Transform._ClipUserPlane[p][2];
+            const GLfloat d = ctx->Transform._ClipUserPlane[p][3];
            LINE_CLIP( CLIP_USER_BIT, a, b, c, d );
         }
       }
    }
 
    if ((ctx->_TriangleCaps & DD_FLATSHADE) && j != jj)
-      tnl->Driver.RenderCopyPV( ctx, jj, j );
+      tnl->Driver.Render.CopyPV( ctx, jj, j );
 
-   tnl->Driver.RenderClippedLine( ctx, ii, jj );
+   tnl->Driver.Render.ClippedLine( ctx, ii, jj );
 }
 
 
 /* Clip a triangle against the viewport and user clip planes.
  */
-static __inline void TAG(clip_tri)( GLcontext *ctx,
-                          GLuint v0, GLuint v1, GLuint v2,
-                          GLubyte mask )
+static INLINE void
+TAG(clip_tri)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLubyte mask )
 {
    TNLcontext *tnl = TNL_CONTEXT(ctx);
    struct vertex_buffer *VB = &tnl->vb;
-   interp_func interp = tnl->Driver.RenderInterp;
+   tnl_interp_func interp = tnl->Driver.Render.Interp;
    GLfloat (*coord)[4] = VB->ClipPtr->data;
-   GLuint pv = v0;
+   GLuint pv = v2;
    GLuint vlist[2][MAX_CLIPPED_VERTICES];
    GLuint *inlist = vlist[0], *outlist = vlist[1];
    GLuint p;
    GLubyte *clipmask = VB->ClipMask;
    GLuint n = 3;
 
-   ASSIGN_3V(inlist, v0, v1, v2 );
+   ASSIGN_3V(inlist, v2, v0, v1 ); /* pv rotated to slot zero */
 
-   VB->LastClipped = VB->FirstClipped;
+   VB->LastClipped = VB->Count;
 
    if (mask & 0x3f) {
       POLY_CLIP( CLIP_RIGHT_BIT,  -1,  0,  0, 1 );
@@ -190,47 +187,47 @@ static __inline void TAG(clip_tri)( GLcontext *ctx,
 
    if (mask & CLIP_USER_BIT) {
       for (p=0;p<MAX_CLIP_PLANES;p++) {
-        if (ctx->Transform.ClipEnabled[p]) {
-           GLfloat a = ctx->Transform._ClipUserPlane[p][0];
-           GLfloat b = ctx->Transform._ClipUserPlane[p][1];
-           GLfloat c = ctx->Transform._ClipUserPlane[p][2];
-           GLfloat d = ctx->Transform._ClipUserPlane[p][3];
-           POLY_CLIP( CLIP_USER_BIT, a, b, c, d );
-        }
+         if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
+            const GLfloat a = ctx->Transform._ClipUserPlane[p][0];
+            const GLfloat b = ctx->Transform._ClipUserPlane[p][1];
+            const GLfloat c = ctx->Transform._ClipUserPlane[p][2];
+            const GLfloat d = ctx->Transform._ClipUserPlane[p][3];
+            POLY_CLIP( CLIP_USER_BIT, a, b, c, d );
+         }
       }
    }
 
    if (ctx->_TriangleCaps & DD_FLATSHADE) {
       if (pv != inlist[0]) {
-        ASSERT( inlist[0] >= VB->FirstClipped );
-        tnl->Driver.RenderCopyPV( ctx, inlist[0], pv );
+        ASSERT( inlist[0] >= VB->Count );
+        tnl->Driver.Render.CopyPV( ctx, inlist[0], pv );
       }
    }
 
-   tnl->Driver.RenderClippedPolygon( ctx, inlist, n );
+   tnl->Driver.Render.ClippedPolygon( ctx, inlist, n );
 }
 
 
 /* Clip a quad against the viewport and user clip planes.
  */
-static __inline void TAG(clip_quad)( GLcontext *ctx,
-                                    GLuint v0, GLuint v1, GLuint v2, GLuint v3,
-                                    GLubyte mask )
+static INLINE void
+TAG(clip_quad)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3,
+                GLubyte mask )
 {
    TNLcontext *tnl = TNL_CONTEXT(ctx);
    struct vertex_buffer *VB = &tnl->vb;
-   interp_func interp = tnl->Driver.RenderInterp;
+   tnl_interp_func interp = tnl->Driver.Render.Interp;
    GLfloat (*coord)[4] = VB->ClipPtr->data;
-   GLuint pv = v0;
+   GLuint pv = v3;
    GLuint vlist[2][MAX_CLIPPED_VERTICES];
    GLuint *inlist = vlist[0], *outlist = vlist[1];
    GLuint p;
    GLubyte *clipmask = VB->ClipMask;
    GLuint n = 4;
 
-   ASSIGN_4V(inlist, v0, v1, v2, v3 );
+   ASSIGN_4V(inlist, v3, v0, v1, v2 ); /* pv rotated to slot zero */
 
-   VB->LastClipped = VB->FirstClipped;
+   VB->LastClipped = VB->Count;
 
    if (mask & 0x3f) {
       POLY_CLIP( CLIP_RIGHT_BIT,  -1,  0,  0, 1 );
@@ -243,11 +240,11 @@ static __inline void TAG(clip_quad)( GLcontext *ctx,
 
    if (mask & CLIP_USER_BIT) {
       for (p=0;p<MAX_CLIP_PLANES;p++) {
-        if (ctx->Transform.ClipEnabled[p]) {
-           GLfloat a = ctx->Transform._ClipUserPlane[p][0];
-           GLfloat b = ctx->Transform._ClipUserPlane[p][1];
-           GLfloat c = ctx->Transform._ClipUserPlane[p][2];
-           GLfloat d = ctx->Transform._ClipUserPlane[p][3];
+        if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
+            const GLfloat a = ctx->Transform._ClipUserPlane[p][0];
+            const GLfloat b = ctx->Transform._ClipUserPlane[p][1];
+            const GLfloat c = ctx->Transform._ClipUserPlane[p][2];
+            const GLfloat d = ctx->Transform._ClipUserPlane[p][3];
            POLY_CLIP( CLIP_USER_BIT, a, b, c, d );
         }
       }
@@ -255,12 +252,12 @@ static __inline void TAG(clip_quad)( GLcontext *ctx,
 
    if (ctx->_TriangleCaps & DD_FLATSHADE) {
       if (pv != inlist[0]) {
-        ASSERT( inlist[0] >= VB->FirstClipped );
-        tnl->Driver.RenderCopyPV( ctx, inlist[0], pv );
+        ASSERT( inlist[0] >= VB->Count );
+        tnl->Driver.Render.CopyPV( ctx, inlist[0], pv );
       }
    }
 
-   tnl->Driver.RenderClippedPolygon( ctx, inlist, n );
+   tnl->Driver.Render.ClippedPolygon( ctx, inlist, n );
 }
 
 #undef W