Changeset 13041 for OpenSceneGraph/trunk/src/osg/Drawable.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osg/Drawable.cpp (modified) (71 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osg/Drawable.cpp
r12480 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 */ … … 37 37 unsigned int Drawable::s_numberDeletedDrawablesInLastFrame = 0; 38 38 39 // static cache of deleted display lists which can only 39 // static cache of deleted display lists which can only 40 40 // by completely deleted once the appropriate OpenGL context 41 41 // is set. Used osg::Drawable::deleteDisplayList(..) and flushDeletedDisplayLists(..) below. … … 57 57 return glGenLists( 1 ); 58 58 } 59 else 59 else 60 60 { 61 61 DisplayListMap::iterator itr = dll.lower_bound(sizeHint); … … 65 65 66 66 ++s_numberDrawablesReusedLastInLastFrame; 67 67 68 68 GLuint globj = itr->second; 69 69 dll.erase(itr); 70 70 71 71 return globj; 72 } 72 } 73 73 else 74 74 { … … 124 124 } 125 125 126 dll.clear(); 126 dll.clear(); 127 127 #else 128 128 OSG_NOTICE<<"Warning: Drawable::deleteDisplayList(..) - not supported."<<std::endl; … … 135 135 136 136 DisplayListMap& dll = s_deletedDisplayListCache[contextID]; 137 dll.clear(); 137 dll.clear(); 138 138 } 139 139 … … 179 179 { 180 180 OSG_WARN<<"Error in delete"<<std::endl; 181 } 181 } 182 182 } 183 183 else … … 204 204 { 205 205 OSG_WARN<<"Error in delete"<<std::endl; 206 } 206 } 207 207 } 208 208 } 209 209 elapsedTime = timer.delta_s(start_tick,timer.tick()); 210 210 211 211 if (noDeleted!=0) OSG_INFO<<"Number display lists deleted = "<<noDeleted<<" elapsed time"<<elapsedTime<<std::endl; 212 212 … … 291 291 292 292 bool dynamic = false; 293 293 294 294 if (getUpdateCallback() || 295 295 getEventCallback() || 296 getCullCallback()) 296 getCullCallback()) 297 297 { 298 298 dynamic = true; 299 299 } 300 300 301 301 setDataVariance(dynamic ? DYNAMIC : STATIC); 302 302 } … … 322 322 // do nothing if nothing changed. 323 323 if (_stateset==stateset) return; 324 324 325 325 // track whether we need to account for the need to do a update or event traversal. 326 326 int delta_update = 0; 327 327 int delta_event = 0; 328 328 329 // remove this node from the current statesets parent list 329 // remove this node from the current statesets parent list 330 330 if (_stateset.valid()) 331 331 { … … 334 334 if (_stateset->requiresEventTraversal()) --delta_event; 335 335 } 336 336 337 337 // set the stateset. 338 338 _stateset = stateset; 339 339 340 340 // add this node to the new stateset to the parent list. 341 341 if (_stateset.valid()) … … 345 345 if (_stateset->requiresEventTraversal()) ++delta_event; 346 346 } 347 347 348 348 349 349 // only inform parents if change occurs and drawable doesn't already have an update callback … … 382 382 if (!_updateCallback && !_parents.empty()) 383 383 { 384 // need to pass on changes to parents. 384 // need to pass on changes to parents. 385 385 int delta = 0; 386 386 if (_numChildrenRequiringUpdateTraversal>0) --delta; … … 394 394 itr != _parents.end(); 395 395 ++itr) 396 { 396 { 397 397 (*itr)->setNumChildrenRequiringUpdateTraversal( (*itr)->getNumChildrenRequiringUpdateTraversal()+delta ); 398 398 } … … 400 400 } 401 401 } 402 402 403 403 // finally update this objects value. 404 404 _numChildrenRequiringUpdateTraversal=num; 405 405 406 406 } 407 407 … … 417 417 if (!_eventCallback && !_parents.empty()) 418 418 { 419 // need to pass on changes to parents. 419 // need to pass on changes to parents. 420 420 int delta = 0; 421 421 if (_numChildrenRequiringEventTraversal>0) --delta; … … 429 429 itr != _parents.end(); 430 430 ++itr) 431 { 431 { 432 432 (*itr)->setNumChildrenRequiringEventTraversal( (*itr)->getNumChildrenRequiringEventTraversal()+delta ); 433 433 } … … 435 435 } 436 436 } 437 437 438 438 // finally Event this objects value. 439 439 _numChildrenRequiringEventTraversal=num; 440 440 441 441 } 442 442 … … 469 469 470 470 #ifdef OSG_GL_DISPLAYLISTS_AVAILABLE 471 // get the contextID (user defined ID of 0 upwards) for the 471 // get the contextID (user defined ID of 0 upwards) for the 472 472 // current OpenGL context. 473 473 unsigned int contextID = renderInfo.getContextID(); … … 478 478 // call the globj if already set otherwise compile and execute. 479 479 if( globj != 0 ) 480 { 480 { 481 481 glDeleteLists( globj, 1 ); 482 482 } … … 487 487 if (_drawCallback.valid()) 488 488 _drawCallback->drawImplementation(renderInfo,this); 489 else 489 else 490 490 drawImplementation(renderInfo); 491 491 … … 522 522 523 523 if (!_useDisplayList) return; 524 524 525 525 if (state) 526 526 { 527 // get the contextID (user defined ID of 0 upwards) for the 527 // get the contextID (user defined ID of 0 upwards) for the 528 528 // current OpenGL context. 529 529 unsigned int contextID = state->getContextID(); … … 537 537 Drawable::deleteDisplayList(contextID,globj, getGLObjectSizeHint()); 538 538 globj = 0; 539 } 539 } 540 540 } 541 541 else … … 562 562 } 563 563 } 564 564 565 565 // set with new value. 566 566 _supportsDisplayList=flag; … … 581 581 dirtyDisplayList(); 582 582 } 583 583 584 584 if (_supportsDisplayList) 585 585 { 586 586 587 587 // set with new value. 588 588 _useDisplayList = flag; 589 589 590 590 } 591 591 else // does not support display lists. … … 595 595 OSG_WARN<<"Warning: attempt to setUseDisplayList(true) on a drawable with does not support display lists."<<std::endl; 596 596 } 597 else 597 else 598 598 { 599 599 // set with new value. … … 644 644 { 645 645 if (_updateCallback==ac) return; 646 646 647 647 int delta = 0; 648 648 if (_updateCallback.valid()) --delta; … … 650 650 651 651 _updateCallback = ac; 652 652 653 653 if (delta!=0 && !(_stateset.valid() && _stateset->requiresUpdateTraversal())) 654 654 { … … 665 665 { 666 666 if (_eventCallback==ac) return; 667 667 668 668 int delta = 0; 669 669 if (_eventCallback.valid()) --delta; … … 671 671 672 672 _eventCallback = ac; 673 673 674 674 if (delta!=0 && !(_stateset.valid() && _stateset->requiresEventTraversal())) 675 675 { … … 688 688 { 689 689 _vertices2f = 0; 690 _vertices3f = 0; 690 _vertices3f = 0; 691 691 _vertices4f = 0; 692 _vertices2d = 0; 693 _vertices3d = 0; 692 _vertices2d = 0; 693 _vertices3d = 0; 694 694 _vertices4d = 0; 695 695 } … … 776 776 virtual void vertex(double x,double y,double z,double w) { if (w!=0.0f) _bb.expandBy(x/w,y/w,z/w); } 777 777 virtual void end() {} 778 778 779 779 const Vec2* _vertices2f; 780 780 const Vec3* _vertices3f; … … 783 783 const Vec3d* _vertices3d; 784 784 const Vec4d* _vertices4d; 785 BoundingBox _bb; 785 BoundingBox _bb; 786 786 }; 787 787 … … 793 793 non_const_this->accept(cb); 794 794 795 #if 0 795 #if 0 796 796 OSG_NOTICE<<"computeBound() "<<cb._bb.xMin()<<", "<<cb._bb.xMax()<<", "<<std::endl; 797 797 OSG_NOTICE<<" "<<cb._bb.yMin()<<", "<<cb._bb.yMax()<<", "<<std::endl; 798 798 OSG_NOTICE<<" "<<cb._bb.zMin()<<", "<<cb._bb.zMax()<<", "<<std::endl; 799 799 #endif 800 800 801 801 return cb._bb; 802 802 } … … 844 844 _isTimerQuerySupported = rhs._isTimerQuerySupported; 845 845 _isARBTimerQuerySupported = rhs._isARBTimerQuerySupported; 846 846 847 847 _glFogCoordfv = rhs._glFogCoordfv; 848 848 _glSecondaryColor3ubv = rhs._glSecondaryColor3ubv; … … 1025 1025 { 1026 1026 OSG_WARN<<"Error: glFogCoordfv not supported by OpenGL driver"<<std::endl; 1027 } 1027 } 1028 1028 } 1029 1029 … … 1056 1056 if (_glMultiTexCoord1f) 1057 1057 { 1058 _glMultiTexCoord1f(target,coord); 1058 _glMultiTexCoord1f(target,coord); 1059 1059 } 1060 1060 else … … 1068 1068 if (_glMultiTexCoord2fv) 1069 1069 { 1070 _glMultiTexCoord2fv(target,coord); 1070 _glMultiTexCoord2fv(target,coord); 1071 1071 } 1072 1072 else … … 1080 1080 if (_glMultiTexCoord3fv) 1081 1081 { 1082 _glMultiTexCoord3fv(target,coord); 1082 _glMultiTexCoord3fv(target,coord); 1083 1083 } 1084 1084 else … … 1092 1092 if (_glMultiTexCoord4fv) 1093 1093 { 1094 _glMultiTexCoord4fv(target,coord); 1094 _glMultiTexCoord4fv(target,coord); 1095 1095 } 1096 1096 else … … 1104 1104 if (_glMultiTexCoord1d) 1105 1105 { 1106 _glMultiTexCoord1d(target,coord); 1106 _glMultiTexCoord1d(target,coord); 1107 1107 } 1108 1108 else … … 1116 1116 if (_glMultiTexCoord2dv) 1117 1117 { 1118 _glMultiTexCoord2dv(target,coord); 1118 _glMultiTexCoord2dv(target,coord); 1119 1119 } 1120 1120 else … … 1128 1128 if (_glMultiTexCoord3dv) 1129 1129 { 1130 _glMultiTexCoord3dv(target,coord); 1130 _glMultiTexCoord3dv(target,coord); 1131 1131 } 1132 1132 else … … 1140 1140 if (_glMultiTexCoord4dv) 1141 1141 { 1142 _glMultiTexCoord4dv(target,coord); 1142 _glMultiTexCoord4dv(target,coord); 1143 1143 } 1144 1144 else … … 1152 1152 if (_glVertexAttrib1s) 1153 1153 { 1154 _glVertexAttrib1s(index,s); 1154 _glVertexAttrib1s(index,s); 1155 1155 } 1156 1156 else … … 1164 1164 if (_glVertexAttrib1f) 1165 1165 { 1166 _glVertexAttrib1f(index,f); 1166 _glVertexAttrib1f(index,f); 1167 1167 } 1168 1168 else … … 1176 1176 if (_glVertexAttrib1d) 1177 1177 { 1178 _glVertexAttrib1d(index,f); 1178 _glVertexAttrib1d(index,f); 1179 1179 } 1180 1180 else … … 1188 1188 if (_glVertexAttrib2fv) 1189 1189 { 1190 _glVertexAttrib2fv(index,v); 1190 _glVertexAttrib2fv(index,v); 1191 1191 } 1192 1192 else … … 1200 1200 if (_glVertexAttrib3fv) 1201 1201 { 1202 _glVertexAttrib3fv(index,v); 1202 _glVertexAttrib3fv(index,v); 1203 1203 } 1204 1204 else … … 1212 1212 if (_glVertexAttrib4fv) 1213 1213 { 1214 _glVertexAttrib4fv(index,v); 1214 _glVertexAttrib4fv(index,v); 1215 1215 } 1216 1216 else … … 1224 1224 if (_glVertexAttrib2dv) 1225 1225 { 1226 _glVertexAttrib2dv(index,v); 1226 _glVertexAttrib2dv(index,v); 1227 1227 } 1228 1228 else … … 1236 1236 if (_glVertexAttrib3dv) 1237 1237 { 1238 _glVertexAttrib3dv(index,v); 1238 _glVertexAttrib3dv(index,v); 1239 1239 } 1240 1240 else … … 1248 1248 if (_glVertexAttrib4dv) 1249 1249 { 1250 _glVertexAttrib4dv(index,v); 1250 _glVertexAttrib4dv(index,v); 1251 1251 } 1252 1252 else … … 1260 1260 if (_glVertexAttrib4ubv) 1261 1261 { 1262 _glVertexAttrib4ubv(index,v); 1262 _glVertexAttrib4ubv(index,v); 1263 1263 } 1264 1264 else … … 1272 1272 if (_glVertexAttrib4Nubv) 1273 1273 { 1274 _glVertexAttrib4Nubv(index,v); 1274 _glVertexAttrib4Nubv(index,v); 1275 1275 } 1276 1276 else … … 1282 1282 void Drawable::Extensions::glGenBuffers(GLsizei n, GLuint *buffers) const 1283 1283 { 1284 if (_glGenBuffers) _glGenBuffers(n, buffers); 1284 if (_glGenBuffers) _glGenBuffers(n, buffers); 1285 1285 else OSG_WARN<<"Error: glGenBuffers not supported by OpenGL driver"<<std::endl; 1286 1286 } … … 1288 1288 void Drawable::Extensions::glBindBuffer(GLenum target, GLuint buffer) const 1289 1289 { 1290 if (_glBindBuffer) _glBindBuffer(target, buffer); 1290 if (_glBindBuffer) _glBindBuffer(target, buffer); 1291 1291 else OSG_WARN<<"Error: glBindBuffer not supported by OpenGL driver"<<std::endl; 1292 1292 } … … 1294 1294 void Drawable::Extensions::glBufferData(GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage) const 1295 1295 { 1296 if (_glBufferData) _glBufferData(target, size, data, usage); 1296 if (_glBufferData) _glBufferData(target, size, data, usage); 1297 1297 else OSG_WARN<<"Error: glBufferData not supported by OpenGL driver"<<std::endl; 1298 1298 } … … 1300 1300 void Drawable::Extensions::glBufferSubData(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data) const 1301 1301 { 1302 if (_glBufferSubData) _glBufferSubData(target, offset, size, data); 1302 if (_glBufferSubData) _glBufferSubData(target, offset, size, data); 1303 1303 else OSG_WARN<<"Error: glBufferData not supported by OpenGL driver"<<std::endl; 1304 1304 } … … 1306 1306 void Drawable::Extensions::glDeleteBuffers(GLsizei n, const GLuint *buffers) const 1307 1307 { 1308 if (_glDeleteBuffers) _glDeleteBuffers(n, buffers); 1308 if (_glDeleteBuffers) _glDeleteBuffers(n, buffers); 1309 1309 else OSG_WARN<<"Error: glBufferData not supported by OpenGL driver"<<std::endl; 1310 1310 } … … 1313 1313 { 1314 1314 if (_glIsBuffer) return _glIsBuffer(buffer); 1315 else 1315 else 1316 1316 { 1317 1317 OSG_WARN<<"Error: glIsBuffer not supported by OpenGL driver"<<std::endl; … … 1329 1329 { 1330 1330 if (_glMapBuffer) return _glMapBuffer(target,access); 1331 else 1331 else 1332 1332 { 1333 1333 OSG_WARN<<"Error: glMapBuffer not supported by OpenGL driver"<<std::endl; … … 1339 1339 { 1340 1340 if (_glUnmapBuffer) return _glUnmapBuffer(target); 1341 else 1341 else 1342 1342 { 1343 1343 OSG_WARN<<"Error: glUnmapBuffer not supported by OpenGL driver"<<std::endl; … … 1368 1368 { 1369 1369 OSG_WARN<<"Error: glGenOcclusionQueries not supported by OpenGL driver"<<std::endl; 1370 } 1370 } 1371 1371 } 1372 1372 … … 1380 1380 { 1381 1381 OSG_WARN<<"Error: glDeleteOcclusionQueries not supported by OpenGL driver"<<std::endl; 1382 } 1382 } 1383 1383 } 1384 1384 … … 1392 1392 { 1393 1393 OSG_WARN<<"Error: glIsOcclusionQuery not supported by OpenGL driver"<<std::endl; 1394 } 1394 } 1395 1395 1396 1396 return GLboolean( 0 ); … … 1406 1406 { 1407 1407 OSG_WARN<<"Error: glBeginOcclusionQuery not supported by OpenGL driver"<<std::endl; 1408 } 1408 } 1409 1409 } 1410 1410 … … 1418 1418 { 1419 1419 OSG_WARN<<"Error: glEndOcclusionQuery not supported by OpenGL driver"<<std::endl; 1420 } 1420 } 1421 1421 } 1422 1422 … … 1430 1430 { 1431 1431 OSG_WARN<<"Error: glGetOcclusionQueryiv not supported by OpenGL driver"<<std::endl; 1432 } 1432 } 1433 1433 } 1434 1434 … … 1442 1442 { 1443 1443 OSG_WARN<<"Error: glGetOcclusionQueryuiv not supported by OpenGL driver"<<std::endl; 1444 } 1444 } 1445 1445 } 1446 1446 … … 1495 1495 void Drawable::Extensions::glDeleteQueries(GLsizei n, const GLuint *ids) const 1496 1496 { 1497 if (_gl_delete_queries_arb) 1497 if (_gl_delete_queries_arb) 1498 1498 _gl_delete_queries_arb(n, ids); 1499 1499 else
