~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
   AEarray arrays[32];
54
54
   AEattrib attribs[VERT_ATTRIB_MAX + 1];
55
55
   GLuint NewState;
 
56
 
 
57
   struct gl_buffer_object *vbo[VERT_ATTRIB_MAX];
 
58
   GLuint nr_vbos;
 
59
   GLboolean mapped_vbos;
 
60
 
56
61
} AEcontext;
57
62
 
58
63
#define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
1046
1051
   FogCoordFuncs[6] = _gloffset_FogCoordfvEXT;
1047
1052
   FogCoordFuncs[7] = _gloffset_FogCoorddvEXT;
1048
1053
 
1049
 
   ctx->aelt_context = MALLOC( sizeof(AEcontext) );
 
1054
   ctx->aelt_context = CALLOC( sizeof(AEcontext) );
1050
1055
   if (!ctx->aelt_context)
1051
1056
      return GL_FALSE;
1052
1057
 
1063
1068
   }
1064
1069
}
1065
1070
 
 
1071
static void check_vbo( AEcontext *actx,
 
1072
                       struct gl_buffer_object *vbo )
 
1073
{
 
1074
   if (vbo->Name && !vbo->Pointer) {
 
1075
      GLuint i;
 
1076
      for (i = 0; i < actx->nr_vbos; i++)
 
1077
         if (actx->vbo[i] == vbo)
 
1078
            return;
 
1079
      assert(actx->nr_vbos < VERT_ATTRIB_MAX);
 
1080
      actx->vbo[actx->nr_vbos++] = vbo;
 
1081
   }
 
1082
}
 
1083
 
1066
1084
 
1067
1085
/**
1068
1086
 * Make a list of per-vertex functions to call for each glArrayElement call.
1077
1095
   AEattrib *at = actx->attribs;
1078
1096
   GLuint i;
1079
1097
 
 
1098
   actx->nr_vbos = 0;
 
1099
 
1080
1100
   /* conventional vertex arrays */
1081
1101
  if (ctx->Array.ArrayObj->Index.Enabled) {
1082
1102
      aa->array = &ctx->Array.ArrayObj->Index;
1083
1103
      aa->offset = IndexFuncs[TYPE_IDX(aa->array->Type)];
 
1104
      check_vbo(actx, aa->array->BufferObj);
1084
1105
      aa++;
1085
1106
   }
1086
1107
   if (ctx->Array.ArrayObj->EdgeFlag.Enabled) {
1087
1108
      aa->array = &ctx->Array.ArrayObj->EdgeFlag;
1088
1109
      aa->offset = _gloffset_EdgeFlagv;
 
1110
      check_vbo(actx, aa->array->BufferObj);
1089
1111
      aa++;
1090
1112
   }
1091
1113
   if (ctx->Array.ArrayObj->Normal.Enabled) {
1092
1114
      aa->array = &ctx->Array.ArrayObj->Normal;
1093
1115
      aa->offset = NormalFuncs[TYPE_IDX(aa->array->Type)];
 
1116
      check_vbo(actx, aa->array->BufferObj);
1094
1117
      aa++;
1095
1118
   }
1096
1119
   if (ctx->Array.ArrayObj->Color.Enabled) {
1097
1120
      aa->array = &ctx->Array.ArrayObj->Color;
1098
1121
      aa->offset = ColorFuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
 
1122
      check_vbo(actx, aa->array->BufferObj);
1099
1123
      aa++;
1100
1124
   }
1101
1125
   if (ctx->Array.ArrayObj->SecondaryColor.Enabled) {
1102
1126
      aa->array = &ctx->Array.ArrayObj->SecondaryColor;
1103
1127
      aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Type)];
 
1128
      check_vbo(actx, aa->array->BufferObj);
1104
1129
      aa++;
1105
1130
   }
1106
1131
   if (ctx->Array.ArrayObj->FogCoord.Enabled) {
1107
1132
      aa->array = &ctx->Array.ArrayObj->FogCoord;
1108
1133
      aa->offset = FogCoordFuncs[TYPE_IDX(aa->array->Type)];
 
1134
      check_vbo(actx, aa->array->BufferObj);
1109
1135
      aa++;
1110
1136
   }
1111
1137
   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
1120
1146
                                 [at->array->Size-1]
1121
1147
                                 [TYPE_IDX(at->array->Type)];
1122
1148
         at->index = VERT_ATTRIB_TEX0 + i;
 
1149
         check_vbo(actx, at->array->BufferObj);
1123
1150
         at++;
1124
1151
      }
1125
1152
   }
1126
1153
 
1127
 
   /* generic vertex attribute arrays */
 
1154
   /* generic vertex attribute arrays */   
1128
1155
   for (i = 1; i < VERT_ATTRIB_MAX; i++) {  /* skip zero! */
1129
1156
      struct gl_client_array *attribArray = &ctx->Array.ArrayObj->VertexAttrib[i];
1130
1157
      if (attribArray->Enabled) {
1146
1173
                                     [TYPE_IDX(at->array->Type)];
1147
1174
         }
1148
1175
         at->index = i;
 
1176
         check_vbo(actx, at->array->BufferObj);
1149
1177
         at++;
1150
1178
      }
1151
1179
   }
1158
1186
      aa->array = &ctx->Array.ArrayObj->VertexAttrib[0];
1159
1187
      assert(aa->array->Size >= 2); /* XXX fix someday? */
1160
1188
      aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
 
1189
      check_vbo(actx, aa->array->BufferObj);
1161
1190
      aa++;
1162
1191
   }
1163
1192
   else if (ctx->Array.ArrayObj->Vertex.Enabled) {
1164
1193
      aa->array = &ctx->Array.ArrayObj->Vertex;
1165
1194
      aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
 
1195
      check_vbo(actx, aa->array->BufferObj);
1166
1196
      aa++;
1167
1197
   }
1168
1198
 
 
1199
   check_vbo(actx, ctx->Array.ElementArrayBufferObj);
 
1200
 
1169
1201
   ASSERT(at - actx->attribs <= VERT_ATTRIB_MAX);
1170
1202
   ASSERT(aa - actx->arrays < 32);
1171
1203
   at->func = NULL;  /* terminate the list */
1174
1206
   actx->NewState = 0;
1175
1207
}
1176
1208
 
 
1209
void _ae_map_vbos( GLcontext *ctx )
 
1210
{
 
1211
   AEcontext *actx = AE_CONTEXT(ctx);
 
1212
   GLuint i;
 
1213
   
 
1214
   if (actx->mapped_vbos)
 
1215
      return;
 
1216
 
 
1217
   if (actx->NewState)
 
1218
      _ae_update_state(ctx);
 
1219
 
 
1220
   for (i = 0; i < actx->nr_vbos; i++)
 
1221
      ctx->Driver.MapBuffer(ctx,
 
1222
                            GL_ARRAY_BUFFER_ARB,
 
1223
                            GL_DYNAMIC_DRAW_ARB,
 
1224
                            actx->vbo[i]);
 
1225
 
 
1226
   if (actx->nr_vbos)
 
1227
      actx->mapped_vbos = GL_TRUE;
 
1228
}
 
1229
 
 
1230
void _ae_unmap_vbos( GLcontext *ctx )
 
1231
{
 
1232
   AEcontext *actx = AE_CONTEXT(ctx);
 
1233
   GLuint i;
 
1234
 
 
1235
   if (!actx->mapped_vbos)
 
1236
      return;
 
1237
 
 
1238
   assert (!actx->NewState);
 
1239
 
 
1240
   for (i = 0; i < actx->nr_vbos; i++)
 
1241
      ctx->Driver.UnmapBuffer(ctx,
 
1242
                              GL_ARRAY_BUFFER_ARB,
 
1243
                              actx->vbo[i]);
 
1244
 
 
1245
   actx->mapped_vbos = GL_FALSE;
 
1246
}
 
1247
 
1177
1248
 
1178
1249
/**
1179
1250
 * Called via glArrayElement() and glDrawArrays().
1188
1259
   const AEarray *aa;
1189
1260
   const AEattrib *at;
1190
1261
   const struct _glapi_table * const disp = GET_DISPATCH();
1191
 
 
1192
 
 
1193
 
   if (actx->NewState)
 
1262
   GLboolean do_map;
 
1263
 
 
1264
   if (actx->NewState) {
 
1265
      assert(!actx->mapped_vbos);
1194
1266
      _ae_update_state( ctx );
1195
 
 
 
1267
   }
 
1268
 
 
1269
   do_map = actx->nr_vbos && !actx->mapped_vbos;
 
1270
 
 
1271
   /* 
 
1272
    */
 
1273
   if (do_map)
 
1274
      _ae_map_vbos(ctx);
 
1275
   
1196
1276
   /* generic attributes */
1197
1277
   for (at = actx->attribs; at->func; at++) {
1198
1278
      const GLubyte *src
1199
 
         = ADD_POINTERS(at->array->BufferObj->Data, at->array->Ptr)
 
1279
         = ADD_POINTERS(at->array->BufferObj->Pointer, at->array->Ptr)
1200
1280
         + elt * at->array->StrideB;
1201
1281
      at->func( at->index, src );
1202
1282
   }
1204
1284
   /* conventional arrays */
1205
1285
   for (aa = actx->arrays; aa->offset != -1 ; aa++) {
1206
1286
      const GLubyte *src
1207
 
         = ADD_POINTERS(aa->array->BufferObj->Data, aa->array->Ptr)
 
1287
         = ADD_POINTERS(aa->array->BufferObj->Pointer, aa->array->Ptr)
1208
1288
         + elt * aa->array->StrideB;
1209
1289
      CALL_by_offset( disp, (array_func), aa->offset, 
1210
1290
                      ((const void *) src) );
1211
1291
   }
 
1292
 
 
1293
   if (do_map)
 
1294
      _ae_unmap_vbos(ctx);
1212
1295
}
1213
1296
 
1214
1297
 
1215
1298
void _ae_invalidate_state( GLcontext *ctx, GLuint new_state )
1216
1299
{
1217
 
   AE_CONTEXT(ctx)->NewState |= new_state;
 
1300
   AEcontext *actx = AE_CONTEXT(ctx);
 
1301
 
 
1302
   
 
1303
   /* Only interested in this subset of mesa state.  Need to prune
 
1304
    * this down as both tnl/ and the drivers can raise statechanges
 
1305
    * for arcane reasons in the middle of seemingly atomic operations
 
1306
    * like DrawElements, over which we'd like to keep a known set of
 
1307
    * arrays and vbo's mapped.  
 
1308
    *
 
1309
    * Luckily, neither the drivers nor tnl muck with the state that
 
1310
    * concerns us here:
 
1311
    */
 
1312
   new_state &= _NEW_ARRAY | _NEW_PROGRAM;
 
1313
   if (new_state) {
 
1314
      assert(!actx->mapped_vbos);
 
1315
      actx->NewState |= new_state;
 
1316
   }
1218
1317
}