@@ -300,13 +300,11 @@ namespace SCIRun {
300300 }
301301
302302 // Add vertex buffer objects.
303- // -----------------------------------------------------------------
304- char * vbo_buffer = 0 ;
305- size_t stride_vbo = 0 ;
306- // -----------------------------------------------------------------
303+ std::vector<char *> vbo_buffer;
304+ std::vector<size_t > stride_vbo;
307305
308306 int nameIndex = 0 ;
309- for (auto it = obj->mVBOs .cbegin (); it != obj->mVBOs .cend (); ++it)
307+ for (auto it = obj->mVBOs .cbegin (); it != obj->mVBOs .cend (); ++it, ++nameIndex )
310308 {
311309 const Core::Datatypes::GeometryObject::SpireVBO& vbo = *it;
312310
@@ -322,17 +320,21 @@ namespace SCIRun {
322320 GLuint vboID = vboMan.addInMemoryVBO (vbo.data ->getBuffer (), vbo.data ->getBufferSize (),
323321 attributeData, vbo.name );
324322 }
325- // -----------------------------------------------------------------
326- vbo_buffer = reinterpret_cast <char *>(vbo.data ->getBuffer ());
323+
324+ vbo_buffer.push_back (reinterpret_cast <char *>(vbo.data ->getBuffer ()));
325+ size_t stride = 0 ;
327326 for (auto a : vbo.attributes )
328- stride_vbo += a.sizeInBytes ;
329- // -----------------------------------------------------------------
327+ stride += a.sizeInBytes ;
328+ stride_vbo.push_back (stride);
329+
330330 bbox.extend (vbo.boundingBox );
331331 }
332332
333+ std::cout << " VBO passes: " << nameIndex << std::endl;
334+
333335 // Add index buffer objects.
334336 nameIndex = 0 ;
335- for (auto it = obj->mIBOs .cbegin (); it != obj->mIBOs .cend (); ++it)
337+ for (auto it = obj->mIBOs .cbegin (); it != obj->mIBOs .cend (); ++it, ++nameIndex )
336338 {
337339 const Core::Datatypes::GeometryObject::SpireIBO& ibo = *it;
338340 GLenum primType = GL_UNSIGNED_SHORT;
@@ -373,13 +375,12 @@ namespace SCIRun {
373375 break ;
374376 }
375377 // / Create sorted lists of Buffers for transparency in each direction of the axis
376- // ----------------------------------------------------------------
377378 uint32_t * ibo_buffer = reinterpret_cast <uint32_t *>(ibo.data ->getBuffer ());
378379 size_t num_triangles = ibo.data ->getBufferSize () / (sizeof (uint32_t ) * 3 );
379380 Core::Geometry::Vector dir (0.0 , 0.0 , 0.0 );
380381
381382 std::vector<DepthIndex> rel_depth (num_triangles);
382- for (int i = 0 ; i <= 6 ; ++i)
383+ for (int i = 0 ; i < 6 ; ++i)
383384 {
384385 std::string name = ibo.name ;
385386
@@ -413,22 +414,16 @@ namespace SCIRun {
413414 dir = Core::Geometry::Vector (0.0 , 0.0 , -1.0 );
414415 name += " NegZ" ;
415416 }
416- else if (i == 6 )
417- {
418- int numPrimitives = ibo.data ->getBufferSize () / ibo.indexSize ;
419- iboMan.addInMemoryIBO (ibo.data ->getBuffer (), ibo.data ->getBufferSize (), primitive, primType, numPrimitives, name);
420- break ;
421- }
422417
423418 for (size_t j = 0 ; j < num_triangles; j++)
424419 {
425- float * vertex1 = reinterpret_cast <float *>(vbo_buffer + stride_vbo * (ibo_buffer[j * 3 ]));
420+ float * vertex1 = reinterpret_cast <float *>(vbo_buffer[nameIndex] + stride_vbo[nameIndex] * (ibo_buffer[j * 3 ]));
426421 Core::Geometry::Point node1 (vertex1[0 ], vertex1[1 ], vertex1[2 ]);
427422
428- float * vertex2 = reinterpret_cast <float *>(vbo_buffer + stride_vbo * (ibo_buffer[j * 3 + 1 ]));
423+ float * vertex2 = reinterpret_cast <float *>(vbo_buffer[nameIndex] + stride_vbo[nameIndex] * (ibo_buffer[j * 3 + 1 ]));
429424 Core::Geometry::Point node2 (vertex2[0 ], vertex2[1 ], vertex2[2 ]);
430425
431- float * vertex3 = reinterpret_cast <float *>(vbo_buffer + stride_vbo * (ibo_buffer[j * 3 + 2 ]));
426+ float * vertex3 = reinterpret_cast <float *>(vbo_buffer[nameIndex] + stride_vbo[nameIndex] * (ibo_buffer[j * 3 + 2 ]));
432427 Core::Geometry::Point node3 (vertex3[0 ], vertex3[1 ], vertex3[2 ]);
433428
434429 rel_depth[j].mDepth = Core::Geometry::Dot (dir, node1) + Core::Geometry::Dot (dir, node2) + Core::Geometry::Dot (dir, node3);
@@ -450,14 +445,11 @@ namespace SCIRun {
450445 }
451446
452447 iboMan.addInMemoryIBO (sbuffer, ibo.data ->getBufferSize (), primitive, primType, numPrimitives, name);
453- }
454- // ----------------------------------------------------------------
455-
456- // int numPrimitives = ibo.data->getBufferSize() / ibo.indexSize;
457-
458- // iboMan.addInMemoryIBO(ibo.data->getBuffer(), ibo.data->getBufferSize(), primitive, primType, numPrimitives, ibo.name);
448+ }
459449 }
460450
451+ std::cout << " IBO passes: " << nameIndex << std::endl;
452+
461453 // Add default identity transform to the object globally (instead of per-pass)
462454 glm::mat4 xform;
463455 mSRObjects .push_back (SRObject (objectName, xform, bbox, obj->mColorMap , port));
@@ -476,20 +468,20 @@ namespace SCIRun {
476468 {
477469 // reorderIBO(pass);
478470 addVBOToEntity (entityID, pass.vboName );
479- for (int i = 0 ; i <= 6 ; ++i)
471+ for (int i = 0 ; i < 6 ; ++i)
480472 {
481473 std::string name = pass.iboName ;
482- if (i == 1 )
474+ if (i == 0 )
483475 name += " X" ;
484- if (i == 2 )
476+ if (i == 1 )
485477 name += " Y" ;
486- if (i == 3 )
478+ if (i == 2 )
487479 name += " Z" ;
488- if (i == 4 )
480+ if (i == 3 )
489481 name += " NegX" ;
490- if (i == 5 )
482+ if (i == 4 )
491483 name += " NegY" ;
492- if (i == 6 )
484+ if (i == 5 )
493485 name += " NegZ" ;
494486
495487 addIBOToEntity (entityID, name);
0 commit comments