Changeset 13041 for OpenSceneGraph/trunk/src/osgUtil/Tessellator.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgUtil/Tessellator.cpp (modified) (28 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgUtil/Tessellator.cpp
r12957 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 25 25 _wtype(TESS_WINDING_ODD), 26 26 _ttype(TESS_TYPE_POLYGONS), 27 _boundaryOnly(false), _numberVerts(0) 27 _boundaryOnly(false), _numberVerts(0) 28 28 { 29 29 _tobj = gluNewTess(); … … 57 57 gluTessProperty(_tobj, GLU_TESS_WINDING_RULE, _wtype); 58 58 gluTessProperty(_tobj, GLU_TESS_BOUNDARY_ONLY, _boundaryOnly); 59 59 60 60 if (tessNormal.length()>0.0) gluTessNormal(_tobj, tessNormal.x(), tessNormal.y(), tessNormal.z()); 61 61 62 62 gluTessBeginPolygon(_tobj,this); 63 63 } 64 } 65 64 } 65 66 66 void Tessellator::beginContour() 67 67 { … … 71 71 } 72 72 } 73 73 74 74 void Tessellator::addVertex(osg::Vec3* vertex) 75 75 { … … 105 105 { 106 106 gluTessEndPolygon(_tobj); 107 107 108 108 if (_errorCode!=0) 109 109 { … … 120 120 delete (*i); 121 121 } 122 122 123 123 // We need to also free the vertex list as well otherwise we are leaking... 124 124 for (NewVertexList::iterator j = _newVertexList.begin(); j != _newVertexList.end(); ++j) … … 139 139 { 140 140 public: 141 141 142 142 float _f1,_f2,_f3,_f4; 143 143 unsigned int _i1,_i2,_i3,_i4; … … 158 158 if (_f3) val += static_cast<TYPE>(array[_i3] * _f3); 159 159 if (_f4) val += static_cast<TYPE>(array[_i4] * _f4); 160 160 161 161 array.push_back(val); 162 162 } … … 180 180 // turn the contour list into primitives, a little like Tessellator does but more generally 181 181 osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geom.getVertexArray()); 182 182 183 183 if (!vertices || vertices->empty() || geom.getPrimitiveSetList().empty()) return; 184 184 … … 190 190 geom.getSecondaryColorIndices() || 191 191 geom.getFogCoordIndices()) return; 192 192 193 193 // not even text coord indices don't handle geometry which use indices... 194 194 for(unsigned int unit=0;unit<geom.getNumTexCoordArrays();++unit) … … 241 241 { 242 242 osg::DrawArrayLengths* drawArrayLengths = static_cast<osg::DrawArrayLengths*>(primitive.get()); 243 unsigned int first = drawArrayLengths->getFirst(); 243 unsigned int first = drawArrayLengths->getFirst(); 244 244 for(osg::DrawArrayLengths::iterator itr=drawArrayLengths->begin(); 245 245 itr!=drawArrayLengths->end(); … … 291 291 if (_ttype==TESS_TYPE_GEOMETRY) { 292 292 endTessellation(); 293 294 collectTessellation(geom, 0); 293 294 collectTessellation(geom, 0); 295 295 } 296 296 } … … 372 372 if (primitive->getMode()==osg::PrimitiveSet::TRIANGLES) nperprim=3; 373 373 unsigned int idx=0; 374 374 375 375 switch(primitive->getType()) 376 376 { … … 378 378 { 379 379 osg::DrawArrays* drawArray = static_cast<osg::DrawArrays*>(primitive); 380 unsigned int first = drawArray->getFirst(); 380 unsigned int first = drawArray->getFirst(); 381 381 unsigned int last = first+drawArray->getCount(); 382 382 addContour(primitive->getMode(),first,last,vertices); … … 438 438 break; 439 439 } 440 440 441 441 } 442 442 … … 445 445 if (!_newVertexList.empty()) 446 446 { 447 447 448 448 osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geom.getVertexArray()); 449 449 osg::Vec3Array* normals = NULL; … … 452 452 normals = dynamic_cast<osg::Vec3Array*>(geom.getNormalArray()); 453 453 } 454 454 455 455 typedef std::vector<osg::Array*> ArrayList; 456 456 ArrayList arrays; 457 457 458 458 if (geom.getColorBinding()==osg::Geometry::BIND_PER_VERTEX) 459 459 { 460 460 arrays.push_back(geom.getColorArray()); 461 461 } 462 462 463 463 if (geom.getSecondaryColorBinding()==osg::Geometry::BIND_PER_VERTEX) 464 464 { 465 465 arrays.push_back(geom.getSecondaryColorArray()); 466 466 } 467 467 468 468 if (geom.getFogCoordBinding()==osg::Geometry::BIND_PER_VERTEX) 469 469 { 470 470 arrays.push_back(geom.getFogCoordArray()); 471 471 } 472 472 473 473 osg::Geometry::ArrayDataList& tcal = geom.getTexCoordArrayList(); 474 474 for(osg::Geometry::ArrayDataList::iterator tcalItr=tcal.begin(); … … 476 476 ++tcalItr) 477 477 { 478 if (tcalItr->array.valid()) 478 if (tcalItr->array.valid()) 479 479 { 480 480 arrays.push_back(tcalItr->array.get()); 481 481 } 482 482 } 483 483 484 484 // now add any new vertices that are required. 485 485 for(NewVertexList::iterator itr=_newVertexList.begin(); … … 489 489 NewVertex& newVertex = (*itr); 490 490 osg::Vec3* vertex = newVertex._vpos; 491 491 492 492 // assign vertex. 493 493 vertexPtrToIndexMap[vertex]=vertices->size(); 494 494 vertices->push_back(*vertex); 495 495 496 496 // assign normals 497 497 if (normals) … … 505 505 normals->push_back(norm); 506 506 } 507 507 508 508 if (!arrays.empty()) 509 509 { … … 512 512 newVertex._f3,vertexPtrToIndexMap[newVertex._v3], 513 513 newVertex._f4,vertexPtrToIndexMap[newVertex._v4]); 514 514 515 515 // assign the rest of the attributes. 516 516 for(ArrayList::iterator aItr=arrays.begin(); … … 522 522 } 523 523 } 524 525 } 526 524 525 } 526 527 527 } 528 528 … … 615 615 } 616 616 break; 617 default: // should also handle:ArrayType' ByteArrayType' ShortArrayType' IntArrayType' 618 // `UShortArrayType' `UIntArrayType' `Vec4ubArrayType' `FloatArrayType' 617 default: // should also handle:ArrayType' ByteArrayType' ShortArrayType' IntArrayType' 618 // `UShortArrayType' `UIntArrayType' `Vec4ubArrayType' `FloatArrayType' 619 619 break; 620 620 } … … 626 626 osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geom.getVertexArray()); 627 627 VertexPtrToIndexMap vertexPtrToIndexMap; 628 628 629 629 // populate the VertexPtrToIndexMap. 630 630 for(unsigned int vi=0;vi<vertices->size();++vi) … … 632 632 vertexPtrToIndexMap[&((*vertices)[vi])] = vi; 633 633 } 634 634 635 635 handleNewVertices(geom, vertexPtrToIndexMap); 636 636 637 637 // we don't properly handle per primitive and per primitive_set bindings yet 638 638 // will need to address this soon. Robert Oct 2002. … … 662 662 break; 663 663 } 664 665 } 666 // GWM Dec 2003 - these holders need to go outside the loop to 664 665 } 666 // GWM Dec 2003 - these holders need to go outside the loop to 667 667 // retain the flat shaded colour &/or normal for each tessellated polygon 668 668 osg::Vec3 norm(0.0f,0.0f,0.0f); … … 720 720 } 721 721 722 if (primItr==_primList.begin()) 722 if (primItr==_primList.begin()) 723 723 { // first primitive so collect primitive normal & colour. 724 724 if (normals) { … … 779 779 } 780 780 } 781 // OSG_WARN<<"Add: "<< iprim << std::endl; 781 // OSG_WARN<<"Add: "<< iprim << std::endl; 782 782 } 783 783 iprim++; // GWM Sep 2002 count which normal we should use
