glsl: fix memory leak
[mesa.git] / src / mesa / tnl / t_vb_program.c
index f99401ca6d870f09657ae26c72d4afb82fe7ce1b..dc954bcba148046f89f553360d30c411d677701c 100644 (file)
@@ -1,8 +1,9 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.1
+ * Version:  7.6
  *
- * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
+ * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
 #include "tnl/t_pipeline.h"
 
 
+#ifdef NAN_CHECK
+/** Check for NaNs and very large values */
+static INLINE void
+check_float(float x)
+{
+   assert(!IS_INF_OR_NAN(x));
+   assert(1.0e-15 <= x && x <= 1.0e15);
+}
+#endif
+
 
 /*!
  * Private storage for the vertex program pipeline stage.
@@ -176,17 +187,12 @@ static void
 vp_fetch_texel(GLcontext *ctx, const GLfloat texcoord[4], GLfloat lambda,
                GLuint unit, GLfloat color[4])
 {
-   GLchan rgba[4];
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
 
    /* XXX use a float-valued TextureSample routine here!!! */
    swrast->TextureSample[unit](ctx, ctx->Texture.Unit[unit]._Current,
                                1, (const GLfloat (*)[4]) texcoord,
-                               &lambda, &rgba);
-   color[0] = CHAN_TO_FLOAT(rgba[0]);
-   color[1] = CHAN_TO_FLOAT(rgba[1]);
-   color[2] = CHAN_TO_FLOAT(rgba[2]);
-   color[3] = CHAN_TO_FLOAT(rgba[3]);
+                               &lambda,  (GLfloat (*)[4]) color);
 }
 
 
@@ -212,7 +218,7 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine)
 {
    /* Input registers get initialized from the current vertex attribs */
    MEMCPY(machine->VertAttribs, ctx->Current.Attrib,
-          MAX_VERTEX_PROGRAM_ATTRIBS * 4 * sizeof(GLfloat));
+          MAX_VERTEX_GENERIC_ATTRIBS * 4 * sizeof(GLfloat));
 
    if (ctx->VertexProgram._Current->IsNVProgram) {
       GLuint i;
@@ -356,6 +362,12 @@ run_vp( GLcontext *ctx, struct tnl_pipeline_stage *stage )
            const GLuint size = VB->AttribPtr[attr]->size;
            const GLuint stride = VB->AttribPtr[attr]->stride;
            const GLfloat *data = (GLfloat *) (ptr + stride * i);
+#ifdef NAN_CHECK
+            check_float(data[0]);
+            check_float(data[1]);
+            check_float(data[2]);
+            check_float(data[3]);
+#endif
            COPY_CLEAN_4V(machine.VertAttribs[attr], size, data);
         }
       }
@@ -366,8 +378,17 @@ run_vp( GLcontext *ctx, struct tnl_pipeline_stage *stage )
       /* copy the output registers into the VB->attribs arrays */
       for (j = 0; j < numOutputs; j++) {
          const GLuint attr = outputs[j];
+#ifdef NAN_CHECK
+         check_float(machine.Outputs[attr][0]);
+         check_float(machine.Outputs[attr][1]);
+         check_float(machine.Outputs[attr][2]);
+         check_float(machine.Outputs[attr][3]);
+#endif
          COPY_4V(store->results[attr].data[i], machine.Outputs[attr]);
       }
+#ifdef NAN_CHECK
+      ASSERT(machine.Outputs[0][3] != 0.0F);
+#endif
 #if 0
       printf("HPOS: %f %f %f %f\n",
              machine.Outputs[0][0],