/usr/include/osg/TriangleLinePointIndexFunctor is in libopenscenegraph-3.4-dev 3.4.1+dfsg1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | /* -*-c++-*- OpenSceneGraph - Copyright (C) Sketchfab
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commercial and non commercial
* applications, as long as this copyright notice is maintained.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#ifndef TRIANGLE_LINE_POINT_INDEX_FUNCTOR
#define TRIANGLE_LINE_POINT_INDEX_FUNCTOR
#include <osg/PrimitiveSet>
#include <osg/Array>
template<class T>
class TriangleLinePointIndexFunctor : public osg::PrimitiveIndexFunctor, public T
{
public:
virtual void setVertexArray(unsigned int,const osg::Vec2*)
{}
virtual void setVertexArray(unsigned int ,const osg::Vec3* )
{}
virtual void setVertexArray(unsigned int,const osg::Vec4* )
{}
virtual void setVertexArray(unsigned int,const osg::Vec2d*)
{}
virtual void setVertexArray(unsigned int ,const osg::Vec3d* )
{}
virtual void setVertexArray(unsigned int,const osg::Vec4d* )
{}
virtual void begin(GLenum mode) {
_modeCache = mode;
_indexCache.clear();
}
virtual void vertex(unsigned int vert) {
_indexCache.push_back(vert);
}
virtual void end() {
if (!_indexCache.empty()) {
drawElements(_modeCache,_indexCache.size(),&_indexCache.front());
}
}
virtual void drawArrays(GLenum mode, GLint first, GLsizei count) {
switch(mode)
{
case(GL_TRIANGLES):
{
unsigned int pos=first;
for(GLsizei i = 2 ; i < count ; i += 3, pos += 3) {
this->operator()(pos, pos + 1, pos + 2);
}
break;
}
case(GL_TRIANGLE_STRIP):
{
unsigned int pos = first;
for(GLsizei i = 2 ; i < count ; ++ i, ++ pos) {
if ((i%2)) this->operator()(pos, pos + 2, pos + 1);
else this->operator()(pos, pos + 1, pos + 2);
}
break;
}
case(GL_QUADS):
{
unsigned int pos = first;
for(GLsizei i = 3 ; i < count ; i += 4, pos += 4) {
this->operator()(pos,pos + 1, pos + 2);
this->operator()(pos,pos + 2, pos + 3);
}
break;
}
case(GL_QUAD_STRIP):
{
unsigned int pos = first;
for(GLsizei i = 3 ; i < count ; i += 2, pos += 2) {
this->operator()(pos, pos + 1,pos + 2);
this->operator()(pos + 1,pos + 3,pos + 2);
}
break;
}
case(GL_POLYGON): // treat polygons as GL_TRIANGLE_FAN
case(GL_TRIANGLE_FAN):
{
unsigned int pos = first + 1;
for(GLsizei i = 2 ; i < count ; ++ i, ++ pos) {
this->operator()(first, pos, pos + 1);
}
break;
}
case(GL_LINES):
{
unsigned int pos = first;
for(GLsizei i = 0 ; i < count ; i += 2, pos += 2) {
this->operator()(pos, pos + 1);
}
break;
}
case(GL_LINE_STRIP):
{
unsigned int pos = first;
for(GLsizei i = 0 ; i < count - 1 ; i += 1, pos += 1) {
this->operator()(pos, pos + 1);
}
break;
}
case(GL_LINE_LOOP):
{
unsigned int pos = first;
for(GLsizei i = 0 ; i < count - 1 ; i += 1, pos += 1) {
this->operator()(pos, pos + 1);
}
this->operator()(pos, first);
break;
}
case(GL_POINTS):
{
unsigned int pos=first;
for(GLsizei i = 0 ; i < count ; ++ i) {
this->operator()(pos + i);
}
break;
}
default:
break;
}
}
template<typename I>
void drawElements(GLenum mode, GLsizei count, const I* indices)
{
typedef I Index;
typedef const I* IndexPointer;
if (indices == 0 || count == 0) {
return;
}
switch(mode)
{
case(GL_TRIANGLES):
{
IndexPointer ilast = &indices[count];
for(IndexPointer iptr = indices ; iptr < ilast ; iptr += 3) {
this->operator()(*iptr, *(iptr + 1), *(iptr + 2));
}
break;
}
case(GL_TRIANGLE_STRIP):
{
IndexPointer iptr = indices;
for(GLsizei i = 2 ; i < count ; ++ i, ++ iptr) {
if ((i%2)) this->operator()(*(iptr), *(iptr + 2), *(iptr + 1));
else this->operator()(*(iptr), *(iptr + 1), *(iptr + 2));
}
break;
}
case(GL_QUADS):
{
IndexPointer iptr = indices;
for(GLsizei i = 3 ; i < count ; i += 4, iptr += 4) {
this->operator()(*(iptr), *(iptr + 1), *(iptr + 2));
this->operator()(*(iptr), *(iptr + 2), *(iptr + 3));
}
break;
}
case(GL_QUAD_STRIP):
{
IndexPointer iptr = indices;
for(GLsizei i = 3 ; i < count ; i += 2, iptr += 2) {
this->operator()(*(iptr), *(iptr + 1), *(iptr + 2));
this->operator()(*(iptr + 1), *(iptr + 3), *(iptr + 2));
}
break;
}
case(GL_POLYGON): // treat polygons as GL_TRIANGLE_FAN
case(GL_TRIANGLE_FAN):
{
IndexPointer iptr = indices;
Index first = *iptr;
++iptr;
for(GLsizei i = 2 ; i < count ; ++ i, ++ iptr) {
this->operator()(first, *(iptr), *(iptr + 1));
}
break;
}
case(GL_LINES):
{
const I* iptr = indices;
for(GLsizei i = 0 ; i < count ; i += 2, iptr += 2) {
this->operator()(*iptr, *(iptr + 1));
}
break;
}
case(GL_LINE_STRIP):
{
const I* iptr = indices;
for(GLsizei i = 0 ; i < count - 1 ; i += 1, iptr += 1) {
this->operator()(*iptr, *(iptr + 1));
}
break;
}
case(GL_LINE_LOOP):
{
const I* iptr = indices;
I first = *iptr;
for(GLsizei i = 0 ; i < count - 1 ; i += 1, iptr += 1) {
this->operator()(*iptr, *(iptr + 1));
}
this->operator()(*iptr, first);
break;
}
case GL_POINTS:
{
IndexPointer ilast = &indices[count];
for(IndexPointer iptr = indices ; iptr < ilast ; iptr += 1) {
this->operator()(*iptr);
}
break;
}
default:
break;
}
}
virtual void drawElements(GLenum mode, GLsizei count, const GLubyte* indices) {
drawElements<GLubyte>(mode, count, indices);
}
virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) {
drawElements<GLushort>(mode, count, indices);
}
virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) {
drawElements<GLuint>(mode, count, indices);
}
GLenum _modeCache;
std::vector<GLuint> _indexCache;
std::vector<unsigned int> _remap;
};
#endif
|