~ubuntu-branches/ubuntu/precise/mesa/precise-updates

« back to all changes in this revision

Viewing changes to src/mesa/main/ffvertex_prog.c

  • Committer: Package Import Robot
  • Author(s): Robert Hooker
  • Date: 2012-02-02 12:05:48 UTC
  • mfrom: (1.7.1) (3.3.27 sid)
  • Revision ID: package-import@ubuntu.com-20120202120548-nvkma85jq0h4coix
Tags: 8.0~rc2-0ubuntu4
Drop drisearchdir handling, it is no longer needed with multiarch
and dri-alternates being removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
   unsigned rescale_normals:1;
62
62
 
63
63
   unsigned fog_source_is_depth:1;
 
64
   unsigned fog_distance_mode:2;
64
65
   unsigned separate_specular:1;
65
66
   unsigned point_attenuated:1;
66
67
   unsigned point_array:1;
67
68
   unsigned texture_enabled_global:1;
68
69
   unsigned fragprog_inputs_read:12;
69
70
 
70
 
   unsigned varying_vp_inputs;
 
71
   GLbitfield64 varying_vp_inputs;
71
72
 
72
73
   struct {
73
74
      unsigned light_enabled:1;
108
109
   }
109
110
}
110
111
 
 
112
#define FDM_EYE_RADIAL    0
 
113
#define FDM_EYE_PLANE     1
 
114
#define FDM_EYE_PLANE_ABS 2
111
115
 
 
116
static GLuint translate_fog_distance_mode( GLenum mode )
 
117
{
 
118
   switch (mode) {
 
119
   case GL_EYE_RADIAL_NV:
 
120
      return FDM_EYE_RADIAL;
 
121
   case GL_EYE_PLANE:
 
122
      return FDM_EYE_PLANE;
 
123
   default: /* shouldn't happen; fall through to a sensible default */
 
124
   case GL_EYE_PLANE_ABSOLUTE_NV:
 
125
      return FDM_EYE_PLANE_ABS;
 
126
   }
 
127
}
112
128
 
113
129
static GLboolean check_active_shininess( struct gl_context *ctx,
114
130
                                         const struct state_key *key,
115
131
                                         GLuint side )
116
132
{
117
 
   GLuint bit = 1 << (MAT_ATTRIB_FRONT_SHININESS + side);
 
133
   GLuint attr = MAT_ATTRIB_FRONT_SHININESS + side;
118
134
 
119
135
   if ((key->varying_vp_inputs & VERT_BIT_COLOR0) &&
120
 
       (key->light_color_material_mask & bit))
121
 
      return GL_TRUE;
122
 
 
123
 
   if (key->varying_vp_inputs & (bit << 16))
124
 
      return GL_TRUE;
125
 
 
126
 
   if (ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS + side][0] != 0.0F)
 
136
       (key->light_color_material_mask & (1 << attr)))
 
137
      return GL_TRUE;
 
138
 
 
139
   if (key->varying_vp_inputs & VERT_ATTRIB_GENERIC(attr))
 
140
      return GL_TRUE;
 
141
 
 
142
   if (ctx->Light.Material.Attrib[attr][0] != 0.0F)
127
143
      return GL_TRUE;
128
144
 
129
145
   return GL_FALSE;
205
221
   if (ctx->Transform.RescaleNormals)
206
222
      key->rescale_normals = 1;
207
223
 
208
 
   if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT)
 
224
   if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT) {
209
225
      key->fog_source_is_depth = 1;
 
226
      key->fog_distance_mode = translate_fog_distance_mode(ctx->Fog.FogDistanceMode);
 
227
   }
210
228
 
211
229
   if (ctx->Point._Attenuated)
212
230
      key->point_attenuated = 1;
213
231
 
214
232
#if FEATURE_point_size_array
215
 
   if (ctx->Array.ArrayObj->PointSize.Enabled)
 
233
   if (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled)
216
234
      key->point_array = 1;
217
235
#endif
218
236
 
427
445
 */
428
446
static struct ureg register_input( struct tnl_program *p, GLuint input )
429
447
{
430
 
   assert(input < 32);
 
448
   assert(input < VERT_ATTRIB_MAX);
431
449
 
432
 
   if (p->state->varying_vp_inputs & (1<<input)) {
433
 
      p->program->Base.InputsRead |= (1<<input);
 
450
   if (p->state->varying_vp_inputs & VERT_BIT(input)) {
 
451
      p->program->Base.InputsRead |= VERT_BIT(input);
434
452
      return make_ureg(PROGRAM_INPUT, input);
435
453
   }
436
454
   else {
455
473
                              GLfloat s2,
456
474
                              GLfloat s3)
457
475
{
458
 
   GLfloat values[4];
 
476
   gl_constant_value values[4];
459
477
   GLint idx;
460
478
   GLuint swizzle;
461
 
   values[0] = s0;
462
 
   values[1] = s1;
463
 
   values[2] = s2;
464
 
   values[3] = s3;
 
479
   values[0].f = s0;
 
480
   values[1].f = s1;
 
481
   values[2].f = s2;
 
482
   values[3].f = s3;
465
483
   idx = _mesa_add_unnamed_constant( p->program->Base.Parameters, values, 4,
466
484
                                     &swizzle );
467
485
   ASSERT(swizzle == SWIZZLE_NOOP);
853
871
         p->color_materials = p->state->light_color_material_mask;
854
872
   }
855
873
 
856
 
   p->materials |= (p->state->varying_vp_inputs >> 16);
 
874
   p->materials |= (p->state->varying_vp_inputs >> VERT_ATTRIB_GENERIC0);
857
875
}
858
876
 
859
877
 
931
949
{
932
950
   struct ureg attenuation = register_param3(p, STATE_LIGHT, i,
933
951
                                             STATE_ATTENUATION);
934
 
   struct ureg att = get_temp(p);
 
952
   struct ureg att = undef;
935
953
 
936
954
   /* Calculate spot attenuation:
937
955
    */
941
959
      struct ureg spot = get_temp(p);
942
960
      struct ureg slt = get_temp(p);
943
961
 
 
962
      att = get_temp(p);
 
963
 
944
964
      emit_op2(p, OPCODE_DP3, spot, 0, negate(VPpli), spot_dir_norm);
945
965
      emit_op2(p, OPCODE_SLT, slt, 0, swizzle1(spot_dir_norm,W), spot);
946
966
      emit_op2(p, OPCODE_POW, spot, 0, spot, swizzle1(attenuation, W));
950
970
      release_temp(p, slt);
951
971
   }
952
972
 
953
 
   /* Calculate distance attenuation:
 
973
   /* Calculate distance attenuation(See formula (2.4) at glspec 2.1 page 62):
 
974
    *
 
975
    * Skip the calucation when _dist_ is undefined(light_eyepos3_is_zero)
954
976
    */
955
 
   if (p->state->unit[i].light_attenuated) {
 
977
   if (p->state->unit[i].light_attenuated && !is_undef(dist)) {
 
978
      if (is_undef(att))
 
979
         att = get_temp(p);
956
980
      /* 1/d,d,d,1/d */
957
981
      emit_op1(p, OPCODE_RCP, dist, WRITEMASK_YZ, dist);
958
982
      /* 1,d,d*d,1/d */
1095
1119
      if (p->state->unit[i].light_enabled) {
1096
1120
         struct ureg half = undef;
1097
1121
         struct ureg att = undef, VPpli = undef;
 
1122
         struct ureg dist = undef;
1098
1123
 
1099
1124
         count++;
1100
 
 
1101
 
         if (p->state->unit[i].light_eyepos3_is_zero) {
1102
 
            /* Can used precomputed constants in this case.
1103
 
             * Attenuation never applies to infinite lights.
1104
 
             */
1105
 
            VPpli = register_param3(p, STATE_INTERNAL,
1106
 
                                    STATE_LIGHT_POSITION_NORMALIZED, i);
1107
 
 
1108
 
            if (!p->state->material_shininess_is_zero) {
1109
 
               if (p->state->light_local_viewer) {
1110
 
                  struct ureg eye_hat = get_eye_position_normalized(p);
1111
 
                  half = get_temp(p);
1112
 
                  emit_op2(p, OPCODE_SUB, half, 0, VPpli, eye_hat);
1113
 
                  emit_normalize_vec3(p, half, half);
1114
 
               }
1115
 
               else {
1116
 
                  half = register_param3(p, STATE_INTERNAL,
1117
 
                                         STATE_LIGHT_HALF_VECTOR, i);
1118
 
               }
1119
 
            }
1120
 
         }
1121
 
         else {
1122
 
            struct ureg Ppli = register_param3(p, STATE_INTERNAL,
1123
 
                                               STATE_LIGHT_POSITION, i);
1124
 
            struct ureg V = get_eye_position(p);
1125
 
            struct ureg dist = get_temp(p);
1126
 
 
1127
 
            VPpli = get_temp(p);
1128
 
 
1129
 
            /* Calculate VPpli vector
1130
 
             */
1131
 
            emit_op2(p, OPCODE_SUB, VPpli, 0, Ppli, V);
1132
 
 
1133
 
            /* Normalize VPpli.  The dist value also used in
1134
 
             * attenuation below.
1135
 
             */
1136
 
            emit_op2(p, OPCODE_DP3, dist, 0, VPpli, VPpli);
1137
 
            emit_op1(p, OPCODE_RSQ, dist, 0, dist);
1138
 
            emit_op2(p, OPCODE_MUL, VPpli, 0, VPpli, dist);
1139
 
 
1140
 
            /* Calculate attenuation:
1141
 
             */
1142
 
            if (!p->state->unit[i].light_spotcutoff_is_180 ||
1143
 
                p->state->unit[i].light_attenuated) {
1144
 
               att = calculate_light_attenuation(p, i, VPpli, dist);
1145
 
            }
1146
 
 
1147
 
            /* Calculate viewer direction, or use infinite viewer:
1148
 
             */
1149
 
            if (!p->state->material_shininess_is_zero) {
1150
 
               half = get_temp(p);
1151
 
 
1152
 
               if (p->state->light_local_viewer) {
1153
 
                  struct ureg eye_hat = get_eye_position_normalized(p);
1154
 
                  emit_op2(p, OPCODE_SUB, half, 0, VPpli, eye_hat);
1155
 
               }
1156
 
               else {
1157
 
                  struct ureg z_dir = swizzle(get_identity_param(p),X,Y,W,Z);
1158
 
                  emit_op2(p, OPCODE_ADD, half, 0, VPpli, z_dir);
1159
 
               }
1160
 
 
1161
 
               emit_normalize_vec3(p, half, half);
1162
 
            }
1163
 
 
1164
 
            release_temp(p, dist);
 
1125
         if (p->state->unit[i].light_eyepos3_is_zero) {
 
1126
             VPpli = register_param3(p, STATE_INTERNAL,
 
1127
                                     STATE_LIGHT_POSITION_NORMALIZED, i);
 
1128
         } else {
 
1129
            struct ureg Ppli = register_param3(p, STATE_INTERNAL,
 
1130
                                               STATE_LIGHT_POSITION, i);
 
1131
            struct ureg V = get_eye_position(p);
 
1132
 
 
1133
            VPpli = get_temp(p);
 
1134
            dist = get_temp(p);
 
1135
 
 
1136
            /* Calculate VPpli vector
 
1137
             */
 
1138
            emit_op2(p, OPCODE_SUB, VPpli, 0, Ppli, V);
 
1139
 
 
1140
            /* Normalize VPpli.  The dist value also used in
 
1141
             * attenuation below.
 
1142
             */
 
1143
            emit_op2(p, OPCODE_DP3, dist, 0, VPpli, VPpli);
 
1144
            emit_op1(p, OPCODE_RSQ, dist, 0, dist);
 
1145
            emit_op2(p, OPCODE_MUL, VPpli, 0, VPpli, dist);
 
1146
         }
 
1147
 
 
1148
         /* Calculate attenuation:
 
1149
          */
 
1150
         att = calculate_light_attenuation(p, i, VPpli, dist);
 
1151
         release_temp(p, dist);
 
1152
 
 
1153
         /* Calculate viewer direction, or use infinite viewer:
 
1154
          */
 
1155
         if (!p->state->material_shininess_is_zero) {
 
1156
            if (p->state->light_local_viewer) {
 
1157
               struct ureg eye_hat = get_eye_position_normalized(p);
 
1158
               half = get_temp(p);
 
1159
               emit_op2(p, OPCODE_SUB, half, 0, VPpli, eye_hat);
 
1160
               emit_normalize_vec3(p, half, half);
 
1161
            } else if (p->state->unit[i].light_eyepos3_is_zero) {
 
1162
               half = register_param3(p, STATE_INTERNAL,
 
1163
                                      STATE_LIGHT_HALF_VECTOR, i);
 
1164
            } else {
 
1165
               struct ureg z_dir = swizzle(get_identity_param(p),X,Y,W,Z);
 
1166
               half = get_temp(p);
 
1167
               emit_op2(p, OPCODE_ADD, half, 0, VPpli, z_dir);
 
1168
               emit_normalize_vec3(p, half, half);
 
1169
            }
1165
1170
         }
1166
1171
 
1167
1172
         /* Calculate dot products:
1308
1313
   struct ureg input;
1309
1314
 
1310
1315
   if (p->state->fog_source_is_depth) {
1311
 
      input = get_eye_position_z(p);
 
1316
 
 
1317
      switch (p->state->fog_distance_mode) {
 
1318
      case FDM_EYE_RADIAL: /* Z = sqrt(Xe*Xe + Ye*Ye + Ze*Ze) */
 
1319
        input = get_eye_position(p);
 
1320
        emit_op2(p, OPCODE_DP3, fog, WRITEMASK_X, input, input);
 
1321
        emit_op1(p, OPCODE_RSQ, fog, WRITEMASK_X, fog);
 
1322
        emit_op1(p, OPCODE_RCP, fog, WRITEMASK_X, fog);
 
1323
        break;
 
1324
      case FDM_EYE_PLANE: /* Z = Ze */
 
1325
        input = get_eye_position_z(p);
 
1326
        emit_op1(p, OPCODE_MOV, fog, WRITEMASK_X, input);
 
1327
        break;
 
1328
      case FDM_EYE_PLANE_ABS: /* Z = abs(Ze) */
 
1329
        input = get_eye_position_z(p);
 
1330
        emit_op1(p, OPCODE_ABS, fog, WRITEMASK_X, input);
 
1331
        break;
 
1332
      default: assert(0); break; /* can't happen */
 
1333
      }
 
1334
 
1312
1335
   }
1313
1336
   else {
1314
1337
      input = swizzle1(register_input(p, VERT_ATTRIB_FOG), X);
 
1338
      emit_op1(p, OPCODE_ABS, fog, WRITEMASK_X, input);
1315
1339
   }
1316
1340
 
1317
 
   /* result.fog = {abs(f),0,0,1}; */
1318
 
   emit_op1(p, OPCODE_ABS, fog, WRITEMASK_X, input);
1319
1341
   emit_op1(p, OPCODE_MOV, fog, WRITEMASK_YZW, get_identity_param(p));
1320
1342
}
1321
1343