fixes for C++ warnings/errors
[mesa.git] / src / mesa / tnl / t_vb_arbprogram.c
index 6c5cfb09e00f4050e7d859b5c8599d15910d8a77..524472a7772d27fee17a622f5063e3cc5026401d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
+ * Version:  6.5.1
  *
  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
@@ -108,11 +108,6 @@ static GLfloat ApproxPower(GLfloat x, GLfloat y)
    return (GLfloat) _mesa_pow(x, y);
 }
 
-static GLfloat rough_approx_log2_0_1(GLfloat x)
-{
-   return LOG2(x);
-}
-
 
 /**
  * Perform a reduced swizzle:
@@ -121,8 +116,8 @@ static void do_RSW( struct arb_vp_machine *m, union instruction op )
 {
    GLfloat *result = m->File[0][op.rsw.dst];
    const GLfloat *arg0 = m->File[op.rsw.file0][op.rsw.idx0];
-   GLuint swz = op.rsw.swz;
-   GLuint neg = op.rsw.neg;
+   const GLuint swz = op.rsw.swz;
+   const GLuint neg = op.rsw.neg;
    GLfloat tmp[4];
 
    /* Need a temporary to be correct in the case where result == arg0.
@@ -149,8 +144,8 @@ static void do_SWZ( struct arb_vp_machine *m, union instruction op )
 {
    GLfloat *result = m->File[0][op.rsw.dst];
    const GLfloat *arg0 = m->File[op.rsw.file0][op.rsw.idx0];
-   GLuint swz = op.rsw.swz;
-   GLuint neg = op.rsw.neg;
+   const GLuint swz = op.rsw.swz;
+   const GLuint neg = op.rsw.neg;
    GLfloat tmp[6];
    tmp[4] = 0.0;
    tmp[5] = 1.0;
@@ -187,10 +182,10 @@ static void do_MSK( struct arb_vp_machine *m, union instruction op )
    GLfloat *dst = m->File[0][op.msk.dst];
    const GLfloat *arg = m->File[op.msk.file][op.msk.idx];
  
-   if (op.msk.mask & 0x1) dst[0] = arg[0];
-   if (op.msk.mask & 0x2) dst[1] = arg[1];
-   if (op.msk.mask & 0x4) dst[2] = arg[2];
-   if (op.msk.mask & 0x8) dst[3] = arg[3];
+   if (op.msk.mask & WRITEMASK_X) dst[0] = arg[0];
+   if (op.msk.mask & WRITEMASK_Y) dst[1] = arg[1];
+   if (op.msk.mask & WRITEMASK_Z) dst[2] = arg[2];
+   if (op.msk.mask & WRITEMASK_W) dst[3] = arg[3];
 }
 
 
@@ -308,13 +303,13 @@ static void do_EXP( struct arb_vp_machine *m, union instruction op )
 {
    GLfloat *result = m->File[0][op.alu.dst];
    const GLfloat *arg0 = m->File[op.alu.file0][op.alu.idx0];
-   GLfloat tmp = arg0[0];
-   GLfloat flr_tmp = FLOORF(tmp);
-   GLfloat frac_tmp = tmp - flr_tmp;
+   const GLfloat tmp = arg0[0];
+   const GLfloat flr_tmp = FLOORF(tmp);
+   const GLfloat frac_tmp = tmp - flr_tmp;
 
    result[0] = LDEXPF(1.0, (int)flr_tmp);
    result[1] = frac_tmp;
-   result[2] = LDEXPF(rough_approx_log2_0_1(frac_tmp), (int)flr_tmp);
+   result[2] = RoughApproxExp2(tmp);
    result[3] = 1.0F;
 }
 
@@ -357,7 +352,7 @@ static void do_LIT( struct arb_vp_machine *m, union instruction op )
 {
    GLfloat *result = m->File[0][op.alu.dst];
    const GLfloat *arg0 = m->File[op.alu.file0][op.alu.idx0];
-   GLfloat tmp[4];
+   GLfloat tmp[4]; /* use temp in case arg0 == result register */
 
    tmp[0] = 1.0;
    tmp[1] = arg0[0];
@@ -369,7 +364,6 @@ static void do_LIT( struct arb_vp_machine *m, union instruction op )
    }
    tmp[3] = 1.0;
 
-
    COPY_4V(result, tmp);
 }
 
@@ -380,9 +374,9 @@ static void do_LOG( struct arb_vp_machine *m, union instruction op )
 {
    GLfloat *result = m->File[0][op.alu.dst];
    const GLfloat *arg0 = m->File[op.alu.file0][op.alu.idx0];
-   GLfloat tmp = FABSF(arg0[0]);
+   const GLfloat tmp = FABSF(arg0[0]);
    int exponent;
-   GLfloat mantissa = FREXPF(tmp, &exponent);
+   const GLfloat mantissa = FREXPF(tmp, &exponent);
 
    result[0] = (GLfloat) (exponent - 1);
    result[1] = 2.0 * mantissa; /* map [.5, 1) -> [1, 2) */
@@ -454,7 +448,7 @@ static void do_POW( struct arb_vp_machine *m, union instruction op )
 static void do_REL( struct arb_vp_machine *m, union instruction op )
 {
    GLfloat *result = m->File[0][op.alu.dst];
-   GLuint idx = (op.alu.idx0 + (GLint)m->File[0][REG_ADDR][0]) & (MAX_NV_VERTEX_PROGRAM_PARAMS-1);
+   const GLuint idx = (op.alu.idx0 + (GLint)m->File[0][REG_ADDR][0]) & (MAX_NV_VERTEX_PROGRAM_PARAMS-1);
    const GLfloat *arg0 = m->File[op.alu.file0][idx];
 
    result[0] = arg0[0];
@@ -548,10 +542,10 @@ static void do_NOP( struct arb_vp_machine *m, union instruction op )
 static void print_mask( GLuint mask )
 {
    _mesa_printf(".");
-   if (mask&0x1) _mesa_printf("x");
-   if (mask&0x2) _mesa_printf("y");
-   if (mask&0x4) _mesa_printf("z");
-   if (mask&0x8) _mesa_printf("w");
+   if (mask & WRITEMASK_X) _mesa_printf("x");
+   if (mask & WRITEMASK_Y) _mesa_printf("y");
+   if (mask & WRITEMASK_Z) _mesa_printf("z");
+   if (mask & WRITEMASK_W) _mesa_printf("w");
 }
 
 static void print_reg( GLuint file, GLuint reg )
@@ -1048,7 +1042,7 @@ static void cvp_emit_inst( struct compilation *cp,
    }
 }
 
-static void free_tnl_data( struct vertex_program *program  )
+static void free_tnl_data( struct gl_vertex_program *program  )
 {
    struct tnl_compiled_program *p = (struct tnl_compiled_program *) program->TnlData;
    if (p->compiled_func)
@@ -1057,12 +1051,12 @@ static void free_tnl_data( struct vertex_program *program  )
    program->TnlData = NULL;
 }
 
-static void compile_vertex_program( struct vertex_program *program,
+static void compile_vertex_program( struct gl_vertex_program *program,
                                    GLboolean try_codegen )
 { 
    struct compilation cp;
    struct tnl_compiled_program *p = CALLOC_STRUCT(tnl_compiled_program);
-   GLuint i;
+   GLint i;
 
    if (program->TnlData) 
       free_tnl_data( program );
@@ -1188,7 +1182,8 @@ do_ndc_cliptest(GLcontext *ctx, struct arb_vp_machine *m)
 
    /* Test userclip planes.  This contributes to VB->ClipMask.
     */
-   if (ctx->Transform.ClipPlanesEnabled && !ctx->VertexProgram._Enabled) {
+   if (ctx->Transform.ClipPlanesEnabled && (!ctx->VertexProgram._Enabled ||
+      ctx->VertexProgram.Current->IsPositionInvariant)) {
       userclip( ctx,
                VB->ClipPtr,
                m->clipmask,
@@ -1226,7 +1221,7 @@ static INLINE void call_func( struct tnl_compiled_program *p,
 static GLboolean
 run_arb_vertex_program(GLcontext *ctx, struct tnl_pipeline_stage *stage)
 {
-   const struct vertex_program *program;
+   const struct gl_vertex_program *program;
    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
    struct arb_vp_machine *m = ARB_VP_MACHINE(stage);
    struct tnl_compiled_program *p;
@@ -1253,7 +1248,7 @@ run_arb_vertex_program(GLcontext *ctx, struct tnl_pipeline_stage *stage)
 
    m->nr_inputs = m->nr_outputs = 0;
 
-   for (i = 0; i < _TNL_ATTRIB_MAX; i++) {
+   for (i = 0; i < VERT_ATTRIB_MAX; i++) {
       if (program->Base.InputsRead & (1<<i) ||
          (i == VERT_ATTRIB_POS && program->IsPositionInvariant)) {
         GLuint j = m->nr_inputs++;
@@ -1295,6 +1290,7 @@ run_arb_vertex_program(GLcontext *ctx, struct tnl_pipeline_stage *stage)
         call_func( p, m );
       }
       else {
+         GLint j;
         for (j = 0; j < p->nr_instructions; j++) {
            union instruction inst = p->instructions[j];         
            opcode_func[inst.alu.opcode]( m, inst );
@@ -1334,13 +1330,16 @@ run_arb_vertex_program(GLcontext *ctx, struct tnl_pipeline_stage *stage)
    VB->ClipPtr = &m->attribs[VERT_RESULT_HPOS];
    VB->ClipPtr->count = VB->Count;
 
+   /* XXX There seems to be confusion between using the VERT_ATTRIB_*
+    * values vs _TNL_ATTRIB_* tokens here:
+    */
    outputs = program->Base.OutputsWritten;
    if (program->IsPositionInvariant) 
       outputs |= (1<<VERT_RESULT_HPOS);
 
    if (outputs & (1<<VERT_RESULT_COL0)) {
-      VB->ColorPtr[0] = &m->attribs[VERT_RESULT_COL0];
-      VB->AttribPtr[VERT_ATTRIB_COLOR0] = VB->ColorPtr[0];
+      VB->ColorPtr[0] =
+      VB->AttribPtr[VERT_ATTRIB_COLOR0] = &m->attribs[VERT_RESULT_COL0];
    }
 
    if (outputs & (1<<VERT_RESULT_BFC0)) {
@@ -1348,8 +1347,8 @@ run_arb_vertex_program(GLcontext *ctx, struct tnl_pipeline_stage *stage)
    }
 
    if (outputs & (1<<VERT_RESULT_COL1)) {
-      VB->SecondaryColorPtr[0] = &m->attribs[VERT_RESULT_COL1];
-      VB->AttribPtr[VERT_ATTRIB_COLOR1] = VB->SecondaryColorPtr[0];
+      VB->SecondaryColorPtr[0] =
+      VB->AttribPtr[VERT_ATTRIB_COLOR1] = &m->attribs[VERT_RESULT_COL1];
    }
 
    if (outputs & (1<<VERT_RESULT_BFC1)) {
@@ -1357,19 +1356,18 @@ run_arb_vertex_program(GLcontext *ctx, struct tnl_pipeline_stage *stage)
    }
 
    if (outputs & (1<<VERT_RESULT_FOGC)) {
-      VB->FogCoordPtr = &m->attribs[VERT_RESULT_FOGC];
-      VB->AttribPtr[VERT_ATTRIB_FOG] = VB->FogCoordPtr;
+      VB->FogCoordPtr =
+      VB->AttribPtr[VERT_ATTRIB_FOG] = &m->attribs[VERT_RESULT_FOGC];
    }
 
    if (outputs & (1<<VERT_RESULT_PSIZ)) {
-      VB->PointSizePtr = &m->attribs[VERT_RESULT_PSIZ];
       VB->AttribPtr[_TNL_ATTRIB_POINTSIZE] = &m->attribs[VERT_RESULT_PSIZ];
    }
 
    for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
       if (outputs & (1<<(VERT_RESULT_TEX0+i))) {
-        VB->TexCoordPtr[i] = &m->attribs[VERT_RESULT_TEX0 + i];
-        VB->AttribPtr[VERT_ATTRIB_TEX0+i] = VB->TexCoordPtr[i];
+        VB->TexCoordPtr[i] =
+        VB->AttribPtr[VERT_ATTRIB_TEX0+i] = &m->attribs[VERT_RESULT_TEX0 + i];
       }
    }
 
@@ -1380,10 +1378,10 @@ run_arb_vertex_program(GLcontext *ctx, struct tnl_pipeline_stage *stage)
             VEC_ELT(VB->ClipPtr, GLfloat, i)[1],
             VEC_ELT(VB->ClipPtr, GLfloat, i)[2],
             VEC_ELT(VB->ClipPtr, GLfloat, i)[3],
-            VEC_ELT(VB->TexCoordPtr[0], GLfloat, i)[0],
-            VEC_ELT(VB->TexCoordPtr[0], GLfloat, i)[1],
-            VEC_ELT(VB->TexCoordPtr[0], GLfloat, i)[2],
-            VEC_ELT(VB->TexCoordPtr[0], GLfloat, i)[3]);
+            VEC_ELT(VB->AttribPtr[VERT_ATTRIB_TEX0], GLfloat, i)[0],
+            VEC_ELT(VB->AttribPtr[VERT_ATTRIB_TEX0], GLfloat, i)[1],
+            VEC_ELT(VB->AttribPtr[VERT_ATTRIB_TEX0], GLfloat, i)[2],
+            VEC_ELT(VB->AttribPtr[VERT_ATTRIB_TEX0], GLfloat, i)[3]);
    }
 #endif
 
@@ -1397,7 +1395,7 @@ static void
 validate_vertex_program( GLcontext *ctx, struct tnl_pipeline_stage *stage )
 {
    struct arb_vp_machine *m = ARB_VP_MACHINE(stage);
-   struct vertex_program *program;
+   struct gl_vertex_program *program;
 
    if (ctx->ShaderObjects._VertexShaderPresent)
       return;
@@ -1530,11 +1528,11 @@ const struct tnl_pipeline_stage _tnl_arb_vertex_program_stage =
  * string has been parsed.
  */
 void
-_tnl_program_string(GLcontext *ctx, GLenum target, struct program *program)
+_tnl_program_string(GLcontext *ctx, GLenum target, struct gl_program *program)
 {
-   if (program->Target == GL_VERTEX_PROGRAM_ARB) {
+   if (target == GL_VERTEX_PROGRAM_ARB) {
       /* free any existing tnl data hanging off the program */
-      struct vertex_program *vprog = (struct vertex_program *) program;
+      struct gl_vertex_program *vprog = (struct gl_vertex_program *) program;
       if (vprog->TnlData) {
          free_tnl_data(vprog);
       }