| 241 | //=========================================================================== |
| 242 | |
| 243 | void FMD3Model::BuildVertexBuffer(FModelRenderer *renderer) |
| 244 | { |
| 245 | if (!GetVertexBuffer(renderer->GetType())) |
| 246 | { |
| 247 | LoadGeometry(); |
| 248 | |
| 249 | unsigned int vbufsize = 0; |
| 250 | unsigned int ibufsize = 0; |
| 251 | |
| 252 | for (unsigned i = 0; i < Surfaces.Size(); i++) |
| 253 | { |
| 254 | MD3Surface * surf = &Surfaces[i]; |
| 255 | vbufsize += Frames.Size() * surf->numVertices; |
| 256 | ibufsize += 3 * surf->numTriangles; |
| 257 | } |
| 258 | |
| 259 | auto vbuf = renderer->CreateVertexBuffer(true, Frames.Size() == 1); |
| 260 | SetVertexBuffer(renderer->GetType(), vbuf); |
| 261 | |
| 262 | FModelVertex *vertptr = vbuf->LockVertexBuffer(vbufsize); |
| 263 | unsigned int *indxptr = vbuf->LockIndexBuffer(ibufsize); |
| 264 | |
| 265 | assert(vertptr != nullptr && indxptr != nullptr); |
| 266 | |
| 267 | unsigned int vindex = 0, iindex = 0; |
| 268 | |
| 269 | for (unsigned i = 0; i < Surfaces.Size(); i++) |
| 270 | { |
| 271 | MD3Surface * surf = &Surfaces[i]; |
| 272 | |
| 273 | surf->vindex = vindex; |
| 274 | surf->iindex = iindex; |
| 275 | for (unsigned j = 0; j < Frames.Size() * surf->numVertices; j++) |
| 276 | { |
| 277 | MD3Vertex* vert = &surf->Vertices[j]; |
| 278 | |
| 279 | FModelVertex *bvert = &vertptr[vindex++]; |
| 280 | |
| 281 | int tc = j % surf->numVertices; |
| 282 | bvert->Set(vert->x, vert->z, vert->y, surf->Texcoords[tc].s, surf->Texcoords[tc].t); |
| 283 | bvert->SetNormal(vert->nx, vert->nz, vert->ny); |
| 284 | } |
| 285 | |
| 286 | for (unsigned k = 0; k < surf->numTriangles; k++) |
| 287 | { |
| 288 | for (int l = 0; l < 3; l++) |
| 289 | { |
| 290 | indxptr[iindex++] = surf->Tris[k].VertIndex[l]; |
| 291 | } |
| 292 | } |
| 293 | surf->UnloadGeometry(); |
| 294 | } |
| 295 | vbuf->UnlockVertexBuffer(); |
| 296 | vbuf->UnlockIndexBuffer(); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 |
nothing calls this directly
no test coverage detected