Changeset 9447
- Timestamp:
- 01/06/09 15:55:49 (4 years ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 7 modified
-
include/osg/PrimitiveSet (modified) (9 diffs)
-
include/osg/State (modified) (3 diffs)
-
src/osg/PrimitiveSet.cpp (modified) (4 diffs)
-
src/osg/State.cpp (modified) (2 diffs)
-
src/osgPlugins/ive/IveVersion.h (modified) (1 diff)
-
src/osgPlugins/ive/PrimitiveSet.cpp (modified) (2 diffs)
-
src/osgPlugins/osg/Geometry.cpp (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osg/PrimitiveSet
r8467 r9447 176 176 }; 177 177 178 PrimitiveSet(Type primType=PrimitiveType,GLenum mode=0 ):178 PrimitiveSet(Type primType=PrimitiveType,GLenum mode=0, int numInstances=0): 179 179 _primitiveType(primType), 180 _numInstances(numInstances), 180 181 _mode(mode), 181 182 _modifiedCount(0), … … 185 186 Object(prim,copyop), 186 187 _primitiveType(prim._primitiveType), 188 _numInstances(prim._numInstances), 187 189 _mode(prim._mode), 188 190 _modifiedCount(0), … … 201 203 virtual const DrawElements* getDrawElements() const { return 0; } 202 204 205 void setNumInstances(int n) { _numInstances = n; } 206 int getNumInstances() const { return _numInstances; } 207 203 208 void setMode(GLenum mode) { _mode = mode; } 204 209 GLenum getMode() const { return _mode; } … … 239 244 240 245 Type _primitiveType; 246 int _numInstances; 241 247 GLenum _mode; 242 248 unsigned int _modifiedCount; … … 276 282 _count(0) {} 277 283 278 DrawArrays(GLenum mode, GLint first, GLsizei count ):279 PrimitiveSet(DrawArraysPrimitiveType, mode),284 DrawArrays(GLenum mode, GLint first, GLsizei count, int numInstances=0): 285 PrimitiveSet(DrawArraysPrimitiveType, mode, numInstances), 280 286 _first(first), 281 287 _count(count) {} … … 386 392 public: 387 393 388 DrawElements(Type primType=PrimitiveType, GLenum mode=0 ):389 PrimitiveSet(primType,mode ),394 DrawElements(Type primType=PrimitiveType, GLenum mode=0, int numInstances=0): 395 PrimitiveSet(primType,mode, numInstances), 390 396 _eboOffset(0) {} 391 397 … … 473 479 vector_type(array) {} 474 480 475 DrawElementsUByte(GLenum mode, unsigned int no, const GLubyte* ptr ) :476 DrawElements(DrawElementsUBytePrimitiveType,mode ),481 DrawElementsUByte(GLenum mode, unsigned int no, const GLubyte* ptr, int numInstances=0) : 482 DrawElements(DrawElementsUBytePrimitiveType,mode,numInstances), 477 483 vector_type(ptr,ptr+no) {} 478 484 … … 543 549 vector_type(array) {} 544 550 545 DrawElementsUShort(GLenum mode, unsigned int no, const GLushort* ptr ) :546 DrawElements(DrawElementsUShortPrimitiveType,mode ),551 DrawElementsUShort(GLenum mode, unsigned int no, const GLushort* ptr, int numInstances=0) : 552 DrawElements(DrawElementsUShortPrimitiveType,mode,numInstances), 547 553 vector_type(ptr,ptr+no) {} 548 554 … … 617 623 vector_type(array) {} 618 624 619 DrawElementsUInt(GLenum mode, unsigned int no, const GLuint* ptr ) :620 DrawElements(DrawElementsUIntPrimitiveType,mode ),625 DrawElementsUInt(GLenum mode, unsigned int no, const GLuint* ptr, int numInstances=0) : 626 DrawElements(DrawElementsUIntPrimitiveType,mode,numInstances), 621 627 vector_type(ptr,ptr+no) {} 622 628 -
OpenSceneGraph/trunk/include/osg/State
r7648 r9447 460 460 _currentPBO = 0; 461 461 } 462 463 464 inline void glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei primcount) 465 { 466 if (primcount>=1 && _glDrawArraysInstanced!=0) _glDrawArraysInstanced(mode, first, count, primcount); 467 else glDrawArrays(mode, first, count); 468 } 469 470 inline void glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount ) 471 { 472 if (primcount>=1 && _glDrawElementsInstanced!=0) _glDrawElementsInstanced(mode, count, type, indices, primcount); 473 else glDrawElements(mode, count, type, indices); 474 } 475 462 476 463 477 /** Wrapper around glInterleavedArrays(..). … … 1294 1308 typedef void (APIENTRY * DisableVertexAttribProc) (unsigned int); 1295 1309 typedef void (APIENTRY * BindBufferProc) (GLenum target, GLuint buffer); 1296 1310 1311 typedef void (APIENTRY * DrawArraysInstancedProc)( GLenum mode, GLint first, GLsizei count, GLsizei primcount ); 1312 typedef void (APIENTRY * DrawElementsInstancedProc)( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount ); 1297 1313 1298 1314 bool _extensionProcsInitialized; … … 1307 1323 DisableVertexAttribProc _glDisableVertexAttribArray; 1308 1324 BindBufferProc _glBindBuffer; 1309 1325 DrawArraysInstancedProc _glDrawArraysInstanced; 1326 DrawElementsInstancedProc _glDrawElementsInstanced; 1310 1327 1311 1328 unsigned int _dynamicObjectCount; -
OpenSceneGraph/trunk/src/osg/PrimitiveSet.cpp
r6582 r9447 36 36 } 37 37 38 void DrawArrays::draw(State&, bool) const 39 { 40 glDrawArrays(_mode,_first,_count); 38 void DrawArrays::draw(State& state, bool) const 39 { 40 if (_numInstances>=1) state.glDrawArraysInstanced(_mode,_first,_count, _numInstances); 41 else glDrawArrays(_mode,_first,_count); 41 42 } 42 43 … … 130 131 if (ebo) 131 132 { 132 glDrawElements(_mode, size(), GL_UNSIGNED_BYTE, getElementBufferObjectOffset()); 133 if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_BYTE, getElementBufferObjectOffset(), _numInstances); 134 else glDrawElements(_mode, size(), GL_UNSIGNED_BYTE, getElementBufferObjectOffset()); 133 135 } 134 136 else 135 137 { 136 glDrawElements(_mode, size(), GL_UNSIGNED_BYTE, &front()); 138 if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_BYTE, &front(), _numInstances); 139 else glDrawElements(_mode, size(), GL_UNSIGNED_BYTE, &front()); 137 140 } 138 141 } 139 142 else 140 143 { 141 glDrawElements(_mode, size(), GL_UNSIGNED_BYTE, &front()); 144 if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_BYTE, &front(), _numInstances); 145 else glDrawElements(_mode, size(), GL_UNSIGNED_BYTE, &front()); 142 146 } 143 147 } … … 177 181 if (ebo) 178 182 { 179 glDrawElements(_mode, size(), GL_UNSIGNED_SHORT, getElementBufferObjectOffset()); 183 if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_BYTE, getElementBufferObjectOffset(), _numInstances); 184 else glDrawElements(_mode, size(), GL_UNSIGNED_SHORT, getElementBufferObjectOffset()); 180 185 } 181 186 else 182 187 { 183 glDrawElements(_mode, size(), GL_UNSIGNED_SHORT, &front()); 188 if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_BYTE, &front(), _numInstances); 189 else glDrawElements(_mode, size(), GL_UNSIGNED_SHORT, &front()); 184 190 } 185 191 } 186 192 else 187 193 { 188 glDrawElements(_mode, size(), GL_UNSIGNED_SHORT, &front()); 194 if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_BYTE, &front(), _numInstances); 195 else glDrawElements(_mode, size(), GL_UNSIGNED_SHORT, &front()); 189 196 } 190 197 } … … 224 231 if (ebo) 225 232 { 226 glDrawElements(_mode, size(), GL_UNSIGNED_INT, getElementBufferObjectOffset()); 233 if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_BYTE, getElementBufferObjectOffset(), _numInstances); 234 else glDrawElements(_mode, size(), GL_UNSIGNED_INT, getElementBufferObjectOffset()); 227 235 } 228 236 else 229 237 { 230 glDrawElements(_mode, size(), GL_UNSIGNED_INT, &front()); 238 if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_BYTE, &front(), _numInstances); 239 else glDrawElements(_mode, size(), GL_UNSIGNED_INT, &front()); 231 240 } 232 241 } 233 242 else 234 243 { 235 glDrawElements(_mode, size(), GL_UNSIGNED_INT, &front()); 244 if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_BYTE, &front(), _numInstances); 245 else glDrawElements(_mode, size(), GL_UNSIGNED_INT, &front()); 236 246 } 237 247 } -
OpenSceneGraph/trunk/src/osg/State.cpp
r9380 r9447 80 80 _glEnableVertexAttribArray = 0; 81 81 _glDisableVertexAttribArray = 0; 82 _glDrawArraysInstanced = 0; 83 _glDrawElementsInstanced = 0; 82 84 83 85 _dynamicObjectCount = 0; … … 755 757 setGLExtensionFuncPtr(_glBindBuffer, "glBindBuffer","glBindBufferARB"); 756 758 759 setGLExtensionFuncPtr(_glDrawArraysInstanced, "glDrawArraysInstanced","glDrawArraysInstancedEXT"); 760 setGLExtensionFuncPtr(_glDrawElementsInstanced, "glDrawElementsInstanced","glDrawElementsInstancedEXT"); 761 757 762 if ( osg::getGLVersionNumber() >= 2.0 || osg::isGLExtensionSupported(_contextID,"GL_ARB_vertex_shader") ) 758 763 { -
OpenSceneGraph/trunk/src/osgPlugins/ive/IveVersion.h
r9411 r9447 47 47 #define VERSION_0036 36 48 48 #define VERSION_0037 37 49 #define VERSION_0038 38 49 50 50 #define VERSION VERSION_003 751 #define VERSION VERSION_0038 51 52 52 53 /* The BYTE_SEX tag is used to check the endian -
OpenSceneGraph/trunk/src/osgPlugins/ive/PrimitiveSet.cpp
r4801 r9447 31 31 32 32 33 if ( out->getVersion() >= VERSION_0038 ) 34 { 35 out->writeInt(getNumInstances()); 36 } 37 33 38 // Write PrimitiveSet's properties. 34 39 out->writeInt(getMode()); … … 50 55 51 56 57 if ( in->getVersion() >= VERSION_0038 ) 58 { 59 setNumInstances(in->readInt()); 60 } 61 52 62 // Read in primitiveset properties. 53 63 setMode(in->readInt()); -
OpenSceneGraph/trunk/src/osgPlugins/osg/Geometry.cpp
r9343 r9447 1004 1004 { 1005 1005 bool iteratorAdvanced = false; 1006 if (fr.matchSequence("DrawArrays %w %i %i")) 1006 bool firstMatched = false; 1007 if ((firstMatched = fr.matchSequence("DrawArrays %w %i %i %i")) || 1008 fr.matchSequence("DrawArrays %w %i %i") ) 1007 1009 { 1008 1010 … … 1016 1018 fr[3].getInt(count); 1017 1019 1018 geom.addPrimitiveSet(new DrawArrays(mode,first,count)); 1019 1020 fr += 4; 1021 1022 iteratorAdvanced = true; 1023 1024 } 1025 else if (fr.matchSequence("DrawArrayLengths %w %i %i {")) 1020 int numInstances = 0; 1021 if (firstMatched) 1022 { 1023 fr[4].getInt(numInstances); 1024 fr += 5; 1025 } 1026 else 1027 { 1028 fr += 4; 1029 } 1030 1031 geom.addPrimitiveSet(new DrawArrays(mode, first, count, numInstances)); 1032 1033 1034 iteratorAdvanced = true; 1035 1036 } 1037 else if ((firstMatched = fr.matchSequence("DrawArrayLengths %w %i %i %i {")) || 1038 fr.matchSequence("DrawArrayLengths %w %i %i {") ) 1026 1039 { 1027 1040 int entry = fr[1].getNoNestedBrackets(); … … 1036 1049 fr[3].getInt(capacity); 1037 1050 1038 fr += 5; 1039 1051 int numInstances = 0; 1052 if (firstMatched) 1053 { 1054 fr[4].getInt(numInstances); 1055 fr += 6; 1056 } 1057 else 1058 { 1059 fr += 5; 1060 } 1061 1040 1062 DrawArrayLengths* prim = new DrawArrayLengths; 1041 1063 prim->setMode(mode); 1064 prim->setNumInstances(numInstances); 1042 1065 prim->setFirst(first); 1043 1066 prim->reserve(capacity); … … 1058 1081 iteratorAdvanced = true; 1059 1082 } 1060 else if (fr.matchSequence("DrawElementsUByte %w %i {")) 1083 else if ((firstMatched = fr.matchSequence("DrawElementsUByte %w %i %i {")) || 1084 fr.matchSequence("DrawElementsUByte %w %i {")) 1061 1085 { 1062 1086 int entry = fr[1].getNoNestedBrackets(); … … 1068 1092 fr[2].getInt(capacity); 1069 1093 1070 fr += 4; 1071 1094 int numInstances = 0; 1095 if (firstMatched) 1096 { 1097 fr[3].getInt(numInstances); 1098 fr += 5; 1099 } 1100 else 1101 { 1102 fr += 4; 1103 } 1104 1072 1105 DrawElementsUByte* prim = new DrawElementsUByte; 1073 1106 prim->setMode(mode); 1107 prim->setNumInstances(numInstances); 1074 1108 prim->reserve(capacity); 1075 1109 … … 1089 1123 iteratorAdvanced = true; 1090 1124 } 1091 else if (fr.matchSequence("DrawElementsUShort %w %i {")) 1125 else if ((firstMatched = fr.matchSequence("DrawElementsUShort %w %i %i {")) || 1126 fr.matchSequence("DrawElementsUShort %w %i {")) 1092 1127 { 1093 1128 int entry = fr[1].getNoNestedBrackets(); … … 1099 1134 fr[2].getInt(capacity); 1100 1135 1101 fr += 4; 1136 int numInstances = 0; 1137 if (firstMatched) 1138 { 1139 fr[3].getInt(numInstances); 1140 fr += 5; 1141 } 1142 else 1143 { 1144 fr += 4; 1145 } 1102 1146 1103 1147 DrawElementsUShort* prim = new DrawElementsUShort; 1104 1148 prim->setMode(mode); 1149 prim->setNumInstances(numInstances); 1105 1150 prim->reserve(capacity); 1106 1151 … … 1120 1165 iteratorAdvanced = true; 1121 1166 } 1122 else if (fr.matchSequence("DrawElementsUInt %w %i {")) 1167 else if ((firstMatched = fr.matchSequence("DrawElementsUInt %w %i %i {")) || 1168 fr.matchSequence("DrawElementsUInt %w %i {")) 1123 1169 { 1124 1170 int entry = fr[1].getNoNestedBrackets(); … … 1130 1176 fr[2].getInt(capacity); 1131 1177 1132 fr += 4; 1178 int numInstances = 0; 1179 if (firstMatched) 1180 { 1181 fr[3].getInt(numInstances); 1182 fr += 5; 1183 } 1184 else 1185 { 1186 fr += 4; 1187 } 1133 1188 1134 1189 DrawElementsUInt* prim = new DrawElementsUInt; 1135 1190 prim->setMode(mode); 1191 prim->setNumInstances(numInstances); 1136 1192 prim->reserve(capacity); 1137 1193 … … 1163 1219 { 1164 1220 const DrawArrays& cprim = static_cast<const DrawArrays&>(prim); 1165 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.getFirst()<<" "<<cprim.getCount()<<std::endl; 1221 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.getFirst()<<" "<<cprim.getCount(); 1222 if (prim.getNumInstances()>0) fw<<" "<<prim.getNumInstances(); 1223 fw<<std::endl; 1166 1224 return true; 1167 1225 } … … 1170 1228 { 1171 1229 const DrawArrayLengths& cprim = static_cast<const DrawArrayLengths&>(prim); 1172 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.getFirst()<<" "<<cprim.size()<<std::endl; 1230 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.getFirst()<<" "<<cprim.size(); 1231 if (prim.getNumInstances()>0) fw<<" "<<prim.getNumInstances(); 1232 fw<<std::endl; 1173 1233 writeArray(fw,cprim.begin(),cprim.end()); 1174 1234 return true; … … 1178 1238 { 1179 1239 const DrawElementsUByte& cprim = static_cast<const DrawElementsUByte&>(prim); 1180 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size()<<std::endl; 1240 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size(); 1241 if (prim.getNumInstances()>0) fw<<" "<<prim.getNumInstances(); 1242 fw<<std::endl; 1181 1243 writeArrayAsInts(fw,cprim.begin(),cprim.end()); 1182 1244 return true; … … 1186 1248 { 1187 1249 const DrawElementsUShort& cprim = static_cast<const DrawElementsUShort&>(prim); 1188 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size()<<std::endl; 1250 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size(); 1251 if (prim.getNumInstances()>0) fw<<" "<<prim.getNumInstances(); 1252 fw<<std::endl; 1189 1253 writeArray(fw,cprim.begin(),cprim.end()); 1190 1254 return true; … … 1194 1258 { 1195 1259 const DrawElementsUInt& cprim = static_cast<const DrawElementsUInt&>(prim); 1196 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size()<<std::endl; 1260 fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size(); 1261 if (prim.getNumInstances()>0) fw<<" "<<prim.getNumInstances(); 1262 fw<<std::endl; 1197 1263 writeArray(fw,cprim.begin(),cprim.end()); 1198 1264 return true;
