- Timestamp:
- 03/21/12 18:36:20 (15 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgUtil/ReversePrimitiveFunctor.cpp
r12292 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 */ … … 20 20 { 21 21 if (indices==0 || count==0) return NULL; 22 22 23 23 Type * dePtr = new Type(mode); 24 24 Type & de = *dePtr; 25 25 de.reserve(count); 26 26 27 27 typedef const typename Type::value_type* IndexPointer; 28 28 … … 32 32 { 33 33 IndexPointer ilast = &indices[count]; 34 34 35 35 for (IndexPointer iptr=indices; iptr<ilast; iptr+=3) 36 36 { … … 43 43 case (GL_QUADS): 44 44 { 45 45 46 46 IndexPointer ilast = &indices[count - 3]; 47 47 for (IndexPointer iptr = indices; iptr<ilast; iptr+=4) … … 68 68 { 69 69 de.push_back(*indices); 70 70 71 71 IndexPointer iptr = indices + 1; 72 72 IndexPointer ilast = &indices[count]; 73 73 de.resize(count); 74 74 std::reverse_copy(iptr, ilast, de.begin() + 1); 75 75 76 76 break; 77 77 } … … 86 86 de.resize(count); 87 87 std::reverse_copy(iptr, ilast, de.begin()); 88 88 89 89 break; 90 90 } … … 92 92 break; 93 93 } 94 94 95 95 return &de; 96 96 } … … 101 101 { 102 102 if (count==0) return ; 103 103 104 104 osg::DrawElementsUInt * dePtr = new osg::DrawElementsUInt(mode); 105 105 osg::DrawElementsUInt & de = *dePtr; … … 107 107 108 108 GLint end = first + count; 109 110 switch (mode) 111 { 112 case (GL_TRIANGLES): 113 { 114 for (GLint i=first; i<end; i+=3) 109 110 switch (mode) 111 { 112 case (GL_TRIANGLES): 113 { 114 for (GLint i=first; i<end; i+=3) 115 115 { 116 116 de.push_back(i); … … 120 120 break; 121 121 } 122 case (GL_QUADS): 123 { 124 for (GLint i=first; i<end; i+=4) 122 case (GL_QUADS): 123 { 124 for (GLint i=first; i<end; i+=4) 125 125 { 126 126 de.push_back(i); … … 132 132 } 133 133 case (GL_TRIANGLE_STRIP): 134 case (GL_QUAD_STRIP): 135 { 136 for (GLint i=first; i<end; i+=2) 134 case (GL_QUAD_STRIP): 135 { 136 for (GLint i=first; i<end; i+=2) 137 137 { 138 138 de.push_back(i+1); … … 141 141 break; 142 142 } 143 case (GL_TRIANGLE_FAN): 143 case (GL_TRIANGLE_FAN): 144 144 { 145 145 de.push_back(first); 146 147 for (GLint i=end-1; i>first; i--) 146 147 for (GLint i=end-1; i>first; i--) 148 148 de.push_back(i); 149 149 … … 154 154 case (GL_LINES): 155 155 case (GL_LINE_STRIP): 156 case (GL_LINE_LOOP): 157 { 158 for (GLint i=end-1; i>=first; i--) 159 de.push_back(i); 160 156 case (GL_LINE_LOOP): 157 { 158 for (GLint i=end-1; i>=first; i--) 159 de.push_back(i); 160 161 161 break; 162 162 } … … 190 190 { 191 191 _running = true; 192 192 193 193 _reversedPrimitiveSet = new osg::DrawElementsUInt(mode); 194 194 } … … 208 208 209 209 void ReversePrimitiveFunctor::end() 210 { 210 { 211 211 if (_running == false) 212 212 { … … 216 216 { 217 217 _running = false; 218 218 219 219 osg::ref_ptr<osg::DrawElementsUInt> tmpDe(static_cast<osg::DrawElementsUInt*>(_reversedPrimitiveSet.get())); 220 220 221 221 _reversedPrimitiveSet = drawElementsTemplate<osg::DrawElementsUInt>(tmpDe->getMode(), tmpDe->size(), &(tmpDe->front())); 222 222 }
