StelVertexArray.cpp   StelVertexArray.cpp 
skipping to change at line 22 skipping to change at line 22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "StelVertexArray.hpp" #include "StelVertexArray.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelPainter.hpp"
#include <QtOpenGL>
void StelVertexArray::draw(StelPainter* painter) const
{
painter->setVertexPointer(3, GL_DOUBLE, vertex.constData());
if (isTextured())
{
painter->setTexCoordPointer(2, GL_FLOAT, texCoords.constData
());
painter->enableClientStates(true, true);
}
else
{
painter->enableClientStates(true, false);
}
if (isIndexed())
painter->drawFromArray((StelPainter::DrawingMode)primitiveTy
pe, indices.size(), 0, true, indices.constData());
else
painter->drawFromArray((StelPainter::DrawingMode)primitiveTy
pe, vertex.size());
painter->enableClientStates(false);
}
StelVertexArray StelVertexArray::removeDiscontinuousTriangles(const StelPro jector* prj) const StelVertexArray StelVertexArray::removeDiscontinuousTriangles(const StelPro jector* prj) const
{ {
// Only support not indexed arrays.
Q_ASSERT(!isIndexed());
StelVertexArray ret = *this; StelVertexArray ret = *this;
// Create a 'Triangles' vertex array from this array. if (isIndexed())
// We have different algorithms for different original mode
switch (primitiveType)
{ {
case TriangleStrip: switch (primitiveType)
ret.indices.reserve(vertex.size() * 3);
for (int i = 2; i < vertex.size(); ++i)
{ {
if (prj->intersectViewportDiscontinuity(vertex[i], v case Triangles:
ertex[i-1]) || {
prj->intersectViewportDiscontinuity(vertex[i QVector<unsigned int> indicesOrig = ret.indices;
-1], vertex[i-2]) || ret.indices.resize(0);
prj->intersectViewportDiscontinuity(vertex[i for (int i = 0; i < indicesOrig.size(); i += 3)
-2], vertex[i]))
{
// We have a discontinuity.
}
else
{ {
if (i % 2 == 0) if (prj->intersectViewportDiscontinuity(vert
ret.indices << i-2 << i-1 << i; ex.at(indicesOrig.at(i)), vertex.at(indicesOrig.at(i+1))) ||
prj->intersectViewportDiscontinuity(
vertex.at(indicesOrig.at(i+1)), vertex.at(indicesOrig.at(i+2))) ||
prj->intersectViewportDiscontinuity(
vertex.at(indicesOrig.at(i+2)), vertex.at(indicesOrig.at(i))))
{
// We have a discontinuity.
}
else else
ret.indices << i-2 << i << i-1; {
ret.indices << indicesOrig.at(i) <<
indicesOrig.at(i+1) << indicesOrig.at(i+2);
}
} }
break;
} }
break; default:
// Unsupported
case Triangles: Q_ASSERT(false);
ret.indices.reserve(vertex.size()); }
}
for (int i = 0; i < vertex.size(); i += 3) else
{
// Create a 'Triangles' vertex array from this array.
// We have different algorithms for different original mode
switch (primitiveType)
{ {
if (prj->intersectViewportDiscontinuity(vertex.at(i) case TriangleStrip:
, vertex.at(i+1)) || ret.indices.reserve(vertex.size() * 3);
prj->intersectViewportDiscontinuity(vertex.a for (int i = 2; i < vertex.size(); ++i)
t(i+1), vertex.at(i+2)) ||
prj->intersectViewportDiscontinuity(vertex.a
t(i+2), vertex.at(i)))
{ {
// We have a discontinuity. if (prj->intersectViewportDiscontinuity(vert
ex[i], vertex[i-1]) ||
prj->intersectViewportDiscontinuity(
vertex[i-1], vertex[i-2]) ||
prj->intersectViewportDiscontinuity(
vertex[i-2], vertex[i]))
{
// We have a discontinuity.
}
else
{
if (i % 2 == 0)
ret.indices << i-2 << i-1 <<
i;
else
ret.indices << i-2 << i << i
-1;
}
} }
else break;
case Triangles:
ret.indices.reserve(vertex.size());
for (int i = 0; i < vertex.size(); i += 3)
{ {
ret.indices << i << i+1 << i+2; if (prj->intersectViewportDiscontinuity(vert
ex.at(i), vertex.at(i+1)) ||
prj->intersectViewportDiscontinuity(
vertex.at(i+1), vertex.at(i+2)) ||
prj->intersectViewportDiscontinuity(
vertex.at(i+2), vertex.at(i)))
{
// We have a discontinuity.
}
else
{
ret.indices << i << i+1 << i+2;
}
} }
} break;
break;
default: default:
Q_ASSERT(false); Q_ASSERT(false);
}
} }
// Just in case we don't have any triangles, we also remove all the vertex. // Just in case we don't have any triangles, we also remove all the vertex.
// This is because we can't specify an empty indexed VertexArray. // This is because we can't specify an empty indexed VertexArray.
// FIXME: we should use an attribute for indexed array. // FIXME: we should use an attribute for indexed array.
if (ret.indices.isEmpty()) if (ret.indices.isEmpty())
ret.vertex.clear(); ret.vertex.clear();
ret.primitiveType = Triangles; ret.primitiveType = Triangles;
return ret; return ret;
} }
QDataStream& operator<<(QDataStream& out, const StelVertexArray& p)
{
out << p.vertex;
out << p.texCoords;
out << p.indices;
out << (unsigned int)p.primitiveType;
return out;
}
QDataStream& operator>>(QDataStream& in, StelVertexArray& p)
{
in >> p.vertex;
in >> p.texCoords;
in >> p.indices;
unsigned int t;
in >> t;
p.primitiveType=(StelVertexArray::StelPrimitiveType)t;
return in;
}
 End of changes. 17 change blocks. 
69 lines changed or deleted 74 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/