Changeset 10650
- Timestamp:
- 10/20/09 21:34:24 (4 years ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 2 added
- 9 modified
-
include/osg/Array (modified) (11 diffs)
-
include/osg/ArrayDispatchers (added)
-
include/osg/Drawable (modified) (3 diffs)
-
include/osg/GLBeginEndAdapter (modified) (2 diffs)
-
include/osg/State (modified) (2 diffs)
-
runexamples.bat (modified) (1 diff)
-
src/osg/ArrayDispatchers.cpp (added)
-
src/osg/CMakeLists.txt (modified) (2 diffs)
-
src/osg/Drawable.cpp (modified) (2 diffs)
-
src/osg/GLBeginEndAdapter.cpp (modified) (2 diffs)
-
src/osg/Geometry.cpp (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osg/Array
r10600 r10650 72 72 Vec2dArrayType = 19, 73 73 Vec3dArrayType = 20, 74 Vec4dArrayType = 21 74 Vec4dArrayType = 21 75 75 }; 76 76 … … 79 79 _dataSize(dataSize), 80 80 _dataType(dataType) {} 81 81 82 82 Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): 83 83 BufferData(array,copyop), … … 89 89 virtual const char* libraryName() const { return "osg"; } 90 90 virtual const char* className() const; 91 91 92 92 virtual void accept(ArrayVisitor&) = 0; 93 93 virtual void accept(ConstArrayVisitor&) const = 0; … … 132 132 { 133 133 public: 134 134 135 135 TemplateArray() : Array(ARRAYTYPE,DataSize,DataType) {} 136 136 … … 138 138 Array(ta,copyop), 139 139 MixinVector<T>(ta) {} 140 140 141 141 TemplateArray(unsigned int no) : 142 142 Array(ARRAYTYPE,DataSize,DataType), … … 182 182 MixinVector<T>( *this ).swap( *this ); 183 183 } 184 184 185 185 virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; } 186 186 virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(T)); } … … 201 201 IndexArray(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0): 202 202 Array(arrayType,dataSize,dataType) {} 203 203 204 204 IndexArray(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): 205 205 Array(array,copyop) {} 206 206 207 207 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const IndexArray*>(obj)!=NULL; } 208 208 209 209 virtual unsigned int index(unsigned int pos) const = 0; 210 210 211 211 protected: 212 212 213 213 virtual ~IndexArray() {} 214 214 }; … … 218 218 { 219 219 public: 220 220 221 221 TemplateIndexArray() : IndexArray(ARRAYTYPE,DataSize,DataType) {} 222 222 … … 224 224 IndexArray(ta,copyop), 225 225 MixinVector<T>(ta) {} 226 226 227 227 TemplateIndexArray(unsigned int no) : 228 228 IndexArray(ARRAYTYPE,DataSize,DataType), … … 268 268 MixinVector<T>( *this ).swap( *this ); 269 269 } 270 270 271 271 virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; } 272 272 virtual unsigned int getTotalDataSize() const { return static_cast<unsigned int>(this->size()*sizeof(T)); } … … 278 278 279 279 protected: 280 280 281 281 virtual ~TemplateIndexArray() {} 282 282 }; -
OpenSceneGraph/trunk/include/osg/Drawable
r9599 r10650 667 667 void glGetQueryObjectui64v(GLuint id, GLenum pname, GLuint64EXT *params) const; 668 668 669 p rotected:669 public: 670 670 671 671 typedef void (APIENTRY * FogCoordProc) (const GLfloat* coord); … … 736 736 VertexAttrib1fProc _glVertexAttrib1f; 737 737 VertexAttrib1dProc _glVertexAttrib1d; 738 VertexAttribfvProc _glVertexAttrib1fv; 738 739 VertexAttribfvProc _glVertexAttrib2fv; 739 740 VertexAttribfvProc _glVertexAttrib3fv; 740 741 VertexAttribfvProc _glVertexAttrib4fv; 742 VertexAttribdvProc _glVertexAttrib1dv; 741 743 VertexAttribdvProc _glVertexAttrib2dv; 742 744 VertexAttribdvProc _glVertexAttrib3dv; … … 746 748 747 749 MultiTexCoord1fProc _glMultiTexCoord1f; 750 MultiTexCoordfvProc _glMultiTexCoord1fv; 748 751 MultiTexCoordfvProc _glMultiTexCoord2fv; 749 752 MultiTexCoordfvProc _glMultiTexCoord3fv; 750 753 MultiTexCoordfvProc _glMultiTexCoord4fv; 751 754 MultiTexCoord1dProc _glMultiTexCoord1d; 755 MultiTexCoorddvProc _glMultiTexCoord1dv; 752 756 MultiTexCoorddvProc _glMultiTexCoord2dv; 753 757 MultiTexCoorddvProc _glMultiTexCoord3dv; -
OpenSceneGraph/trunk/include/osg/GLBeginEndAdapter
r10646 r10650 55 55 void Rotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z); 56 56 57 void Color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);58 void Color4fv(const GLfloat* c) { Color4f(c[0], c[1], c[2], c[3]); }59 60 57 void Vertex3f(GLfloat x, GLfloat y, GLfloat z); 61 58 void Vertex3fv(const GLfloat* v) { Vertex3f(v[0], v[1], v[2]); } 62 59 63 void Normal3f(GLfloat x, GLfloat y, GLfloat z); 60 void Color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) 61 { 62 _normalAssigned = true; 63 _color.set(red,green,blue,alpha); 64 } 65 66 void Color4fv(const GLfloat* c) { Color4f(c[0], c[1], c[2], c[3]); } 67 68 void Normal3f(GLfloat x, GLfloat y, GLfloat z) 69 { 70 _normalAssigned = true; 71 _normal.set(x,y,z); 72 } 73 64 74 void Normal3fv(const GLfloat* n) { Normal3f(n[0], n[1], n[2]); } 65 75 … … 141 151 }; 142 152 143 144 153 } 145 154 -
OpenSceneGraph/trunk/include/osg/State
r10642 r10650 477 477 } 478 478 479 void TexCoord(float x, float y=0.0f, float z=0.0f, float w= 0.0f)479 void TexCoord(float x, float y=0.0f, float z=0.0f, float w=1.0f) 480 480 { 481 481 if (_useVertexAttributeAliasing) _glVertexAttrib4f( _texCoordAliasList[0]._location, x,y,z,w); … … 483 483 } 484 484 485 void MultiTexCoord(unsigned int unit, float x, float y=0.0f, float z=0.0f, float w= 0.0f)485 void MultiTexCoord(unsigned int unit, float x, float y=0.0f, float z=0.0f, float w=1.0f) 486 486 { 487 487 if (_useVertexAttributeAliasing) _glVertexAttrib4f( _texCoordAliasList[unit]._location, x,y,z,w); -
OpenSceneGraph/trunk/runexamples.bat
r8092 r10650 26 26 27 27 echo osgcatch 28 osgcatch28 # osgcatch 29 29 30 30 echo osgclip -
OpenSceneGraph/trunk/src/osg/CMakeLists.txt
r10642 r10650 26 26 ${HEADER_PATH}/ArgumentParser 27 27 ${HEADER_PATH}/Array 28 ${HEADER_PATH}/ArrayDispatchers 28 29 ${HEADER_PATH}/AudioStream 29 30 ${HEADER_PATH}/AutoTransform … … 196 197 ArgumentParser.cpp 197 198 Array.cpp 199 ArrayDispatchers.cpp 198 200 AudioStream.cpp 199 201 AutoTransform.cpp -
OpenSceneGraph/trunk/src/osg/Drawable.cpp
r10632 r10650 935 935 setGLExtensionFuncPtr(_glSecondaryColor3fv, "glSecondaryColor3fv","glSecondaryColor3fvEXT"); 936 936 setGLExtensionFuncPtr(_glMultiTexCoord1f, "glMultiTexCoord1f","glMultiTexCoord1fARB"); 937 setGLExtensionFuncPtr(_glMultiTexCoord1fv, "glMultiTexCoord1fv","glMultiTexCoord1fvARB"); 937 938 setGLExtensionFuncPtr(_glMultiTexCoord2fv, "glMultiTexCoord2fv","glMultiTexCoord2fvARB"); 938 939 setGLExtensionFuncPtr(_glMultiTexCoord3fv, "glMultiTexCoord3fv","glMultiTexCoord3fvARB"); … … 946 947 setGLExtensionFuncPtr(_glVertexAttrib1f, "glVertexAttrib1f","glVertexAttrib1fARB"); 947 948 setGLExtensionFuncPtr(_glVertexAttrib1d, "glVertexAttrib1d","glVertexAttrib1dARB"); 949 setGLExtensionFuncPtr(_glVertexAttrib1fv, "glVertexAttrib1fv","glVertexAttrib1fvARB"); 948 950 setGLExtensionFuncPtr(_glVertexAttrib2fv, "glVertexAttrib2fv","glVertexAttrib2fvARB"); 949 951 setGLExtensionFuncPtr(_glVertexAttrib3fv, "glVertexAttrib3fv","glVertexAttrib3fvARB"); -
OpenSceneGraph/trunk/src/osg/GLBeginEndAdapter.cpp
r10646 r10650 98 98 } 99 99 100 void GLBeginEndAdapter::Color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)101 {102 _normalAssigned = true;103 _color.set(red,green,blue,alpha);104 }105 106 void GLBeginEndAdapter::Normal3f(GLfloat x, GLfloat y, GLfloat z)107 {108 _normalAssigned = true;109 _normal.set(x,y,z);110 }111 112 100 void GLBeginEndAdapter::MultiTexCoord4f(unsigned int unit, GLfloat x, GLfloat y, GLfloat z, GLfloat w) 113 101 { … … 133 121 134 122 if (!_vertices) _vertices = new osg::Vec3Array; 135 136 123 137 124 if (_normalAssigned) -
OpenSceneGraph/trunk/src/osg/Geometry.cpp
r10642 r10650 14 14 15 15 #include <osg/Geometry> 16 #include <osg/ArrayDispatchers> 16 17 #include <osg/Notify> 17 18 … … 224 225 public: 225 226 226 DrawVertexAttrib(const Drawable::Extensions * extensions,unsigned int vertAttribIndex,GLboolean normalized,const Array* attribcoords,const IndexArray* indices): 227 DrawVertexAttrib(const Drawable::Extensions * extensions,unsigned int vertAttribIndex,GLboolean normalized,const Array* attribcoords,const IndexArray* indices): 227 228 _vertAttribIndex(vertAttribIndex), 228 229 _normalized(normalized), … … 337 338 virtual void apply(const Vec4& v) { _extensions->glMultiTexCoord4fv(_target,v.ptr()); } 338 339 339 GLenum _target;340 GLenum _target; 340 341 const Array* _texcoords; 341 342 const IndexArray* _indices; … … 413 414 Geometry::Geometry() 414 415 { 416 // temporary test 417 // setSupportsDisplayList(false); 418 415 419 _fastPath = false; 416 420 _fastPathHint = true; … … 427 431 _fastPathHint(geometry._fastPathHint) 428 432 { 433 // temporary test 434 // setSupportsDisplayList(false); 435 429 436 for(PrimitiveSetList::const_iterator pitr=geometry._primitives.begin(); 430 437 pitr!=geometry._primitives.end(); … … 1273 1280 } 1274 1281 1282 #if 1 1275 1283 void Geometry::drawImplementation(RenderInfo& renderInfo) const 1276 1284 { 1277 1285 State& state = *renderInfo.getState(); 1278 1286 bool vertexAttribAlias = state.getUseVertexAttributeAliasing(); 1287 Drawable::Extensions* extensions = Drawable::getExtensions(state.getContextID(),true); 1288 1289 bool useFastPath = areFastPathsUsed(); 1290 bool usingVertexBufferObjects = _useVertexBufferObjects && state.isVertexBufferObjectSupported(); 1291 bool handleVertexAttributes = !_vertexAttribList.empty() && extensions->isVertexProgramSupported(); 1292 1293 osg::ref_ptr<ArrayDispatchers> s_ArrayDispatchers = 0; 1294 if (!s_ArrayDispatchers) s_ArrayDispatchers = new ArrayDispatchers(state); 1295 1296 ArrayDispatchers& arrayDispatchers = *s_ArrayDispatchers; 1297 1298 arrayDispatchers.reset(); 1299 arrayDispatchers.setUseGLBeginEndAdapter(!useFastPath); 1300 1301 arrayDispatchers.activateNormalArray(_normalData.binding, _normalData.array.get(), _normalData.indices.get()); 1302 arrayDispatchers.activateColorArray(_colorData.binding, _colorData.array.get(), _colorData.indices.get()); 1303 arrayDispatchers.activateSecondaryColorArray(_secondaryColorData.binding, _secondaryColorData.array.get(), _secondaryColorData.indices.get()); 1304 arrayDispatchers.activateFogCoordArray(_fogCoordData.binding, _fogCoordData.array.get(), _fogCoordData.indices.get()); 1305 1306 for(unsigned int unit=0;unit<_texCoordList.size();++unit) 1307 { 1308 arrayDispatchers.activateTexCoordArray(BIND_PER_VERTEX, unit, _texCoordList[unit].array.get(), _texCoordList[unit].indices.get()); 1309 } 1310 1311 for(unsigned int unit=0;unit<_vertexAttribList.size();++unit) 1312 { 1313 arrayDispatchers.activateVertexAttribArray(_vertexAttribList[unit].binding, unit, _vertexAttribList[unit].array.get(), _vertexAttribList[unit].indices.get()); 1314 } 1315 1316 arrayDispatchers.activateVertexArray(BIND_PER_VERTEX, _vertexData.array.get(), _vertexData.indices.get()); 1317 1318 1319 // dispatch any attributes that are bound overall 1320 arrayDispatchers.dispatch(BIND_OVERALL); 1321 1322 state.lazyDisablingOfVertexAttributes(); 1323 1324 if (useFastPath) 1325 { 1326 // set up arrays 1327 if( _vertexData.array.valid() ) 1328 state.setVertexPointer(_vertexData.array.get()); 1329 1330 if (_normalData.binding==BIND_PER_VERTEX && _normalData.array.valid()) 1331 state.setNormalPointer(_normalData.array.get()); 1332 1333 if (_colorData.binding==BIND_PER_VERTEX && _colorData.array.valid()) 1334 state.setColorPointer(_colorData.array.get()); 1335 1336 if (_secondaryColorData.binding==BIND_PER_VERTEX && _secondaryColorData.array.valid()) 1337 state.setSecondaryColorPointer(_secondaryColorData.array.get()); 1338 1339 if (_fogCoordData.binding==BIND_PER_VERTEX && _fogCoordData.array.valid()) 1340 state.setFogCoordPointer(_fogCoordData.array.get()); 1341 1342 for(unsigned int unit=0;unit<_texCoordList.size();++unit) 1343 { 1344 const Array* array = _texCoordList[unit].array.get(); 1345 if (array) state.setTexCoordPointer(unit,array); 1346 } 1347 1348 if( handleVertexAttributes ) 1349 { 1350 for(unsigned int index = 0; index < _vertexAttribList.size(); ++index ) 1351 { 1352 const Array* array = _vertexAttribList[index].array.get(); 1353 const AttributeBinding ab = _vertexAttribList[index].binding; 1354 if( ab == BIND_PER_VERTEX && array ) 1355 { 1356 state.setVertexAttribPointer( index, array, _vertexAttribList[index].normalize ); 1357 } 1358 } 1359 } 1360 } 1361 1362 state.applyDisablingOfVertexAttributes(); 1363 1364 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1365 // 1366 // draw the primitives themselves. 1367 // 1368 for(PrimitiveSetList::const_iterator itr=_primitives.begin(); 1369 itr!=_primitives.end(); 1370 ++itr) 1371 { 1372 // dispatch any attributes that are bound per primitive 1373 arrayDispatchers.dispatch(BIND_PER_PRIMITIVE_SET); 1374 1375 const PrimitiveSet* primitiveset = itr->get(); 1376 1377 if (useFastPath) 1378 { 1379 primitiveset->draw(state, usingVertexBufferObjects); 1380 } 1381 else 1382 { 1383 GLenum mode=primitiveset->getMode(); 1384 1385 unsigned int primLength; 1386 switch(mode) 1387 { 1388 case(GL_POINTS): primLength=1; break; 1389 case(GL_LINES): primLength=2; break; 1390 case(GL_TRIANGLES): primLength=3; break; 1391 case(GL_QUADS): primLength=4; break; 1392 default: primLength=0; break; // compute later when =0. 1393 } 1394 1395 // draw primitives by the more flexible "slow" path, 1396 // sending OpenGL glBegin/glVertex.../glEnd(). 1397 switch(primitiveset->getType()) 1398 { 1399 case(PrimitiveSet::DrawArraysPrimitiveType): 1400 { 1401 if (primLength==0) primLength=primitiveset->getNumIndices(); 1402 1403 const DrawArrays* drawArray = static_cast<const DrawArrays*>(primitiveset); 1404 arrayDispatchers.Begin(mode); 1405 1406 unsigned int primCount=0; 1407 unsigned int indexEnd = drawArray->getFirst()+drawArray->getCount(); 1408 for(unsigned int vindex=drawArray->getFirst(); 1409 vindex<indexEnd; 1410 ++vindex,++primCount) 1411 { 1412 if ((primCount%primLength)==0) 1413 { 1414 arrayDispatchers.dispatch(BIND_PER_PRIMITIVE); 1415 } 1416 1417 arrayDispatchers.dispatch(BIND_PER_VERTEX, vindex); 1418 } 1419 1420 arrayDispatchers.End(); 1421 break; 1422 } 1423 case(PrimitiveSet::DrawArrayLengthsPrimitiveType): 1424 { 1425 const DrawArrayLengths* drawArrayLengths = static_cast<const DrawArrayLengths*>(primitiveset); 1426 unsigned int vindex=drawArrayLengths->getFirst(); 1427 for(DrawArrayLengths::const_iterator primItr=drawArrayLengths->begin(); 1428 primItr!=drawArrayLengths->end(); 1429 ++primItr) 1430 { 1431 unsigned int localPrimLength; 1432 if (primLength==0) localPrimLength=*primItr; 1433 else localPrimLength=primLength; 1434 1435 arrayDispatchers.Begin(mode); 1436 1437 for(GLsizei primCount=0; 1438 primCount<*primItr; 1439 ++vindex,++primCount) 1440 { 1441 if ((primCount%localPrimLength)==0) 1442 { 1443 arrayDispatchers.dispatch(BIND_PER_PRIMITIVE); 1444 } 1445 arrayDispatchers.dispatch(BIND_PER_VERTEX, vindex); 1446 } 1447 1448 arrayDispatchers.End(); 1449 1450 } 1451 break; 1452 } 1453 case(PrimitiveSet::DrawElementsUBytePrimitiveType): 1454 { 1455 if (primLength==0) primLength=primitiveset->getNumIndices(); 1456 1457 const DrawElementsUByte* drawElements = static_cast<const DrawElementsUByte*>(primitiveset); 1458 arrayDispatchers.Begin(mode); 1459 1460 unsigned int primCount=0; 1461 for(DrawElementsUByte::const_iterator primItr=drawElements->begin(); 1462 primItr!=drawElements->end(); 1463 ++primCount,++primItr) 1464 { 1465 1466 if ((primCount%primLength)==0) 1467 { 1468 arrayDispatchers.dispatch(BIND_PER_PRIMITIVE); 1469 } 1470 1471 unsigned int vindex=*primItr; 1472 arrayDispatchers.dispatch(BIND_PER_VERTEX, vindex); 1473 } 1474 1475 arrayDispatchers.End(); 1476 break; 1477 } 1478 case(PrimitiveSet::DrawElementsUShortPrimitiveType): 1479 { 1480 if (primLength==0) primLength=primitiveset->getNumIndices(); 1481 1482 const DrawElementsUShort* drawElements = static_cast<const DrawElementsUShort*>(primitiveset); 1483 arrayDispatchers.Begin(mode); 1484 1485 unsigned int primCount=0; 1486 for(DrawElementsUShort::const_iterator primItr=drawElements->begin(); 1487 primItr!=drawElements->end(); 1488 ++primCount,++primItr) 1489 { 1490 if ((primCount%primLength)==0) 1491 { 1492 arrayDispatchers.dispatch(BIND_PER_PRIMITIVE); 1493 } 1494 1495 unsigned int vindex=*primItr; 1496 arrayDispatchers.dispatch(BIND_PER_VERTEX, vindex); 1497 } 1498 1499 arrayDispatchers.End(); 1500 break; 1501 } 1502 case(PrimitiveSet::DrawElementsUIntPrimitiveType): 1503 { 1504 if (primLength==0) primLength=primitiveset->getNumIndices(); 1505 1506 const DrawElementsUInt* drawElements = static_cast<const DrawElementsUInt*>(primitiveset); 1507 arrayDispatchers.Begin(mode); 1508 1509 unsigned int primCount=0; 1510 for(DrawElementsUInt::const_iterator primItr=drawElements->begin(); 1511 primItr!=drawElements->end(); 1512 ++primCount,++primItr) 1513 { 1514 if ((primCount%primLength)==0) 1515 { 1516 arrayDispatchers.dispatch(BIND_PER_PRIMITIVE); 1517 } 1518 1519 unsigned int vindex=*primItr; 1520 arrayDispatchers.dispatch(BIND_PER_VERTEX, vindex); 1521 } 1522 1523 arrayDispatchers.End(); 1524 break; 1525 } 1526 default: 1527 { 1528 break; 1529 } 1530 } 1531 } 1532 } 1533 } 1534 #else 1535 void Geometry::drawImplementation(RenderInfo& renderInfo) const 1536 { 1537 State& state = *renderInfo.getState(); 1538 bool vertexAttribAlias = state.getUseVertexAttributeAliasing(); 1539 1279 1540 1280 1541 // unsigned int contextID = state.getContextID(); … … 1339 1600 1340 1601 1602 1341 1603 unsigned int normalIndex = 0; 1342 1604 unsigned int colorIndex = 0; … … 1367 1629 if (normalBinding!=BIND_OFF && normalBinding!=BIND_PER_VERTEX) 1368 1630 { 1369 osg::notify(osg::NOTICE)<<"normal assign"<<std::endl;1370 1631 drawVertexAttribMap[normalBinding].push_back( new DrawVertexAttrib(extensions,2,false,_normalData.array.get(),_normalData.indices.get()) ); 1371 1632 normalBinding = BIND_OFF; … … 1374 1635 if (colorBinding!=BIND_OFF && colorBinding!=BIND_PER_VERTEX) 1375 1636 { 1376 osg::notify(osg::NOTICE)<<"color assign"<<std::endl;1377 1637 drawVertexAttribMap[colorBinding].push_back( new DrawVertexAttrib(extensions,3,false,_colorData.array.get(),_colorData.indices.get()) ); 1378 1638 colorBinding = BIND_OFF; … … 1383 1643 } 1384 1644 1385 1386 if (areFastPathsUsed()) 1645 // force the use of the slow path code to test the glBegin/glEnd replacement codes. 1646 bool forceSlowPath = false; 1647 1648 if (areFastPathsUsed() && !forceSlowPath) 1387 1649 { 1388 1650 … … 1815 2077 } 1816 2078 1817 1818 2079 // draw primitives by the more flexible "slow" path, 1819 2080 // sending OpenGL glBegin/glVertex.../glEnd(). … … 2168 2429 2169 2430 } 2431 #endif 2170 2432 2171 2433 class AttributeFunctorArrayVisitor : public ArrayVisitor
