| 211 | | if (_ttype==TESS_TYPE_POLYGONS || _ttype==TESS_TYPE_DRAWABLE) { |
| 212 | | if (primitive->getMode()==osg::PrimitiveSet::POLYGON ||_ttype==TESS_TYPE_DRAWABLE) { |
| 213 | | beginTesselation(); |
| 214 | | addContour(primitive.get(), vertices); |
| 215 | | endTesselation(); |
| 216 | | |
| 217 | | collectTesselation(geom); |
| 218 | | } else { // copy the contour primitive as it is not being tesselated |
| | 211 | if (_ttype==TESS_TYPE_POLYGONS || _ttype==TESS_TYPE_DRAWABLE) |
| | 212 | { |
| | 213 | if (primitive->getMode()==osg::PrimitiveSet::POLYGON || _ttype==TESS_TYPE_DRAWABLE) |
| | 214 | { |
| | 215 | |
| | 216 | if (primitive->getType()==osg::PrimitiveSet::DrawArrayLengthsPrimitiveType) |
| | 217 | { |
| | 218 | osg::DrawArrayLengths* drawArrayLengths = static_cast<osg::DrawArrayLengths*>(primitive.get()); |
| | 219 | unsigned int first = drawArrayLengths->getFirst(); |
| | 220 | for(osg::DrawArrayLengths::iterator itr=drawArrayLengths->begin(); |
| | 221 | itr!=drawArrayLengths->end(); |
| | 222 | ++itr) |
| | 223 | { |
| | 224 | beginTesselation(); |
| | 225 | unsigned int last = first + *itr; |
| | 226 | addContour(primitive->getMode(),first,last,vertices); |
| | 227 | first = last; |
| | 228 | endTesselation(); |
| | 229 | collectTesselation(geom); |
| | 230 | } |
| | 231 | } |
| | 232 | else |
| | 233 | { |
| | 234 | beginTesselation(); |
| | 235 | addContour(primitive.get(), vertices); |
| | 236 | endTesselation(); |
| | 237 | collectTesselation(geom); |
| | 238 | } |
| | 239 | |
| | 240 | } |
| | 241 | else |
| | 242 | { // copy the contour primitive as it is not being tesselated |
| | 268 | void Tesselator::addContour(GLenum mode, unsigned int first, unsigned int last, osg::Vec3Array* vertices) |
| | 269 | { |
| | 270 | beginContour(); |
| | 271 | |
| | 272 | unsigned int idx=0; |
| | 273 | unsigned int nperprim=0; // number of vertices per primitive |
| | 274 | if (mode==osg::PrimitiveSet::QUADS) nperprim=4; |
| | 275 | else if (mode==osg::PrimitiveSet::TRIANGLES) nperprim=3; |
| | 276 | |
| | 277 | unsigned int i; |
| | 278 | switch (mode) |
| | 279 | { |
| | 280 | case osg::PrimitiveSet::QUADS: |
| | 281 | case osg::PrimitiveSet::TRIANGLES: |
| | 282 | case osg::PrimitiveSet::POLYGON: |
| | 283 | case osg::PrimitiveSet::LINE_LOOP: |
| | 284 | case osg::PrimitiveSet::TRIANGLE_FAN: |
| | 285 | { |
| | 286 | for(i=first;i<last;++i, idx++) |
| | 287 | { |
| | 288 | addVertex(&((*vertices)[i])); |
| | 289 | if (nperprim>0 && i<last-1 && idx%nperprim==nperprim-1) { |
| | 290 | endContour(); |
| | 291 | beginContour(); |
| | 292 | } |
| | 293 | } |
| | 294 | } |
| | 295 | break; |
| | 296 | case osg::PrimitiveSet::QUAD_STRIP: |
| | 297 | { // always has an even number of vertices |
| | 298 | for(i=first;i<last;i+=2) |
| | 299 | { // 0,2,4... |
| | 300 | addVertex(&((*vertices)[i])); |
| | 301 | } |
| | 302 | for(i=last-1;i>=first;i-=2) |
| | 303 | { // ...5,3,1 |
| | 304 | addVertex(&((*vertices)[i])); |
| | 305 | } |
| | 306 | } |
| | 307 | break; |
| | 308 | case osg::PrimitiveSet::TRIANGLE_STRIP: |
| | 309 | { |
| | 310 | for( i=first;i<last;i+=2) |
| | 311 | {// 0,2,4,... |
| | 312 | addVertex(&((*vertices)[i])); |
| | 313 | } |
| | 314 | for(i=((last-first)%2)?(last-2):(last-1) ;i>first&& i<last;i-=2) |
| | 315 | { |
| | 316 | addVertex(&((*vertices)[i])); |
| | 317 | } |
| | 318 | } |
| | 319 | break; |
| | 320 | default: // lines, points, line_strip |
| | 321 | { |
| | 322 | for(i=first;i<last;++i, idx++) |
| | 323 | { |
| | 324 | addVertex(&((*vertices)[i])); |
| | 325 | if (nperprim>0 && i<last-1 && idx%nperprim==nperprim-1) { |
| | 326 | endContour(); |
| | 327 | beginContour(); |
| | 328 | } |
| | 329 | } |
| | 330 | } |
| | 331 | break; |
| | 332 | } |
| | 333 | |
| | 334 | endContour(); |
| | 335 | } |
| | 336 | |
| 261 | | |
| 262 | | switch (primitive->getMode()) { |
| 263 | | case osg::PrimitiveSet::QUADS: |
| 264 | | case osg::PrimitiveSet::TRIANGLES: |
| 265 | | case osg::PrimitiveSet::POLYGON: |
| 266 | | case osg::PrimitiveSet::LINE_LOOP: |
| 267 | | case osg::PrimitiveSet::TRIANGLE_FAN: |
| 268 | | { |
| 269 | | for(i=first;i<last;++i, idx++) |
| 270 | | { |
| 271 | | addVertex(&((*vertices)[i])); |
| 272 | | if (nperprim>0 && i<last-1 && idx%nperprim==nperprim-1) { |
| 273 | | endContour(); |
| 274 | | beginContour(); |
| 275 | | } |
| 276 | | } |
| 277 | | } |
| 278 | | break; |
| 279 | | case osg::PrimitiveSet::QUAD_STRIP: |
| 280 | | { // always has an even number of vertices |
| 281 | | for( i=first;i<last;i+=2) |
| 282 | | { // 0,2,4... |
| 283 | | addVertex(&((*vertices)[i])); |
| 284 | | } |
| 285 | | for(i=last-1;i>=first;i-=2) |
| 286 | | { // ...5,3,1 |
| 287 | | addVertex(&((*vertices)[i])); |
| 288 | | } |
| 289 | | } |
| 290 | | break; |
| 291 | | case osg::PrimitiveSet::TRIANGLE_STRIP: |
| 292 | | { |
| 293 | | for( i=first;i<last;i+=2) |
| 294 | | {// 0,2,4,... |
| 295 | | addVertex(&((*vertices)[i])); |
| 296 | | } |
| 297 | | for(i=((last-first)%2)?(last-2):(last-1) ;i>first&& i<last;i-=2) |
| 298 | | { |
| 299 | | addVertex(&((*vertices)[i])); |
| 300 | | } |
| 301 | | } |
| 302 | | break; |
| 303 | | default: // lines, points, line_strip |
| 304 | | { |
| 305 | | for(i=first;i<last;++i, idx++) |
| 306 | | { |
| 307 | | addVertex(&((*vertices)[i])); |
| 308 | | if (nperprim>0 && i<last-1 && idx%nperprim==nperprim-1) { |
| 309 | | endContour(); |
| 310 | | beginContour(); |
| 311 | | } |
| 312 | | } |
| 313 | | } |
| 314 | | break; |
| 315 | | } |
| | 352 | addContour(primitive->getMode(),first,last,vertices); |